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:org.eclipse.gmf.runtime.common.ui.services.properties.extended.PropertyPageCellEditor.java

License:Open Source License

/**
 * Opens the {@link org.eclipse.gmf.runtime.common.ui.dialogs.PropertiesDialog}. Always
 * returns null. The UI is updated by the model event when the property
 * is modified by the property dialog.//from  w w w.j  a  v  a  2  s  . c  o m
 * 
 * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control)
 */
protected Object openDialogBox(Control cellEditorWindow) {

    // Invoke the property dialog
    PropertiesDialog dialog = new PropertiesDialog(getControl().getShell(), new PreferenceManager());

    // handle invokation of cell editor from collection editor
    PropertyPagePropertyDescriptor realDescriptor = null;
    if (getValue() instanceof ElementValue) {
        Object element = ((ElementValue) getValue()).getElement();
        if (element instanceof PropertyPagePropertyDescriptor) {
            realDescriptor = (PropertyPagePropertyDescriptor) element;
        }
    }

    List pages = null;
    if (realDescriptor != null) {
        pages = realDescriptor.createPropertyPages();
    } else {
        pages = getPropertyDescriptor().createPropertyPages();
    }

    for (Iterator i = pages.iterator(); i.hasNext();) {
        PropertyPage page = (PropertyPage) i.next();

        // handle invokation of cell editor from collection editor
        if (realDescriptor != null) {
            final IPropertySource source = realDescriptor.getPropertySource();
            page.setElement(new IAdaptable() {
                public Object getAdapter(Class adapter) {
                    if (adapter.equals(IPropertySource.class)) {
                        return source;
                    }
                    return null;
                }
            });
        }

        dialog.getPreferenceManager().addToRoot(new PreferenceNode(StringStatics.BLANK, page));
    }

    dialog.create();
    dialog.open();

    // refresh property for collection editor
    for (Iterator i = pages.iterator(); i.hasNext();) {
        PropertyPage page = (PropertyPage) i.next();
        IAdaptable adaptable = page.getElement();
        if (adaptable != null) {
            IPropertySource source = (IPropertySource) adaptable.getAdapter(IPropertySource.class);
            if (source instanceof IExtendedPropertySource) {
                Object element = ((IExtendedPropertySource) source).getElement();

                IPropertySource propertySource = PropertiesService.getInstance().getPropertySource(

                        element);
                assert null != propertySource;

                for (Iterator j = Arrays.asList(propertySource.getPropertyDescriptors()).iterator(); j
                        .hasNext();) {
                    IPropertyDescriptor descriptor = (IPropertyDescriptor) j.next();
                    if (descriptor.getId().equals(getPropertyDescriptor().getId())) {
                        // apply new value in cell editor
                        setValue(new ElementValue(source, propertySource.getPropertyValue(descriptor.getId())));
                        fireApplyEditorValue();
                        break;
                    }
                }
            }
        }
    }

    return null;
}

From source file:org.eclipse.gmf.runtime.diagram.ui.internal.dialogs.PageSetupSelectionConfigBlock.java

License:Open Source License

/** 
 * Attach selection handling logic to 'Configure workspace settings' button. 
 *//*from   w  w  w.  j a  v a 2 s .  c o m*/
private void addConfigureWorkspaceSettingsListener() {
    fButtonConfigure.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            // Display Printing preference page allowing the user to configure global printing settings
            IPreferencePage page = new PrintingPreferencePage(fGlobalStore);
            page.setTitle(ILabels.LABEL_PREFERENCE_PAGE_PRINTING);

            IPreferenceNode targetNode = new PreferenceNode(ID_PAGE_SETUP_PREF_PAGE, page);
            PreferenceManager manager = new PreferenceManager();
            manager.addToRoot(targetNode);

            PreferenceDialog dialog = new PreferenceDialog(fShell, manager);

            dialog.create();
            dialog.setMessage(TITLE_PAGE_SETUP_TAB_ITEM);
            dialog.open();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
        }

    });
}

From source file:org.eclipse.gmf.runtime.emf.ui.properties.actions.PropertyPageViewAction.java

License:Open Source License

