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

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

Introduction

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

Prototype

public PopupDialog(Shell parent, int shellStyle, boolean takeFocusOnOpen, boolean persistSize,
        boolean persistLocation, boolean showDialogMenu, boolean showPersistActions, String titleText,
        String infoText) 

Source Link

Document

Constructs a new instance of PopupDialog.

Usage

From source file:com.aptana.scripting.keybindings.internal.KeybindingsManager.java

License:Open Source License

private void popup(final Shell shell, final IBindingService bindingService,
        final IContextService contextService, final ICommandElementsProvider commandElementsProvider,
        final List<CommandElement> commandElements, final Event event, final Binding binding,
        final Point initialLocation) {
    PopupDialog popupDialog = new PopupDialog(shell, PopupDialog.INFOPOPUP_SHELLSTYLE, true, false, false,
            false, false, null, null) {//  w  w  w. j  av a  2 s .  co m

        @Override
        protected Point getInitialLocation(Point initialSize) {
            Display display = shell.getDisplay();
            Point cursorLocation = display.getCursorLocation();
            if (initialLocation != null) {
                // Warp the cursor ?
                // if (!cursorLocation.equals(initialLocation))
                // {
                // display.setCursorLocation(initialLocation);
                // }
                return initialLocation;
            }
            return cursorLocation;
        }

        protected Control createDialogArea(Composite parent) {

            registerShellType();

            // Create a composite for the dialog area.
            final Composite composite = new Composite(parent, SWT.NONE);
            final GridLayout compositeLayout = new GridLayout();
            compositeLayout.marginHeight = 1;
            compositeLayout.marginWidth = 1;
            composite.setLayout(compositeLayout);
            composite.setLayoutData(new GridData(GridData.FILL_BOTH));

            // Layout the table.
            final Table commandElementTable = new Table(composite,
                    SWT.FULL_SELECTION | SWT.SINGLE | SWT.NO_SCROLL);
            final GridData gridData = new GridData(GridData.FILL_BOTH);
            commandElementTable.setLayoutData(gridData);
            commandElementTable.setLinesVisible(true);

            // Initialize the columns and rows.
            final TableColumn columnCommandName = new TableColumn(commandElementTable, SWT.LEFT, 0);
            final TableColumn columnAccelerator = new TableColumn(commandElementTable, SWT.CENTER, 1);

            int mnemonic = 0;
            for (CommandElement commandElement : commandElements) {
                final String[] text = { commandElement.getDisplayName(),
                        (mnemonic < MNEMONICS.length() ? String.valueOf(MNEMONICS.charAt(mnemonic++)) : "") }; //$NON-NLS-1$
                final TableItem item = new TableItem(commandElementTable, SWT.NULL);
                item.setText(text);
                item.setData(CommandElement.class.getName(), commandElement);
            }

            if (binding != null) {
                ParameterizedCommand originalParameterizedCommand = binding.getParameterizedCommand();
                // Add original command
                if (originalParameterizedCommand != null) {
                    try {
                        String name = originalParameterizedCommand.getName();
                        final TableItem item = new TableItem(commandElementTable, SWT.NULL);
                        item.setText(new String[] { name,
                                (mnemonic < MNEMONICS.length() ? String.valueOf(MNEMONICS.charAt(mnemonic++))
                                        : "") }); //$NON-NLS-1$
                        item.setData(ParameterizedCommand.class.getName(), originalParameterizedCommand);
                    } catch (NotDefinedException nde) {
                        IdeLog.logError(ScriptingActivator.getDefault(), nde.getMessage(), nde);
                    }
                }
            }

            Dialog.applyDialogFont(parent);
            columnAccelerator.pack();
            columnCommandName.pack();
            columnAccelerator.setWidth(columnAccelerator.getWidth() * 4);

            /*
             * If the user double-clicks on the table row, it should execute the selected command.
             */
            commandElementTable.addListener(SWT.DefaultSelection, new Listener() {
                public final void handleEvent(final Event event) {
                    // Try to execute the corresponding command.
                    Object commandElement = null;
                    Object parameterizedCommand = null;
                    final TableItem[] selection = commandElementTable.getSelection();
                    if (selection.length > 0) {
                        commandElement = selection[0].getData(CommandElement.class.getName());
                        parameterizedCommand = selection[0].getData(ParameterizedCommand.class.getName());
                    }
                    close();
                    if (commandElement instanceof CommandElement) {
                        executeCommandElement(commandElementsProvider, (CommandElement) commandElement);
                    } else if (parameterizedCommand instanceof ParameterizedCommand) {
                        try {
                            executeCommand(binding, event);
                        } catch (CommandException e) {
                            IdeLog.logError(ScriptingActivator.getDefault(), e.getMessage(), e);
                        }
                    }
                }
            });

            commandElementTable.addKeyListener(new KeyListener() {
                public void keyReleased(KeyEvent e) {
                }

                public void keyPressed(KeyEvent e) {
                    if (!e.doit) {
                        return;
                    }
                    int index = MNEMONICS.indexOf(e.character);
                    if (index != -1) {
                        if (index < commandElementTable.getItemCount()) {
                            e.doit = false;
                            TableItem tableItem = commandElementTable.getItem(index);
                            Object commandElement = tableItem.getData(CommandElement.class.getName());
                            Object parameterizedCommand = tableItem
                                    .getData(ParameterizedCommand.class.getName());
                            close();
                            if (commandElement instanceof CommandElement) {
                                executeCommandElement(commandElementsProvider, (CommandElement) commandElement);
                            } else if (parameterizedCommand instanceof ParameterizedCommand) {
                                try {
                                    executeCommand(binding, event);
                                } catch (CommandException ex) {
                                    IdeLog.logError(ScriptingActivator.getDefault(), ex.getMessage(), ex);
                                }
                            }
                        }
                    }
                }
            });
            return composite;
        }

        protected Color getBackground() {
            return getShell().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
        }

        @Override
        protected Control createContents(Composite parent) {
            return super.createContents(parent);
        }

        @Override
        public int open() {
            showingCommandsMenu = true;
            bindingService.setKeyFilterEnabled(false);
            return super.open();
        }

        @Override
        public boolean close() {
            boolean closed = super.close();
            if (closed) {
                showingCommandsMenu = false;
                bindingService.setKeyFilterEnabled(true);
            }
            return closed;
        }

        /**
         * Registers the shell as the same type as its parent with the context support. This ensures that it does
         * not modify the current state of the application.
         */
        private final void registerShellType() {
            final Shell shell = getShell();
            contextService.registerShell(shell, contextService.getShellType((Shell) shell.getParent()));
        }
    };

    popupDialog.open();
}

