Search in sources :

Example 46 with Dialog

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

the class KeyAssistDialog method open.

/**
 * Opens this dialog with the list of bindings for the user to select from.
 *
 * @return The return code from this dialog.
 * @since 3.3
 */
public int open(Collection<Binding> bindings) {
    matches = new TreeSet<>((a, b) -> {
        Binding bindingA = a;
        Binding bindingB = b;
        ParameterizedCommand commandA = bindingA.getParameterizedCommand();
        ParameterizedCommand commandB = bindingB.getParameterizedCommand();
        try {
            return commandA.getName().compareTo(commandB.getName());
        } catch (NotDefinedException e) {
            // should not happen
            return 0;
        }
    });
    matches.addAll(bindings);
    // If the dialog is already open, dispose the shell and recreate it.
    Shell shell = getShell();
    if (shell != null) {
        close(false, false);
        return Window.OK;
    }
    create();
    // Bug 369860. Stop ShellActivationListener from creating a context for this.
    // $NON-NLS-1$
    getShell().setData("org.eclipse.e4.ui.ignoreDialog", Boolean.TRUE);
    // Configure the size and location.
    Point size = configureSize();
    configureLocation(size);
    // Call the super method.
    return super.open();
}
Also used : ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) TableColumn(org.eclipse.swt.widgets.TableColumn) Rectangle(org.eclipse.swt.graphics.Rectangle) Table(org.eclipse.swt.widgets.Table) Point(org.eclipse.swt.graphics.Point) TreeSet(java.util.TreeSet) Event(org.eclipse.swt.widgets.Event) ArrayList(java.util.ArrayList) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) EBindingService(org.eclipse.e4.ui.bindings.EBindingService) CommandException(org.eclipse.core.commands.common.CommandException) TableItem(org.eclipse.swt.widgets.TableItem) Shell(org.eclipse.swt.widgets.Shell) Iterator(java.util.Iterator) KeyBindingDispatcher(org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher) Collection(java.util.Collection) PopupDialog(org.eclipse.jface.dialogs.PopupDialog) List(java.util.List) Window(org.eclipse.jface.window.Window) Dialog(org.eclipse.jface.dialogs.Dialog) Binding(org.eclipse.jface.bindings.Binding) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) Binding(org.eclipse.jface.bindings.Binding) Shell(org.eclipse.swt.widgets.Shell) NotDefinedException(org.eclipse.core.commands.common.NotDefinedException) Point(org.eclipse.swt.graphics.Point) ParameterizedCommand(org.eclipse.core.commands.ParameterizedCommand)

Example 47 with Dialog

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

the class BrowserDescriptorDialog method createText.

protected Text createText(Composite comp, String txt, final StringModifyListener listener, boolean multiLine) {
    int style = SWT.BORDER;
    if (multiLine) {
        style = SWT.BORDER | SWT.V_SCROLL | SWT.MULTI | SWT.WRAP;
    }
    final Text text = new Text(comp, style);
    if (multiLine) {
        text.addTraverseListener(event -> {
            switch(event.detail) {
                case SWT.TRAVERSE_RETURN:
                case SWT.TRAVERSE_TAB_NEXT:
                case SWT.TRAVERSE_TAB_PREVIOUS:
                    event.doit = true;
                    break;
            }
        });
    }
    // final Text text = SWTUtil.createMultilineText(comp, style);
    if (txt != null)
        text.setText(txt);
    GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
    data.widthHint = 450;
    if (multiLine) {
        // then expand this control as the dialog resizes
        data.verticalAlignment = SWT.FILL;
        data.grabExcessVerticalSpace = true;
        data.heightHint = convertHeightInCharsToPixels(4);
    }
    text.setLayoutData(data);
    if (listener != null)
        text.addModifyListener(e -> listener.valueChanged(text.getText()));
    return text;
}
Also used : Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) Button(org.eclipse.swt.widgets.Button) NLS(org.eclipse.osgi.util.NLS) PlatformUI(org.eclipse.ui.PlatformUI) FileDialog(org.eclipse.swt.widgets.FileDialog) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) File(java.io.File) Util(org.eclipse.jface.util.Util) Dialog(org.eclipse.jface.dialogs.Dialog) Composite(org.eclipse.swt.widgets.Composite) SWT(org.eclipse.swt.SWT) Font(org.eclipse.swt.graphics.Font) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Control(org.eclipse.swt.widgets.Control) SelectionListener(org.eclipse.swt.events.SelectionListener) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) Text(org.eclipse.swt.widgets.Text)

