| /***************************************************************************** |
| * Copyright (c) 2019 CEA LIST. |
| * |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456 |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.uml.diagram.clazz.lf.autosizeableclasses.preference; |
| |
| import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
| import org.eclipse.core.runtime.preferences.InstanceScope; |
| import org.eclipse.papyrus.uml.diagram.clazz.lf.autosizeableclasses.Activator; |
| import org.osgi.service.prefs.BackingStoreException; |
| |
| /** |
| * This class helps at accessing to eclipse configuration options related to |
| * this plug-in. |
| * |
| */ |
| public class Settings { |
| |
| private static final String COMPARTMENT_FIELD = "onlyConcernedCompartment"; //$NON-NLS-1$ |
| |
| private static final String ACTIVATED_FIELD = "activated"; //$NON-NLS-1$ |
| |
| private static final String KEEP_SIZE_FIELD = "keepsCreationSize"; //$NON-NLS-1$ |
| |
| private static final Settings INSTANCE = new Settings(); |
| |
| /** |
| * The instance (singleton) that allows to access to the configuration options. |
| * |
| * @return |
| */ |
| public static Settings getInstance() { |
| return INSTANCE; |
| } |
| |
| /** |
| * Option: is the plug-in is on ? |
| * |
| * @return true if it is on. |
| */ |
| public boolean isActivated() { |
| return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).getBoolean(ACTIVATED_FIELD, true); |
| } |
| |
| /** |
| * set the Option: is the plug-in is on ? |
| * |
| * @param activated |
| * true to activate the plug-in. |
| */ |
| public void setActivated(boolean activated) { |
| IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); |
| preferences.putBoolean(ACTIVATED_FIELD, activated); |
| try { |
| preferences.flush(); |
| } catch (BackingStoreException exception) { |
| Activator.getDefault().logError(exception.getMessage(), exception); |
| } |
| } |
| |
| /** |
| * Option: keeps the size of a class given by the user when creating it |
| * |
| * @return true if the creation size will be kept. |
| */ |
| public boolean keepsCreationSize() { |
| return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).getBoolean(KEEP_SIZE_FIELD, true); |
| } |
| |
| /** |
| * set the Option: keeps the size of a class given by the user when creating it |
| * |
| * @param keepsCreationSize |
| * true to keep the creation size |
| */ |
| public void setKeepsCreationSize(boolean keepsCreationSize) { |
| IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); |
| preferences.putBoolean(KEEP_SIZE_FIELD, keepsCreationSize); |
| try { |
| preferences.flush(); |
| } catch (BackingStoreException exception) { |
| Activator.getDefault().logError(exception.getMessage(), exception); |
| } |
| } |
| |
| /** |
| * Option: only collapse / expand the compartment concerned by the current |
| * request. |
| * |
| * @return true if only concerned compartment will be collapsed / expanded |
| */ |
| public boolean isOnlyConcernedCompartment() { |
| return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).getBoolean(COMPARTMENT_FIELD, true); |
| } |
| |
| /** |
| * Option: only collapse / expand the compartment concerned by the current |
| * request. |
| * |
| * @param onlyConcernedCompartment |
| * true if only concerned compartment will be collapsed / expanded |
| */ |
| public void setOnlyConcernedCompartment(boolean onlyConcernedCompartment) { |
| IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); |
| preferences.putBoolean(COMPARTMENT_FIELD, onlyConcernedCompartment); |
| try { |
| preferences.flush(); |
| } catch (BackingStoreException exception) { |
| Activator.getDefault().logError(exception.getMessage(), exception); |
| } |
| } |
| } |