| /*=============================================================================# |
| # Copyright (c) 2015, 2020 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.r.core.util; |
| |
| import org.eclipse.core.runtime.preferences.IScopeContext; |
| |
| import org.eclipse.statet.jcommons.collections.ImList; |
| |
| import org.eclipse.statet.ecommons.preferences.core.PreferenceAccess; |
| import org.eclipse.statet.ecommons.preferences.core.util.PreferenceAccessWrapper; |
| |
| import org.eclipse.statet.r.core.IRCoreAccess; |
| import org.eclipse.statet.r.core.RCodeStyleSettings; |
| import org.eclipse.statet.rj.renv.core.REnv; |
| |
| |
| public class RCoreAccessWrapper extends PreferenceAccessWrapper |
| implements IRCoreAccess { |
| |
| |
| private IRCoreAccess parent; |
| |
| |
| public RCoreAccessWrapper(final IRCoreAccess rCoreAccess) { |
| if (rCoreAccess == null) { |
| throw new NullPointerException("rCoreAccess"); //$NON-NLS-1$ |
| } |
| |
| updateParent(null, rCoreAccess); |
| } |
| |
| |
| public synchronized IRCoreAccess getParent() { |
| return this.parent; |
| } |
| |
| public synchronized boolean setParent(final IRCoreAccess rCoreAccess) { |
| if (rCoreAccess == null) { |
| throw new NullPointerException("rCoreAccess"); //$NON-NLS-1$ |
| } |
| if (rCoreAccess != this.parent) { |
| updateParent(this.parent, rCoreAccess); |
| return true; |
| } |
| return false; |
| } |
| |
| protected void updateParent(final IRCoreAccess oldParent, final IRCoreAccess newParent) { |
| this.parent= newParent; |
| |
| super.setPreferenceContexts(newParent.getPrefs().getPreferenceContexts()); |
| } |
| |
| @Override |
| public void setPreferenceContexts(final ImList<IScopeContext> contexts) { |
| throw new UnsupportedOperationException(); |
| } |
| |
| |
| @Override |
| public PreferenceAccess getPrefs() { |
| return this; |
| } |
| |
| @Override |
| public REnv getREnv() { |
| return this.parent.getREnv(); |
| } |
| |
| @Override |
| public RCodeStyleSettings getRCodeStyle() { |
| return this.parent.getRCodeStyle(); |
| } |
| |
| } |