001: /**
002: * <copyright>
003: * </copyright>
004: *
005: * $Id: PageItemProvider.java 23333 2006-12-08 19:40:41Z jeichar $
006: */package net.refractions.udig.printing.model.provider;
007:
008: import java.util.ArrayList;
009: import java.util.Collection;
010: import java.util.Iterator;
011: import java.util.List;
012:
013: import net.refractions.udig.printing.model.Box;
014: import net.refractions.udig.printing.model.BoxPrinter;
015: import net.refractions.udig.printing.model.ModelFactory;
016: import net.refractions.udig.printing.model.ModelPackage;
017: import net.refractions.udig.printing.model.Page;
018: import net.refractions.udig.printing.model.impl.MapBoxPrinter;
019: import net.refractions.udig.project.internal.Map;
020: import net.refractions.udig.project.internal.ProjectPackage;
021:
022: import org.eclipse.emf.common.notify.AdapterFactory;
023: import org.eclipse.emf.common.notify.Notification;
024: import org.eclipse.emf.common.util.ResourceLocator;
025: import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
026: import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
027: import org.eclipse.emf.edit.provider.IItemLabelProvider;
028: import org.eclipse.emf.edit.provider.IItemPropertySource;
029: import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
030: import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
031: import org.eclipse.emf.edit.provider.ItemPropertyDescriptor;
032: import org.eclipse.emf.edit.provider.ViewerNotification;
033:
034: /**
035: * This is the item provider adapter for a {@link net.refractions.udig.printing.model.Page} object.
036: * <!-- begin-user-doc -->
037: * <!-- end-user-doc -->
038: * @generated
039: */
040: public class PageItemProvider extends ElementItemProvider implements
041: IEditingDomainItemProvider, IStructuredItemContentProvider,
042: ITreeItemContentProvider, IItemLabelProvider,
043: IItemPropertySource {
044:
045: protected List children = null;;
046:
047: /*
048: * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object)
049: */
050: public Collection getChildren(Object object) {
051: if (children == null) {
052: children = new ArrayList();
053:
054: Page page = (Page) object;
055: Iterator iter = page.getBoxes().iterator();
056: while (iter.hasNext()) {
057: BoxPrinter box = ((Box) iter.next()).getBoxPrinter();
058: if (box instanceof MapBoxPrinter) {
059: Map map = ((MapBoxPrinter) box).getMap();
060: // children.add(new MapItemProvider(adapterFactory, map));
061: children.add(map);
062: }
063: }
064:
065: }
066: return children;
067: }
068:
069: /**
070: * This constructs an instance from a factory and a notifier.
071: * <!-- begin-user-doc -->
072: * <!-- end-user-doc -->
073: * @generated
074: */
075: public PageItemProvider(AdapterFactory adapterFactory) {
076: super (adapterFactory);
077: }
078:
079: /**
080: * This returns the property descriptors for the adapted class.
081: * <!-- begin-user-doc -->
082: * <!-- end-user-doc -->
083: * @generated
084: */
085: public List getPropertyDescriptors(Object object) {
086: if (itemPropertyDescriptors == null) {
087: super .getPropertyDescriptors(object);
088:
089: addNamePropertyDescriptor(object);
090: }
091: return itemPropertyDescriptors;
092: }
093:
094: /**
095: * This adds a property descriptor for the Name feature.
096: * <!-- begin-user-doc -->
097: * <!-- end-user-doc -->
098: * @generated
099: */
100: protected void addNamePropertyDescriptor(Object object) {
101: itemPropertyDescriptors
102: .add(createItemPropertyDescriptor(
103: ((ComposeableAdapterFactory) adapterFactory)
104: .getRootAdapterFactory(),
105: getResourceLocator(),
106: getString("_UI_ProjectElement_name_feature"), //$NON-NLS-1$
107: getString(
108: "_UI_PropertyDescriptor_description", "_UI_ProjectElement_name_feature", "_UI_ProjectElement_type"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
109: ProjectPackage.eINSTANCE
110: .getProjectElement_Name(), true,
111: ItemPropertyDescriptor.GENERIC_VALUE_IMAGE,
112: null, null));
113: }
114:
115: /**
116: * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate feature for an
117: * {@link org.eclipse.emf.edit.command.AddCommand}, {@link org.eclipse.emf.edit.command.RemoveCommand} or
118: * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}.
119: * <!-- begin-user-doc -->
120: * <!-- end-user-doc -->
121: * @generated NOT
122: */
123: public Collection getChildrenFeatures(Object object) {
124: if (childrenFeatures == null) {
125: super .getChildrenFeatures(object);
126: childrenFeatures
127: .add(ModelPackage.eINSTANCE.getPage_Boxes());
128: }
129: return childrenFeatures;
130: }
131:
132: /**
133: * This returns Page.gif.
134: * <!-- begin-user-doc -->
135: * <!-- end-user-doc -->
136: * @generated
137: */
138: public Object getImage(Object object) {
139: return getResourceLocator().getImage("full/obj16/Page"); //$NON-NLS-1$
140: }
141:
142: /**
143: * This returns the label text for the adapted class.
144: * <!-- begin-user-doc -->
145: * <!-- end-user-doc -->
146: * @generated NOT
147: */
148: public String getText(Object object) {
149: String label = ((Page) object).getName();
150: return label == null || label.length() == 0 ? getString("_UI_Page_type") : //$NON-NLS-1$
151: label;
152: }
153:
154: /**
155: * This handles model notifications by calling {@link #updateChildren} to update any cached
156: * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
157: * <!-- begin-user-doc -->
158: * <!-- end-user-doc -->
159: * @generated
160: */
161: public void notifyChanged(Notification notification) {
162: updateChildren(notification);
163:
164: switch (notification.getFeatureID(Page.class)) {
165: case ModelPackage.PAGE__NAME:
166: fireNotifyChanged(new ViewerNotification(notification,
167: notification.getNotifier(), false, true));
168: return;
169: case ModelPackage.PAGE__BOXES:
170: fireNotifyChanged(new ViewerNotification(notification,
171: notification.getNotifier(), true, false));
172: return;
173: }
174: super .notifyChanged(notification);
175: }
176:
177: /**
178: * This adds to the collection of {@link org.eclipse.emf.edit.command.CommandParameter}s
179: * describing all of the children that can be created under this object.
180: * <!-- begin-user-doc -->
181: * <!-- end-user-doc -->
182: * @generated
183: */
184: protected void collectNewChildDescriptors(
185: Collection newChildDescriptors, Object object) {
186: super .collectNewChildDescriptors(newChildDescriptors, object);
187:
188: newChildDescriptors.add(createChildParameter(
189: ModelPackage.eINSTANCE.getPage_Boxes(),
190: ModelFactory.eINSTANCE.createBox()));
191:
192: newChildDescriptors.add(createChildParameter(
193: ModelPackage.eINSTANCE.getPage_Boxes(),
194: ModelFactory.eINSTANCE.createDecoratorBox()));
195: }
196:
197: /**
198: * Return the resource locator for this item provider's resources.
199: * <!-- begin-user-doc -->
200: * <!-- end-user-doc -->
201: * @generated
202: */
203: public ResourceLocator getResourceLocator() {
204: return PageEditPlugin.INSTANCE;
205: }
206:
207: }
|