1 /*******************************************************************************
2 * Copyright (c) 2012 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling.ui.sharedontology.wizard;
14 import java.util.Deque;
15 import java.util.Iterator;
16 import java.util.LinkedList;
18 import java.util.TreeSet;
20 import org.eclipse.ui.IMemento;
21 import org.simantics.utils.ui.workbench.StringMemento;
24 * @author Tuukka Lehtonen
26 public final class Preferences {
28 public static final String RECENT_SHARED_LIBRARY_IMPORT_LOCATIONS = "RECENT_SHARED_LIBRARY_IMPORT_LOCATIONS";
29 public static final String RECENT_SHARED_LIBRARY_EXPORT_LOCATIONS = "RECENT_SHARED_LIBRARY_EXPORT_LOCATIONS";
30 public static final String SHARED_LIBRARY_EXPORT_OVERWRITE = "SHARED_LIBRARY_EXPORT_OVERWRITE";
32 private static final String TAG_PATH = "path";
33 private static final String ATTR_NAME = "name";
35 public static Deque<String> decodePaths(String recentPathsPref) {
36 Deque<String> result = new LinkedList<String>();
38 StringMemento sm = new StringMemento(recentPathsPref);
39 for (IMemento m : sm.getChildren(TAG_PATH)) {
40 String name = m.getString(ATTR_NAME);
41 if (name != null && !name.isEmpty())
44 } catch (IllegalArgumentException e) {
49 public static String encodePaths(Deque<String> recentPaths) {
50 StringMemento sm = new StringMemento();
51 for (String path : recentPaths) {
52 IMemento m = sm.createChild(TAG_PATH);
53 m.putString(ATTR_NAME, path);
58 public static <T> void removeDuplicates(Iterable<String> iter) {
60 Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
61 for (Iterator<String> it = iter.iterator(); it.hasNext();) {
62 String path = it.next();
63 if (!dups.add(path)) {