org.eclipse.core.runtime.preferences.IScopeContext Java Examples

The following examples show how to use org.eclipse.core.runtime.preferences.IScopeContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CodeCheckerProject.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Updates project related fields, and saves to the preferences.
 */
private void updateProjectRelated() {
    IScopeContext context = new ProjectScope(project);
    IEclipsePreferences preferences = context.getNode(CodeCheckerNature.NATURE_ID);

    for (ConfigTypes ctp : ConfigTypes.PROJECT_TYPE){
        String value = null;
        switch (ctp) {
            case CHECKER_WORKSPACE:
                value = codeCheckerWorkspace.toString();
                break;
            case IS_GLOBAL:
                value = Boolean.toString(isGlobal);
                break;
            default:
                break;
        }
        preferences.put(ctp.toString(), value);
    }
    try {
        preferences.flush();
    } catch (BackingStoreException e) {
        Logger.log(IStatus.ERROR, "Preferences cannot be saved!");
        e.printStackTrace();
    }
}
 
Example #2
Source File: XtendPreferenceStoreAccess.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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()
	});
}
 
Example #3
Source File: AbstractFormatterSelectionBlock.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public AbstractFormatterSelectionBlock(IStatusChangeListener context, IProject project,
		IWorkbenchPreferenceContainer container)
{
	super(context, project, ProfileManager.collectPreferenceKeys(TEMP_LIST, true), container);
	Collections.sort(TEMP_LIST, new Comparator<IScriptFormatterFactory>()
	{
		public int compare(IScriptFormatterFactory s1, IScriptFormatterFactory s2)
		{
			return s1.getName().compareToIgnoreCase(s2.getName());
		}
	});
	factories = TEMP_LIST.toArray(new IScriptFormatterFactory[TEMP_LIST.size()]);
	TEMP_LIST = new ArrayList<IScriptFormatterFactory>();
	sourcePreviewViewers = new ArrayList<SourceViewer>();

	// Override the super preferences lookup order.
	// All the changes to the formatter settings should go to the instance scope (no project scope here). Only the
	// selected profile will be picked from the project scope and then the instance scope when requested.
	fLookupOrder = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() };
}
 
Example #4
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void updateProfilesWithName(String oldName, Profile newProfile, boolean applySettings) {
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (int i = 0; i < projects.length; i++) {
		IScopeContext projectScope = fPreferencesAccess.getProjectScope(projects[i]);
		IEclipsePreferences node = projectScope.getNode(getNodeId());
		String profileId = node.get(fProfileKey, null);
		if (oldName.equals(profileId)) {
			if (newProfile == null) {
				node.remove(fProfileKey);
			} else {
				if (applySettings) {
					writeToPreferenceStore(newProfile, projectScope);
				} else {
					node.put(fProfileKey, newProfile.getID());
				}
			}
		}
	}

	IScopeContext instanceScope = fPreferencesAccess.getInstanceScope();
	final IEclipsePreferences uiPrefs = instanceScope.getNode(getNodeId());
	if (newProfile != null && oldName.equals(uiPrefs.get(fProfileKey, null))) {
		writeToPreferenceStore(newProfile, instanceScope);
	}
}
 
Example #5
Source File: OptionsConfigurationBlock.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public boolean hasProjectSpecificOptions(IProject project)
{
	if (project != null)
	{
		IScopeContext projectContext = new ProjectScope(project);
		PreferenceKey[] allKeys = fAllKeys;
		for (int i = 0; i < allKeys.length; i++)
		{
			if (allKeys[i].getStoredValue(projectContext, fManager) != null)
			{
				return true;
			}
		}
	}
	return false;
}
 
Example #6
Source File: PreferenceStoreAccessImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public IPreferenceStore getWritablePreferenceStore(Object context) {
	lazyInitialize();
	IProject project = getProject(context);
	if (project == null) {
		return getWritablePreferenceStore();
	}
	ProjectScope projectScope = new ProjectScope(project);
	FixedScopedPreferenceStore result = new FixedScopedPreferenceStore(projectScope, getQualifier());
	result.setSearchContexts(new IScopeContext[] {
		projectScope,
		new InstanceScope(),
		new ConfigurationScope()
	});
	return result;
}
 
