Example usage for org.eclipse.jface.preference PreferenceManager PreferenceManager

List of usage examples for org.eclipse.jface.preference PreferenceManager PreferenceManager

Introduction

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

Prototype

public PreferenceManager() 

Source Link

Document

Creates a new preference manager.

Usage

From source file:com.motorolamobility.preflighting.ui.utilities.EclipseUtils.java

License:Apache License

@SuppressWarnings("unchecked")
public static void openPreference(Shell shell, String nodeID) {
    // Makes the network preferences dialog manager
    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode networkNode = null;/*  ww w.  jav  a 2 s. co  m*/
    for (IPreferenceNode node : (List<IPreferenceNode>) manager.getElements(PreferenceManager.PRE_ORDER)) {
        if (node.getId().equals(nodeID)) {
            networkNode = node;
            break;
        }
    }
    PreferenceManager prefMan = new PreferenceManager();
    if (networkNode != null) {
        prefMan.addToRoot(networkNode);
    }
    PreferenceDialog preferencesDialog = new WorkbenchPreferenceDialog(shell, prefMan);
    preferencesDialog.create();
    preferencesDialog.open();
}

From source file:com.nokia.carbide.internal.bugdatacollector.ui.preferences.BugDataCollectorPreferencePage.java

License:Open Source License

/**
 * Shows the preference dialog with only this preference page 
 * available in the tree//  w ww  . j a va2 s  .c  o  m
 * @param shell 
 */
public static void showYourself(Shell shell) {
    IPreferencePage page = new BugDataCollectorPreferencePage();
    PreferenceManager mgr = new PreferenceManager();
    IPreferenceNode node = new PreferenceNode("1", page); //$NON-NLS-1$
    mgr.addToRoot(node);
    PreferenceDialog dialog = new PreferenceDialog(shell, mgr);
    dialog.create();
    dialog.setMessage(page.getTitle());
    dialog.open();
}

From source file:com.nokia.s60tools.hticonnection.actions.OpenPreferencePageAction.java

License:Open Source License

/**
 * Open HTI API preferences page preference page
 *//*w  ww. ja  v  a  2  s. c  o  m*/
private void openPreferencePage() {
    IPreferencePage page = new HtiApiPreferencePage();
    PreferenceManager mgr = new PreferenceManager();
    IPreferenceNode node = new PreferenceNode("1", page);//$NON-NLS-1$
    mgr.addToRoot(node);
    PreferenceDialog dialog = new PreferenceDialog(HtiApiActivator.getCurrentlyActiveWbWindowShell(), mgr);
    dialog.create();
    dialog.setMessage(page.getTitle());
    dialog.open();
}

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

License:Open Source License

/**
 * Creates Client UI//from  ww  w.j av  a 2s.c om
 */
private static void createClientUI() {
    PreferenceManager mgr = new PreferenceManager();

    // Create connection preference page
    IPreferencePage connectionPage = new TraceViewerConnectionPreferencesPage();
    IPreferenceNode connectionNode = new PreferenceNode("1", connectionPage); //$NON-NLS-1$
    mgr.addToRoot(connectionNode);

    // Create the dialog
    PreferenceDialog dialog = new PreferenceDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
            mgr);
    dialog.create();
}

From source file:com.nokia.traceviewer.view.TraceViewerView.java

License:Open Source License

