Java Code Examples for org.eclipse.core.runtime.preferences.IEclipsePreferences#flush()

The following examples show how to use org.eclipse.core.runtime.preferences.IEclipsePreferences#flush() . 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: UserAgentManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void clearPreferences(IProject project)
{
	if (project != null)
	{
		// Save to the project scope
		IEclipsePreferences preferences = new ProjectScope(project).getNode(CommonEditorPlugin.PLUGIN_ID);
		preferences.remove(IPreferenceConstants.USER_AGENT_PREFERENCE);
		try
		{
			preferences.flush();
		}
		catch (BackingStoreException e)
		{
			// ignore
		}
	}
}
 
Example 2
Source File: OsgiBinariesPreferenceStore.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IStatus save() {
	try {
		final IEclipsePreferences node = InstanceScope.INSTANCE.getNode(QUALIFIER);
		for (final Entry<Binary, URI> entry : getOrCreateState().entrySet()) {
			final URI path = entry.getValue();
			if (null != path) {
				final File file = new File(path);
				if (file.isDirectory()) {
					node.put(entry.getKey().getId(), file.getAbsolutePath());
				}
			} else {
				// Set to default.
				node.put(entry.getKey().getId(), "");
			}
		}
		node.flush();
		return OK_STATUS;
	} catch (final BackingStoreException e) {
		final String message = "Unexpected error when trying to persist binary preferences.";
		LOGGER.error(message, e);
		return statusHelper.createError(message, e);
	}
}
 
Example 3
Source File: TLCPreferenceInitializer.java    From tlaplus with MIT License 5 votes vote down vote up
/**
   * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
   */
  public void initializeDefaultPreferences()
  {
      final IPreferenceStore uiPreferencesStore = TLCUIActivator.getDefault().getPreferenceStore();
      final IPreferenceStore tlcPreferencesStore = TLCActivator.getDefault().getPreferenceStore();

      tlcPreferencesStore.setDefault(TLCActivator.I_TLC_SNAPSHOT_KEEP_COUNT, 10);

      // This is so bad.. we store them in parallel because one is needed by plugin relied upon the PreferencePage
      //      and the other by a plugin which is on the opposite side of the dependency. (TLCModelLaunchDelegate)
      uiPreferencesStore.setDefault(TLCActivator.I_TLC_SNAPSHOT_KEEP_COUNT, 10);

      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_TRACE_MAX_SHOW_ERRORS, 10000);
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_POPUP_ERRORS, true);
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_REVALIDATE_ON_MODIFY, true);
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_DEFAULT_WORKERS_COUNT,
      							  TLCConsumptionProfile.LOCAL_NORMAL.getWorkerThreads());
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_MAXIMUM_HEAP_SIZE_DEFAULT, MAX_HEAP_SIZE_DEFAULT);
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_MAXSETSIZE_DEFAULT, TLCGlobals.setBound);
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_FPBITS_DEFAULT, 1);
      uiPreferencesStore.setDefault(ITLCPreferenceConstants.I_TLC_FPSETIMPL_DEFAULT, FPSetFactory.getImplementationDefault());
      // store.setDefault(ITLCPreferenceConstants.I_TLC_DELETE_PREVIOUS_FILES, true);

// By default we want the Toolbox to show a modal progress dialog upon TLC
// startup. A user can opt to subsequently suppress the dialog.
// This restores the behavior prior to https://bugs.eclipse.org/146205#c10.
      if (!uiPreferencesStore.contains(ITLCPreferenceConstants.I_TLC_SHOW_MODAL_PROGRESS)) {
	final IEclipsePreferences node = InstanceScope.INSTANCE
			.getNode(WorkbenchPlugin.getDefault().getBundle().getSymbolicName());
	node.putBoolean(IPreferenceConstants.RUN_IN_BACKGROUND, false);
	try {
		node.flush();
	} catch (final BackingStoreException e) {
		TLCUIActivator.getDefault().logError("Error trying to flush the workbench plugin preferences store.",
				e);
	}
	uiPreferencesStore.setValue(ITLCPreferenceConstants.I_TLC_SHOW_MODAL_PROGRESS, true);
}
  }
 
