X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.template2d.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftemplate2d%2Fui%2Fwizard%2FPreferences.java;fp=bundles%2Forg.simantics.modeling.template2d.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftemplate2d%2Fui%2Fwizard%2FPreferences.java;h=6aa4f43248ae9141a5485c2c0247b353e13b30ec;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/Preferences.java b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/Preferences.java new file mode 100644 index 000000000..6aa4f4324 --- /dev/null +++ b/bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/Preferences.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2012 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.modeling.template2d.ui.wizard; + +import java.util.Deque; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.ui.IMemento; +import org.simantics.utils.ui.workbench.StringMemento; + +/** + * @author Tuukka Lehtonen + */ +public final class Preferences { + + public static final String RECENT_DRAWING_TEMPLATE_IMPORT_LOCATIONS = "RECENT_DRAWING_TEMPLATE_IMPORT_LOCATIONS"; + public static final String RECENT_DRAWING_TEMPLATE_EXPORT_LOCATIONS = "RECENT_DRAWING_TEMPLATE_EXPORT_LOCATIONS"; + public static final String DRAWING_TEMPLATE_EXPORT_OVERWRITE = "DRAWING_TEMPLATE_EXPORT_OVERWRITE"; + + private static final String TAG_PATH = "path"; + private static final String ATTR_NAME = "name"; + + public static Deque decodePaths(String recentPathsPref) { + Deque result = new LinkedList(); + try { + StringMemento sm = new StringMemento(recentPathsPref); + for (IMemento m : sm.getChildren(TAG_PATH)) { + String name = m.getString(ATTR_NAME); + if (name != null && !name.isEmpty()) + result.add(name); + } + } catch (IllegalArgumentException e) { + } + return result; + } + + public static String encodePaths(Deque recentPaths) { + StringMemento sm = new StringMemento(); + for (String path : recentPaths) { + IMemento m = sm.createChild(TAG_PATH); + m.putString(ATTR_NAME, path); + } + return sm.toString(); + } + + public static void removeDuplicates(Iterable iter) { + // Remove duplicates + Set dups = new TreeSet(String.CASE_INSENSITIVE_ORDER); + for (Iterator it = iter.iterator(); it.hasNext();) { + String path = it.next(); + if (!dups.add(path)) { + it.remove(); + } + } + } + +}