Java Code Examples for org.eclipse.core.runtime.preferences.IEclipsePreferences#IPreferenceChangeListener

The following examples show how to use org.eclipse.core.runtime.preferences.IEclipsePreferences#IPreferenceChangeListener . 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: FixedScopedPreferenceStore.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Initialize the preferences listener.
 */
private void initializePreferencesListener() {
	if (preferencesListener == null) {
		preferencesListener = new IEclipsePreferences.IPreferenceChangeListener() {
			/*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener#preferenceChange(org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent)
			 */
			@Override
			public void preferenceChange(PreferenceChangeEvent event) {

				if (silentRunning) {
					return;
				}

				Object oldValue = event.getOldValue();
				Object newValue = event.getNewValue();
				String key = event.getKey();
				if (newValue == null) {
					newValue = getDefault(key, oldValue);
				} else if (oldValue == null) {
					oldValue = getDefault(key, newValue);
				}
				firePropertyChangeEvent(event.getKey(), oldValue, newValue);
			}
		};
		getStorePreferences().addPreferenceChangeListener(
				preferencesListener);
	}

}
 
Example 2
Source File: NodeModuleResolver.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected synchronized IPath nodeSrcPath()
{
	// Cache value and hook pref listener
	if (fNodeSrcPathListener == null)
	{
		fNodeSrcPathListener = new IEclipsePreferences.IPreferenceChangeListener()
		{
			public void preferenceChange(PreferenceChangeEvent event)
			{
				if (IPreferenceConstants.NODEJS_SOURCE_PATH.equals(event.getKey()))
				{
					String value = (String) event.getNewValue();
					if (StringUtil.isEmpty(value))
					{
						fNodeSrcPath = null;
					}
					else
					{
						fNodeSrcPath = Path.fromOSString(value);
					}
				}
			}
		};
		EclipseUtil.instanceScope().getNode(JSCorePlugin.PLUGIN_ID)
				.addPreferenceChangeListener(fNodeSrcPathListener);

		String value = Platform.getPreferencesService().getString(JSCorePlugin.PLUGIN_ID,
				IPreferenceConstants.NODEJS_SOURCE_PATH, null, null);
		if (StringUtil.isEmpty(value))
		{
			fNodeSrcPath = null;
		}
		else
		{
			fNodeSrcPath = Path.fromOSString(value);
		}
	}

	return fNodeSrcPath;
}
 
Example 3
Source File: TaskTag.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Add a pref change listener for changes to values, set up starting values. This is a performance change so we
 * don't lookup the preference values repeatedly.
 */
protected synchronized static void initializeValues()
{
	if (fgPrefListener == null)
	{
		final IScopeContext[] contexts = new IScopeContext[] { EclipseUtil.instanceScope(),
				EclipseUtil.defaultScope() };
		try
		{
			fgPrefListener = new IEclipsePreferences.IPreferenceChangeListener()
			{

				public void preferenceChange(PreferenceChangeEvent event)
				{
					if (ICorePreferenceConstants.TASK_TAGS_CASE_SENSITIVE.equals(event.getKey()))
					{
						fgCaseSensitive = Platform.getPreferencesService().getBoolean(PREF_PLUGIN_ID,
								ICorePreferenceConstants.TASK_TAGS_CASE_SENSITIVE, true, contexts);
					}
					else if (ICorePreferenceConstants.TASK_TAG_PRIORITIES.equals(event.getKey())
							|| ICorePreferenceConstants.TASK_TAG_NAMES.equals(event.getKey()))
					{
						fgTaskTags = getCurrentTaskTags();
					}
				}
			};
			EclipseUtil.instanceScope().getNode(PREF_PLUGIN_ID).addPreferenceChangeListener(fgPrefListener);
		}
		catch (Exception e)
		{
			IdeLog.logError(CorePlugin.getDefault(), "Failed to attach preference listener for task tag prefs", e); //$NON-NLS-1$
			fgPrefListener = null;
		}
		fgCaseSensitive = Platform.getPreferencesService().getBoolean(PREF_PLUGIN_ID,
				ICorePreferenceConstants.TASK_TAGS_CASE_SENSITIVE, true, contexts);
	}
	if (fgTaskTags == null)
	{
		fgTaskTags = getCurrentTaskTags();
	}
}
 
Example 4
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the project custom preference pool.
 * Project preferences may include custom encoding.
 * @return IEclipsePreferences or <code>null</code> if the project
 * 	does not have a java nature.
 */
