Changeset 2623 in josm for trunk


Ignore:
Timestamp:
2009-12-12T21:25:10+01:00 (12 years ago)
Author:
jttt
Message:

Fire primitivesAdded event after also after primitive was downloaded (incomplete set to false). Remove DataChangeListener from RelationListDialog (should not be necessary anymore, was there only for catching incomplete state changes)

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2622 r2623  
    203203        allPrimitives.add(primitive);
    204204        primitive.setDataset(this);
    205         firePrimitivesAdded(Collections.singletonList(primitive));
     205        firePrimitivesAdded(Collections.singletonList(primitive), false);
    206206    }
    207207
     
    246246        primitive.setDataset(null);
    247247        errors.remove(primitive);
    248         firePrimitivesRemoved(Collections.singletonList(primitive));
     248        firePrimitivesRemoved(Collections.singletonList(primitive), false);
    249249    }
    250250
     
    837837    }
    838838
    839     void firePrimitivesAdded(Collection<? extends OsmPrimitive> added) {
    840         fireEvent(new PrimitivesAddedEvent(this, added));
    841     }
    842 
    843     void firePrimitivesRemoved(Collection<? extends OsmPrimitive> removed) {
    844         fireEvent(new PrimitivesRemovedEvent(this, removed));
     839    void firePrimitivesAdded(Collection<? extends OsmPrimitive> added, boolean wasIncomplete) {
     840        fireEvent(new PrimitivesAddedEvent(this, added, wasIncomplete));
     841    }
     842
     843    void firePrimitivesRemoved(Collection<? extends OsmPrimitive> removed, boolean wasComplete) {
     844        fireEvent(new PrimitivesRemovedEvent(this, removed, wasComplete));
    845845    }
    846846
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r2620 r2623  
    564564        if (dataSet != null) {
    565565            if (deleted) {
    566                 dataSet.firePrimitivesRemoved(Collections.singleton(this));
     566                dataSet.firePrimitivesRemoved(Collections.singleton(this), false);
    567567            } else {
    568                 dataSet.firePrimitivesAdded(Collections.singleton(this));
     568                dataSet.firePrimitivesAdded(Collections.singleton(this), false);
    569569            }
    570570        }
     
    956956     */
    957957    public void cloneFrom(OsmPrimitive other) {
     958        if (id != other.id && dataSet != null)
     959            throw new DataIntegrityProblemException("Osm id cannot be changed after primitive was added to the dataset");
    958960        setKeys(other.getKeys());
    959961        id = other.id;
     
    12101212
    12111213    private void setIncomplete(boolean incomplete) {
     1214        if (dataSet != null && incomplete != this.incomplete) {
     1215            if (incomplete) {
     1216                dataSet.firePrimitivesRemoved(Collections.singletonList(this), true);
     1217            } else {
     1218                dataSet.firePrimitivesAdded(Collections.singletonList(this), true);
     1219            }
     1220        }
    12121221        this.incomplete = incomplete;
    12131222    }
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r2620 r2623  
    217217        result.append(" version=");
    218218        result.append(getVersion());
     219        result.append(" ");
     220        result.append(getFlagsAsString());
    219221        result.append(" [");
    220222        for (RelationMember rm:getMembers()) {
  • trunk/src/org/openstreetmap/josm/data/osm/event/PrimitivesAddedEvent.java

    r2622 r2623  
    1313
    1414    private final List<? extends OsmPrimitive> primitives;
     15    private final boolean wasIncomplete;
    1516
    16     public PrimitivesAddedEvent(DataSet dataSet, Collection<? extends OsmPrimitive> primitives) {
     17    public PrimitivesAddedEvent(DataSet dataSet, Collection<? extends OsmPrimitive> primitives, boolean wasIncomplete) {
    1718        super(dataSet);
    1819        this.primitives = Collections.unmodifiableList(new ArrayList<OsmPrimitive>(primitives));
     20        this.wasIncomplete = wasIncomplete;
    1921    }
    2022
     
    2426    }
    2527
     28    @Override
    2629    public List<? extends OsmPrimitive> getPrimitives() {
    2730        return primitives;
    2831    }
    2932
     33    /**
     34     *
     35     * @return True if primitive was in dataset before (so it's not really added), but it was incomplete
     36     */
     37    public boolean wasIncomplete() {
     38        return wasIncomplete;
     39    }
     40
    3041}
  • trunk/src/org/openstreetmap/josm/data/osm/event/PrimitivesRemovedEvent.java

    r2622 r2623  
    1313
    1414    private final List<? extends OsmPrimitive> primitives;
     15    private final boolean wasComplete;
    1516
    16     public PrimitivesRemovedEvent(DataSet dataSet, Collection<? extends OsmPrimitive> primitives) {
     17    public PrimitivesRemovedEvent(DataSet dataSet, Collection<? extends OsmPrimitive> primitives, boolean wasComplete) {
    1718        super(dataSet);
    1819        this.primitives = Collections.unmodifiableList(new ArrayList<OsmPrimitive>(primitives));
     20        this.wasComplete = wasComplete;
    1921    }
    2022
     
    2426    }
    2527
     28    @Override
    2629    public List<? extends OsmPrimitive> getPrimitives() {
    2730        return primitives;
    2831    }
    2932
     33    /**
     34     *
     35     * @return True if primitive wasn't really removed from the dataset, it only become incomplete again
     36     */
     37    public boolean wasComplete() {
     38        return wasComplete;
     39    }
     40
    3041}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r2622 r2623  
    5252import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    5353import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    54 import org.openstreetmap.josm.gui.layer.DataChangeListener;
    5554import org.openstreetmap.josm.gui.layer.Layer;
    5655import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    6665 * objects are visible on the map and can be selected there. Relations are not.
    6766 */
    68 public class RelationListDialog extends ToggleDialog implements MapView.LayerChangeListener, DataSetListener, DataChangeListener {
     67public class RelationListDialog extends ToggleDialog implements DataSetListener {
    6968    //private static final Logger logger = Logger.getLogger(RelationListDialog.class.getName());
    7069
     
    143142
    144143    @Override public void showNotify() {
    145         MapView.addLayerChangeListener(this);
    146144        MapView.addLayerChangeListener(newAction);
    147145        DatasetEventManager.getInstance().addDatasetListener(this, true);
    148         dataChanged(Main.main.getEditLayer());
     146        dataChanged(null);
    149147    }
    150148
    151149    @Override public void hideNotify() {
    152         MapView.removeLayerChangeListener(this);
    153150        MapView.removeLayerChangeListener(newAction);
    154151        DatasetEventManager.getInstance().removeDatasetListener(this);
     
    521518        }
    522519
     520        public synchronized void sort() {
     521            Collections.sort(
     522                    relations,
     523                    new Comparator<Relation>() {
     524                        NameFormatter formatter = DefaultNameFormatter.getInstance();
     525
     526                        public int compare(Relation r1, Relation r2) {
     527                            return r1.getDisplayName(formatter).compareTo(r2.getDisplayName(formatter));
     528                        }
     529                    }
     530            );
     531        }
     532
     533        private boolean isValid(Relation r) {
     534            return !r.isDeleted() && r.isVisible() && !r.isIncomplete();
     535        }
     536
    523537        public synchronized void setRelations(Collection<Relation> relations) {
    524538            List<Relation> sel =  getSelectedRelations();
     
    531545            }
    532546            for (Relation r: relations) {
    533                 if (! r.isDeleted() && r.isVisible() && !r.isIncomplete()) {
     547                if (isValid(r)) {
    534548                    this.relations.add(r);
    535549                }
     
    538552            fireIntervalAdded(this, 0, getSize());
    539553            setSelectedRelations(sel);
    540         }
    541 
    542         public synchronized void sort() {
    543             Collections.sort(
    544                     relations,
    545                     new Comparator<Relation>() {
    546                         NameFormatter formatter = DefaultNameFormatter.getInstance();
    547 
    548                         public int compare(Relation r1, Relation r2) {
    549                             return r1.getDisplayName(formatter).compareTo(r2.getDisplayName(formatter));
    550                         }
    551                     }
    552             );
    553554        }
    554555
     
    561562         */
    562563        public synchronized void addRelations(Collection<? extends OsmPrimitive> addedPrimitives) {
    563             if (addedPrimitives == null || addedPrimitives.isEmpty()) return;
    564564            boolean added = false;
    565565            for (OsmPrimitive p: addedPrimitives) {
     
    567567                    continue;
    568568                }
    569                 if (relations.contains(p)) {
     569
     570                Relation r = (Relation)p;
     571                if (relations.contains(r)) {
    570572                    continue;
    571573                }
    572                 relations.add((Relation)p);
    573                 added = true;
     574                if (isValid(r)) {
     575                    relations.add(r);
     576                    added = true;
     577                }
    574578            }
    575579            if (added) {
     
    695699
    696700    /* ---------------------------------------------------------------------------------- */
    697     /* LayerChangeListener                                                                */
    698     /* ---------------------------------------------------------------------------------- */
    699     public void activeLayerChange(Layer a, Layer b) {
    700         if (a != null && a instanceof OsmDataLayer) {
    701             ((OsmDataLayer)a).listenerDataChanged.remove(this);
    702         }
    703         if (b != null && b instanceof OsmDataLayer) {
    704             ((OsmDataLayer)b).listenerDataChanged.add(this);
    705         }
    706 
    707     }
    708     public void layerRemoved(Layer a) {/* irrelevant in this context */}
    709     public void layerAdded(Layer a) {/* irrelevant in this context */}
    710 
    711     /* ---------------------------------------------------------------------------------- */
    712701    /* DataSetListener                                                                    */
    713702    /* ---------------------------------------------------------------------------------- */
     
    751740        }
    752741    }
    753 
    754     /* ---------------------------------------------------------------------------------- */
    755     /* DataSetListener                                                                    */
    756     /* ---------------------------------------------------------------------------------- */
    757     public void dataChanged(OsmDataLayer l) {
    758         if (l != null && l == Main.main.getEditLayer()) {
    759             initFromLayer(l);
    760         }
    761     }
    762742}
Note: See TracChangeset for help on using the changeset viewer.