Search in sources :

Example 1 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project sling by apache.

the class ProjectUtil method getSyncDirectoryValue.

/**
     * Returns the value of the sync directory configured for a project.
     * 
     * <p>
     * The value is returned as a relative path to the project's location. If the property value is not set, it defaults
     * to {@value #PROPERTY_SYNC_ROOT_DEFAULT_VALUE}.
     * </p>
     * 
     * @param project the project, must not be null
     * @return the value of the sync directory
     */
public static IPath getSyncDirectoryValue(IProject project) {
    // for compatibility reasons, read the old value first
    String oldValue = null;
    try {
        oldValue = project.getPersistentProperty(PROPERTY_SYNC_ROOT_OLD);
    } catch (CoreException e) {
        Activator.getDefault().getPluginLogger().trace("Failed retrieving old values for content sync root for project " + project.getName(), e);
    }
    // read a value from the new store, returning a default if none is found 
    IScopeContext projectScope = new ProjectScope(project);
    IEclipsePreferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
    if (projectNode == null) {
        String value;
        // try to read from old values
        if (oldValue != null) {
            value = oldValue;
        } else {
            value = PROPERTY_SYNC_ROOT_DEFAULT_VALUE;
        }
        return Path.fromOSString(value);
    }
    // if no new value if found and an old value exists, use the old value and save it in the new store
    String value = projectNode.get(PROPERTY_SYNC_ROOT, null);
    if (value == null && oldValue != null) {
        value = oldValue;
        setSyncDirectoryPath(project, Path.fromPortableString(value));
    }
    // it is now safe to delete the value from the old store
    if (oldValue != null) {
        try {
            project.setPersistentProperty(PROPERTY_SYNC_ROOT_OLD, null);
        } catch (CoreException e) {
            Activator.getDefault().getPluginLogger().error(e.getMessage(), e);
        }
    }
    // TODO central place for defaults
    if (value == null) {
        return Path.fromOSString(PROPERTY_SYNC_ROOT_DEFAULT_VALUE);
    } else {
        return Path.fromPortableString(value);
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) CoreException(org.eclipse.core.runtime.CoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 2 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project sling by apache.

the class ProjectUtil method getProvisioningModelPath.

public static IPath getProvisioningModelPath(IProject project) {
    if (project == null || !project.isOpen() || !ProjectHelper.isLaunchpadProject(project)) {
        return null;
    }
    IScopeContext projectScope = new ProjectScope(project);
    IEclipsePreferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
    if (projectNode == null) {
        return null;
    }
    String propertyValue = projectNode.get(PROPERTY_PROVISIONING_MODEL_DIR, null);
    if (propertyValue == null) {
        return null;
    }
    return Path.fromPortableString(propertyValue);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences)

Example 3 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project eclipse.platform.text by eclipse.

the class ResourceTextFileBufferManager method getLineDelimiterPreference.

private String getLineDelimiterPreference(IFile file) {
    IScopeContext[] scopeContext;
    if (file != null && file.getProject() != null) {
        // project preference
        scopeContext = new IScopeContext[] { new ProjectScope(file.getProject()) };
        String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
        if (lineDelimiter != null)
            return lineDelimiter;
    }
    // workspace preference
    scopeContext = new IScopeContext[] { InstanceScope.INSTANCE };
    return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext)

Example 4 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project linuxtools by eclipse.

the class AbstractProviderPropertyTab method createControls.

@Override
protected void createControls(final Composite parent) {
    super.createControls(parent);
    usercomp.setLayout(new GridLayout(2, true));
    // Get the property provider (project, file, folder) and fine the project.
    IResource resource = page.getElement().getAdapter(IResource.class);
    IProject project = resource.getProject();
    // Create the preference store to use
    ProjectScope ps = new ProjectScope(project);
    ScopedPreferenceStore scoped = new ScopedPreferenceStore(ps, ProviderProfileConstants.PLUGIN_ID);
    scoped.setSearchContexts(new IScopeContext[] { ps, InstanceScope.INSTANCE });
    setPreferenceStore(scoped);
    getPreferenceStore().setDefault(ProviderProfileConstants.USE_PROJECT_SETTINGS + getType(), false);
    useProjectSetting = new Button(usercomp, SWT.CHECK);
    useProjectSetting.setText(Messages.UseProjectSetting_0);
    useProjectSetting.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
    useProjectSetting.setSelection(getPreferenceStore().getBoolean(ProviderProfileConstants.USE_PROJECT_SETTINGS + getType()));
    useProjectSetting.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> updateOptionsEnable()));
    String highestProviderId = ProviderFramework.getHighestProviderId(getType());
    if (highestProviderId != null) {
        getPreferenceStore().setDefault(ProviderProfileConstants.PREFS_KEY + getType(), highestProviderId);
    } else {
        useProjectSetting.setEnabled(false);
    }
    fLink = new Link(usercomp, SWT.NULL);
    fLink.setText(Messages.PreferenceLink_0);
    fLink.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false, 1, 1));
    fLink.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> PreferencesUtil.createPreferenceDialogOn(parent.getShell(), getPrefPageId(), null, null).open()));
    HashMap<String, String> map = ProviderFramework.getProviderNamesForType(getType());
    // 2d array containing launch provider names on the first column and
    // corresponding id's on the second.
    String[][] providerList = new String[map.size()][2];
    int i = 0;
    for (Entry<String, String> entry : map.entrySet()) {
        String toolId = entry.getValue();
        String toolDescription = ProviderFramework.getToolInformationFromId(toolId, PROVIDER_ATT_DESC);
        String toolName = entry.getKey();
        // Append tool description to tool name if available.
        if (toolDescription != null && !toolDescription.isEmpty()) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            toolName = toolName + " " + "[" + toolDescription + "]";
        }
        providerList[i][0] = toolName;
        providerList[i][1] = toolId;
        i++;
    }
    projectSettingsGroup = new Group(usercomp, SWT.NONE);
    projectSettingsGroup.setFont(parent.getFont());
    projectSettingsGroup.setText(Messages.ProviderPreferencesPage_1);
    projectSettingsGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    GridLayout layout = new GridLayout();
    layout.horizontalSpacing = 8;
    layout.numColumns = 1;
    projectSettingsGroup.setLayout(layout);
    radioButtons = new Button[map.size()];
    for (int j = 0; j < radioButtons.length; j++) {
        Button radio = new Button(projectSettingsGroup, SWT.RADIO | SWT.LEFT);
        radio.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, true, false, 1, 1));
        radioButtons[j] = radio;
        String[] labelAndValue = providerList[j];
        String curProviderId = labelAndValue[1];
        // Set tool tip description text.
        String toolInfo = ProviderFramework.getToolInformationFromId(curProviderId, PROVIDER_ATT_INFO);
        if (toolInfo != null && !toolInfo.isEmpty()) {
            radio.setToolTipText(toolInfo);
        }
        radio.setText(labelAndValue[0]);
        radio.setData(labelAndValue[1]);
        radio.setFont(parent.getFont());
        radio.addSelectionListener(SelectionListener.widgetSelectedAdapter(event -> value = (String) event.widget.getData()));
    }
    projectSettingsGroup.addDisposeListener(event -> {
        projectSettingsGroup = null;
        radioButtons = null;
    });
    updateOptionsEnable();
    updateValue(getPreferenceStore().getString(ProviderProfileConstants.PREFS_KEY + getType()));
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, getHelpContextId());
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) PreferencesUtil(org.eclipse.ui.dialogs.PreferencesUtil) IOException(java.io.IOException) HashMap(java.util.HashMap) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore) Messages(org.eclipse.linuxtools.internal.profiling.launch.provider.launch.Messages) Group(org.eclipse.swt.widgets.Group) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IProject(org.eclipse.core.resources.IProject) Composite(org.eclipse.swt.widgets.Composite) IResource(org.eclipse.core.resources.IResource) SWT(org.eclipse.swt.SWT) Entry(java.util.Map.Entry) ProviderFramework(org.eclipse.linuxtools.internal.profiling.launch.provider.launch.ProviderFramework) AbstractCPropertyTab(org.eclipse.cdt.ui.newui.AbstractCPropertyTab) ProjectScope(org.eclipse.core.resources.ProjectScope) GridData(org.eclipse.swt.layout.GridData) ICResourceDescription(org.eclipse.cdt.core.settings.model.ICResourceDescription) Link(org.eclipse.swt.widgets.Link) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) IProject(org.eclipse.core.resources.IProject) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) IResource(org.eclipse.core.resources.IResource) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore) Link(org.eclipse.swt.widgets.Link)

Example 5 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project erlide_eclipse by erlang.

the class PreferencesHelperTest method nextContexts_1.

@Test
public void nextContexts_1() {
    final IScopeContext[] list = PreferencesHelperTest.ALL_SCOPE_CONTEXTS;
    final IScopeContext item = ConfigurationScope.INSTANCE;
    final IScopeContext[] val = PreferencesHelper.getNextContexts(list, item);
    Assert.assertNotNull(val);
    Assert.assertEquals(1, val.length);
    Assert.assertEquals(DefaultScope.INSTANCE, val[0]);
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Test(org.junit.Test)

Aggregations

IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)74 ProjectScope (org.eclipse.core.resources.ProjectScope)42 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)17 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)16 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)15 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Preferences (org.osgi.service.prefs.Preferences)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)6 IResource (org.eclipse.core.resources.IResource)6 ILiferayProjectProvider (com.liferay.ide.core.ILiferayProjectProvider)5 Iterator (java.util.Iterator)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 IFile (org.eclipse.core.resources.IFile)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 PreferencesAccess (org.eclipse.jdt.internal.ui.preferences.PreferencesAccess)4 FormatterProfileStore (org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore)4