Example usage for org.eclipse.jface.dialogs Dialog Dialog

List of usage examples for org.eclipse.jface.dialogs Dialog Dialog

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog Dialog.

Prototype

protected Dialog(IShellProvider parentShell) 

Source Link

Document

Creates a dialog with the given parent.

Usage

From source file:org.eclipse.nebula.widgets.treemapper.tests.ProgrammaticTest.java

License:Open Source License

/**
 * @param treeContent//  w  ww .j  a  va 2 s. c o  m
 * @param mappings
 * @return
 */
private Dialog openMapperDialog(final String[] treeContent, final String[] mappings) {
    Dialog dialog = new Dialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()) {
        @Override
        public Composite createDialogArea(Composite parent) {
            Composite res = (Composite) super.createDialogArea(parent);
            TreeMapper<String, String, String> mapper = new TreeMapper<String, String, String>(parent,
                    new ObjectSemanticSupport(),
                    new TreeMapperUIConfigProvider(ColorConstants.blue, 2, ColorConstants.darkBlue, 4));
            mapper.setContentProviders(new ArrayTreeContentProvider(), new ArrayTreeContentProvider());
            mapper.setInput(treeContent, treeContent, Arrays.asList(mappings));
            return res;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();
    return dialog;
}

From source file:org.eclipse.ptp.internal.remote.terminal.RemoteConnection.java

License:Open Source License

/**
 * The param "str" should be a list of files delimited by "~~". The
 * user will be shown a choice dialog, allowing the user to pick one
 * file to open. This selects one file from a list obtained by a shell
 * wild card./*from ww w  . j av  a  2 s  . com*/
 * 
 * @param str
 */
private void doChoiceAction(final String str) {
    final String[] choices = str.split("\\s*~~\\s*"); //$NON-NLS-1$

    getStandardDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            try {
                final Dialog dialog = new Dialog(getStandardDisplay().getActiveShell()) {
                    Combo combo;
                    String[] comboChoices;

                    @Override
                    protected void configureShell(Shell shell) {
                        shell.setText(Messages.CHOOSE_FILE);
                        super.configureShell(shell);
                    }

                    @Override
                    protected Control createDialogArea(Composite parent) {
                        Composite container = (Composite) super.createDialogArea(parent);
                        combo = new Combo(container, SWT.NONE);
                        combo.setItems(choices);
                        comboChoices = choices;
                        Point pt = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                        combo.setSize(pt.x, 5 * pt.y);
                        return container;
                    }

                    @Override
                    public void buttonPressed(int buttonId) {
                        int n = combo.getSelectionIndex();
                        if (buttonId == 0 && n >= 0 && n < comboChoices.length) {
                            openFile(comboChoices[n]);
                        }
                        close();
                    }
                };
                dialog.open();
            } catch (Exception t) {
                Activator.log(t);
            }
        }

    });
}

From source file:org.eclipse.ptp.internal.remote.terminal.RemoteConnection.java

License:Open Source License

/**
 * Creates a dialog with a radio button that will perform one shell command
 * from a list. The string ~~ is used to delimit commands, and ::~ is used
 * to separate user-displayed text from the command itself. Thus, a script
 * containing:/*from w ww .  j a v  a 2s.c  o  m*/
 * 
 * <pre>
 * #!/bin/bash
 * echo "~~EPTP:Radio~~ List Files::~ls -F~~Current Dir::~pwd"
 * </pre>
 * 
 * Will produce a menu allowing the user to select from "List Files" and
 * "Current Dir". The former will perform an "ls -F", the latter will
 * perform a "pwd" command.
 * 
 * @param str
 */
