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:at.nucle.e4.plugin.preferences.core.internal.registry.PreferenceRegistry.java

License:Open Source License

public PreferenceManager createPages(PreferenceManager preferenceManager) {
    preferenceManager.removeAll();/*from   w  ww .j a v a  2  s  .  c o  m*/
    elements.values().forEach(element -> {
        PreferencePage page = null;
        if (element.getAttribute(ATTRIBUTE_CLASS) != null) {
            try {
                Object obj = element.createExecutableExtension(ATTRIBUTE_CLASS);
                if (obj instanceof PreferencePage) {
                    page = (PreferencePage) obj;

                    ContextInjectionFactory.inject(page, context);
                    if ((page.getTitle() == null || page.getTitle().isEmpty())
                            && element.getAttribute(ATTRIBUTE_TITLE) != null) {
                        page.setTitle(element.getAttribute(ATTRIBUTE_TITLE));
                    }

                    setPreferenceStore(page, element.getNamespaceIdentifier());
                    String category = element.getAttribute(ATTRIBUTE_CATEGORY);
                    if (category != null) {
                        preferenceManager.addTo(category,
                                new PreferenceNode(element.getAttribute(ATTRIBUTE_ID), page));
                    } else {
                        preferenceManager
                                .addToRoot(new PreferenceNode(element.getAttribute(ATTRIBUTE_ID), page));
                    }
                } else {
                    System.out.println(TAG + " Object must extend FieldEditorPreferencePage or PreferencePage");
                }
            } catch (CoreException exception) {
                exception.printStackTrace();
            }
        } else {
            System.out.println(TAG + " Attribute class may not be null");
        }
    });
    return preferenceManager;
}

From source file:at.spardat.xma.guidesign.preferences.AbstractPreferenceAndPropertyPage.java

License:Open Source License

/**
 * Show a single preference pages/*  w  w w. j  av  a  2  s  .c om*/
 * 
 * @param id
 *            - the preference page identification
 * @param page
 *            - the preference page
 */
protected void showPreferencePage(String id, IPreferencePage page) {
    final IPreferenceNode targetNode = new PreferenceNode(id, page);
    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PreferenceDialog dialog = new PreferenceDialog(getControl().getShell(), manager);
    BusyIndicator.showWhile(getControl().getDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            dialog.open();
        }
    });
}

From source file:au.gov.ga.earthsci.application.preferences.PreferenceUtil.java

License:Apache License

/**
 * Populate the provided preference manager with nodes from the provided list of preference elements.
 * /*from  ww w .j av a2 s . c o m*/
 * @param pm The preference manager to populate
 * @param preferenceElements The list of preference elements from which to populate the manager
 * @param context The current eclipse context for DI etc.
 */
private static void populatePreferenceManager(PreferenceManager pm, IEclipseContext context,
        List<IConfigurationElement> preferenceElements) {
    // Add nodes in 3 phases:
    // 1. Add all root nodes (no category specified)
    // 2. Progressively add child nodes to build up the node tree, breadth first
    // 3. Add remaining (orphan) child nodes, along with a warning

    // Add root nodes
    int maxPathLength = 0;
    List<IConfigurationElement> remainingElements = new ArrayList<IConfigurationElement>();
    for (IConfigurationElement elmt : preferenceElements) {
        if (isEmpty(elmt.getAttribute(ATTR_CATEGORY))) {
            IPreferenceNode node = createPreferenceNode(elmt, context);
            if (node == null) {
                continue;
            }
            pm.addToRoot(node);
        } else {
            int categoryPathLength = elmt.getAttribute(ATTR_CATEGORY).split("\\\\").length; //$NON-NLS-1$
            maxPathLength = Math.max(maxPathLength, categoryPathLength);
            remainingElements.add(elmt);
        }
    }

    // Add child nodes
    preferenceElements = remainingElements;
    for (int i = 0; i < maxPathLength; i++) {
        remainingElements = new ArrayList<IConfigurationElement>();
        for (IConfigurationElement elmt : preferenceElements) {
            IPreferenceNode parent = findNode(pm, elmt.getAttribute(ATTR_CATEGORY));
            if (parent != null) {
                IPreferenceNode node = createPreferenceNode(elmt, context);
                parent.add(node);
            } else {
                remainingElements.add(elmt);
            }
        }
        preferenceElements = remainingElements;
    }

    // Finally, add any nodes that are parent-less, along with a warning
    for (IConfigurationElement elmt : preferenceElements) {
        logger.warn("Preference page {0} expected category {1} but none was found.", elmt.getAttribute(ATTR_ID), //$NON-NLS-1$
                elmt.getAttribute(ATTR_CATEGORY));
        IPreferenceNode node = createPreferenceNode(elmt, context);
        if (node == null) {
            continue;
        }
        pm.addToRoot(node);
    }
}

