Search in sources :

Example 51 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.

the class WebBrowserPreferencePage method createContents.

/**
 * Create the preference options.
 *
 * @param parent
 *            org.eclipse.swt.widgets.Composite
 * @return org.eclipse.swt.widgets.Control
 */
@Override
protected Control createContents(Composite parent) {
    initializeDialogUnits(parent);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ContextIds.PREF_BROWSER);
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
    layout.verticalSpacing = convertVerticalDLUsToPixels(3);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    composite.setLayoutData(data);
    Label label = new Label(composite, SWT.WRAP);
    label.setText(Messages.preferenceWebBrowserDescription);
    data = new GridData(SWT.FILL, SWT.NONE, false, false);
    data.horizontalSpan = 2;
    data.widthHint = 275;
    label.setLayoutData(data);
    internal = new Button(composite, SWT.RADIO);
    internal.setText(Messages.prefInternalBrowser);
    data = new GridData(SWT.FILL, SWT.NONE, true, false);
    data.horizontalSpan = 2;
    internal.setLayoutData(data);
    if (!WebBrowserUtil.canUseInternalWebBrowser())
        internal.setEnabled(false);
    external = new Button(composite, SWT.RADIO);
    external.setText(Messages.prefExternalBrowser);
    data = new GridData(SWT.FILL, SWT.NONE, true, false);
    data.horizontalSpan = 2;
    external.setLayoutData(data);
    label = new Label(composite, SWT.NONE);
    label.setText(Messages.browserList);
    data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    data = new GridData(SWT.FILL, SWT.FILL, true, true);
    table.setLayoutData(data);
    table.setHeaderVisible(false);
    table.setLinesVisible(false);
    TableLayout tableLayout = new TableLayout();
    new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnWeightData(100));
    table.setLayout(tableLayout);
    tableViewer = new CheckboxTableViewer(table);
    tableViewer.setContentProvider(new BrowserTableContentProvider());
    tableViewer.setLabelProvider(new BrowserTableLabelProvider());
    tableViewer.setInput(BrowserManager.getInstance());
    // uncheck any other elements that might be checked and leave only the
    // element checked to remain checked since one can only chose one
    // brower at a time to be current.
    tableViewer.addCheckStateListener(e -> {
        checkNewDefaultBrowser(e.getElement());
        checkedBrowser = (IBrowserDescriptor) e.getElement();
        // if no other browsers are checked, don't allow the single one
        // currently checked to become unchecked, and lose a current
        // browser. That is, don't permit unchecking if no other item
        // is checked which is supposed to be the case.
        Object[] obj = tableViewer.getCheckedElements();
        if (obj.length == 0)
            tableViewer.setChecked(e.getElement(), true);
    });
    // set a default, checked browser based on the current browser. If there
    // is not a current browser, but the first item exists, use that instead.
    // This will work currently until workbench shutdown, because current
    // browser is not yet persisted.
    checkedBrowser = BrowserManager.getInstance().getCurrentWebBrowser();
    if (checkedBrowser != null)
        tableViewer.setChecked(checkedBrowser, true);
    else {
        Object obj = tableViewer.getElementAt(0);
        if (obj != null)
            tableViewer.setChecked(obj, true);
    }
    tableViewer.addSelectionChangedListener(event -> {
        IStructuredSelection sele = tableViewer.getStructuredSelection();
        boolean sel = sele.getFirstElement() != null && !(sele.getFirstElement() instanceof SystemBrowserDescriptor);
        remove.setEnabled(sel);
        edit.setEnabled(sel);
    });
    tableViewer.addDoubleClickListener(event -> {
        IStructuredSelection sel = tableViewer.getStructuredSelection();
        Object firstElem = sel.getFirstElement();
        if (firstElem != null && !(firstElem instanceof SystemBrowserDescriptor)) {
            IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
            IBrowserDescriptorWorkingCopy wc = browser2.getWorkingCopy();
            BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell(), wc);
            if (dialog.open() != Window.CANCEL) {
                try {
                    tableViewer.refresh(wc.save());
                } catch (Exception ex) {
                // ignore
                }
            }
        }
    });
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.character == SWT.DEL) {
                IStructuredSelection sel = tableViewer.getStructuredSelection();
                if (sel.getFirstElement() != null) {
                    IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
                    try {
                        browser2.delete();
                        tableViewer.remove(browser2);
                        // need here to ensure that if the item deleted was
                        // checked, ie. was
                        // the current browser, that the new current browser
                        // will be the first in the
                        // list, typically, the internal browser, which
                        // cannot be
                        // deleted, and be current
                        BrowserManager manager = BrowserManager.getInstance();
                        if (browser2 == checkedBrowser) {
                            if (manager.browsers.size() > 0) {
                                checkedBrowser = manager.browsers.get(0);
                                tableViewer.setChecked(checkedBrowser, true);
                            }
                        }
                    } catch (Exception ex) {
                    // ignore
                    }
                }
            }
        }
    });
    Composite buttonComp = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = convertVerticalDLUsToPixels(3);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 1;
    buttonComp.setLayout(layout);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    buttonComp.setLayoutData(data);
    final Button add = SWTUtil.createButton(buttonComp, Messages.add);
    add.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell());
        if (dialog.open() == Window.CANCEL)
            return;
        tableViewer.refresh();
        if (checkedBrowser != null)
            tableViewer.setChecked(checkedBrowser, true);
    }));
    edit = SWTUtil.createButton(buttonComp, Messages.edit);
    edit.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        IStructuredSelection sel = tableViewer.getStructuredSelection();
        IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
        IBrowserDescriptorWorkingCopy wc = browser2.getWorkingCopy();
        BrowserDescriptorDialog dialog = new BrowserDescriptorDialog(getShell(), wc);
        if (dialog.open() != Window.CANCEL) {
            try {
                tableViewer.refresh(wc.save());
            } catch (Exception ex) {
            // ignore
            }
        }
    }));
    remove = SWTUtil.createButton(buttonComp, Messages.remove);
    remove.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        IStructuredSelection sel = tableViewer.getStructuredSelection();
        IBrowserDescriptor browser2 = (IBrowserDescriptor) sel.getFirstElement();
        try {
            browser2.delete();
            tableViewer.remove(browser2);
            // need here to ensure that if the item deleted was checked,
            // ie. was the current browser, that the new current browser
            // will be
            // the first in the list, typically, the internal browser, which
            // cannot be
            // deleted, and be current
            BrowserManager manager = BrowserManager.getInstance();
            if (browser2 == checkedBrowser) {
                if (manager.browsers.size() > 0) {
                    checkedBrowser = manager.browsers.get(0);
                    tableViewer.setChecked(checkedBrowser, true);
                }
            }
        } catch (Exception ex) {
        // ignore
        }
    }));
    search = SWTUtil.createButton(buttonComp, Messages.search);
    data = (GridData) search.getLayoutData();
    data.verticalIndent = 9;
    search.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        final List<IBrowserDescriptorWorkingCopy> foundBrowsers = new ArrayList<>();
        final List<String> existingPaths = WebBrowserUtil.getExternalBrowserPaths();
        // select a target directory for the search
        DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SHEET);
        dialog.setMessage(Messages.selectDirectory);
        dialog.setText(Messages.directoryDialogTitle);
        String path = dialog.open();
        if (path == null)
            return;
        final File rootDir = new File(path);
        ProgressMonitorDialog pm = new ProgressMonitorDialog(getShell());
        IRunnableWithProgress r = monitor -> {
            monitor.beginTask(Messages.searchingTaskName, IProgressMonitor.UNKNOWN);
            search(rootDir, existingPaths, foundBrowsers, new HashSet<>(), monitor);
            monitor.done();
        };
        try {
            pm.run(true, true, r);
        } catch (InvocationTargetException ex) {
            Trace.trace(Trace.SEVERE, // $NON-NLS-1$
            "Invocation Exception occured running monitor: " + ex);
        } catch (InterruptedException ex) {
            Trace.trace(Trace.SEVERE, // $NON-NLS-1$
            "Interrupted exception occured running monitor: " + ex);
            return;
        }
        if (pm.getProgressMonitor().isCanceled())
            return;
        List<IBrowserDescriptorWorkingCopy> browsersToCreate = foundBrowsers;
        if (browsersToCreate.isEmpty()) {
            // no browsers found
            WebBrowserUtil.openMessage(Messages.searchingNoneFound);
            return;
        }
        Iterator<IBrowserDescriptorWorkingCopy> iterator = browsersToCreate.iterator();
        while (iterator.hasNext()) {
            IBrowserDescriptorWorkingCopy browser2 = iterator.next();
            browser2.save();
        }
        tableViewer.refresh();
        if (checkedBrowser != null)
            tableViewer.setChecked(checkedBrowser, true);
    }));
    restore = SWTUtil.createButton(buttonComp, Messages.restore);
    data = (GridData) restore.getLayoutData();
    data.verticalIndent = 9;
    restore.addSelectionListener(widgetSelectedAdapter(e -> addDefaults()));
    tableViewer.addCheckStateListener(e -> {
        checkNewDefaultBrowser(e.getElement());
        checkedBrowser = (IBrowserDescriptor) e.getElement();
    });
    internal.setSelection(WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.INTERNAL);
    external.setSelection(WebBrowserPreference.getBrowserChoice() == WebBrowserPreference.EXTERNAL);
    // boolean sel = !tableViewer.getSelection().isEmpty();
    IStructuredSelection sele = tableViewer.getStructuredSelection();
    boolean sel = sele.getFirstElement() != null && !(sele.getFirstElement() instanceof SystemBrowserDescriptor);
    edit.setEnabled(sel);
    remove.setEnabled(sel);
    Dialog.applyDialogFont(composite);
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn) Image(org.eclipse.swt.graphics.Image) Table(org.eclipse.swt.widgets.Table) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) TableLayout(org.eclipse.jface.viewers.TableLayout) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) GridData(org.eclipse.swt.layout.GridData) KeyAdapter(org.eclipse.swt.events.KeyAdapter) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) TableItem(org.eclipse.swt.widgets.TableItem) Iterator(java.util.Iterator) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IWorkbenchPreferencePage(org.eclipse.ui.IWorkbenchPreferencePage) Set(java.util.Set) IOException(java.io.IOException) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PreferencePage(org.eclipse.jface.preference.PreferencePage) List(java.util.List) Window(org.eclipse.jface.window.Window) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) Dialog(org.eclipse.jface.dialogs.Dialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) ISelection(org.eclipse.jface.viewers.ISelection) IWorkbench(org.eclipse.ui.IWorkbench) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TableLayout(org.eclipse.jface.viewers.TableLayout) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) TableColumn(org.eclipse.swt.widgets.TableColumn) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) GridData(org.eclipse.swt.layout.GridData) File(java.io.File)