public boolean openPreferencePage(TVPreferencePage TVpage) {
    boolean ret = false;
    PreferenceManager mgr = new PreferenceManager();

    // Create general preference page
    IPreferencePage generalPage = new TraceViewerPreferencesPage();
    generalPage.setTitle(TRACE_VIEWER_TITLE);
    IPreferenceNode generalNode = new PreferenceNode("1", generalPage); //$NON-NLS-1$
    mgr.addToRoot(generalNode);/* ww  w.  j  av  a  2 s .  c om*/

    // Create advanced preference page
    IPreferencePage advancedPage = new TraceViewerAdvancedPreferencesPage();
    advancedPage.setTitle(Messages.getString("TraceViewerView.AdvancedPageTitle")); //$NON-NLS-1$
    IPreferenceNode advancedNode = new PreferenceNode("2", advancedPage); //$NON-NLS-1$
    mgr.addTo("1", advancedNode); //$NON-NLS-1$

    // Create connection preference page
    IPreferencePage connectionPage = new TraceViewerConnectionPreferencesPage();
    connectionPage.setTitle(Messages.getString("TraceViewerView.ConnectionPageTitle")); //$NON-NLS-1$
    IPreferenceNode connectionNode = new PreferenceNode("3", connectionPage); //$NON-NLS-1$
    mgr.addTo("1", connectionNode); //$NON-NLS-1$

    PreferenceDialog dialog = new PreferenceDialog(getShell(), mgr);
    dialog.create();
    dialog.getTreeViewer().expandAll();

    // Switch the page
    switch (TVpage) {
    case GENERAL:
        dialog.getTreeViewer().setSelection(new StructuredSelection(generalNode));
        break;
    case ADVANCED:
        dialog.getTreeViewer().setSelection(new StructuredSelection(advancedNode));
        break;
    case CONNECTION:
        dialog.getTreeViewer().setSelection(new StructuredSelection(connectionNode));
        break;
    default:
        break;
    }

    // Open dialog and get return value
    int ok = dialog.open();
    if (ok == Window.OK) {
        ret = true;
    }

    return ret;
}

From source file:com.nsn.squirrel.preferences.internal.E4PreferenceRegistry.java

License:Open Source License

public PreferenceManager getPreferenceManager() {

    // Remember of the unbounded nodes to order parent pages.
    // Map<category, list of children> (all nodes except root nodes)
    Map<String, Collection<IPreferenceNode>> childrenNodes = new HashMap<String, Collection<IPreferenceNode>>();
    if (pm != null)
        return pm;
    pm = new PreferenceManager();
    IContributionFactory factory = context.get(IContributionFactory.class);
    for (IConfigurationElement elmt : registry.getConfigurationElementsFor(PREFS_PAGE_XP)) {
        String bundleId = elmt.getNamespaceIdentifier();
        if (!elmt.getName().equals(ELMT_PAGE)) {
            logger.warn("unexpected element: {0}", elmt.getName());
            continue;
        } else if (isEmpty(elmt.getAttribute(ATTR_ID)) || isEmpty(elmt.getAttribute(ATTR_NAME))) {
            logger.warn("missing id and/or name: {}", bundleId);
            continue;
        }/*from  w w w. ja  v a 2  s  . c om*/
        PreferenceNode pn = null;
        if (elmt.getAttribute(ATTR_CLASS) != null) {
            PreferencePage page = null;
            try {
                String prefPageURI = getClassURI(bundleId, elmt.getAttribute(ATTR_CLASS));
                Object object = factory.create(prefPageURI, context);
                if (!(object instanceof PreferencePage)) {
                    logger.error("Expected instance of PreferencePage: {0}", elmt.getAttribute(ATTR_CLASS));
                    continue;
                }
                page = (PreferencePage) object;
                setPreferenceStore(bundleId, page);
            } catch (ClassNotFoundException e) {
                logger.error(e);
                continue;
            }
            ContextInjectionFactory.inject(page, context);
            if ((page.getTitle() == null || page.getTitle().isEmpty())
                    && elmt.getAttribute(ATTR_NAME) != null) {
                page.setTitle(elmt.getAttribute(ATTR_NAME));
            }
            pn = new PreferenceNode(elmt.getAttribute(ATTR_ID), page);
        } else {
            pn = new PreferenceNode(elmt.getAttribute(ATTR_ID),
                    new EmptyPreferencePage(elmt.getAttribute(ATTR_NAME)));
        }
        // Issue 2 : Fix bug on order (see :
        // https://github.com/opcoach/e4Preferences/issues/2)
        // Add only pages at root level and remember of child pages for
        // categories
        String category = elmt.getAttribute(ATTR_CATEGORY);
        if (isEmpty(category)) {
            pm.addToRoot(pn);
        } else {
            /*
             * IPreferenceNode parent = findNode(pm, category); if (parent
             * == null) { // No parent found, but may be the extension has
             * not been read yet. So remember of it unboundedNodes.put(pn,
             * category); } else { parent.add(pn); }
             */
            // Check if this category is already registered.
            Collection<IPreferenceNode> children = childrenNodes.get(category);
            if (children == null) {
                children = new ArrayList<IPreferenceNode>();
                childrenNodes.put(category, children);
            }
            children.add(pn);
        }
    }
    // Must now bind pages that has not been added in nodes (depends on the
    // preference page read order)
    // Iterate on all possible categories
    Collection<String> categoriesDone = new ArrayList<String>();
    while (!childrenNodes.isEmpty()) {
        for (String cat : Collections.unmodifiableSet(childrenNodes.keySet())) {
            // Is this category already in preference manager ? If not add
            // it later...
            IPreferenceNode parent = findNode(pm, cat);
            if (parent != null) {
                // Can add the list of children to this parent page...
                for (IPreferenceNode pn : childrenNodes.get(cat)) {
                    parent.add(pn);
                }
                // Ok This parent page is done. Can remove it from map
                // outside of this loop
                categoriesDone.add(cat);
            }
        }
        for (String keyToRemove : categoriesDone)
            childrenNodes.remove(keyToRemove);
        categoriesDone.clear();
    }
    return pm;
}

