1 17 package org.eclipse.emf.edit.tree.provider; 18 19 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import org.eclipse.emf.common.notify.AdapterFactory; 26 import org.eclipse.emf.common.notify.Notification; 27 import org.eclipse.emf.common.notify.Notifier; 28 import org.eclipse.emf.ecore.EObject; 29 import org.eclipse.emf.edit.provider.AdapterFactoryItemDelegator; 30 import org.eclipse.emf.edit.provider.ComposeableAdapterFactory; 31 import org.eclipse.emf.edit.provider.IChangeNotifier; 32 import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; 33 import org.eclipse.emf.edit.provider.IItemLabelProvider; 34 import org.eclipse.emf.edit.provider.IItemPropertyDescriptor; 35 import org.eclipse.emf.edit.provider.IItemPropertySource; 36 import org.eclipse.emf.edit.provider.INotifyChangedListener; 37 import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; 38 import org.eclipse.emf.edit.provider.ITreeItemContentProvider; 39 import org.eclipse.emf.edit.provider.ItemPropertyDescriptorDecorator; 40 import org.eclipse.emf.edit.provider.ItemProviderAdapter; 41 import org.eclipse.emf.edit.provider.ViewerNotification; 42 import org.eclipse.emf.edit.tree.TreeNode; 43 import org.eclipse.emf.edit.tree.TreePackage; 44 45 46 51 public class TreeNodeItemProvider 52 extends ItemProviderAdapter 53 implements 54 IEditingDomainItemProvider, 55 INotifyChangedListener, 56 IStructuredItemContentProvider, 57 ITreeItemContentProvider, 58 IItemLabelProvider, 59 IItemPropertySource 60 { 61 protected IChangeNotifier delegateItemProvider; 62 63 protected AdapterFactoryItemDelegator itemDelegator; 64 65 68 public TreeNodeItemProvider(AdapterFactory adapterFactory) 69 { 70 super(adapterFactory); 71 itemDelegator = new AdapterFactoryItemDelegator(((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory()); 72 } 73 74 public void setTarget(Notifier target) 75 { 76 super.setTarget(target); 77 if (target == null) 78 { 79 if (delegateItemProvider != null) 80 { 81 delegateItemProvider.removeListener(this); 82 delegateItemProvider = null; 83 } 84 } 85 else 86 { 87 TreeNode treeNode = (TreeNode)target; 88 delegateItemProvider = 89 (IChangeNotifier) 90 ((ComposeableAdapterFactory)adapterFactory).getRootAdapterFactory().adapt(treeNode.getData(), IItemLabelProvider.class); 91 delegateItemProvider.addListener(this); 92 } 93 } 94 95 98 public List getPropertyDescriptors(Object object) 99 { 100 TreeNode treeNode = (TreeNode)object; 101 itemPropertyDescriptors = new ArrayList (); 102 for (Iterator propertyDescriptors = itemDelegator.getPropertyDescriptors(treeNode.getData()).iterator(); 103 propertyDescriptors.hasNext(); ) 104 { 105 IItemPropertyDescriptor itemPropertyDescriptor = (IItemPropertyDescriptor)propertyDescriptors.next(); 106 itemPropertyDescriptors.add(new ItemPropertyDescriptorDecorator(treeNode.getData(), itemPropertyDescriptor)); 107 } 108 return itemPropertyDescriptors; 109 } 110 111 118 public Collection getChildrenFeatures(Object object) 119 { 120 if (childrenFeatures == null) 121 { 122 super.getChildrenFeatures(object); 123 childrenFeatures.add(TreePackage.eINSTANCE.getTreeNode_Children()); 124 } 125 return childrenFeatures; 126 } 127 128 131 public Object getParent(Object object) 132 { 133 return ((EObject)object).eContainer(); 134 } 135 136 public Object getImage(Object object) 137 { 138 TreeNode treeNode = ((TreeNode)object); 139 return itemDelegator.getImage(treeNode.getData()); 140 } 141 142 public String getText(Object object) 143 { 144 TreeNode treeNode = ((TreeNode)object); 145 return itemDelegator.getText(treeNode.getData()); 146 } 147 148 154 public void notifyChanged(final Notification notification) 155 { 156 fireNotifyChanged(ViewerNotification.wrapNotification(notification, target)); 157 } 158 159 164 protected void collectNewChildDescriptors(Collection newChildDescriptors, Object object) 165 { 166 169 } 170 171 public void dispose() 172 { 173 super.dispose(); 174 if (delegateItemProvider != null) 175 { 176 delegateItemProvider.removeListener(this); 177 } 178 } 179 } 180 | Popular Tags |