From source file:com.liferay.ide.project.ui.upgrade.animated.InitConfigureProjectPage.java

License:Open Source License

@Override
public void createSpecialDescriptor(Composite parent, int style) {
    Composite fillLayoutComposite = SWTUtil.createComposite(parent, 2, 2, GridData.FILL_HORIZONTAL);

    final String descriptor = "The initial step will be to upgrade to Liferay Workspace or Liferay Plugins SDK 7.0. "
            + "For more details, please see <a>dev.liferay.com</a>.";

    String url = "https://dev.liferay.com/develop/tutorials";

    SWTUtil.createHyperLink(fillLayoutComposite, SWT.WRAP, descriptor, 1, url);

    final String extensionDec = "The first step will help you convert a Liferay Plugins SDK 6.2 to Liferay Plugins SDK 7.0 or to Liferay Workspace.\n"
            + "Click the \"import\" button to import your project into Eclipse workspace"
            + "(this process maybe need 5-10 mins for bundle init).\n" + "Note:\n"
            + "       In order to save time, downloading 7.0 ivy cache locally could be a good choice to upgrade to liferay plugins sdk 7. \n"
            + "       Theme and ext projects will be ignored for that we do not support to upgrade them in this tool currently. \n";

    Label image = new Label(fillLayoutComposite, SWT.WRAP);
    image.setImage(loadImage("question.png"));

    PopupDialog popupDialog = new PopupDialog(fillLayoutComposite.getShell(),
            PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, false, false, false, false, null, null) {
        private static final int CURSOR_SIZE = 15;

        protected Point getInitialLocation(Point initialSize) {
            Display display = getShell().getDisplay();
            Point location = display.getCursorLocation();
            location.x += CURSOR_SIZE;//from   w  ww .  j  a  va2s  .  co  m
            location.y += CURSOR_SIZE;
            return location;
        }

        protected Control createDialogArea(Composite parent) {
            Label label = new Label(parent, SWT.WRAP);
            label.setText(extensionDec);
            label.setFont(new Font(null, "Times New Roman", 11, SWT.NORMAL));
            GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
            gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
            gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
            label.setLayoutData(gd);
            return label;
        }
    };

    image.addListener(SWT.MouseHover, new org.eclipse.swt.widgets.Listener() {
        @Override
        public void handleEvent(org.eclipse.swt.widgets.Event event) {
            popupDialog.open();
        }
    });

    image.addListener(SWT.MouseExit, new org.eclipse.swt.widgets.Listener() {
        @Override
        public void handleEvent(org.eclipse.swt.widgets.Event event) {
            popupDialog.close();
        }
    });
}

