1 /*******************************************************************************
\r
2 * Copyright (c) 2012 Association for Decentralized Information Management in
\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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.annotation.ui.wizard;
\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
20 import org.eclipse.ui.IMemento;
\r
21 import org.simantics.utils.ui.workbench.StringMemento;
\r
24 * @author Tuukka Lehtonen
\r
26 public final class Preferences {
\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
32 private static final String TAG_PATH = "path";
\r
33 private static final String ATTR_NAME = "name";
\r
35 public static Deque<String> decodePaths(String recentPathsPref) {
\r
36 Deque<String> result = new LinkedList<String>();
\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
44 } catch (IllegalArgumentException e) {
\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
55 return sm.toString();
\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