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

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

Introduction

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

Prototype

public PreferenceNode(String id, IPreferencePage preferencePage) 

Source Link

Document

Creates a preference node with the given id and preference page.

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 w  w.ja  v a 2s  .  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//from w  ww  .  jav a  2  s  .c o m
 * 
 * @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

private static IPreferenceNode createPreferenceNode(IConfigurationElement elmt, IEclipseContext context) {
    if (elmt.getAttribute(ATTR_CLASS) != null) {
        IPreferencePage page = null;/*  www  .ja v  a 2  s  . c  om*/
        try {
            String prefPageURI = getClassURI(elmt.getNamespaceIdentifier(), elmt.getAttribute(ATTR_CLASS));
            Object object = context.get(IContributionFactory.class).create(prefPageURI, context);
            if (!(object instanceof IPreferencePage)) {
                logger.error("Expected instance of IPreferencePage: {0}", elmt.getAttribute(ATTR_CLASS)); //$NON-NLS-1$
                return null;
            }
            page = (IPreferencePage) object;
        } catch (Exception e) {
            logger.error(e);
            return null;
        }

        ContextInjectionFactory.inject(page, context);
        if ((page.getTitle() == null || page.getTitle().isEmpty()) && elmt.getAttribute(ATTR_NAME) != null) {
            page.setTitle(elmt.getAttribute(ATTR_NAME));
        }
        return new PreferenceNode(elmt.getAttribute(ATTR_ID), page);
    } else {
        return new PreferenceNode(elmt.getAttribute(ATTR_ID),
                new EmptyPreferencePage(elmt.getAttribute(ATTR_NAME)));
    }
}

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

License:Apache License

/**
 * Toggles sample nature on a project//from  w w w .j a  v 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.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();//from ww w .  j  a  v a 2s  . c  om
        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.j a  v a 2  s.  c  om
 */
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
 * /*from w w  w  .  java  2s .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)
 *//*from  ww w .ja  v a 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);
        }
    });
}

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

License:Open Source License

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

    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PreferenceDialog dialog = new PreferenceDialog(UIUtils.getActiveShell(), 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);
        }
    });
}

From source file:com.bdaum.overlayPages.FieldEditorOverlayPage.java

License:Open Source License

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