Example #7
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 6 votes vote down vote up
private boolean getChanges(IScopeContext currContext, List<Key> changedSettings) {
	boolean needsBuild = false;
	for (int i = 0; i < fAllKeys.length; i++) {
		Key key = fAllKeys[i];
		String oldVal = key.getStoredValue(currContext, null);
		String val = key.getStoredValue(currContext, fManager);
		if (val == null) {
			if (oldVal != null) {
				changedSettings.add(key);
				needsBuild |= !oldVal.equals(key.getStoredValue(fLookupOrder, true, fManager));
			}
		} else if (!val.equals(oldVal)) {
			changedSettings.add(key);
			needsBuild |= oldVal != null || !val.equals(key.getStoredValue(fLookupOrder, true, fManager));
		}
	}
	return needsBuild;
}
 
Example #8
Source File: BazelProjectSupport.java    From eclipse with Apache License 2.0 6 votes vote down vote up
private static void addSettings(IProject project, String workspaceRoot, List<String> targets,
    List<String> buildFlags) throws BackingStoreException {
  IScopeContext projectScope = new ProjectScope(project);
  Preferences projectNode = projectScope.getNode(Activator.PLUGIN_ID);
  int i = 0;
  for (String target : targets) {
    projectNode.put("target" + i, target);
    i++;
  }
  projectNode.put("workspaceRoot", workspaceRoot);
  i = 0;
  for (String flag : buildFlags) {
    projectNode.put("buildFlag" + i, flag);
    i++;
  }
  projectNode.flush();
}
 
