1 17 package org.eclipse.emf.codegen.ecore.genmodel.provider; 18 19 20 import java.util.Arrays ; 21 import java.util.List ; 22 23 import org.eclipse.emf.codegen.ecore.genmodel.GenBase; 24 import org.eclipse.emf.codegen.ecore.genmodel.GenModel; 25 import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; 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.EStructuralFeature; 30 import org.eclipse.emf.edit.provider.ComposedImage; 31 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 32 import org.eclipse.emf.edit.provider.IItemLabelProvider; 33 import org.eclipse.emf.edit.provider.IItemPropertySource; 34 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 35 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 36 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor; 37 import org.eclipse.emf.edit.provider.ItemProviderAdapter; 38 39 40 46 public class GenBaseItemProvider 47 extends ItemProviderAdapter 48 implements 49 IEditingDomainItemProvider, IStructuredItemContentProvider, ITreeItemContentProvider, IItemLabelProvider, IItemPropertySource 50 { 51 public static class UnderlayedImage extends ComposedImage 52 { 53 public UnderlayedImage(Object imageDescriptor) 54 { 55 super 56 (Arrays.asList 57 (new Object [] 58 { GenModelEditPlugin.INSTANCE.getImage("full/obj16/Underlay"), 59 imageDescriptor 60 })); 61 } 62 63 public UnderlayedImage(Object imageDescriptor, Object multiplicity) 64 { 65 super 66 (Arrays.asList 67 (new Object [] 68 { GenModelEditPlugin.INSTANCE.getImage("full/obj16/Underlay"), 69 imageDescriptor, 70 multiplicity 71 })); 72 } 73 74 public List getDrawPoints(Size size) 75 { 76 List result = super.getDrawPoints(size); 77 if (result.size() > 2) 78 { 79 ((Point)result.get(1)).y = -2; 80 } 81 return result; 82 } 83 } 84 85 91 public GenBaseItemProvider(AdapterFactory adapterFactory) 92 { 93 super(adapterFactory); 94 } 95 96 102 public List getPropertyDescriptors(Object object) 103 { 104 if (itemPropertyDescriptors == null) 105 { 106 super.getPropertyDescriptors(object); 107 108 } 109 return itemPropertyDescriptors; 110 } 111 112 118 public String getText(Object object) 119 { 120 return getString("_UI_GenBase_type"); 121 } 122 123 130 public void notifyChanged(Notification notification) 131 { 132 updateChildren(notification); 133 super.notifyChanged(notification); 134 } 135 136 142 public ResourceLocator getResourceLocator() 143 { 144 return GenModelEditPlugin.INSTANCE; 145 } 146 147 150 protected static boolean canEdit(Object object) 151 { 152 if (object instanceof GenModel) return true; 153 if (object instanceof GenPackage) 154 { 155 return ((GenPackage)object).canGenerate(); 156 } 157 if (object instanceof GenBase) 158 { 159 return canEdit(((GenBase)object).eContainer()); 160 } 161 return false; 162 } 163 164 protected ItemPropertyDescriptor createItemPropertyDescriptor(AdapterFactory adapterFactory, ResourceLocator resourceLocator, String displayName, String description, EStructuralFeature feature, boolean isSettable, Object staticImage, String category, String [] filterFlags) 165 { 166 return new GenItemPropertyDescriptor( 167 adapterFactory, 168 displayName, 169 description, 170 feature, 171 isSettable, 172 staticImage, 173 category); 174 } 175 176 180 protected static class GenItemPropertyDescriptor 181 extends ItemPropertyDescriptor 182 { 183 public GenItemPropertyDescriptor( 184 AdapterFactory adapterFactory, String displayName, String description, 185 EStructuralFeature feature, boolean isSettable, String category) 186 { 187 super(adapterFactory, displayName, description, feature, isSettable, 188 category); 189 190 } 191 192 public GenItemPropertyDescriptor( 193 AdapterFactory adapterFactory, String displayName, String description, 194 EStructuralFeature feature, boolean isSettable, Object staticImage, 195 String category) 196 { 197 super(adapterFactory, displayName, description, feature, isSettable, 198 staticImage, category); 199 } 200 201 public boolean canSetProperty(Object object) 202 { 203 return isSettable && canEdit(object); 204 } 205 } 206 207 } 208 | Popular Tags |