001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.internal;
010:
011: import org.eclipse.emf.common.notify.Notification;
012: import org.eclipse.emf.common.notify.impl.AdapterImpl;
013:
014: /**
015: * An Adapter for ContextModels that allow other objects to listen to state changes that occur in
016: * the ContextModel and its Layers.
017: * <p>
018: * See the example for how to use an this class as a listener.
019: * </p>
020: * <p>
021: * Responsibilities:
022: * <ul>
023: * <li>Listener for ContextModel state events</li>
024: * <li>Call methods when an event occurs that can be mapped to one of the methods.
025: * <p>
026: * For example if a layer is added the layerAdded method is called.
027: * </p>
028: * </li>
029: * </ul>
030: * </p>
031: * <p>
032: * The following example adds an observer/listener that only reacts to single layer added events...
033: * <b>Note that multiple layers being added are ignored </b>. Example Use:
034: *
035: * <pre><code>
036: * contextModel.eAdapters().add(new ContextModelListenerAdapter(){
037: * protected void layerAdded( Notification msg ) {
038: * //Enter behaviour
039: * }
040: * });
041: * </code></pre>
042: *
043: * </p>
044: * <p>
045: * The following example adds an observer/listener that is notified of style change events that
046: * occur in the layers contained by the ContextModel.
047: * </p>
048: * <p>
049: * Note: getDeepAdapters() adds the listener/adapter/observer to the context model and all of the
050: * children. Children that are later added or removed automatically have the deep adapter added or
051: * removed.
052: * </p>
053: * <p>
054: * Example Use:
055: *
056: * <pre><code>
057: * contextModel.getDeepAdapters().add(new ContextModelListenerAdapter(){
058: * protected void styleChanged( Notification msg ) {
059: * //Enter behaviour
060: * }
061: * });
062: * </code></pre>
063: *
064: * </p>
065: *
066: * @author jeichar
067: * @since 0.3
068: */
069:
070: public class ContextModelListenerAdapter extends AdapterImpl {
071:
072: /**
073: * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
074: */
075: public void notifyChanged(Notification msg) {
076: if (msg.getNotifier() instanceof ContextModel) {
077: switch (msg.getFeatureID(ContextModel.class)) {
078: case ProjectPackage.CONTEXT_MODEL__LAYERS: {
079: switch (msg.getEventType()) {
080: case Notification.ADD: {
081: layerAdded(msg);
082: break;
083: }// case
084: case Notification.ADD_MANY: {
085: manyLayersAdded(msg);
086: break;
087: }// case
088: case Notification.REMOVE: {
089: layerRemoved(msg);
090: break;
091: }// case
092: case Notification.REMOVE_MANY: {
093: manyLayersRemoved(msg);
094: break;
095: }// case
096: case Notification.MOVE: {
097: zorderChanged(msg);
098: break;
099: }// case
100: }// switch
101: break;
102: }// case
103: }// switch
104: }// if
105: else if (msg.getNotifier() instanceof Layer) {
106: switch (msg.getFeatureID(Layer.class)) {
107: case ProjectPackage.LAYER__GLYPH: {
108: glyphChanged(msg);
109: break;
110: }// case
111: case ProjectPackage.LAYER__STYLE_BLACKBOARD: { // FIXME: Changed from LAYER__STYLE
112: styleChanged(msg);
113: break;
114: }// case
115: case ProjectPackage.LAYER__VISIBLE: {
116: visibilityChanged(msg);
117: break;
118: }// case
119: }// switch
120:
121: }// else
122: }
123:
124: /**
125: * This method is called when a single layer has been added.
126: * <p>
127: * msg.getNewValue() will return the layer added
128: * </p>
129: *
130: * @param msg The Notification object with all the information about the event.
131: */
132: protected void layerAdded(Notification msg) {
133: // do nothing
134: }
135:
136: /**
137: * This method is called when more than on layer has been added.
138: * <li>msg.getNewValue() will return a list of the layers added</li>
139: * <li>msg.getNotifier() will return the ContextModel</li>
140: * </ul>
141: * </p>
142: *
143: * @param msg The Notification object with all the information about the event.
144: */
145: protected void manyLayersAdded(Notification msg) {
146: // do nothing
147: }
148:
149: /**
150: * This method is called when a single layer has been removed.
151: * <p>
152: * <ul>
153: * <li>msg.getOldValue() will return the layer removed</li>
154: * <li>msg.getNotifier() will return the ContextModel</li>
155: * </ul>
156: * </p>
157: *
158: * @param msg The Notification object with all the information about the event.
159: */
160: protected void layerRemoved(Notification msg) {
161: // do nothing
162: }
163:
164: /**
165: * This method is called when a multiple layers have been removed.
166: * <p>
167: * <ul>
168: * <li>msg.getOldValue() will return a list with the layers removed</li>
169: * <li>msg.getNotifier() will return the ContextModel</li>
170: * </ul>
171: * </p>
172: *
173: * @param msg The Notification object with all the information about the event.
174: */
175: protected void manyLayersRemoved(Notification msg) {
176: // do nothing
177: }
178:
179: /**
180: * The order of the layer in the list has been changed. Therefore the zorder of the layer has
181: * been changed.
182: * <p>
183: * The closer to the beginning of the list the later the object will be rendered. In other words
184: * the list is in reverse zorder
185: * </p>
186: * <p>
187: * <ul>
188: * <li>msg.getNewIntValue() will return the new position of the layer</li>
189: * <li>msg.getOldIntValue() will return the old position of the layer</li>
190: * <li>msg.getNotifier() will return the ContextModel</li>
191: * </ul>
192: * </p>
193: *
194: * @param msg The Notification object with all the information about the event.
195: */
196: protected void zorderChanged(Notification msg) {
197: // do nothing
198: }
199:
200: /**
201: * Called when the Glyph of a layer has been changed.
202: * <p>
203: * <ul>
204: * <li>msg.getNewValue() will return the new Glyph</li>
205: * <li>msg.getOldValue() will return the old Glyph</li>
206: * <li>msg.getNotifier() will return the Layer</li>
207: * </ul>
208: * </p>
209: *
210: * @param msg The Notification object with all the information about the event.
211: */
212: protected void glyphChanged(Notification msg) {
213: // do nothing
214: }
215:
216: /**
217: * Called when the Style of a layer has been changed.
218: * <p>
219: * <ul>
220: * <li>msg.getNewValue() will return the new Style</li>
221: * <li>msg.getOldValue() will return the old Style</li>
222: * <li>msg.getNotifier() will return the Layer</li>
223: * </ul>
224: * </p>
225: *
226: * @param msg The Notification object with all the information about the event.
227: */
228: protected void styleChanged(Notification msg) {
229: // do nothing
230: }
231:
232: /**
233: * Called when the Visibility of a layer has been changed.
234: * <p>
235: * <ul>
236: * <li>msg.getNewValue() will return the new Visibility</li>
237: * <li>msg.getOldValue() will return the old Visibility</li>
238: * <li>msg.getNotifier() will return the Layer</li>
239: * </ul>
240: * </p>
241: *
242: * @param msg The Notification object with all the information about the event.
243: */
244: protected void visibilityChanged(Notification msg) {
245: // do nothing
246: }
247: }
|