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.debug.internal.ui.views.memory.renderings.TableRenderingPrefAction.java

License:Open Source License

protected void showPreferencePage(String id, IPreferencePage page) {
    final IPreferenceNode targetNode = new PreferenceNode(id, page);

    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);//from  w  w w  .  j a v  a2  s . c  o  m
    final PreferenceDialog dialog = new PreferenceDialog(DebugUIPlugin.getShell(), 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:org.eclipse.debug.ui.StringVariableSelectionDialog.java

License:Open Source License

/**
 * Shows the string variables preference page and returns <code>true</code> if OK was pressed.
 * /*ww w  . j  a v a  2  s . c  om*/
 * @return whether OK was pressed
 */
private boolean showVariablesPage() {
    StringVariablePreferencePage page = new StringVariablePreferencePage();
    page.setTitle(StringSubstitutionMessages.StringVariableSelectionDialog_1);
    final IPreferenceNode targetNode = new PreferenceNode("org.eclipse.debug.ui.StringVariablePreferencePage", //$NON-NLS-1$
            page);
    PreferenceManager manager = new PreferenceManager();
    manager.addToRoot(targetNode);
    final PreferenceDialog dialog = new PreferenceDialog(DebugUIPlugin.getShell(), 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);
        }
    });
    return result[0];
}

From source file:org.eclipse.dltk.debug.ui.DLTKDebugUIPlugin.java

License:Open Source License

/**
 * Displays the given preference page.// www .ja  v  a  2s. c o m
 * 
 * @param id
 *            pref page id
 * @param page
 *            pref page
 */
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(DLTKDebugUIPlugin.getActiveWorkbenchShell(), manager);
    final boolean[] result = new boolean[] { false };
    BusyIndicator.showWhile(DLTKDebugUIPlugin.getStandardDisplay(), new Runnable() {
        public void run() {
            dialog.create();
            dialog.setMessage(targetNode.getLabelText());
            result[0] = (dialog.open() == Window.OK);
        }
    });
}

From source file:org.eclipse.dltk.internal.debug.ui.handlers.AbstractOpenPreferencePageStatusHandler.java

License:Open Source License

protected void showPreferencePage(String pageId) {
    final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, pageId, null, null);
    dialog.open();
}

From source file:org.eclipse.dltk.internal.ui.wizards.buildpath.newsourcepage.ConfigureBuildPathAction.java

License:Open Source License

public void run() {
    if (fProject != null) {
        // TODO retrieve the page id via project nature
        PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(getShell(), fProject, null, null,
                null);//from  w ww  . jav a2  s . c om
        // search for the language specific page
        final List elements = dialog.getPreferenceManager().getElements(PreferenceManager.PRE_ORDER);
        for (Iterator i = elements.iterator(); i.hasNext();) {
            final IPreferenceNode node = (IPreferenceNode) i.next();
            final String nodeId = node.getId();
            if (nodeId.endsWith("BuildpathProperties")) { //$NON-NLS-1$
                // recreate dialog and select page found
                dialog.close();
                dialog = PreferencesUtil.createPropertyDialogOn(getShell(), fProject, nodeId, null, null);
                break;
            }
        }
        dialog.open();
    }
}

From source file:org.eclipse.dltk.tcl.internal.console.ui.TclConsoleFactory.java

License:Open Source License

protected void showInterpreterPreferencePage(String natureId) {
    String preferencePageId = null;
    IDLTKUILanguageToolkit languageToolkit = null;
    languageToolkit = DLTKUILanguageManager.getLanguageToolkit(natureId);
    if (languageToolkit == null) {
        return;//from w ww .j  a va2s .com
    }
    preferencePageId = languageToolkit.getInterpreterPreferencePage();

    if (preferencePageId != null) {
        PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(null, preferencePageId, null, null);
        dialog.open();
    }
}

From source file:org.eclipse.dltk.ui.wizards.NewSourceModulePage.java

License:Open Source License

