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

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

Introduction

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

Prototype

public void addToRoot(IPreferenceNode node) 

Source Link

Document

Adds the given preference node as a subnode of the root.

Usage

From source file:org.pwsafe.passwordsafeswt.action.OptionsAction.java

License:Open Source License

/**
 * @see org.eclipse.jface.action.Action#run()
 *//*  ww  w.j av  a 2 s  .  c o m*/
@Override
public void run() {
    final PasswordSafeJFace app = PasswordSafeJFace.getApp();

    // Create the preference manager
    PreferenceManager mgr = new PreferenceManager();

    // Create the nodes
    PreferenceNode displayPrefs = new PreferenceNode("display", Messages.getString("OptionsAction.DisplayNode"), //$NON-NLS-1$//$NON-NLS-2$
            null, DisplayPreferences.class.getName());
    PreferenceNode securityPrefs = new PreferenceNode("security", //$NON-NLS-1$
            Messages.getString("OptionsAction.SecurityNode"), null, SecurityPreferences.class //$NON-NLS-1$
                    .getName());
    PreferenceNode passwordPolicyPrefs = new PreferenceNode("policy", //$NON-NLS-1$
            Messages.getString("OptionsAction.PolicyNode"), null, //$NON-NLS-1$
            PasswordPolicyPreferences.class.getName());
    PreferenceNode usernamePrefs = new PreferenceNode("username", //$NON-NLS-1$
            Messages.getString("OptionsAction.UserNameNode"), null, UsernamePreferences.class //$NON-NLS-1$
                    .getName());
    PreferenceNode miscPrefs = new PreferenceNode("misc", Messages.getString("OptionsAction.MiscNode"), null, //$NON-NLS-1$//$NON-NLS-2$
            MiscPreferences.class.getName());

    // Add the nodes
    mgr.addToRoot(displayPrefs);
    mgr.addToRoot(securityPrefs);
    mgr.addToRoot(passwordPolicyPrefs);
    mgr.addToRoot(usernamePrefs);
    mgr.addToRoot(miscPrefs);

    // Create the preferences dialog
    PreferenceDialog dlg = new PreferenceDialog(app.getShell(), mgr);
    Window.setDefaultImage(
            IOUtils.getImage(PasswordSafeJFace.class, "/org/pwsafe/passwordsafeswt/images/clogo.gif")); //$NON-NLS-1$

    // Set the preference store
    dlg.setPreferenceStore(JFacePreferences.getPreferenceStore());

    // Open the dialog
    dlg.open();

    try {
        if (JFacePreferences.getPreferenceStore().needsSaving()) {
            // Be Paranoid - Save the preferences now
            UserPreferences.getInstance().savePreferences();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.reap.internal.core.persistence.PersistenceManager.java

License:Open Source License

private void showConfigDialog(final PersistenceConfig config) {
    final Display display = Activator.getDefault().getWorkbench().getDisplay();
    display.syncExec(new Runnable() {
        public void run() {
            final PreferenceManager manager = new PreferenceManager();
            final PreferenceDialog dialog = new PreferenceDialog(new Shell(display), manager);
            final PreferencePage page = new PersistenceConfigPage(config);
            final IPreferenceNode node = new PreferenceNode("Datenbank", page);
            manager.addToRoot(node);
            configDialogState = dialog.open();
        }/*w  w  w.  j  av  a  2  s  .com*/
    });
}

From source file:org.rubypeople.rdt.internal.ui.preferences.PreferencePageSupport.java

License:Open Source License

/**
 * Open the given preference page in a preference dialog.
 * @param shell The shell to open on//w  w w .j a  v  a  2s. c o  m
 * @param id The id of the preference page as in the plugin.xml 
 * @param page An instance of the page. Note that such a page should also set its own
 * title to correctly show up.
 * @return Returns <code>true</code> if the user ended the page by pressing OK.
 */
public static boolean showPreferencePage(Shell shell, String id, IPreferencePage page) {
    final IPreferenceNode targetNode = new PreferenceNode(id, page);

    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PreferenceDialog dialog = new PreferenceDialog(shell, manager);
    final boolean[] result = new boolean[] { false };
    BusyIndicator.showWhile(shell.getDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            result[0] = (dialog.open() == Window.OK);
        }
    });
    return result[0];
}

From source file:org.springframework.ide.eclipse.ui.SpringUIUtils.java

License:Open Source License

private static boolean openPreferenceNode(final String propertyPageId, final IPreferenceNode targetNode,
        final String title, Object element, Map<String, Object> data) {

    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PropertyDialog dialog = new PropertyDialog(SpringUIPlugin.getActiveWorkbenchShell(), manager,
            new StructuredSelection(element));

    if (propertyPageId != null) {
        dialog.setSelectedNode(propertyPageId);
    }/*  ww  w .j av  a  2 s  . co  m*/
    if (data != null) {
        dialog.setPageData(data);
    }

    final boolean[] result = new boolean[] { false };
    BusyIndicator.showWhile(getStandardDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            dialog.getShell().setText(title);
            result[0] = (dialog.open() == Window.OK);
        }
    });
    return result[0];
}

