]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.annotation.ui/src/org/simantics/annotation/ui/wizard/Preferences.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.annotation.ui / src / org / simantics / annotation / ui / wizard / Preferences.java
1 /*******************************************************************************\r
2  * Copyright (c) 2012 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.annotation.ui.wizard;\r
13 \r
14 import java.util.Deque;\r
15 import java.util.Iterator;\r
16 import java.util.LinkedList;\r
17 import java.util.Set;\r
18 import java.util.TreeSet;\r
19 \r
20 import org.eclipse.ui.IMemento;\r
21 import org.simantics.utils.ui.workbench.StringMemento;\r
22 \r
23 /**\r
24  * @author Tuukka Lehtonen\r
25  */\r
26 public final class Preferences {\r
27 \r
28     public static final String  RECENT_ANNOTATION_TYPE_IMPORT_LOCATIONS = "RECENT_ANNOTATION_TYPE_IMPORT_LOCATIONS";\r
29     public static final String  RECENT_ANNOTATION_TYPE_EXPORT_LOCATIONS = "RECENT_ANNOTATION_TYPE_EXPORT_LOCATIONS";\r
30     public static final String  ANNOTATION_TYPE_EXPORT_OVERWRITE = "ANNOTATION_TYPE_EXPORT_OVERWRITE";\r
31 \r
32     private static final String TAG_PATH                = "path";\r
33     private static final String ATTR_NAME               = "name";\r
34 \r
35     public static Deque<String> decodePaths(String recentPathsPref) {\r
36         Deque<String> result = new LinkedList<String>();\r
37         try {\r
38             StringMemento sm = new StringMemento(recentPathsPref);\r
39             for (IMemento m : sm.getChildren(TAG_PATH)) {\r
40                 String name = m.getString(ATTR_NAME);\r
41                 if (name != null && !name.isEmpty())\r
42                     result.add(name);\r
43             }\r
44         } catch (IllegalArgumentException e) {\r
45         }\r
46         return result;\r
47     }\r
48 \r
49     public static String encodePaths(Deque<String> recentPaths) {\r
50         StringMemento sm = new StringMemento();\r
51         for (String path : recentPaths) {\r
52             IMemento m = sm.createChild(TAG_PATH);\r
53             m.putString(ATTR_NAME, path);\r
54         }\r
55         return sm.toString();\r
56     }\r
57 \r
58     public static <T> void removeDuplicates(Iterable<String> iter) {\r
59         // Remove duplicates\r
60         Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);\r
61         for (Iterator<String> it = iter.iterator(); it.hasNext();) {\r
62             String path = it.next();\r
63             if (!dups.add(path)) {\r
64                 it.remove();\r
65             }\r
66         }\r
67     }\r
68 \r
69 }\r