protected void createTemplateControls(Composite parent, int nColumns) {
    fTemplateDialogField.doFillIntoGrid(parent, nColumns - 1);
    LayoutUtil.setWidthHint(fTemplateDialogField.getComboControl(null), getMaxFieldWidth());
    final Button configureTemplates = new Button(parent, SWT.PUSH);
    GridData configureData = new GridData(SWT.FILL, SWT.NONE, false, false);
    configureData.widthHint = SWTUtil.getButtonWidthHint(configureTemplates);
    configureTemplates.setLayoutData(configureData);
    configureTemplates.setText(Messages.NewSourceModulePage_ConfigureTemplates);
    configureTemplates.addSelectionListener(new SelectionAdapter() {
        @Override//from   w w  w.  ja  va2s  .co  m
        public void widgetSelected(SelectionEvent e) {
            String templateName = null;
            final Template template = getSelectedTemplate();
            if (template != null) {
                templateName = template.getName();
            }
            Map<String, Object> data = null;
            if (templateName != null) {
                data = new HashMap<String, Object>();
                data.put(CodeTemplatesPreferencePage.DATA_SELECT_TEMPLATE, templateName);
            }
            // TODO handle project specific preferences if any?
            final String prefPageId = getTemplateArea().getTemplatePreferencePageId();
            final PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), prefPageId,
                    new String[] { prefPageId }, data);
            if (dialog.open() == Window.OK) {
                updateTemplates();
            }
        }
    });
}

From source file:org.eclipse.edt.ide.internal.sql.util.RDBConnectionUtility.java

License:Open Source License

public static IStatus connectWithPromptIfNeeded(IConnectionProfile profile, boolean reprompt) {
    String profileName = profile.getName();

    Shell shell = Display.getCurrent().getActiveShell();
    IStatus connectionStatus = null;/*from  ww w  . j a v a2  s.com*/
    ConnectionInfo info = null;
    if (profile != null) {
        if (shell == null) {
            connectionStatus = profile.connect();
        } else {
            connectionStatus = profile.connectWithoutJob();
            if (reprompt && profile.getConnectionState() != IConnectionProfile.CONNECTED_STATE
                    && connectionStatus.getCode() != IStatus.OK) // could be marked OK if the profile can't be found for some reason
            {
                String title = NLS.bind(SQLNlsStrings.SQL_CONNECTION_FAILURE_MSG, profile.getName());
                MessageDialog.openInformation(shell, title,
                        connectionStatus.getChildren()[0].getException().getLocalizedMessage());

                // Prompt to fix properties
                PropertyDialogAction propertyDialogAction = new PropertyDialogAction(
                        new SameShellProvider(shell), new ConnectionPropertiesWizardSelectionProvider(profile));

                StructuredSelection selection = new StructuredSelection(profile);
                propertyDialogAction.selectionChanged(selection);
                if (!profile.arePropertiesComplete() && propertyDialogAction.isApplicableForSelection()) {
                    //something in createDialog is failing to initialize the properties correctly the first time 
                    //around. I can't debug it because it crashes the debugger when I set a breakpoint, so I'll 
                    //call twice for now to get the initialization to happen until I figure it out.
                    PreferenceDialog dialog = propertyDialogAction.createDialog();
                    dialog = propertyDialogAction.createDialog();
                    String shellText = NLS.bind(SQLNlsStrings.SQL_CONNECTION_PROPERTIES_FOR, profile.getName());
                    dialog.getShell().setText(shellText);
                    IConnectionProfileProvider provider = profile.getProvider();
                    IPropertiesPersistenceHook hook = ((ConnectionProfileProvider) provider)
                            .getPropertiesPersistenceHook();
                    String initialPage = hook.getConnectionPropertiesPageID();
                    if (initialPage != null) {
                        ((IWorkbenchPreferenceContainer) dialog).openPage(initialPage, null);
                    }
                    if (dialog.open() == Dialog.CANCEL) {
                        reprompt = false;
                    }
                }
                if (reprompt) {
                    connectionStatus = profile.connectWithoutJob();
                }
            }
        }
    }

    return connectionStatus;
}

