Example usage for org.eclipse.jface.util Util isGtk

List of usage examples for org.eclipse.jface.util Util isGtk

Introduction

In this page you can find the example usage for org.eclipse.jface.util Util isGtk.

Prototype

public static boolean isGtk() 

Source Link

Document

Common WS query helper method.

Usage

From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java

License:Open Source License

/**
 * Synchronizes the UI with the given property.
 *
 * @param propertyName/*from ww w  . ja  va  2 s.  c o m*/
 *          the name of the property, or <code>null</code> meaning all
 *          applicable properties
 */
@Override
public void update(String propertyName) {
    if (widget != null) {
        // determine what to do
        final boolean textChanged = (propertyName == null) || propertyName.equals(IAction.TEXT);
        boolean imageChanged = (propertyName == null) || propertyName.equals(IAction.IMAGE);
        final boolean tooltipTextChanged = (propertyName == null) || propertyName.equals(IAction.TOOL_TIP_TEXT);
        final boolean enableStateChanged = (propertyName == null) || propertyName.equals(IAction.ENABLED)
                || propertyName.equals(IContributionManagerOverrides.P_ENABLED);
        final boolean checkChanged = ((action.getStyle() == IAction.AS_CHECK_BOX)
                || (action.getStyle() == IAction.AS_RADIO_BUTTON))
                && ((propertyName == null) || propertyName.equals(IAction.CHECKED));

        if (!showImage) {
            //  do not update the image if not show image
            imageChanged = false;
        }
        if (widget instanceof ToolItem) {
            final ToolItem ti = (ToolItem) widget;
            String text = action.getText();
            // the set text is shown only if there is no image or if forced
            // by MODE_FORCE_TEXT
            final boolean showText = (text != null)
                    && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action));

            // only do the trimming if the text will be used
            if (showText && (text != null)) {
                text = Action.removeAcceleratorText(text);
                text = Action.removeMnemonics(text);
            }

            if (textChanged) {
                final String textToSet = showText ? text : ""; //$NON-NLS-1$
                final boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0;
                if (rightStyle || !ti.getText().equals(textToSet)) {
                    // In addition to being required to update the text if
                    // it
                    // gets nulled out in the action, this is also a
                    // workaround
                    // for bug 50151: Using SWT.RIGHT on a ToolBar leaves
                    // blank space
                    ti.setText(textToSet);
                }
            }

            if (imageChanged) {
                // only substitute a missing image if it has no text
                updateImages(!showText);
            }

            if (tooltipTextChanged || textChanged) {
                String toolTip = action.getToolTipText();
                if ((toolTip == null) || (toolTip.length() == 0)) {
                    toolTip = text;
                }

                final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance()
                        .getCallback();
                final String commandId = action.getActionDefinitionId();
                if ((callback != null) && (commandId != null) && (toolTip != null)) {
                    final String acceleratorText = callback.getAcceleratorText(commandId);
                    if ((acceleratorText != null) && (acceleratorText.length() != 0)) {
                        toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$
                                new Object[] { toolTip, acceleratorText });
                    }
                }

                // if the text is showing, then only set the tooltip if
                // different
                if (!showText || ((toolTip != null) && !toolTip.equals(text))) {
                    ti.setToolTipText(toolTip);
                } else {
                    ti.setToolTipText(null);
                }
            }

            if (enableStateChanged) {
                final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();

                if (ti.getEnabled() != shouldBeEnabled) {
                    ti.setEnabled(shouldBeEnabled);
                }
            }

            if (checkChanged) {
                final boolean bv = action.isChecked();

                if (ti.getSelection() != bv) {
                    ti.setSelection(bv);
                }
            }
            return;
        }

        if (widget instanceof MenuItem) {
            final MenuItem mi = (MenuItem) widget;

            if (textChanged) {
                int accelerator = 0;
                String acceleratorText = null;
                final ActionEx updatedAction = getAction();
                String text = null;
                accelerator = updatedAction.getAccelerator();
                final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance()
                        .getCallback();

                // Block accelerators that are already in use.
                if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) {
                    accelerator = 0;
                }

                /*
                 * Process accelerators on GTK in a special way to avoid Bug 42009. We
                 * will override the native input method by allowing these reserved
                 * accelerators to be placed on the menu. We will only do this for
                 * "Ctrl+Shift+[0-9A-FU]".
                 */
                final String commandId = updatedAction.getActionDefinitionId();
                if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) {
                    final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;
                    final IKeyLookup lookup = KeyLookupFactory.getDefault();
                    final TriggerSequence[] triggerSequences = bindingManagerCallback
                            .getActiveBindingsFor(commandId);
                    for (final TriggerSequence triggerSequence : triggerSequences) {
                        final Trigger[] triggers = triggerSequence.getTriggers();
                        if (triggers.length == 1) {
                            final Trigger trigger = triggers[0];
                            if (trigger instanceof KeyStroke) {
                                final KeyStroke currentKeyStroke = (KeyStroke) trigger;
                                final int currentNaturalKey = currentKeyStroke.getNaturalKey();
                                if ((currentKeyStroke
                                        .getModifierKeys() == (lookup.getCtrl() | lookup.getShift()))
                                        && (((currentNaturalKey >= '0') && (currentNaturalKey <= '9'))
                                                || ((currentNaturalKey >= 'A') && (currentNaturalKey <= 'F'))
                                                || (currentNaturalKey == 'U'))) {
                                    accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey;
                                    acceleratorText = triggerSequence.format();
                                    break;
                                }
                            }
                        }
                    }
                }

                if (accelerator == 0) {
                    if ((callback != null) && (commandId != null)) {
                        acceleratorText = callback.getAcceleratorText(commandId);
                    }
                }

                IContributionManagerOverrides overrides = null;

                if (getParent() != null) {
                    overrides = getParent().getOverrides();
                }

                if (overrides != null) {
                    text = getParent().getOverrides().getText(this);
                }

                mi.setAccelerator(accelerator);

                if (text == null) {
                    text = updatedAction.getText();
                }

                if ((text != null) && (acceleratorText == null)) {
                    // use extracted accelerator text in case accelerator
                    // cannot be fully represented in one int (e.g.
                    // multi-stroke keys)
                    acceleratorText = LegacyActionTools.extractAcceleratorText(text);
                    if ((acceleratorText == null) && (accelerator != 0)) {
                        acceleratorText = Action.convertAccelerator(accelerator);
                    }
                }

                if (text == null) {
                    text = ""; //$NON-NLS-1$
                } else {
                    text = Action.removeAcceleratorText(text);
                }

                // add "..." if the action will show a dialog
                if (updatedAction.isShowDialog()) {
                    text = text + dialogIndicator;
                }

                if (acceleratorText == null) {
                    mi.setText(text);
                } else {
                    mi.setText(text + '\t' + acceleratorText);
                }
            }

            if (imageChanged) {
                updateImages(false);
            }

            if (enableStateChanged) {
                final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();

                if (mi.getEnabled() != shouldBeEnabled) {
                    mi.setEnabled(shouldBeEnabled);
                }
            }

            if (checkChanged) {
                final boolean bv = action.isChecked();

                if (mi.getSelection() != bv) {
                    mi.setSelection(bv);
                }
            }

            return;
        }

        if (widget instanceof Button) {
            final Button button = (Button) widget;

            if (imageChanged) {
                updateImages(false);
            }

            if (textChanged) {
                String text = action.getText();
                final boolean showText = (text != null)
                        && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action));
                // only do the trimming if the text will be used
                if (showText) {
                    text = Action.removeAcceleratorText(text);
                }
                final String textToSet = showText ? text : ""; //$NON-NLS-1$
                button.setText(textToSet);
            }

            if (tooltipTextChanged) {
                button.setToolTipText(action.getToolTipText());
            }

            if (enableStateChanged) {
                final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();

                if (button.getEnabled() != shouldBeEnabled) {
                    button.setEnabled(shouldBeEnabled);
                }
            }

            if (checkChanged) {
                final boolean bv = action.isChecked();

                if (button.getSelection() != bv) {
                    button.setSelection(bv);
                }
            }
            return;
        }
    }
}

