org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener Java Examples

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: ConsoleThemer.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * listenForThemeChanges
 */
private void listenForThemeChanges()
{
	this.fThemeChangeListener = new IPreferenceChangeListener()
	{
		public void preferenceChange(PreferenceChangeEvent event)
		{
			if (event.getKey().equals(IThemeManager.THEME_CHANGED))
			{
				applyTheme();
			}
		}
	};

	EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID).addPreferenceChangeListener(this.fThemeChangeListener);
}
 
Example #2
Source File: ThemeManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Remove preference change listener to observe changed of Eclipse E4 Theme and
 * TextMate theme association with grammar.
 * 
 * @param themeChangeListener
 */
public void removePreferenceChangeListener(IPreferenceChangeListener themeChangeListener) {
	// Observe change of Eclipse E4 Theme
	IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore();
	if (preferences != null) {
		preferences.removePreferenceChangeListener(themeChangeListener);
	}
	// Observe change of TextMate Theme association
	preferences = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID);
	if (preferences != null) {
		preferences.removePreferenceChangeListener(themeChangeListener);
	}
}
 
Example #3
Source File: SourceCodeTextEditor.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public SourceCodeTextEditor() {
	super();
	rulerPainters = LineNumberColumnPainterRegistry.get().contributions();
	
	corePluginPreferenceListener = new IPreferenceChangeListener() {
		@Override
		public void preferenceChange(PreferenceChangeEvent event) {
			String key = event.getKey();
			if (PreferenceKeys.PKEY_EXECUTABLE_SOURCE_CODE_COLOR.getKey().equals(key)) {
				fLineNumberRulerColumn.redraw();
			}
		}
	};
	PreferenceKeys.addChangeListener(corePluginPreferenceListener);
}
 
Example #4
Source File: ThemeManager.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add preference change listener to observe changed of Eclipse E4 Theme and
 * TextMate theme association with grammar.
 * 
 * @param themeChangeListener
 */
public void addPreferenceChangeListener(IPreferenceChangeListener themeChangeListener) {
	// Observe change of Eclipse E4 Theme
	IEclipsePreferences preferences = PreferenceUtils.getE4PreferenceStore();
	if (preferences != null) {
		preferences.addPreferenceChangeListener(themeChangeListener);
	}
	// Observe change of TextMate Theme association
	preferences = InstanceScope.INSTANCE.getNode(TMUIPlugin.PLUGIN_ID);
	if (preferences != null) {
		preferences.addPreferenceChangeListener(themeChangeListener);
	}
}
 
Example #5
Source File: AllCleanUpsAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void installPreferenceListener() {
   fPreferenceChangeListener= new IPreferenceChangeListener() {
	public void preferenceChange(PreferenceChangeEvent event) {
		if (event.getKey().equals(CleanUpConstants.SHOW_CLEAN_UP_WIZARD)) {
			updateActionLabel();
		}
	}
};
InstanceScope.INSTANCE.getNode(JavaUI.ID_PLUGIN).addPreferenceChangeListener(fPreferenceChangeListener);
  }
 
Example #6
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 #7
Source File: PreferenceKey.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void addChangeListener(IScopeContext context, IWorkingCopyManager manager, 
                                     String qualifier, IPreferenceChangeListener listener) 
{
    IEclipsePreferences node= context.getNode(qualifier);
    if (manager != null) {
        node =  manager.getWorkingCopy(node);
    }
    node.addPreferenceChangeListener(listener);
}
 
Example #8
Source File: PreferenceKey.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static void removeChangeListener(IScopeContext context, IWorkingCopyManager manager, 
                                        String qualifier, IPreferenceChangeListener listener) 
{
    IEclipsePreferences node= context.getNode(qualifier);
    if (manager != null) {
        node =  manager.getWorkingCopy(node);
    }
    node.removePreferenceChangeListener(listener);
}
 
Example #9
Source File: ControlThemer.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void addThemeChangeListener()
{
	// TODO Just use one global listener that updates all instances?
	fThemeChangeListener = new IPreferenceChangeListener()
	{
		public void preferenceChange(PreferenceChangeEvent event)
		{
			if (event.getKey().equals(IThemeManager.THEME_CHANGED))
			{
				applyTheme();
			}
			else if (event.getKey().equals(IPreferenceConstants.INVASIVE_FONT))
			{
				// Handle the invasive font setting change
				if (Boolean.parseBoolean((String) event.getNewValue()))
				{
					applyControlFont();
				}
				else
				{
					unapplyControlFont();
				}
			}
			else if (event.getKey().equals(IPreferenceConstants.APPLY_TO_ALL_VIEWS))
			{
				if (Boolean.parseBoolean((String) event.getNewValue()))
				{
					applyTheme();
				}
				else
				{
					unapplyTheme();
				}
			}
		}
	};
	EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID).addPreferenceChangeListener(fThemeChangeListener);
}
 
