Search in sources :

Example 1 with PropertyChangeEvent

use of org.eclipse.core.runtime.Preferences.PropertyChangeEvent in project yamcs-studio by yamcs.

the class OPIBuilderPlugin method start.

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
    resources = new ResourceHelper();
    ui = new UIHelper();
    // set this to resolve Xincludes in XMLs
    System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", "org.apache.xerces.parsers.XIncludeParserConfiguration");
    ScriptService.getInstance();
    if (PreferencesHelper.isDisplaySystemOutput()) {
        ConsoleService.getInstance().turnOnSystemOutput();
    }
    preferenceLisener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(PreferencesHelper.COLOR_FILE))
                MediaService.getInstance().reloadColorFile();
            else if (event.getProperty().equals(PreferencesHelper.FONT_FILE))
                MediaService.getInstance().reloadFontFile();
            else if (event.getProperty().equals(PreferencesHelper.OPI_GUI_REFRESH_CYCLE))
                GUIRefreshThread.getInstance(true).reLoadGUIRefreshCycle();
            else if (event.getProperty().equals(PreferencesHelper.DISABLE_ADVANCED_GRAPHICS)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                String disabled = PreferencesHelper.isAdvancedGraphicsDisabled() ? "true" : "false";
                // for swt.widgets
                System.setProperty("org.csstudio.swt.widget.prohibit_advanced_graphics", // $NON-NLS-1$
                disabled);
                // for XYGraph
                // $NON-NLS-1$
                System.setProperty("prohibit_advanced_graphics", disabled);
            } else if (event.getProperty().equals(PreferencesHelper.URL_FILE_LOADING_TIMEOUT))
                System.setProperty(// $NON-NLS-1$
                "org.csstudio.swt.widget.url_file_load_timeout", Integer.toString(PreferencesHelper.getURLFileLoadingTimeout()));
            else if (event.getProperty().equals(PreferencesHelper.SCHEMA_OPI)) {
                SchemaService.getInstance().reLoad();
            } else if (event.getProperty().equals(PreferencesHelper.DISPLAY_SYSTEM_OUTPUT)) {
                if (PreferencesHelper.isDisplaySystemOutput())
                    ConsoleService.getInstance().turnOnSystemOutput();
                else
                    ConsoleService.getInstance().turnOffSystemOutput();
            }
        }
    };
    getPluginPreferences().addPropertyChangeListener(preferenceLisener);
    @SuppressWarnings("serial")
    class HackPropertyChangeEvent extends PropertyChangeEvent {

        public HackPropertyChangeEvent(Object source, String property, Object oldValue, Object newValue) {
            super(source, property, oldValue, newValue);
        }
    }
    preferenceLisener.propertyChange(new HackPropertyChangeEvent(this, PreferencesHelper.DISABLE_ADVANCED_GRAPHICS, null, null));
    preferenceLisener.propertyChange(new HackPropertyChangeEvent(this, PreferencesHelper.URL_FILE_LOADING_TIMEOUT, null, null));
}
Also used : IPropertyChangeListener(org.eclipse.core.runtime.Preferences.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) ResourceHelper(org.csstudio.utility.singlesource.ResourceHelper) UIHelper(org.csstudio.utility.singlesource.UIHelper)

Example 2 with PropertyChangeEvent

use of org.eclipse.core.runtime.Preferences.PropertyChangeEvent in project eclipse.platform.runtime by eclipse.

the class PreferenceForwarderTest method testListenerOnRemove.

/* Comment this test out until we are able to use session tests
	 * with it. - ddw
	 * 	public void testPluginPrefs() {
	 IPluginRegistry registry = InternalPlatform.getPluginRegistry();
	 IPluginDescriptor resPlugin = registry.getPluginDescriptor("org.eclipse.core.resources");
	 Preferences perfs = null;
	 try {
	 perfs = resPlugin.getPlugin().getPluginPreferences();
	 } catch (CoreException ce) {
	 fail("0.1 core exception from getPlugin");
	 }
	 boolean oneBoolean = perfs.getBoolean("OneBoolean");
	 double oneDouble = perfs.getDouble("OneDouble");
	 float oneFloat = perfs.getFloat("OneFloat");
	 int oneInt = perfs.getInt("OneInt");
	 long oneLong = perfs.getLong("OneLong");
	 String oneString = perfs.getString("OneString");
	 assertTrue("1.0 boolean", oneBoolean);
	 assertTrue("2.0 double", oneDouble == 4);
	 assertTrue("3.0 float", oneFloat ==	4.3f);
	 assertTrue("4.0 int", oneInt == 5);
	 assertTrue("5.0 long", oneLong == 6);
	 assertTrue("6.0 string", oneString.equals("A string from the plugin root directory"));
	 int a = 4;
	 int b = 3;
	 }
	 */
/*
	 * Regression test for bug 178815.
	 */
public void testListenerOnRemove() {
    // create a new log listener that will fail if anything is written
    ILogListener logListener = new ILogListener() {

        @Override
        public void logging(IStatus status, String plugin) {
            CoreException ex = new CoreException(status);
            fail("0.99", ex);
        }
    };
    // set a preference value to get everything initialized
    String id = getUniqueString();
    Preferences ps = new PreferenceForwarder(id);
    ps.setValue("key", "value");
    // add a property change listener which will cause one to be
    // added at the preference node level
    IPropertyChangeListener listener = new Preferences.IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
        }
    };
    ps.addPropertyChangeListener(listener);
    ps.setValue("key2", "value2");
    IEclipsePreferences node = InstanceScope.INSTANCE.getNode(id);
    // add our log listener and remove the node. nothing should be logged.
    RuntimeLog.addLogListener(logListener);
    try {
        node.removeNode();
    } catch (BackingStoreException e) {
        fail("4.99", e);
    } catch (IllegalStateException e) {
        fail("5.00", e);
    } finally {
        RuntimeLog.removeLogListener(logListener);
    }
}
Also used : IPropertyChangeListener(org.eclipse.core.runtime.Preferences.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) PreferenceForwarder(org.eclipse.core.internal.preferences.legacy.PreferenceForwarder)

Aggregations

IPropertyChangeListener (org.eclipse.core.runtime.Preferences.IPropertyChangeListener)2 PropertyChangeEvent (org.eclipse.core.runtime.Preferences.PropertyChangeEvent)2 ResourceHelper (org.csstudio.utility.singlesource.ResourceHelper)1 UIHelper (org.csstudio.utility.singlesource.UIHelper)1 PreferenceForwarder (org.eclipse.core.internal.preferences.legacy.PreferenceForwarder)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1