From source file:com.google.dart.tools.ui.internal.text.correction.proposals.ChangeCorrectionProposal.java

License:Open Source License

/**
 * Returns the change that will be executed when the proposal is applied.
 * /* w  w  w  . ja va 2 s  .  c o m*/
 * @return returns the change for this proposal.
 * @throws CoreException thrown when the change could not be created
 */
public final Change getChange() throws CoreException {
    if (Util.isGtk()) {
        // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=293995 :
        // [Widgets] Deadlock while UI thread displaying/computing a change proposal and non-UI thread creating image

        // Solution is to create the change outside a 'synchronized' block.
        // Synchronization is achieved by polling fChange, using "fChange == COMPUTING_CHANGE" as barrier.
        // Timeout of 10s for safety reasons (should not be reached).
        long end = System.currentTimeMillis() + 10000;
        do {
            boolean computing;
            synchronized (this) {
                computing = fChange == COMPUTING_CHANGE;
            }
            if (computing) {
                try {
                    Display display = Display.getCurrent();
                    if (display != null) {
                        while (!display.isDisposed() && display.readAndDispatch()) {
                        }
                        display.sleep();
                    } else {
                        Thread.sleep(100);
                    }
                } catch (InterruptedException e) {
                    //continue
                }
            } else {
                synchronized (this) {
                    if (fChange == COMPUTING_CHANGE) {
                        continue;
                    } else if (fChange != null) {
                        return fChange;
                    } else {
                        fChange = COMPUTING_CHANGE;
                    }
                }
                Change change = createChange();
                synchronized (this) {
                    fChange = change;
                }
                return change;
            }
        } while (System.currentTimeMillis() < end);

        synchronized (this) {
            if (fChange == COMPUTING_CHANGE) {
                return null; //failed
            }
        }

    } else {
        synchronized (this) {
            if (fChange == null) {
                fChange = createChange();
            }
        }
    }
    return fChange;
}

