Class AutoCompletionManager
- java.lang.Object
-
- org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager
-
- All Implemented Interfaces:
DataSetListener
public class AutoCompletionManager extends Object implements DataSetListener
AutoCompletionManager holds a cache of keys with a list of possible auto completion values for each key. Each DataSet can be assigned one AutoCompletionManager instance such that- any key used in a tag in the data set is part of the key list in the cache
- any value used in a tag for a specific key is part of the autocompletion list of this key
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AutoCompletionManager.UserInputTag
Data class to remember tags that the user has entered.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
dirty
If the dirty flag is set true, a rebuild is necessary.protected DataSet
ds
The data set that is managedprivate static Map<DataSet,AutoCompletionManager>
INSTANCES
(package private) static Set<String>
PRESET_ROLE_CACHE
the same as roleCache but for the preset roles can be accessed directly(package private) static MultiMap<String,String>
PRESET_TAG_CACHE
the same as tagCache but for the preset keys and values can be accessed directlyprotected Set<String>
roleCache
the cached list of member roles only accessed by getRoleCache(), rebuild() and cacheRelationMemberRoles() use getRoleCache() accessorprotected MultiMap<String,String>
tagCache
the cached tags given by a tag key and a list of values for this tag only accessed by getTagCache(), rebuild() and cachePrimitiveTags() use getTagCache() accessor(package private) static Set<AutoCompletionManager.UserInputTag>
USER_INPUT_TAG_CACHE
Cache for tags that have been entered by the user.
-
Constructor Summary
Constructors Constructor Description AutoCompletionManager(DataSet ds)
Constructs a newAutoCompletionManager
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cachePrimitives(Collection<? extends OsmPrimitive> primitives)
protected void
cachePrimitiveTags(OsmPrimitive primitive)
make sure, the keys and values of all tags held by primitive are in the auto completion cacheprotected void
cacheRelationMemberRoles(Relation relation)
Caches all member roles of the relationrelation
void
dataChanged(DataChangedEvent event)
Called after big changes in dataset.List<AutoCompletionItem>
getAllForKeys(List<String> keys)
Returns all cachedAutoCompletionItem
s for given keys.protected List<String>
getDataKeys()
replies the keys held by the cacheprotected List<String>
getDataValues(String key)
replies the auto completion values allowed for a specific key.List<String>
getMemberRoles()
Replies the list of member rolesprotected Set<String>
getRoleCache()
protected MultiMap<String,String>
getTagCache()
AutoCompletionSet
getTagKeys()
Returns the currently cached tag keys.List<AutoCompletionItem>
getTagKeys(Comparator<AutoCompletionItem> comparator)
Returns the currently cached tag keys.AutoCompletionSet
getTagValues(String key)
Returns the currently cached tag values for a given tag key.List<AutoCompletionItem>
getTagValues(String key, Comparator<AutoCompletionItem> comparator)
Returns the currently cached tag values for a given tag key.AutoCompletionSet
getTagValues(List<String> keys)
Returns the currently cached tag values for a given list of tag keys.List<AutoCompletionItem>
getTagValues(List<String> keys, Comparator<AutoCompletionItem> comparator)
Returns the currently cached tag values for a given list of tag keys.protected Collection<String>
getUserInputKeys()
protected static Collection<String>
getUserInputValues(String key)
void
nodeMoved(NodeMovedEvent event)
A node's coordinates were modified.static AutoCompletionManager
of(DataSet dataSet)
Returns theAutoCompletionManager
for the given data set.void
otherDatasetChange(AbstractDatasetChangedEvent event)
Minor dataset change, currently only changeset id changed is supported, but can be extended in future.void
populateWithKeys(AutoCompletionList list)
Populates the anAutoCompletionList
with the currently cached tag keysvoid
populateWithMemberRoles(AutoCompletionList list)
Populates theAutoCompletionList
with the currently cached member roles.void
populateWithMemberRoles(AutoCompletionList list, Relation r)
Populates theAutoCompletionList
with the roles used in this relation plus the ones defined in its applicable presets, if any.void
populateWithTagValues(AutoCompletionList list, String key)
Populates the anAutoCompletionList
with the currently cached values for a tagvoid
populateWithTagValues(AutoCompletionList list, List<String> keys)
Populates theAutoCompletionList
with the currently cached values for some given tagsvoid
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.protected void
rebuild()
initializes the cache from the primitives in the datasetprivate AutoCompletionManager
registerListeners()
void
relationMembersChanged(RelationMembersChangedEvent event)
A relation's members have changed.static void
rememberUserInput(String key, String value, boolean defaultKey)
Remembers user input for the given key/value.private static List<AutoCompletionItem>
setToList(AutoCompletionSet set, Comparator<AutoCompletionItem> comparator)
void
tagsChanged(TagsChangedEvent event)
There was some change in the tag set of a primitive.void
wayNodesChanged(WayNodesChangedEvent event)
A way's node list was changed.
-
-
-
Field Detail
-
dirty
protected boolean dirty
If the dirty flag is set true, a rebuild is necessary.
-
tagCache
protected MultiMap<String,String> tagCache
the cached tags given by a tag key and a list of values for this tag only accessed by getTagCache(), rebuild() and cachePrimitiveTags() use getTagCache() accessor
-
PRESET_TAG_CACHE
static final MultiMap<String,String> PRESET_TAG_CACHE
the same as tagCache but for the preset keys and values can be accessed directly
-
USER_INPUT_TAG_CACHE
static final Set<AutoCompletionManager.UserInputTag> USER_INPUT_TAG_CACHE
Cache for tags that have been entered by the user.
-
roleCache
protected Set<String> roleCache
the cached list of member roles only accessed by getRoleCache(), rebuild() and cacheRelationMemberRoles() use getRoleCache() accessor
-
PRESET_ROLE_CACHE
static final Set<String> PRESET_ROLE_CACHE
the same as roleCache but for the preset roles can be accessed directly
-
INSTANCES
private static final Map<DataSet,AutoCompletionManager> INSTANCES
-
-
Constructor Detail
-
AutoCompletionManager
public AutoCompletionManager(DataSet ds)
Constructs a newAutoCompletionManager
.- Parameters:
ds
- data set- Throws:
NullPointerException
- if ds is null
-
-
Method Detail
-
getTagCache
protected MultiMap<String,String> getTagCache()
-
getRoleCache
protected Set<String> getRoleCache()
-
rebuild
protected void rebuild()
initializes the cache from the primitives in the dataset
-
cachePrimitives
protected void cachePrimitives(Collection<? extends OsmPrimitive> primitives)
-
cachePrimitiveTags
protected void cachePrimitiveTags(OsmPrimitive primitive)
make sure, the keys and values of all tags held by primitive are in the auto completion cache- Parameters:
primitive
- an OSM primitive
-
cacheRelationMemberRoles
protected void cacheRelationMemberRoles(Relation relation)
Caches all member roles of the relationrelation
- Parameters:
relation
- the relation
-
rememberUserInput
public static void rememberUserInput(String key, String value, boolean defaultKey)
Remembers user input for the given key/value.- Parameters:
key
- Tag keyvalue
- Tag valuedefaultKey
- true, if the key was not really entered by the user, e.g. for preset text fields
-
getDataKeys
protected List<String> getDataKeys()
replies the keys held by the cache- Returns:
- the list of keys held by the cache
-
getUserInputKeys
protected Collection<String> getUserInputKeys()
-
getDataValues
protected List<String> getDataValues(String key)
replies the auto completion values allowed for a specific key. Replies an empty list if key is null or if key is not ingetTagKeys()
.- Parameters:
key
- OSM key- Returns:
- the list of auto completion values
-
getUserInputValues
protected static Collection<String> getUserInputValues(String key)
-
getMemberRoles
public List<String> getMemberRoles()
Replies the list of member roles- Returns:
- the list of member roles
-
populateWithMemberRoles
public void populateWithMemberRoles(AutoCompletionList list)
Populates theAutoCompletionList
with the currently cached member roles.- Parameters:
list
- the list to populate
-
populateWithMemberRoles
public void populateWithMemberRoles(AutoCompletionList list, Relation r)
Populates theAutoCompletionList
with the roles used in this relation plus the ones defined in its applicable presets, if any. If the relation type is unknown, then all the roles known globally will be added, as inpopulateWithMemberRoles(AutoCompletionList)
.- Parameters:
list
- the list to populater
- the relation to get roles from- Throws:
IllegalArgumentException
- if list is null- Since:
- 7556
-
populateWithKeys
public void populateWithKeys(AutoCompletionList list)
Populates the anAutoCompletionList
with the currently cached tag keys- Parameters:
list
- the list to populate
-
populateWithTagValues
public void populateWithTagValues(AutoCompletionList list, String key)
Populates the anAutoCompletionList
with the currently cached values for a tag- Parameters:
list
- the list to populatekey
- the tag key
-
populateWithTagValues
public void populateWithTagValues(AutoCompletionList list, List<String> keys)
Populates theAutoCompletionList
with the currently cached values for some given tags- Parameters:
list
- the list to populatekeys
- the tag keys
-
setToList
private static List<AutoCompletionItem> setToList(AutoCompletionSet set, Comparator<AutoCompletionItem> comparator)
-
getAllForKeys
public List<AutoCompletionItem> getAllForKeys(List<String> keys)
Returns all cachedAutoCompletionItem
s for given keys.- Parameters:
keys
- retrieve the items for these keys- Returns:
- the currently cached items, sorted by priority and alphabet
- Since:
- 18221
-
getTagKeys
public AutoCompletionSet getTagKeys()
Returns the currently cached tag keys.- Returns:
- a set of tag keys
- Since:
- 12859
-
getTagKeys
public List<AutoCompletionItem> getTagKeys(Comparator<AutoCompletionItem> comparator)
Returns the currently cached tag keys.- Parameters:
comparator
- the custom comparator used to sort the list- Returns:
- a list of tag keys
- Since:
- 12859
-
getTagValues
public AutoCompletionSet getTagValues(String key)
Returns the currently cached tag values for a given tag key.- Parameters:
key
- the tag key- Returns:
- a set of tag values
- Since:
- 12859
-
getTagValues
public List<AutoCompletionItem> getTagValues(String key, Comparator<AutoCompletionItem> comparator)
Returns the currently cached tag values for a given tag key.- Parameters:
key
- the tag keycomparator
- the custom comparator used to sort the list- Returns:
- a list of tag values
- Since:
- 12859
-
getTagValues
public AutoCompletionSet getTagValues(List<String> keys)
Returns the currently cached tag values for a given list of tag keys.- Parameters:
keys
- the tag keys- Returns:
- a set of tag values
- Since:
- 12859
-
getTagValues
public List<AutoCompletionItem> getTagValues(List<String> keys, Comparator<AutoCompletionItem> comparator)
Returns the currently cached tag values for a given list of tag keys.- Parameters:
keys
- the tag keyscomparator
- the custom comparator used to sort the list- Returns:
- a set of tag values
- Since:
- 12859
-
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
-
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.
-
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.
-
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.
-
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.
-
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
-
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
-
registerListeners
private AutoCompletionManager registerListeners()
-
of
public static AutoCompletionManager of(DataSet dataSet)
Returns theAutoCompletionManager
for the given data set.- Parameters:
dataSet
- the data set- Returns:
- the
AutoCompletionManager
for the given data set - Since:
- 12758
-
-