Example 4
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void setUnixLineEndings(IProject project) {
	IEclipsePreferences prefs = new ProjectScope(project).getNode(Platform.PI_RUNTIME);
	prefs.put(Platform.PREF_LINE_SEPARATOR, "\n");
	try {
		prefs.flush();
	} catch (BackingStoreException e) {
		throw new RuntimeException(e);
	}
}
 
Example 5
Source File: WebAppProjectProperties.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public static void setJarsExcludedFromWebInfLib(IProject project, List<IPath> excludedJars)
    throws BackingStoreException {
  IEclipsePreferences prefs = getProjectProperties(project);
  String rawPropVal = PropertiesUtilities.serializePaths(excludedJars);
  prefs.put(JARS_EXCLUDED_FROM_WEB_INF_LIB, rawPropVal);
  prefs.flush();
}
 
Example 6
Source File: CloudSdkPreferences.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static void flushPreferences(IEclipsePreferences preferenceNode) {
  try {
    preferenceNode.flush();
  } catch (BackingStoreException ex) {
    logger.log(Level.WARNING, "could not save preferences", ex);
  }
}
 
Example 7
Source File: ReleaseNotes.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void setLastVersion(String version) {
	IEclipsePreferences node = ConfigurationScope.INSTANCE.getNode(ReleaseNotes.class.getName());
	node.put(Version.class.getSimpleName(), version);
	try {
		node.flush();
		return;
	} catch (BackingStoreException e) {
		e.printStackTrace();
	}
}
 
Example 8
Source File: Util.java    From saneclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static  void savePrefs(IEclipsePreferences prefs) {
	try {
		prefs.flush();
	} catch (org.osgi.service.prefs.BackingStoreException e) {
		e.printStackTrace();
	}

}
 
Example 9
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;
}
 
Example 10
Source File: DialogUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public static void setShouldShowDialog(String dialogKey, boolean shouldShow)
{
	final IEclipsePreferences prefs = (EclipseUtil.instanceScope()).getNode(UIEplPlugin.PLUGIN_ID);
	String[] keys = prefs.get(IEplPreferenceConstants.HIDDEN_MESSAGES, StringUtil.EMPTY).split(","); //$NON-NLS-1$
	Set<String> keysSet = CollectionsUtil.newSet(keys);

	if (shouldShow)
	{
		if (!keysSet.contains(dialogKey))
		{
			// Do nothing
			return;
		}
		keysSet.remove(dialogKey);
	}
	else
	{
		if (keysSet.contains(dialogKey))
		{
			// Do nothing
			return;
		}
		keysSet.add(dialogKey);
	}

	prefs.put(IEplPreferenceConstants.HIDDEN_MESSAGES, StringUtil.join(",", keysSet)); //$NON-NLS-1$
	try
	{
		prefs.flush();
	}
	catch (Exception e)
	{
		IdeLog.logError(UIPlugin.getDefault(), e);
	}
}
 
Example 11
Source File: TypeScriptCorePreferenceInitializer.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * Fix the embedded TypeScript runtime ande node.js preference if needed.
 * 
 * @param preferences
 * @see https://github.com/angelozerr/typescript.java/issues/121
 */
public static void fixEmbeddedPreference(IEclipsePreferences preferences) {
	boolean refresh = false;
	// Fix embedded TypeScript runtime if needed
	String embeddedTypeScriptId = preferences.get(TypeScriptCorePreferenceConstants.EMBEDDED_TYPESCRIPT_ID, null);
	if (embeddedTypeScriptId != null
			&& TypeScriptCorePlugin.getTypeScriptRepositoryManager().getRepository(embeddedTypeScriptId) == null) {
		preferences.put(TypeScriptCorePreferenceConstants.EMBEDDED_TYPESCRIPT_ID,
				TypeScriptCorePlugin.getTypeScriptRepositoryManager().getDefaultRepository().getName());
		refresh = true;
	}
	// Fix embedded node.js if needed
	String embeddedNode = preferences.get(TypeScriptCorePreferenceConstants.NODEJS_EMBEDDED_ID, null);
	if (embeddedNode != null
			&& TypeScriptCorePlugin.getNodejsInstallManager().findNodejsInstall(embeddedNode) == null) {
		if (useBundledNodeJsEmbedded(preferences)) {
			refresh = true;
		}
	}
	if (refresh) {
		try {
			preferences.flush();
		} catch (BackingStoreException e) {
			Trace.trace(Trace.SEVERE, "Error while fixing embedded TypeScript runtime and node.js preference", e);
		}
	}
}
 
