001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.osm.event;
003
004import java.util.Collection;
005
006import org.openstreetmap.josm.data.osm.DataSet;
007import org.openstreetmap.josm.data.osm.OsmPrimitive;
008
009/**
010 * Base class of all dataset change events.
011 * @since 2622
012 */
013public abstract class AbstractDatasetChangedEvent {
014
015    /**
016     * Type of dataset changed event, returned by {@link AbstractDatasetChangedEvent#getType}.
017     */
018    public enum DatasetEventType {
019        /**
020         * A combination of multiple events
021         */
022        DATA_CHANGED,
023        /**
024         * The lat/lon coordinates of a node have changed.
025         */
026        NODE_MOVED,
027        /**
028         * Primitives have been added to this dataset
029         */
030        PRIMITIVES_ADDED,
031        /**
032         * Primitives have been removed from this dataset
033         */
034        PRIMITIVES_REMOVED,
035        /**
036         * The members of a relation have changed
037         */
038        RELATION_MEMBERS_CHANGED,
039        /**
040         * The tags of a primitve have changed
041         */
042        TAGS_CHANGED,
043        /**
044         * The nodes of a way or their order has changed
045         */
046        WAY_NODES_CHANGED,
047        /**
048         * The changeset id changed for a list of primitives
049         */
050        CHANGESET_ID_CHANGED,
051        /**
052         * The filtered state changed for a list of primitives
053         */
054        FILTERS_CHANGED,
055        /**
056         * The flags changed for a primitive and have not been covered in an other event
057         */
058        PRIMITIVE_FLAGS_CHANGED,
059    }
060
061    /**
062     * The dataset from which the event came from.
063     */
064    protected final DataSet dataSet;
065
066    /**
067     * Constructs a new {@code AbstractDatasetChangedEvent}.
068     * @param dataSet the dataset from which the event came from
069     */
070    protected AbstractDatasetChangedEvent(DataSet dataSet) {
071        this.dataSet = dataSet;
072    }
073
074    /**
075     * Calls the appropriate method of the listener for this event.
076     * @param listener dataset listener to notify about this event
077     */
078    public abstract void fire(DataSetListener listener);
079
080    /**
081     * Returns list of primitives modified by this event.
082     * <br>
083     * <strong>WARNING</strong> This value might be incorrect in case
084     * of {@link DataChangedEvent}. It returns all primitives in the dataset
085     * when this method is called (live list), not list of primitives when
086     * the event was created
087     * @return List of modified primitives
088     */
089    public abstract Collection<? extends OsmPrimitive> getPrimitives();
090
091    /**
092     * Returns the dataset from which the event came from.
093     * @return the dataset from which the event came from
094     */
095    public DataSet getDataset() {
096        return dataSet;
097    }
098
099    /**
100     * Returns the type of dataset changed event.
101     * @return the type of dataset changed event
102     */
103    public abstract DatasetEventType getType();
104
105    @Override
106    public String toString() {
107        return getType().toString();
108    }
109
110}