1 package org.simantics.team.ui;
\r
3 import java.util.Deque;
\r
4 import java.util.Iterator;
\r
5 import java.util.LinkedList;
\r
6 import java.util.Set;
\r
7 import java.util.TreeSet;
\r
9 import org.eclipse.ui.IMemento;
\r
10 import org.simantics.utils.ui.workbench.StringMemento;
\r
12 public final class Preferences {
\r
13 public static final String CURRENT_TEAM_FOLDER = "CURRENT_TEAM_FOLDER";
\r
14 public static final String RECENT_TEAM_FOLDERS = "RECENT_TEAM_FOLDERS";
\r
15 private static final String TAG_PATH = "path";
\r
16 private static final String ATTR_NAME = "name";
\r
17 public static Deque<String> decodePaths(String recentPathsPref) {
\r
18 Deque<String> result = new LinkedList<String>();
\r
20 StringMemento sm = new StringMemento(recentPathsPref);
\r
21 for (IMemento m : sm.getChildren(TAG_PATH)) {
\r
22 String name = m.getString(ATTR_NAME);
\r
23 if (name != null && !name.isEmpty())
\r
26 } catch (IllegalArgumentException e) {
\r
30 public static String encodePaths(Deque<String> recentPaths) {
\r
31 StringMemento sm = new StringMemento();
\r
32 for (String path : recentPaths) {
\r
33 IMemento m = sm.createChild(TAG_PATH);
\r
34 m.putString(ATTR_NAME, path);
\r
36 return sm.toString();
\r
38 public static <T> void removeDuplicates(Iterable<String> iter) {
\r
39 // Remove duplicates
\r
40 Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
\r
41 for (Iterator<String> it = iter.iterator(); it.hasNext();) {
\r
42 String path = it.next();
\r
43 if (!dups.add(path)) {
\r