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 flags changed for a primitive and have not been covered in an other event 053 */ 054 PRIMITIVE_FLAGS_CHANGED, 055 } 056 057 /** 058 * The dataset from which the event came from. 059 */ 060 protected final DataSet dataSet; 061 062 /** 063 * Constructs a new {@code AbstractDatasetChangedEvent}. 064 * @param dataSet the dataset from which the event came from 065 */ 066 protected AbstractDatasetChangedEvent(DataSet dataSet) { 067 this.dataSet = dataSet; 068 } 069 070 /** 071 * Calls the appropriate method of the listener for this event. 072 * @param listener dataset listener to notify about this event 073 */ 074 public abstract void fire(DataSetListener listener); 075 076 /** 077 * Returns list of primitives modified by this event. 078 * <br> 079 * <strong>WARNING</strong> This value might be incorrect in case 080 * of {@link DataChangedEvent}. It returns all primitives in the dataset 081 * when this method is called (live list), not list of primitives when 082 * the event was created 083 * @return List of modified primitives 084 */ 085 public abstract Collection<? extends OsmPrimitive> getPrimitives(); 086 087 /** 088 * Returns the dataset from which the event came from. 089 * @return the dataset from which the event came from 090 */ 091 public DataSet getDataset() { 092 return dataSet; 093 } 094 095 /** 096 * Returns the type of dataset changed event. 097 * @return the type of dataset changed event 098 */ 099 public abstract DatasetEventType getType(); 100 101 @Override 102 public String toString() { 103 return getType().toString(); 104 } 105 106}