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

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

Introduction

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

Prototype

void setValue(String name, boolean value);

Source Link

Document

Sets the current value of the boolean-valued preference with the given name.

Usage

From source file:com.nokia.tools.ui.prefs.UserPreferencePage.java

License:Open Source License

public void setDataToPreferenceStore(final String id, final String value) {
    final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    store.setValue(id, value);
}

From source file:com.nokia.traceviewer.action.ConnectAction.java

License:Open Source License

/**
 * Checks used media protocol//from  www  . j  a va 2 s  .c o  m
 * 
 * @return true if TraceViewer can still continue connecting. False if
 *         currently selected TraceProvider doesn't support connecting.
 */
private boolean checkUsedProtocol() {
    boolean canConnect = true;

    // First check there are more than one TraceProviders
    if (TraceViewerGlobals.getListOfTraceProviders().size() > 1 && showProtocolChangeDialog) {

        IPreferenceStore store = TraceViewerPlugin.getDefault().getPreferenceStore();
        String selectedConnectionType = store.getString(PreferenceConstants.CONNECTION_TYPE);

        // Check if current TraceProvider has selected connection type as
        // preferred
        String preferredConnectionType = TraceViewerGlobals.getTraceProvider().getPreferredConnectionType();

        // If current TraceProvider returns not supported as preferred
        // connection type,
        if (preferredConnectionType.equals(PreferenceConstants.CONNECTION_TYPE_NOT_SUPPORTED)) {
            canConnect = false;
        }

        // Connection type doesn't match, find other TraceProvider which has
        // the selected connection type as preferred
        if (!preferredConnectionType.equals(selectedConnectionType)) {
            List<TraceProvider> traceProviders = TraceViewerGlobals.getListOfTraceProviders();

            // Go through list of TraceProviders
            for (int i = 0; i < traceProviders.size(); i++) {
                TraceProvider newProvider = traceProviders.get(i);
                if (newProvider.getPreferredConnectionType().equals(selectedConnectionType)) {

                    // Create human readable change message
                    String selectedConnectionHuman = Messages.getString("ConnectAction.USBSerialMsg"); //$NON-NLS-1$
                    if (selectedConnectionType.equals(PreferenceConstants.CONNECTION_TYPE_TCPIP)) {
                        selectedConnectionHuman = Messages.getString("ConnectAction.TCPIPMsg"); //$NON-NLS-1$
                    }
                    String changeMsgStart = Messages.getString("ConnectAction.ChangeDataFormatMsg1"); //$NON-NLS-1$
                    String changeMsgEnd = Messages.getString("ConnectAction.ChangeDataFormatMsg2"); //$NON-NLS-1$

                    String confirmationMsg = selectedConnectionHuman + changeMsgStart + newProvider.getName()
                            + changeMsgEnd;

                    // Ask the user if the TraceProvider should be changed
                    boolean ret = TraceViewerGlobals.getTraceViewer().getDialogs()
                            .showConfirmationDialog(confirmationMsg);

                    // Change TraceProvider
                    if (ret) {
                        store.setValue(PreferenceConstants.DATA_FORMAT, newProvider.getName());
                        TraceViewerGlobals.getTraceViewer().clearAllData();
                        TraceViewerGlobals.setTraceProvider(newProvider, true);
                        canConnect = true;
                    } else {
                        showProtocolChangeDialog = false;
                    }
                    break;
                }
            }
        }
    }

    // Current TraceProvider doesn't support connecting
    if (!canConnect && showErrors) {
        TraceViewerGlobals.getTraceViewer().getDialogs().showErrorMessage(
                TraceViewerGlobals.getTraceProvider().getName() + CONNECTION_NOT_SUPPORTED_ERROR);
    }

    return canConnect;
}

From source file:com.nokia.traceviewer.api.ConnectionHandler.java

License:Open Source License

/**
 * Changes Data Format//from  w  w  w  .j a va2s. co  m
 */