From source file:org.eclipse.egit.ui.internal.dialogs.CommitDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    parent.getShell().setText(UIText.CommitDialog_CommitChanges);

    GridLayout layout = new GridLayout(2, false);
    container.setLayout(layout);//  w w w  .  jav  a 2 s  .  c  o  m

    Label label = new Label(container, SWT.LEFT);
    label.setText(UIText.CommitDialog_CommitMessage);
    label.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, false).create());

    commitText = new SpellcheckableMessageArea(container, commitMessage);
    Point size = commitText.getTextWidget().getSize();
    int minHeight = commitText.getTextWidget().getLineHeight() * 3;
    commitText.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, true).hint(size)
            .minSize(size.x, minHeight).align(SWT.FILL, SWT.FILL).create());
    commitText.setText(commitMessage);

    // allow to commit with ctrl-enter
    commitText.getTextWidget().addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.CR && (event.stateMask & SWT.CONTROL) > 0) {
                okPressed();
            } else if (event.keyCode == SWT.TAB && (event.stateMask & SWT.SHIFT) == 0) {
                event.doit = false;
                commitText.traverse(SWT.TRAVERSE_TAB_NEXT);
            }
        }
    });

    new Label(container, SWT.LEFT).setText(UIText.CommitDialog_Author);
    authorText = new Text(container, SWT.BORDER);
    authorText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (author != null)
        authorText.setText(author);

    authorHandler = UIUtils.addPreviousValuesContentProposalToText(authorText, AUTHOR_VALUES_PREF);
    new Label(container, SWT.LEFT).setText(UIText.CommitDialog_Committer);
    committerText = new Text(container, SWT.BORDER);
    committerText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    if (committer != null)
        committerText.setText(committer);
    committerText.addModifyListener(new ModifyListener() {
        String oldCommitter = committerText.getText();

        public void modifyText(ModifyEvent e) {
            if (signedOffButton.getSelection()) {
                // the commit message is signed
                // the signature must be updated
                String newCommitter = committerText.getText();
                String oldSignOff = getSignedOff(oldCommitter);
                String newSignOff = getSignedOff(newCommitter);
                commitText.setText(replaceSignOff(commitText.getText(), oldSignOff, newSignOff));
                oldCommitter = newCommitter;
            }
        }
    });

    committerHandler = UIUtils.addPreviousValuesContentProposalToText(committerText, COMMITTER_VALUES_PREF);

    Link preferencesLink = new Link(container, SWT.NONE);
    preferencesLink.setText(UIText.CommitDialog_ConfigureLink);
    preferencesLink.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            String preferencePageId = "org.eclipse.egit.ui.internal.preferences.CommitDialogPreferencePage"; //$NON-NLS-1$
            PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), preferencePageId,
                    new String[] { preferencePageId }, null);
            dialog.open();
            commitText.reconfigure();
        }
    });

    amendingButton = new Button(container, SWT.CHECK);
    if (amending) {
        amendingButton.setSelection(amending);
        amendingButton.setEnabled(false); // if already set, don't allow any changes
        commitText.setText(previousCommitMessage);
        authorText.setText(previousAuthor);
        saveOriginalChangeId();
    } else if (!amendAllowed) {
        amendingButton.setEnabled(false);
        originalChangeId = null;
    }
    amendingButton.addSelectionListener(new SelectionListener() {
        boolean alreadyAdded = false;

        public void widgetSelected(SelectionEvent arg0) {
            if (!amendingButton.getSelection()) {
                originalChangeId = null;
                authorText.setText(author);
            } else {
                saveOriginalChangeId();
                if (!alreadyAdded) {
                    alreadyAdded = true;
                    String curText = commitText.getText();
                    if (curText.length() > 0)
                        curText += Text.DELIMITER;
                    commitText.setText(curText + previousCommitMessage.replaceAll("\n", Text.DELIMITER)); //$NON-NLS-1$
                }
                authorText.setText(previousAuthor);
            }
            refreshChangeIdText();
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
            // Empty
        }
    });

    amendingButton.setText(UIText.CommitDialog_AmendPreviousCommit);
    amendingButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    signedOffButton = new Button(container, SWT.CHECK);
    signedOffButton.setSelection(signedOff);
    signedOffButton.setText(UIText.CommitDialog_AddSOB);
    signedOffButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    signedOffButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent arg0) {
            String curText = commitText.getText();
            if (signedOffButton.getSelection()) {
                // add signed off line
                commitText.setText(signOff(curText));
            } else {
                // remove signed off line
                curText = replaceSignOff(curText, getSignedOff(), ""); //$NON-NLS-1$
                if (curText.endsWith(Text.DELIMITER + Text.DELIMITER))
                    curText = curText.substring(0, curText.length() - Text.DELIMITER.length());
                commitText.setText(curText);
            }
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
            // Empty
        }
    });

    changeIdButton = new Button(container, SWT.CHECK);
    changeIdButton.setText(UIText.CommitDialog_AddChangeIdLabel);
    changeIdButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());
    changeIdButton.setToolTipText(UIText.CommitDialog_AddChangeIdTooltip);
    changeIdButton.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            refreshChangeIdText();
        }

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

    showUntrackedButton = new Button(container, SWT.CHECK);
    showUntrackedButton.setText(UIText.CommitDialog_ShowUntrackedFiles);
    showUntrackedButton.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).span(2, 1).create());

    IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
    if (settings.get(SHOW_UNTRACKED_PREF) != null) {
        showUntracked = Boolean.valueOf(settings.get(SHOW_UNTRACKED_PREF)).booleanValue();
    }

    showUntrackedButton.setSelection(showUntracked);

    showUntrackedButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            showUntracked = showUntrackedButton.getSelection();
            filesViewer.refresh(true);
        }

    });

    commitText.getTextWidget().addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            updateSignedOffButton();
            updateChangeIdButton();
        }
    });
    updateSignedOffButton();
    updateChangeIdButton();

    Table resourcesTable = new Table(container,
            SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.CHECK | SWT.BORDER);
    resourcesTable
            .setLayoutData(GridDataFactory.fillDefaults().hint(600, 200).span(2, 1).grab(true, true).create());

    resourcesTable.addSelectionListener(new CommitItemSelectionListener());

    resourcesTable.setHeaderVisible(true);
    TableColumn statCol = new TableColumn(resourcesTable, SWT.LEFT);
    statCol.setText(UIText.CommitDialog_Status);
    statCol.setWidth(150);
    statCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByStatus));

    TableColumn resourceCol = new TableColumn(resourcesTable, SWT.LEFT);
    resourceCol.setText(UIText.CommitDialog_File);
    resourceCol.setWidth(415);
    resourceCol.addSelectionListener(new HeaderSelectionListener(CommitItem.Order.ByFile));

    filesViewer = new CheckboxTableViewer(resourcesTable);
    filesViewer.setContentProvider(ArrayContentProvider.getInstance());
    filesViewer.setLabelProvider(new CommitLabelProvider());
    filesViewer.addFilter(new CommitItemFilter());
    filesViewer.setInput(items);
    filesViewer.getTable().setMenu(getContextMenu());
    if (!allowToChangeSelection) {
        amendingButton.setSelection(false);
        amendingButton.setEnabled(false);
        showUntrackedButton.setSelection(false);
        showUntrackedButton.setEnabled(false);

        filesViewer.addCheckStateListener(new ICheckStateListener() {

            public void checkStateChanged(CheckStateChangedEvent event) {
                if (!event.getChecked()) {
                    filesViewer.setAllChecked(true);
                }
            }
        });
        filesViewer.setAllGrayed(true);
        filesViewer.setAllChecked(true);
    } else {
        // pre-emptively check any preselected files
        for (IFile selectedFile : preselectedFiles) {
            for (CommitItem item : items) {
                if (item.file.equals(selectedFile) && !item.status.equals(UIText.CommitDialog_StatusUntracked)
                        && !item.status.equals(UIText.CommitDialog_StatusAssumeUnchaged)) {
                    filesViewer.setChecked(item, true);
                    break;
                }
            }
        }
    }

    applyDialogFont(container);
    container.pack();
    return container;
}

From source file:org.eclipse.elk.alg.graphviz.layouter.GraphvizTool.java

License:Open Source License

/**
 * Handle missing path to the dot executable. The Graphviz preference page
 * is opened so the user can enter the correct path. The method returns
 * after the preference page has been closed.
 * //from   www .  j a  v  a  2 s . c o m
 * @return true if the user has selected "Ok" in the shown dialog, false otherwise
 */
private static boolean handleExecPath() {
    try {
        final Display display = PlatformUI.getWorkbench().getDisplay();
        final Maybe<Integer> dialogResult = Maybe.create();
        display.syncExec(new Runnable() {
            public void run() {
                PreferenceDialog preferenceDialog = PreferencesUtil.createPreferenceDialogOn(
                        display.getActiveShell(), GraphvizPreferencePage.ID, new String[] {}, null);
                dialogResult.set(preferenceDialog.open());
            }
        });
        return dialogResult.get() == PreferenceDialog.OK;
    } catch (NoClassDefFoundError e) {
        // silent
    }
    return false;
}