public void run() {
    Trace.trace(EMFPropertiesPlugin.getDefault(), EMFPropertiesDebugOptions.METHODS_ENTERING,
            "PropertyPageViewActionDelegate.doRun Entering"); //$NON-NLS-1$
    IWorkbenchPage page = EMFPropertiesPlugin.getActivePage();
    if (page != null) {
        final ISelection selection = page.getSelection();
        if (selection != null && selection instanceof IStructuredSelection) {
            TransactionalEditingDomain domain = getEditingDomain((IStructuredSelection) selection);

            if (domain != null) {
                try {
                    domain.runExclusive(new Runnable() {

                        public void run() {

                            // build the pages for the property dialog
                            List propertyPages = getMergedPropertyPages((IStructuredSelection) selection);

                            if (!propertyPages.isEmpty()) {
                                // sort the pages
                                Collections.sort(propertyPages, new Comparator() {

                                    public int compare(Object o1, Object o2) {
                                        IPreferencePage p1 = (IPreferencePage) o1;
                                        IPreferencePage p2 = (IPreferencePage) o2;
                                        String s1 = p1.getTitle();
                                        String s2 = p2.getTitle();
                                        return Collator.getInstance().compare(s1, s2);
                                    }/*from  w ww.jav a 2 s  .c  o  m*/
                                });

                                // add the pages and invoke the property
                                // dialog
                                PropertiesDialog dialog = new PropertiesDialog(
                                        Display.getCurrent().getActiveShell(), new PreferenceManager());

                                for (Iterator iter = propertyPages.iterator(); iter.hasNext();) {
                                    dialog.getPreferenceManager().addToRoot(new PreferenceNode(
                                            StringStatics.BLANK, (IPreferencePage) iter.next()));
                                }

                                dialog.create();
                                dialog.open();
                            } else {
                                MessageDialog.openInformation(Display.getCurrent().getActiveShell(),
                                        EMFUIPropertiesMessages.PropertyPageViewAction_NoPropertiesMessageBox_Title,
                                        EMFUIPropertiesMessages.PropertyPageViewAction_NoPropertiesMessageBox_Message);
                            }
                        }
                    });
                } catch (InterruptedException e) {
                    Trace.catching(EMFPropertiesPlugin.getDefault(),
                            EMFPropertiesDebugOptions.EXCEPTIONS_CATCHING, getClass(), "run", e); //$NON-NLS-1$
                    Log.error(EMFPropertiesPlugin.getDefault(), EMFPropertiesStatusCodes.ACTION_FAILURE,
                            e.getLocalizedMessage(), e);
                }
            }
        }
    }
    Trace.trace(EMFPropertiesPlugin.getDefault(), EMFPropertiesDebugOptions.METHODS_EXITING,
            "PropertyPageViewActionDelegate.doRun Exiting"); //$NON-NLS-1$
}

From source file:org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin.java

License:Open Source License

/**
 * Displays the given preference page.//from w  w w. jav  a 2s.c  o m
 * 
 * @param id pref page id
 * @param page pref page
 * @deprecated use <code>JDIDebugUIPlugin#showPreferencePage(String pageId)</code>, which uses the <code>PreferenceUtils</code> framework for opening pages.
 */
@Deprecated
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(JDIDebugUIPlugin.getActiveWorkbenchShell(), manager);
    final boolean[] result = new boolean[] { false };
    BusyIndicator.showWhile(JDIDebugUIPlugin.getStandardDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            result[0] = (dialog.open() == Window.OK);
        }
    });
}

From source file:org.eclipse.jst.pagedesigner.actions.single.ChangeStyleAction.java

License:Open Source License

public void run() {
    ICSSStyleDeclaration styleDeclaration = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) this._element)
            .getStyle();//from  ww w.  j  a v  a 2 s .  com
    PreferenceManager manager = new PreferenceManager();
    EditPartViewer viewer = this._editPart.getViewer();
    Shell shell = viewer.getControl().getShell();

    CSSPropertyContext context = new CSSPropertyContext(styleDeclaration);
    StyleDialog dialog = new StyleDialog(shell, manager, _element, context);
    if (dialog.open() == Window.OK) {
        if (context.isModified()) {
            ChangeStyleCommand c = new ChangeStyleCommand(_element, _attribute, context);
            c.execute();
        }
    }
}

From source file:org.eclipse.jst.pagedesigner.properties.celleditors.CSSDialogCellEditor.java

License:Open Source License