From source file:com.google.dart.tools.ui.omni.BasePopupDialog.java

License:Open Source License

/**
 * Show the dialog's menu. This message has no effect if the receiver was not configured to show a
 * menu. Clients may call this method in order to trigger the menu via keystrokes or other
 * gestures. Subclasses typically do not override method.
 *///from w  ww.j a  va2s.  c  om
protected void showDialogMenu() {
    if (!showDialogMenu) {
        return;
    }

    if (menuManager == null) {
        menuManager = new MenuManager();
        fillDialogMenu(menuManager);
    }
    // Setting this flag works around a problem that remains on X only,
    // whereby activating the menu deactivates our shell.
    listenToDeactivate = !Util.isGtk();

    Menu menu = menuManager.createContextMenu(getShell());
    Rectangle bounds = toolBar.getBounds();
    Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
    topLeft = getShell().toDisplay(topLeft);
    menu.setLocation(topLeft.x, topLeft.y);
    menu.setVisible(true);
}

From source file:com.redhat.ceylon.eclipse.code.correct.CorrectionProposal.java

License:Open Source License

/**
 * Returns the change that will be executed when the proposal is applied.
 * This method calls {@link #createChange()} to compute the change.
 * //from w ww  . j a v  a 2  s.co m
 * @return the change for this proposal, can be <code>null</code> in rare cases if creation of
 *         the change failed
 * @throws CoreException when the change could not be created
 */
public final Change getChange() throws CoreException {
    if (Util.isGtk()) {
        // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=293995 :
        // [Widgets] Deadlock while UI thread displaying/computing a change proposal and non-UI thread creating image

        // Solution is to create the change outside a 'synchronized' block.
        // Synchronization is achieved by polling fChange, using "fChange == COMPUTING_CHANGE" as barrier.
        // Timeout of 10s for safety reasons (should not be reached).
        long end = System.currentTimeMillis() + 10000;
        do {
            boolean computing;
            synchronized (this) {
                computing = change == COMPUTING_CHANGE;
            }
            if (computing) {
                try {
                    Display display = Display.getCurrent();
                    if (display != null) {
                        while (!display.isDisposed() && display.readAndDispatch()) {
                            // empty the display loop
                        }
                        display.sleep();
                    } else {
                        Thread.sleep(100);
                    }
                } catch (InterruptedException e) {
                    //continue
                }
            } else {
                synchronized (this) {
                    if (change == COMPUTING_CHANGE) {
                        continue;
                    } else if (change != null) {
                        return change;
                    } else {
                        change = COMPUTING_CHANGE;
                    }
                }
                Change change = createChange();
                synchronized (this) {
                    this.change = change;
                }
                return change;
            }
        } while (System.currentTimeMillis() < end);

        synchronized (this) {
            if (change == COMPUTING_CHANGE) {
                return null; //failed
            }
        }

    } else {
        synchronized (this) {
            if (change == null) {
                change = createChange();
            }
        }
    }
    return change;
}