Example 48 with Dialog

use of org.eclipse.jface.dialogs.Dialog in project sonarlint-eclipse by SonarSource.

the class EditProjectExclusionDialog method selectFile.

/**
 * Opens a dialog where the user can select a file path.
 */
private void selectFile() {
    ISelectionStatusValidator validator = arr -> {
        if (arr.length > 1) {
            return ValidationStatus.error("Only one file can be selected");
        }
        if (arr.length == 0) {
            return ValidationStatus.ok();
        }
        Object obj = arr[0];
        ISonarLintFile file = Adapters.adapt(obj, ISonarLintFile.class);
        return file != null ? ValidationStatus.ok() : ValidationStatus.error("Select a file");
    };
    var viewFilter = new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IFolder) {
                var folder = (IFolder) element;
                return SonarLintUtils.isSonarLintFileCandidate(folder);
            }
            if (element instanceof IFile) {
                var file = Adapters.adapt(element, ISonarLintFile.class);
                return file != null;
            }
            return false;
        }
    };
    var lp = new WorkbenchLabelProvider();
    var cp = new WorkbenchContentProvider();
    var dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
    dialog.setTitle("Select File");
    dialog.setInput(project.getResource());
    dialog.setAllowMultiple(false);
    dialog.addFilter(viewFilter);
    dialog.setValidator(validator);
    dialog.setMessage("Select a project file to be excluded from SonarLint analysis");
    if (editItem != null) {
        dialog.setInitialSelection(editItem.item());
    }
    if (dialog.open() == Window.OK) {
        var obj = dialog.getFirstResult();
        var file = Adapters.adapt(obj, ISonarLintFile.class);
        if (file != null) {
            editItem = new ExclusionItem(Type.FILE, file.getProjectRelativePath());
            fileField.setText(editItem.item());
        }
    }
}
Also used : WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) IFolder(org.eclipse.core.resources.IFolder) ExclusionItem(org.sonarlint.eclipse.core.internal.resources.ExclusionItem) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) StringUtils(org.sonarlint.eclipse.core.internal.utils.StringUtils) Type(org.sonarlint.eclipse.core.internal.resources.ExclusionItem.Type) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) IMessageProvider(org.eclipse.jface.dialogs.IMessageProvider) Nullable(org.eclipse.jdt.annotation.Nullable) Composite(org.eclipse.swt.widgets.Composite) IFile(org.eclipse.core.resources.IFile) GridData(org.eclipse.swt.layout.GridData) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ISonarLintProject(org.sonarlint.eclipse.core.resource.ISonarLintProject) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) PatternSyntaxException(java.util.regex.PatternSyntaxException) Shell(org.eclipse.swt.widgets.Shell) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) SonarLintUtils(org.sonarlint.eclipse.core.internal.utils.SonarLintUtils) Adapters(org.eclipse.core.runtime.Adapters) Window(org.eclipse.jface.window.Window) Dialog(org.eclipse.jface.dialogs.Dialog) ModifyListener(org.eclipse.swt.events.ModifyListener) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) ISonarLintFile(org.sonarlint.eclipse.core.resource.ISonarLintFile) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileSystems(java.nio.file.FileSystems) Control(org.eclipse.swt.widgets.Control) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ISonarLintFile(org.sonarlint.eclipse.core.resource.ISonarLintFile) Viewer(org.eclipse.jface.viewers.Viewer) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) ExclusionItem(org.sonarlint.eclipse.core.internal.resources.ExclusionItem) IFolder(org.eclipse.core.resources.IFolder)

Example 49 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 50 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)

Aggregations

Dialog (org.eclipse.jface.dialogs.Dialog)232 Test (org.junit.Test)125 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)82 Composite (org.eclipse.swt.widgets.Composite)37 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)27 GridData (org.eclipse.swt.layout.GridData)26 WizardDialog (org.eclipse.jface.wizard.WizardDialog)24 Button (org.eclipse.swt.widgets.Button)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