From source file:com.opcoach.e4.preferences.internal.E4PreferenceRegistry.java

License:Open Source License

public PreferenceManager getPreferenceManager() {

    // Remember of the unbounded nodes to order parent pages.
    // Map<category, list of children> (all nodes except root nodes)
    Map<String, Collection<IPreferenceNode>> childrenNodes = new HashMap<String, Collection<IPreferenceNode>>();

    if (pm != null)
        return pm;

    pm = new PreferenceManager();
    IContributionFactory factory = context.get(IContributionFactory.class);

    for (IConfigurationElement elmt : registry.getConfigurationElementsFor(PREFS_PAGE_XP)) {
        String bundleId = elmt.getNamespaceIdentifier();
        if (!elmt.getName().equals(ELMT_PAGE)) {
            logger.warn("unexpected element: {0}", elmt.getName());
            continue;
        } else if (isEmpty(elmt.getAttribute(ATTR_ID)) || isEmpty(elmt.getAttribute(ATTR_NAME))) {
            logger.warn("missing id and/or name: {}", bundleId);
            continue;
        }// w w w. j av a  2 s  .c om
        PreferenceNode pn = null;
        if (elmt.getAttribute(ATTR_CLASS) != null) {
            PreferencePage page = null;
            try {
                String prefPageURI = getClassURI(bundleId, elmt.getAttribute(ATTR_CLASS));
                Object object = factory.create(prefPageURI, context);
                if (!(object instanceof PreferencePage)) {
                    logger.error("Expected instance of PreferencePage: {0}", elmt.getAttribute(ATTR_CLASS));
                    continue;
                }
                page = (PreferencePage) object;
                setPreferenceStore(bundleId, page);

            } catch (ClassNotFoundException e) {
                logger.error(e);
                continue;
            }
            ContextInjectionFactory.inject(page, context);
            if ((page.getTitle() == null || page.getTitle().isEmpty())
                    && elmt.getAttribute(ATTR_NAME) != null) {
                page.setTitle(elmt.getAttribute(ATTR_NAME));
            }

            pn = new PreferenceNode(elmt.getAttribute(ATTR_ID), page);
        } else {
            pn = new PreferenceNode(elmt.getAttribute(ATTR_ID),
                    new EmptyPreferencePage(elmt.getAttribute(ATTR_NAME)));
        }

        // Issue 2 : Fix bug on order (see :
        // https://github.com/opcoach/e4Preferences/issues/2)
        // Add only pages at root level and remember of child pages for
        // categories
        String category = elmt.getAttribute(ATTR_CATEGORY);
        if (isEmpty(category)) {
            pm.addToRoot(pn);
        } else {
            /*
             * IPreferenceNode parent = findNode(pm, category); if (parent
             * == null) { // No parent found, but may be the extension has
             * not been read yet. So remember of it unboundedNodes.put(pn,
             * category); } else { parent.add(pn); }
             */
            // Check if this category is already registered.
            Collection<IPreferenceNode> children = childrenNodes.get(category);
            if (children == null) {
                children = new ArrayList<IPreferenceNode>();
                childrenNodes.put(category, children);
            }
            children.add(pn);
        }
    }

    // Must now bind pages that has not been added in nodes (depends on the
    // preference page read order)
    // Iterate on all possible categories
    Collection<String> categoriesDone = new ArrayList<String>();

    while (!childrenNodes.isEmpty()) {
        for (String cat : Collections.unmodifiableSet(childrenNodes.keySet())) {
            // Is this category already in preference manager ? If not add
            // it later...
            IPreferenceNode parent = findNode(pm, cat);
            if (parent != null) {
                // Can add the list of children to this parent page...
                for (IPreferenceNode pn : childrenNodes.get(cat)) {
                    parent.add(pn);
                }
                // Ok This parent page is done. Can remove it from map
                // outside of this loop
                categoriesDone.add(cat);
            }
        }

        for (String keyToRemove : categoriesDone)
            childrenNodes.remove(keyToRemove);
        categoriesDone.clear();

    }

    return pm;
}

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

