Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/KnownModesForNames.java')
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/KnownModesForNames.java111
1 files changed, 2 insertions, 109 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/KnownModesForNames.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/KnownModesForNames.java
index 3b8fc54bb..b4466f714 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/KnownModesForNames.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/internal/core/KnownModesForNames.java
@@ -11,12 +11,7 @@
package org.eclipse.team.internal.core;
-import java.util.*;
-
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.team.core.IFileTypeInfo;
-import org.eclipse.team.core.Team;
/**
*
@@ -45,112 +40,10 @@ public class KnownModesForNames {
return fMode;
}
}
+ static final String PREF_TEAM_TYPES_FOR_FILES= "cvs_mode_for_file_without_extensions"; //$NON-NLS-1$
- private static class CachedModesForNames implements Preferences.IPropertyChangeListener {
-
- private static final String PREF_TEAM_TYPES_FOR_FILES= "cvs_mode_for_file_without_extensions";
- private static final String PREF_TEAM_SEPARATOR = "\n"; //$NON-NLS-1$
-
- private Map fMap;
- private final Preferences fPreferences;
-
- public CachedModesForNames() {
- fPreferences= TeamPlugin.getPlugin().getPluginPreferences();
- fPreferences.addPropertyChangeListener(this);
- }
-
- public Map referenceMap() {
- if (fMap == null) {
- fMap= new HashMap();
- if (!fPreferences.contains(PREF_TEAM_TYPES_FOR_FILES))
- return Collections.EMPTY_MAP;
-
- final String prefTypes = fPreferences.getString(PREF_TEAM_TYPES_FOR_FILES);
- final StringTokenizer tok = new StringTokenizer(prefTypes, PREF_TEAM_SEPARATOR);
- try {
- while (true) {
- final String name = tok.nextToken();
- if (name.length()==0)
- return Collections.EMPTY_MAP;
- final String mode= tok.nextToken();
- fMap.put(name, Integer.valueOf(mode));
- }
- } catch (NoSuchElementException e) {
- return Collections.EMPTY_MAP;
- }
-
- }
- return fMap;
- }
-
- public void propertyChange(PropertyChangeEvent event) {
- if(event.getProperty().equals(PREF_TEAM_TYPES_FOR_FILES))
- fMap= null;
- }
-
- public void save() {
- // Now set into preferences
- final StringBuffer buffer = new StringBuffer();
- final Iterator e = fMap.keySet().iterator();
-
- while (e.hasNext()) {
- final String filename = (String)e.next();
- buffer.append(filename);
- buffer.append(PREF_TEAM_SEPARATOR);
- final Integer type = (Integer)fMap.get(filename);
- buffer.append(type);
- buffer.append(PREF_TEAM_SEPARATOR);
- }
- TeamPlugin.getPlugin().getPluginPreferences().setValue(PREF_TEAM_TYPES_FOR_FILES, buffer.toString());
- }
- }
-
- private static final CachedModesForNames fCachedModes= new CachedModesForNames();
+ private static final UserStringMappings fCachedModes= new UserStringMappings(PREF_TEAM_TYPES_FOR_FILES);
private KnownModesForNames() {
}
-
- public static IFileTypeInfo [] getKnownModesForNames() {
- return toFileTypeInfoArray(fCachedModes.referenceMap());
- }
-
- public static void addModesForFiles(String [] names, int [] modes) {
- final Map map= fCachedModes.referenceMap();
- map.putAll(toMap(names, modes));
- fCachedModes.save();
- }
-
- public static void setModesforFiles(String [] names, int [] modes) {
- final Map map= fCachedModes.referenceMap();
- map.putAll(toMap(names, modes));
- fCachedModes.save();
- }
-
- private static Map toMap(String [] filenames, int [] modes) {
- final SortedMap map= new TreeMap();
- for (int i = 0; i < filenames.length; i++) {
- map.put(filenames[i], new Integer(modes[i]));
- }
- return map;
- }
-
- private static IFileTypeInfo [] toFileTypeInfoArray(Map map) {
-
- final IFileTypeInfo [] result= new IFileTypeInfo[map.size()];
- int index= 0;
- for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
- final String name = (String) iter.next();
- result[index++]= new FileTypeInfo(name, (Integer)map.get(name));
- }
- return result;
- }
-
- /**
- * @param name
- * @return
- */
- public static int getType(String name) {
- final Integer mode= (Integer)fCachedModes.referenceMap().get(name);
- return mode != null ? mode.intValue() : Team.UNKNOWN;
- }
}

Back to the top