private void doRadioAction(final String str) {
    final String[] choices = str.split("\\s*~~\\s*"); //$NON-NLS-1$

    getStandardDisplay().asyncExec(new Runnable() {
        @Override
        public void run() {
            try {
                final Dialog dialog = new Dialog(getStandardDisplay().getActiveShell()) {
                    private final Map<String, String> smap = new HashMap<String, String>();
                    private final List<Button> buttons = new ArrayList<Button>();

                    @Override
                    protected void configureShell(Shell shell) {
                        shell.setText(Messages.CHOOSE_FILE);
                        super.configureShell(shell);
                    }

                    @Override
                    protected Control createDialogArea(Composite parent) {
                        Composite container = (Composite) super.createDialogArea(parent);
                        for (String choice : choices) {
                            String[] keyvalue = choice.split("::~"); //$NON-NLS-1$
                            if (keyvalue.length == 2) {
                                Button b = new Button(container, SWT.RADIO);
                                b.setText(keyvalue[0]);
                                smap.put(keyvalue[0], keyvalue[1]);
                                buttons.add(b);
                            }
                        }
                        return container;
                    }

                    @Override
                    public void buttonPressed(int buttonId) {
                        if (buttonId == 0) {
                            for (Button b : buttons) {
                                if (b.getSelection()) {
                                    String value = smap.get(b.getText());
                                    try {
                                        OutputStream out = fProcess.getOutputStream();
                                        out.write((value + "\n").getBytes()); //$NON-NLS-1$
                                        out.flush();
                                    } catch (IOException ioe) {

                                    }
                                }
                            }
                        }
                        close();
                    }
                };
                dialog.open();
            } catch (Exception t) {
                Activator.log(t);
            }
        }
    });
}

From source file:org.eclipse.ptp.internal.remote.terminal.RemoteTerminalParser.java

License:Open Source License

/**
 * The param "str" should be a list of files delimited by "~~". The
 * user will be shown a choice dialog, allowing the user to pick one
 * file to open. This selects one file from a list obtained by a shell
 * wild card./* w  w  w .  j  a v  a2 s .  c om*/
 * 
 * @param str
 */
private void doChoiceAction(final String str, final String arg) {
    final String[] choices = str.split("\\s*~~\\s*"); //$NON-NLS-1$

    getStandardDisplay().asyncExec(new Runnable() {

        @Override
        public void run() {
            try {
                final Dialog dialog = new Dialog(getStandardDisplay().getActiveShell()) {
                    private Combo combo;
                    private String[] comboChoices;

                    @Override
                    public void buttonPressed(int buttonId) {
                        int n = combo.getSelectionIndex();
                        if (buttonId == 0 && n >= 0 && n < comboChoices.length) {
                            openFile(comboChoices[n], arg);
                        }
                        close();
                    }

                    @Override
                    protected void configureShell(Shell shell) {
                        shell.setText(Messages.CHOOSE_FILE);
                        super.configureShell(shell);
                    }

                    @Override
                    protected Control createDialogArea(Composite parent) {
                        Composite container = (Composite) super.createDialogArea(parent);
                        combo = new Combo(container, SWT.NONE);
                        combo.setItems(choices);
                        comboChoices = choices;
                        Point pt = combo.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                        combo.setSize(pt.x, 5 * pt.y);
                        return container;
                    }
                };
                dialog.open();
            } catch (Exception t) {
                Activator.log(t);
            }
        }

    });
}

From source file:org.eclipse.ptp.internal.remote.terminal.RemoteTerminalParser.java

License:Open Source License

/**
 * Creates a dialog with a radio button that will perform one shell command
 * from a list. The string ~~ is used to delimit commands, and ::~ is used
 * to separate user-displayed text from the command itself. Thus, a script
 * containing://from  w  w  w . j  av  a  2  s . c o m
 * 
 * <pre>
 * #!/bin/bash
 * echo "~~EPTP:Radio~~ List Files::~ls -F~~Current Dir::~pwd"
 * </pre>
 * 
 * Will produce a menu allowing the user to select from "List Files" and
 * "Current Dir". The former will perform an "ls -F", the latter will
 * perform a "pwd" command.
 * 
 * @param str
 */
