Ignore:
Timestamp:
06.02.2010 17:37:52 (2 years ago)
Author:
bastiK
Message:

autocompletion: Always add the preset keys/values to the autocompletion list.
Does not apply to the Properties dialog, because it has a seperate implementation of the autocompletion feature.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionCache.java

    r2621 r2946  
    1010 
    1111import org.openstreetmap.josm.data.osm.OsmPrimitive; 
     12import org.openstreetmap.josm.data.osm.OsmUtils; 
    1213import org.openstreetmap.josm.data.osm.Relation; 
    1314import org.openstreetmap.josm.data.osm.RelationMember; 
     
    1516import org.openstreetmap.josm.gui.layer.Layer; 
    1617import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
     18import org.openstreetmap.josm.gui.tagging.TaggingPreset; 
     19import org.openstreetmap.josm.tools.MultiMap; 
    1720 
    1821/** 
     
    6770    } 
    6871 
    69     /** the cached tags give by a tag key and a list of values for this tag*/ 
    70     private HashMap<String, Set<String>> tagCache; 
     72    /** the cached tags given by a tag key and a list of values for this tag */ 
     73    private MultiMap<String, String> tagCache; 
     74    /**  the layer this cache is built for */ 
     75    private OsmDataLayer layer; 
     76    /** the same as tagCache but for the preset keys and values */ 
     77    private static MultiMap<String, String> presetTagCache = new MultiMap<String, String>(); 
    7178    /** the cached list of member roles */ 
    7279    private  Set<String> roleCache; 
    73     /**  the layer this cache is built for */ 
    74     private OsmDataLayer layer; 
    7580 
    7681    /** 
     
    7883     */ 
    7984    public AutoCompletionCache(OsmDataLayer layer) { 
    80         tagCache = new HashMap<String, Set<String>>(); 
     85        tagCache = new MultiMap<String, String>(); 
    8186        roleCache = new HashSet<String>(); 
    8287        this.layer = layer; 
     
    8590    public AutoCompletionCache() { 
    8691        this(null); 
    87     } 
    88  
    89     /** 
    90      * make sure, <code>key</code> is in the cache 
    91      * 
    92      * @param key  the key 
    93      */ 
    94     protected void cacheKey(String key) { 
    95         if (tagCache.containsKey(key)) 
    96             return; 
    97         tagCache.put(key, new HashSet<String>()); 
    98     } 
    99  
    100     /** 
    101      * make sure, value is one of the auto completion values allowed for key 
    102      * 
    103      * @param key the key 
    104      * @param value the value 
    105      */ 
    106     protected void cacheValue(String key, String value) { 
    107         cacheKey(key); 
    108         tagCache.get(key).add(value); 
    10992    } 
    11093 
     
    118101        for (String key: primitive.keySet()) { 
    119102            String value = primitive.get(key); 
    120             cacheValue(key, value); 
     103            tagCache.put(key, value); 
    121104        } 
    122105    } 
     
    141124     */ 
    142125    public void initFromDataSet() { 
    143         tagCache = new HashMap<String, Set<String>>(); 
     126        tagCache = new MultiMap<String, String>(); 
    144127        if (layer == null) 
    145128            return; 
     
    157140 
    158141    /** 
     142     * Initialize the cache for presets. This is done only once. 
     143     */ 
     144    public static void cachePresets(Collection<TaggingPreset> presets) { 
     145        for (final TaggingPreset p : presets) { 
     146            for (TaggingPreset.Item item : p.data) { 
     147                if (item instanceof TaggingPreset.Check) { 
     148                    TaggingPreset.Check ch = (TaggingPreset.Check) item; 
     149                    presetTagCache.put(ch.key, OsmUtils.falseval); 
     150                    presetTagCache.put(ch.key, OsmUtils.trueval); 
     151                } else if (item instanceof TaggingPreset.Combo) { 
     152                    TaggingPreset.Combo co = (TaggingPreset.Combo) item; 
     153                    for (String value : co.values.split(",")) { 
     154                        presetTagCache.put(co.key, value); 
     155                    } 
     156                } else if (item instanceof TaggingPreset.Key) { 
     157                    TaggingPreset.Key ky = (TaggingPreset.Key) item; 
     158                    presetTagCache.put(ky.key, ky.value); 
     159                } else if (item instanceof TaggingPreset.Text) { 
     160                    TaggingPreset.Text tt = (TaggingPreset.Text) item; 
     161                    presetTagCache.putVoid(tt.key); 
     162                    if (tt.default_ != null && !tt.default_.equals("")) { 
     163                        presetTagCache.put(tt.key, tt.default_); 
     164                    } 
     165                } 
     166            } 
     167        } 
     168    } 
     169     
     170    /** 
    159171     * replies the keys held by the cache 
    160172     * 
    161173     * @return the list of keys held by the cache 
    162174     */ 
    163     public List<String> getKeys() { 
     175    protected List<String> getDataKeys() { 
    164176        return new ArrayList<String>(tagCache.keySet()); 
     177    } 
     178 
     179    protected List<String> getPresetKeys() { 
     180        return new ArrayList<String>(presetTagCache.keySet()); 
    165181    } 
    166182 
     
    172188     * @return the list of auto completion values 
    173189     */ 
    174     public List<String> getValues(String key) { 
    175         if (!tagCache.containsKey(key)) 
    176             return new ArrayList<String>(); 
    177         return new ArrayList<String>(tagCache.get(key)); 
     190    protected List<String> getDataValues(String key) { 
     191        return new ArrayList<String>(tagCache.getValues(key)); 
     192    } 
     193 
     194    protected static List<String> getPresetValues(String key) { 
     195        return new ArrayList<String>(presetTagCache.getValues(key)); 
    178196    } 
    179197 
     
    211229            list.clear(); 
    212230        } 
    213         list.add(getValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 
     231        list.add(getDataValues(key), AutoCompletionItemPritority.IS_IN_DATASET); 
     232        list.add(getPresetValues(key), AutoCompletionItemPritority.IS_IN_STANDARD); 
    214233    } 
    215234 
     
    226245            list.clear(); 
    227246        } 
    228         list.add(tagCache.keySet(), AutoCompletionItemPritority.IS_IN_DATASET); 
     247        list.add(getDataKeys(), AutoCompletionItemPritority.IS_IN_DATASET); 
     248        list.add(getPresetKeys(), AutoCompletionItemPritority.IS_IN_STANDARD); 
    229249    } 
    230250} 
Note: See TracChangeset for help on using the changeset viewer.