From source file:org.springsource.ide.eclipse.commons.ui.SpringUIUtils.java

License:Open Source License

private static boolean openPreferenceNode(final String propertyPageId, final IPreferenceNode targetNode,
        final String title, Object element, Map<String, Object> data) {

    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PropertyDialog dialog = new PropertyDialog(UiPlugin.getActiveWorkbenchShell(), manager,
            new StructuredSelection(element));

    if (propertyPageId != null) {
        dialog.setSelectedNode(propertyPageId);
    }/* www.  j  a  v a 2 s .c  o m*/
    if (data != null) {
        dialog.setPageData(data);
    }

    final boolean[] result = new boolean[] { false };
    BusyIndicator.showWhile(getStandardDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            dialog.getShell().setText(title);
            result[0] = (dialog.open() == Window.OK);
        }
    });
    return result[0];
}

From source file:org.springsource.ide.eclipse.gradle.ui.JavaHomeSection.java

License:Open Source License

public void createContents(Composite page) {
    GridDataFactory grabHorizontal = GridDataFactory.fillDefaults().grab(true, false);
    Label label = new Label(page, SWT.NONE);
    label.setText("Java Home (requires Gradle 1.0.RC1 or later)");

    //Alternative 1

    Composite composite = new Composite(page, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);//from w w  w.  jav  a  2 s.c o m
    grabHorizontal.applyTo(composite);

    defaultButton = new Button(composite, SWT.RADIO);
    defaultButton.setText("Use Gradle wrapper's default");
    GridDataFactory span = GridDataFactory.fillDefaults().span(3, 1);
    span.applyTo(defaultButton);

    //Alternative 2: choose a workspace JRE

    customHomeButton = new Button(composite, SWT.RADIO);
    customHomeButton.setText("Workspace JRE: ");
    customHomeButton.setToolTipText("Use a specific Java installation configured in this workspace");

    customJRECombo = new Combo(composite, SWT.DROP_DOWN + SWT.READ_ONLY);
    refreshJREs();

    browseHomeButton = new Button(composite, SWT.PUSH);
    browseHomeButton.setText("Configure JREs");

    customHomeButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            enableDisableWidgets();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });

    browseHomeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            @SuppressWarnings("restriction")
            IPreferencePage page = new org.eclipse.jdt.internal.debug.ui.jres.JREsPreferencePage();
            PreferenceManager mgr = new PreferenceManager();
            IPreferenceNode node = new PreferenceNode("1", page);
            mgr.addToRoot(node);
            PreferenceDialog dialog = new PreferenceDialog(owner.getShell(), mgr);
            dialog.create();
            dialog.setMessage(page.getTitle());
            dialog.open();

            refreshJREs();

            //            System.out.println("kdvolder");

            //            PreferenceDialog w = PreferencesUtil.createPreferenceDialogOn(owner.getShell(), JRE_PREF_PAGE_ID, new String[] {JRE_PREF_PAGE_ID, GradlePreferencesPage.ID}, null);
            //            w.setBlockOnOpen(true);
            //            w.open();
            //            //Eclipse only allows one preferences dialog to be open at the same time
            //            //We only get here after user closed dialog, so we must reopen it on the Gradle preferences page.
            //            PreferencesUtil.createPreferenceDialogOn(null, GradlePreferencesPage.ID, new String[] {JRE_PREF_PAGE_ID, GradlePreferencesPage.ID}, null).open();
        }

    });

    customJRECombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            validator.refresh();
        }
    });

    grabHorizontal.applyTo(customJRECombo);

    setJavaHomeInPage(getJavaHome());
    enableDisableWidgets();
}