Example 12
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 13
Source File: Activator.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * In oxygen there is an nature solution lookup feature that causes a dialog to open for each imported project. 
 * We disable it since it's not a very useful feature.
 * 
 * @return
 */
private boolean disableProjectNatureSolutionLookup()
{
	IEclipsePreferences prefs =  InstanceScope.INSTANCE.getNode(ORG_ECLIPSE_EPP_MPC_UI_PREFS);
	boolean val = prefs.getBoolean(ORG_ECLIPSE_EPP_MPC_NATURELOOKUP, true);
	prefs.putBoolean(ORG_ECLIPSE_EPP_MPC_NATURELOOKUP, false);
	try {
		prefs.flush();
	} catch (BackingStoreException e) {
		throw new IllegalStateException(e);
	}
	return val;
}
 
Example 14
Source File: JSLintValidator.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @deprecated Remove as this is only used by testing, and we should be able to set the options in another way!
 * @param optionsAsJSON
 * @throws IllegalStateException
 *             if the JSON is un-parseable.
 */
protected void setJSONOptions(String optionsAsJSON) throws IllegalStateException
{
	JSON.parse(optionsAsJSON);
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode(getPreferenceNode());
	prefs.put(IPreferenceConstants.JS_LINT_OPTIONS, optionsAsJSON);
	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(BuildPathCorePlugin.getDefault(), e);
	}
}
 
