Example usage for org.eclipse.jface.preference IPreferenceStore addPropertyChangeListener

List of usage examples for org.eclipse.jface.preference IPreferenceStore addPropertyChangeListener

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferenceStore addPropertyChangeListener.

Prototype

void addPropertyChangeListener(IPropertyChangeListener listener);

Source Link

Document

Adds a property change listener to this preference store.

Usage

From source file:ca.uvic.cs.tagsea.monitoring.internal.Monitoring.java

License:Open Source License

/**
 * @param monitors2/* w w w.  java2s. c o  m*/
 */
private void hookPreferences() {
    IPreferenceStore prefs = TagSEAPlugin.getDefault().getPreferenceStore();
    prefs.addPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            String prop = event.getProperty();
            boolean active = false;
            try {
                active = Boolean.parseBoolean(event.getNewValue().toString());
            } catch (Exception e) {
                return;
            }
            ITagSEAMonitor monitor = getMonitorForPreference(prop);
            if (monitor != null) {
                synchronized (monitors) {
                    if (active) {
                        activate(monitor);
                        monitors.add(monitor);
                    } else {
                        monitors.remove(monitor);
                    }
                }
            }
        }
    });
}

From source file:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileMonitor.java

License:Apache License

/**
 * @param prefStore/*  w w  w .  j av a  2s.com*/
 *            the preference store where the credentials file's location is
 *            configured.
 */
public void start(IPreferenceStore prefStore) {

    // Stop listening to preference property updates while configuring the
    // internals
    if (this.prefStore != null) {
        this.prefStore.removePropertyChangeListener(this);
    }

    // Spins up a new content monitor on the location that is currently
    // configured in the preference store.
    String location = prefStore.getString(PreferenceConstants.P_CREDENTIAL_PROFILE_FILE_LOCATION);
    resetFileContentMonitor(location);

    // Now we are done -- start listening to preference property changes
    prefStore.addPropertyChangeListener(this);
}

From source file:com.amazonaws.eclipse.core.preferences.PreferenceChangeRefreshListener.java

License:Apache License

/**
 * Constructs a new preference change refresh listener that will refresh the
 * specified {@code IRefreshable} object when it receives a notification
 * that one of the specified preference properties changed on the specified
 * preference store./* w  w w .  j  a  v  a  2  s  . c  o  m*/
 *
 * @param refreshable
 *            The object to be refreshed when the specified preferences are
 *            changed.
 * @param preferenceStore
 *            The preference this listener is listening to.
 * @param refreshablePreferences
 *            The set of preferences that require the specified IRefreshable
 *            object to be refreshed.
 */
public PreferenceChangeRefreshListener(IRefreshable refreshable, IPreferenceStore preferenceStore,
        String[] refreshablePreferences) {
    this.refreshable = refreshable;
    this.preferenceStore = preferenceStore;

    for (String property : refreshablePreferences) {
        refreshablePreferenceSet.add(property);
    }

    preferenceStore.addPropertyChangeListener(this);
}

From source file:com.android.ide.eclipse.adt.AdtPlugin.java

License:Open Source License

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);

    // set the default android console.
    mAndroidConsole = new MessageConsole("Android", null); //$NON-NLS-1$
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { mAndroidConsole });

    // get the stream to write in the android console.
    mAndroidConsoleStream = mAndroidConsole.newMessageStream();
    mAndroidConsoleErrorStream = mAndroidConsole.newMessageStream();

    // get the eclipse store
    IPreferenceStore eclipseStore = getPreferenceStore();
    AdtPrefs.init(eclipseStore);//from w w w.  ja v a  2 s .  c o  m

    // set the listener for the preference change
    eclipseStore.addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // load the new preferences
            AdtPrefs.getPrefs().loadValues(event);

            // if the SDK changed, we have to do some extra work
            if (AdtPrefs.PREFS_SDK_DIR.equals(event.getProperty())) {

                // finally restart adb, in case it's a different version
                DdmsPlugin.setToolsLocation(getOsAbsoluteAdb(), true /* startAdb */, getOsAbsoluteHprofConv(),
                        getOsAbsoluteTraceview());

                // get the SDK location and build id.
                if (checkSdkLocationAndId()) {
                    // if sdk if valid, reparse it

                    reparseSdk();
                }
            }
        }
    });

    // load preferences.
    AdtPrefs.getPrefs().loadValues(null /*event*/);

    // initialize property-sheet library
    DesignerPlugin.initialize(this, PLUGIN_ID, CURRENT_PLATFORM == PLATFORM_WINDOWS,
            CURRENT_PLATFORM == PLATFORM_DARWIN, CURRENT_PLATFORM == PLATFORM_LINUX);

    // initialize editors
    startEditors();

    // Listen on resource file edits for updates to file inclusion
    IncludeFinder.start();
}