From source file:org.springsource.ide.eclipse.gradle.ui.JavaHomeSectionImpl.java

License:Open Source License

/**
 * This does more or less what a PageSection implementation of createContents should do (i.e. 
 * create the widgets on the page).//from   www  . j ava 2  s .  co  m
 * <p>
 * However, it does not fill the widget contents with the contents of the preferences because
 * this implementation may not yet be connected to a preferences store yet when the widgets
 * are being created. It is up to the caller/client to make sure a to call copyFrom method
 * to (re)initialise the widget contents at an appropriate time. 
 * 
 * @param page
 */
public void createWidgets(Composite page) {
    GridDataFactory grabHor = GridDataFactory.fillDefaults().grab(true, false);
    Group group = null;
    if (!border) {
        Label label = new Label(page, SWT.NONE);
        label.setText(TITLE);
    } else {
        group = new Group(page, SWT.BORDER);
        group.setText(TITLE);
    }

    //Alternative 1

    Composite composite = border ? group : new Composite(page, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    composite.setLayout(layout);
    grabHor.applyTo(composite);

    defaultButton = new Button(composite, SWT.RADIO);
    defaultButton.setText("Use Gradle wrapper's default");
    GridDataFactory span = GridDataFactory.fillDefaults().span(3, 1);
    span.applyTo(defaultButton);

    //Alternative 2: choose a workspace JRE

    customHomeButton = new Button(composite, SWT.RADIO);
    customHomeButton.setText("Workspace JRE: ");
    customHomeButton.setToolTipText("Use a specific Java installation configured in this workspace");
    customJRECombo = new Combo(composite, SWT.DROP_DOWN + SWT.READ_ONLY);
    configureJREsButton = new Button(composite, SWT.PUSH);
    configureJREsButton.setText("Configure JREs");

    grabHor.applyTo(configureJREsButton);
    grabHor.applyTo(customJRECombo);

    //Alternative 3: choose an execution environment
    customExecutionEnvButton = new Button(composite, SWT.RADIO);
    customExecutionEnvButton.setText("Execution Environment");
    customExecutionEnvButton.setToolTipText("Specify a JRE indirectly via an execution environment");
    customExecutionEnvCombo = new Combo(composite, SWT.DROP_DOWN + SWT.READ_ONLY);
    configureExecEnvsButton = new Button(composite, SWT.PUSH);
    configureExecEnvsButton.setText("Configure EEs");

    grabHor.applyTo(configureExecEnvsButton);
    grabHor.applyTo(customExecutionEnvCombo);

    refreshJREs();

    customHomeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            enableDisableWidgets(customHomeButton, customJRECombo, configureJREsButton);
            doRefresh();
        }
    });
    customExecutionEnvButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            enableDisableWidgets(customExecutionEnvButton, customExecutionEnvCombo, configureExecEnvsButton);
            doRefresh();
        }
    });

    configureJREsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            @SuppressWarnings("restriction")
            IPreferencePage page = new org.eclipse.jdt.internal.debug.ui.jres.JREsPreferencePage();
            PreferenceManager mgr = new PreferenceManager();
            IPreferenceNode node = new PreferenceNode("1", page);
            mgr.addToRoot(node);
            PreferenceDialog dialog = new PreferenceDialog(owner.getShell(), mgr);
            dialog.create();
            dialog.setMessage(page.getTitle());
            dialog.open();

            refreshJREs();
        }
    });

    configureExecEnvsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            @SuppressWarnings("restriction")
            IPreferencePage page = new org.eclipse.jdt.internal.debug.ui.jres.ExecutionEnvironmentsPreferencePage();
            PreferenceManager mgr = new PreferenceManager();
            IPreferenceNode node = new PreferenceNode("1", page);
            mgr.addToRoot(node);
            PreferenceDialog dialog = new PreferenceDialog(owner.getShell(), mgr);
            dialog.create();
            dialog.setMessage(page.getTitle());
            dialog.open();

            refreshJREs();
        }

    });

    customJRECombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            doRefresh();
        }
    });

    customExecutionEnvCombo.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            doRefresh();
        }
    });

    grabHor.applyTo(customJRECombo);
}

