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";
31 public static final String EXPORT_INCLUDE_DEPENDENCIES = "EXPORT_INCLUDE_DEPENDENCIES";
32 public static final String IMPORT_INCLUDE_DEPENDENCIES = "IMPORT_INCLUDE_DEPENDENCIES";
34 private static final String TAG_PATH = "path";
35 private static final String ATTR_NAME = "name";
37 public static Deque<String> decodePaths(String recentPathsPref) {
38 Deque<String> result = new LinkedList<String>();
40 StringMemento sm = new StringMemento(recentPathsPref);
41 for (IMemento m : sm.getChildren(TAG_PATH)) {
42 String name = m.getString(ATTR_NAME);
43 if (name != null && !name.isEmpty())
46 } catch (IllegalArgumentException e) {
51 public static String encodePaths(Deque<String> recentPaths) {
52 StringMemento sm = new StringMemento();
53 for (String path : recentPaths) {
54 IMemento m = sm.createChild(TAG_PATH);
55 m.putString(ATTR_NAME, path);
60 public static <T> void removeDuplicates(Iterable<String> iter) {
62 Set<String> dups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
63 for (Iterator<String> it = iter.iterator(); it.hasNext();) {
64 String path = it.next();
65 if (!dups.add(path)) {