private void changeDataFormat() {

    // Get the TraceViewer preferenceStore
    IPreferenceStore store = TraceViewerPlugin.getDefault().getPreferenceStore();

    // If there are more than one TraceProvider
    if (TraceViewerGlobals.getListOfTraceProviders().size() > 1) {

        String selectedConnectionType = store.getString(PreferenceConstants.CONNECTION_TYPE);

        // If the currently selected TraceProvider doesn't has selected
        // connection as preferred, try to find one that does
        if (!TraceViewerGlobals.getTraceProvider().getPreferredConnectionType()
                .equals(selectedConnectionType)) {

            List<TraceProvider> traceProviders = TraceViewerGlobals.getListOfTraceProviders();

            // Go through list of TraceProviders
            for (int i = 0; i < traceProviders.size(); i++) {
                TraceProvider newProvider = traceProviders.get(i);
                if (newProvider.getPreferredConnectionType().equals(selectedConnectionType)) {
                    store.setValue(PreferenceConstants.DATA_FORMAT, newProvider.getName());

                    // Set new Trace provider
                    TraceViewerGlobals.setTraceProvider(newProvider, true);
                    break;
                }
            }
        }
    }
}

From source file:com.nokia.traceviewer.api.ConnectionHandler.java

License:Open Source License

/**
 * Sets new connection preferences/*from   w  ww  . ja  va2s .com*/
 * 
 * @param connectionMethod
 *            connection method
 * @param parameters
 *            connection parameters
 * @return true if succeeded, false if failed
 */
private boolean setNewConnectionPreferences(int connectionMethod, String[] parameters) {

    boolean succeeded = true;

    // Get the TraceViewer preferenceStore
    IPreferenceStore store = TraceViewerPlugin.getDefault().getPreferenceStore();

    try {
        String connectionMethodStr = null;

        // TCP / IP
        if (connectionMethod == TraceViewerAPI.TVAPI_CONNECTION_TCP) {
            connectionMethodStr = PreferenceConstants.CONNECTION_TYPE_TCPIP;

            // There must be at least 2 parameters
            if (parameters != null && parameters.length > 1) {

                // Set IP address
                store.setValue(PreferenceConstants.IP_ADDRESS, parameters[0]);

                // Set port number
                store.setValue(PreferenceConstants.TCPIP_PORT, parameters[1]);

                // Check if there is channel specified
                if (parameters.length > 2) {

                    // Set channel number
                    store.setValue(PreferenceConstants.TCPIP_CHANNEL, parameters[2]);
                }

            } else {
                succeeded = false;
            }

            // USB Serial
        } else if (connectionMethod == TraceViewerAPI.TVAPI_CONNECTION_USB_SERIAL) {
            connectionMethodStr = PreferenceConstants.CONNECTION_TYPE_USB_SERIAL;

            // There must be at least 1 parameters
            if (parameters != null && parameters.length > 0) {

                // Set com port
                store.setValue(PreferenceConstants.USB_SERIAL_COM_PORT, parameters[0]);

            } else {
                succeeded = false;
            }
        }

        // Set the connection method
        if (succeeded) {
            store.setValue(PreferenceConstants.CONNECTION_TYPE, connectionMethodStr);

            // Old connection ID is not valid, since connection settings
            // have been changed.
            store.setValue(PreferenceConstants.SELECTED_CONNECTION_ID, ""); //$NON-NLS-1$
        }
    } catch (Exception e) {
        succeeded = false;
    }

    return succeeded;
}

From source file:com.nokia.traceviewer.api.ConnectionHandler.java

License:Open Source License

/**
 * Sets old connection preferences back to preference store
 *//*from  www.j av  a  2s  . co  m*/
private void setOldPreferencesBack() {

    // Get the TraceViewer preferenceStore
    IPreferenceStore store = TraceViewerPlugin.getDefault().getPreferenceStore();

    // Set the connection method
    store.setValue(PreferenceConstants.CONNECTION_TYPE, oldConnectionMethod);
    // Set the selected connection ID
    store.setValue(PreferenceConstants.SELECTED_CONNECTION_ID, oldSelectedConnectionID);

    // TCP / IP connection
    if (oldConnectionMethod.equals(PreferenceConstants.CONNECTION_TYPE_TCPIP)) {
        store.setValue(PreferenceConstants.IP_ADDRESS, oldParameters[0]);
        store.setValue(PreferenceConstants.TCPIP_PORT, oldParameters[1]);

        // USB Serial connection
    } else if (oldConnectionMethod.equals(PreferenceConstants.CONNECTION_TYPE_USB_SERIAL)) {
        store.setValue(PreferenceConstants.USB_SERIAL_COM_PORT, oldParameters[0]);
    }

    // Resetting old connection settings
    oldConnectionMethod = null;
    oldParameters = null;
}