From source file:org.swtchart.ext.InteractiveChart.java

License:Apache License

/**
 * Opens the properties dialog./* w w w.j av  a2 s .co  m*/
 */
private void openPropertiesDialog() {
    PreferenceManager manager = new PreferenceManager();

    final String chartTitle = "Chart";
    PreferenceNode chartNode = new PreferenceNode(chartTitle);
    chartNode.setPage(new ChartPage(this, resources, chartTitle));
    manager.addToRoot(chartNode);

    final String legendTitle = "Legend";
    PreferenceNode legendNode = new PreferenceNode(legendTitle);
    legendNode.setPage(new LegendPage(this, resources, legendTitle));
    manager.addTo(chartTitle, legendNode);

    final String xAxisTitle = "X Axis";
    PreferenceNode xAxisNode = new PreferenceNode(xAxisTitle);
    xAxisNode.setPage(new AxisPage(this, resources, Direction.X, xAxisTitle));
    manager.addTo(chartTitle, xAxisNode);

    final String gridTitle = "Grid";
    PreferenceNode xGridNode = new PreferenceNode(gridTitle);
    xGridNode.setPage(new GridPage(this, resources, Direction.X, gridTitle));
    manager.addTo(chartTitle + "." + xAxisTitle, xGridNode);

    final String tickTitle = "Tick";
    PreferenceNode xTickNode = new PreferenceNode(tickTitle);
    xTickNode.setPage(new AxisTickPage(this, resources, Direction.X, tickTitle));
    manager.addTo(chartTitle + "." + xAxisTitle, xTickNode);

    final String yAxisTitle = "Y Axis";
    PreferenceNode yAxisNode = new PreferenceNode(yAxisTitle);
    yAxisNode.setPage(new AxisPage(this, resources, Direction.Y, yAxisTitle));
    manager.addTo(chartTitle, yAxisNode);

    PreferenceNode yGridNode = new PreferenceNode(gridTitle);
    yGridNode.setPage(new GridPage(this, resources, Direction.Y, gridTitle));
    manager.addTo(chartTitle + "." + yAxisTitle, yGridNode);

    PreferenceNode yTickNode = new PreferenceNode(tickTitle);
    yTickNode.setPage(new AxisTickPage(this, resources, Direction.Y, tickTitle));
    manager.addTo(chartTitle + "." + yAxisTitle, yTickNode);

    final String seriesTitle = "Series";
    PreferenceNode plotNode = new PreferenceNode(seriesTitle);
    plotNode.setPage(new SeriesPage(this, resources, seriesTitle));
    manager.addTo(chartTitle, plotNode);

    final String labelTitle = "Label";
    PreferenceNode labelNode = new PreferenceNode(labelTitle);
    labelNode.setPage(new SeriesLabelPage(this, resources, labelTitle));
    manager.addTo(chartTitle + "." + seriesTitle, labelNode);

    PreferenceDialog dialog = new PreferenceDialog(getShell(), manager);
    dialog.create();
    dialog.getShell().setText("Properties");
    dialog.getTreeViewer().expandAll();
    dialog.open();
}

From source file:org.talend.repository.ui.dialog.ProjectSettingDialog.java

License:Open Source License

/**
 * get all projectsettingPage node dynamic. need get the different result each time. because the tester will calc
 * dymamic.//from   ww  w. jav  a  2s.c  o  m
 * 
 * @return PreferenceManager
 */