Example 15
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected void applyToWST_CSSEditor(Theme theme, boolean revertToDefaults)
{
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("org.eclipse.wst.css.ui"); //$NON-NLS-1$
	setGeneralEditorValues(theme, prefs, revertToDefaults);

	setWSTToken(prefs, theme,
			"meta.property-name.css support.type.property-name.css", "PROPERTY_NAME", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "entity.other.attribute-name.class.css", "CLASS", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "ATTRIBUTE_VALUE", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "UNIVERSAL", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "punctuation.css", "COMBINATOR", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "punctuation.terminator.rule.css", "SEMI_COLON", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "punctuation.bracket.css", "ATTRIBUTE_DELIM", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "entity.name.tag.css", "SELECTOR", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "URI", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "ATTRIBUTE_NAME", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "punctuation.separator.key-value.css", "COLON", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "entity.other.attribute-name.id.css", "ID", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "NORMAL", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "string.quoted.css", "STRING", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "punctuation.section.property-list.css", "CURLY_BRACE", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "PSEUDO", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "comment.block.css", "COMMENT", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "support.constant.property-value.css", "PROPERTY_VALUE", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "keyword.control.at-rule.css", "ATMARK_RULE", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "source.css", "ATTRIBUTE_OPERATOR", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setWSTToken(prefs, theme, "support.constant.media.css", "MEDIA", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$

	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}
}
 
Example 16
Source File: ThemeManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private void setAnnotationColorsToMatchTheme(Theme theme)
{
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors"); //$NON-NLS-1$
	if (!theme.hasEntry("override.searchResultIndication")) //$NON-NLS-1$
	{
		prefs.put("searchResultIndicationColor", toString(theme.getSearchResultColor())); //$NON-NLS-1$
	}
	// TODO Use markup.changed bg color for "decoration color" in Prefs>General>Appearance>Colors and Fonts

	// TODO Move this stuff over to theme change listeners in the XML/HTML/Ruby editor plugins?
	if (!theme.hasEntry("override.xmlTagPairOccurrenceIndication")) //$NON-NLS-1$
	{
		prefs.putBoolean("xmlTagPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
		prefs.putBoolean("xmlTagPairOccurrenceIndication", true); //$NON-NLS-1$
		prefs.put("xmlTagPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
		prefs.put("xmlTagPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
	}
	if (!theme.hasEntry("override.htmlTagPairOccurrenceIndication")) //$NON-NLS-1$
	{
		prefs.putBoolean("htmlTagPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
		prefs.putBoolean("htmlTagPairOccurrenceIndication", true); //$NON-NLS-1$
		prefs.put("htmlTagPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
		prefs.put("htmlTagPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
	}
	if (!theme.hasEntry("override.rubyBlockPairOccurrenceIndication")) //$NON-NLS-1$
	{
		prefs.putBoolean("rubyBlockPairOccurrenceIndicationHighlighting", false); //$NON-NLS-1$
		prefs.putBoolean("rubyBlockPairOccurrenceIndication", true); //$NON-NLS-1$
		prefs.put("rubyBlockPairOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
		prefs.put("rubyBlockPairOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
	}
	// PyDev Occurrences (com.python.pydev.occurrences)
	// Override them if pydev is set to use our themes
	if (Platform.getPreferencesService().getBoolean("org.python.pydev.red_core", "PYDEV_USE_APTANA_THEMES", true, //$NON-NLS-1$ //$NON-NLS-2$
			null))
	{
		if (!theme.hasEntry("override.pydevOccurrenceIndication")) //$NON-NLS-1$
		{
			MarkerAnnotationPreferences preferences = new MarkerAnnotationPreferences();
			AnnotationPreference pydevOccurPref = null;
			for (Object obj : preferences.getAnnotationPreferences())
			{
				AnnotationPreference pref = (AnnotationPreference) obj;
				Object type = pref.getAnnotationType();
				if ("com.python.pydev.occurrences".equals(type)) //$NON-NLS-1$
				{
					pydevOccurPref = pref;
				}
			}
			if (pydevOccurPref != null)
			{
				if (pydevOccurPref.getTextStylePreferenceKey() != null)
				{
					// Now that pydev supports text style, use the box style and don't highlight.
					prefs.putBoolean("pydevOccurrenceHighlighting", false); //$NON-NLS-1$
					prefs.putBoolean("pydevOccurrenceIndication", true); //$NON-NLS-1$
					prefs.put("pydevOccurrenceIndicationColor", toString(theme.getOccurenceHighlightColor())); //$NON-NLS-1$
					prefs.put("pydevOccurrenceIndicationTextStyle", AnnotationPreference.STYLE_BOX); //$NON-NLS-1$
				}
				else
				{
					// Must use highlighting, since we're against older pydev that had no text style
					prefs.putBoolean("pydevOccurrenceHighlighting", true); //$NON-NLS-1$
					prefs.putBoolean("pydevOccurrenceIndication", true); //$NON-NLS-1$
					prefs.put("pydevOccurrenceIndicationColor", toString(theme.getSearchResultColor())); //$NON-NLS-1$
				}
			}
		}
	}

	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}
}
 
Example 17
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Hook up a listener for theme changes, and change the PHP occurrence colors!
 */
private void listenForThemeChanges()
{
	Job job = new UIJob("Set occurrence colors to theme") //$NON-NLS-1$
	{
		private void setOccurrenceColors()
		{
			IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors"); //$NON-NLS-1$
			Theme theme = ThemePlugin.getDefault().getThemeManager().getCurrentTheme();

			prefs.put("OccurrenceIndicationColor", StringConverter.asString(theme.getSearchResultColor())); //$NON-NLS-1$

			try
			{
				prefs.flush();
			}
			catch (BackingStoreException e)
			{
				// ignore
			}
		}

		@Override
		public IStatus runInUIThread(IProgressMonitor monitor)
		{
			fThemeChangeListener = new IPreferenceChangeListener()
			{
				public void preferenceChange(PreferenceChangeEvent event)
				{
					if (event.getKey().equals(IThemeManager.THEME_CHANGED))
					{
						setOccurrenceColors();
					}
				}
			};

			setOccurrenceColors();

			EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID)
					.addPreferenceChangeListener(fThemeChangeListener);

			return Status.OK_STATUS;
		}
	};

	EclipseUtil.setSystemForJob(job);
	job.schedule(2000);
}
 
Example 18
Source File: InvasiveThemeHijacker.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected void applyThemetoJDT(Theme theme, boolean revertToDefaults)
{
	// Now set for JDT...
	IEclipsePreferences prefs = EclipseUtil.instanceScope().getNode(ORG_ECLIPSE_JDT_UI);
	setGeneralEditorValues(theme, prefs, revertToDefaults);

	// Set prefs for JDT so it's various tokens get colors that match up to our theme!
	// prefs = EclipseUtil.instanceScope().getNode("org.eclipse.jdt.ui");
	setToken(prefs, theme, "string.quoted.double.java", "java_string", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "source.java", "java_default", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "keyword", "java_keyword", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "keyword.operator", "java_operator", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "keyword.control.java", "java_keyword_return", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "comment.line.double-slash.java", "java_single_line_comment", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "comment.block", "java_multi_line_comment", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "punctuation.bracket.java", "java_bracket", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	// Javadoc
	//String TASK_TAG= "java_comment_task_tag"; //$NON-NLS-1$
	setToken(prefs, theme, "keyword.other.documentation.java", "java_doc_keyword", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "entity.name.tag.inline.any.html", "java_doc_tag", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "markup.underline.link.javadoc", "java_doc_link", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "comment.block.documentation.javadoc", "java_doc_default", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$

	// deprecated
	// setToken(prefs, theme, "entity.name.function.java", "java_method_name", revertToDefaults);
	setToken(prefs, theme, "entity.name.type.class.java", "java_type", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "storage.type.annotation.java", "java_annotation", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$

	// Semantic
	setSemanticToken(prefs, theme, "entity.name.type.class.java", "class", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "entity.name.type.enum.java", "enum", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "entity.name.type.interface.java", "interface", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "constant.numeric.java", "number", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "variable.parameter.java", "parameterVariable", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "constant.other.java", "staticField", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "constant.other.java", "staticFinalField", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "entity.name.function.java", "methodDeclarationName", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "invalid.deprecated.java", "deprecatedMember", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "storage.type.annotation.java", "annotation", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "constant.other.key.java", "annotationElementReference", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "localVariable", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "field", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "staticMethodInvocation", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "inheritedMethodInvocation", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "abstractMethodInvocation", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "localVariableDeclaration", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "method", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "typeParameter", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "autoboxing", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setSemanticToken(prefs, theme, "source.java", "typeArgument", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$

	// Java *.properties files
	setToken(prefs, theme, "keyword.other.java-props", "pf_coloring_key", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "comment.line.number-sign.java-props", "pf_coloring_comment", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "string.java-props", "pf_coloring_value", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "punctuation.separator.key-value.java-props", "pf_coloring_assignment", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$
	setToken(prefs, theme, "string.interpolated.java-props", "pf_coloring_argument", revertToDefaults); //$NON-NLS-1$ //$NON-NLS-2$

	// Override pair matching colors
	if (!revertToDefaults)
	{
		// FIXME Revert back to default value if revertToDefaults!
		prefs.put("matchingBracketsColor", StringConverter.asString(theme.getCharacterPairColor())); //$NON-NLS-1$
	}

	try
	{
		prefs.flush();
	}
	catch (BackingStoreException e)
	{
		IdeLog.logError(ThemePlugin.getDefault(), e);
	}

	// Override JDT editor font
	Font fFont = JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT);
	JFaceResources.getFontRegistry().put("org.eclipse.jdt.ui.editors.textfont", fFont.getFontData()); //$NON-NLS-1$
}
 
Example 19
Source File: PreferenceInitializer.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void initializeDefaultPreferences()
{
	IEclipsePreferences prefs = EclipseUtil.defaultScope().getNode(JSCorePlugin.PLUGIN_ID);

	prefs.putDouble(IPreferenceConstants.JS_INDEX_VERSION, 0);

	// Warn on missing semicolons
	prefs.put(IPreferenceConstants.PREF_MISSING_SEMICOLON_SEVERITY, IProblem.Severity.WARNING.id());

	// Set up JS Parser validator to be on for build and reconcile
	prefs.putBoolean(PreferenceUtil.getEnablementPreferenceKey(JSParserValidator.ID, BuildType.BUILD), true);
	prefs.putBoolean(PreferenceUtil.getEnablementPreferenceKey(JSParserValidator.ID, BuildType.RECONCILE), true);

	// Set up JSLint prefs
	// Set default options
	// @formatter:off
	prefs.put(IPreferenceConstants.JS_LINT_OPTIONS, "{\n" + //$NON-NLS-1$
			"  \"laxLineEnd\": true,\n" + //$NON-NLS-1$
			"  \"undef\": true,\n" + //$NON-NLS-1$
			"  \"browser\": true,\n" + //$NON-NLS-1$
			"  \"jscript\": true,\n" + //$NON-NLS-1$
			"  \"debug\": true,\n" + //$NON-NLS-1$
			"  \"maxerr\": 100000,\n" + //$NON-NLS-1$
			"  \"white\": true,\n" + //$NON-NLS-1$
			"  \"predef\": [\n" + //$NON-NLS-1$
			"    \"Ti\",\n" + //$NON-NLS-1$
			"    \"Titanium\",\n" + //$NON-NLS-1$
			"    \"alert\",\n" + //$NON-NLS-1$
			"    \"require\",\n" + //$NON-NLS-1$
			"    \"exports\",\n" + //$NON-NLS-1$
			"    \"native\",\n" + //$NON-NLS-1$
			"    \"implements\",\n" + //$NON-NLS-1$
			"  ]\n" + //$NON-NLS-1$
			"}"); //$NON-NLS-1$
	// @formatter:on

	// Set default JSLint filters
	String[] defaultJSLintFilters = new String[] {
			"Missing space between .+", "Unexpected '\\(space\\)'\\.", //$NON-NLS-1$ //$NON-NLS-2$
			"Expected '.+' at column \\d+, not column \\d+\\.", "Unexpected space between .+", "Expected exactly one space between .+" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	prefs.put(PreferenceUtil.getFiltersKey(JSLintValidator.ID),
			PreferenceUtil.serializeFilters(defaultJSLintFilters));

	// Migrate the old filter prefs to new validator
	IEclipsePreferences cepPrefs = EclipseUtil.instanceScope().getNode("com.aptana.editor.common"); //$NON-NLS-1$
	String oldKey = MessageFormat.format("{0}:{1}", IJSConstants.CONTENT_TYPE_JS, //$NON-NLS-1$
			"com.aptana.editor.common.filterExpressions"); //$NON-NLS-1$
	String oldFilters = cepPrefs.get(oldKey, null);
	if (oldFilters != null)
	{
		try
		{
			String[] oldFilterArray = oldFilters.split(AbstractBuildParticipant.FILTER_DELIMITER);
			String[] combined = ArrayUtil.flatten(oldFilterArray, defaultJSLintFilters);

			IEclipsePreferences newPrefs = EclipseUtil.instanceScope().getNode(JSCorePlugin.PLUGIN_ID);
			newPrefs.put(PreferenceUtil.getFiltersKey(JSLintValidator.ID),
					PreferenceUtil.serializeFilters(combined));
			newPrefs.flush();
			cepPrefs.remove(oldKey);
		}
		catch (BackingStoreException e)
		{
			// ignore
		}
	}
}
 
Example 20
Source File: CheckstyleUIPluginPrefs.java    From eclipse-cs with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Set a boolean preference for the given preference id.
 * 
 * @param prefId
 *          the preference id
 * @param value
 *          the boolean value
 * @throws BackingStoreException
 *           if this operation cannot be completed due to a failure in the
 *           backing store, or inability to communicate with it.
 */
public static void setBoolean(String prefId, boolean value) throws BackingStoreException {

  IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(CheckstyleUIPlugin.PLUGIN_ID);
  prefs.putBoolean(prefId, value);
  prefs.flush();
}