From source file:ca.mcgill.cs.swevo.qualyzer.ApplicationWorkbenchWindowAdvisor.java

License:Open Source License

@Override
public void postWindowCreate() {
    PreferenceManager pm = PlatformUI.getWorkbench().getPreferenceManager();

    pm.remove("net.sf.colorer.eclipse.PreferencePage"); //$NON-NLS-1$
    IPreferenceNode node = pm.remove("org.eclipse.ui.preferencePages.Workbench"); //$NON-NLS-1$
    for (IPreferenceNode sub : node.getSubNodes()) {
        if (sub.getId().equals("org.eclipse.ui.preferencePages.Keys")) //$NON-NLS-1$
        {/* w  w w.j av a 2  s .  c om*/
            pm.addToRoot(sub);
        }
    }

    String upgradeMessage = QualyzerActivator.getDefault().getUpgradeMessage();
    if (upgradeMessage != null) {
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
        boolean error = QualyzerActivator.getDefault().isUpgradeMessageError();
        if (error) {
            MessageDialog.openError(shell, Messages.getString("QualyzerActivator.upgradedTitle"), //$NON-NLS-1$
                    upgradeMessage); //$NON-NLS-1$
        } else {
            MessageDialog.openInformation(shell, Messages.getString("QualyzerActivator.upgradedTitle"), //$NON-NLS-1$
                    upgradeMessage);
        }
    }
}

From source file:com.aerospike.core.nature.AddRemoveAerospikeNatureHandler.java

License:Apache License

/**
 * Toggles sample nature on a project/*from  ww  w .  j av a 2 s.  c o  m*/
 *
 * @param project
 *            to have sample nature added or removed
 */
private void toggleNature() {
    if (selection instanceof IStructuredSelection) {
        for (Iterator<?> it = ((IStructuredSelection) selection).iterator(); it.hasNext();) {
            Object element = it.next();
            IProject project = null;
            if (element instanceof IProject) {
                project = (IProject) element;
            } else if (element instanceof IAdaptable) {
                project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
            }
            if (project != null) {
                try {
                    IProjectDescription description = project.getDescription();
                    String[] natures = description.getNatureIds();

                    for (int i = 0; i < natures.length; ++i) {
                        if (AerospikeNature.NATURE_ID.equals(natures[i])) {
                            // Remove the nature
                            String[] newNatures = new String[natures.length - 1];
                            System.arraycopy(natures, 0, newNatures, 0, i);
                            System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1);
                            description.setNatureIds(newNatures);
                            project.setDescription(description, null);
                            return;
                        }
                    }
                    // Add the nature
                    String[] newNatures = new String[natures.length + 1];
                    System.arraycopy(natures, 0, newNatures, 0, natures.length);
                    newNatures[natures.length] = AerospikeNature.NATURE_ID;
                    description.setNatureIds(newNatures);
                    project.setDescription(description, null);
                    // Show property page
                    ClusterPropertyPage page = new ClusterPropertyPage();
                    page.setElement((IAdaptable) element);
                    PreferenceManager mgr = new PreferenceManager();
                    IPreferenceNode node = new PreferenceNode("1", page);
                    mgr.addToRoot(node);
                    Shell shell = this.part.getSite().getShell();
                    PropertyDialog dialog = new PropertyDialog(shell, mgr, this.selection);
                    dialog.create();
                    dialog.setMessage(page.getTitle());
                    dialog.open();
                } catch (CoreException e) {
                    CoreActivator.showError(e, "Could not change Aerospike Nature");
                }
            }
        }
    }
}

From source file:com.agynamix.platform.frontend.preferences.ApplicationPreferenceDialog.java

License:Open Source License

public int open() {
    PreferenceConfigAdapterImpl configAdapter = new PreferenceConfigAdapterImpl();
    ApplicationPreferenceStore store = new ApplicationPreferenceStore(configAdapter); // AppConfigUtil.getPreferencesFile());

    store.addPropertyChangeListener(configAdapter);

    PreferenceManager manager = new PreferenceManager();

    GlobalPreferencePageDefaults defaultPage = new GlobalPreferencePageDefaults(configAdapter);
    defaultPage.addPreferenceDialogListener(this);
    PreferenceNode defaultsNode = new PreferenceNode("defaultsPage");
    GlobalPreferencePageNetwork networkPage = new GlobalPreferencePageNetwork(configAdapter);
    networkPage.addPreferenceDialogListener(this);
    PreferenceNode networkNode = new PreferenceNode("networkPage");
    defaultsNode.setPage(defaultPage);/*from   w  w  w .  j  a va2  s.c o m*/
    manager.addToRoot(defaultsNode);
    networkNode.setPage(networkPage);
    manager.addToRoot(networkNode);

    PreferenceDialog dialog = new PreferenceDialog(shell, manager);
    dialog.setPreferenceStore(store);
    int result = dialog.open();
    for (IPreferenceDialogListener l : preferenceDialogListeners) {
        l.dialogClosed(result);
    }
    return result;
}

