Search in sources :

Example 11 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project xtext-xtend by eclipse.

the class XtendPreferenceStoreAccess method getContextPreferenceStore.

@SuppressWarnings("all")
@Override
public IPreferenceStore getContextPreferenceStore(Object context) {
    IProject project = getProject(context);
    if (project == null)
        return getPreferenceStore();
    IPreferenceStore store = super.getContextPreferenceStore(context);
    ProjectScope projectScope = new ProjectScope(project);
    FixedScopedPreferenceStore jdtStore = new FixedScopedPreferenceStore(projectScope, JavaCore.PLUGIN_ID);
    jdtStore.setSearchContexts(new IScopeContext[] { projectScope, new InstanceScope(), new ConfigurationScope() });
    return new ChainedPreferenceStore(new IPreferenceStore[] { store, jdtStore, PreferenceConstants.getPreferenceStore() });
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ChainedPreferenceStore(org.eclipse.ui.texteditor.ChainedPreferenceStore) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) FixedScopedPreferenceStore(org.eclipse.xtext.ui.editor.preferences.FixedScopedPreferenceStore) IProject(org.eclipse.core.resources.IProject) ConfigurationScope(org.eclipse.core.runtime.preferences.ConfigurationScope)

Example 12 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project xtext-xtend by eclipse.

the class XtendProjectConfigurator method writePreferences.

private void writePreferences(OutputConfiguration configuration, IProject project) {
    ProjectScope projectPreferences = new ProjectScope(project);
    IEclipsePreferences languagePreferences = projectPreferences.getNode("org.eclipse.xtend.core.Xtend");
    languagePreferences.putBoolean(OptionsConfigurationBlock.isProjectSpecificPropertyKey(BuilderConfigurationBlock.PROPERTY_PREFIX), true);
    languagePreferences.putBoolean(getKey(configuration, INSTALL_DSL_AS_PRIMARY_SOURCE), configuration.isInstallDslAsPrimarySource());
    languagePreferences.putBoolean(getKey(configuration, HIDE_LOCAL_SYNTHETIC_VARIABLES), configuration.isHideSyntheticLocalVariables());
    languagePreferences.putBoolean(getKey(configuration, USE_OUTPUT_PER_SOURCE_FOLDER), true);
    for (SourceMapping sourceMapping : configuration.getSourceMappings()) {
        languagePreferences.put(getOutputForSourceFolderKey(configuration, sourceMapping.getSourceFolder()), Strings.nullToEmpty(sourceMapping.getOutputDirectory()));
    }
    try {
        languagePreferences.flush();
    } catch (BackingStoreException e) {
        throw new RuntimeIOException(e);
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) SourceMapping(org.eclipse.xtext.generator.OutputConfiguration.SourceMapping)

Example 13 with ProjectScope

use of org.eclipse.core.resources.ProjectScope 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 14 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project linuxtools by eclipse.

the class LinuxtoolsPathProperty method getLinuxtoolsPath.

/*
     * This function will return the selected Linuxtools Path in the
     * 'Linux Tools Path' project properties page.
     * If there is a default path setted by the extension point it should be
     * selected as the default by the tools.launch.ui classes. This function
     * will not care about it.
     *
     * * If the tools.launch.ui is not installed this function should always
     * return "".
     * * If the option 'Use the System env PATH' this function should return ""
     * * If the option 'Prepend string to path' is selected this function
     * should return the value of the selected path.
     */
public String getLinuxtoolsPath(IProject project) {
    if (project == null) {
        // $NON-NLS-1$
        return "";
    }
    ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project), LaunchCoreConstants.PLUGIN_ID);
    // If the value is not stored we use the default
    boolean systemPathSelected;
    if (store.contains(LaunchCoreConstants.LINUXTOOLS_PATH_SYSTEM_NAME)) {
        systemPathSelected = store.getBoolean(LaunchCoreConstants.LINUXTOOLS_PATH_SYSTEM_NAME);
    } else {
        systemPathSelected = getLinuxtoolsPathSystemDefault();
    }
    if (systemPathSelected) {
        // $NON-NLS-1$
        return "";
    }
    String path = null;
    if (store.contains(LaunchCoreConstants.LINUXTOOLS_PATH_NAME)) {
        path = store.getString(LaunchCoreConstants.LINUXTOOLS_PATH_NAME);
    }
    if (path == null) {
        return getLinuxtoolsPathDefault();
    }
    return path;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore)

Example 15 with ProjectScope

use of org.eclipse.core.resources.ProjectScope in project linuxtools by eclipse.

the class LinuxtoolsPathPropertyPage method setElement.

/**
 * Receives the object that owns the properties shown in this property page.
 *
 * @see org.eclipse.ui.IWorkbenchPropertyPage#setElement(org.eclipse.core.runtime.IAdaptable)
 */
@Override
public void setElement(IAdaptable element) {
    this.element = element;
    IAdaptable e = getElement();
    if (e != null) {
        setPreferenceStore(new ScopedPreferenceStore(new ProjectScope((IProject) e), LaunchCoreConstants.PLUGIN_ID));
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IAdaptable(org.eclipse.core.runtime.IAdaptable) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore)

Aggregations

ProjectScope (org.eclipse.core.resources.ProjectScope)28 IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)13 IProject (org.eclipse.core.resources.IProject)11 ScopedPreferenceStore (org.eclipse.ui.preferences.ScopedPreferenceStore)9 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)6 Preferences (org.osgi.service.prefs.Preferences)5 IResource (org.eclipse.core.resources.IResource)3 CoreException (org.eclipse.core.runtime.CoreException)3 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)3 BackingStoreException (org.osgi.service.prefs.BackingStoreException)3 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IPath (org.eclipse.core.runtime.IPath)2 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)2 ILaunch (org.eclipse.debug.core.ILaunch)2 Launch (org.eclipse.debug.core.Launch)2 Before (org.junit.Before)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 IOException (java.io.IOException)1