Class TagEditorModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- org.openstreetmap.josm.gui.tagging.TagEditorModel
-
- All Implemented Interfaces:
Serializable
,TableModel
- Direct Known Subclasses:
UploadDialogModel
public class TagEditorModel extends AbstractTableModel
TagEditorModel is a table model to use withTagEditorPanel
.- Since:
- 1762
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TagEditorModel.EndEditListener
A listener that is called whenever the cells may be updated from outside the editor and the editor should thus be committed.(package private) class
TagEditorModel.SelectionStateMemento
-
Field Summary
Fields Modifier and Type Field Description private DefaultListSelectionModel
colSelectionModel
private boolean
dirty
indicates whether the model is dirtyprivate TagEditorModel.EndEditListener
endEditListener
private OsmPrimitive
primitive
static String
PROP_DIRTY
The dirty property.private PropertyChangeSupport
propChangeSupport
private DefaultListSelectionModel
rowSelectionModel
protected List<TagModel>
tags
the list holding the tags-
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description TagEditorModel()
Creates a new tag editor model.TagEditorModel(DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel)
Creates a new tag editor model.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String name, String value)
adds a tag given by a name/value pair to the tag editor model.void
add(TagModel tag)
adds a tag to the modelvoid
addPropertyChangeListener(PropertyChangeListener listener)
Adds property change listener.void
appendNewTag()
creates a new tag and appends it to the modelvoid
applyToPrimitive(Tagged primitive)
applies the current state of the tag editor model to a primitiveprivate Map<String,String>
applyToTags(boolean keepEmpty)
applies the current state of the tag editor model to a map of tagsvoid
clear()
removes all tags in the modelprotected void
commitPendingEdit()
protected Command
createDeleteTagsCommand(Collection<OsmPrimitive> primitives)
protected Command
createUpdateTagCommand(Collection<OsmPrimitive> primitives, TagModel tag)
void
delete(String name)
Deletes all tags with namename
void
deleteTagNames(int... tagIndices)
deletes the names of the tags given by tagIndicesvoid
deleteTags(int... tagIndices)
deletes the tags given by tagIndicesvoid
deleteTagValues(int... tagIndices)
deletes the values of the tags given by tagIndicesvoid
ensureOneTag()
makes sure the model includes at least one (empty) tagprotected void
fireDirtyStateChanged(boolean oldValue, boolean newValue)
TagEditorModel
forPrimitive(OsmPrimitive primitive)
Makes this TagEditorModel specific to a given OSM primitive.TagModel
get(int idx)
Gets a tag rowTagModel
get(String name)
replies the tag with namename
; null, if no such tag existsint
getColumnCount()
DefaultListSelectionModel
getColumnSelectionModel()
Replies the column selection model used by this tag editor modelList<String>
getKeys()
replies the list of keys of the tags managed by this modelint
getRowCount()
DefaultListSelectionModel
getRowSelectionModel()
Replies the row selection model used by this tag editor modelTagCollection
getTagCollection()
Replies the tags in this tag editor model asTagCollection
.Collection<TaggingPresetType>
getTaggingPresetTypes()
Returns the list of tagging presets types to consider when updating the presets list panel.Map<String,String>
getTags()
Returns tags, without empty ones.Map<String,String>
getTags(boolean keepEmpty)
Returns tags.Object
getValueAt(int rowIndex, int columnIndex)
boolean
includesTag(String key)
checks whether the tag model includes a tag with a given keyvoid
initFromPrimitive(Tagged primitive)
initializes the model with the tags of an OSM primitivevoid
initFromTags(Map<String,String> tags)
Initializes the model with the tags of an OSM primitivevoid
initFromTags(TagCollection tags)
Initializes the model with the tags in a tag collection.boolean
isCellEditable(int row, int col)
boolean
isDirty()
replies true, if this model has been updatedvoid
prepend(TagModel tag)
Add a tag at the beginning of the table.void
removePropertyChangeListener(PropertyChangeListener listener)
Removes property change listener.protected void
setDirty(boolean newValue)
void
setEndEditListener(TagEditorModel.EndEditListener endEditListener)
Sets the listener that is notified when an edit should be aborted.void
setValueAt(Object value, int row, int col)
protected void
sort()
sorts the current tags according alphabetical order of namesvoid
updateTagName(TagModel tag, String newName)
updates the name of a tag and sets the dirty state to true if the new name is different from the old name.void
updateTags(List<Tag> tags)
Load tags from given listvoid
updateTagValue(TagModel tag, String newValue)
updates the value value of a tag and sets the dirty state to true if the new name is different from the old name-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getColumnName, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Field Detail
-
PROP_DIRTY
public static final String PROP_DIRTY
The dirty property. It is set whenever this table was changed
-
dirty
private boolean dirty
indicates whether the model is dirty
-
propChangeSupport
private final PropertyChangeSupport propChangeSupport
-
rowSelectionModel
private final DefaultListSelectionModel rowSelectionModel
-
colSelectionModel
private final DefaultListSelectionModel colSelectionModel
-
primitive
private transient OsmPrimitive primitive
-
endEditListener
private transient TagEditorModel.EndEditListener endEditListener
-
-
Constructor Detail
-
TagEditorModel
public TagEditorModel()
Creates a new tag editor model. Internally allocates two selection models for row selection and column selection. To create aJTable
with this model:TagEditorModel model = new TagEditorModel(); TagTable tbl = new TagTabel(model);
- See Also:
getRowSelectionModel()
,getColumnSelectionModel()
-
TagEditorModel
public TagEditorModel(DefaultListSelectionModel rowSelectionModel, DefaultListSelectionModel colSelectionModel)
Creates a new tag editor model.- Parameters:
rowSelectionModel
- the row selection model. Must not be null.colSelectionModel
- the column selection model. Must not be null.- Throws:
IllegalArgumentException
- ifrowSelectionModel
is nullIllegalArgumentException
- ifcolSelectionModel
is null
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Adds property change listener.- Parameters:
listener
- property change listener to add
-
getRowSelectionModel
public DefaultListSelectionModel getRowSelectionModel()
Replies the row selection model used by this tag editor model- Returns:
- the row selection model used by this tag editor model
-
getColumnSelectionModel
public DefaultListSelectionModel getColumnSelectionModel()
Replies the column selection model used by this tag editor model- Returns:
- the column selection model used by this tag editor model
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Removes property change listener.- Parameters:
listener
- property change listener to remove
-
fireDirtyStateChanged
protected void fireDirtyStateChanged(boolean oldValue, boolean newValue)
-
setDirty
protected void setDirty(boolean newValue)
-
getColumnCount
public int getColumnCount()
-
getRowCount
public int getRowCount()
-
getValueAt
public Object getValueAt(int rowIndex, int columnIndex)
-
setValueAt
public void setValueAt(Object value, int row, int col)
- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
-
clear
public void clear()
removes all tags in the model
-
add
public void add(TagModel tag)
adds a tag to the model- Parameters:
tag
- the tag. Must not be null.- Throws:
IllegalArgumentException
- if tag is null
-
prepend
public void prepend(TagModel tag)
Add a tag at the beginning of the table.- Parameters:
tag
- The tag to add- Throws:
IllegalArgumentException
- if tag is null- See Also:
add(TagModel)
-
add
public void add(String name, String value)
adds a tag given by a name/value pair to the tag editor model. If there is no tag with namename
yet, a newTagModel
is created and append to this model. If there is a tag with namename
,value
is merged to the list of values for this tag.- Parameters:
name
- the name; converted to "" if nullvalue
- the value; converted to "" if null
-
get
public TagModel get(String name)
replies the tag with namename
; null, if no such tag exists- Parameters:
name
- the tag name- Returns:
- the tag with name
name
; null, if no such tag exists
-
get
public TagModel get(int idx)
Gets a tag row- Parameters:
idx
- The index of the row- Returns:
- The tag model for that row
-
isCellEditable
public boolean isCellEditable(int row, int col)
- Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
-
deleteTagNames
public void deleteTagNames(int... tagIndices)
deletes the names of the tags given by tagIndices- Parameters:
tagIndices
- a list of tag indices
-
deleteTagValues
public void deleteTagValues(int... tagIndices)
deletes the values of the tags given by tagIndices- Parameters:
tagIndices
- the lit of tag indices
-
delete
public void delete(String name)
Deletes all tags with namename
- Parameters:
name
- the name. Ignored if null.
-
deleteTags
public void deleteTags(int... tagIndices)
deletes the tags given by tagIndices- Parameters:
tagIndices
- the list of tag indices
-
appendNewTag
public void appendNewTag()
creates a new tag and appends it to the model
-
ensureOneTag
public void ensureOneTag()
makes sure the model includes at least one (empty) tag
-
initFromPrimitive
public void initFromPrimitive(Tagged primitive)
initializes the model with the tags of an OSM primitive- Parameters:
primitive
- the OSM primitive
-
initFromTags
public void initFromTags(Map<String,String> tags)
Initializes the model with the tags of an OSM primitive- Parameters:
tags
- the tags of an OSM primitive
-
initFromTags
public void initFromTags(TagCollection tags)
Initializes the model with the tags in a tag collection. Removes all tags iftags
is null.- Parameters:
tags
- the tags
-
applyToPrimitive
public void applyToPrimitive(Tagged primitive)
applies the current state of the tag editor model to a primitive- Parameters:
primitive
- the primitive
-
applyToTags
private Map<String,String> applyToTags(boolean keepEmpty)
applies the current state of the tag editor model to a map of tags- Parameters:
keepEmpty
-true
to keep empty tags- Returns:
- the map of key/value pairs
-
getTags
public Map<String,String> getTags()
Returns tags, without empty ones.- Returns:
- not-empty tags
-
getTags
public Map<String,String> getTags(boolean keepEmpty)
Returns tags.- Parameters:
keepEmpty
-true
to keep empty tags- Returns:
- tags
-
getTagCollection
public TagCollection getTagCollection()
Replies the tags in this tag editor model asTagCollection
.- Returns:
- the tags in this tag editor model as
TagCollection
-
includesTag
public boolean includesTag(String key)
checks whether the tag model includes a tag with a given key- Parameters:
key
- the key- Returns:
- true, if the tag model includes the tag; false, otherwise
-
createUpdateTagCommand
protected Command createUpdateTagCommand(Collection<OsmPrimitive> primitives, TagModel tag)
-
createDeleteTagsCommand
protected Command createDeleteTagsCommand(Collection<OsmPrimitive> primitives)
-
getKeys
public List<String> getKeys()
replies the list of keys of the tags managed by this model- Returns:
- the list of keys managed by this model
-
sort
protected void sort()
sorts the current tags according alphabetical order of names
-
updateTagName
public void updateTagName(TagModel tag, String newName)
updates the name of a tag and sets the dirty state to true if the new name is different from the old name.- Parameters:
tag
- the tagnewName
- the new name
-
updateTagValue
public void updateTagValue(TagModel tag, String newValue)
updates the value value of a tag and sets the dirty state to true if the new name is different from the old name- Parameters:
tag
- the tagnewValue
- the new value
-
updateTags
public void updateTags(List<Tag> tags)
Load tags from given list- Parameters:
tags
- - the list
-
isDirty
public boolean isDirty()
replies true, if this model has been updated- Returns:
- true, if this model has been updated
-
getTaggingPresetTypes
public Collection<TaggingPresetType> getTaggingPresetTypes()
Returns the list of tagging presets types to consider when updating the presets list panel. By default returns type of associated primitive or empty set.- Returns:
- the list of tagging presets types to consider when updating the presets list panel
- Since:
- 9588
- See Also:
forPrimitive(org.openstreetmap.josm.data.osm.OsmPrimitive)
,TaggingPresetType.forPrimitive(org.openstreetmap.josm.data.osm.IPrimitive)
-
forPrimitive
public TagEditorModel forPrimitive(OsmPrimitive primitive)
Makes this TagEditorModel specific to a given OSM primitive.- Parameters:
primitive
- primitive to consider- Returns:
this
- Since:
- 9588
-
setEndEditListener
public void setEndEditListener(TagEditorModel.EndEditListener endEditListener)
Sets the listener that is notified when an edit should be aborted.- Parameters:
endEditListener
- The listener to be notified when editing should be aborted.
-
commitPendingEdit
protected void commitPendingEdit()
-
-