org.openstreetmap.josm.gui.tagging.ac
Class AutoCompletionManager

java.lang.Object
  extended by org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager
All Implemented Interfaces:
DataSetListener

public class AutoCompletionManager
extends java.lang.Object
implements DataSetListener

AutoCompletionManager holds a cache of keys with a list of possible auto completion values for each key. Each DataSet is assigned one AutoCompletionManager instance such that

  1. any key used in a tag in the data set is part of the key list in the cache
  2. any value used in a tag for a specific key is part of the autocompletion list of this key
Building up auto completion lists should not slow down tabbing from input field to input field. Looping through the complete data set in order to build up the auto completion list for a specific input field is not efficient enough, hence this cache. TODO: respect the relation type for member role autocompletion


Field Summary
protected  boolean dirty
          If the dirty flag is set true, a rebuild is necessary.
protected  DataSet ds
          The data set that is managed
protected static java.util.Set<java.lang.String> presetRoleCache
          the same as roleCache but for the preset roles can be accessed directly
protected static MultiMap<java.lang.String,java.lang.String> presetTagCache
          the same as tagCache but for the preset keys and values can be accessed directly
protected  java.util.Set<java.lang.String> roleCache
          the cached list of member roles only accessed by getRoleCache(), rebuild() and cacheRelationMemberRoles() use getRoleCache() accessor
protected  MultiMap<java.lang.String,java.lang.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
 
Constructor Summary
AutoCompletionManager(DataSet ds)
           
 
Method Summary
static void cachePresets(java.util.Collection<TaggingPreset> presets)
          Initialize the cache for presets.
