FieldItemProvider.java
Go to the documentation of this file.
00001 
00007 package org.best_of_robotics.model.datatypes.provider;
00008 
00009 
00010 import java.util.Collection;
00011 import java.util.List;
00012 
00013 import org.best_of_robotics.model.datatypes.ComplexType;
00014 import org.best_of_robotics.model.datatypes.DataType;
00015 import org.best_of_robotics.model.datatypes.DatatypesPackage;
00016 import org.best_of_robotics.model.datatypes.Field;
00017 import org.best_of_robotics.model.datatypes.SimpleType;
00018 import org.eclipse.emf.common.notify.AdapterFactory;
00019 import org.eclipse.emf.common.notify.Notification;
00020 import org.eclipse.emf.common.util.ResourceLocator;
00021 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
00022 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
00023 import org.eclipse.emf.edit.provider.IItemLabelProvider;
00024 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
00025 import org.eclipse.emf.edit.provider.IItemPropertySource;
00026 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
00027 import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
00028 import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
00029 import org.eclipse.emf.edit.provider.ItemProviderAdapter;
00030 import org.eclipse.emf.edit.provider.ViewerNotification;
00031 
00038 public class FieldItemProvider
00039         extends ItemProviderAdapter
00040         implements
00041                 IEditingDomainItemProvider,
00042                 IStructuredItemContentProvider,
00043                 ITreeItemContentProvider,
00044                 IItemLabelProvider,
00045                 IItemPropertySource {
00052         public FieldItemProvider(AdapterFactory adapterFactory) {
00053                 super(adapterFactory);
00054         }
00055 
00062         @Override
00063         public List<IItemPropertyDescriptor> getPropertyDescriptors(Object object) {
00064                 if (itemPropertyDescriptors == null) {
00065                         super.getPropertyDescriptors(object);
00066 
00067                         addNamePropertyDescriptor(object);
00068                         addTypePropertyDescriptor(object);
00069                         addDescriptionPropertyDescriptor(object);
00070                         addMeasureUnitPropertyDescriptor(object);
00071                 }
00072                 return itemPropertyDescriptors;
00073         }
00074 
00081         protected void addNamePropertyDescriptor(Object object) {
00082                 itemPropertyDescriptors.add
00083                         (createItemPropertyDescriptor
00084                                 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00085                                  getResourceLocator(),
00086                                  getString("_UI_Field_name_feature"),
00087                                  getString("_UI_PropertyDescriptor_description", "_UI_Field_name_feature", "_UI_Field_type"),
00088                                  DatatypesPackage.Literals.FIELD__NAME,
00089                                  true,
00090                                  false,
00091                                  false,
00092                                  ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00093                                  null,
00094                                  null));
00095         }
00096 
00103         protected void addTypePropertyDescriptor(Object object) {
00104                 itemPropertyDescriptors.add
00105                         (createItemPropertyDescriptor
00106                                 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00107                                  getResourceLocator(),
00108                                  getString("_UI_Field_type_feature"),
00109                                  getString("_UI_PropertyDescriptor_description", "_UI_Field_type_feature", "_UI_Field_type"),
00110                                  DatatypesPackage.Literals.FIELD__TYPE,
00111                                  true,
00112                                  false,
00113                                  true,
00114                                  null,
00115                                  null,
00116                                  null));
00117         }
00118 
00125         protected void addDescriptionPropertyDescriptor(Object object) {
00126                 itemPropertyDescriptors.add
00127                         (createItemPropertyDescriptor
00128                                 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00129                                  getResourceLocator(),
00130                                  getString("_UI_Field_description_feature"),
00131                                  getString("_UI_PropertyDescriptor_description", "_UI_Field_description_feature", "_UI_Field_type"),
00132                                  DatatypesPackage.Literals.FIELD__DESCRIPTION,
00133                                  true,
00134                                  false,
00135                                  false,
00136                                  ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00137                                  null,
00138                                  null));
00139         }
00140 
00147         protected void addMeasureUnitPropertyDescriptor(Object object) {
00148                 itemPropertyDescriptors.add
00149                         (createItemPropertyDescriptor
00150                                 (((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory(),
00151                                  getResourceLocator(),
00152                                  getString("_UI_Field_measureUnit_feature"),
00153                                  getString("_UI_PropertyDescriptor_description", "_UI_Field_measureUnit_feature", "_UI_Field_type"),
00154                                  DatatypesPackage.Literals.FIELD__MEASURE_UNIT,
00155                                  true,
00156                                  false,
00157                                  false,
00158                                  ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
00159                                  null,
00160                                  null));
00161         }
00162 
00169         @Override
00170         public Object getImage(Object object) {
00171                 return overlayImage(object, getResourceLocator().getImage("full/obj16/Field"));
00172         }
00173 
00181         @Override
00182         public String getText(Object object) {
00183                 String label = ((Field)object).getName();
00184                 DataType fieldType = ((Field)object).getType();
00185                 if(fieldType == null){
00186                         return getString("_UI_Field_type");
00187                 }
00188                 if(fieldType instanceof ComplexType){
00189                         label = ((ComplexType) fieldType).getLabel() + " " + label;
00190                 }else{
00191                         label = ((SimpleType) fieldType).getName() + " " + label;
00192                 }
00193                 
00194                 return label == null || label.length() == 0 ?
00195                         getString("_UI_Field_type") :
00196                                 label + " - " + getString("_UI_Field_type");
00197         }
00198 
00206         @Override
00207         public void notifyChanged(Notification notification) {
00208                 updateChildren(notification);
00209 
00210                 switch (notification.getFeatureID(Field.class)) {
00211                         case DatatypesPackage.FIELD__NAME:
00212                         case DatatypesPackage.FIELD__DESCRIPTION:
00213                         case DatatypesPackage.FIELD__MEASURE_UNIT:
00214                                 fireNotifyChanged(new ViewerNotification(notification, notification.getNotifier(), false, true));
00215                                 return;
00216                 }
00217                 super.notifyChanged(notification);
00218         }
00219 
00227         @Override
00228         protected void collectNewChildDescriptors(Collection<Object> newChildDescriptors, Object object) {
00229                 super.collectNewChildDescriptors(newChildDescriptors, object);
00230         }
00231 
00238         @Override
00239         public ResourceLocator getResourceLocator() {
00240                 return DataTypesEditPlugin.INSTANCE;
00241         }
00242 
00243 }


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:34