Example 52 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.

the class ChooseWorkspaceDialog method createRecentWorkspacesComposite.

/**
 * The Recent Workspaces area of the dialog is only shown if Recent
 * Workspaces are defined. It provides a faster way to launch a specific
 * Workspace
 */
private void createRecentWorkspacesComposite(final Composite composite) {
    FormToolkit toolkit = new FormToolkit(composite.getDisplay());
    composite.addDisposeListener(c -> toolkit.dispose());
    recentWorkspacesForm = toolkit.createForm(composite);
    recentWorkspacesForm.setBackground(composite.getBackground());
    recentWorkspacesForm.getBody().setLayout(new GridLayout());
    ExpandableComposite recentWorkspacesExpandable = toolkit.createExpandableComposite(recentWorkspacesForm.getBody(), ExpandableComposite.TWISTIE);
    recentWorkspacesForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    recentWorkspacesExpandable.setBackground(composite.getBackground());
    recentWorkspacesExpandable.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_recentWorkspaces);
    recentWorkspacesExpandable.setExpanded(launchData.isShowRecentWorkspaces());
    recentWorkspacesExpandable.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(ExpansionEvent e) {
            launchData.setShowRecentWorkspaces(((ExpandableComposite) e.getSource()).isExpanded());
            Point size = getInitialSize();
            Shell shell = getShell();
            shell.setBounds(getConstrainedShellBounds(new Rectangle(shell.getLocation().x, shell.getLocation().y, size.x, size.y)));
        }
    });
    Composite panel = new Composite(recentWorkspacesExpandable, SWT.NONE);
    recentWorkspacesExpandable.setClient(panel);
    RowLayout layout = new RowLayout(SWT.VERTICAL);
    layout.marginLeft = 14;
    layout.spacing = 6;
    panel.setLayout(layout);
    recentWorkspacesLinks = new HashMap<>(launchData.getRecentWorkspaces().length);
    Map<String, String> uniqueWorkspaceNames = createUniqueWorkspaceNameMap();
    List<String> recentWorkspacesList = Arrays.asList(launchData.getRecentWorkspaces()).stream().filter(s -> s != null && !s.isEmpty()).collect(Collectors.toList());
    List<Entry<String, String>> sortedList = uniqueWorkspaceNames.entrySet().stream().sorted((e1, e2) -> Integer.compare(recentWorkspacesList.indexOf(e1.getValue()), recentWorkspacesList.indexOf(e2.getValue()))).collect(Collectors.toList());
    for (Entry<String, String> uniqueWorkspaceEntry : sortedList) {
        final String recentWorkspace = uniqueWorkspaceEntry.getValue();
        Link link = new Link(panel, SWT.WRAP);
        link.setLayoutData(new RowData(SWT.DEFAULT, SWT.DEFAULT));
        // $NON-NLS-1$ //$NON-NLS-2$
        link.setText("<a>" + uniqueWorkspaceEntry.getKey() + "</a>");
        link.setToolTipText(recentWorkspace);
        link.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                workspaceSelected(recentWorkspace);
            }
        });
        recentWorkspacesLinks.put(recentWorkspace, link);
        Menu menu = new Menu(link);
        MenuItem forgetItem = new MenuItem(menu, SWT.PUSH);
        forgetItem.setText(IDEWorkbenchMessages.ChooseWorkspaceDialog_removeWorkspaceSelection);
        forgetItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                removeWorkspaceFromLauncher(recentWorkspace);
            }
        });
        link.setMenu(menu);
    }
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Arrays(java.util.Arrays) TextProcessor(org.eclipse.osgi.util.TextProcessor) Rectangle(org.eclipse.swt.graphics.Rectangle) HashMap(java.util.HashMap) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Function(java.util.function.Function) Point(org.eclipse.swt.graphics.Point) ArrayList(java.util.ArrayList) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) GridData(org.eclipse.swt.layout.GridData) Geometry(org.eclipse.jface.util.Geometry) RowData(org.eclipse.swt.layout.RowData) Link(org.eclipse.swt.widgets.Link) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) Monitor(org.eclipse.swt.widgets.Monitor) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Collectors(java.util.stream.Collectors) File(java.io.File) Form(org.eclipse.ui.forms.widgets.Form) List(java.util.List) Window(org.eclipse.jface.window.Window) RowLayout(org.eclipse.swt.layout.RowLayout) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) TitleAreaDialog(org.eclipse.jface.dialogs.TitleAreaDialog) MenuItem(org.eclipse.swt.widgets.MenuItem) Dialog(org.eclipse.jface.dialogs.Dialog) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Entry(java.util.Map.Entry) IProduct(org.eclipse.core.runtime.IProduct) Platform(org.eclipse.core.runtime.Platform) Pattern(java.util.regex.Pattern) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) FrameworkUtil(org.osgi.framework.FrameworkUtil) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayout(org.eclipse.swt.layout.GridLayout) Shell(org.eclipse.swt.widgets.Shell) Entry(java.util.Map.Entry) RowData(org.eclipse.swt.layout.RowData) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) Link(org.eclipse.swt.widgets.Link)

