| /*=============================================================================# |
| # Copyright (c) 2007, 2018 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.internal.r.ui; |
| |
| import java.util.Arrays; |
| import java.util.Map; |
| |
| import org.eclipse.statet.ecommons.preferences.AbstractPreferencesModelObject; |
| import org.eclipse.statet.ecommons.preferences.core.Preference; |
| import org.eclipse.statet.ecommons.preferences.core.Preference.StringArrayPref; |
| import org.eclipse.statet.ecommons.preferences.core.PreferenceAccess; |
| |
| import org.eclipse.statet.r.core.RSymbolComparator; |
| import org.eclipse.statet.r.ui.RUI; |
| import org.eclipse.statet.r.ui.RUIPreferenceConstants; |
| |
| |
| /** |
| * |
| */ |
| public class RIdentifierGroups extends AbstractPreferencesModelObject { |
| |
| |
| public final static String GROUP_ID = "r.editor/identifiergroups"; //$NON-NLS-1$ |
| |
| |
| private String[] fIdentifiersItemsAssignment; |
| private String[] fIdentifiersItemsLogical; |
| private String[] fIdentifiersItemsFlowcontrol; |
| private String[] fIdentifiersItemsCustom1; |
| private String[] fIdentifiersItemsCustom2; |
| |
| |
| public RIdentifierGroups() { |
| installLock(); |
| } |
| |
| @Override |
| public String[] getNodeQualifiers() { |
| return new String[0]; |
| } |
| |
| @Override |
| public void loadDefaults() { |
| } |
| |
| @Override |
| public void load(final PreferenceAccess prefs) { |
| final RSymbolComparator comparator = new RSymbolComparator(); |
| fIdentifiersItemsAssignment = loadValues(prefs, RUIPreferenceConstants.R.TS_IDENTIFIER_SUB_ASSIGNMENT_ITEMS); |
| Arrays.sort(fIdentifiersItemsAssignment, comparator); |
| fIdentifiersItemsLogical = loadValues(prefs, RUIPreferenceConstants.R.TS_IDENTIFIER_SUB_LOGICAL_ITEMS); |
| Arrays.sort(fIdentifiersItemsLogical, comparator); |
| fIdentifiersItemsFlowcontrol = loadValues(prefs, RUIPreferenceConstants.R.TS_IDENTIFIER_SUB_FLOWCONTROL_ITEMS); |
| Arrays.sort(fIdentifiersItemsFlowcontrol, comparator); |
| fIdentifiersItemsCustom1 = loadValues(prefs, RUIPreferenceConstants.R.TS_IDENTIFIER_SUB_CUSTOM1_ITEMS); |
| Arrays.sort(fIdentifiersItemsCustom1, comparator); |
| fIdentifiersItemsCustom2 = loadValues(prefs, RUIPreferenceConstants.R.TS_IDENTIFIER_SUB_CUSTOM2_ITEMS); |
| Arrays.sort(fIdentifiersItemsCustom2, comparator); |
| } |
| |
| @Override |
| public Map<Preference<?>, Object> deliverToPreferencesMap(final Map<Preference<?>, Object> map) { |
| return map; |
| } |
| |
| private final String[] loadValues(final PreferenceAccess prefs, final String key) { |
| final Preference<String[]> pref = new StringArrayPref(RUI.BUNDLE_ID, key); |
| return prefs.getPreferenceValue(pref); |
| } |
| |
| |
| public String[] getAssignmentIdentifiers() { |
| return fIdentifiersItemsAssignment; |
| } |
| |
| public String[] getLogicalIdentifiers() { |
| return fIdentifiersItemsLogical; |
| } |
| |
| public String[] getFlowcontrolIdentifiers() { |
| return fIdentifiersItemsFlowcontrol; |
| } |
| |
| public String[] getCustom1Identifiers() { |
| return fIdentifiersItemsCustom1; |
| } |
| |
| public String[] getCustom2Identifiers() { |
| return fIdentifiersItemsCustom2; |
| } |
| |
| } |