protected  void cachePrimitives(java.util.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 cache
protected  void cacheRelationMemberRoles(Relation relation)
          Caches all member roles of the relation relation
 void dataChanged(DataChangedEvent event)
          Called after big changes in dataset.
protected  java.util.List<java.lang.String> getDataKeys()
          replies the keys held by the cache
protected  java.util.List<java.lang.String> getDataValues(java.lang.String key)
          replies the auto completion values allowed for a specific key.
 java.util.List<AutoCompletionListItem> getKeys()
          Returns the currently cached tag keys.
 java.util.List<java.lang.String> getMemberRoles()
          Replies the list of member roles
protected  java.util.List<java.lang.String> getPresetKeys()
           
protected static java.util.List<java.lang.String> getPresetValues(java.lang.String key)
           
protected  java.util.Set<java.lang.String> getRoleCache()
           
protected  MultiMap<java.lang.String,java.lang.String> getTagCache()
           
 java.util.List<AutoCompletionListItem> getValues(java.util.List<java.lang.String> keys)
          Returns the currently cached tag values for a given list of tag keys.
 java.util.List<AutoCompletionListItem> getValues(java.lang.String key)
          Returns the currently cached tag values for a given tag key.
 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 populateWithKeys(AutoCompletionList list)
          Populates the an AutoCompletionList with the currently cached tag keys
 void populateWithMemberRoles(AutoCompletionList list)
          Populates the an AutoCompletionList with the currently cached member roles.
 void populateWithTagValues(AutoCompletionList list, java.util.List<java.lang.String> keys)
          Populates the an AutoCompletionList with the currently cached values for some given tags
 void populateWithTagValues(AutoCompletionList list, java.lang.String key)
          Populates the an AutoCompletionList with the currently cached values for a tag
 void primitivesAdded(PrimitivesAddedEvent event)
          Implementation of the DataSetListener interface
 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 dataset
 void relationMembersChanged(RelationMembersChangedEvent event)
          A relation's members have changed.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dirty

protected boolean dirty
If the dirty flag is set true, a rebuild is necessary.


ds

protected DataSet ds
The data set that is managed


tagCache

protected MultiMap<java.lang.String,java.lang.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


presetTagCache

protected static final MultiMap<java.lang.String,java.lang.String> presetTagCache
the same as tagCache but for the preset keys and values can be accessed directly


roleCache

protected java.util.Set<java.lang.String> roleCache
the cached list of member roles only accessed by getRoleCache(), rebuild() and cacheRelationMemberRoles() use getRoleCache() accessor


presetRoleCache

protected static final java.util.Set<java.lang.String> presetRoleCache
the same as roleCache but for the preset roles can be accessed directly

Constructor Detail

AutoCompletionManager

public AutoCompletionManager(DataSet ds)
Method Detail

getTagCache

protected MultiMap<java.lang.String,java.lang.String> getTagCache()

getRoleCache

protected java.util.Set<java.lang.String> getRoleCache()

rebuild

protected void rebuild()
initializes the cache from the primitives in the dataset


cachePrimitives

protected void cachePrimitives(java.util.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 relation relation

Parameters:
relation - the relation

cachePresets

public static void cachePresets(java.util.Collection<TaggingPreset> presets)
Initialize the cache for presets. This is done only once.


getDataKeys

protected java.util.List<java.lang.String> getDataKeys()
replies the keys held by the cache

Returns:
the list of keys held by the cache

getPresetKeys

protected java.util.List<java.lang.String> getPresetKeys()

getDataValues

protected java.util.List<java.lang.String> getDataValues(java.lang.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 in getKeys().

Parameters:
key -
Returns:
the list of auto completion values

getPresetValues

protected static java.util.List<java.lang.String> getPresetValues(java.lang.String key)

getMemberRoles

public java.util.List<java.lang.String> getMemberRoles()
Replies the list of member roles

Returns:
the list of member roles

populateWithMemberRoles

public void populateWithMemberRoles(AutoCompletionList list)
Populates the an AutoCompletionList with the currently cached member roles.

Parameters:
list - the list to populate

populateWithKeys

public void populateWithKeys(AutoCompletionList list)
Populates the an AutoCompletionList with the currently cached tag keys

Parameters:
list - the list to populate

populateWithTagValues

public void populateWithTagValues(AutoCompletionList list,
                                  java.lang.String key)
Populates the an AutoCompletionList with the currently cached values for a tag

Parameters:
list - the list to populate
key - the tag key

populateWithTagValues

public void populateWithTagValues(AutoCompletionList list,
                                  java.util.List<java.lang.String> keys)
Populates the an AutoCompletionList with the currently cached values for some given tags

Parameters:
list - the list to populate
keys - the tag keys

getKeys

public java.util.List<AutoCompletionListItem> getKeys()
Returns the currently cached tag keys.

Returns:
a list of tag keys

getValues

public java.util.List<AutoCompletionListItem> getValues(java.lang.String key)
Returns the currently cached tag values for a given tag key.

Parameters:
key - the tag key
Returns:
a list of tag values

getValues

public java.util.List<AutoCompletionListItem> getValues(java.util.List<java.lang.String> keys)
Returns the currently cached tag values for a given list of tag keys.

Parameters:
keys - the tag keys
Returns:
a list of tag values

primitivesAdded

public void primitivesAdded(PrimitivesAddedEvent event)
Implementation of the DataSetListener interface

Specified by:
primitivesAdded in interface DataSetListener

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 interface DataSetListener

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 interface DataSetListener

nodeMoved

public void nodeMoved(NodeMovedEvent event)
Description copied from interface: DataSetListener
A node's coordinates were modified.

Specified by:
nodeMoved in interface DataSetListener

wayNodesChanged

public void wayNodesChanged(WayNodesChangedEvent event)
Description copied from interface: DataSetListener
A way's node list was changed.

Specified by:
wayNodesChanged in interface DataSetListener

relationMembersChanged

public void relationMembersChanged(RelationMembersChangedEvent event)
Description copied from interface: DataSetListener
A relation's members have changed.

Specified by:
relationMembersChanged in interface DataSetListener

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 interface DataSetListener

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()), #dataChanged() is called.

Specified by:
dataChanged in interface DataSetListener


JOSM