protected Object openDialogBox(Control cellEditorWindow) {
    final ICSSStyleDeclaration styleDeclaration = CSSStyleDeclarationFactory.getInstance()
            .getStyleDeclaration(_element, _attr.getAttributeName());

    final PreferenceManager manager = new PreferenceManager();
    final Shell shell = cellEditorWindow.getShell();

    final CSSPropertyContext context = new CSSPropertyContext(styleDeclaration);
    final StyleDialog dialog = new StyleDialog(shell, manager, _element, context);
    if (dialog.open() == Window.OK) {
        if (context.isModified()) {
            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                public void run() {
                    final ChangeStyleCommand c = new ChangeStyleCommand(_element, _attr.getAttributeName(),
                            context);//from w ww.  j av a 2  s  . c  om
                    c.execute();
                }
            });
        }
    }

    String style = (_element == null ? null : _element.getAttribute(_attr.getAttributeName()));
    return style == null ? "" : style; //$NON-NLS-1$
}

From source file:org.eclipse.jst.pagedesigner.ui.dialogfields.StyleButtonDialogField.java

License:Open Source License

private void browseButtonPressed() {
    if (_element instanceof ElementCSSInlineStyle) {
        ICSSStyleDeclaration styleDeclaration = (ICSSStyleDeclaration) ((ElementCSSInlineStyle) _element)
                .getStyle();//from www . ja  v a2 s .  co  m

        PreferenceManager manager = new PreferenceManager();
        Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

        CSSPropertyContext context = new CSSPropertyContext(styleDeclaration);
        StyleDialog dialog = new StyleDialog(shell, manager, _element, context);
        if (dialog.open() == Dialog.OK) {
            if (!context.isModified()) {
                return;
            }
            ChangeStyleCommand c = new ChangeStyleCommand(_element, context);
            c.execute();

            String style = (_element == null ? null : _element.getAttribute(IJSFConstants.ATTR_STYLE));
            setText(style);
        }
    }
}

From source file:org.eclipse.jst.server.generic.ui.internal.JRESelectDecorator.java

License:Open Source License

protected boolean showPreferencePage(GenericServerComposite composite) {
    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode node = manager.find("org.eclipse.jdt.ui.preferences.JavaBasePreferencePage") //$NON-NLS-1$
            .findSubNode("org.eclipse.jdt.debug.ui.preferences.VMPreferencePage"); //$NON-NLS-1$
    PreferenceManager manager2 = new PreferenceManager();
    manager2.addToRoot(node);/* w  ww . ja va  2  s. c  o  m*/
    final PreferenceDialog dialog = new PreferenceDialog(composite.getShell(), manager2);
    final boolean[] result = new boolean[] { false };
    BusyIndicator.showWhile(composite.getDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            if (dialog.open() == Window.OK)
                result[0] = true;
        }
    });
    return result[0];
}

From source file:org.eclipse.jst.server.jetty.ui.internal.JettyRuntimeComposite.java

License:Open Source License

protected boolean showPreferencePage() {
    String id = "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage";

    // should be using the following API, but it only allows a single
    // preference page instance.
    // see bug 168211 for details
    // PreferenceDialog dialog =
    // PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[]
    // { id }, null);
    // return (dialog.open() == Window.OK);

    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode node = manager.find("org.eclipse.jdt.ui.preferences.JavaBasePreferencePage")
            .findSubNode(id);//from  w w  w  .  ja v a 2s  . c  o  m
    PreferenceManager manager2 = new PreferenceManager();
    manager2.addToRoot(node);
    PreferenceDialog dialog = new PreferenceDialog(getShell(), manager2);
    dialog.create();
    return (dialog.open() == Window.OK);
}

From source file:org.eclipse.jst.server.tomcat.ui.internal.TomcatRuntimeComposite.java

License:Open Source License

protected boolean showPreferencePage() {
    String id = "org.eclipse.jdt.debug.ui.preferences.VMPreferencePage";

    // should be using the following API, but it only allows a single preference page instance.
    // see bug 168211 for details
    //PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String[] { id }, null);
    //return (dialog.open() == Window.OK);      

    PreferenceManager manager = PlatformUI.getWorkbench().getPreferenceManager();
    IPreferenceNode node = manager.find("org.eclipse.jdt.ui.preferences.JavaBasePreferencePage")
            .findSubNode(id);//from   w ww .  j  av  a 2s.  c  o  m
    PreferenceManager manager2 = new PreferenceManager();
    manager2.addToRoot(node);
    PreferenceDialog dialog = new PreferenceDialog(getShell(), manager2);
    dialog.create();
    return (dialog.open() == Window.OK);
}