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

The following examples show how to use org.eclipse.core.runtime.preferences.IEclipsePreferences#NodeChangeEvent . 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: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Initialize preferences lookups for JavaCore plug-in.
 */
public void initializePreferences() {

	// Create lookups
	this.preferencesLookup[PREF_INSTANCE] = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
	this.preferencesLookup[PREF_DEFAULT] = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);

	// Listen to instance preferences node removal from parent in order to refresh stored one
	this.instanceNodeListener = new IEclipsePreferences.INodeChangeListener() {
		public void added(IEclipsePreferences.NodeChangeEvent event) {
			// do nothing
		}
		public void removed(IEclipsePreferences.NodeChangeEvent event) {
			if (event.getChild() == JavaModelManager.this.preferencesLookup[PREF_INSTANCE]) {
				JavaModelManager.this.preferencesLookup[PREF_INSTANCE] = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
				JavaModelManager.this.preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
			}
		}
	};
	((IEclipsePreferences) this.preferencesLookup[PREF_INSTANCE].parent()).addNodeChangeListener(this.instanceNodeListener);
	this.preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(this.instancePreferencesListener = new EclipsePreferencesListener());

	// Listen to default preferences node removal from parent in order to refresh stored one
	this.defaultNodeListener = new IEclipsePreferences.INodeChangeListener() {
		public void added(IEclipsePreferences.NodeChangeEvent event) {
			// do nothing
		}
		public void removed(IEclipsePreferences.NodeChangeEvent event) {
			if (event.getChild() == JavaModelManager.this.preferencesLookup[PREF_DEFAULT]) {
				JavaModelManager.this.preferencesLookup[PREF_DEFAULT] = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
			}
		}
	};
	((IEclipsePreferences) this.preferencesLookup[PREF_DEFAULT].parent()).addNodeChangeListener(this.defaultNodeListener);
}
 
Example 2
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void added(IEclipsePreferences.NodeChangeEvent event) {
	// do nothing
}
 
Example 3
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void removed(IEclipsePreferences.NodeChangeEvent event) {
	if (event.getChild() == JavaModelManager.this.preferencesLookup[PREF_INSTANCE]) {
		JavaModelManager.this.preferencesLookup[PREF_INSTANCE] = InstanceScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
		JavaModelManager.this.preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
	}
}
 
Example 4
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void added(IEclipsePreferences.NodeChangeEvent event) {
	// do nothing
}
 
Example 5
Source File: JavaModelManager.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void removed(IEclipsePreferences.NodeChangeEvent event) {
	if (event.getChild() == JavaModelManager.this.preferencesLookup[PREF_DEFAULT]) {
		JavaModelManager.this.preferencesLookup[PREF_DEFAULT] = DefaultScope.INSTANCE.getNode(JavaCore.PLUGIN_ID);
	}
}
 
Example 6
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;
}