From source file:net.yatomiya.e4.ui.internal.workbench.renderers.swt.AbstractTableInformationControl.java

License:Open Source License

/**
 * Creates an information control with the given shell as parent. The given
 * styles are applied to the shell and the table widget.
 *
 * @param parent/*w w  w  . ja va2 s .c  o m*/
 *            the parent shell
 * @param shellStyle
 *            the additional styles for the shell
 * @param controlStyle
 *            the additional styles for the control
 */
public AbstractTableInformationControl(Shell parent, int shellStyle, int controlStyle) {
    fShell = new Shell(parent, shellStyle);
    fShell.setLayout(new FillLayout());

    // Composite for filter text and viewer
    fComposite = new Composite(fShell, SWT.RESIZE);
    GridLayout layout = new GridLayout(1, false);
    fComposite.setLayout(layout);
    createFilterText(fComposite);

    fTableViewer = createTableViewer(fComposite, controlStyle);

    final Table table = fTableViewer.getTable();
    table.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent e) {
            switch (e.keyCode) {
            case SWT.ESC:
                dispose();
                break;
            case SWT.DEL:
                removeSelectedItems();
                e.character = SWT.NONE;
                e.doit = false;
                break;
            case SWT.ARROW_UP:
                if (table.getSelectionIndex() == 0) {
                    // on the first item, going up should grant focus to
                    // text field
                    fFilterText.setFocus();
                }
                break;
            case SWT.ARROW_DOWN:
                if (table.getSelectionIndex() == table.getItemCount() - 1) {
                    // on the last item, going down should grant focus to
                    // the text field
                    fFilterText.setFocus();
                }
                break;
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });

    table.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // do nothing;
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            gotoSelectedElement();
        }
    });

    /*
     * Bug in GTK, see SWT bug: 62405 Editor drop down performance slow on
     * Linux-GTK on mouse move. Rather then removing the support altogether
     * this feature has been worked around for GTK only as we expect that
     * newer versions of GTK will no longer exhibit this quality and we will
     * be able to have the desired support running on all platforms. See
     * comment https://bugs.eclipse.org/bugs/show_bug.cgi?id=62405#c22 TODO:
     * remove this code once bug 62405 is fixed for the mainstream GTK
     * version
     */
    final int ignoreEventCount = Util.isGtk() ? 4 : 1;

    table.addMouseMoveListener(new MouseMoveListener() {
        TableItem fLastItem = null;
        int lastY = 0;
        int itemHeightdiv4 = table.getItemHeight() / 4;
        int tableHeight = table.getBounds().height;
        Point tableLoc = table.toDisplay(0, 0);
        int divCount = 0;

        @Override
        public void mouseMove(MouseEvent e) {
            if (divCount == ignoreEventCount) {
                divCount = 0;
            }
            if (table.equals(e.getSource()) & ++divCount == ignoreEventCount) {
                Object o = table.getItem(new Point(e.x, e.y));
                if (fLastItem == null ^ o == null) {
                    table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                }
                if (o instanceof TableItem && lastY != e.y) {
                    lastY = e.y;
                    if (!o.equals(fLastItem)) {
                        fLastItem = (TableItem) o;
                        table.setSelection(new TableItem[] { fLastItem });
                    } else if (e.y < itemHeightdiv4) {
                        // Scroll up
                        Item item = fTableViewer.scrollUp(e.x + tableLoc.x, e.y + tableLoc.y);
                        if (item instanceof TableItem) {
                            fLastItem = (TableItem) item;
                            table.setSelection(new TableItem[] { fLastItem });
                        }
                    } else if (e.y > tableHeight - itemHeightdiv4) {
                        // Scroll down
                        Item item = fTableViewer.scrollDown(e.x + tableLoc.x, e.y + tableLoc.y);
                        if (item instanceof TableItem) {
                            fLastItem = (TableItem) item;
                            table.setSelection(new TableItem[] { fLastItem });
                        }
                    }
                } else if (o == null) {
                    fLastItem = null;
                }
            }
        }
    });

    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {
            if (table.getSelectionCount() < 1) {
                return;
            }

            if (e.button == 1) {
                if (table.equals(e.getSource())) {
                    Object o = table.getItem(new Point(e.x, e.y));
                    TableItem selection = table.getSelection()[0];
                    if (selection.equals(o)) {
                        gotoSelectedElement();
                    }
                }
            }
            if (e.button == 3) {
                TableItem tItem = fTableViewer.getTable().getItem(new Point(e.x, e.y));
                if (tItem != null) {
                    Menu menu = new Menu(fTableViewer.getTable());
                    MenuItem mItem = new MenuItem(menu, SWT.NONE);
                    mItem.setText(SWTRenderersMessages.menuClose);
                    mItem.addSelectionListener(new SelectionAdapter() {
                        @Override
                        public void widgetSelected(SelectionEvent selectionEvent) {
                            removeSelectedItems();
                        }
                    });
                    menu.setVisible(true);
                }
            }
        }
    });

    fShell.addTraverseListener(new TraverseListener() {
        @Override
        public void keyTraversed(TraverseEvent e) {
            switch (e.detail) {
            case SWT.TRAVERSE_PAGE_NEXT:
                e.detail = SWT.TRAVERSE_NONE;
                e.doit = true; {
                int n = table.getItemCount();
                if (n == 0)
                    return;

                int i = table.getSelectionIndex() + 1;
                if (i >= n)
                    i = 0;
                table.setSelection(i);
            }
                break;

            case SWT.TRAVERSE_PAGE_PREVIOUS:
                e.detail = SWT.TRAVERSE_NONE;
                e.doit = true; {
                int n = table.getItemCount();
                if (n == 0)
                    return;

                int i = table.getSelectionIndex() - 1;
                if (i < 0)
                    i = n - 1;
                table.setSelection(i);
            }
                break;
            }
        }
    });

    setInfoSystemColor();
    installFilter();
}

