Example usage for org.eclipse.jface.preference PreferenceDialog open

List of usage examples for org.eclipse.jface.preference PreferenceDialog open

Introduction

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

Prototype

public int open() 

Source Link

Document

Opens this window, creating it first if it has not yet been created.

Usage

From source file:org.eclipse.titan.executor.properties.FieldEditorPropertyPage.java

License:Open Source License

protected void showPreferencePage(final String id, final IPreferencePage page) {
    final IPreferenceNode targetNode = new PreferenceNode(id, page);
    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);//w ww.ja  v  a 2  s  . c  om
    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();
        }
    });
}

From source file:org.eclipse.titan.log.viewer.actions.ExtractComponentsMenuAction.java

License:Open Source License

private void setNewProperties(List<String> components, IFile logFile, PreferencesHolder preferences) {
    if (components == null) {
        return;//  www  . j  av a 2 s  .c o m
    }

    // Check APPEND / REPLACE
    if (!preferences.getReplaceCompVisOrder()) {
        // Append
        List<String> compVisOrder = preferences.getVisualOrderComponents();
        for (String currComponent : components) {
            if (!compVisOrder.contains(currComponent)) {
                compVisOrder.add(currComponent);
            }
        }
        components = compVisOrder;
    } else {
        // Replace
        components.add(0, Constants.SUT);
        components.add(0, Constants.MTC);
    }

    // Check DIALOG / NO DIALOG
    if (preferences.getOpenPropAfterCompExt()) {
        // Open dialog
        PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(null, logFile.getProject(),
                PreferenceConstants.PAGE_ID_COMP_VIS_ORDER_PAGE, null, null);
        Object currentPage = dialog.getSelectedPage();
        if (currentPage instanceof ComponentsVisualOrderPrefPage) {
            ComponentsVisualOrderPrefPage componentsVisualOrderPrefPage = (ComponentsVisualOrderPrefPage) currentPage;
            componentsVisualOrderPrefPage.setUseProjectSetting(true);
            componentsVisualOrderPrefPage.clearList();
            for (String component : components) {
                componentsVisualOrderPrefPage.addComponent(component);
            }
            dialog.open();
        }
    } else {
        // No dialog - write directly to properties
        StringBuilder path = new StringBuilder(""); //$NON-NLS-1$
        for (String currComponent : components) {
            path.append(currComponent);
            path.append(File.pathSeparator);
        }
        try {
            // Set resource to use project settings
            ResourcePropertyHandler.setProperty(logFile.getProject(),
                    PreferenceConstants.PAGE_ID_COMP_VIS_ORDER_PAGE,
                    LogViewerPreferenceRootPage.USEPROJECTSETTINGS, LogViewerPreferenceRootPage.TRUE);
            // Set new component visual order
            ResourcePropertyHandler.setProperty(logFile.getProject(),
                    PreferenceConstants.PAGE_ID_COMP_VIS_ORDER_PAGE,
                    PreferenceConstants.PREF_COMPONENT_ORDER_ID, path.toString());
        } catch (CoreException e) {
            // Do nothing
        }
    }
}

From source file:org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.LoadDialog.java

License:Open Source License

@Override
protected void createButtonsForButtonBar(final Composite parent) {
    createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
    Button manageButton = createButton(parent, IDialogConstants.CLIENT_ID + 1,
            Messages.TraceControl_ManageButtonText, false);
    manageButton.addSelectionListener(new SelectionAdapter() {
        @Override//w  w w  .j av  a 2 s  .com
        public void widgetSelected(SelectionEvent e) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(parent.getShell(),
                    ControlRemoteProfilesPreferencePage.ID,
                    new String[] { ControlRemoteProfilesPreferencePage.ID }, null);
            dialog.open();
            if (fLocalComposite != null) {
                fFolderViewer.setInput(LTTngProfileViewer.getViewerInput());
                enableLocalButtons();
            }
        }
    });
    Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
    button.setEnabled(false);
}

From source file:org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.RemoteFetchLogWizardPage.java

License:Open Source License