private void doRadioAction(final String str) {
    final String[] choices = str.split("\\s*~~\\s*"); //$NON-NLS-1$

    getStandardDisplay().asyncExec(new Runnable() {
        @Override
        public void run() {
            try {
                final Dialog dialog = new Dialog(getStandardDisplay().getActiveShell()) {
                    private final Map<String, String> smap = new HashMap<String, String>();
                    private final List<Button> buttons = new ArrayList<Button>();

                    @Override
                    public void buttonPressed(int buttonId) {
                        if (buttonId == 0) {
                            for (Button b : buttons) {
                                if (b.getSelection()) {
                                    String value = smap.get(b.getText());
                                    try {
                                        OutputStream out = fProcess.getOutputStream();
                                        out.write((value + "\n").getBytes()); //$NON-NLS-1$
                                        out.flush();
                                    } catch (IOException ioe) {

                                    }
                                }
                            }
                        }
                        close();
                    }

                    @Override
                    protected void configureShell(Shell shell) {
                        shell.setText(Messages.CHOOSE_FILE);
                        super.configureShell(shell);
                    }

                    @Override
                    protected Control createDialogArea(Composite parent) {
                        Composite container = (Composite) super.createDialogArea(parent);
                        for (String choice : choices) {
                            String[] keyvalue = choice.split("::~"); //$NON-NLS-1$
                            if (keyvalue.length == 2) {
                                Button b = new Button(container, SWT.RADIO);
                                b.setText(keyvalue[0]);
                                smap.put(keyvalue[0], keyvalue[1]);
                                buttons.add(b);
                            }
                        }
                        return container;
                    }
                };
                dialog.open();
            } catch (Exception t) {
                Activator.log(t);
            }
        }
    });
}

From source file:org.eclipse.sapphire.ui.forms.swt.internal.HyperlinkTable.java

License:Open Source License

private void handleJumpCommand() {
    final TableItem[] items = HyperlinkTable.this.table.getSelection();

    if (items.length == 1) {
        final TableItem item = items[0];
        final List<Integer> columnsWithHyperlinks = new ArrayList<Integer>();

        for (int i = 0, n = getColumnCount(HyperlinkTable.this.table); i < n; i++) {
            if (this.controller.isHyperlinkEnabled(item, i)) {
                columnsWithHyperlinks.add(i);
            }//from  w ww .  jav a  2  s  .c  o m
        }

        if (columnsWithHyperlinks.size() == 1) {
            handleJumpCommand(item, columnsWithHyperlinks.get(0));
        } else if (!columnsWithHyperlinks.isEmpty()) {
            final Dialog dialog = new Dialog(this.table.getShell()) {
                private int choice = columnsWithHyperlinks.get(0);

                @Override
                protected Control createDialogArea(final Composite parent) {
                    getShell().setText(jumpDialogTitle.text());

                    final Composite composite = (Composite) super.createDialogArea(parent);

                    final Label prompt = new Label(composite, SWT.WRAP);
                    prompt.setLayoutData(gdwhint(gdhfill(), 300));
                    prompt.setText(jumpDialogPrompt.text());

                    final SelectionListener listener = new SelectionAdapter() {
                        public void widgetSelected(final SelectionEvent event) {
                            setChoice((Integer) event.widget.getData());
                        }
                    };

                    boolean first = true;

                    for (Integer col : columnsWithHyperlinks) {
                        final Button button = new Button(composite, SWT.RADIO | SWT.WRAP);
                        button.setLayoutData(gdhindent(gd(), 10));
                        button.setText(item.getText(col));
                        button.setData(col);

                        if (first) {
                            button.setSelection(true);
                            first = false;
                        }

                        button.addSelectionListener(listener);
                    }

                    return composite;
                }

                @Override
                protected void okPressed() {
                    super.okPressed();
                    handleJumpCommand(item, this.choice);
                }

                private void setChoice(final int choice) {
                    this.choice = choice;
                }
            };

            dialog.open();
        }
    }
}

From source file:org.eclipse.sapphire.ui.swt.renderer.HyperlinkTable.java

License:Open Source License