Example 53 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.

the class EditorSelectionDialog method createDialogArea.

/**
 * Creates and returns the contents of the upper part of the dialog (above the
 * button bar).
 *
 * Subclasses should overide.
 *
 * @param parent the parent composite to contain the dialog area
 * @return the dialog area control
 */
@Override
protected Control createDialogArea(Composite parent) {
    Font font = parent.getFont();
    // create main group
    Composite contents = (Composite) super.createDialogArea(parent);
    ((GridLayout) contents.getLayout()).numColumns = 2;
    // begin the layout
    Label textLabel = new Label(contents, SWT.WRAP);
    textLabel.setText(message);
    GridData data = new GridData();
    data.horizontalSpan = 2;
    data.horizontalAlignment = SWT.FILL;
    data.widthHint = TABLE_WIDTH;
    textLabel.setLayoutData(data);
    textLabel.setFont(font);
    Composite group = new Composite(contents, SWT.SHADOW_NONE);
    data = new GridData();
    data.grabExcessHorizontalSpace = true;
    data.horizontalAlignment = SWT.FILL;
    data.horizontalSpan = 2;
    group.setLayout(new RowLayout(SWT.HORIZONTAL));
    group.setLayoutData(data);
    internalButton = new Button(group, SWT.RADIO | SWT.LEFT);
    internalButton.setText(WorkbenchMessages.EditorSelection_internal);
    internalButton.addListener(SWT.Selection, listener);
    internalButton.setFont(font);
    externalButton = new Button(group, SWT.RADIO | SWT.LEFT);
    externalButton.setText(WorkbenchMessages.EditorSelection_external);
    externalButton.addListener(SWT.Selection, listener);
    externalButton.setFont(font);
    editorTable = new FilteredTree(contents, SWT.SINGLE | SWT.BORDER, new PatternFilter(), true);
    editorTableViewer = editorTable.getViewer();
    Tree tree = editorTableViewer.getTree();
    tree.addListener(SWT.Selection, listener);
    tree.addListener(SWT.DefaultSelection, listener);
    tree.addListener(SWT.MouseDoubleClick, listener);
    data = new GridData();
    data.widthHint = convertHorizontalDLUsToPixels(TABLE_WIDTH);
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.verticalAlignment = GridData.FILL;
    data.grabExcessVerticalSpace = true;
    data.horizontalSpan = 2;
    editorTable.setLayoutData(data);
    editorTable.setFont(font);
    data.heightHint = tree.getItemHeight() * 12;
    editorTableViewer.setContentProvider(new TreeArrayContentProvider());
    editorTableViewer.setLabelProvider(createTextImageProvider(element -> {
        IEditorDescriptor d = (IEditorDescriptor) element;
        // $NON-NLS-1$
        return TextProcessor.process(d.getLabel(), ".");
    }, element -> {
        IEditorDescriptor d = (IEditorDescriptor) element;
        return (Image) resourceManager.get(d.getImageDescriptor());
    }));
    browseExternalEditorsButton = new Button(contents, SWT.PUSH);
    browseExternalEditorsButton.setText(WorkbenchMessages.EditorSelection_browse);
    browseExternalEditorsButton.addListener(SWT.Selection, listener);
    data = new GridData();
    int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
    data.widthHint = Math.max(widthHint, browseExternalEditorsButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
    data.horizontalSpan = 2;
    browseExternalEditorsButton.setLayoutData(data);
    browseExternalEditorsButton.setFont(font);
    if (fileName != null) {
        rememberEditorButton = new Button(contents, SWT.CHECK | SWT.LEFT);
        rememberEditorButton.setText(NLS.bind(WorkbenchMessages.EditorSelection_rememberEditor, fileName));
        rememberEditorButton.addListener(SWT.Selection, listener);
        data = new GridData();
        data.horizontalSpan = 2;
        rememberEditorButton.setLayoutData(data);
        rememberEditorButton.setFont(font);
        String fileType = getFileType();
        if (!fileType.isEmpty()) {
            rememberTypeButton = new Button(contents, SWT.CHECK | SWT.LEFT);
            rememberTypeButton.setText(NLS.bind(WorkbenchMessages.EditorSelection_rememberType, fileType));
            rememberTypeButton.addListener(SWT.Selection, listener);
            data = new GridData();
            data.horizontalSpan = 2;
            rememberTypeButton.setLayoutData(data);
            rememberTypeButton.setFont(font);
        }
    }
    initializeSuggestion();
    // Place buttons to the appropriate state
    restoreWidgetValues();
    // Run async to restore selection on *visible* dialog - otherwise three won't
    // scroll
    PlatformUI.getWorkbench().getDisplay().asyncExec(() -> {
        if (editorTable.isDisposed()) {
            return;
        }
        fillEditorTable();
        updateEnableState();
    });
    return contents;
}
Also used : Arrays(java.util.Arrays) WorkbenchPlugin(org.eclipse.ui.internal.WorkbenchPlugin) TextProcessor(org.eclipse.osgi.util.TextProcessor) ResourceManager(org.eclipse.jface.resource.ResourceManager) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Program(org.eclipse.swt.program.Program) IStatus(org.eclipse.core.runtime.IStatus) EditorDescriptor(org.eclipse.ui.internal.registry.EditorDescriptor) Composite(org.eclipse.swt.widgets.Composite) IProgressService(org.eclipse.ui.progress.IProgressService) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) StatusManager(org.eclipse.ui.statushandlers.StatusManager) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) Status(org.eclipse.core.runtime.Status) InvocationTargetException(java.lang.reflect.InvocationTargetException) Util(org.eclipse.jface.util.Util) LabelProvider.createTextImageProvider(org.eclipse.jface.viewers.LabelProvider.createTextImageProvider) List(java.util.List) Tree(org.eclipse.swt.widgets.Tree) SWT(org.eclipse.swt.SWT) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IEditorRegistry(org.eclipse.ui.IEditorRegistry) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) Label(org.eclipse.swt.widgets.Label) Image(org.eclipse.swt.graphics.Image) JFaceResources(org.eclipse.jface.resource.JFaceResources) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) IWorkbenchHelpContextIds(org.eclipse.ui.internal.IWorkbenchHelpContextIds) Listener(org.eclipse.swt.widgets.Listener) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) Shell(org.eclipse.swt.widgets.Shell) WorkbenchMessages(org.eclipse.ui.internal.WorkbenchMessages) FileDialog(org.eclipse.swt.widgets.FileDialog) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping) FileEditorMapping(org.eclipse.ui.internal.registry.FileEditorMapping) RowLayout(org.eclipse.swt.layout.RowLayout) EditorRegistry(org.eclipse.ui.internal.registry.EditorRegistry) Dialog(org.eclipse.jface.dialogs.Dialog) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) FrameworkUtil(org.osgi.framework.FrameworkUtil) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) Label(org.eclipse.swt.widgets.Label) Font(org.eclipse.swt.graphics.Font) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree)