@Override
protected void createSourceGroup(final Composite parent) {
    Composite directoryContainerGroup = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;/*w  ww  .j a v a  2s  .  c o m*/
    directoryContainerGroup.setLayout(layout);
    directoryContainerGroup.setFont(parent.getFont());
    directoryContainerGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    Label profileLabel = new Label(directoryContainerGroup, SWT.NONE);
    profileLabel.setText(RemoteMessages.RemoteProfilesPreferencePage_ProfileNameLabel);
    profileLabel.setFont(parent.getFont());

    fProfileNameCombo = new Combo(directoryContainerGroup, SWT.BORDER | SWT.READ_ONLY);
    GridData pdata = new GridData(SWT.FILL, SWT.FILL, true, false);
    pdata.widthHint = SIZING_TEXT_FIELD_WIDTH;
    fProfileNameCombo.setLayoutData(pdata);
    fProfileNameCombo.setFont(parent.getFont());

    Button manageProfilesButton = new Button(directoryContainerGroup, SWT.NONE);
    manageProfilesButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(parent.getShell(),
                    RemoteProfilesPreferencePage.ID, new String[] { RemoteProfilesPreferencePage.ID }, null);
            RemoteProfilesPreferencePage page = (RemoteProfilesPreferencePage) dialog.getSelectedPage();
            page.setSelectedProfile(fProfileNameCombo.getText());
            if (dialog.open() == Window.OK) {
                fProfiles.clear();
                fProfile = null;
                updateProfileData();
                if (page.getSelectedProfile() != null) {
                    int index = fProfileNameCombo.indexOf(page.getSelectedProfile());
                    fProfileNameCombo.select(index);
                }
                updateFromSourceField();
            }
        }
    });

    manageProfilesButton.setText(RemoteMessages.RemoteFetchLogWizardPage_ManageProfileLabel);

    Label nodesLabel = new Label(directoryContainerGroup, SWT.NONE);
    nodesLabel.setText(RemoteMessages.RemoteFetchLogWizardPage_NodesLabel);
    nodesLabel.setFont(parent.getFont());

    fNodesText = new Text(directoryContainerGroup, SWT.NONE);
    GridData gd_nodeText = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd_nodeText.horizontalSpan = 2;
    gd_nodeText.widthHint = 0;
    fNodesText.setLayoutData(gd_nodeText);
    fNodesText.setEditable(false);
    fNodesText.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            updateNodesText();
        }
    });

    updateProfileData();
    updateFromSourceField();

    fProfileNameCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            updateFromSourceField();
        }
    });

    setErrorMessage(null);
    setPageComplete(true);
}

From source file:org.eclipse.ui.dialogs.PropertyDialogAction.java

License:Open Source License

public void run() {

    PreferenceDialog dialog = createDialog();
    if (dialog != null) {
        dialog.open();
    }
}

From source file:org.eclipse.ui.internal.dialogs.cpd.ItemDetailToolTip.java

License:Open Source License