private void handleJumpCommand() {
    final TableItem[] items = HyperlinkTable.this.table.getSelection();

    if (items.length == 1) {
        final TableItem item = items[0];
        final List<Integer> columnsWithHyperlinks = new ArrayList<Integer>();

        for (int i = 0, n = getColumnCount(HyperlinkTable.this.table); i < n; i++) {
            if (this.controller.isHyperlinkEnabled(item, i)) {
                columnsWithHyperlinks.add(i);
            }/*  www.jav  a2 s  .co m*/
        }

        if (columnsWithHyperlinks.size() == 1) {
            handleJumpCommand(item, columnsWithHyperlinks.get(0));
        } else if (!columnsWithHyperlinks.isEmpty()) {
            final Dialog dialog = new Dialog(this.table.getShell()) {
                private int choice = columnsWithHyperlinks.get(0);

                @Override
                protected Control createDialogArea(final Composite parent) {
                    getShell().setText(Resources.jumpDialogTitle);

                    final Composite composite = (Composite) super.createDialogArea(parent);

                    final Label prompt = new Label(composite, SWT.WRAP);
                    prompt.setLayoutData(gdwhint(gdhfill(), 300));
                    prompt.setText(Resources.jumpDialogPrompt);

                    final SelectionListener listener = new SelectionAdapter() {
                        public void widgetSelected(final SelectionEvent event) {
                            setChoice((Integer) event.widget.getData());
                        }
                    };

                    boolean first = true;

                    for (Integer col : columnsWithHyperlinks) {
                        final Button button = new Button(composite, SWT.RADIO | SWT.WRAP);
                        button.setLayoutData(gdhindent(gd(), 10));
                        button.setText(item.getText(col));
                        button.setData(col);

                        if (first) {
                            button.setSelection(true);
                            first = false;
                        }

                        button.addSelectionListener(listener);
                    }

                    return composite;
                }

                @Override
                protected void okPressed() {
                    super.okPressed();
                    handleJumpCommand(item, this.choice);
                }

                private void setChoice(final int choice) {
                    this.choice = choice;
                }
            };

            dialog.open();
        }
    }
}

From source file:org.eclipse.servicesregistry.search.ui.test.classifications.pageobjects.ClassificationsTreePageObject.java

License:Open Source License

private void createUi(final ClassificationTreeContribution contribution,
        final IDiscoveryEnvironment environment) {
    asyncExec(new VoidResult() {
        @Override/*from w ww.j  a v a2  s.c  om*/
        public void run() {
            final Dialog dlg = new Dialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()) {
                @Override
                protected Control createContents(Composite parent) {
                    parent.setLayout(new FillLayout(SWT.VERTICAL));
                    final Composite hostComposite = new Composite(parent, SWT.NONE);
                    hostComposite.setLayout(new FormLayout());
                    contribution.createUi(hostComposite, Mockito.mock(IServicesRegistryDestination.class),
                            toolkit, environment, null);
                    contribution.handleVisibilityChange(true);
                    return parent;
                }
            };

            dlg.setBlockOnOpen(false);
            dlg.open();
            shell = new SWTBotShell(dlg.getShell());
        }
    });

    Assertions.waitAssert(new IWaitCondition() {

        @Override
        public boolean checkCondition() throws ConditionCheckException {
            return shell != null;
        }
    }, "Test shell could not be created");
}

From source file:org.eclipse.ui.tests.browser.internal.ToolbarBrowserTestCase.java

License:Open Source License

public void test00Open() throws Exception {
    shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    dialog = new Dialog(shell) {
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);

            browser = new BrowserViewer(composite, BrowserViewer.LOCATION_BAR | BrowserViewer.BUTTON_BAR);
            GridData data = new GridData(GridData.FILL_BOTH);
            data.widthHint = 400;//from   w ww  . j a  va 2  s. c  o m
            data.heightHint = 400;
            browser.setLayoutData(data);

            return composite;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();

    boolean b = Display.getCurrent().readAndDispatch();
    while (b)
        b = Display.getCurrent().readAndDispatch();
}

From source file:org.eclipse.ui.tests.browser.internal.ToolbarBrowserTestCase.java

License:Open Source License

public void test14ProtectedMethods() {
    shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    dialog = new Dialog(shell) {
        protected Control createDialogArea(Composite parent) {
            Composite composite = (Composite) super.createDialogArea(parent);

            ttb = new TestToolbarBrowser(composite, BrowserViewer.LOCATION_BAR | BrowserViewer.BUTTON_BAR);
            GridData data = new GridData(GridData.FILL_BOTH);
            data.widthHint = 400;//from w  ww. j a va2  s.  c  o  m
            data.heightHint = 400;
            ttb.setLayoutData(data);

            return composite;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();

    ttb.testProtectedMethods();
    dialog.close();
}