From source file:com.aliyun.odps.eclipse.create.wizard.NewOdpsProjectWizardPage.java

License:Apache License

public void widgetSelected(SelectionEvent e) {
    if (e.getSource() == linkConfigDefaultConsoleLocation) {
        PreferenceManager manager = new PreferenceManager();
        manager.addToRoot(new PreferenceNode("ODPS Console Directory", new PreferencePageOdpsConsole()));
        PreferenceDialog dialog = new PreferenceDialog(this.getShell(), manager);
        dialog.create();// w  w w. j a  v  a  2 s  .  c o m
        dialog.setMessage(CONSOLE_LOCATION_TXT);
        dialog.setBlockOnOpen(true);
        dialog.open();
        updateHadoopDirLabelFromPreferences();
    } else if (e.getSource() == btnNewConsoleLocation) {
        DirectoryDialog dialog = new DirectoryDialog(this.getShell());
        dialog.setMessage(CONSOLE_LOCATION_TXT);
        dialog.setText(CONSOLE_LOCATION_TXT);
        String directory = dialog.open();

        if (directory != null) {
            txtNewConsoleLocation.setText(directory);

            if (!validateODPSConoleLocation()) {
                setErrorMessage("No ODPS SDK jar found in specified directory");
            } else {
                setErrorMessage(null);
            }
        }
    } else if (radioNewConsoleLocation.getSelection()) {
        txtNewConsoleLocation.setEnabled(true);
        btnNewConsoleLocation.setEnabled(true);
    } else {
        txtNewConsoleLocation.setEnabled(false);
        btnNewConsoleLocation.setEnabled(false);
    }
    getContainer().updateButtons();
}

From source file:com.android.ddms.PrefsDialog.java

License:Apache License

/**
 * Create and display the dialog.//from w  ww.  java  2 s . co m
 */
public static void run(Shell shell) {
    PreferenceStore prefStore = mStore.getPreferenceStore();
    assert prefStore != null;

    PreferenceManager prefMgr = new PreferenceManager();

    PreferenceNode node, subNode;

    // this didn't work -- got NPE, possibly from class lookup:
    //PreferenceNode app = new PreferenceNode("app", "Application", null,
    //    AppPrefs.class.getName());

    node = new PreferenceNode("debugger", new DebuggerPrefs());
    prefMgr.addToRoot(node);

    subNode = new PreferenceNode("panel", new PanelPrefs());
    //prefMgr.addTo(node.getId(), subNode);
    prefMgr.addToRoot(subNode);

    node = new PreferenceNode("LogCat", new LogCatPrefs());
    prefMgr.addToRoot(node);

    node = new PreferenceNode("misc", new MiscPrefs());
    prefMgr.addToRoot(node);

    node = new PreferenceNode("stats", new UsageStatsPrefs());
    prefMgr.addToRoot(node);

    PreferenceDialog dlg = new PreferenceDialog(shell, prefMgr);
    dlg.setPreferenceStore(prefStore);

    // run it
    try {
        dlg.open();
    } catch (Throwable t) {
        Log.e("ddms", t);
    }

    // save prefs
    try {
        prefStore.save();
    } catch (IOException ioe) {
    }

    // discard the stuff we created
    //prefMgr.dispose();
    //dlg.dispose();
}

From source file:com.aptana.formatter.ui.util.SWTUtil.java

License:Open Source License

/**
 * This method allows us to open the preference dialog on the specific page, in this case the perspective page
 * // w ww  .j  a  va 2 s  .  c o  m
 * @param id
 *            the id of pref page to show
 * @param page
 *            the actual page to show Copied from org.eclipse.debug.internal.ui.SWTUtil
 */
public static void showPreferencePage(String id, IPreferencePage page) {
    final IPreferenceNode targetNode = new PreferenceNode(id, page);
    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PreferenceDialog dialog = new PreferenceDialog(UIUtils.getActiveShell(), manager);
    BusyIndicator.showWhile(getStandardDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            dialog.open();
        }
    });
}

From source file:com.aptana.ide.debug.internal.ui.actions.DetailOptionsActionDelegate.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
 *///  ww w . java  2  s  . c om
public void run(IAction action) {
    final IPreferenceNode targetNode = new PreferenceNode(
            "com.aptana.ide.debug.ui.preferences.jsDetailFormatters", new JSDetailFormattersPreferencePage()); //$NON-NLS-1$

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