Example #10
Source File: TmfAlignmentSynchronizer.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private IPreferenceChangeListener createPreferenceListener() {
    IPreferenceChangeListener listener = event -> {
        if (event.getKey().equals(ITmfUIPreferences.PREF_ALIGN_VIEWS)) {
            Object oldValue = event.getOldValue();
            Object newValue = event.getNewValue();
            if (Boolean.toString(false).equals(oldValue) && Boolean.toString(true).equals(newValue)) {
                realignViews();
            } else if (Boolean.toString(true).equals(oldValue) && Boolean.toString(false).equals(newValue)) {
                restoreViews();
            }
        }
    };
    InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID).addPreferenceChangeListener(listener);
    return listener;
}
 
Example #11
Source File: DebugEarlyStartup.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void earlyStartup() {
    //Note: preferences are in the PydevPlugin, not in the debug plugin.
    IEclipsePreferences preferenceStore = PydevPrefs.getEclipsePreferences();
    preferenceStore.addPreferenceChangeListener(new IPreferenceChangeListener() {

        @Override
        public void preferenceChange(PreferenceChangeEvent event) {
            if (DebugPluginPrefsInitializer.DEBUG_SERVER_STARTUP.equals(event.getKey())) {
                //On a change in the preferences, re-check if it should be always on...
                checkAlwaysOnJob.schedule(200);
            }
        }
    });

    RemoteDebuggerServer.getInstance().addListener(new IRemoteDebuggerListener() {

        @Override
        public void stopped(RemoteDebuggerServer remoteDebuggerServer) {
            //When it stops, re-check if it should be always on.
            checkAlwaysOnJob.schedule(200);
        }
    });
    checkAlwaysOnJob.schedule(500); //wait a little bit more to enable on startup.

    DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() {

        @Override
        public void handleDebugEvents(DebugEvent[] events) {
            if (events != null) {
                for (DebugEvent debugEvent : events) {
                    if (debugEvent.getKind() == DebugEvent.SUSPEND) {
                        if (debugEvent.getDetail() == DebugEvent.BREAKPOINT) {
                            if (debugEvent.getSource() instanceof PyThread) {

                                IPreferenceStore preferenceStore2 = PyDevUiPrefs.getPreferenceStore();
                                final int forceOption = preferenceStore2
                                        .getInt(DebugPluginPrefsInitializer.FORCE_SHOW_SHELL_ON_BREAKPOINT);

                                if (forceOption != DebugPluginPrefsInitializer.FORCE_SHOW_SHELL_ON_BREAKPOINT_MAKE_NOTHING) {
                                    Runnable r = new Runnable() {

                                        @Override
                                        public void run() {
                                            Shell activeShell = UIUtils.getActiveShell();
                                            if (activeShell != null) {
                                                forceActive(activeShell, forceOption);
                                            }
                                        }
                                    };
                                    boolean runNowIfInUiThread = true;
                                    RunInUiThread.async(r, runNowIfInUiThread);
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
 
Example #12
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 #13
Source File: ThemeManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
private ThemeManager()
{
	EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors").addPreferenceChangeListener( //$NON-NLS-1$
			new IPreferenceChangeListener()
			{

				public void preferenceChange(PreferenceChangeEvent event)
				{
					// Listen to see if the user is modifying the annotations through Annotations pref page
					for (String prefix : annotationKeyPrefixes)
					{
						if (event.getKey().startsWith(prefix))
						{
							final String scopeSelector = "override." + prefix; //$NON-NLS-1$
							// If it's color and getting set to null, then it probably means that user
							// chose to restore defaults. Does that mean we should remove override?
							if (event.getNewValue() == null && event.getKey().endsWith("Color")) //$NON-NLS-1$
							{
								// Do we need to run this in a delayed job to avoid clashes when the other pref
								// changes come through at same time...?
								Job job = new UIJob("Restoring overrides of Annotation") //$NON-NLS-1$
								{
									@Override
									public IStatus runInUIThread(IProgressMonitor monitor)
									{
										ThemeRule rule = getCurrentTheme().getRuleForSelector(
												new ScopeSelector(scopeSelector));
										if (rule != null)
										{
											getCurrentTheme().remove(rule);
										}
										return Status.OK_STATUS;
									}
								};
								EclipseUtil.setSystemForJob(job);
								job.setPriority(Job.DECORATE);
								job.schedule();
							}
							else
							{
								if (!getCurrentTheme().hasEntry(scopeSelector))
								{
									// Store that the user has overridden this annotation in this theme
									int index = getCurrentTheme().getTokens().size();
									getCurrentTheme().addNewRule(index, "Annotation Override - " + prefix, //$NON-NLS-1$
											new ScopeSelector(scopeSelector), null);
								}

							}
							break;
						}
					}
				}
			});
}
 
Example #14
Source File: ThemePlugin.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void start(BundleContext context) throws Exception
	{
		super.start(context);
		plugin = this;
		
//		if (OS.isMacintosh()) {
//		      IEclipsePreferences prefs1 = EclipseUtil.instanceScope().getNode("org.eclipse.jdt.ui");
//		      String path = Platform.getInstanceLocation().getURL().getPath();
//		      String path1 = "/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.workbench.prefs";
//		      String prefspath = path + path1;
//		      File prefFile = new File(prefspath);
//		      if (!(prefFile.exists()))
//		      {
//		        prefFile.createNewFile();
//		      }
//		      IEclipsePreferences prefs2 = EclipseUtil.instanceScope().getNode("org.eclipse.ui.workbench");
//
//		      String fontsize = prefs1.get("org.eclipse.jface.textfont", "");
//		      prefs2.put("org.eclipse.jface.textfont", fontsize);
//		}		

		// Listen to when invasive themes is turned on or off and cache the value for perf sake
		fThemeChangeListener = new IPreferenceChangeListener()
		{
			public void preferenceChange(PreferenceChangeEvent event)
			{
				if (IPreferenceConstants.APPLY_TO_ALL_VIEWS.equals(event.getKey()))
				{
					fApplyThemeToAllViews = Platform.getPreferencesService().getBoolean(ThemePlugin.PLUGIN_ID,
							IPreferenceConstants.APPLY_TO_ALL_VIEWS, false, null);
				}
				else if (IPreferenceConstants.APPLY_TO_ALL_EDITORS.equals(event.getKey()))
				{
					fApplyThemeToAllEditors = Platform.getPreferencesService().getBoolean(ThemePlugin.PLUGIN_ID,
							IPreferenceConstants.APPLY_TO_ALL_EDITORS, false, null);
				}
			}
		};
		EclipseUtil.instanceScope().getNode(ThemePlugin.PLUGIN_ID).addPreferenceChangeListener(fThemeChangeListener);
		fApplyThemeToAllViews = Platform.getPreferencesService().getBoolean(ThemePlugin.PLUGIN_ID,
				IPreferenceConstants.APPLY_TO_ALL_VIEWS, false, null);
		fApplyThemeToAllEditors = Platform.getPreferencesService().getBoolean(ThemePlugin.PLUGIN_ID,
				IPreferenceConstants.APPLY_TO_ALL_EDITORS, false, null);

		themeHijacker = new InvasiveThemeHijacker();
		themeHijacker.apply();

		// Listen for changes to eclipse editor colors and synch them back to our theme
		fEclipseColorsListener = new EditorColorSyncher();
		EclipseUtil.instanceScope().getNode("org.eclipse.ui.editors") //$NON-NLS-1$
				.addPreferenceChangeListener(fEclipseColorsListener);
	}
 
Example #15
Source File: PreferenceKeys.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void removeChangeListener(IPreferenceChangeListener listener){
	PreferenceKey.removeChangeListener(XdsCorePlugin.PLUGIN_ID, listener);
}
 
Example #16
Source File: PreferenceKeys.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void addChangeListener(IPreferenceChangeListener listener){
	PreferenceKey.addChangeListener(XdsCorePlugin.PLUGIN_ID, listener);
}
 
Example #17
Source File: PreferenceKey.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void removeChangeListener(String qualifier, IPreferenceChangeListener listener) 
{
    removeChangeListener(defScope, defManager, qualifier, listener);
}
 
Example #18
Source File: PreferenceKey.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void addChangeListener(String qualifier, IPreferenceChangeListener listener) 
{
    addChangeListener(defScope, defManager, qualifier, listener);
}
 
Example #19
Source File: PreferenceKey.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public void addChangeListener(IPreferenceChangeListener listener) {
	addChangeListener(getQualifier(), listener);
}
 
Example #20
Source File: AbstractProjectSettings.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public void removeChangeListener(IPreferenceChangeListener listener) {
	PreferenceKey.removeChangeListener(projectScope, null, quailifier, listener);
}
 
Example #21
Source File: AbstractProjectSettings.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public void addChangeListener(IPreferenceChangeListener listener) {
	PreferenceKey.addChangeListener(projectScope, null, quailifier, listener);
}