Example 54 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.

the class WorkingSetConfigurationBlock method createContent.

/**
 * Add this block to the <code>parent</code>
 *
 * @param parent the parent to add the block to
 */
public void createContent(final Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    composite.setLayout(new GridLayout(3, false));
    enableButton = new Button(composite, SWT.CHECK);
    enableButton.setText(enableButtonLabel);
    GridData enableData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    enableData.horizontalSpan = 2;
    enableButton.setLayoutData(enableData);
    enableButton.setSelection(selectedWorkingSets.length > 0);
    newButton = new Button(composite, SWT.PUSH);
    newButton.setText(this.newButtonLabel);
    setButtonLayoutData(newButton);
    newButton.addSelectionListener(widgetSelectedAdapter(e -> createNewWorkingSet(newButton.getShell())));
    workingSetLabel = new Label(composite, SWT.NONE);
    workingSetLabel.setText(comboLabel);
    workingSetCombo = new Combo(composite, SWT.READ_ONLY | SWT.BORDER);
    GridData textData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    textData.horizontalIndent = 0;
    workingSetCombo.setLayoutData(textData);
    selectButton = new Button(composite, SWT.PUSH);
    selectButton.setText(selectLabel);
    setButtonLayoutData(selectButton);
    selectButton.addSelectionListener(widgetSelectedAdapter(e -> {
        SimpleWorkingSetSelectionDialog dialog = new SimpleWorkingSetSelectionDialog(parent.getShell(), workingSetTypeIds, selectedWorkingSets, false);
        dialog.setMessage(WorkbenchMessages.WorkingSetGroup_WorkingSetSelection_message);
        if (dialog.open() == Window.OK) {
            IWorkingSet[] result = dialog.getSelection();
            if (result != null && result.length > 0) {
                selectedWorkingSets = result;
                PlatformUI.getWorkbench().getWorkingSetManager().addRecentWorkingSet(result[0]);
            } else {
                selectedWorkingSets = EMPTY_WORKING_SET_ARRAY;
            }
            updateWorkingSetSelection();
        }
    }));
    enableButton.addSelectionListener(widgetSelectedAdapter(e -> updateEnableState(enableButton.getSelection())));
    updateEnableState(enableButton.getSelection());
    workingSetCombo.addSelectionListener(widgetSelectedAdapter(e -> updateSelectedWorkingSets()));
    workingSetCombo.setItems(getHistoryEntries());
    if (selectedWorkingSets.length == 0 && selectionHistory.size() > 0) {
        workingSetCombo.select(historyIndex(selectionHistory.get(0)));
        updateSelectedWorkingSets();
    } else {
        updateWorkingSetSelection();
    }
}
Also used : Arrays(java.util.Arrays) WorkbenchPlugin(org.eclipse.ui.internal.WorkbenchPlugin) IWizardPage(org.eclipse.jface.wizard.IWizardPage) SimpleWorkingSetSelectionDialog(org.eclipse.ui.internal.dialogs.SimpleWorkingSetSelectionDialog) FontMetrics(org.eclipse.swt.graphics.FontMetrics) JFaceResources(org.eclipse.jface.resource.JFaceResources) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SelectionListener.widgetSelectedAdapter(org.eclipse.swt.events.SelectionListener.widgetSelectedAdapter) IWorkbenchHelpContextIds(org.eclipse.ui.internal.IWorkbenchHelpContextIds) StringTokenizer(java.util.StringTokenizer) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Collator(java.text.Collator) Combo(org.eclipse.swt.widgets.Combo) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) WorkbenchMessages(org.eclipse.ui.internal.WorkbenchMessages) Collection(java.util.Collection) Assert(org.eclipse.core.runtime.Assert) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) List(java.util.List) Window(org.eclipse.jface.window.Window) Dialog(org.eclipse.jface.dialogs.Dialog) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SWT(org.eclipse.swt.SWT) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) SimpleWorkingSetSelectionDialog(org.eclipse.ui.internal.dialogs.SimpleWorkingSetSelectionDialog)

