1 17 package org.eclipse.emf.mapping.provider; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.List ; 24 25 import org.eclipse.emf.common.command.Command; 26 import org.eclipse.emf.common.command.UnexecutableCommand; 27 import org.eclipse.emf.common.notify.AdapterFactory; 28 import org.eclipse.emf.common.notify.Notification; 29 import org.eclipse.emf.common.notify.NotificationWrapper; 30 import org.eclipse.emf.ecore.EObject; 31 import org.eclipse.emf.edit.command.CommandParameter; 32 import org.eclipse.emf.edit.domain.EditingDomain; 33 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 34 import org.eclipse.emf.edit.provider.IChangeNotifier; 35 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 36 import org.eclipse.emf.edit.provider.IItemLabelProvider; 37 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; 38 import org.eclipse.emf.edit.provider.IItemPropertySource; 39 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 40 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 41 import org.eclipse.emf.edit.provider.ItemPropertyDescriptorDecorator; 42 import org.eclipse.emf.edit.provider.ItemProviderDecorator; 43 import org.eclipse.emf.mapping.MappedObjectState; 44 import org.eclipse.emf.mapping.Mapping; 45 46 47 50 public class MappedObjectItemProvider 51 extends 52 ItemProviderDecorator 53 implements 54 IEditingDomainItemProvider, 55 IStructuredItemContentProvider, 56 ITreeItemContentProvider, 57 IItemLabelProvider, 58 IItemPropertySource 59 { 60 protected Mapping mapping; 61 protected EObject mappedObject; 62 protected MappedObjectState mappedObjectState; 63 64 67 public MappedObjectItemProvider(AdapterFactory adapterFactory, EObject mappedObject, Mapping mapping) 68 { 69 super(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory()); 70 setDecoratedItemProvider((IChangeNotifier)this.adapterFactory.adapt(mappedObject, IItemLabelProvider.class)); 71 this.mappedObject = mappedObject; 72 this.mapping = mapping; 73 74 mappedObjectState = mapping.getMappingRoot().getMappedObjectState(mappedObject); 75 mappedObjectState.addListener(this); 76 } 77 78 81 public Object getParent(Object object) 82 { 83 return mapping; 88 } 89 90 public Collection getElements(Object object) 91 { 92 return Collections.EMPTY_LIST; 93 } 94 95 public Collection getChildren(Object object) 96 { 97 return Collections.EMPTY_LIST; 98 } 99 100 public boolean hasChildren(Object object) 101 { 102 return false; 103 } 104 105 public Object getImage(Object object) 106 { 107 return super.getImage(mappedObject); 108 } 109 110 public String getText(Object object) 111 { 112 return super.getText(mappedObject); 113 } 114 115 public List getPropertyDescriptors(Object object) 116 { 117 List descriptors = super.getPropertyDescriptors(mappedObject); 118 119 List result = new ArrayList (); 120 for (int i = 0; i < descriptors.size(); ++i) 121 { 122 result.add(new ItemPropertyDescriptorDecorator(mappedObject, (IItemPropertyDescriptor)descriptors.get(i))); 123 } 124 return result; 125 } 126 127 public IItemPropertyDescriptor getPropertyDescriptor(Object object, Object propertyId) 128 { 129 IItemPropertyDescriptor descriptor = super.getPropertyDescriptor(mappedObject, propertyId); 130 if (descriptor != null) 131 { 132 return new ItemPropertyDescriptorDecorator(mappedObject, descriptor); 133 } 134 return null; 135 } 136 137 140 public void notifyChanged(Notification msg) 141 { 142 if (msg.getFeature() == null) 143 { 144 Notification notification = new NotificationWrapper(this, msg); 145 super.notifyChanged(notification); 146 } 147 else 148 { 149 super.notifyChanged(msg); 150 } 151 } 152 153 public Command createCommand(Object object, EditingDomain editingDomain, Class commandClass, CommandParameter commandParameter) 154 { 155 if (commandClass == org.eclipse.emf.edit.command.DragAndDropCommand.class) 156 { 157 return super.createCommand(object, editingDomain, commandClass, commandParameter); 158 } 159 else 160 { 161 return UnexecutableCommand.INSTANCE; 162 } 163 } 164 165 public EObject getMappedObject() 166 { 167 return mappedObject; 168 } 169 170 public Mapping getMapping() 171 { 172 return mapping; 173 } 174 175 public void dispose() 176 { 177 mappedObjectState.removeListener(this); 178 super.dispose(); 179 } 180 } 181 | Popular Tags |