private PreferenceManager getNodeManager() {
    // PreferenceManager manager = new PreferenceManager(WorkbenchPlugin.PREFERENCE_PAGE_CATEGORY_SEPARATOR);
    PreferenceManager manager = new PreferenceManager('/');
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IConfigurationElement[] configurationElements = registry
            .getConfigurationElementsFor("org.talend.repository.projectsetting_page"); //$NON-NLS-1$

    Map<String, List<IPreferenceNode>> hasCategoriesNodes = new HashMap<String, List<IPreferenceNode>>();

    for (IConfigurationElement element : configurationElements) {
        ProjectSettingNode node = new ProjectSettingNode(element);
        try {
            IPreferencePage page = (IPreferencePage) element.createExecutableExtension("class"); //$NON-NLS-1$
            node.setPage(page);
            String id = element.getAttribute("id");//$NON-NLS-1$
            IConfigurationElement[] testers = element.getChildren("tester");
            if (testers != null && testers.length == 1) { // currently, only one tester is supported.
                try {
                    IProjectSettingPageTester pageTester = (IProjectSettingPageTester) testers[0]
                            .createExecutableExtension("class");
                    if (pageTester != null) {
                        if (!pageTester.valid(element, node)) {
                            continue; // don't add this page node.
                        }
                    }
                } catch (CoreException ex) {
                    // can't create the tester
                    log.log(Level.WARN, "can't create the project setting tester for " + id, ex);
                }
            }

            page.setDescription(element.getAttribute("description")); //$NON-NLS-1$
            page.setTitle(element.getAttribute("title")); //$NON-NLS-1$
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        // add all into root.
        manager.addToRoot(node);

        // has category
        String category = node.getCategory();
        if (category != null && category.length() > 0) {
            List<IPreferenceNode> list = hasCategoriesNodes.get(category);
            if (list == null) {
                list = new ArrayList<IPreferenceNode>();
                hasCategoriesNodes.put(category, list);
            }
            list.add(node);
        }
    }

    // add the speciall node for maven custom
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IMavenUIService.class)) {
        IMavenUIService mavenUIService = (IMavenUIService) GlobalServiceRegister.getDefault()
                .getService(IMavenUIService.class);
        IPreferenceNode mavenCostomSetup = manager.find("projectsetting.MavenCustomSetup");
        mavenUIService.addCustomMavenSettingChildren(mavenCostomSetup);
    }

    // find parent nodes for category
    Map<String, IPreferenceNode> parentNodesMap = new HashMap<String, IPreferenceNode>();
    for (String category : hasCategoriesNodes.keySet()) {
        IPreferenceNode parent = manager.find(category);
        if (parent != null) {
            parentNodesMap.put(category, parent);
        }
    }
    // process children nodes
    for (String category : hasCategoriesNodes.keySet()) {
        List<IPreferenceNode> list = hasCategoriesNodes.get(category);
        if (list != null) {

            IPreferenceNode parent = parentNodesMap.get(category);
            Collections.sort(list, COMPARATOR);
            for (IPreferenceNode node : list) {
                // if the parent is not valid or not existed. the node won't show also.
                manager.remove(node); // remove from root node.
                if (parent != null) { // the parent existed.
                    parent.add(node);
                }
            }
        }
    }

    // sort the root nodes
    List<IPreferenceNode> rootSubNodesList = new ArrayList<IPreferenceNode>(
            Arrays.asList(manager.getRootSubNodes()));

    Collections.sort(rootSubNodesList, COMPARATOR);
    manager.removeAll(); // clean all to re-add for order

    // add the sorted list to manager
    for (IPreferenceNode rootSubNode : rootSubNodesList) {
        manager.addToRoot(rootSubNode);
    }
    return manager;
}

From source file:org.xwalk.ide.eclipse.xdt.wizards.export.ExportProjectWizard.java

License:Apache License

private void showQuickPreferenceDialog() {
    IPreferencePage page = new settingPage();
    PreferenceManager mgr = new PreferenceManager('/');
    IPreferenceNode node = new PreferenceNode("1", page);
    mgr.addToRoot(node);
    PreferenceDialog dialog = new PreferenceDialog(getShell(), mgr);
    dialog.create();/*w ww.  j a  v  a2  s .  co m*/
    dialog.setMessage(page.getTitle());
    dialog.open();
}