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;
010:
011: import java.util.EventObject;
012:
013: import net.refractions.udig.project.internal.ProjectPackage;
014:
015: import org.eclipse.emf.common.notify.Notification;
016: import org.geotools.data.FeatureEvent;
017:
018: /**
019: * An event indicating a change in a layer.
020: *
021: * @author Jesse
022: * @since 1.0.0
023: */
024: public class LayerEvent extends EventObject {
025: /** <code>serialVersionUID</code> field */
026: private static final long serialVersionUID = 3762247556733614390L;
027:
028: public static enum EventType {
029: /**
030: * Indicates the Filter of the layer has changed.
031: */
032: FILTER,
033: /**
034: * Indicates a Resource has changed
035: */
036: RESOURCE,
037: /**
038: * Indicates the style changed
039: */
040: STYLE,
041: /**
042: * Indicates the zorder of the layer has changed
043: */
044: ZORDER,
045: /**
046: * Indicates the visibility of the layer has changed
047: */
048: VISIBILITY,
049: /**
050: * Indicates the name of the layer has changed
051: */
052: NAME,
053: /**
054: * Indicates "something" changed. Inspect the layer. Shouldn't be used often.
055: */
056: ALL,
057: /**
058: * Indicates that and edit event has occurred
059: * OldValue will always be null.
060: * NewValue will always be a {@link FeatureEvent}
061: */
062: EDIT_EVENT
063: }
064:
065: /** Type of event, FILTER, RESOURCE, ALL or STYLE */
066: private EventType type;
067:
068: /**
069: * Previous value of the changed field, may be null if unknown.
070: * <p>
071: * Remeber the event is issued after the change has taken place
072: * </p>
073: */
074: private Object oldValue;
075:
076: /**
077: * Current value of changed field, may be null if unknown.
078: * <p>
079: * Remeber the event is issued after the change has taken place
080: * </p>
081: */
082: private Object newValue;
083:
084: // API enum?
085: /** Indicate a change has occured the the filter (defines the selection) */
086: public static final int FILTER = ProjectPackage.LAYER__FILTER;
087:
088: /** Resource used by the layer has changed */
089: public static final int RESOURCE = ProjectPackage.LAYER__GEO_RESOURCE;
090:
091: /** Indicates something somewhere is different - make no assumptions */
092: public static final int ALL = Notification.NO_FEATURE_ID;
093:
094: /**
095: * The contents of the blackboard have changed.
096: */
097: public static final int STYLE = ProjectPackage.LAYER__STYLE_BLACKBOARD;
098:
099: /**
100: * Creates a new event for the given source, indicating that all labels provided by the source
101: * are no longer valid and should be updated.
102: *
103: * @param source the label provider
104: */
105: public LayerEvent(ILayer layer) {
106: this (layer, EventType.ALL);
107: }
108:
109: /** Creates a specific kind of layer event, FILTER, RESOURCE, ALL or STYLE */
110: public LayerEvent(ILayer layer, EventType type) {
111: this (layer, type, null, null);
112: }
113:
114: /** Creates a specific kind of layer event, FILTER, RESOURCE, ALL or STYLE */
115: public LayerEvent(ILayer layer, EventType type, Object oldValue,
116: Object newValue) {
117: super (layer);
118: this .type = type;
119: this .oldValue = oldValue;
120: this .newValue = newValue;
121: }
122:
123: /**
124: * The layer being modified.
125: *
126: * @return The modified layer
127: * @see ILayer
128: */
129: public ILayer getSource() {
130: return (ILayer) super .getSource();
131: }
132:
133: /**
134: * @return the newValue.
135: */
136: public Object getNewValue() {
137: return newValue;
138: }
139:
140: /**
141: * @param newValue The newValue to set.
142: */
143: public void setNewValue(Object newValue) {
144: this .newValue = newValue;
145: }
146:
147: /**
148: * @return Returns the oldValue.
149: */
150: public Object getOldValue() {
151: return oldValue;
152: }
153:
154: /**
155: * @param oldValue The oldValue to set.
156: */
157: public void setOldValue(Object oldValue) {
158: this .oldValue = oldValue;
159: }
160:
161: /**
162: * Type of event
163: */
164: public EventType getType() {
165: return type;
166: }
167:
168: /**
169: * Type of event
170: *
171: * @see EventType
172: * @param type
173: */
174: public void setType(EventType type) {
175: this.type = type;
176: }
177: }
|