1 17 package org.eclipse.emf.edit.provider; 18 19 20 import java.util.Collections ; 21 import java.util.List ; 22 23 import org.eclipse.emf.common.command.Command; 24 import org.eclipse.emf.common.notify.AdapterFactory; 25 import org.eclipse.emf.common.util.ResourceLocator; 26 import org.eclipse.emf.ecore.EAttribute; 27 import org.eclipse.emf.ecore.EDataType; 28 import org.eclipse.emf.ecore.EObject; 29 import org.eclipse.emf.ecore.util.EcoreUtil; 30 import org.eclipse.emf.edit.command.CommandParameter; 31 import org.eclipse.emf.edit.command.CopyCommand; 32 import org.eclipse.emf.edit.command.SetCommand; 33 import org.eclipse.emf.edit.domain.EditingDomain; 34 35 36 39 public class AttributeValueWrapperItemProvider extends WrapperItemProvider 40 implements 41 IStructuredItemContentProvider, 42 ITreeItemContentProvider, 43 IItemLabelProvider, 44 IItemPropertySource, 45 IEditingDomainItemProvider 46 { 47 50 protected ResourceLocator resourceLocator; 51 52 55 protected List propertyDescriptors; 56 57 60 public AttributeValueWrapperItemProvider(Object value, EObject owner, EAttribute attribute, AdapterFactory adapterFactory, ResourceLocator resourceLocator) 61 { 62 super(value, owner, attribute, CommandParameter.NO_INDEX, adapterFactory); 63 this.resourceLocator = resourceLocator; 64 } 65 66 69 public AttributeValueWrapperItemProvider(Object value, EObject owner, EAttribute attribute, int index, AdapterFactory adapterFactory, ResourceLocator resourceLocator) 70 { 71 super(value, owner, attribute, index, adapterFactory); 72 this.resourceLocator = resourceLocator; 73 } 74 75 82 public AttributeValueWrapperItemProvider(Object value, EObject owner, EAttribute attribute, AdapterFactory adapterFactory) 83 { 84 this(value, owner, attribute, adapterFactory, null); 85 } 86 87 94 public AttributeValueWrapperItemProvider(Object value, EObject owner, EAttribute attribute, int index, AdapterFactory adapterFactory) 95 { 96 this(value, owner, attribute, index, adapterFactory, null); 97 } 98 99 102 public String getText(Object object) 103 { 104 return value != null ? EcoreUtil.convertToString(((EAttribute)feature).getEAttributeType(), value) : "null"; 105 } 106 107 110 public List getPropertyDescriptors(Object object) 111 { 112 if (propertyDescriptors == null) 113 { 114 propertyDescriptors = Collections.singletonList(new WrapperItemPropertyDescriptor(resourceLocator, feature)); 115 } 116 return propertyDescriptors; 117 } 118 119 122 protected Command createSetCommand(EditingDomain domain, Object owner, Object feature, Object value, int index) 123 { 124 return new ReplacementAffectedObjectCommand(SetCommand.create(domain, this.owner, this.feature, value, this.index)); 125 } 126 127 131 protected Command createCopyCommand(EditingDomain domain, Object owner, CopyCommand.Helper helper) 132 { 133 return new SimpleCopyCommand(domain) 134 { 135 public IWrapperItemProvider copy() 136 { 137 Object valueCopy = null; 138 139 if (value != null) 140 { 141 EDataType dataType = ((EAttribute)feature).getEAttributeType(); 142 String serialization = EcoreUtil.convertToString(dataType, value); 143 valueCopy = EcoreUtil.createFromString(dataType, serialization); 144 if (serialization == value && serialization == valueCopy) 145 { 146 valueCopy = new String ((String )value); 147 } 148 } 149 return new AttributeValueWrapperItemProvider( 150 valueCopy, (EObject)AttributeValueWrapperItemProvider.this.owner, (EAttribute)feature, index, adapterFactory); 151 } 152 }; 153 } 154 } 155 | Popular Tags |