From source file:org.eclipse.e4.ui.internal.workbench.renderers.swt.AbstractTableInformationControl.java

License:Open Source License

/**
 * Creates an information control with the given shell as parent. The given
 * styles are applied to the shell and the table widget.
 * /*from  ww w . jav  a2  s .  co m*/
 * @param parent
 *            the parent shell
 * @param shellStyle
 *            the additional styles for the shell
 * @param controlStyle
 *            the additional styles for the control
 */
public AbstractTableInformationControl(Shell parent, int shellStyle, int controlStyle) {
    fShell = new Shell(parent, shellStyle);
    fShell.setLayout(new FillLayout());

    // Composite for filter text and viewer
    fComposite = new Composite(fShell, SWT.RESIZE);
    GridLayout layout = new GridLayout(1, false);
    fComposite.setLayout(layout);
    createFilterText(fComposite);

    fTableViewer = createTableViewer(fComposite, controlStyle);

    final Table table = fTableViewer.getTable();
    table.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            switch (e.keyCode) {
            case SWT.ESC:
                dispose();
                break;
            case SWT.DEL:
                removeSelectedItems();
                e.character = SWT.NONE;
                e.doit = false;
                break;
            case SWT.ARROW_UP:
                if (table.getSelectionIndex() == 0) {
                    // on the first item, going up should grant focus to
                    // text field
                    fFilterText.setFocus();
                }
                break;
            case SWT.ARROW_DOWN:
                if (table.getSelectionIndex() == table.getItemCount() - 1) {
                    // on the last item, going down should grant focus to
                    // the text field
                    fFilterText.setFocus();
                }
                break;
            }
        }

        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });

    table.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            // do nothing;
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            gotoSelectedElement();
        }
    });

    /*
     * Bug in GTK, see SWT bug: 62405 Editor drop down performance slow on
     * Linux-GTK on mouse move. Rather then removing the support altogether
     * this feature has been worked around for GTK only as we expect that
     * newer versions of GTK will no longer exhibit this quality and we will
     * be able to have the desired support running on all platforms. See
     * comment https://bugs.eclipse.org/bugs/show_bug.cgi?id=62405#c22 TODO:
     * remove this code once bug 62405 is fixed for the mainstream GTK
     * version
     */
    final int ignoreEventCount = Util.isGtk() ? 4 : 1;

    table.addMouseMoveListener(new MouseMoveListener() {
        TableItem fLastItem = null;
        int lastY = 0;
        int itemHeightdiv4 = table.getItemHeight() / 4;
        int tableHeight = table.getBounds().height;
        Point tableLoc = table.toDisplay(0, 0);
        int divCount = 0;

        public void mouseMove(MouseEvent e) {
            if (divCount == ignoreEventCount) {
                divCount = 0;
            }
            if (table.equals(e.getSource()) & ++divCount == ignoreEventCount) {
                Object o = table.getItem(new Point(e.x, e.y));
                if (fLastItem == null ^ o == null) {
                    table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                }
                if (o instanceof TableItem && lastY != e.y) {
                    lastY = e.y;
                    if (!o.equals(fLastItem)) {
                        fLastItem = (TableItem) o;
                        table.setSelection(new TableItem[] { fLastItem });
                    } else if (e.y < itemHeightdiv4) {
                        // Scroll up
                        Item item = fTableViewer.scrollUp(e.x + tableLoc.x, e.y + tableLoc.y);
                        if (item instanceof TableItem) {
                            fLastItem = (TableItem) item;
                            table.setSelection(new TableItem[] { fLastItem });
                        }
                    } else if (e.y > tableHeight - itemHeightdiv4) {
                        // Scroll down
                        Item item = fTableViewer.scrollDown(e.x + tableLoc.x, e.y + tableLoc.y);
                        if (item instanceof TableItem) {
                            fLastItem = (TableItem) item;
                            table.setSelection(new TableItem[] { fLastItem });
                        }
                    }
                } else if (o == null) {
                    fLastItem = null;
                }
            }
        }
    });

    table.addMouseListener(new MouseAdapter() {
        public void mouseUp(MouseEvent e) {
            if (table.getSelectionCount() < 1) {
                return;
            }

            if (e.button == 1) {
                if (table.equals(e.getSource())) {
                    Object o = table.getItem(new Point(e.x, e.y));
                    TableItem selection = table.getSelection()[0];
                    if (selection.equals(o)) {
                        gotoSelectedElement();
                    }
                }
            }
            if (e.button == 3) {
                TableItem tItem = fTableViewer.getTable().getItem(new Point(e.x, e.y));
                if (tItem != null) {
                    Menu menu = new Menu(fTableViewer.getTable());
                    MenuItem mItem = new MenuItem(menu, SWT.NONE);
                    mItem.setText(SWTRenderersMessages.menuClose);
                    mItem.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent selectionEvent) {
                            removeSelectedItems();
                        }
                    });
                    menu.setVisible(true);
                }
            }
        }
    });

    fShell.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            switch (e.detail) {
            case SWT.TRAVERSE_PAGE_NEXT:
                e.detail = SWT.TRAVERSE_NONE;
                e.doit = true; {
                int n = table.getItemCount();
                if (n == 0)
                    return;

                int i = table.getSelectionIndex() + 1;
                if (i >= n)
                    i = 0;
                table.setSelection(i);
            }
                break;

            case SWT.TRAVERSE_PAGE_PREVIOUS:
                e.detail = SWT.TRAVERSE_NONE;
                e.doit = true; {
                int n = table.getItemCount();
                if (n == 0)
                    return;

                int i = table.getSelectionIndex() - 1;
                if (i < 0)
                    i = n - 1;
                table.setSelection(i);
            }
                break;
            }
        }
    });

    setInfoSystemColor();
    installFilter();
}