@Override
protected void addContent(Composite destination, Object modelElement) {
    final DisplayItem item = (DisplayItem) modelElement;

    // Show any relevant action set info
    if (showActionSet) {
        String text = null;// w ww  .  j a  v a 2s  .com
        Image image = null;

        if (CustomizePerspectiveDialog.isEffectivelyAvailable(item, filter)) {
            if (item.actionSet != null) {
                //give information on which command group the item is in

                final String actionSetName = item.getActionSet().descriptor.getLabel();

                text = NLS.bind(WorkbenchMessages.HideItems_itemInActionSet, actionSetName);
            }
        } else {
            //give feedback on why item is unavailable

            image = dialog.warningImageDescriptor.createImage();

            if (item.getChildren().isEmpty() && item.getActionSet() != null) {
                //i.e. is a leaf

                final String actionSetName = item.getActionSet().descriptor.getLabel();

                text = NLS.bind(WorkbenchMessages.HideItems_itemInUnavailableActionSet, actionSetName);

            } else if (item.getChildren().isEmpty() && item.getActionSet() == null
                    && item.getIContributionItem() instanceof HandledContributionItem) {
                text = WorkbenchMessages.HideItems_itemInUnavailableCommand;
            } else {
                //i.e. has children
                Set<ActionSet> actionGroup = new LinkedHashSet<>();
                ItemDetailToolTip.collectDescendantCommandGroups(actionGroup, item, filter);

                if (actionGroup.size() == 1) {
                    //i.e. only one child
                    ActionSet actionSet = actionGroup.iterator().next();
                    text = NLS.bind(WorkbenchMessages.HideItems_unavailableChildCommandGroup,
                            actionSet.descriptor.getId(), actionSet.descriptor.getLabel());
                } else {
                    //i.e. multiple children
                    String commandGroupList = null;

                    for (Iterator<ActionSet> i = actionGroup.iterator(); i.hasNext();) {
                        ActionSet actionSet = i.next();

                        // For each action set, make a link for it, set
                        // the href to its id
                        String commandGroupLink = MessageFormat.format("<a href=\"{0}\">{1}</a>", //$NON-NLS-1$
                                new Object[] { actionSet.descriptor.getId(), actionSet.descriptor.getLabel() });

                        if (commandGroupList == null) {
                            commandGroupList = commandGroupLink;
                        } else {
                            commandGroupList = Util.createList(commandGroupList, commandGroupLink);
                        }
                    }

                    commandGroupList = NLS.bind("{0}{1}", //$NON-NLS-1$
                            new Object[] { CustomizePerspectiveDialog.NEW_LINE, commandGroupList });
                    text = NLS.bind(WorkbenchMessages.HideItems_unavailableChildCommandGroups,
                            commandGroupList);
                }
            }
        }

        if (text != null) {
            Link link = createEntryWithLink(destination, image, text);
            link.addSelectionListener(new SelectionListener() {
                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    widgetSelected(e);
                }

                @Override
                public void widgetSelected(SelectionEvent e) {
                    ActionSet actionSet = dialog.idToActionSet.get(e.text);
                    if (actionSet == null) {
                        hide();
                        dialog.showActionSet(item);
                    } else {
                        hide();
                        dialog.showActionSet(actionSet);
                    }
                }
            });
        }
    }

    // Show key binding info
    if (showKeyBindings && CustomizePerspectiveDialog.getCommandID(item) != null) {
        // See if there is a command associated with the command id
        ICommandService commandService = (ICommandService) dialog.window.getService(ICommandService.class);
        Command command = commandService.getCommand(CustomizePerspectiveDialog.getCommandID(item));

        if (command != null && command.isDefined()) {
            // Find the bindings and list them as a string
            Binding[] bindings = ItemDetailToolTip.getKeyBindings(dialog.window, item);
            String keybindings = ItemDetailToolTip.keyBindingsAsString(bindings);

            String text = null;

            // Is it possible for this item to be visible?
            final boolean available = (item.getActionSet() == null) || (item.getActionSet().isActive());

            if (bindings.length > 0) {
                if (available) {
                    text = NLS.bind(WorkbenchMessages.HideItems_keyBindings, keybindings);
                } else {
                    text = NLS.bind(WorkbenchMessages.HideItems_keyBindingsActionSetUnavailable, keybindings);
                }
            } else {
                if (available) {
                    text = WorkbenchMessages.HideItems_noKeyBindings;
                } else {
                    text = WorkbenchMessages.HideItems_noKeyBindingsActionSetUnavailable;
                }
            }

            // Construct link to go to the preferences page for key
            // bindings
            final Object highlight;
            if (bindings.length == 0) {
                Map<String, String> parameters = new HashMap<>();

                // If item is a shortcut, need to add a parameter to go
                // to
                // the correct item
                if (item instanceof ShortcutItem) {
                    if (CustomizePerspectiveDialog.isNewWizard(item)) {
                        parameters.put(IWorkbenchCommandConstants.FILE_NEW_PARM_WIZARDID,
                                CustomizePerspectiveDialog.getParamID(item));
                    } else if (CustomizePerspectiveDialog.isShowPerspective(item)) {
                        parameters.put(IWorkbenchCommandConstants.PERSPECTIVES_SHOW_PERSPECTIVE_PARM_ID,
                                CustomizePerspectiveDialog.getParamID(item));
                    } else if (CustomizePerspectiveDialog.isShowView(item)) {
                        parameters.put(IWorkbenchCommandConstants.VIEWS_SHOW_VIEW_PARM_ID,
                                CustomizePerspectiveDialog.getParamID(item));
                    }
                }

                ParameterizedCommand pc = ParameterizedCommand.generateCommand(command, parameters);
                highlight = pc;
            } else {
                highlight = bindings[0];
            }

            Link bindingLink = createEntryWithLink(destination, null, text);

            bindingLink.addSelectionListener(new SelectionListener() {
                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                    widgetSelected(e);
                }

                @Override
                public void widgetSelected(SelectionEvent e) {
                    PreferenceDialog pdialog = PreferencesUtil.createPreferenceDialogOn(dialog.getShell(),
                            CustomizePerspectiveDialog.KEYS_PREFERENCE_PAGE_ID, new String[0], highlight);
                    hide();
                    pdialog.open();
                }
            });
        }
    }

    // Show dynamic menu item info
    if (item instanceof DynamicContributionItem) {
        DynamicContributionItem dynamic = ((DynamicContributionItem) item);
        StringBuffer text = new StringBuffer();
        final List<MenuItem> currentItems = dynamic.getCurrentItems();

        if (currentItems.size() > 0) {
            // Create a list of the currently displayed items
            text.append(WorkbenchMessages.HideItems_dynamicItemList);
            for (Iterator<MenuItem> i = currentItems.iterator(); i.hasNext();) {
                MenuItem menuItem = i.next();
                text.append(CustomizePerspectiveDialog.NEW_LINE).append("- ") //$NON-NLS-1$
                        .append(menuItem.getText());
            }
        } else {
            text.append(WorkbenchMessages.HideItems_dynamicItemEmptyList);
        }
        createEntry(destination, null, text.toString());
    }
}

