org.openstreetmap.josm.gui.conflict.pair
Class ListMergeModel<T extends PrimitiveId>

java.lang.Object
  extended by java.util.Observable
      extended by org.openstreetmap.josm.gui.conflict.pair.ListMergeModel<T>
Type Parameters:
T - the type of the list entries
Direct Known Subclasses:
NodeListMergeModel, RelationMemberListMergeModel

public abstract class ListMergeModel<T extends PrimitiveId>
extends java.util.Observable

ListMergeModel is a model for interactively comparing and merging two list of entries of type T. It maintains three lists of entries of type T:

  1. the list of my entries
  2. the list of their entries
  3. the list of merged entries
A ListMergeModel is a factory for three ListMergeModel.EntriesTableModels and three ListSelectionModels:
  1. the table model and the list selection for for a JTable which shows my entries. See getMyTableModel()
  2. and getMySelectionModel()
  3. dito for their entries and merged entries
A ListMergeModel can be ''frozen''. If it's frozen, it doesn't accept additional merge decisions. PropertyChangeListeners can register for property value changes of #PROP_FROZEN. ListMergeModel is an abstract class. Three methods have to be implemented by subclasses: A ListMergeModel is used in combination with a ListMerger.

See Also:
ListMerger

Nested Class Summary
 class ListMergeModel.ComparePairListModel
           
protected  class ListMergeModel.EntriesSelectionModel
          This is the selection model to be used in a JTable which displays an entry list managed by ListMergeModel.
 class ListMergeModel.EntriesTableModel
          This an adapter between a JTable and one of the three entry lists in the role ListRole managed by the ListMergeModel.
 
Field Summary
private  ListMergeModel.ComparePairListModel comparePairListModel
           
protected  java.util.HashMap<ListRole,java.util.ArrayList<T>> entries
           
static java.lang.String FROZEN_PROP
           
private  boolean isFrozen
           
private  java.util.List<java.beans.PropertyChangeListener> listeners
           
private static int MAX_DELETED_PRIMITIVE_IN_DIALOG
           
protected  ListMergeModel.EntriesSelectionModel mergedEntriesSelectionModel
           
protected  ListMergeModel.EntriesTableModel mergedEntriesTableModel
           
private  java.util.Map<PrimitiveId,PrimitiveId> mergedMap
           
private  DataSet myDataset
           
protected  ListMergeModel.EntriesSelectionModel myEntriesSelectionModel
           
protected  ListMergeModel.EntriesTableModel myEntriesTableModel
           
protected  ListMergeModel.EntriesSelectionModel theirEntriesSelectionModel
           
protected  ListMergeModel.EntriesTableModel theirEntriesTableModel
           
 
Constructor Summary
ListMergeModel()
           
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
           
protected  void alertCopyFailedForDeletedPrimitives(java.util.List<PrimitiveId> deletedIds)
           
protected  void buildMergedEntriesTableModel()
           
protected  void buildMyEntriesTableModel()
           
protected  void buildTheirEntriesTableModel()
           
 void clearMerged()
           
protected abstract  T cloneEntryForMergedList(T entry)
          Creates a clone of an entry of type T suitable to be included in the list of merged entries
private  void copy(ListRole sourceRole, int[] rows, int position)
           
protected  void copyAfterCurrent(ListRole source, int[] rows, int current)
          Copies the nodes given by indices in rows from the list of nodes source to the list of merged nodes.
 void copyAll(ListRole source)
           
protected  void copyBeforeCurrent(ListRole source, int[] rows, int current)
          Copies the nodes given by indices in rows from the list of nodes source to the list of merged nodes.
 void copyMyAfterCurrent(int[] rows, int current)
          Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.
 void copyMyBeforeCurrent(int[] rows, int current)
          Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.
 void copyMyToEnd(int[] rows)
          Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.
 void copyMyToTop(int[] rows)
          Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.
 void copyTheirAfterCurrent(int[] rows, int current)
          Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.
 void copyTheirBeforeCurrent(int[] rows, int current)
          Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes.
 void copyTheirToEnd(int[] rows)
          Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes.
 void copyTheirToTop(int[] rows)
          Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes.
 void copyToEnd(ListRole source, int[] rows)
          Copies the nodes given by indices in rows from the list of nodes in source to the list of merged nodes.
protected  void copyToTop(ListRole role, int[] rows)
           
protected  void fireFrozenChanged(boolean oldValue, boolean newValue)
           
protected  void fireModelDataChanged()
           
 ListMergeModel.ComparePairListModel getComparePairListModel()
           
protected  java.util.List<T> getMergedEntries()
           
 int getMergedEntriesSize()
           
 ListMergeModel.EntriesSelectionModel getMergedSelectionModel()
           
 OsmPrimitivesTableModel getMergedTableModel()
           
protected  java.util.List<T> getMyEntries()
           
 int getMyEntriesSize()
           
 OsmPrimitive getMyPrimitive(T entry)
           
 OsmPrimitive getMyPrimitiveById(PrimitiveId entry)
           
 ListMergeModel.EntriesSelectionModel getMySelectionModel()
           
 OsmPrimitivesTableModel getMyTableModel()
           
