KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > tree > provider > TreeNodeItemProvider


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: TreeNodeItemProvider.java,v 1.4 2005/06/08 06:17:06 nickb Exp $
16  */

17 package org.eclipse.emf.edit.tree.provider;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
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 /**
47  * This is the item provider adpater for a {@link org.eclipse.emf.edit.tree.TreeNode} object.
48  *
49  * @generated modifiable
50  */

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   /**
66    * This constructs an instance from a factory and a notifier.
67    */

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   /**
96    * This returns the property descriptors for the adapted class.
97    */

98   public List JavaDoc getPropertyDescriptors(Object JavaDoc object)
99   {
100     TreeNode treeNode = (TreeNode)object;
101     itemPropertyDescriptors = new ArrayList JavaDoc();
102     for (Iterator JavaDoc 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   /**
112    * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
113    * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
114    * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
115    * <!-- begin-user-doc -->
116    * <!-- end-user-doc -->
117    */

118   public Collection JavaDoc getChildrenFeatures(Object JavaDoc 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   /**
129    * This returns the parent of the TreeNode.
130    */

131   public Object JavaDoc getParent(Object JavaDoc object)
132   {
133     return ((EObject)object).eContainer();
134   }
135
136   public Object JavaDoc getImage(Object JavaDoc object)
137   {
138     TreeNode treeNode = ((TreeNode)object);
139     return itemDelegator.getImage(treeNode.getData());
140   }
141
142   public String JavaDoc getText(Object JavaDoc object)
143   {
144     TreeNode treeNode = ((TreeNode)object);
145     return itemDelegator.getText(treeNode.getData());
146   }
147
148   /**
149    * This handles notification by calling {@link #fireNotifyChanged fireNotifyChanged}.
150    * This will also be called by the {@link #delegateItemProvider} when it normally fires a notification to its adapter factory;
151    * the listener method is hooked up in {@link #setTarget setTarget}. Notifications are wrapped to look like they originate from
152    * the target.
153    */

154   public void notifyChanged(final Notification notification)
155   {
156     fireNotifyChanged(ViewerNotification.wrapNotification(notification, target));
157   }
158
159   /**
160    * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s
161    * describing all of the children that can be created under this object.
162    * @generated NOT
163    */

164   protected void collectNewChildDescriptors(Collection JavaDoc newChildDescriptors, Object JavaDoc object)
165   {
166 /*
167     super.collectNewChildDescriptors(newChildDescriptors, object);
168 */

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