Class MemberTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.EventListener
,javax.swing.event.TableModelListener
,javax.swing.table.TableModel
,DataSelectionListener
,DataSetListener
,ReorderableModel<RelationMember>
,SortableModel<RelationMember>
,ReorderableTableModel<RelationMember>
,SortableTableModel<RelationMember>
,OsmPrimitivesTableModel
public class MemberTableModel extends javax.swing.table.AbstractTableModel implements javax.swing.event.TableModelListener, DataSelectionListener, DataSetListener, OsmPrimitivesTableModel, SortableTableModel<RelationMember>
This is the base model used for theMemberTable
. It holds the member data.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.data.osm.DataSelectionListener
DataSelectionListener.AbstractSelectionEvent, DataSelectionListener.SelectionAddEvent, DataSelectionListener.SelectionChangeEvent, DataSelectionListener.SelectionRemoveEvent, DataSelectionListener.SelectionReplaceEvent, DataSelectionListener.SelectionToggleEvent
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<WayConnectionType>
connectionType
private OsmDataLayer
layer
private java.util.concurrent.CopyOnWriteArrayList<IMemberModelListener>
listeners
private javax.swing.DefaultListSelectionModel
listSelectionModel
private java.util.List<RelationMember>
members
data of the table model: The list of members and the cached WayConnectionType of each member.private TaggingPresetHandler
presetHandler
private Relation
relation
private RelationSorter
relationSorter
private WayConnectionTypeCalculator
wayConnectionTypeCalculator
-
Constructor Summary
Constructors Constructor Description MemberTableModel(Relation relation, OsmDataLayer layer, TaggingPresetHandler presetHandler)
constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMemberModelListener(IMemberModelListener listener)
Add a new member model listener.void
addMembersAfterIdx(java.util.List<? extends OsmPrimitive> primitives, int idx)
void
addMembersAtBeginning(java.util.List<? extends OsmPrimitive> primitives)
void
addMembersAtEnd(java.util.List<? extends OsmPrimitive> primitives)
private void
addMembersAtIndex(java.util.List<? extends OsmPrimitive> primitives, int index)
(package private) void
addMembersAtIndexKeepingOldSelection(java.lang.Iterable<RelationMember> newMembers, int index)
void
addMembersBeforeIdx(java.util.List<? extends OsmPrimitive> primitives, int idx)
private int
addToSelectedMembers(java.util.BitSet selectedIndices)
Add one or more members indices to the selection.void
applyToRelation(Relation relation)
Applies this member model to the given relation.boolean
canRemove(int... rows)
Checks that a range of rows can be removed.void
dataChanged(DataChangedEvent event)
Called after big changes in dataset.protected void
fireMakeMemberVisible(int index)
java.util.Set<OsmPrimitive>
getChildPrimitives(java.util.Collection<? extends OsmPrimitive> referenceSet)
Replies the set of selected referrers.int
getColumnCount()
java.util.Set<OsmPrimitive>
getIncompleteMemberPrimitives()
Replies the set of incomplete primitivesOsmDataLayer
getLayer()
Returns the data layer.int
getNumMembersWithPrimitive(OsmPrimitive primitive)
Replies the number of members which refer to a particular primitiveOsmPrimitive
getReferredPrimitive(int idx)
Gets the primitive at a given row index(package private) RelationMember
getRelationMemberForPrimitive(OsmPrimitive primitive)
int
getRowCount()
Returns the number of rows in the list/table.java.util.Collection<OsmPrimitive>
getSelectedChildPrimitives()
Replies the set of selected referrers.java.util.Set<OsmPrimitive>
getSelectedIncompleteMemberPrimitives()
Replies the set of selected incomplete primitivesjava.util.Collection<RelationMember>
getSelectedMembers()
Get the currently selected relation membersjavax.swing.DefaultListSelectionModel
getSelectionModel()
Returns the selection model.RelationMember
getValue(int index)
Get object value at given index.java.lang.Object
getValueAt(int rowIndex, int columnIndex)
(package private) WayConnectionType
getWayConnection(int i)
boolean
hasIncompleteMembers()
Replies true if at least one the relation members is incompleteboolean
hasIncompleteSelectedMembers()
Replies true if at least one of the selected members is incompleteboolean
hasMembersReferringTo(java.util.Collection<OsmPrimitive> primitives)
Replies true if there is at least one relation member in this model which refers to at least on the primitives inprimitives
.static boolean
hasMembersReferringTo(java.util.Collection<RelationMember> members, java.util.Collection<OsmPrimitive> primitives)
Replies true if there is at least one relation member given asmembers
which refers to at least on the primitives inprimitives
.boolean
hasSameMembersAs(Relation relation)
Determines if this model has the same members as the given relation.private void
invalidateConnectionType()
boolean
isCellEditable(int rowIndex, int columnIndex)
boolean
isEditableRelation(int index)
Replies true if the index-th relation members refers to an editable relation, i.e.boolean
isInJosmSelection(OsmPrimitive primitive)
Replies true ifprimitive
is currently selected in the layer this model is attached toboolean
move(int delta, int... selectedRows)
Move selected rows by any number of positions, if possible.void
nodeMoved(NodeMovedEvent event)
A node's coordinates were modified.void
otherDatasetChange(AbstractDatasetChangedEvent event)
Minor dataset change, currently only changeset id changed is supported, but can be extended in future.void
populate(Relation relation)
Populates this model from the given relation.void
primitivesAdded(PrimitivesAddedEvent event)
A bunch of primitives were added into the DataSet, or existing deleted/invisible primitives were resurrected.void
primitivesRemoved(PrimitivesRemovedEvent event)
A bunch of primitives were removed from the DataSet, or preexisting primitives were marked as deleted.void
register()
Registers listeners (selection change and dataset change).void
relationMembersChanged(RelationMembersChangedEvent event)
A relation's members have changed.void
remove(int... selectedRows)
Remove selected rows, if possible.void
removeMemberModelListener(IMemberModelListener listener)
Remove a member model listener.void
removeMembersReferringTo(java.util.List<? extends OsmPrimitive> primitives)
Remove members referring to the given list of primitives.void
reverse()
Reverse the relation members.void
selectionChanged(DataSelectionListener.SelectionChangeEvent event)
Called whenever the selection is changed.void
selectMembersReferringTo(java.util.Collection<? extends OsmPrimitive> primitives)
Selects all members which refer toOsmPrimitive
s in the collectionsprimitives
.void
setSelectedMembers(java.util.Collection<RelationMember> selectedMembers)
Selects the members in the collection selectedMembersvoid
setSelectedMembersIdx(java.util.Collection<java.lang.Integer> selectedIndices)
Selects the members in the collection selectedIndicesRelationMember
setValue(int index, RelationMember value)
Set object value at given index.void
setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
void
sort()
Sort the selected relation members by the way they are linked.void
sortBelow()
Sort the selected relation members and all members below by the way they are linked.void
tableChanged(javax.swing.event.TableModelEvent e)
void
tagsChanged(TagsChangedEvent event)
There was some change in the tag set of a primitive.void
unregister()
Unregisters listeners (selection change and dataset change).void
updateRole(int[] idx, java.lang.String role)
updates the role of the members given by the indices inidx
void
wayNodesChanged(WayNodesChangedEvent event)
A way's node list was changed.-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.osm.event.DataSetListener
dataChangedIndividualEvents
-
Methods inherited from interface org.openstreetmap.josm.data.ReorderableModel
canMove, canMoveDown, canMoveUp, doMove
-
Methods inherited from interface org.openstreetmap.josm.gui.util.ReorderableTableModel
canMove, canMoveDown, canMoveDown, canMoveUp, canMoveUp, getSelectedIndices, moveDown, moveDown, moveUp, moveUp, selectedIndices
-
-
-
-
Field Detail
-
members
private final transient java.util.List<RelationMember> members
data of the table model: The list of members and the cached WayConnectionType of each member.
-
connectionType
private transient java.util.List<WayConnectionType> connectionType
-
listSelectionModel
private javax.swing.DefaultListSelectionModel listSelectionModel
-
listeners
private final transient java.util.concurrent.CopyOnWriteArrayList<IMemberModelListener> listeners
-
layer
private final transient OsmDataLayer layer
-
presetHandler
private final transient TaggingPresetHandler presetHandler
-
wayConnectionTypeCalculator
private final transient WayConnectionTypeCalculator wayConnectionTypeCalculator
-
relationSorter
private final transient RelationSorter relationSorter
-
-
Constructor Detail
-
MemberTableModel
public MemberTableModel(Relation relation, OsmDataLayer layer, TaggingPresetHandler presetHandler)
constructor- Parameters:
relation
- relationlayer
- data layerpresetHandler
- tagging preset handler
-
-
Method Detail
-
getLayer
public OsmDataLayer getLayer()
Returns the data layer.- Returns:
- the data layer
-
register
public void register()
Registers listeners (selection change and dataset change).
-
unregister
public void unregister()
Unregisters listeners (selection change and dataset change).
-
selectionChanged
public void selectionChanged(DataSelectionListener.SelectionChangeEvent event)
Description copied from interface:DataSelectionListener
Called whenever the selection is changed. You get notified about the new selection, the elements that were added and removed and the layer that triggered the event.- Specified by:
selectionChanged
in interfaceDataSelectionListener
- Parameters:
event
- The selection change event.- See Also:
DataSelectionListener.SelectionChangeEvent
-
dataChanged
public void dataChanged(DataChangedEvent event)
Description copied from interface:DataSetListener
Called after big changes in dataset. Usually other events are stopped using Dataset.beginUpdate() and after operation is completed (Dataset.endUpdate()),DataSetListener.dataChanged(DataChangedEvent event)
is called.- Specified by:
dataChanged
in interfaceDataSetListener
- Parameters:
event
- data change event
-
nodeMoved
public void nodeMoved(NodeMovedEvent event)
Description copied from interface:DataSetListener
A node's coordinates were modified.- Specified by:
nodeMoved
in interfaceDataSetListener
- Parameters:
event
- The event for the node that was moved.
-
primitivesAdded
public void primitivesAdded(PrimitivesAddedEvent event)
Description copied from interface:DataSetListener
A bunch of primitives were added into the DataSet, or existing deleted/invisible primitives were resurrected.- Specified by:
primitivesAdded
in interfaceDataSetListener
- Parameters:
event
- An event for an collection of newly-visible primitives
-
primitivesRemoved
public void primitivesRemoved(PrimitivesRemovedEvent event)
Description copied from interface:DataSetListener
A bunch of primitives were removed from the DataSet, or preexisting primitives were marked as deleted.- Specified by:
primitivesRemoved
in interfaceDataSetListener
- Parameters:
event
- An event for an collection of newly-invisible primitives
-
relationMembersChanged
public void relationMembersChanged(RelationMembersChangedEvent event)
Description copied from interface:DataSetListener
A relation's members have changed.- Specified by:
relationMembersChanged
in interfaceDataSetListener
- Parameters:
event
- The event for the relation that was modified.
-
tagsChanged
public void tagsChanged(TagsChangedEvent event)
Description copied from interface:DataSetListener
There was some change in the tag set of a primitive. It can have been a tag addition, tag removal or change in tag value.- Specified by:
tagsChanged
in interfaceDataSetListener
- Parameters:
event
- the event for the primitive, whose tags were affected.
-
wayNodesChanged
public void wayNodesChanged(WayNodesChangedEvent event)
Description copied from interface:DataSetListener
A way's node list was changed.- Specified by:
wayNodesChanged
in interfaceDataSetListener
- Parameters:
event
- The event for the way that was modified.
-
otherDatasetChange
public void otherDatasetChange(AbstractDatasetChangedEvent event)
Description copied from interface:DataSetListener
Minor dataset change, currently only changeset id changed is supported, but can be extended in future.- Specified by:
otherDatasetChange
in interfaceDataSetListener
- Parameters:
event
- the event for data modification
-
addMemberModelListener
public void addMemberModelListener(IMemberModelListener listener)
Add a new member model listener.- Parameters:
listener
- member model listener to add
-
removeMemberModelListener
public void removeMemberModelListener(IMemberModelListener listener)
Remove a member model listener.- Parameters:
listener
- member model listener to remove
-
fireMakeMemberVisible
protected void fireMakeMemberVisible(int index)
-
populate
public void populate(Relation relation)
Populates this model from the given relation.- Parameters:
relation
- relation
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCount
in interfacejavax.swing.table.TableModel
-
getRowCount
public int getRowCount()
Description copied from interface:ReorderableTableModel
Returns the number of rows in the list/table.- Specified by:
getRowCount
in interfaceReorderableTableModel<RelationMember>
- Specified by:
getRowCount
in interfacejavax.swing.table.TableModel
- Returns:
- the number of rows in the list/table
- See Also:
ListModel.getSize()
,TableModel.getRowCount()
-
getValueAt
public java.lang.Object getValueAt(int rowIndex, int columnIndex)
- Specified by:
getValueAt
in interfacejavax.swing.table.TableModel
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
- Specified by:
isCellEditable
in interfacejavax.swing.table.TableModel
- Overrides:
isCellEditable
in classjavax.swing.table.AbstractTableModel
-
setValueAt
public void setValueAt(java.lang.Object value, int rowIndex, int columnIndex)
- Specified by:
setValueAt
in interfacejavax.swing.table.TableModel
- Overrides:
setValueAt
in classjavax.swing.table.AbstractTableModel
-
getReferredPrimitive
public OsmPrimitive getReferredPrimitive(int idx)
Description copied from interface:OsmPrimitivesTableModel
Gets the primitive at a given row index- Specified by:
getReferredPrimitive
in interfaceOsmPrimitivesTableModel
- Parameters:
idx
- The row- Returns:
- The primitive in that row
-
move
public boolean move(int delta, int... selectedRows)
Description copied from interface:ReorderableTableModel
Move selected rows by any number of positions, if possible.- Specified by:
move
in interfaceReorderableTableModel<RelationMember>
- Parameters:
delta
- negative or positive deltaselectedRows
- rows to move- Returns:
true
if the move was performed- See Also:
ReorderableTableModel.canMove(int)
-
remove
public void remove(int... selectedRows)
Remove selected rows, if possible.- Parameters:
selectedRows
- rows to remove- See Also:
canRemove(int...)
-
canRemove
public boolean canRemove(int... rows)
Checks that a range of rows can be removed.- Parameters:
rows
- indexes of rows to remove- Returns:
true
if rows can be removed
-
getSelectionModel
public javax.swing.DefaultListSelectionModel getSelectionModel()
Description copied from interface:ReorderableTableModel
Returns the selection model.- Specified by:
getSelectionModel
in interfaceReorderableTableModel<RelationMember>
- Returns:
- the selection model (never null)
- See Also:
JList.getSelectionModel()
,JTable.getSelectionModel()
-
getValue
public RelationMember getValue(int index)
Description copied from interface:ReorderableModel
Get object value at given index.- Specified by:
getValue
in interfaceReorderableModel<RelationMember>
- Parameters:
index
- index- Returns:
- object value at given index
-
setValue
public RelationMember setValue(int index, RelationMember value)
Description copied from interface:ReorderableModel
Set object value at given index.- Specified by:
setValue
in interfaceReorderableModel<RelationMember>
- Parameters:
index
- indexvalue
- new value- Returns:
- the value previously at the specified position
-
removeMembersReferringTo
public void removeMembersReferringTo(java.util.List<? extends OsmPrimitive> primitives)
Remove members referring to the given list of primitives.- Parameters:
primitives
- list of OSM primitives
-
applyToRelation
public void applyToRelation(Relation relation)
Applies this member model to the given relation.- Parameters:
relation
- relation
-
hasSameMembersAs
public boolean hasSameMembersAs(Relation relation)
Determines if this model has the same members as the given relation.- Parameters:
relation
- relation- Returns:
true
if this model has the same members asrelation
-
getIncompleteMemberPrimitives
public java.util.Set<OsmPrimitive> getIncompleteMemberPrimitives()
Replies the set of incomplete primitives- Returns:
- the set of incomplete primitives
-
getSelectedIncompleteMemberPrimitives
public java.util.Set<OsmPrimitive> getSelectedIncompleteMemberPrimitives()
Replies the set of selected incomplete primitives- Returns:
- the set of selected incomplete primitives
-
hasIncompleteMembers
public boolean hasIncompleteMembers()
Replies true if at least one the relation members is incomplete- Returns:
- true if at least one the relation members is incomplete
-
hasIncompleteSelectedMembers
public boolean hasIncompleteSelectedMembers()
Replies true if at least one of the selected members is incomplete- Returns:
- true if at least one of the selected members is incomplete
-
addMembersAtIndex
private void addMembersAtIndex(java.util.List<? extends OsmPrimitive> primitives, int index)
-
getRelationMemberForPrimitive
RelationMember getRelationMemberForPrimitive(OsmPrimitive primitive)
-
addMembersAtIndexKeepingOldSelection
void addMembersAtIndexKeepingOldSelection(java.lang.Iterable<RelationMember> newMembers, int index)
-
addMembersAtBeginning
public void addMembersAtBeginning(java.util.List<? extends OsmPrimitive> primitives)
-
addMembersAtEnd
public void addMembersAtEnd(java.util.List<? extends OsmPrimitive> primitives)
-
addMembersBeforeIdx
public void addMembersBeforeIdx(java.util.List<? extends OsmPrimitive> primitives, int idx)
-
addMembersAfterIdx
public void addMembersAfterIdx(java.util.List<? extends OsmPrimitive> primitives, int idx)
-
getNumMembersWithPrimitive
public int getNumMembersWithPrimitive(OsmPrimitive primitive)
Replies the number of members which refer to a particular primitive- Parameters:
primitive
- the primitive- Returns:
- the number of members which refer to a particular primitive
-
updateRole
public void updateRole(int[] idx, java.lang.String role)
updates the role of the members given by the indices inidx
- Parameters:
idx
- the array of indicesrole
- the new role
-
getSelectedMembers
public java.util.Collection<RelationMember> getSelectedMembers()
Get the currently selected relation members- Returns:
- a collection with the currently selected relation members
-
getSelectedChildPrimitives
public java.util.Collection<OsmPrimitive> getSelectedChildPrimitives()
Replies the set of selected referrers. Never null, but may be empty.- Returns:
- the set of selected referrers
-
getChildPrimitives
public java.util.Set<OsmPrimitive> getChildPrimitives(java.util.Collection<? extends OsmPrimitive> referenceSet)
Replies the set of selected referrers. Never null, but may be empty.- Parameters:
referenceSet
- reference set- Returns:
- the set of selected referrers
-
setSelectedMembers
public void setSelectedMembers(java.util.Collection<RelationMember> selectedMembers)
Selects the members in the collection selectedMembers- Parameters:
selectedMembers
- the collection of selected members
-
setSelectedMembersIdx
public void setSelectedMembersIdx(java.util.Collection<java.lang.Integer> selectedIndices)
Selects the members in the collection selectedIndices- Parameters:
selectedIndices
- the collection of selected member indices
-
addToSelectedMembers
private int addToSelectedMembers(java.util.BitSet selectedIndices)
Add one or more members indices to the selection. Detect groups of consecutive indices. Only one costly call of addSelectionInterval is performed for each group- Parameters:
selectedIndices
- selected indices as a bitset- Returns:
- number of groups
-
isEditableRelation
public boolean isEditableRelation(int index)
Replies true if the index-th relation members refers to an editable relation, i.e. a relation which is not incomplete.- Parameters:
index
- the index- Returns:
- true, if the index-th relation members refers to an editable relation, i.e. a relation which is not incomplete
-
hasMembersReferringTo
public static boolean hasMembersReferringTo(java.util.Collection<RelationMember> members, java.util.Collection<OsmPrimitive> primitives)
Replies true if there is at least one relation member given asmembers
which refers to at least on the primitives inprimitives
.- Parameters:
members
- the membersprimitives
- the collection of primitives- Returns:
- true if there is at least one relation member in this model
which refers to at least on the primitives in
primitives
; false otherwise
-
hasMembersReferringTo
public boolean hasMembersReferringTo(java.util.Collection<OsmPrimitive> primitives)
Replies true if there is at least one relation member in this model which refers to at least on the primitives inprimitives
.- Parameters:
primitives
- the collection of primitives- Returns:
- true if there is at least one relation member in this model
which refers to at least on the primitives in
primitives
; false otherwise
-
selectMembersReferringTo
public void selectMembersReferringTo(java.util.Collection<? extends OsmPrimitive> primitives)
Selects all members which refer toOsmPrimitive
s in the collectionsprimitives
. Does nothing is primitives is null.- Parameters:
primitives
- the collection of primitives
-
isInJosmSelection
public boolean isInJosmSelection(OsmPrimitive primitive)
Replies true ifprimitive
is currently selected in the layer this model is attached to- Parameters:
primitive
- the primitive- Returns:
- true if
primitive
is currently selected in the layer this model is attached to, false otherwise
-
sort
public void sort()
Sort the selected relation members by the way they are linked.- Specified by:
sort
in interfaceSortableModel<RelationMember>
-
sortBelow
public void sortBelow()
Sort the selected relation members and all members below by the way they are linked.
-
getWayConnection
WayConnectionType getWayConnection(int i)
-
tableChanged
public void tableChanged(javax.swing.event.TableModelEvent e)
- Specified by:
tableChanged
in interfacejavax.swing.event.TableModelListener
-
invalidateConnectionType
private void invalidateConnectionType()
-
reverse
public void reverse()
Reverse the relation members.- Specified by:
reverse
in interfaceSortableModel<RelationMember>
-
-