From source file:com.android.ide.eclipse.auidt.AdtPlugin.java

License:Open Source License

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);

    // set the default android console.
    mAndroidConsole = new MessageConsole("AUIDT", null); //$NON-NLS-1$
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { mAndroidConsole });

    // get the stream to write in the android console.
    mAndroidConsoleStream = mAndroidConsole.newMessageStream();
    mAndroidConsoleErrorStream = mAndroidConsole.newMessageStream();

    // get the eclipse store
    IPreferenceStore eclipseStore = getPreferenceStore();
    AdtPrefs.init(eclipseStore);//from ww w  . ja  v  a  2s.  co m

    // set the listener for the preference change
    eclipseStore.addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // load the new preferences
            AdtPrefs.getPrefs().loadValues(event);

            // if the SDK changed, we have to do some extra work
            if (AdtPrefs.PREFS_SDK_DIR.equals(event.getProperty())) {

                // finally restart adb, in case it's a different version
                DdmsPlugin.setToolsLocation(getOsAbsoluteAdb(), true /* startAdb */, getOsAbsoluteHprofConv(),
                        getOsAbsoluteTraceview());

                // get the SDK location and build id.
                if (checkSdkLocationAndId()) {
                    // if sdk if valid, reparse it

                    reparseSdk();
                }
            }
        }
    });

    // load preferences.
    AdtPrefs.getPrefs().loadValues(null /*event*/);

    // initialize property-sheet library
    DesignerPlugin.initialize(this, PLUGIN_ID, CURRENT_PLATFORM == PLATFORM_WINDOWS,
            CURRENT_PLATFORM == PLATFORM_DARWIN, CURRENT_PLATFORM == PLATFORM_LINUX);

    // initialize editors
    startEditors();

    // Listen on resource file edits for updates to file inclusion
    IncludeFinder.start();

    // Parse the SDK content.
    // This is deferred in separate jobs to avoid blocking the bundle start.
    final boolean isSdkLocationValid = checkSdkLocationAndId();
    if (isSdkLocationValid) {
        // parse the SDK resources.
        // Wait 2 seconds before starting the job. This leaves some time to the
        // other bundles to initialize.
        parseSdkContent(2000 /*milliseconds*/);
    }
}

From source file:com.android.ide.eclipse.ddms.DdmsPlugin.java

License:Apache License

