001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.preferences; 020 021import icy.workspace.Workspace; 022 023import java.util.ArrayList; 024 025/** 026 * @author Stephane 027 */ 028public class WorkspaceLocalPreferences 029{ 030 /** 031 * pref id 032 */ 033 private static final String PREF_ID = "local"; 034 035 /** 036 * id 037 */ 038 private static final String ID_ACTIVES = "actives"; 039 040 /** 041 * preferences 042 */ 043 private static XMLPreferences preferences; 044 045 public static void load() 046 { 047 preferences = WorkspacePreferences.getPreferences().node(PREF_ID); 048 } 049 050 /** 051 * @return the preferences 052 */ 053 public static XMLPreferences getPreferences() 054 { 055 return preferences; 056 } 057 058 public static ArrayList<String> getActivesWorkspace() 059 { 060 final ArrayList<String> result = new ArrayList<String>(); 061 062 if (preferences.nodeExists(ID_ACTIVES)) 063 { 064 final XMLPreferences activesNode = preferences.node(ID_ACTIVES); 065 066 for (String name : activesNode.keys()) 067 if (activesNode.getBoolean(name, false)) 068 result.add(name); 069 } 070 else 071 { 072 // default workspaces 073 for (String workspaceName : Workspace.DEFAULT_ACTIVE_WORKSPACES) 074 result.add(workspaceName); 075 } 076 077 return result; 078 } 079 080 public static void setActivesWorkspace(ArrayList<String> names) 081 { 082 final XMLPreferences activesNode = preferences.node(ID_ACTIVES); 083 084 activesNode.clear(); 085 for (String name : names) 086 activesNode.putBoolean(name, true); 087 088 // clean up all non element nodes 089 activesNode.clean(); 090 } 091 092 public static boolean isWorkspaceEnable(String workspaceName) 093 { 094 return getActivesWorkspace().contains(workspaceName); 095 } 096 097 public static void setWorkspaceEnable(String workspaceName, boolean value) 098 { 099 final ArrayList<String> activesWorkspace = getActivesWorkspace(); 100 101 if (value) 102 { 103 if (!activesWorkspace.contains(workspaceName)) 104 activesWorkspace.add(workspaceName); 105 } 106 else 107 activesWorkspace.remove(workspaceName); 108 109 setActivesWorkspace(activesWorkspace); 110 } 111 112}