Example 55 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project eclipse.platform.ui by eclipse-platform.

the class InfoAboutHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    Dialog dialog = new InfoAboutDialog(window.getShell());
    dialog.open();
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Dialog(org.eclipse.jface.dialogs.Dialog)

Aggregations

Dialog (org.eclipse.jface.dialogs.Dialog)233 Test (org.junit.Test)125 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)82 Composite (org.eclipse.swt.widgets.Composite)38 Shell (org.eclipse.swt.widgets.Shell)35 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)32 Control (org.eclipse.swt.widgets.Control)32 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)28 SWT (org.eclipse.swt.SWT)28 GridData (org.eclipse.swt.layout.GridData)27 Button (org.eclipse.swt.widgets.Button)25 WizardDialog (org.eclipse.jface.wizard.WizardDialog)24 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)24 ContainerSelectionDialog (org.eclipse.ui.dialogs.ContainerSelectionDialog)23 EditorSelectionDialog (org.eclipse.ui.dialogs.EditorSelectionDialog)23 ListSelectionDialog (org.eclipse.ui.dialogs.ListSelectionDialog)23 ProjectLocationSelectionDialog (org.eclipse.ui.dialogs.ProjectLocationSelectionDialog)23 TypeFilteringDialog (org.eclipse.ui.dialogs.TypeFilteringDialog)23 AboutDialog (org.eclipse.ui.internal.dialogs.AboutDialog)23 FileExtensionDialog (org.eclipse.ui.internal.dialogs.FileExtensionDialog)23