Changeset 11318 in josm for trunk


Ignore:
Timestamp:
2016-11-26T21:28:20+01:00 (8 years ago)
Author:
Don-vip
Message:

refactor conflict classes

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r10413 r11318  
    1111
    1212import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.data.conflict.Conflict;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.data.osm.Relation;
     
    1920/**
    2021 * Represents the resolution of conflicts in the member list of two {@link Relation}s.
    21  *
     22 * @since 1631
    2223 */
    2324public class RelationMemberConflictResolverCommand extends ConflictResolveCommand {
    24     /** my relation */
    25     private final Relation my;
    26     /** their relation */
    27     private final Relation their;
    28     /** the list of merged nodes. This becomes the list of news of my way after the
    29      *  command is executed
    30      */
     25    /** the conflict to resolve */
     26    private final Conflict<Relation> conflict;
     27    /** the list of merged nodes. This becomes the list of news of my way after the command is executed */
    3128    private final List<RelationMember> mergedMembers;
    3229
    3330    /**
    34      *
    35      * @param my my relation
    36      * @param their their relation
     31     * Constructs a new {@code RelationMemberConflictResolverCommand}.
     32     * @param conflict the conflict to resolve
    3733     * @param mergedMembers the list of merged relation members
    3834     */
    39     public RelationMemberConflictResolverCommand(Relation my, Relation their, List<RelationMember> mergedMembers) {
    40         this.my = my;
    41         this.their = their;
     35    @SuppressWarnings("unchecked")
     36    public RelationMemberConflictResolverCommand(Conflict<? extends OsmPrimitive> conflict, List<RelationMember> mergedMembers) {
     37        this.conflict = (Conflict<Relation>) conflict;
    4238        this.mergedMembers = mergedMembers;
    4339    }
     
    4541    @Override
    4642    public String getDescriptionText() {
    47         return tr("Resolve conflicts in member list of relation {0}", my.getId());
     43        return tr("Resolve conflicts in member list of relation {0}", conflict.getMy().getId());
    4844    }
    4945
     
    6157        // replace the list of members of 'my' relation by the list of merged members
    6258        //
    63         my.setMembers(mergedMembers);
     59        conflict.getMy().setMembers(mergedMembers);
    6460
    6561        return true;
     
    6965    public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted,
    7066            Collection<OsmPrimitive> added) {
    71         modified.add(my);
     67        modified.add(conflict.getMy());
    7268    }
    7369
     
    9288        // restore a conflict if necessary
    9389        //
    94         if (!editLayer.getConflicts().hasConflictForMy(my)) {
    95             editLayer.getConflicts().add(my, their);
     90        if (!editLayer.getConflicts().hasConflictForMy(conflict.getMy())) {
     91            editLayer.getConflicts().add(conflict);
    9692        }
    9793    }
     
    9995    @Override
    10096    public int hashCode() {
    101         return Objects.hash(super.hashCode(), my, their, mergedMembers);
     97        return Objects.hash(super.hashCode(), conflict, mergedMembers);
    10298    }
    10399
     
    108104        if (!super.equals(obj)) return false;
    109105        RelationMemberConflictResolverCommand that = (RelationMemberConflictResolverCommand) obj;
    110         return Objects.equals(my, that.my) &&
    111                 Objects.equals(their, that.their) &&
    112                 Objects.equals(mergedMembers, that.mergedMembers);
     106        return Objects.equals(conflict, that.conflict) &&
     107               Objects.equals(mergedMembers, that.mergedMembers);
    113108    }
    114109}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ConflictResolver.java

    r10454 r11318  
    2424import org.openstreetmap.josm.data.osm.Relation;
    2525import org.openstreetmap.josm.data.osm.Way;
    26 import org.openstreetmap.josm.gui.conflict.pair.nodes.NodeListMergeModel;
    2726import org.openstreetmap.josm.gui.conflict.pair.nodes.NodeListMerger;
    2827import org.openstreetmap.josm.gui.conflict.pair.properties.PropertiesMergeModel;
    2928import org.openstreetmap.josm.gui.conflict.pair.properties.PropertiesMerger;
    30 import org.openstreetmap.josm.gui.conflict.pair.relation.RelationMemberListMergeModel;
    3129import org.openstreetmap.josm.gui.conflict.pair.relation.RelationMemberMerger;
    3230import org.openstreetmap.josm.gui.conflict.pair.tags.TagMergeModel;
     
    4644 *   their primitive</li>
    4745 * </ul>
    48  *
     46 * @since 1622
    4947 */
    5048public class ConflictResolver extends JPanel implements PropertyChangeListener {
     
    274272
    275273    /**
    276      * Builds the resolution command(s) for the resolved conflicts in this
    277      * ConflictResolver
     274     * Builds the resolution command(s) for the resolved conflicts in this ConflictResolver
    278275     *
    279276     * @return the resolution command
     
    287284        commands.addAll(propertiesMerger.getModel().buildResolveCommand(conflict));
    288285        if (my instanceof Way && nodeListMerger.getModel().isFrozen()) {
    289             NodeListMergeModel model = (NodeListMergeModel) nodeListMerger.getModel();
    290             commands.add(model.buildResolveCommand(conflict));
     286            commands.add(nodeListMerger.getModel().buildResolveCommand(conflict));
    291287        } else if (my instanceof Relation && relationMemberMerger.getModel().isFrozen()) {
    292             RelationMemberListMergeModel model = (RelationMemberListMergeModel) relationMemberMerger.getModel();
    293             commands.add(model.buildResolveCommand((Relation) my, (Relation) their));
     288            commands.add(relationMemberMerger.getModel().buildResolveCommand(conflict));
    294289        }
    295290        if (isResolvedCompletely()) {
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMergeModel.java

    r11121 r11318  
    2929
    3030import org.openstreetmap.josm.Main;
     31import org.openstreetmap.josm.command.conflict.ConflictResolveCommand;
     32import org.openstreetmap.josm.data.conflict.Conflict;
    3133import org.openstreetmap.josm.data.osm.DataSet;
    3234import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6971 * A ListMergeModel is used in combination with a {@link ListMerger}.
    7072 *
    71  * @param <T>  the type of the list entries
     73 * @param <T> the type of the list entries
     74 * @param <C> the type of conflict resolution command
    7275 * @see ListMerger
    7376 */
    74 public abstract class ListMergeModel<T extends PrimitiveId> extends ChangeNotifier {
     77public abstract class ListMergeModel<T extends PrimitiveId, C extends ConflictResolveCommand> extends ChangeNotifier {
    7578    public static final String FROZEN_PROP = ListMergeModel.class.getName() + ".frozen";
    7679
     
    614617        }
    615618
    616         public ListMergeModel<T> getListMergeModel() {
     619        /**
     620         * Returns the list merge model.
     621         * @return the list merge model
     622         */
     623        public ListMergeModel<T, C> getListMergeModel() {
    617624            return ListMergeModel.this;
    618625        }
     
    861868        }
    862869    }
     870
     871    /**
     872     * Builds the command to resolve conflicts in the list.
     873     *
     874     * @param conflict the conflict data set
     875     * @return the command
     876     * @throws IllegalStateException if the merge is not yet frozen
     877     */
     878    public abstract C buildResolveCommand(Conflict<? extends OsmPrimitive> conflict);
    863879}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/ListMerger.java

    r10667 r11318  
    3232
    3333import org.openstreetmap.josm.Main;
     34import org.openstreetmap.josm.command.conflict.ConflictResolveCommand;
    3435import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3536import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    4647 *
    4748 * @param <T> the type of the entries
     49 * @param <C> the type of conflict resolution command
    4850 * @see ListMergeModel
    4951 * @since 1631
    5052 */
    51 public abstract class ListMerger<T extends PrimitiveId> extends JPanel implements PropertyChangeListener, ChangeListener, IConflictResolver {
     53public abstract class ListMerger<T extends PrimitiveId, C extends ConflictResolveCommand> extends JPanel
     54implements PropertyChangeListener, ChangeListener, IConflictResolver {
    5255    protected OsmPrimitivesTable myEntriesTable;
    5356    protected OsmPrimitivesTable mergedEntriesTable;
    5457    protected OsmPrimitivesTable theirEntriesTable;
    5558
    56     protected transient ListMergeModel<T> model;
     59    protected transient ListMergeModel<T, C> model;
    5760
    5861    private CopyStartLeftAction copyStartLeftAction;
     
    406409     * @param model list merger model
    407410     */
    408     public ListMerger(ListMergeModel<T> model) {
     411    public ListMerger(ListMergeModel<T, C> model) {
    409412        this.model = model;
    410413        model.addChangeListener(this);
     
    861864    }
    862865
    863     public ListMergeModel<T> getModel() {
     866    /**
     867     * Returns the model.
     868     * @return the model
     869     */
     870    public ListMergeModel<T, C> getModel() {
    864871        return model;
    865872    }
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/PairTable.java

    r10308 r11318  
    66import javax.swing.table.TableColumnModel;
    77
     8import org.openstreetmap.josm.command.conflict.ConflictResolveCommand;
    89import org.openstreetmap.josm.data.osm.OsmPrimitive;
    910import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    1415public abstract class PairTable extends OsmPrimitivesTable {
    1516
    16     private final transient ListMergeModel<? extends PrimitiveId> model;
     17    private final transient ListMergeModel<? extends PrimitiveId, ? extends ConflictResolveCommand> model;
    1718
    1819    /**
     
    2425     * @param sm selection model
    2526     */
    26     public PairTable(String name, ListMergeModel<? extends PrimitiveId> model,
     27    public PairTable(String name, ListMergeModel<? extends PrimitiveId, ? extends ConflictResolveCommand> model,
    2728            OsmPrimitivesTableModel dm, TableColumnModel cm, ListSelectionModel sm) {
    2829        super(dm, cm, sm);
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMergeModel.java

    r8465 r11318  
    1818import org.openstreetmap.josm.gui.conflict.pair.ListRole;
    1919
    20 public class NodeListMergeModel extends ListMergeModel<Node> {
     20/**
     21 * The model for merging two lists of way nodess
     22 * @since 1622
     23 */
     24public class NodeListMergeModel extends ListMergeModel<Node, WayNodesConflictResolverCommand> {
    2125
    2226    /**
     
    4953    }
    5054
    51     /**
    52      * Builds the command to resolve conflicts in the node list of a way
    53      *
    54      * @param conflict the conflict data set
    55      * @return the command
    56      * @throws IllegalStateException if the merge is not yet frozen
    57      */
     55    @Override
    5856    public WayNodesConflictResolverCommand buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
    5957        if (!isFrozen())
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListMerger.java

    r10378 r11318  
    44import javax.swing.JScrollPane;
    55
     6import org.openstreetmap.josm.command.conflict.WayNodesConflictResolverCommand;
    67import org.openstreetmap.josm.data.conflict.Conflict;
    78import org.openstreetmap.josm.data.osm.Node;
     
    1415 * @since 1622
    1516 */
    16 public class NodeListMerger extends ListMerger<Node> {
     17public class NodeListMerger extends ListMerger<Node, WayNodesConflictResolverCommand> {
    1718
    1819    /**
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListTable.java

    r10308 r11318  
    55
    66import org.openstreetmap.josm.actions.ZoomToAction;
     7import org.openstreetmap.josm.command.conflict.WayNodesConflictResolverCommand;
    78import org.openstreetmap.josm.data.osm.Node;
    89import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
     
    1011import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel;
    1112
     13/**
     14 * Node list table.
     15 * @since 5297
     16 */
    1217public class NodeListTable extends PairTable {
    1318
     
    1924     * @param sm selection model
    2025     */
    21     public NodeListTable(String name, ListMergeModel<Node> model, OsmPrimitivesTableModel dm, ListSelectionModel sm) {
     26    public NodeListTable(String name, ListMergeModel<Node, WayNodesConflictResolverCommand> model,
     27            OsmPrimitivesTableModel dm, ListSelectionModel sm) {
    2228        super(name, model, dm, new NodeListColumnModel(new NodeListTableCellRenderer()), sm);
    2329    }
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/nodes/NodeListTableCellRenderer.java

    r10308 r11318  
    1212import javax.swing.table.TableCellRenderer;
    1313
     14import org.openstreetmap.josm.command.conflict.WayNodesConflictResolverCommand;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.gui.DefaultNameFormatter;
     
    5455     * @param isSelected true, if the current row is selected
    5556     */
    56     protected void renderNode(ListMergeModel<Node>.EntriesTableModel model, Node node, int row, boolean isSelected) {
     57    protected void renderNode(ListMergeModel<Node, WayNodesConflictResolverCommand>.EntriesTableModel model, Node node,
     58            int row, boolean isSelected) {
    5759        setIcon(icon);
    5860        setBorder(null);
     
    8890     * @param row the row index
    8991     */
    90     protected void renderRowId(ListMergeModel<Node>.EntriesTableModel model, int row) {
     92    protected void renderRowId(ListMergeModel<Node, WayNodesConflictResolverCommand>.EntriesTableModel model, int row) {
    9193        setIcon(null);
    9294        setBorder(rowNumberBorder);
     
    130132     */
    131133    @SuppressWarnings("unchecked")
    132     protected ListMergeModel<Node>.EntriesTableModel getModel(JTable table) {
    133         return (ListMergeModel<Node>.EntriesTableModel) table.getModel();
     134    protected ListMergeModel<Node, WayNodesConflictResolverCommand>.EntriesTableModel getModel(JTable table) {
     135        return (ListMergeModel<Node, WayNodesConflictResolverCommand>.EntriesTableModel) table.getModel();
    134136    }
    135137}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberListMergeModel.java

    r8510 r11318  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.List;
    76import java.util.Map;
    87
     
    109
    1110import org.openstreetmap.josm.command.conflict.RelationMemberConflictResolverCommand;
     11import org.openstreetmap.josm.data.conflict.Conflict;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1313import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    1717import org.openstreetmap.josm.gui.conflict.pair.ListRole;
    1818import org.openstreetmap.josm.tools.CheckParameterUtil;
     19
    1920/**
    2021 * The model for merging two lists of relation members
    21  *
     22 * @since 1631
    2223 */
    23 public class RelationMemberListMergeModel extends ListMergeModel<RelationMember> {
     24public class RelationMemberListMergeModel extends ListMergeModel<RelationMember, RelationMemberConflictResolverCommand> {
    2425
    2526    @Override
     
    9697    }
    9798
    98     /**
    99      * Builds the command to resolve conflicts in the node list of a way
    100      *
    101      * @param my  my relation. Must not be null.
    102      * @param their  their relation. Must not be null
    103      * @return the command
    104      * @throws IllegalArgumentException if my is null
    105      * @throws IllegalArgumentException if their is null
    106      * @throws IllegalStateException if the merge is not yet frozen
    107      */
    108     public RelationMemberConflictResolverCommand buildResolveCommand(Relation my, Relation their) {
    109         CheckParameterUtil.ensureParameterNotNull(my, "my");
    110         CheckParameterUtil.ensureParameterNotNull(their, "their");
     99    @Override
     100    public RelationMemberConflictResolverCommand buildResolveCommand(Conflict<? extends OsmPrimitive> conflict) {
     101        CheckParameterUtil.ensureParameterNotNull(conflict, "conflict");
    111102        if (!isFrozen())
    112             throw new IllegalArgumentException(tr("Merged nodes not frozen yet. Cannot build resolution command"));
    113         List<RelationMember> entries = getMergedEntries();
    114         return new RelationMemberConflictResolverCommand(my, their, entries);
     103            throw new IllegalArgumentException(tr("Merged members not frozen yet. Cannot build resolution command"));
     104        return new RelationMemberConflictResolverCommand(conflict, getMergedEntries());
    115105    }
    116106}
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberMerger.java

    r10378 r11318  
    44import javax.swing.JScrollPane;
    55
     6import org.openstreetmap.josm.command.conflict.RelationMemberConflictResolverCommand;
    67import org.openstreetmap.josm.data.conflict.Conflict;
    78import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1415 * @since 1631
    1516 */
    16 public class RelationMemberMerger extends ListMerger<RelationMember> {
     17public class RelationMemberMerger extends ListMerger<RelationMember, RelationMemberConflictResolverCommand> {
    1718
    1819    /**
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberTable.java

    r10308 r11318  
    55
    66import org.openstreetmap.josm.actions.ZoomToAction;
     7import org.openstreetmap.josm.command.conflict.RelationMemberConflictResolverCommand;
    78import org.openstreetmap.josm.data.osm.RelationMember;
    89import org.openstreetmap.josm.gui.conflict.pair.ListMergeModel;
     
    1011import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel;
    1112
     13/**
     14 * Relation member table.
     15 * @since 5297
     16 */
    1217public class RelationMemberTable extends PairTable {
    1318
     
    1924     * @param sm selection model
    2025     */
    21     public RelationMemberTable(String name, ListMergeModel<RelationMember> model, OsmPrimitivesTableModel dm, ListSelectionModel sm) {
     26    public RelationMemberTable(String name, ListMergeModel<RelationMember, RelationMemberConflictResolverCommand> model,
     27            OsmPrimitivesTableModel dm, ListSelectionModel sm) {
    2228        super(name, model, dm, new RelationMemberListColumnModel(), sm);
    2329    }
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberTableCellRenderer.java

    r10378 r11318  
    1111import javax.swing.table.TableCellRenderer;
    1212
    13 import org.openstreetmap.josm.data.osm.Node;
     13import org.openstreetmap.josm.command.conflict.RelationMemberConflictResolverCommand;
    1414import org.openstreetmap.josm.data.osm.RelationMember;
    1515import org.openstreetmap.josm.gui.DefaultNameFormatter;
     
    2020/**
    2121 * This is the {@link TableCellRenderer} used in the tables of {@link RelationMemberMerger}.
    22  *
     22 * @since 1631
    2323 */
    2424public class RelationMemberTableCellRenderer extends JLabel implements TableCellRenderer {
     
    4545    }
    4646
    47     protected void renderBackground(ListMergeModel<Node>.EntriesTableModel model, RelationMember member, int row, int col, boolean isSelected) {
     47    protected void renderBackground(ListMergeModel<RelationMember, RelationMemberConflictResolverCommand>.EntriesTableModel model,
     48            RelationMember member, int row, int col, boolean isSelected) {
    4849        Color bgc = ConflictColors.BGCOLOR.get();
    4950        if (col == 0) {
     
    7778    }
    7879
    79     protected void renderForeground(ListMergeModel<Node>.EntriesTableModel model, RelationMember member, int row, int col, boolean isSelected) {
     80    protected void renderForeground(ListMergeModel<RelationMember, RelationMemberConflictResolverCommand>.EntriesTableModel model,
     81            RelationMember member, int row, int col, boolean isSelected) {
    8082        Color fgc = ConflictColors.FGCOLOR.get();
    8183        if (col == 0 && model.isParticipatingInCurrentComparePair() && !model.getListMergeModel().isFrozen()) {
     
    146148     */
    147149    @SuppressWarnings("unchecked")
    148     protected ListMergeModel<Node>.EntriesTableModel getModel(JTable table) {
    149         return (ListMergeModel<Node>.EntriesTableModel) table.getModel();
     150    protected ListMergeModel<RelationMember, RelationMemberConflictResolverCommand>.EntriesTableModel getModel(JTable table) {
     151        return (ListMergeModel<RelationMember, RelationMemberConflictResolverCommand>.EntriesTableModel) table.getModel();
    150152    }
    151153}
Note: See TracChangeset for help on using the changeset viewer.