public IEclipsePreferences getEclipsePreferences() {
	if (!JavaProject.hasJavaNature(this.project)) return null;
	// Get cached preferences if exist
	JavaModelManager.PerProjectInfo perProjectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfo(this.project, true);
	if (perProjectInfo.preferences != null) return perProjectInfo.preferences;
	// Init project preferences
	IScopeContext context = new ProjectScope(getProject());
	final IEclipsePreferences eclipsePreferences = context.getNode(JavaCore.PLUGIN_ID);
	updatePreferences(eclipsePreferences);
	perProjectInfo.preferences = eclipsePreferences;

	// Listen to new preferences node
	final IEclipsePreferences eclipseParentPreferences = (IEclipsePreferences) eclipsePreferences.parent();
	if (eclipseParentPreferences != null) {
		if (this.preferencesNodeListener != null) {
			eclipseParentPreferences.removeNodeChangeListener(this.preferencesNodeListener);
		}
		this.preferencesNodeListener = new IEclipsePreferences.INodeChangeListener() {
			public void added(IEclipsePreferences.NodeChangeEvent event) {
				// do nothing
			}
			public void removed(IEclipsePreferences.NodeChangeEvent event) {
				if (event.getChild() == eclipsePreferences) {
					JavaModelManager.getJavaModelManager().resetProjectPreferences(JavaProject.this);
				}
			}
		};
		eclipseParentPreferences.addNodeChangeListener(this.preferencesNodeListener);
	}

	// Listen to preferences changes
	if (this.preferencesChangeListener != null) {
		eclipsePreferences.removePreferenceChangeListener(this.preferencesChangeListener);
	}
	this.preferencesChangeListener = new IEclipsePreferences.IPreferenceChangeListener() {
		public void preferenceChange(IEclipsePreferences.PreferenceChangeEvent event) {
			String propertyName = event.getKey();
			JavaModelManager manager = JavaModelManager.getJavaModelManager();
			if (propertyName.startsWith(JavaCore.PLUGIN_ID)) {
				if (propertyName.equals(JavaCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER) ||
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_RESOURCE_COPY_FILTER) ||
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_DUPLICATE_RESOURCE) ||
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_RECREATE_MODIFIED_CLASS_FILES_IN_OUTPUT_FOLDER) ||
					propertyName.equals(JavaCore.CORE_JAVA_BUILD_INVALID_CLASSPATH) ||
					propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_EXCLUSION_PATTERNS) ||
					propertyName.equals(JavaCore.CORE_ENABLE_CLASSPATH_MULTIPLE_OUTPUT_LOCATIONS) ||
					propertyName.equals(JavaCore.CORE_INCOMPLETE_CLASSPATH) ||
					propertyName.equals(JavaCore.CORE_CIRCULAR_CLASSPATH) ||
					propertyName.equals(JavaCore.CORE_OUTPUT_LOCATION_OVERLAPPING_ANOTHER_SOURCE) ||
					propertyName.equals(JavaCore.CORE_INCOMPATIBLE_JDK_LEVEL) ||
					propertyName.equals(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM))
				{
					manager.deltaState.addClasspathValidation(JavaProject.this);
				}
				manager.resetProjectOptions(JavaProject.this);
				JavaProject.this.resetCaches(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=233568
			}
		}
	};
	eclipsePreferences.addPreferenceChangeListener(this.preferencesChangeListener);
	return eclipsePreferences;
}
 
Example 5
Source File: PyParserManager.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructor
 *
 * @param prefs the prefs to get to the parser
 */
private PyParserManager(IEclipsePreferences prefs) {
    super();
    Assert.isNotNull(prefs); //in this constructor the prefs may never be null!

    //Override the default to deal with pydev preferences.
    this.prefs = prefs;
    this.millisBeforeAnalysis = prefs.getInt(PYDEV_ELAPSE_BEFORE_ANALYSIS,
            PyDevBuilderPreferences.DEFAULT_PYDEV_ELAPSE_BEFORE_ANALYSIS);

    this.useOnlyOnSave = prefs.getBoolean(USE_PYDEV_ANALYSIS_ONLY_ON_DOC_SAVE,
            PyDevBuilderPreferences.DEFAULT_USE_PYDEV_ONLY_ON_DOC_SAVE);

    //singleton: private constructor
    IEclipsePreferences.IPreferenceChangeListener prefListener = new IEclipsePreferences.IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            String property = event.getKey();
            if (property.equals(USE_PYDEV_ANALYSIS_ONLY_ON_DOC_SAVE)
                    || property.equals(PYDEV_ELAPSE_BEFORE_ANALYSIS)) {
                //reset the caches
                millisBeforeAnalysis = PyParserManager.this.prefs.getInt(PYDEV_ELAPSE_BEFORE_ANALYSIS,
                        PyDevBuilderPreferences.DEFAULT_PYDEV_ELAPSE_BEFORE_ANALYSIS);

                useOnlyOnSave = PyParserManager.this.prefs.getBoolean(USE_PYDEV_ANALYSIS_ONLY_ON_DOC_SAVE,
                        PyDevBuilderPreferences.DEFAULT_USE_PYDEV_ONLY_ON_DOC_SAVE);

                //and set the needed parsers
                boolean useAnalysisOnlyOnDocSave = useAnalysisOnlyOnDocSave();

                synchronized (lock) {
                    for (IParser parser : parsers.keySet()) {
                        parser.resetTimeoutPreferences(useAnalysisOnlyOnDocSave);
                    }
                }
            }
        }
    };
    this.prefs.addPreferenceChangeListener(prefListener);
}