From source file:com.nokia.traceviewer.engine.ConnectionHelper.java

License:Open Source License

/**
 * Saves connection settings to preference store
 * /*from  ww w .  ja  v  a2s .  c om*/
 * @param ensureConnection
 *            if true, connection is ensured. It means that if the saved ID
 *            is not a ID of a "real" connection, we must find a real
 *            connection for this virtual ID
 * @return found IConnection object
 */
public static IConnection saveConnectionSettingsToPreferenceStore(boolean ensureConnection) {

    IPreferenceStore store = TraceViewerPlugin.getDefault().getPreferenceStore();

    IConnection conn = null;

    if (ensureConnection) {
        String selectedConnId = clientServiceUI.getSelectedConnection();
        if (selectedConnId == null && isCurrentConnectionSelected) {
            selectedConnId = CURRENT_CONNECTION_ID;
        } else if (selectedConnId == null) {
            selectedConnId = store.getString(PreferenceConstants.SELECTED_CONNECTION_ID);
        }

        try {
            ISelectedConnectionInfo ret = RemoteConnectionsActivator.getConnectionsManager()
                    .ensureConnection(selectedConnId, getTracingService());
            conn = ret.getConnection();
        } catch (CoreException e) {
            e.printStackTrace();
        }

    } else {
        conn = ConnectionHelper.getSelectedConnection();
    }

    // Save the currently ensured connection object
    currentEnsuredConnection = conn;

    if (conn != null && PlatformUI.getWorkbench().getDisplay().getActiveShell() != null
            && !PlatformUI.getWorkbench().getDisplay().getActiveShell().isDisposed()) {

        String connectionTypeId = conn.getConnectionType().getIdentifier();
        boolean isMusti = connectionTypeId
                .equals("com.nokia.carbide.trk.support.connection.TCPIPConnectionType"); //$NON-NLS-1$

        boolean isPlatsim = connectionTypeId
                .equals("com.nokia.carbide.trk.support.connection.PlatSimConnectionType"); //$NON-NLS-1$

        // TCP / IP connection
        if (isMusti || isPlatsim) {
            String address = conn.getSettings().get("ipAddress"); //$NON-NLS-1$
            String port = conn.getSettings().get("port"); //$NON-NLS-1$
            int channel = PreferenceConstants.TCPIP_DEFAULT_CHANNEL;
            if (isMusti) {
                try {
                    channel = Integer.parseInt(conn.getSettings().get("mustiChannel")); //$NON-NLS-1$
                } catch (NumberFormatException e) {
                    channel = 1;
                }
            }

            // Save Connection type, IP address, port number and channel
            store.setValue(PreferenceConstants.CONNECTION_TYPE, PreferenceConstants.CONNECTION_TYPE_TCPIP);
            store.setValue(PreferenceConstants.IP_ADDRESS, address);
            store.setValue(PreferenceConstants.TCPIP_PORT, port);
            store.setValue(PreferenceConstants.TCPIP_CHANNEL, channel);

            // USB connection
        } else if (connectionTypeId.equals("com.nokia.carbide.trk.support.connection.USBConnectionType")) { //$NON-NLS-1$
            String portNumStr = conn.getSettings().get("port"); //$NON-NLS-1$
            int portNum = Integer.parseInt(portNumStr);

            // Save Connection type and port number
            store.setValue(PreferenceConstants.CONNECTION_TYPE, PreferenceConstants.CONNECTION_TYPE_USB_SERIAL);
            store.setValue(PreferenceConstants.USB_SERIAL_COM_PORT, portNum);

        }

        // Save selected connection name. Only save the identifier if we
        // have not selected the "current connection"
        store.setValue(PreferenceConstants.SELECTED_CONNECTION_NAME, conn.getDisplayName());

        if (!isCurrentConnectionSelected) {
            store.setValue(PreferenceConstants.SELECTED_CONNECTION_ID, conn.getIdentifier());
        }

        // Current connection selected
    } else if (isCurrentConnectionSelected) {
        store.setValue(PreferenceConstants.CONNECTION_TYPE, CURRENT_CONNECTION_ID);
        store.setValue(PreferenceConstants.SELECTED_CONNECTION_ID, CURRENT_CONNECTION_ID);
        store.setValue(PreferenceConstants.SELECTED_CONNECTION_NAME, CURRENT_CONNECTION_ID);

        // Couldn't find connection
    } else {
        store.setValue(PreferenceConstants.CONNECTION_TYPE, ""); //$NON-NLS-1$

        // Resetting selected connection identifier
        store.setValue(PreferenceConstants.SELECTED_CONNECTION_ID, ""); //$NON-NLS-1$
        store.setValue(PreferenceConstants.SELECTED_CONNECTION_NAME, ""); //$NON-NLS-1$
    }

    // Change connection button tooltip
    ConnectAction action = (ConnectAction) TraceViewerGlobals.getTraceViewer().getView().getActionFactory()
            .getConnectAction();
    action.changeConnectToolTip();

    return conn;
}