Example #9
Source File: AbstractPreferencePage.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Switches the search scope of the preference store to use [Project, Instance, Configuration] if values are project
 * specific, and [Instance, Configuration] otherwise. This implementation requires that the given preference store
 * is based on the Project preference store when the page is used as a Properties page. (This is done in
 * {@link #doGetPreferenceStore()}).
 */
@SuppressWarnings("deprecation")
private void handleUseProjectSettings() {
	// Note: uses the pre Eclipse 3.6 way of specifying search scopes (deprecated since 3.6)
	boolean isUseProjectSettings = useProjectSettingsButton.getSelection();
	link.setEnabled(!isUseProjectSettings);
	if (!isUseProjectSettings) {
		((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
				new InstanceScope(), new ConfigurationScope() });
	} else {
		((FixedScopedPreferenceStore) getPreferenceStore()).setSearchContexts(new IScopeContext[] {
				new ProjectScope(currentProject()), new InstanceScope(), new ConfigurationScope() });
		setProjectSpecificValues();
	}
	updateFieldEditors(isUseProjectSettings);
}
 
Example #10
Source File: SendPingJob.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean sendFirstRunEvent()
{
	ConfigurationScope scope = EclipseUtil.configurationScope();
	boolean hasRun = Platform.getPreferencesService().getBoolean(UsagePlugin.PLUGIN_ID,
			IPreferenceConstants.P_IDE_HAS_RUN, false, new IScopeContext[] { scope });
	if (!hasRun)
	{
		// checks with the previous plugin id
		hasRun = Platform.getPreferencesService().getBoolean(UsagePlugin.OLD_PLUGIN_ID,
				IPreferenceConstants.P_IDE_HAS_RUN, false, new IScopeContext[] { scope });
		if (!hasRun)
		{
			StudioAnalytics.getInstance().sendEvent(new AnalyticsEvent(STUDIO_FIRST_RUN, STUDIO_FIRST_RUN, null));

			IEclipsePreferences store = scope.getNode(UsagePlugin.PLUGIN_ID);
			store.putBoolean(IPreferenceConstants.P_IDE_HAS_RUN, true);
			try
			{
				store.flush();
				return true;
			}
			catch (BackingStoreException e)
			{
				UsagePlugin.logError(e);
			}
		}
	}
	return false;
}
 
Example #11
Source File: CheckConfigurationStore.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
public boolean getBoolean(final String key, final boolean defaultValue) {
  IScopeContext scope = getProjectScope();
  if (scope != null) {
    for (final String node : nodes) {
      boolean result = scope.getNode(node).getBoolean(key, defaultValue);
      if (result != defaultValue) {
        return result;
      }
    }
  }
  return defaultValue;
}
 
Example #12
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void clearAllSettings(IScopeContext context) {
	for (int i = 0; i < fKeySets.length; i++) {
		updatePreferences(context.getNode(fKeySets[i].getNodeName()), fKeySets[i].getKeys(), Collections.EMPTY_MAP);
	}
	final IEclipsePreferences uiPrefs = context.getNode(getNodeId());
	uiPrefs.remove(fProfileKey);
}
 
Example #13
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 5 votes vote down vote up
public void setStoredValue(IScopeContext context, String value, IWorkingCopyManager manager) {
	if (value != null) {
		getNode(context, manager).put(fKey, value);
	} else {
		getNode(context, manager).remove(fKey);
	}
}
 
Example #14
Source File: DefaultResourceBlacklist.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected String getPersistentValues(IProject project) {
	IScopeContext projectScope = getPreferenceScope(project);
	IEclipsePreferences node = projectScope.getNode(SCT_RESOURCE_NODE);

	String string = node.get(SCT_BLACKLIST_KEY, SCT_BLACKLIST_DEFAULT);
	return string;
}
 
Example #15
Source File: TypeScriptMainPreferencePage.java    From typescript.java with MIT License 5 votes vote down vote up
public TypeScriptMainPreferencePage() {
	super(GRID);
	IScopeContext scope = DefaultScope.INSTANCE;
	setPreferenceStore(new ScopedPreferenceStore(scope, TypeScriptCorePlugin.PLUGIN_ID));
	// setDescription(Messages.js_debug_pref_page_desc);
	setImageDescriptor(TypeScriptUIImageResource.getImageDescriptor(TypeScriptUIImageResource.IMG_LOGO));
}
 
Example #16
Source File: Theme.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void delete(IScopeContext context)
{
	try
	{
		IEclipsePreferences prefs = context.getNode(ThemePlugin.PLUGIN_ID);
		Preferences preferences = prefs.node(ThemeManager.THEMES_NODE);
		preferences.remove(getName());
		preferences.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}
}
 
Example #17
Source File: OptionsConfigurationBlock.java    From typescript.java with MIT License 5 votes vote down vote up
public final boolean hasProjectSpecificOptions(IProject project) {
	if (project != null) {
		IScopeContext projectContext = new ProjectScope(project);
		Key[] allKeys = fAllKeys;
		for (int i = 0; i < allKeys.length; i++) {
			if (allKeys[i].getStoredValue(projectContext, fManager) != null) {
				return true;
			}
		}
	}
	return false;
}
 
Example #18
Source File: ThemeManager.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * laziliy init the set of theme names.
 */
public synchronized Set<String> getThemeNames()
{
	if (fThemeNames == null)
	{
		fThemeNames = new HashSet<String>();
		// Add names of themes from builtins...
		fThemeNames.addAll(getBuiltinThemeNames());

		// Look in prefs to see what user themes are stored there, garb their names
		IScopeContext[] scopes = new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() };
		for (IScopeContext scope : scopes)
		{
			IEclipsePreferences prefs = scope.getNode(ThemePlugin.PLUGIN_ID);
			Preferences preferences = prefs.node(ThemeManager.THEMES_NODE);
			try
			{
				String[] themeNames = preferences.keys();
				fThemeNames.addAll(Arrays.asList(themeNames));
			}
			catch (BackingStoreException e)
			{
				IdeLog.logError(ThemePlugin.getDefault(), e);
			}
		}
	}
	return fThemeNames;
}
 
Example #19
Source File: CheckConfigurationStore.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
public String getString(final String key, final String defaultValue) {
  IScopeContext scope = getProjectScope();
  if (scope != null) {
    for (final String node : nodes) {
      String result = scope.getNode(node).get(key, null);
      if (result != null) {
        return result;
      }
    }
  }
  return defaultValue;
}
 
Example #20
Source File: WebServerPreferences.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns preferences-specified local webserver port range
 * 
 * @return
 */
public static int[] getPortRange()
{
	String portsString = Platform.getPreferencesService().getString(WebServerCorePlugin.PLUGIN_ID,
			IWebServerPreferenceConstants.PREF_HTTP_SERVER_PORTS, null,
			new IScopeContext[] { EclipseUtil.instanceScope(), EclipseUtil.defaultScope() });
	int portsStart = IWebServerPreferenceConstants.DEFAULT_HTTP_SERVER_PORTS_RANGE[0];
	int portsEnd = IWebServerPreferenceConstants.DEFAULT_HTTP_SERVER_PORTS_RANGE[1];
	if (portsString != null && portsString.length() > 0)
	{
		Matcher matcher = Pattern.compile(PORTS_PATTERN).matcher(portsString);
		if (matcher.matches())
		{
			try
			{
				int start = Integer.parseInt(matcher.group(1));
				int end = start;
				if (matcher.group(2) != null)
				{
					end = Integer.parseInt(matcher.group(3));
				}
				if (start < end)
				{
					portsStart = start;
					portsEnd = end;
				}
			}
			catch (NumberFormatException e)
			{
				IdeLog.logWarning(WebServerCorePlugin.getDefault(), e);
			}
		}
	}
	return new int[] { portsStart, portsEnd };
}
 
Example #21
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Only to read project specific settings to find out to what profile it matches.
 * 
 * @param context
 *            The project context
 */
private Map readFromPreferenceStore(IScopeContext context, Profile workspaceProfile) {
	final Map profileOptions = new HashMap();
	IEclipsePreferences uiPrefs = context.getNode(getNodeId());

	int version = uiPrefs.getInt(fProfileVersionKey, fProfileVersioner.getFirstVersion());
	if (version != fProfileVersioner.getCurrentVersion()) {
		Map allOptions = new HashMap();
		for (int i = 0; i < fKeySets.length; i++) {
			addAll(context.getNode(fKeySets[i].getNodeName()), allOptions);
		}
		CustomProfile profile = new CustomProfile("tmp", allOptions, version, fProfileVersioner.getProfileKind()); //$NON-NLS-1$
		fProfileVersioner.update(profile);
		return profile.getSettings();
	}

	boolean hasValues = false;
	for (int i = 0; i < fKeySets.length; i++) {
		KeySet keySet = fKeySets[i];
		IEclipsePreferences preferences = context.getNode(keySet.getNodeName());
		for (final Iterator keyIter = keySet.getKeys().iterator(); keyIter.hasNext();) {
			final String key = (String) keyIter.next();
			Object val = preferences.get(key, null);
			if (val != null) {
				hasValues = true;
			} else {
				val = workspaceProfile.getSettings().get(key);
			}
			profileOptions.put(key, val);
		}
	}

	if (!hasValues) {
		return null;
	}

	setLatestCompliance(profileOptions);
	return profileOptions;
}
 
Example #22
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean hasProjectSpecificSettings(IScopeContext context) {
	if (fKeySets != null)
		return hasProjectSpecificSettings(context, fKeySets);
	else
		return false;
}
 
Example #23
Source File: AbstractProfileManager.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean hasProjectSpecificSettings(IScopeContext context, KeySet[] keySets) {
	for (int i = 0; i < keySets.length; i++) {
		KeySet keySet = keySets[i];
		IEclipsePreferences preferences = context.getNode(keySet.getNodeName());
		for (final Iterator keyIter = keySet.getKeys().iterator(); keyIter.hasNext();) {
			final String key = (String) keyIter.next();
			Object val = preferences.get(key, null);
			if (val != null) {
				return true;
			}
		}
	}
	return false;
}
 
Example #24
Source File: PreferenceKey.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void setStoredValue(IScopeContext context, String value, IWorkingCopyManager manager)
{
	if (value != null)
	{
		getNode(context, manager).put(fKey, value);
	}
	else
	{
		getNode(context, manager).remove(fKey);
	}
}
 
Example #25
Source File: JavaProjectPreferencesInitializer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("restriction")
@Inject
public void addOwnFileExtensionsToJavaBuildResourceCopyFilter(FileExtensionProvider extensionProvider) {
	@SuppressWarnings("deprecation")
	IScopeContext defaultScope = new DefaultScope();

	// The class org.eclipse.jdt.internal.launching.LaunchingPreferenceInitializer has this very nasty habit 
	// of replacing all RESOURCE_COPY_FILTERs with its own filter. Calling getNode(LaunchingPlugin.ID_PLUGIN) 
	// causes LaunchingPreferenceInitializer to be executed that afterwards we can append our filters safely.    
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=395366
	defaultScope.getNode(org.eclipse.jdt.internal.launching.LaunchingPlugin.ID_PLUGIN);

	IEclipsePreferences dnode = defaultScope.getNode(JavaCore.PLUGIN_ID);
	if (dnode == null)
		return;
	Set<String> filters = Sets.newLinkedHashSet();
	for (String filter : dnode.get(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, "").split(",")) {
		String trimmed = filter.trim();
		if (!"".equals(trimmed))
			filters.add(trimmed);
	}
	for (String ext : extensionProvider.getFileExtensions())
		filters.add("*." + ext);
	dnode.put(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER, Joiner.on(", ").join(filters));
	try {
		dnode.flush();
	} catch (BackingStoreException e) {
		log.error("Error saving preferences", e);
	}
}
 
Example #26
Source File: Activator.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public static TimeZone getTimeZone ()
{
    final IScopeContext[] scopeContext = new IScopeContext[] { ConfigurationScope.INSTANCE };
    final String tzId = Platform.getPreferencesService ().getString ( PLUGIN_ID, TIME_ZONE_KEY, TimeZone.getDefault ().getID (), scopeContext );
    if ( Arrays.asList ( TimeZone.getAvailableIDs () ).contains ( tzId ) )
    {
        return TimeZone.getTimeZone ( tzId );
    }
    return TimeZone.getDefault ();
}
 
Example #27
Source File: XtendPreferenceStoreAccess.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("all")
@Override
public IPreferenceStore getPreferenceStore() {
	IPreferenceStore store = super.getPreferenceStore();
	FixedScopedPreferenceStore jdtStore = new FixedScopedPreferenceStore(new InstanceScope(), JavaCore.PLUGIN_ID);
	jdtStore.setSearchContexts(new IScopeContext[] {
			new InstanceScope(),
			new ConfigurationScope()
	});
	return new ChainedPreferenceStore(new IPreferenceStore[] {
		store,
		jdtStore,
		PreferenceConstants.getPreferenceStore()
	});
}
 
Example #28
Source File: CodeCheckerProject.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initializes project related fields.
 *  - Is the last used configuration was local or global.
 */
private void initProjectRelated() {
    IScopeContext context = new ProjectScope(project);
    IEclipsePreferences preferences = context.getNode(CodeCheckerNature.NATURE_ID);

    isGlobal = preferences.getBoolean(ConfigTypes.IS_GLOBAL.toString(), true);
}
 
Example #29
Source File: PreferenceKey.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private IEclipsePreferences getNode(IScopeContext context, IWorkingCopyManager manager)
{
	IEclipsePreferences node = context.getNode(fQualifier);
	if (manager != null)
	{
		return manager.getWorkingCopy(node);
	}
	return node;
}
 
Example #30
Source File: SendPingJob.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean enroll()
{
	ConfigurationScope scope = EclipseUtil.configurationScope();
	boolean hasEnrolled = Platform.getPreferencesService().getBoolean(UsagePlugin.PLUGIN_ID,
			IPreferenceConstants.HAS_ENROLLED, false, new IScopeContext[] { scope });
	if (!hasEnrolled)
	{
		AnalyticsInfo info = UsagePlugin.getDefault().getAnalyticsInfoManager()
				.getInfo("com.aptana.usage.analytics"); //$NON-NLS-1$
		String guid = info.getAppGuid();
		// only sends the enroll ping if it's Aptana Studio
		if ((new DefaultAnalyticsInfo()).getAppGuid().equals(guid))
		{
			// @formatter:off
			Map<String, String> payload = CollectionsUtil.newInOrderMap(
				"guid", guid, //$NON-NLS-1$
				"mid", CorePlugin.getMID()); //$NON-NLS-1$
			// @formatter:on

			StudioAnalytics.getInstance().sendEvent(new AnalyticsEvent(STUDIO_ENROLL, STUDIO_ENROLL, payload));
		}

		IEclipsePreferences store = scope.getNode(UsagePlugin.PLUGIN_ID);
		store.putBoolean(IPreferenceConstants.HAS_ENROLLED, true);
		try
		{
			store.flush();
			return true;
		}
		catch (BackingStoreException e)
		{
			UsagePlugin.logError(e);
		}
	}
	return false;
}