From source file:org.eclipse.babel.editor.widgets.suggestion.PartialTranslationDialog.java

License:Open Source License

private void createDialog(final int shellStyle) {
    // int shellStyle = PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE;
    boolean takeFocusOnOpen = false;
    boolean persistSize = false;
    boolean persistLocation = false;
    boolean showDialogMenu = false;
    boolean showPersistActions = false;
    String titleText = null;/*  www  .j  av  a2  s.  c om*/
    dialog = new PopupDialog(shell, shellStyle, takeFocusOnOpen, persistSize, persistLocation, showDialogMenu,
            showPersistActions, titleText, infoText) {

        @Override
        protected Control createDialogArea(Composite parent) {
            composite = (Composite) super.createDialogArea(parent);

            composite.setLayout(new GridLayout(2, false));

            final Button button = new Button(composite, SWT.PUSH);
            button.setText("Apply");
            button.setEnabled(false);
            button.addSelectionListener(new SelectionListener() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    NullableText nText = (NullableText) PartialTranslationDialog.this.parent.getTextField()
                            .getParent();

                    nText.setText(PartialTranslationDialog.this.parent.getTextField().getText()
                            + textField.getSelectionText(), true);

                    PartialTranslationDialog.this.parent.dispose();
                }

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {
                }

            });

            Label label = new Label(composite, SWT.NONE);
            label.setText("Selected translation");

            FontData fontData = label.getFont().getFontData()[0];
            Font font = new Font(label.getDisplay(),
                    new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
            label.setFont(font);

            // Invisible separator
            new Label(composite, SWT.NONE);

            textField = new Text(composite, SWT.V_SCROLL | SWT.WRAP | SWT.MULTI | SWT.READ_ONLY | orientation);
            textField.setText(text);
            textField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
            textField.addListener(SWT.MouseUp, new Listener() {
                @Override
                public void handleEvent(Event event) {
                    Text text = (Text) event.widget;

                    String selection = text.getSelectionText();

                    if (selection.length() > 0 && !SuggestionErrors.contains(textField.getText())) {
                        button.setEnabled(true);
                    } else {
                        button.setEnabled(false);
                    }
                }
            });

            Listener scrollBarListener = new Listener() {
                @Override
                public void handleEvent(Event event) {
                    Text t = (Text) event.widget;
                    Rectangle r1 = t.getClientArea();
                    Rectangle r2 = t.computeTrim(r1.x, r1.y, r1.width, r1.height);
                    Point p = t.computeSize(composite.getSize().x, SWT.DEFAULT, true);
                    t.getVerticalBar().setVisible(r2.height <= p.y);
                }
            };

            textField.addListener(SWT.Resize, scrollBarListener);

            return composite;
        }

        @Override
        protected void adjustBounds() {
            super.adjustBounds();

            Point start = parent.getCurrentLocation();
            Point size = parent.getSize();

            int x = start.x + size.x;
            int y = start.y;
            int screenWidth = Display.getCurrent().getBounds().width;

            if (screenWidth - x <= 200) {
                x = start.x - 450;
            }

            getShell().setLocation(x, y);

            if (screenWidth - x < 450) {
                getShell().setSize(screenWidth - x, 200);
            } else {
                getShell().setSize(450, 200);
            }
        }

        @Override
        protected void configureShell(Shell shell) {
            super.configureShell(shell);

            if (win) {
                shell.addFocusListener(new FocusListener() {

                    @Override
                    public void focusGained(FocusEvent e) {
                        if (shellStyle == INFOPOPUPRESIZE_SHELLSTYLE || dialog == null) {
                            return;
                        }
                        dialog.close();
                        infoText = FOOT_NOTE_2;
                        createDialog(PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE);
                        dialog.open();
                        dialog.getShell().setFocus();
                    }

                    @Override
                    public void focusLost(FocusEvent e) {
                    }
                });
            }
        }
    };
}

From source file:org.eclipse.babel.editor.widgets.suggestion.SuggestionBubble.java

License:Open Source License

