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
TableModels and threeListSelectionModels:- the table model and the list selection for for a
JTablewhich shows my entries. SeegetMyTableModel()andgetMySelectionModel() - dito for their entries and merged entries
PropertyChangeListeners 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 classAbstractListMergeModel.ComparePairListModelA model forComparePairTypewith the enums added as options.protected classAbstractListMergeModel.EntriesSelectionModelThis is the selection model to be used in aJTablewhich displays an entry list managed byAbstractListMergeModel.classAbstractListMergeModel.EntriesTableModelThis an adapter between aJTableand one of the three entry lists in the roleListRolemanaged by theAbstractListMergeModel.
-
Field Summary
Fields Modifier and Type Field Description private AbstractListMergeModel.ComparePairListModelcomparePairListModelprotected java.util.Map<ListRole,java.util.ArrayList<T>>entriesstatic java.lang.StringFROZEN_PROPThe property name to listen for frozen changes.private booleanisFrozenprivate java.util.Set<java.beans.PropertyChangeListener>listenersprivate static intMAX_DELETED_PRIMITIVE_IN_DIALOGprotected AbstractListMergeModel.EntriesSelectionModelmergedEntriesSelectionModelprotected AbstractListMergeModel.EntriesTableModelmergedEntriesTableModelprivate java.util.Map<PrimitiveId,PrimitiveId>mergedMapprivate DataSetmyDatasetprotected AbstractListMergeModel.EntriesSelectionModelmyEntriesSelectionModelprotected AbstractListMergeModel.EntriesTableModelmyEntriesTableModelprotected AbstractListMergeModel.EntriesSelectionModeltheirEntriesSelectionModelprotected AbstractListMergeModel.EntriesTableModeltheirEntriesTableModel
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractListMergeModel()Constructs a newListMergeModel.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)protected voidalertCopyFailedForDeletedPrimitives(java.util.List<PrimitiveId> deletedIds)protected voidbuildMergedEntriesTableModel()protected voidbuildMyEntriesTableModel()abstract CbuildResolveCommand(Conflict<? extends OsmPrimitive> conflict)Builds the command to resolve conflicts in the list.protected voidbuildTheirEntriesTableModel()voidclearMerged()Clear the merged list.protected abstract TcloneEntryForMergedList(T entry)Creates a clone of an entry of type T suitable to be included in the list of merged entriesprivate voidcopy(ListRole sourceRole, int[] rows, int position)protected voidcopyAfterCurrent(ListRole source, int[] rows, int current)Copies the nodes given by indices in rows from the list of nodessourceto the list of merged nodes.voidcopyAll(ListRole source)Copies over all values from the given side to the merged table..protected voidcopyBeforeCurrent(ListRole source, int[] rows, int current)Copies the nodes given by indices in rows from the list of nodessourceto the list of merged nodes.voidcopyMyAfterCurrent(int[] rows, int current)Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.voidcopyMyBeforeCurrent(int[] rows, int current)Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.voidcopyMyToEnd(int... rows)Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.voidcopyMyToTop(int... rows)Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.voidcopyTheirAfterCurrent(int[] rows, int current)Copies the nodes given by indices in rows from the list of my nodes to the list of merged nodes.voidcopyTheirBeforeCurrent(int[] rows, int current)Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes.voidcopyTheirToEnd(int... rows)Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes.voidcopyTheirToTop(int... rows)Copies the nodes given by indices in rows from the list of their nodes to the list of merged nodes.voidcopyToEnd(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 voidcopyToTop(ListRole role, int... rows)protected voidfireFrozenChanged(boolean oldValue, boolean newValue)protected voidfireModelDataChanged()AbstractListMergeModel.ComparePairListModelgetComparePairListModel()protected java.util.List<T>getMergedEntries()intgetMergedEntriesSize()AbstractListMergeModel.EntriesSelectionModelgetMergedSelectionModel()OsmPrimitivesTableModelgetMergedTableModel()protected java.util.List<T>getMyEntries()intgetMyEntriesSize()OsmPrimitivegetMyPrimitive(T entry)Replies primitive from my dataset referenced by entryOsmPrimitivegetMyPrimitiveById(PrimitiveId entry)AbstractListMergeModel.EntriesSelectionModelgetMySelectionModel()OsmPrimitivesTableModelgetMyTableModel()protected java.util.List<T>getTheirEntries()intgetTheirEntriesSize()AbstractListMergeModel.EntriesSelectionModelgetTheirSelectionModel()OsmPrimitivesTableModelgetTheirTableModel()protected voidinitPopulate(OsmPrimitive my, OsmPrimitive their, java.util.Map<PrimitiveId,PrimitiveId> mergedMap)abstract booleanisEqualEntry(T e1, T e2)checks whether two entries are equal.booleanisFrozen()Check if the model is frozen.voidmoveDownMerged(int... rows)Moves the nodes given by indices in rows down by one position in the list of merged nodes.voidmoveUpMerged(int... rows)Moves the nodes given by indices in rows up by one position in the list of merged nodes.protected booleanmyAndTheirEntriesEqual()Replies true if the list of my entries and the list of their entries are equalvoidremoveMerged(int... rows)Removes the nodes given by indices in rows from the list of merged nodes.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)voidsetFrozen(boolean isFrozen)Sets the frozen status for this model.protected abstract voidsetValueAt(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-trueif 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 nodessourceto 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 nodessourceto 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
-
-