License:Apache License

private void configureWorkspaceSettings() {
    String preferenceNodeId = this.getPreferenceNodeId();
    IPreferencePage preferencePage = newPreferencePage();
    final IPreferenceNode preferenceNode = new PreferenceNode(preferenceNodeId, preferencePage);

    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(preferenceNode);// w  ww  .  j a va 2s  .c  o m

    final PreferenceDialog dialog = new PreferenceDialog(this.getControl().getShell(), manager);
    BusyIndicator.showWhile(this.getControl().getDisplay(), new Runnable() {
        @Override
        public void run() {
            dialog.create();
            dialog.setMessage(preferenceNode.getLabelText());
            dialog.open();
        }
    });
}

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

License:Apache License

public static void main(String[] args) throws Exception {
    Display display = new Display();
    // Allows to test the preference page from Eclipse
    Shell shell = new Shell();
    shell.setSize(450, 300);//from  ww  w . j a v a  2s  .co  m
    shell.setText("SWT Application");

    //create an instance of the custom MyPreference class
    IPreferencePage page = new PeergreenPreferencePage();

    //create a new PreferenceNode that will appear in the Preference window
    PreferenceNode node = new PreferenceNode("1", page);

    //use workbenches's preference manager
    PreferenceManager mgr = new PreferenceManager();
    mgr.addToRoot(node); //add the node in the PreferenceManager

    //instantiate the PreferenceDialog
    PreferenceDialog pd = new PreferenceDialog(shell, mgr);

    pd.create();
    pd.open();

}

From source file:com.persistent.util.WAEclipseHelper.java

License:Open Source License

/**
 * Method creates tree structure of azure property pages. and opens property
 * dialog with desired property page selected & active.
 * //from w  w w. j ava 2s  .c om
 * @param windowsAzureRole
 *            : worker role
 * @param pageToDisplay
 *            : property page Id which should be active after opening dialog
 * @param tabToSelect : In case pageToDisplay is Server Configuration page then
 *                   provide tab which should be selected.
 * @return integer
 */