private void createDialog() {
    boolean takeFocusOnOpen = false;
    boolean persistSize = false;
    boolean persistLocation = false;
    boolean showDialogMenu = false;
    boolean showPersistActions = false;
    String titleText = "Suggestions (" + SRC_LANG + " > " + targetLanguage.toUpperCase() + ")";
    String infoText = "Ctrl+Space to display all suggestions";
    dialog = new PopupDialog(shell, SHELL_STYLE, takeFocusOnOpen, persistSize, persistLocation, showDialogMenu,
            showPersistActions, titleText, infoText) {

        @Override//from  w  ww  . j ava 2 s .  c  o  m
        protected Control createDialogArea(Composite parent) {
            scrollComposite = new ScrolledComposite((Composite) super.createDialogArea(parent),
                    SWT.V_SCROLL | SWT.H_SCROLL);
            scrollComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
            scrollComposite.setExpandVertical(true);
            scrollComposite.setExpandHorizontal(true);

            GridLayout gl = new GridLayout(1, true);
            gl.verticalSpacing = 0;
            composite = new Composite(scrollComposite, SWT.NONE);
            composite.setLayout(gl);
            scrollComposite.setContent(composite);

            tableViewer = new TableViewer(composite, SWT.NO_SCROLL);
            tableViewer.getTable().setLayoutData(new GridData(GridData.FILL, SWT.TOP, true, false));

            tableViewer.setContentProvider(new ArrayContentProvider());
            tableViewer.setLabelProvider(new ITableLabelProvider() {

                @Override
                public Image getColumnImage(Object arg0, int arg1) {
                    Suggestion s = (Suggestion) arg0;
                    return s.getIcon();
                }

                @Override
                public String getColumnText(Object element, int index) {
                    return ((Suggestion) element).getText();

                }

                @Override
                public void addListener(ILabelProviderListener listener) {
                    // nothing to do
                }

                @Override
                public void dispose() {
                    // nothing to do
                }

                @Override
                public boolean isLabelProperty(Object arg0, String arg1) {
                    return true;
                }

                @Override
                public void removeListener(ILabelProviderListener arg0) {
                    // nothing to do
                }
            });

            tableViewer.addFilter(suggestionFilter);

            tableViewer.addDoubleClickListener(new DoubleClickListener() {

                @Override
                public void doubleClick(DoubleClickEvent event) {
                    applySuggestion(text);
                }

            });

            tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

                @Override
                public void selectionChanged(SelectionChangedEvent event) {
                    if (tableViewer.getTable().getSelection().length > 0) {
                        partialTranslationDialog.openDialog(tableViewer.getTable().getSelection()[0].getText(),
                                text.getOrientation());
                    }
                }
            });

            // For Windows 7
            // Set background color of column line
            // tableViewer.getTable().addListener(SWT.EraseItem, new
            // Listener() {
            // @Override
            // public void handleEvent(Event event) {
            // event.gc.setBackground(new Color(shell.getDisplay(), 255,
            // 255, 225));
            // event.gc.fillRectangle(event.getBounds());
            // }
            // });

            tableViewer.getTable().setSelection(0);
            return scrollComposite;
        }

        @Override
        protected void adjustBounds() {
            super.adjustBounds();

            Point point = text.getCaretLocation();

            getShell().setLocation(text.toDisplay(1, 1).x + point.x + 5, text.toDisplay(1, 1).y + point.y + 20);

            getShell().setSize(450, 200);
        }

    };
    dialog.open();

    partialTranslationDialog = new PartialTranslationDialog(dialog.getShell(), this);

    dialog.getShell().addListener(SWT.Resize, new Listener() {
        public void handleEvent(Event e) {
            partialTranslationDialog.dispose();
        }
    });

    updateSuggestions();
}

From source file:org.eclipse.e4.ui.workbench.swt.internal.copy.ShowViewDialog.java

License:Open Source License

private void popUp(final String description) {
    new PopupDialog(filteredTree.getShell(), PopupDialog.HOVER_SHELLSTYLE, true, false, false, false, false,
            null, null) {//from   w ww  . ja  va 2s . c o m
        private static final int CURSOR_SIZE = 15;

        protected Point getInitialLocation(Point initialSize) {
            // show popup relative to cursor
            Display display = getShell().getDisplay();
            Point location = display.getCursorLocation();
            location.x += CURSOR_SIZE;
            location.y += CURSOR_SIZE;
            return location;
        }

        protected Control createDialogArea(Composite parent) {
            Label label = new Label(parent, SWT.WRAP);
            label.setText(description);
            label.addFocusListener(new FocusAdapter() {
                public void focusLost(FocusEvent event) {
                    close();
                }
            });
            // Use the compact margins employed by PopupDialog.
            GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
            gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
            gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
            label.setLayoutData(gd);
            return label;
        }
    }.open();
}

