Changeset 2881 in josm for trunk


Ignore:
Timestamp:
2010-01-23T14:24:03+01:00 (10 years ago)
Author:
jttt
Message:

Fixed #4412 after confict management: selecting a relation does not highlight all members

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

Legend:

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

    r2512 r2881  
    1818 */
    1919public class  Conflict<T extends OsmPrimitive> {
    20     private T my;
    21     private T their;
     20    private final T my;
     21    private final T their;
    2222
    2323    public Conflict(T my, T their) {
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java

    r2846 r2881  
    1212import java.beans.PropertyChangeEvent;
    1313import java.beans.PropertyChangeListener;
    14 import java.text.MessageFormat;
    1514import java.util.ArrayList;
    1615import java.util.HashMap;
     16import java.util.List;
    1717import java.util.Observable;
    1818
     
    229229
    230230    protected void copyToTop(ListRole role, int []rows) {
    231         if (rows == null || rows.length == 0)
    232             return;
    233         for (int i = rows.length - 1; i >= 0; i--) {
    234             int row = rows[i];
    235             T n = entries.get(role).get(row);
    236             entries.get(MERGED_ENTRIES).add(0, cloneEntryForMergedList(n));
    237         }
     231        copy(role, rows, 0);
    238232        fireModelDataChanged();
    239233        mergedEntriesSelectionModel.setSelectionInterval(0, rows.length -1);
     
    272266
    273267    public void copyToEnd(ListRole source, int [] rows) {
    274         if (rows == null || rows.length == 0)
    275             return;
    276         ArrayList<T> mergedEntries = getMergedEntries();
    277         for (int row : rows) {
    278             T n = entries.get(source).get(row);
    279             mergedEntries.add(cloneEntryForMergedList(n));
    280         }
     268        copy(source, rows, getMergedEntriesSize());
    281269        fireModelDataChanged();
    282         mergedEntriesSelectionModel.setSelectionInterval(mergedEntries.size()-rows.length, mergedEntries.size() -1);
     270        mergedEntriesSelectionModel.setSelectionInterval(getMergedEntriesSize()-rows.length, getMergedEntriesSize() -1);
    283271
    284272    }
     
    306294    }
    307295
     296    private void copy(ListRole sourceRole, int[] rows, int position) {
     297        List<T> newItems = new ArrayList<T>(rows.length);
     298        List<T> source = entries.get(sourceRole);
     299        for (int row: rows) {
     300            T clone = cloneEntryForMergedList(source.get(row));
     301            if (clone != null) {
     302                newItems.add(clone);
     303            }
     304        }
     305        getMergedEntries().addAll(position, newItems);
     306    }
     307
    308308    /**
    309309     * Copies the nodes given by indices in rows from the list of  nodes <code>source</code> to the
     
    317317     */
    318318    protected void copyBeforeCurrent(ListRole source, int [] rows, int current) {
    319         if (rows == null || rows.length == 0)
    320             return;
    321         ArrayList<T> mergedEntries = getMergedEntries();
    322         if (current < 0 || current >= mergedEntries.size())
    323             throw new IllegalArgumentException(MessageFormat.format("Parameter current out of range. Got {0}.", current));
    324         for (int i=rows.length -1; i>=0; i--) {
    325             int row = rows[i];
    326             T n = entries.get(source).get(row);
    327             mergedEntries.add(current, cloneEntryForMergedList(n));
    328         }
     319        copy(source, rows, current);
    329320        fireModelDataChanged();
    330321        mergedEntriesSelectionModel.setSelectionInterval(current, current + rows.length-1);
     
    368359     */
    369360    protected void copyAfterCurrent(ListRole source, int [] rows, int current) {
    370         if (rows == null || rows.length == 0)
    371             return;
    372         ArrayList<T> mergedEntries = getMergedEntries();
    373 
    374         if (current < 0 || current >= mergedEntries.size())
    375             throw new IllegalArgumentException(MessageFormat.format("Parameter current out of range. Got {0}.", current));
    376         if (current == mergedEntries.size() -1) {
    377             copyToEnd(source, rows);
    378         } else {
    379             for (int i=rows.length -1; i>=0; i--) {
    380                 int row = rows[i];
    381                 T n = entries.get(source).get(row);
    382                 mergedEntries.add(current+1, cloneEntryForMergedList(n));
    383             }
    384         }
     361        copy(source, rows, current + 1);
    385362        fireModelDataChanged();
    386363        mergedEntriesSelectionModel.setSelectionInterval(current+1, current + rows.length-1);
     
    551528        }
    552529
    553         public ListMergeModel getListMergeModel() {
     530        public ListMergeModel<T> getListMergeModel() {
    554531            return ListMergeModel.this;
    555532        }
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberListMergeModel.java

    r2846 r2881  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.ArrayList;
    7 import java.util.logging.Logger;
     6import java.util.List;
    87
     8import javax.swing.JOptionPane;
    99import javax.swing.table.DefaultTableModel;
    1010
    1111import org.openstreetmap.josm.command.RelationMemberConflictResolverCommand;
     12import org.openstreetmap.josm.data.osm.DataSet;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1214import org.openstreetmap.josm.data.osm.Relation;
    1315import org.openstreetmap.josm.data.osm.RelationMember;
     16import org.openstreetmap.josm.gui.DefaultNameFormatter;
    1417import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
    1518import org.openstreetmap.josm.gui.conflict.pair.ListRole;
     
    2023 */
    2124public class RelationMemberListMergeModel extends ListMergeModel<RelationMember>{
     25    //private static final Logger logger = Logger.getLogger(RelationMemberListMergeModel.class.getName());
    2226
    23     private static final Logger logger = Logger.getLogger(RelationMemberListMergeModel.class.getName());
     27    private DataSet myDataset;
    2428
    2529    @Override
     
    6569     */
    6670    public void populate(Relation my, Relation their) {
     71        this.myDataset = my.getDataSet();
     72
    6773        CheckParameterUtil.ensureParameterNotNull(my, "my");
    6874        CheckParameterUtil.ensureParameterNotNull(their, "their");
     
    9298    @Override
    9399    protected RelationMember cloneEntryForMergedList(RelationMember entry) {
    94         return new 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 removed.",
     104                            primitive.getDisplayName(DefaultNameFormatter.getInstance())));
     105            return null;
     106        } else
     107            return new RelationMember(entry.getRole(), primitive);
    95108    }
    96109
     
    110123        if (! isFrozen())
    111124            throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Cannot build resolution command"));
    112         ArrayList<RelationMember> entries = getMergedEntries();
     125        List<RelationMember> entries = getMergedEntries();
    113126        return new RelationMemberConflictResolverCommand(my, their, entries);
    114127    }
Note: See TracChangeset for help on using the changeset viewer.