Class AbstractListMergeModel<T extends PrimitiveId,C extends ConflictResolveCommand>
- java.lang.Object
-
- org.openstreetmap.josm.gui.util.ChangeNotifier
-
- org.openstreetmap.josm.gui.conflict.pair.AbstractListMergeModel<T,C>
-
- Type Parameters:
T
- the type of the list entriesC
- the type of conflict resolution command
- Direct Known Subclasses:
NodeListMergeModel
,RelationMemberListMergeModel
public abstract class AbstractListMergeModel<T extends PrimitiveId,C extends ConflictResolveCommand> extends ChangeNotifier
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:- the list of my entries
- the list of their entries
- the list of merged entries
TableModel
s and threeListSelectionModel
s:- the table model and the list selection for for a
JTable
which shows my entries. SeegetMyTableModel()
andgetMySelectionModel()
- dito for their entries and merged entries
PropertyChangeListener
s can register for property value changes ofFROZEN_PROP
.ListMergeModel is an abstract class. Three methods have to be implemented by subclasses:
cloneEntryForMergedList(T)
- clones an entry of type TisEqualEntry(T, T)
- checks whether two entries are equalssetValueAt(DefaultTableModel, Object, int, int)
- handles values edited in a JTable, dispatched fromTableModel.setValueAt(Object, int, int)
AbstractListMerger
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractListMergeModel.ComparePairListModel
A model forComparePairType
with the enums added as options.protected class
AbstractListMergeModel.EntriesSelectionModel
This is the selection model to be used in aJTable
which displays an entry list managed byAbstractListMergeModel
.class
AbstractListMergeModel.EntriesTableModel
This an adapter between aJTable
and one of the three entry lists in the roleListRole
managed by theAbstractListMergeModel
.
-
Field Summary
Fields Modifier and Type Field Description private AbstractListMergeModel.ComparePairListModel
comparePairListModel
protected java.util.Map<ListRole,java.util.ArrayList<T>>
entries
static java.lang.String
FROZEN_PROP
The property name to listen for frozen changes.private boolean
isFrozen
private java.util.Set<java.beans.PropertyChangeListener>
listeners
private static int
MAX_DELETED_PRIMITIVE_IN_DIALOG
protected AbstractListMergeModel.EntriesSelectionModel
mergedEntriesSelectionModel
protected AbstractListMergeModel.EntriesTableModel
mergedEntriesTableModel
private java.util.Map<PrimitiveId,PrimitiveId>
mergedMap
private DataSet
myDataset
protected AbstractListMergeModel.EntriesSelectionModel
myEntriesSelectionModel
protected AbstractListMergeModel.EntriesTableModel
myEntriesTableModel
protected AbstractListMergeModel.EntriesSelectionModel
theirEntriesSelectionModel
protected AbstractListMergeModel.EntriesTableModel
theirEntriesTableModel
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractListMergeModel()
Constructs a newListMergeModel
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
protected void
alertCopyFailedForDeletedPrimitives(java.util.List<PrimitiveId> deletedIds)
protected void
buildMergedEntriesTableModel()
protected void
buildMyEntriesTableModel()
abstract C
buildResolveCommand(Conflict<? extends OsmPrimitive> conflict)
Builds the command to resolve conflicts in the list.protected void
buildTheirEntriesTableModel()
void
clearMerged()
Clear the merged list.protected abstract T
cloneEntryForMergedList(T entry)
Creates a clone of an entry of type T suitable to be included in the list of merged entriesprivate 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 nodessource
to the list of merged nodes.void
copyAll(ListRole source)
Copies over all values from the given side to the merged table..protected void
copyBeforeCurrent(ListRole source, int[] rows, int current)
Copies the nodes given by indices in rows from the list of nodessource
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()
AbstractListMergeModel.ComparePairListModel
getComparePairListModel()
protected java.util.List<T>
getMergedEntries()
int
getMergedEntriesSize()
AbstractListMergeModel.EntriesSelectionModel
getMergedSelectionModel()
OsmPrimitivesTableModel
getMergedTableModel()
protected java.util.List<T>
getMyEntries()
int
getMyEntriesSize()
OsmPrimitive
getMyPrimitive(T entry)
Replies primitive from my dataset referenced by entryOsmPrimitive
getMyPrimitiveById(PrimitiveId entry)
AbstractListMergeModel.EntriesSelectionModel
getMySelectionModel()
OsmPrimitivesTableModel
getMyTableModel()
protected java.util.List<T>
getTheirEntries()
int
getTheirEntriesSize()
AbstractListMergeModel.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()
Check if the model is frozen.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 equalvoid
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)
Sets the frozen status for this model.protected abstract void
setValueAt(javax.swing.table.DefaultTableModel model, java.lang.Object value, int row, int col)
Handles method dispatches fromTableModel.setValueAt(Object, int, int)
.-
Methods inherited from class org.openstreetmap.josm.gui.util.ChangeNotifier
addChangeListener, fireStateChanged, removeChangeListener
-
-
-
-
Field Detail
-
FROZEN_PROP
public static final java.lang.String FROZEN_PROP
The property name to listen for frozen changes.- See Also:
setFrozen(boolean)
,isFrozen()
-
MAX_DELETED_PRIMITIVE_IN_DIALOG
private static final int MAX_DELETED_PRIMITIVE_IN_DIALOG
- See Also:
- Constant Field Values
-
entries
protected java.util.Map<ListRole,java.util.ArrayList<T extends PrimitiveId>> entries
-
myEntriesTableModel
protected AbstractListMergeModel.EntriesTableModel myEntriesTableModel
-
theirEntriesTableModel
protected AbstractListMergeModel.EntriesTableModel theirEntriesTableModel
-
mergedEntriesTableModel
protected AbstractListMergeModel.EntriesTableModel mergedEntriesTableModel
-
myEntriesSelectionModel
protected AbstractListMergeModel.EntriesSelectionModel myEntriesSelectionModel
-
theirEntriesSelectionModel
protected AbstractListMergeModel.EntriesSelectionModel theirEntriesSelectionModel
-
mergedEntriesSelectionModel
protected AbstractListMergeModel.EntriesSelectionModel mergedEntriesSelectionModel
-
listeners
private final java.util.Set<java.beans.PropertyChangeListener> listeners
-
isFrozen
private boolean isFrozen
-
comparePairListModel
private final AbstractListMergeModel.ComparePairListModel comparePairListModel
-
mergedMap
private java.util.Map<PrimitiveId,PrimitiveId> mergedMap
-
-
Constructor Detail
-
AbstractListMergeModel
protected AbstractListMergeModel()
Constructs a newListMergeModel
.
-
-
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 entrye2
- 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 fromTableModel.setValueAt(Object, int, int)
.- Parameters:
model
- the table modelvalue
- the value to be setrow
- the row indexcol
- the column index- See Also:
TableModel.setValueAt(Object, int, int)
-
getMyPrimitive
public OsmPrimitive getMyPrimitive(T entry)
Replies primitive from my dataset referenced by entry- Parameters:
entry
- 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 final void setFrozen(boolean isFrozen)
Sets the frozen status for this model.- Parameters:
isFrozen
-true
if it should be frozen.
-
isFrozen
public final boolean isFrozen()
Check if the model is frozen.- Returns:
- The current frozen state.
-
getMyTableModel
public OsmPrimitivesTableModel getMyTableModel()
-
getTheirTableModel
public OsmPrimitivesTableModel getTheirTableModel()
-
getMergedTableModel
public OsmPrimitivesTableModel getMergedTableModel()
-
getMySelectionModel
public AbstractListMergeModel.EntriesSelectionModel getMySelectionModel()
-
getTheirSelectionModel
public AbstractListMergeModel.EntriesSelectionModel getTheirSelectionModel()
-
getMergedSelectionModel
public AbstractListMergeModel.EntriesSelectionModel getMergedSelectionModel()
-
fireModelDataChanged
protected void fireModelDataChanged()
-
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 fromrows
- 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()
Clear the merged list.
-
initPopulate
protected final void initPopulate(OsmPrimitive my, OsmPrimitive their, java.util.Map<PrimitiveId,PrimitiveId> mergedMap)
-
alertCopyFailedForDeletedPrimitives
protected void alertCopyFailedForDeletedPrimitives(java.util.List<PrimitiveId> deletedIds)
-
copyAll
public void copyAll(ListRole source)
Copies over all values from the given side to the merged table..- Parameters:
source
- The source side to copy from.
-
copyBeforeCurrent
protected void copyBeforeCurrent(ListRole source, int[] rows, int current)
Copies the nodes given by indices in rows from the list of nodessource
to the list of merged nodes. Inserts the nodes before row given by current.- Parameters:
source
- the list of nodes to copy fromrows
- the indicescurrent
- the row index before which the nodes are inserted- Throws:
java.lang.IllegalArgumentException
- 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 indicescurrent
- the row index before which the nodes are inserted- Throws:
java.lang.IllegalArgumentException
- 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 indicescurrent
- the row index before which the nodes are inserted- Throws:
java.lang.IllegalArgumentException
- 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 nodessource
to the list of merged nodes. Inserts the nodes after the row given by current.- Parameters:
source
- the list of nodes to copy fromrows
- the indicescurrent
- the row index after which the nodes are inserted- Throws:
java.lang.IllegalArgumentException
- 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 indicescurrent
- the row index after which the nodes are inserted- Throws:
java.lang.IllegalArgumentException
- 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 indicescurrent
- the row index after which the nodes are inserted- Throws:
java.lang.IllegalArgumentException
- 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 AbstractListMergeModel.ComparePairListModel getComparePairListModel()
-
buildResolveCommand
public abstract C buildResolveCommand(Conflict<? extends OsmPrimitive> conflict)
Builds the command to resolve conflicts in the list.- Parameters:
conflict
- the conflict data set- Returns:
- the command
- Throws:
java.lang.IllegalStateException
- if the merge is not yet frozen
-
-