From source file:com.nomagic.magicdraw.classpath.MDClasspathContainerPage.java

License:Open Source License

public IPath setMDInstallRootPath(String mdInstallRoot) {
    fMDInstallRootPath = new Path(mdInstallRoot);
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    try {//from   w  w w .  j  a v a 2s . c om
        JavaCore.setClasspathVariable(MDVariableInitializer.MD_CLASSPATH_VARIABLE, fMDInstallRootPath,
                new NullProgressMonitor());
        store.setValue(PreferenceConstants.MAGICDRAW_INSTALL_ROOT_PATH, mdInstallRoot);
        ((IPersistentPreferenceStore) store).save();
    } catch (JavaModelException e) {
        Activator.log(IStatus.ERROR, "MDClasspathContainer (set)", e);
        throw new RuntimeException(e);
    } catch (IOException e) {
        Activator.log(IStatus.ERROR, "MDClasspathContainer (save preference)", e);
    }
    return fMDInstallRootPath;
}

From source file:com.palantir.typescript.preferences.ContentAssistPreferencePage.java

License:Apache License

@Override
public boolean performOk() {
    IPreferenceStore preferenceStore = TypeScriptPlugin.getDefault().getPreferenceStore();

    boolean autoActivationEnabled = this.autoActivationEnabledButton.getSelection();
    preferenceStore.setValue(IPreferenceConstants.CONTENT_ASSIST_AUTO_ACTIVATION_ENABLED,
            autoActivationEnabled);//w  w w  .  j av a 2s  .  c  om

    for (Control control : this.controls) {
        String preferenceName = (String) control.getData();

        if (preferenceName != null) {
            if (control instanceof Text) {
                String value = ((Text) control).getText();

                preferenceStore.setValue(preferenceName, value);
            }
        }
    }

    return true;
}

From source file:com.peergreen.eclipse.osgi.preferences.PeergreenPreferencePage.java

License:Apache License

/**
 * Save the current configuration/*from ww  w. j  a va2  s .c  o m*/
 */
@Override
public boolean performOk() {

    // Save the values
    IPreferenceStore preferenceStore = getPreferenceStore();
    if (preferenceStore != null) {
        // save the current configuration
        StringWriter stringWriter = new StringWriter();
        try {
            new ServersConfigurationWriter().write(serversConfiguration, stringWriter);
        } catch (ParsingException e) {
            throw new IllegalStateException("Unable to save the current server configuration", e);
        }
        preferenceStore.setValue(SERVER_XML_CONTENT, stringWriter.toString());

    }

    return super.performOk();
}

From source file:com.peergreen.eclipse.osgi.preferences.PreferenceInitializer.java

License:Apache License