From source file:org.eclipse.edt.ide.ui.internal.quickfix.proposals.ChangeCorrectionProposal.java

License:Open Source License

public final Change getChange() throws CoreException {
    if (Util.isGtk()) {
        long end = System.currentTimeMillis() + 10000;
        do {//  w w w .  j  ava  2 s  . c  om
            boolean computing;
            synchronized (this) {
                computing = fChange == COMPUTING_CHANGE;
            }
            if (computing) {
                try {
                    Display display = Display.getCurrent();
                    if (display != null) {
                        while (!display.isDisposed() && display.readAndDispatch()) {
                        }
                        display.sleep();
                    } else {
                        Thread.sleep(100);
                    }
                } catch (InterruptedException e) {
                    //continue
                }
            } else {
                synchronized (this) {
                    if (fChange == COMPUTING_CHANGE) {
                        continue;
                    } else if (fChange != null) {
                        return fChange;
                    } else {
                        fChange = COMPUTING_CHANGE;
                    }
                }
                Change change = createChange();
                synchronized (this) {
                    fChange = change;
                }
                return change;
            }
        } while (System.currentTimeMillis() < end);

        synchronized (this) {
            if (fChange == COMPUTING_CHANGE) {
                return null; //failed
            }
        }

    } else {
        synchronized (this) {
            if (fChange == null) {
                fChange = createChange();
            }
        }
    }
    return fChange;
}