protected  java.util.List<T> getTheirEntries()
           
 int getTheirEntriesSize()
           
 ListMergeModel.EntriesSelectionModel getTheirSelectionModel()
           
 OsmPrimitivesTableModel getTheirTableModel()
           
protected  void initPopulate(OsmPrimitive my, OsmPrimitive their, java.util.Map<PrimitiveId,PrimitiveId> mergedMap)
           
abstract  boolean isEqualEntry(T e1, T e2)
          checks whether two entries are equal.
 boolean isFrozen()
           
 void moveDownMerged(int[] rows)
          Moves the nodes given by indices in rows down by one position in the list of merged nodes.
 void moveUpMerged(int[] rows)
          Moves the nodes given by indices in rows up by one position in the list of merged nodes.
protected  boolean myAndTheirEntriesEqual()
          Replies true if the list of my entries and the list of their entries are equal
 void removeMerged(int[] rows)
          Removes the nodes given by indices in rows from the list of merged nodes.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
           
 void setFrozen(boolean isFrozen)
           
protected abstract  void setValueAt(javax.swing.table.DefaultTableModel model, java.lang.Object value, int row, int col)
          Handles method dispatches from ListMergeModel.EntriesTableModel.setValueAt(Object, int, int).
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FROZEN_PROP

public static final java.lang.String FROZEN_PROP

MAX_DELETED_PRIMITIVE_IN_DIALOG

private static final int MAX_DELETED_PRIMITIVE_IN_DIALOG
See Also:
Constant Field Values

entries

protected java.util.HashMap<ListRole,java.util.ArrayList<T extends PrimitiveId>> entries

myEntriesTableModel

protected ListMergeModel.EntriesTableModel myEntriesTableModel

theirEntriesTableModel

protected ListMergeModel.EntriesTableModel theirEntriesTableModel

mergedEntriesTableModel

protected ListMergeModel.EntriesTableModel mergedEntriesTableModel

myEntriesSelectionModel

protected ListMergeModel.EntriesSelectionModel myEntriesSelectionModel

theirEntriesSelectionModel

protected ListMergeModel.EntriesSelectionModel theirEntriesSelectionModel

mergedEntriesSelectionModel

protected ListMergeModel.EntriesSelectionModel mergedEntriesSelectionModel

listeners

private final java.util.List<java.beans.PropertyChangeListener> listeners

isFrozen

private boolean isFrozen

comparePairListModel

private final ListMergeModel.ComparePairListModel comparePairListModel

myDataset

private DataSet myDataset

mergedMap

private java.util.Map<PrimitiveId,PrimitiveId> mergedMap
Constructor Detail

ListMergeModel

public ListMergeModel()
Method Detail

cloneEntryForMergedList

protected abstract T cloneEntryForMergedList(T entry)
Creates a clone of an entry of type T suitable to be included in the list of merged entries

Parameters:
entry - the entry
Returns:
the cloned entry

isEqualEntry

public abstract boolean isEqualEntry(T e1,
                                     T e2)
checks whether two entries are equal. This is not necessarily the same as e1.equals(e2).

Parameters:
e1 - the first entry
e2 - the second entry
Returns:
true, if the entries are equal, false otherwise.

setValueAt

protected abstract void setValueAt(javax.swing.table.DefaultTableModel model,
                                   java.lang.Object value,
                                   int row,
                                   int col)
Handles method dispatches from ListMergeModel.EntriesTableModel.setValueAt(Object, int, int).

Parameters:
model - the table model
value - the value to be set
row - the row index
col - the column index
See Also:
ListMergeModel.EntriesTableModel.setValueAt(Object, int, int)

getMyPrimitive

public OsmPrimitive getMyPrimitive(T entry)
Parameters:
entry -
Returns:
Primitive from my dataset referenced by entry

getMyPrimitiveById

public final OsmPrimitive getMyPrimitiveById(PrimitiveId entry)

buildMyEntriesTableModel

protected void buildMyEntriesTableModel()

buildTheirEntriesTableModel

protected void buildTheirEntriesTableModel()

buildMergedEntriesTableModel

protected void buildMergedEntriesTableModel()

getMergedEntries

protected java.util.List<T> getMergedEntries()

getMyEntries

protected java.util.List<T> getMyEntries()

getTheirEntries

protected java.util.List<T> getTheirEntries()

getMyEntriesSize

public int getMyEntriesSize()

getMergedEntriesSize

public int getMergedEntriesSize()

getTheirEntriesSize

public int getTheirEntriesSize()

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)

fireFrozenChanged

protected void fireFrozenChanged(boolean oldValue,
                                 boolean newValue)

setFrozen

public void setFrozen(boolean isFrozen)

isFrozen

public boolean isFrozen()

getMyTableModel

public OsmPrimitivesTableModel getMyTableModel()

getTheirTableModel

public OsmPrimitivesTableModel getTheirTableModel()

getMergedTableModel