public static int openRolePropertyDialog(WindowsAzureRole windowsAzureRole, String pageToDisplay,
        String tabToSelect) {
    int retVal = Window.CANCEL; // value corresponding to cancel
    try {
        // Node creation
        PreferenceNode nodeGeneral = new PreferenceNode(Messages.cmhIdGeneral, Messages.cmhLblGeneral, null,
                WARGeneral.class.toString());
        nodeGeneral.setPage(new WARGeneral());
        nodeGeneral.getPage().setTitle(Messages.cmhLblGeneral);

        PreferenceNode nodeCache = new PreferenceNode(Messages.cmhIdCach, Messages.cmhLblCach, null,
                WARCaching.class.toString());
        nodeCache.setPage(new WARCaching());
        nodeCache.getPage().setTitle(Messages.cmhLblCach);

        PreferenceNode nodeCert = new PreferenceNode(Messages.cmhIdCert, Messages.cmhLblCert, null,
                WARCertificates.class.toString());
        nodeCert.setPage(new WARCertificates());
        nodeCert.getPage().setTitle(Messages.cmhLblCert);

        PreferenceNode nodeCmpnts = new PreferenceNode(Messages.cmhIdCmpnts, Messages.cmhLblCmpnts, null,
                WARComponents.class.toString());
        nodeCmpnts.setPage(new WARComponents());
        nodeCmpnts.getPage().setTitle(Messages.cmhLblCmpnts);

        PreferenceNode nodeDebugging = new PreferenceNode(Messages.cmhIdDbg, Messages.cmhLblDbg, null,
                WARDebugging.class.toString());
        nodeDebugging.setPage(new WARDebugging());
        nodeDebugging.getPage().setTitle(Messages.cmhLblDbg);

        PreferenceNode nodeEndPts = new PreferenceNode(Messages.cmhIdEndPts, Messages.cmhLblEndPts, null,
                WAREndpoints.class.toString());
        nodeEndPts.setPage(new WAREndpoints());
        nodeEndPts.getPage().setTitle(Messages.cmhLblEndPts);

        PreferenceNode nodeEnvVars = new PreferenceNode(Messages.cmhIdEnvVars, Messages.cmhLblEnvVars, null,
                WAREnvVars.class.toString());
        nodeEnvVars.setPage(new WAREnvVars());
        nodeEnvVars.getPage().setTitle(Messages.cmhLblEnvVars);

        PreferenceNode nodeLdBlnc = new PreferenceNode(Messages.cmhIdLdBlnc, Messages.cmhLblLdBlnc, null,
                WARLoadBalance.class.toString());
        nodeLdBlnc.setPage(new WARLoadBalance());
        nodeLdBlnc.getPage().setTitle(Messages.cmhLblLdBlnc);

        PreferenceNode nodeLclStg = new PreferenceNode(Messages.cmhIdLclStg, Messages.cmhLblLclStg, null,
                WARLocalStorage.class.toString());
        nodeLclStg.setPage(new WARLocalStorage());
        nodeLclStg.getPage().setTitle(Messages.cmhLblLclStg);

        PreferenceNode nodeSrvCnfg = new PreferenceNode(Messages.cmhIdSrvCnfg, Messages.cmhLblSrvCnfg, null,
                WAServerConfiguration.class.toString());
        nodeSrvCnfg.setPage(new WAServerConfiguration(tabToSelect));
        nodeSrvCnfg.getPage().setTitle(Messages.cmhLblSrvCnfg);

        PreferenceNode nodeSslOff = new PreferenceNode(Messages.cmhIdSsl, Messages.cmhLblSsl, null,
                WASSLOffloading.class.toString());
        nodeSslOff.setPage(new WASSLOffloading());
        nodeSslOff.getPage().setTitle(Messages.cmhLblSsl);

        /*
         * Tree structure creation. Don't change order while adding nodes.
         * Its the default alphabetical order given by eclipse.
         */
        nodeGeneral.add(nodeCache);
        nodeGeneral.add(nodeCert);
        nodeGeneral.add(nodeCmpnts);
        nodeGeneral.add(nodeDebugging);
        nodeGeneral.add(nodeEndPts);
        nodeGeneral.add(nodeEnvVars);
        nodeGeneral.add(nodeLdBlnc);
        nodeGeneral.add(nodeLclStg);
        nodeGeneral.add(nodeSrvCnfg);
        nodeGeneral.add(nodeSslOff);

        PreferenceManager mgr = new PreferenceManager();
        mgr.addToRoot(nodeGeneral);
        // Dialog creation
        PreferenceDialog dialog = new PreferenceDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
                mgr);
        // make desired property page active.
        dialog.setSelectedNode(pageToDisplay);
        dialog.create();
        String dlgTitle = String.format(Messages.cmhPropFor, windowsAzureRole.getName());
        dialog.getShell().setText(dlgTitle);
        dialog.open();
        // return whether user has pressed OK or Cancel button
        retVal = dialog.getReturnCode();
    } catch (Exception ex) {
        PluginUtil.displayErrorDialogAndLog(new Shell(), Messages.rolsDlgErr, Messages.rolsDlgErrMsg, ex);
    }
    return retVal;
}