From source file:org.eclipse.gyrex.admin.ui.pages.FilteredAdminPage.java

License:Open Source License

void openFilterPopUp(final String filter, final Point location, final Runnable closeCallback) {
    final PopupDialog dialog = new PopupDialog(SwtUtil.getShell(filterPanel),
            SWT.NO_TRIM | SWT.NO_SCROLL | SWT.MODELESS, false, false, false, false, false, null, null) {

        /** serialVersionUID */
        private static final long serialVersionUID = 1L;

        @Override//from  ww w.  j a  v a 2  s  .c  om
        protected void adjustBounds() {
            getShell().pack(true);
            getShell().setLocation(location);
        }

        @Override
        public boolean close() {
            final boolean closed = super.close();
            if (!closed) {
                return closed;
            }

            if (null != closeCallback) {
                closeCallback.run();
            }
            return closed;
        }

        @Override
        protected void configureShell(final Shell shell) {
            super.configureShell(shell);
            shell.setLayout(new FillLayout());
            shell.setData(RWT.CUSTOM_VARIANT, "filter-popup"); //$NON-NLS-1$
        }

        @Override
        protected Control createContents(final Composite parent) {
            final Control control = createFilterControl(filter, parent);
            if (parent.getLayout() instanceof FillLayout) {
                final Control[] children = parent.getChildren();
                for (final Control child : children) {
                    if (null != child.getLayoutData()) {
                        throw new IllegalStateException(String.format(
                                "%s#createFilterControl not allowed to set layout data on children!",
                                FilteredAdminPage.this.getClass()));
                    }
                }
            }
            return control;
        }

        @Override
        public int open() {
            final int result = super.open();
            final Listener closeListener = new Listener() {
                /** serialVersionUID */
                private static final long serialVersionUID = 1L;

                @Override
                public void handleEvent(final Event event) {
                    close();
                }
            };
            getShell().addListener(SWT.Deactivate, closeListener);
            getShell().addListener(SWT.Close, closeListener);

            getShell().setActive();
            return result;
        }
    };

    dialog.open();
}

From source file:org.eclipse.ui.internal.dialogs.ShowViewDialog.java

License:Open Source License

private void popUp(final String description) {
    new PopupDialog(filteredTree.getShell(), PopupDialog.HOVER_SHELLSTYLE, true, false, false, false, false,
            null, null) {/*from w w  w.  j a v  a2 s .  c  om*/
        private static final int CURSOR_SIZE = 15;

        protected Point getInitialLocation(Point initialSize) {
            //show popup relative to cursor
            Display display = getShell().getDisplay();
            Point location = display.getCursorLocation();
            location.x += CURSOR_SIZE;
            location.y += CURSOR_SIZE;
            return location;
        }

        protected Control createDialogArea(Composite parent) {
            Label label = new Label(parent, SWT.WRAP);
            label.setText(description);
            label.addFocusListener(new FocusAdapter() {
                public void focusLost(FocusEvent event) {
                    close();
                }
            });
            // Use the compact margins employed by PopupDialog.
            GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
            gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
            gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
            label.setLayoutData(gd);
            return label;
        }
    }.open();
}

From source file:org.mwc.debrief.core.ResetPerspective.java

License:Open Source License

protected void showDialog(Shell shell, final String info) {
    final PopupDialog dialog = new PopupDialog(shell, PopupDialog.HOVER_SHELLSTYLE, true, false, false, false,
            false, null, null) {//from   ww  w  . java 2s .c  o  m

        @Override
        protected Control createDialogArea(Composite parent) {
            GridData gd = new GridData(GridData.FILL_BOTH);
            StyledText text = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP);
            text.setLayoutData(gd);
            text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
            text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
            text.setText(info);
            text.setEditable(false);
            return text;
        }
    };
    dialog.open();
}

From source file:pow.views.BPMNView.java

License:Open Source License

private void showMessage(String message) {
    //      MessageDialog.openInformation(
    //         viewer.getControl().getShell(),
    //         "BPMN Tree View",
    //         message);
    new PopupDialog(viewer.getControl().getShell(), PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE, true, false, false,
            false, false, "BPMN Tree View", message).open();
}