From source file:org.eclipse.ui.internal.handlers.PropertyDialogHandler.java

License:Open Source License

public Object execute(ExecutionEvent event) throws ExecutionException {
    PreferenceDialog dialog;
    Object element = null;/*from  ww  w  .  ja  va2 s.c o m*/
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    Shell shell;

    if (currentSelection instanceof IStructuredSelection) {
        element = ((IStructuredSelection) currentSelection).getFirstElement();
    } else {
        return null;
    }

    if (activeWorkbenchWindow != null) {
        shell = activeWorkbenchWindow.getShell();
        dialog = PropertyDialog.createDialogOn(shell, initialPageId, element);
        if (dialog != null) {
            dialog.open();
        }
    }
    return null;
}

From source file:org.eclipse.ui.internal.handlers.ShowPreferencePageHandler.java

License:Open Source License

public final Object execute(final ExecutionEvent event) {
    final String preferencePageId = event
            .getParameter(IWorkbenchCommandConstants.WINDOW_PREFERENCES_PARM_PAGEID);
    final IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);

    final Shell shell;
    if (activeWorkbenchWindow == null) {
        shell = null;//from  w  ww. ja  va  2 s.  c  o m
    } else {
        shell = activeWorkbenchWindow.getShell();
    }

    final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, preferencePageId, null,
            null);
    dialog.open();

    return null;
}

From source file:org.eclipse.ui.internal.keys.GlobalKeyAssistDialog.java

License:Open Source License

/**
 * Opens the key binding preference page, closes this dialog
 *///from  w w w .java 2 s .c  om
private int openPreferencePage() {
    // Create a preference dialog on the keys preference page.

    Shell shell = getShell();
    if (shell.getParent() != null) {
        shell = shell.getParent().getShell();
    }

    PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, keysPageId, null,
            getSelectedBinding());
    close();
    return dialog.open();
}

From source file:org.eclipse.ui.internal.keys.KeyAssistDialog.java

License:Open Source License

/**
 * Edits the remembered selection in the preference dialog.
 *//* w  ww  .ja va2 s.c  o  m*/
private final void editKeyBinding() {
    // Create a preference dialog on the keys preference page.
    final String keysPageId = "org.eclipse.ui.preferencePages.Keys"; //$NON-NLS-1$
    final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), keysPageId, null,
            binding);

    /*
     * Forget the remembered state (so we don't get stuck editing
     * preferences).
     */
    clearRememberedState();

    // Open the dialog (blocking).
    dialog.open();
}