Changeset 2949 in josm for trunk/src


Ignore:
Timestamp:
2010-02-07T22:54:58+01:00 (10 years ago)
Author:
jttt
Message:

Show only one message box in conflicts dialog when multiple members are deleted, use clone method for copyAll method

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

    r2915 r2949  
    3434 */
    3535public class ConflictCollection implements Iterable<Conflict<?>>{
    36     private ArrayList<Conflict<?>> conflicts;
     36    private final List<Conflict<?>> conflicts;
    3737    private CopyOnWriteArrayList<IConflictListener> listeners;
    3838
     
    313313        return size() == 0;
    314314    }
     315
     316    @Override
     317    public String toString() {
     318        return conflicts.toString();
     319    }
    315320}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java

    r2945 r2949  
    2020import javax.swing.ComboBoxModel;
    2121import javax.swing.DefaultListSelectionModel;
     22import javax.swing.JOptionPane;
    2223import javax.swing.table.DefaultTableModel;
    2324import javax.swing.table.TableModel;
     25
     26import org.openstreetmap.josm.data.osm.OsmPrimitive;
     27import org.openstreetmap.josm.data.osm.PrimitiveId;
    2428
    2529/**
     
    6064    public static final String FROZEN_PROP = ListMergeModel.class.getName() + ".frozen";
    6165
     66    private static final int MAX_DELETED_PRIMITIVE_IN_DIALOG = 5;
     67
    6268    protected HashMap<ListRole, ArrayList<T>> entries;
    6369
     
    104110     */
    105111    protected abstract void setValueAt(DefaultTableModel model, Object value, int row, int col);
     112
     113    /**
     114     *
     115     * @param entry
     116     * @return Primitive from my dataset referenced by entry
     117     */
     118    protected abstract OsmPrimitive getMyPrimitive(T entry);
    106119
    107120    protected void buildMyEntriesTableModel() {
     
    300313        List<T> newItems = new ArrayList<T>(rows.length);
    301314        List<T> source = entries.get(sourceRole);
     315        List<PrimitiveId> deletedIds = new ArrayList<PrimitiveId>();
    302316        for (int row: rows) {
    303             T clone = cloneEntryForMergedList(source.get(row));
    304             if (clone != null) {
     317            T entry = source.get(row);
     318            OsmPrimitive primitive = getMyPrimitive(entry);
     319            if (!primitive.isDeleted()) {
     320                T clone = cloneEntryForMergedList(entry);
    305321                newItems.add(clone);
     322            } else {
     323                deletedIds.add(primitive.getPrimitiveId());
    306324            }
    307325        }
    308326        getMergedEntries().addAll(position, newItems);
    309327        fireModelDataChanged();
     328        if (!deletedIds.isEmpty()) {
     329            List<String> items = new ArrayList<String>();
     330            for (int i=0; i<Math.min(MAX_DELETED_PRIMITIVE_IN_DIALOG, deletedIds.size()); i++) {
     331                items.add(deletedIds.get(i).toString());
     332            }
     333            if (deletedIds.size() > MAX_DELETED_PRIMITIVE_IN_DIALOG) {
     334                items.add(tr("{0} more...", deletedIds.size() - MAX_DELETED_PRIMITIVE_IN_DIALOG));
     335            }
     336            JOptionPane.showMessageDialog(null, tr("Following primitives could not be added because they are deleted: {0}", items));
     337        }
    310338    }
    311339
    312340    public void copyAll(ListRole source) {
    313341        getMergedEntries().clear();
    314         getMergedEntries().addAll(entries.get(source));
    315         fireModelDataChanged();
     342
     343        int[] rows = new int[entries.get(source).size()];
     344        for (int i=0; i<rows.length; i++) {
     345            rows[i] = i;
     346        }
     347        copy(source, rows, 0);
    316348    }
    317349
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModel.java

    r2882 r2949  
    66import java.util.ArrayList;
    77
    8 import javax.swing.JOptionPane;
    98import javax.swing.table.DefaultTableModel;
    109
     
    1211import org.openstreetmap.josm.data.osm.DataSet;
    1312import org.openstreetmap.josm.data.osm.Node;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1414import org.openstreetmap.josm.data.osm.Way;
    15 import org.openstreetmap.josm.gui.DefaultNameFormatter;
    1615import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
    1716import org.openstreetmap.josm.gui.conflict.pair.ListRole;
     
    8988    @Override
    9089    protected Node cloneEntryForMergedList(Node entry) {
    91         Node node = (Node) myDataset.getPrimitiveById(entry);
    92         if (node.isDeleted()) {
    93             JOptionPane.showMessageDialog(null, tr("Node {0} cannot be added to the way because it was deleted", node.getDisplayName(DefaultNameFormatter.getInstance())));
    94             return null;
    95         } else
    96             return node;
     90        return (Node) getMyPrimitive(entry);
    9791    }
     92
     93    @Override
     94    protected OsmPrimitive getMyPrimitive(Node entry) {
     95        return myDataset.getPrimitiveById(entry);
     96    }
     97
    9898}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberListMergeModel.java

    r2882 r2949  
    66import java.util.List;
    77
    8 import javax.swing.JOptionPane;
    98import javax.swing.table.DefaultTableModel;
    109
     
    1413import org.openstreetmap.josm.data.osm.Relation;
    1514import org.openstreetmap.josm.data.osm.RelationMember;
    16 import org.openstreetmap.josm.gui.DefaultNameFormatter;
    1715import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
    1816import org.openstreetmap.josm.gui.conflict.pair.ListRole;
     
    9896    @Override
    9997    protected RelationMember cloneEntryForMergedList(RelationMember entry) {
    100         OsmPrimitive primitive = myDataset.getPrimitiveById(entry.getMember());
    101         if (primitive.isDeleted()) {
    102             JOptionPane.showMessageDialog(null,
    103                     tr("Primitive {0} cannot be added to the relation because it was deleted.",
    104                             primitive.getDisplayName(DefaultNameFormatter.getInstance())));
    105             return null;
    106         } else
    107             return new RelationMember(entry.getRole(), primitive);
     98        OsmPrimitive primitive = getMyPrimitive(entry);
     99        return new RelationMember(entry.getRole(), primitive);
     100    }
     101
     102    @Override
     103    protected OsmPrimitive getMyPrimitive(RelationMember entry) {
     104        return myDataset.getPrimitiveById(entry.getMember());
    108105    }
    109106
Note: See TracChangeset for help on using the changeset viewer.