@Override
public void start(BundleContext context) throws Exception {
    super.start(context);

    final Display display = getDisplay();

    // get the eclipse store
    final IPreferenceStore eclipseStore = getPreferenceStore();

    AndroidDebugBridge.addDeviceChangeListener(this);

    DdmUiPreferences.setStore(eclipseStore);

    //DdmUiPreferences.displayCharts();

    // set the consoles.
    mDdmsConsole = new MessageConsole("DDMS", null); //$NON-NLS-1$
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { mDdmsConsole });

    final MessageConsoleStream consoleStream = mDdmsConsole.newMessageStream();
    final MessageConsoleStream errorConsoleStream = mDdmsConsole.newMessageStream();
    mRed = new Color(display, 0xFF, 0x00, 0x00);

    // because this can be run, in some cases, by a non UI thread, and because
    // changing the console properties update the UI, we need to make this change
    // in the UI thread.
    display.asyncExec(new Runnable() {
        @Override/*from  ww  w  .j av a2  s.  c o m*/
        public void run() {
            errorConsoleStream.setColor(mRed);
        }
    });

    // set up the ddms log to use the ddms console.
    Log.setLogOutput(new ILogOutput() {
        @Override
        public void printLog(LogLevel logLevel, String tag, String message) {
            if (logLevel.getPriority() >= LogLevel.ERROR.getPriority()) {
                printToStream(errorConsoleStream, tag, message);
                showConsoleView(mDdmsConsole);
            } else {
                printToStream(consoleStream, tag, message);
            }
        }

        @Override
        public void printAndPromptLog(final LogLevel logLevel, final String tag, final String message) {
            printLog(logLevel, tag, message);
            // dialog box only run in UI thread..
            display.asyncExec(new Runnable() {
                @Override
                public void run() {
                    Shell shell = display.getActiveShell();
                    if (logLevel == LogLevel.ERROR) {
                        MessageDialog.openError(shell, tag, message);
                    } else {
                        MessageDialog.openWarning(shell, tag, message);
                    }
                }
            });
        }

    });

    // set up the ddms console to use this objects
    DdmConsole.setConsole(new IDdmConsole() {
        @Override
        public void printErrorToConsole(String message) {
            printToStream(errorConsoleStream, null, message);
            showConsoleView(mDdmsConsole);
        }

        @Override
        public void printErrorToConsole(String[] messages) {
            for (String m : messages) {
                printToStream(errorConsoleStream, null, m);
            }
            showConsoleView(mDdmsConsole);
        }

        @Override
        public void printToConsole(String message) {
            printToStream(consoleStream, null, message);
        }

        @Override
        public void printToConsole(String[] messages) {
            for (String m : messages) {
                printToStream(consoleStream, null, m);
            }
        }
    });

    // set the listener for the preference change
    eclipseStore.addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // get the name of the property that changed.
            String property = event.getProperty();

            if (PreferenceInitializer.ATTR_DEBUG_PORT_BASE.equals(property)) {
                DdmPreferences
                        .setDebugPortBase(eclipseStore.getInt(PreferenceInitializer.ATTR_DEBUG_PORT_BASE));
            } else if (PreferenceInitializer.ATTR_SELECTED_DEBUG_PORT.equals(property)) {
                DdmPreferences.setSelectedDebugPort(
                        eclipseStore.getInt(PreferenceInitializer.ATTR_SELECTED_DEBUG_PORT));
            } else if (PreferenceInitializer.ATTR_THREAD_INTERVAL.equals(property)) {
                DdmUiPreferences.setThreadRefreshInterval(
                        eclipseStore.getInt(PreferenceInitializer.ATTR_THREAD_INTERVAL));
            } else if (PreferenceInitializer.ATTR_LOG_LEVEL.equals(property)) {
                DdmPreferences.setLogLevel(eclipseStore.getString(PreferenceInitializer.ATTR_LOG_LEVEL));
            } else if (PreferenceInitializer.ATTR_TIME_OUT.equals(property)) {
                DdmPreferences.setTimeOut(eclipseStore.getInt(PreferenceInitializer.ATTR_TIME_OUT));
            } else if (PreferenceInitializer.ATTR_USE_ADBHOST.equals(property)) {
                DdmPreferences.setUseAdbHost(eclipseStore.getBoolean(PreferenceInitializer.ATTR_USE_ADBHOST));
            } else if (PreferenceInitializer.ATTR_ADBHOST_VALUE.equals(property)) {
                DdmPreferences
                        .setAdbHostValue(eclipseStore.getString(PreferenceInitializer.ATTR_ADBHOST_VALUE));
            }
        }
    });

    // do some last initializations

    // set the preferences.
    PreferenceInitializer.setupPreferences();

    // this class is set as the main source revealer and will look at all the implementations
    // of the extension point. see #reveal(String, String, int)
    StackTracePanel.setSourceRevealer(this);

    /*
     * Load the extension point implementations.
     * The first step is to load the IConfigurationElement representing the implementations.
     * The 2nd step is to use these objects to instantiate the implementation classes.
     *
     * Because the 2nd step will trigger loading the plug-ins providing the implementations,
     * and those plug-ins could access DDMS classes (like ADT), this 2nd step should be done
     * in a Job to ensure that DDMS is loaded, so that the other plug-ins can load.
     *
     * Both steps could be done in the 2nd step but some of DDMS UI rely on knowing if there
     * is an implementation or not (DeviceView), so we do the first steps in start() and, in
     * some case, record it.
     *
     */

    // get the IConfigurationElement for the debuggerConnector right away.
    final IConfigurationElement[] dcce = findConfigElements("com.android.ide.eclipse.ddms.debuggerConnector"); //$NON-NLS-1$
    mHasDebuggerConnectors = dcce.length > 0;

    // get the other configElements and instantiante them in a Job.
    new Job(Messages.DdmsPlugin_DDMS_Post_Create_Init) {
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                // init the lib
                AndroidDebugBridge.init(true /* debugger support */);

                // get the available adb locators
                IConfigurationElement[] elements = findConfigElements(
                        "com.android.ide.eclipse.ddms.toolsLocator"); //$NON-NLS-1$

                IToolsLocator[] locators = instantiateToolsLocators(elements);

                for (IToolsLocator locator : locators) {
                    try {
                        String adbLocation = locator.getAdbLocation();
                        String traceviewLocation = locator.getTraceViewLocation();
                        String hprofConvLocation = locator.getHprofConvLocation();
                        if (adbLocation != null && traceviewLocation != null && hprofConvLocation != null) {
                            // checks if the location is valid.
                            if (setToolsLocation(adbLocation, hprofConvLocation, traceviewLocation)) {

                                AndroidDebugBridge.createBridge(sAdbLocation, true /* forceNewBridge */);

                                // no need to look at the other locators.
                                break;
                            }
                        }
                    } catch (Throwable t) {
                        // ignore, we'll just not use this implementation.
                    }
                }

                // get the available debugger connectors
                mDebuggerConnectors = instantiateDebuggerConnectors(dcce);

                // get the available Traceview Launchers.
                elements = findConfigElements("com.android.ide.eclipse.ddms.traceviewLauncher"); //$NON-NLS-1$
                mTraceviewLaunchers = instantiateTraceviewLauncher(elements);

                return Status.OK_STATUS;
            } catch (CoreException e) {
                return e.getStatus();
            }
        }
    }.schedule();
}

