| 1 | /** |
| 2 | * <copyright> |
| 3 | * </copyright> |
| 4 | * |
| 5 | * $Id$ |
| 6 | */ |
| 7 | package QVTRelation.provider; |
| 8 | |
| 9 | |
| 10 | import EMOF.provider.QvtmodelsEditPlugin; |
| 11 | |
| 12 | import EssentialOCL.EssentialOCLFactory; |
| 13 | |
| 14 | import QVTBase.QVTBaseFactory; |
| 15 | |
| 16 | import QVTBase.provider.RuleItemProvider; |
| 17 | |
| 18 | import QVTRelation.QVTRelationFactory; |
| 19 | import QVTRelation.QVTRelationPackage; |
| 20 | import QVTRelation.Relation; |
| 21 | |
| 22 | import java.util.Collection; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import org.eclipse.emf.common.notify.AdapterFactory; |
| 26 | import org.eclipse.emf.common.notify.Notification; |
| 27 | |
| 28 | import org.eclipse.emf.common.util.ResourceLocator; |
| 29 | |
| 30 | import org.eclipse.emf.ecore.EStructuralFeature; |
| 31 | |
| 32 | import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; |
| 33 | import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 34 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 35 | import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; |
| 36 | import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 37 | import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 38 | import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 39 | import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; |
| 40 | import org.eclipse.emf.edit.provider.ViewerNotification; |
| 41 | |
| 42 | /** |
| 43 | * This is the item provider adapter for a {@link QVTRelation.Relation} object. |
| 44 | * <!-- begin-user-doc --> |
| 45 | * <!-- end-user-doc --> |
| 46 | * @generated |
| 47 | */ |
| 48 | public class RelationItemProvider |
| 49 | extends RuleItemProvider |
| 50 | implements |
| 51 | IEditingDomainItemProvider, |
| 52 | IStructuredItemContentProvider, |
| 53 | ITreeItemContentProvider, |
| 54 | IItemLabelProvider, |
| 55 | IItemPropertySource { |
| 56 | /** |
| 57 | * This constructs an instance from a factory and a notifier. |
| 58 | * <!-- begin-user-doc --> |
| 59 | * <!-- end-user-doc --> |
| 60 | * @generated |
| 61 | */ |
| 62 | public RelationItemProvider(AdapterFactory adapterFactory) { |
| 63 | super(adapterFactory); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * This returns the property descriptors for the adapted class. |
| 68 | * <!-- begin-user-doc --> |
| 69 | * <!-- end-user-doc --> |
| 70 | * @generated |
| 71 | */ |
| 72 | @Override |
| 73 | public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) { |
| 74 | if (itemPropertyDescriptors == null) { |
| 75 | super.getPropertyDescriptors(object); |
| 76 | |
| 77 | addIsTopLevelPropertyDescriptor(object); |
| 78 | } |
| 79 | return itemPropertyDescriptors; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * This adds a property descriptor for the Is Top Level feature. |
| 84 | * <!-- begin-user-doc --> |
| 85 | * <!-- end-user-doc --> |
| 86 | * @generated |
| 87 | */ |
| 88 | protected void addIsTopLevelPropertyDescriptor(Object object) { |
| 89 | itemPropertyDescriptors.add |
| 90 | (createItemPropertyDescriptor |
| 91 | (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), |
| 92 | getResourceLocator(), |
| 93 | getString("_UI_Relation_isTopLevel_feature"), |
| 94 | getString("_UI_PropertyDescriptor_description", "_UI_Relation_isTopLevel_feature", "_UI_Relation_type"), |
| 95 | QVTRelationPackage.Literals.RELATION__IS_TOP_LEVEL, |
| 96 | true, |
| 97 | false, |
| 98 | false, |
| 99 | ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, |
| 100 | null, |
| 101 | null)); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an |
| 106 | * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or |
| 107 | * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. |
| 108 | * <!-- begin-user-doc --> |
| 109 | * <!-- end-user-doc --> |
| 110 | * @generated |
| 111 | */ |
| 112 | @Override |
| 113 | public Collection<? extends EStructuralFeature> getChildrenFeatures(Object object) { |
| 114 | if (childrenFeatures == null) { |
| 115 | super.getChildrenFeatures(object); |
| 116 | childrenFeatures.add(QVTRelationPackage.Literals.RELATION__OPERATIONAL_IMPL); |
| 117 | childrenFeatures.add(QVTRelationPackage.Literals.RELATION__VARIABLE); |
| 118 | childrenFeatures.add(QVTRelationPackage.Literals.RELATION__WHEN); |
| 119 | childrenFeatures.add(QVTRelationPackage.Literals.RELATION__WHERE); |
| 120 | } |
| 121 | return childrenFeatures; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * <!-- begin-user-doc --> |
| 126 | * <!-- end-user-doc --> |
| 127 | * @generated |
| 128 | */ |
| 129 | @Override |
| 130 | protected EStructuralFeature getChildFeature(Object object, Object child) { |
| 131 | // Check the type of the specified child object and return the proper feature to use for |
| 132 | // adding (see {@link AddCommand}) it as a child. |
| 133 | |
| 134 | return super.getChildFeature(object, child); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * This returns Relation.gif. |
| 139 | * <!-- begin-user-doc --> |
| 140 | * <!-- end-user-doc --> |
| 141 | * @generated |
| 142 | */ |
| 143 | @Override |
| 144 | public Object getImage(Object object) { |
| 145 | return overlayImage(object, getResourceLocator().getImage("full/obj16/Relation")); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * This returns the label text for the adapted class. |
| 150 | * <!-- begin-user-doc --> |
| 151 | * <!-- end-user-doc --> |
| 152 | * @generated |
| 153 | */ |
| 154 | @Override |
| 155 | public String getText(Object object) { |
| 156 | String label = ((Relation)object).getName(); |
| 157 | return label == null || label.length() == 0 ? |
| 158 | getString("_UI_Relation_type") : |
| 159 | getString("_UI_Relation_type") + " " + label; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * This handles model notifications by calling {@link #updateChildren} to update any cached |
| 164 | * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}. |
| 165 | * <!-- begin-user-doc --> |
| 166 | * <!-- end-user-doc --> |
| 167 | * @generated |
| 168 | */ |
| 169 | @Override |
| 170 | public void notifyChanged(Notification notification) { |
| 171 | updateChildren(notification); |
| 172 | |
| 173 | switch (notification.getFeatureID(Relation.class)) { |
| 174 | case QVTRelationPackage.RELATION__IS_TOP_LEVEL: |
| 175 | fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); |
| 176 | return; |
| 177 | case QVTRelationPackage.RELATION__OPERATIONAL_IMPL: |
| 178 | case QVTRelationPackage.RELATION__VARIABLE: |
| 179 | case QVTRelationPackage.RELATION__WHEN: |
| 180 | case QVTRelationPackage.RELATION__WHERE: |
| 181 | fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), true, false)); |
| 182 | return; |
| 183 | } |
| 184 | super.notifyChanged(notification); |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * This adds {@link org.eclipse.emf.edit.command.CommandParameter}s describing the children |
| 189 | * that can be created under this object. |
| 190 | * <!-- begin-user-doc --> |
| 191 | * <!-- end-user-doc --> |
| 192 | * @generated |
| 193 | */ |
| 194 | @Override |
| 195 | protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) { |
| 196 | super.collectNewChildDescriptors(newChildDescriptors, object); |
| 197 | |
| 198 | newChildDescriptors.add |
| 199 | (createChildParameter |
| 200 | (QVTRelationPackage.Literals.RELATION__OPERATIONAL_IMPL, |
| 201 | QVTRelationFactory.eINSTANCE.createRelationImplementation())); |
| 202 | |
| 203 | newChildDescriptors.add |
| 204 | (createChildParameter |
| 205 | (QVTRelationPackage.Literals.RELATION__VARIABLE, |
| 206 | EssentialOCLFactory.eINSTANCE.createVariable())); |
| 207 | |
| 208 | newChildDescriptors.add |
| 209 | (createChildParameter |
| 210 | (QVTRelationPackage.Literals.RELATION__VARIABLE, |
| 211 | QVTBaseFactory.eINSTANCE.createFunctionParameter())); |
| 212 | |
| 213 | newChildDescriptors.add |
| 214 | (createChildParameter |
| 215 | (QVTRelationPackage.Literals.RELATION__WHEN, |
| 216 | QVTRelationFactory.eINSTANCE.createDomainPattern())); |
| 217 | |
| 218 | newChildDescriptors.add |
| 219 | (createChildParameter |
| 220 | (QVTRelationPackage.Literals.RELATION__WHEN, |
| 221 | QVTBaseFactory.eINSTANCE.createPattern())); |
| 222 | |
| 223 | newChildDescriptors.add |
| 224 | (createChildParameter |
| 225 | (QVTRelationPackage.Literals.RELATION__WHERE, |
| 226 | QVTRelationFactory.eINSTANCE.createDomainPattern())); |
| 227 | |
| 228 | newChildDescriptors.add |
| 229 | (createChildParameter |
| 230 | (QVTRelationPackage.Literals.RELATION__WHERE, |
| 231 | QVTBaseFactory.eINSTANCE.createPattern())); |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * This returns the label text for {@link org.eclipse.emf.edit.command.CreateChildCommand}. |
| 236 | * <!-- begin-user-doc --> |
| 237 | * <!-- end-user-doc --> |
| 238 | * @generated |
| 239 | */ |
| 240 | @Override |
| 241 | public String getCreateChildText(Object owner, Object feature, Object child, Collection<?> selection) { |
| 242 | Object childFeature = feature; |
| 243 | Object childObject = child; |
| 244 | |
| 245 | boolean qualify = |
| 246 | childFeature == QVTRelationPackage.Literals.RELATION__WHEN || |
| 247 | childFeature == QVTRelationPackage.Literals.RELATION__WHERE; |
| 248 | |
| 249 | if (qualify) { |
| 250 | return getString |
| 251 | ("_UI_CreateChild_text2", |
| 252 | new Object[] { getTypeText(childObject), getFeatureText(childFeature), getTypeText(owner) }); |
| 253 | } |
| 254 | return super.getCreateChildText(owner, feature, child, selection); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Return the resource locator for this item provider's resources. |
| 259 | * <!-- begin-user-doc --> |
| 260 | * <!-- end-user-doc --> |
| 261 | * @generated |
| 262 | */ |
| 263 | @Override |
| 264 | public ResourceLocator getResourceLocator() { |
| 265 | return QvtmodelsEditPlugin.INSTANCE; |
| 266 | } |
| 267 | |
| 268 | } |