public OsmPrimitivesTableModel getMergedTableModel()

getMySelectionModel

public ListMergeModel.EntriesSelectionModel getMySelectionModel()

getTheirSelectionModel

public ListMergeModel.EntriesSelectionModel getTheirSelectionModel()

getMergedSelectionModel

public ListMergeModel.EntriesSelectionModel getMergedSelectionModel()

fireModelDataChanged

protected void fireModelDataChanged()

copyToTop

protected void copyToTop(ListRole role,
                         int[] rows)

copyMyToTop

public void copyMyToTop(int[] rows)
Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes. Inserts the nodes at the top of the list of merged nodes.

Parameters:
rows - the indices

copyTheirToTop

public void copyTheirToTop(int[] rows)
Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes. Inserts the nodes at the top of the list of merged nodes.

Parameters:
rows - the indices

copyToEnd

public void copyToEnd(ListRole source,
                      int[] rows)
Copies the nodes given by indices in rows from the list of nodes in source to the list of merged nodes. Inserts the nodes at the end of the list of merged nodes.

Parameters:
source - the list of nodes to copy from
rows - the indices

copyMyToEnd

public void copyMyToEnd(int[] rows)
Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes. Inserts the nodes at the end of the list of merged nodes.

Parameters:
rows - the indices

copyTheirToEnd

public void copyTheirToEnd(int[] rows)
Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes. Inserts the nodes at the end of the list of merged nodes.

Parameters:
rows - the indices

clearMerged

public void clearMerged()

initPopulate

protected final void initPopulate(OsmPrimitive my,
                                  OsmPrimitive their,
                                  java.util.Map<PrimitiveId,PrimitiveId> mergedMap)

alertCopyFailedForDeletedPrimitives

protected void alertCopyFailedForDeletedPrimitives(java.util.List<PrimitiveId> deletedIds)

copy

private void copy(ListRole sourceRole,
                  int[] rows,
                  int position)

copyAll

public void copyAll(ListRole source)

copyBeforeCurrent

protected void copyBeforeCurrent(ListRole source,
                                 int[] rows,
                                 int current)
Copies the nodes given by indices in rows from the list of nodes source to the list of merged nodes. Inserts the nodes before row given by current.

Parameters:
source - the list of nodes to copy from
rows - the indices
current - the row index before which the nodes are inserted
Throws:
java.lang.IllegalArgumentException - thrown, if current < 0 or >= #nodes in list of merged nodes

copyMyBeforeCurrent

public void copyMyBeforeCurrent(int[] rows,
                                int current)
Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes. Inserts the nodes before row given by current.

Parameters:
rows - the indices
current - the row index before which the nodes are inserted
Throws:
java.lang.IllegalArgumentException - thrown, if current < 0 or >= #nodes in list of merged nodes

copyTheirBeforeCurrent

public void copyTheirBeforeCurrent(int[] rows,
                                   int current)
Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes. Inserts the nodes before row given by current.

Parameters:
rows - the indices
current - the row index before which the nodes are inserted
Throws:
java.lang.IllegalArgumentException - thrown, if current < 0 or >= #nodes in list of merged nodes

copyAfterCurrent

protected void copyAfterCurrent(ListRole source,
                                int[] rows,
                                int current)
Copies the nodes given by indices in rows from the list of nodes source to the list of merged nodes. Inserts the nodes after the row given by current.

Parameters:
source - the list of nodes to copy from
rows - the indices
current - the row index after which the nodes are inserted
Throws:
java.lang.IllegalArgumentException - thrown, if current < 0 or >= #nodes in list of merged nodes

copyMyAfterCurrent

public void copyMyAfterCurrent(int[] rows,
                               int current)
Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes. Inserts the nodes after the row given by current.

Parameters:
rows - the indices
current - the row index after which the nodes are inserted
Throws:
java.lang.IllegalArgumentException - thrown, if current < 0 or >= #nodes in list of merged nodes

copyTheirAfterCurrent

public void copyTheirAfterCurrent(int[] rows,
                                  int current)
Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes. Inserts the nodes after the row given by current.

Parameters:
rows - the indices
current - the row index after which the nodes are inserted
Throws:
java.lang.IllegalArgumentException - thrown, if current < 0 or >= #nodes in list of merged nodes

moveUpMerged

public void moveUpMerged(int[] rows)
Moves the nodes given by indices in rows up by one position in the list of merged nodes.

Parameters:
rows - the indices

moveDownMerged

public void moveDownMerged(int[] rows)
Moves the nodes given by indices in rows down by one position in the list of merged nodes.

Parameters:
rows - the indices

removeMerged

public void removeMerged(int[] rows)
Removes the nodes given by indices in rows from the list of merged nodes.

Parameters:
rows - the indices

myAndTheirEntriesEqual

protected boolean myAndTheirEntriesEqual()
Replies true if the list of my entries and the list of their entries are equal

Returns:
true, if the lists are equal; false otherwise

getComparePairListModel

public ListMergeModel.ComparePairListModel getComparePairListModel()


JOSM