@Override
public void initializeDefaultPreferences() {
    IPreferenceStore store = Activator.getDefault().getPreferenceStore();

    Enumeration<String> serversPath = Activator.getDefault().getBundle().getEntryPaths(SERVERS_PATH);
    if (serversPath == null || !serversPath.hasMoreElements()) {
        throw new IllegalStateException(
                String.format("Unable to find any peergreen server in '%s' plugin", PLUGIN_ID));
    }/*from  www.j  a  v a 2 s .co m*/

    URL serverURL = null;
    String defaultServerPath = null;
    // Now, add entry for each server
    while (serversPath.hasMoreElements()) {
        String serverPath = serversPath.nextElement();
        try {
            URL url = Activator.getDefault().getBundle().getEntry(serverPath);
            if (url == null) {
                throw new IllegalStateException(
                        String.format("Unable to find the peergreen server in '%s' plugin", PLUGIN_ID));
            }
            serverURL = FileLocator.toFileURL(FileLocator.resolve(url));
            defaultServerPath = serverURL.getPath();
        } catch (IOException e) {
            throw new IllegalStateException(
                    String.format("Unable to find the peergreen server in '%s' plugin", PLUGIN_ID), e);
        }
        store.setDefault(SERVER_PATH, defaultServerPath);

    }

    // validate the current value
    String path = store.getString(SERVER_PATH);
    if (path != null && !path.equals(defaultServerPath)) {
        File localFile = new File(path);
        // file removed so revert to the default value
        if (!localFile.exists()) {
            store.setValue(SERVER_PATH, defaultServerPath);
        }
    }

    // XM file ?
    String xmlContent = store.getString(SERVER_XML_CONTENT);
    if (xmlContent == null || "".equals(xmlContent)) {
        // initialize default xml

        try (JarFile jarFile = new JarFile(defaultServerPath)) {
            // Check if manifest is OK
            Manifest manifest = jarFile.getManifest();
            String serverName = manifest.getMainAttributes().getValue("Peergreen-Server-Name");
            String version = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_VERSION);

            // no name
            if (serverName == null) {
                throw new IllegalStateException(String.format(
                        "Selected file %s is a JAR file but not a valid Peergreen Server", defaultServerPath));
            }

            // no version
            if (version == null) {
                throw new IllegalStateException(String
                        .format("Unable to find the version of the Peergreen Server %s", defaultServerPath));
            }

            xmlContent = "<peergreen-server><entry name='".concat(serverName).concat("' version='")
                    .concat(version).concat("' isDefault='true' localPath='").concat(defaultServerPath)
                    .concat("' /></peergreen-server>>");
            store.setDefault(SERVER_XML_CONTENT, xmlContent);

        } catch (IOException e) {
            throw new IllegalStateException(String.format("Unable to open the jar file %s", defaultServerPath));
        }

    }

    /*String defaultServerPath = null;
    URL serverURL = null;
    try {
        URL url = Activator.getDefault().getBundle().getEntry(ENTRY);
        if (url == null) {
      throw new IllegalStateException(String.format("Unable to find the peergreen server in '%s' plugin", PLUGIN_ID));
        }
        serverURL = FileLocator.toFileURL(FileLocator.resolve(url));
        defaultServerPath = serverURL.getPath();
    } catch (IOException e) {
    throw new IllegalStateException(String.format("Unable to find the peergreen server in '%s' plugin", PLUGIN_ID), e);
    }
    store.setDefault(SERVER_PATH, defaultServerPath);
            
            
    // validate the current value
    String path = store.getString(SERVER_PATH);
    if (path != null && !path.equals(defaultServerPath)) {
        File localFile = new File(path);
        // file removed so revert to the default value
        if (!localFile.exists()) {
      store.setValue(SERVER_PATH, defaultServerPath);
        }
    }
            
    // XM file ?
    String xmlContent = store.getString(SERVER_XML_CONTENT);
    if (xmlContent == null || "".equals(xmlContent)) {
        // initialize default xml
        xmlContent = "<peergreen-server><entry name='Peergreen Server Light' version='1.0.0-M0' isDefault='true' localPath='".concat(defaultServerPath).concat("' /></peergreen-server>>");
        store.setDefault(SERVER_XML_CONTENT, xmlContent);
    }*/

}