From source file:org.eclipse.riena.ui.swt.layout.DpiTableColumnLayout.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  ww .ja  va  2 s. c om*/
 * 
 * @see org.eclipse.jface.layout.AbstractColumnLayout#updateColumnData(org.eclipse.swt.widgets.Widget)
 */
@Override
protected void updateColumnData(final Widget column) {
    final TableColumn tColumn = (TableColumn) column;
    final Table t = tColumn.getParent();

    if (!Util.isGtk() || t.getColumn(t.getColumnCount() - 1) != tColumn) {
        tColumn.setData(LAYOUT_DATA, new ColumnPixelData(tColumn.getWidth()));
        layout(t.getParent(), true);
    }
}

From source file:org.eclipse.ui.internal.ide.IDEPreferenceInitializer.java

License:Open Source License

/**
 * The default command for launching the system explorer on this platform.
 *
 * @return The default command which launches the system explorer on this system, or an empty
 *         string if no default exists// w  w  w.  j  av a2s .c  o  m
 * @see ShowInSystemExplorerHandler#getDefaultCommand()
 */
public static String getShowInSystemExplorerCommand() {
    // See https://bugs.eclipse.org/419940 why it is implemented in here and not in ShowInSystemExplorerHandler#getDefaultCommand()
    if (Util.isGtk()) {
        return "dbus-send --print-reply --dest=org.freedesktop.FileManager1 /org/freedesktop/FileManager1 org.freedesktop.FileManager1.ShowItems array:string:\"${selected_resource_uri}\" string:\"\""; //$NON-NLS-1$
    } else if (Util.isWindows()) {
        return "explorer /E,/select=${selected_resource_loc}"; //$NON-NLS-1$
    } else if (Util.isMac()) {
        return "open -R \"${selected_resource_loc}\""; //$NON-NLS-1$
    }

    // if all else fails, return empty default
    return ""; //$NON-NLS-1$
}

From source file:org.eclipse.ui.internal.keys.NativeModifierKeyComparator.java

License:Open Source License

/**
 * Calculates a rank for a given modifier key.
 * /*from www  . j a va 2  s .co m*/
 * @param modifierKey
 *            The modifier key to rank; may be <code>null</code>.
 * @return The rank of this modifier key. This is a non-negative number
 *         where a lower number suggests a higher rank.
 */
private int rank(ModifierKey modifierKey) {

    if (Util.isWindows()) {
        return rankWindows(modifierKey);
    }

    if (Util.isGtk()) {
        // TODO Do a look-up on window manager.
        return rankGNOME(modifierKey);
    }

    if (Util.isMac()) {
        return rankMacOSX(modifierKey);
    }

    if (Util.isMotif()) {
        // TODO Do a look-up on window manager.
        return rankGNOME(modifierKey);
    }

    return UNKNOWN_KEY;
}