1 17 package org.eclipse.emf.ecore.provider; 18 19 20 import java.util.Collection ; 21 import java.util.List ; 22 import java.util.Map ; 23 24 import org.eclipse.emf.common.command.Command; 25 import org.eclipse.emf.common.command.CommandWrapper; 26 import org.eclipse.emf.common.notify.AdapterFactory; 27 import org.eclipse.emf.common.notify.Notification; 28 import org.eclipse.emf.common.util.ResourceLocator; 29 import org.eclipse.emf.ecore.EObject; 30 import org.eclipse.emf.ecore.EStructuralFeature; 31 import org.eclipse.emf.ecore.EcorePackage; 32 import org.eclipse.emf.edit.domain.EditingDomain; 33 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 34 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 35 import org.eclipse.emf.edit.provider.IItemLabelProvider; 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.ItemProviderAdapter; 41 42 import org.eclipse.emf.edit.provider.ViewerNotification; 43 44 50 public class EStringToStringMapEntryItemProvider 51 extends ItemProviderAdapter 52 implements 53 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 54 { 55 61 public EStringToStringMapEntryItemProvider(AdapterFactory adapterFactory) 62 { 63 super(adapterFactory); 64 } 65 66 72 public List getPropertyDescriptors(Object object) 73 { 74 if (itemPropertyDescriptors == null) 75 { 76 super.getPropertyDescriptors(object); 77 78 addKeyPropertyDescriptor(object); 79 addValuePropertyDescriptor(object); 80 } 81 return itemPropertyDescriptors; 82 } 83 84 90 protected void addKeyPropertyDescriptor(Object object) 91 { 92 itemPropertyDescriptors.add 93 (createItemPropertyDescriptor 94 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 95 getResourceLocator(), 96 getString("_UI_EStringToStringMapEntry_key_feature"), 97 getString("_UI_PropertyDescriptor_description", "_UI_EStringToStringMapEntry_key_feature", "_UI_EStringToStringMapEntry_type"), 98 EcorePackage.eINSTANCE.getEStringToStringMapEntry_Key(), 99 true, 100 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 101 null, 102 null)); 103 } 104 105 111 protected void addValuePropertyDescriptor(Object object) 112 { 113 itemPropertyDescriptors.add 114 (createItemPropertyDescriptor 115 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(), 116 getResourceLocator(), 117 getString("_UI_EStringToStringMapEntry_value_feature"), 118 getString("_UI_PropertyDescriptor_description", "_UI_EStringToStringMapEntry_value_feature", "_UI_EStringToStringMapEntry_type"), 119 EcorePackage.eINSTANCE.getEStringToStringMapEntry_Value(), 120 true, 121 ItemPropertyDescriptor.GENERIC_VALUE_IMAGE, 122 null, 123 null)); 124 } 125 126 132 public Object getImage(Object object) 133 { 134 return getResourceLocator().getImage("full/obj16/EStringToStringMapEntry"); 135 } 136 137 143 public String getText(Object object) 144 { 145 Map.Entry eStringToStringMapEntry = (Map.Entry )object; 146 return "" + eStringToStringMapEntry.getKey() + " -> " + eStringToStringMapEntry.getValue(); 147 } 148 149 156 public void notifyChanged(Notification notification) 157 { 158 updateChildren(notification); 159 160 switch (notification.getFeatureID(Map.Entry .class)) 161 { 162 case EcorePackage.ESTRING_TO_STRING_MAP_ENTRY__KEY: 163 case EcorePackage.ESTRING_TO_STRING_MAP_ENTRY__VALUE: 164 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true)); 165 return; 166 } 167 super.notifyChanged(notification); 168 } 169 170 177 protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) 178 { 179 super.collectNewChildDescriptors(newChildDescriptors, object); 180 } 181 182 185 protected Command createSetCommand(EditingDomain domain, final EObject owner, EStructuralFeature feature, Object value, int index) 186 { 187 Command result = super.createSetCommand(domain, owner, feature, value, index); 188 if (feature == EcorePackage.eINSTANCE.getEStringToStringMapEntry_Key()) 189 { 190 result = new 191 CommandWrapper(result) 192 { 193 public void execute() 194 { 195 super.execute(); 196 reindex(); 197 } 198 199 public void undo() 200 { 201 super.undo(); 202 reindex(); 203 } 204 205 public void redo() 206 { 207 super.redo(); 208 reindex(); 209 } 210 211 private void reindex() 212 { 213 EObject parent = owner.eContainer(); 214 if (parent != null) 215 { 216 EStructuralFeature feature = owner.eContainmentFeature(); 217 List list = (List )parent.eGet(feature); 218 list.set(list.indexOf(owner), owner); 219 } 220 } 221 }; 222 } 223 return result; 224 } 225 226 232 public ResourceLocator getResourceLocator() 233 { 234 return EcoreEditPlugin.INSTANCE; 235 } 236 237 } 238 | Popular Tags |