From source file:com.aptana.editor.common.CommonContentAssistProcessor.java

License:Open Source License

/**
 * IndexContentAssistProcessor//  w w w .  j a  v a 2s  . c o m
 * 
 * @param editor
 */
public CommonContentAssistProcessor(AbstractThemeableEditor editor) {
    this.editor = editor;

    _completionProposalChars = retrieveCAPreference(
            IPreferenceConstants.COMPLETION_PROPOSAL_ACTIVATION_CHARACTERS);
    _contextInformationChars = retrieveCAPreference(
            IPreferenceConstants.CONTEXT_INFORMATION_ACTIVATION_CHARACTERS);
    _proposalTriggerChars = retrieveCAPreference(IPreferenceConstants.PROPOSAL_TRIGGER_CHARACTERS);

    IPreferenceStore commonPreferences = CommonEditorPlugin.getDefault().getPreferenceStore();
    String filterTypeString = commonPreferences
            .getString(IPreferenceConstants.CONTENT_ASSIST_USER_AGENT_FILTER_TYPE);
    _filterType = UserAgentFilterType.get(filterTypeString);
    commonPreferences.addPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (IPreferenceConstants.CONTENT_ASSIST_USER_AGENT_FILTER_TYPE.equals(event.getProperty())) {
                _filterType = UserAgentFilterType.get(event.getNewValue().toString());
            }
        }
    });

    if (getPreferenceNodeQualifier() != null) {
        EclipseUtil.instanceScope().getNode(getPreferenceNodeQualifier()).addPreferenceChangeListener(this);
    }
}

From source file:com.aptana.editor.findbar.impl.FindBarDecorator.java

License:Open Source License

/**
 * Updates the find bar given the preferences (and registers a listener to update it whenever needed).
 *///from   w ww . j av  a  2  s .c om
public void installActions() {
    IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore();
    preferenceStore.addPropertyChangeListener(fFindBarActionOnPropertyChange);
    fOriginalFindBarAction = textEditor.getAction(ITextEditorActionConstants.FIND);
    updateFindBarAction();
}

From source file:com.aptana.editor.findbar.impl.FindBarEntriesHelper.java

License:Open Source License

/**
 * Start taking control of the text (i.e.: when the preference changes, update the text).
 * /* w  w  w  .j a v  a 2 s .  c  om*/
 * @return a handle that should be used to later unregister it.
 */
public EntriesControlHandle register(Text text, IStartEndIgnore modifyListener, final String preferenceName) {
    List<String> items = loadEntries(preferenceName);
    setTextText(text, modifyListener, items);
    Set<EntriesControlHandle> set = preferenceToTextAndListener.get(preferenceName);
    if (set == null) {
        set = new HashSet<EntriesControlHandle>();
        preferenceToTextAndListener.put(preferenceName, set);
        // preference that's still not treated: start to hear it.
        IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore();
        final Set<EntriesControlHandle> usedInternal = set;
        preferenceStore.addPropertyChangeListener(new IPropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent event) {
                if (preferenceName.equals(event.getProperty())) {
                    List<String> entries = loadEntries(preferenceName);
                    for (EntriesControlHandle entry : usedInternal) {
                        setTextText(entry.text, entry.modifyListener, entries);
                    }
                }
            }
        });
    }
    EntriesControlHandle handle = new EntriesControlHandle(preferenceName, text, modifyListener);
    set.add(handle);
    return handle;
}

From source file:com.aptana.editor.findbar.impl.FindBarOption.java

License:Open Source License

public FindBarOption(String fieldName, String image, String imageDisabled, String initialText,
        FindBarDecorator findBarDecorator, boolean initiallyEnabled, String preferencesKey) {
    this.fieldName = fieldName;
    this.image = image;
    this.imageDisabled = imageDisabled;
    this.initialText = initialText;
    this.findBarDecorator = new WeakReference<FindBarDecorator>(findBarDecorator);
    this.initiallyEnabled = initiallyEnabled;
    this.preferencesKey = preferencesKey;
    if (preferencesKey != null) {
        IPreferenceStore preferenceStore = FindBarPlugin.getDefault().getPreferenceStore();
        preferenceStore.addPropertyChangeListener(getPropertyChangeListener());
    }/*from  w  ww  .  j  a  v a2  s.  c o m*/
}