001: /**
002: * <copyright>
003: * </copyright>
004: *
005: * $Id: ContextModelItemProvider.java 24145 2007-02-01 18:03:34Z jeichar $
006: */package net.refractions.udig.project.internal.provider;
007:
008: import java.util.Collection;
009: import java.util.List;
010:
011: import net.refractions.udig.project.internal.ContextModel;
012: import net.refractions.udig.project.internal.ProjectPackage;
013:
014: import org.eclipse.emf.common.notify.AdapterFactory;
015: import org.eclipse.emf.common.notify.Notification;
016: import org.eclipse.emf.common.util.EList;
017: import org.eclipse.emf.common.util.ResourceLocator;
018: import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
019: import org.eclipse.emf.edit.provider.IItemLabelProvider;
020: import org.eclipse.emf.edit.provider.IItemPropertySource;
021: import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
022: import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
023: import org.eclipse.emf.edit.provider.ItemProviderAdapter;
024: import org.eclipse.emf.edit.provider.ViewerNotification;
025:
026: /**
027: * This is the item provider adapter for a
028: * {@link net.refractions.udig.project.internal.ContextModel} object. <!-- begin-user-doc --> <!--
029: * end-user-doc -->
030: *
031: * @generated
032: */
033: public class ContextModelItemProvider extends ItemProviderAdapter
034: implements IEditingDomainItemProvider,
035: IStructuredItemContentProvider, ITreeItemContentProvider,
036: IItemLabelProvider, IItemPropertySource {
037: /**
038: * <!-- begin-user-doc --> <!-- end-user-doc -->
039: *
040: * @generated
041: */
042: public static final String copyright = "uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004, Refractions Research Inc. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; version 2.1 of the License. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details."; //$NON-NLS-1$
043:
044: /**
045: * This constructs an instance from a factory and a notifier. <!-- begin-user-doc --> <!--
046: * end-user-doc -->
047: *
048: * @generated
049: */
050: public ContextModelItemProvider(AdapterFactory adapterFactory) {
051: super (adapterFactory);
052: }
053:
054: /**
055: * This returns the property descriptors for the adapted class. <!-- begin-user-doc --> <!--
056: * end-user-doc -->
057: *
058: * @generated NOT
059: */
060: public List getPropertyDescriptors(Object object) {
061: if (itemPropertyDescriptors == null) {
062: super .getPropertyDescriptors(object);
063:
064: }
065: return itemPropertyDescriptors;
066: }
067:
068: /**
069: * This specifies how to implement {@link #getChildren} and is used to deduce an appropriate
070: * feature for an {@link org.eclipse.emf.edit.command.AddCommand},
071: * {@link org.eclipse.emf.edit.command.RemoveCommand} or
072: * {@link org.eclipse.emf.edit.command.MoveCommand} in {@link #createCommand}. <!--
073: * begin-user-doc --> <!-- end-user-doc -->
074: *
075: * @generated
076: */
077: public Collection getChildrenFeatures(Object object) {
078: if (childrenFeatures == null) {
079: super .getChildrenFeatures(object);
080: childrenFeatures.add(ProjectPackage.eINSTANCE
081: .getContextModel_Layers());
082: }
083: return childrenFeatures;
084: }
085:
086: /**
087: * This returns ContextModel.gif. <!-- begin-user-doc --> <!-- end-user-doc -->
088: *
089: * @generated
090: */
091: public Object getImage(Object object) {
092: return getResourceLocator().getImage("full/obj16/ContextModel"); //$NON-NLS-1$
093: }
094:
095: /**
096: * This returns the label text for the adapted class. <!-- begin-user-doc --> <!-- end-user-doc
097: * -->
098: *
099: * @generated NOT
100: */
101: public String getText(Object object) {
102: return "Context Model";
103: }
104:
105: @Override
106: protected void updateChildren(Notification notification) {
107: super .updateChildren(notification);
108: switch (notification.getEventType()) {
109: case Notification.ADD:
110: case Notification.ADD_MANY:
111: case Notification.REMOVE:
112: case Notification.REMOVE_MANY:
113: case Notification.MOVE:
114:
115: Object notifier = notification.getNotifier();
116: if (notifier instanceof ContextModel) {
117: if (notification.getFeatureID(ContextModel.class) != ProjectPackage.CONTEXT_MODEL__LAYERS)
118: return;
119:
120: // we need to tell the map item provider that the layers have changed.
121: ContextModel model = (ContextModel) notifier;
122: EList adapters = model.getMap().eAdapters();
123: for (Object object : adapters) {
124: if (object instanceof MapItemProvider) {
125: MapItemProvider mapItemProvider = ((MapItemProvider) object);
126: // mapItemProvider.updateChildList(notification);
127: mapItemProvider.getChildFetcher()
128: .notifyChanged();
129: break;
130: }
131: }
132: } else {
133: ProjectEditPlugin
134: .log(
135: "notifier is not a contextModel as expect. It is a " + notifier.getClass().getSimpleName(), null); //$NON-NLS-1$
136: }
137: break;
138:
139: default:
140: break;
141: }
142: }
143:
144: /**
145: * This handles model notifications by calling {@link #updateChildren} to update any cached
146: * children and by creating a viewer notification, which it passes to {@link #fireNotifyChanged}.
147: * <!-- begin-user-doc --> <!-- end-user-doc -->
148: *
149: * @generated
150: */
151: public void notifyChanged(Notification notification) {
152: updateChildren(notification);
153:
154: switch (notification.getFeatureID(ContextModel.class)) {
155: case ProjectPackage.CONTEXT_MODEL__LAYERS:
156: fireNotifyChanged(new ViewerNotification(notification,
157: ((ContextModel) notification.getNotifier())
158: .getMap(), true, false));
159: return;
160: }
161: super .notifyChanged(notification);
162: }
163:
164: /**
165: * Return the resource locator for this item provider's resources. <!-- begin-user-doc --> <!--
166: * end-user-doc -->
167: *
168: * @generated
169: */
170: public ResourceLocator getResourceLocator() {
171: return ProjectEditPlugin.INSTANCE;
172: }
173:
174: }
|