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

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

Introduction

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

Prototype

public static boolean isMac() 

Source Link

Document

Common WS query helper method.

Usage

From source file:at.bestsolution.efxclipse.tooling.ui.handler.OpenWithFXMLHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEvaluationContext context = (IEvaluationContext) event.getApplicationContext();
    ISelection s = (ISelection) context.getVariable(ISources.ACTIVE_MENU_SELECTION_NAME);
    if (s instanceof IStructuredSelection) {
        Object o = ((IStructuredSelection) s).getFirstElement();
        if (o instanceof IFile) {
            IFile f = (IFile) o;//from  w w w.  j a v  a 2s.  c o  m
            String scenebuilder = InstanceScope.INSTANCE.getNode("at.bestsolution.efxclipse.tooling.ui")
                    .get("scenebuilder.exe", null);
            if (scenebuilder != null) {
                try {
                    String executable = scenebuilder;
                    if (Util.isMac()) {
                        executable += "/Contents/MacOS/scenebuilder-launcher.sh";
                    }
                    Runtime.getRuntime()
                            .exec(new String[] { executable, f.getLocation().toFile().getAbsolutePath() });
                } catch (IOException e) {
                    MessageDialog.openError(HandlerUtil.getActiveShell(event), "Launch failed",
                            "Failed to launch SceneBuilder. The error message was: " + e.getMessage());
                }
            } else {
                if (Program.findProgram(".fxml") != null) {
                    if (!Program.launch(f.getLocation().toFile().getAbsolutePath())) {
                        MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Unable to open file",
                                "Opening the file with SceneBuilder failed. Try setting the absolute path to scenebuilder in your the preferences");
                    }
                } else {
                    MessageDialog.openInformation(HandlerUtil.getActiveShell(event), "Unable to open file",
                            "Opening the file with SceneBuilder failed. Try setting the absolute path to scenebuilder in your the preferences");
                }
            }
        }
    }
    return null;
}

From source file:br.ufes.inf.nemo.ontouml.transformation.onto2info.ui.util.EmulatedNativeCheckBoxLabelProvider.java

License:Open Source License

private Image makeShot(Control control, boolean type) {
    // Hopefully no platform uses exactly this color because we'll make
    // it transparent in the image.
    Color greenScreen = new Color(control.getDisplay(), 222, 223, 224);

    Shell shell = new Shell(control.getShell(), SWT.NO_TRIM);

    // otherwise we have a default gray color
    shell.setBackground(greenScreen);/*  w w w  .  j a va2  s  .  c  om*/

    if (Util.isMac()) {
        Button button2 = new Button(shell, SWT.CHECK);
        Point bsize = button2.computeSize(SWT.DEFAULT, SWT.DEFAULT);

        // otherwise an image is stretched by width
        bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
        bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
        button2.setSize(bsize);
        button2.setLocation(100, 100);
    }

    Button button = new Button(shell, SWT.CHECK);
    button.setBackground(greenScreen);
    button.setSelection(type);

    // otherwise an image is located in a corner
    button.setLocation(1, 1);
    Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    // otherwise an image is stretched by width
    bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
    bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
    button.setSize(bsize);

    shell.setSize(bsize);

    shell.open();

    GC gc = new GC(shell);
    Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
    gc.copyArea(image, 0, 0);
    gc.dispose();
    shell.close();

    ImageData imageData = image.getImageData();
    imageData.transparentPixel = imageData.palette.getPixel(greenScreen.getRGB());

    Image img = new Image(control.getDisplay(), imageData);
    image.dispose();

    return img;
}

From source file:codemirror.eclipse.swt.search.FindReplaceDialog.java

License:Open Source License

protected Control createContents(Composite parent) {

    Composite panel = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;/*from w w  w . ja  v  a  2s  .c  o m*/
    layout.makeColumnsEqualWidth = true;
    panel.setLayout(layout);
    panel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Composite inputPanel = createInputPanel(panel);
    setGridData(inputPanel, SWT.FILL, true, SWT.TOP, false);

    Composite configPanel = createConfigPanel(panel);
    setGridData(configPanel, SWT.FILL, true, SWT.TOP, true);

    Composite buttonPanelB = createButtonSection(panel);
    setGridData(buttonPanelB, SWT.RIGHT, true, SWT.BOTTOM, false);

    Composite statusBar = createStatusAndCloseButton(panel);
    setGridData(statusBar, SWT.FILL, true, SWT.BOTTOM, false);

    panel.addTraverseListener(new TraverseListener() {
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                if (!Util.isMac()) {
                    Control controlWithFocus = getShell().getDisplay().getFocusControl();
                    if (controlWithFocus != null && (controlWithFocus.getStyle() & SWT.PUSH) == SWT.PUSH)
                        return;
                }
                Event event = new Event();
                event.type = SWT.Selection;
                event.stateMask = e.stateMask;
                fFindNextButton.notifyListeners(SWT.Selection, event);
                e.doit = false;
            } else if (e.detail == TRAVERSE_MNEMONIC) {
                Character mnemonic = new Character(Character.toLowerCase(e.character));
                if (fMnemonicButtonMap.containsKey(mnemonic)) {
                    Button button = (Button) fMnemonicButtonMap.get(mnemonic);
                    if ((fFindField.isFocusControl() || fReplaceField.isFocusControl()
                            || (button.getStyle() & SWT.PUSH) != 0) && button.isEnabled()) {
                        Event event = new Event();
                        event.type = SWT.Selection;
                        event.stateMask = e.stateMask;
                        if ((button.getStyle() & SWT.RADIO) != 0) {
                            Composite buttonParent = button.getParent();
                            if (buttonParent != null) {
                                Control[] children = buttonParent.getChildren();
                                for (int i = 0; i < children.length; i++)
                                    ((Button) children[i]).setSelection(false);
                            }
                            button.setSelection(true);
                        } else {
                            button.setSelection(!button.getSelection());
                        }
                        button.notifyListeners(SWT.Selection, event);
                        e.detail = SWT.TRAVERSE_NONE;
                        e.doit = true;
                    }
                }
            }
        }
    });

    updateButtonState();

    applyDialogFont(panel);

    return panel;
}

From source file:com.github.haixing_hu.swt.window.ApplicationWindowEx.java

License:Open Source License

/**
 * Returns whether to show a top separator line between the menu bar
 * and the rest of the window contents.  On some platforms such as the Mac,
 * the menu is separated from the main window already, so a separator line
 * is not desired./*from  www. jav  a  2  s .  c o  m*/
 *
 * @return <code>true</code> to show the top separator, <code>false</code>
 *   to not show it
 * @since 3.0
 */
protected boolean showTopSeperator() {
    return !Util.isMac();
}

From source file:com.google.dart.tools.deploy.ApplicationActionBarAdvisor.java

License:Open Source License

/**
 * Creates and returns the File menu./*  w  ww .  j  a v  a 2  s .c o m*/
 */
private MenuManager createFileMenu() {
    MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_file, IWorkbenchActionConstants.M_FILE);
    menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));

    Action newApplicationAction = new OpenNewApplicationWizardAction();
    OpenNewFileWizardAction newFileAction = new OpenNewFileWizardAction(getWindow());
    menu.add(newApplicationAction);
    menu.add(newFileAction);
    OpenNewFolderWizardAction newFolderAction = new OpenNewFolderWizardAction(getWindow());
    menu.add(newFolderAction);

    menu.add(new Separator());
    IAction openFolderAction = OpenFolderHandler.createCommandAction(getWindow());
    menu.add(openFolderAction);

    menu.add(new Separator());

    menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

    menu.add(new Separator());

    menu.add(closeAction);
    menu.add(closeAllAction);

    //      menu.add(closeAllSavedAction);
    menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
    menu.add(new Separator());
    menu.add(saveAction);
    //TODO (keertip) : renable when we have save as implemented
    //  menu.add(saveAsAction);
    menu.add(saveAllAction);
    menu.add(actionFactory.getRevertItem());
    menu.add(new Separator());
    //TODO (pquitslund): re-enable when we have proper refactoring support implemented
    //    menu.add(actionFactory.getMoveItem());
    //    menu.add(actionFactory.getRenameItem());

    menu.add(actionFactory.getRefreshItem());

    menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
    //menu.add(new Separator());
    //menu.add(actionFactory.getPrintItem());
    //menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
    //menu.add(new Separator());
    //menu.add(importResourcesAction);
    //menu.add(exportResourcesAction);
    //menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
    //menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

    //    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    //    menu.add(new Separator());
    //    menu.add(actionFactory.getPropertiesItem());

    menu.add(ContributionItemFactory.REOPEN_EDITORS.create(getWindow()));
    menu.add(new GroupMarker(IWorkbenchActionConstants.MRU));
    menu.add(new Separator());

    // If we're on OS X we shouldn't show this command in the File menu. It
    // should be invisible to the user. However, we should not remove it -
    // the carbon UI code will do a search through our menu structure
    // looking for it when Cmd-Q is invoked (or Quit is chosen from the
    // application menu.
    ActionContributionItem quitItem = new ActionContributionItem(quitAction);
    quitItem.setVisible(!Util.isMac());
    menu.add(quitItem);
    menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
    return menu;
}

From source file:com.google.dart.tools.deploy.ApplicationActionBarAdvisor.java

License:Open Source License

/**
 * Creates and returns the Help menu.//from www  . j a  va 2  s.c  o  m
 */
private MenuManager createHelpMenu() {
    MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_help, IWorkbenchActionConstants.M_HELP);

    menu.add(new Separator("group.assist")); //$NON-NLS-1$
    menu.add(new Separator("group.main")); //$NON-NLS-1$
    menu.add(openApiDocsAction);
    menu.add(openOnlineDocsAction);

    // HELP_START should really be the first item, but it was after
    // quickStartAction and tipsAndTricksAction in 2.1.
    menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
    menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
    menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
    addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);

    // about should always be at the bottom
    menu.add(new Separator("group.about")); //$NON-NLS-1$

    ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
    aboutItem.setVisible(!Util.isMac());
    menu.add(aboutItem);
    menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
    return menu;
}

From source file:com.google.dart.tools.deploy.ApplicationActionBarAdvisor.java

License:Open Source License

/**
 * Creates and returns the Window menu./*from  w  ww  .  j a v  a2 s .co m*/
 */
private MenuManager createToolsMenu() {
    MenuManager menu = new MenuManager(WorkbenchMessages.tools_menu, IWorkbenchActionConstants.M_WINDOW);

    menu.add(new OpenIntroEditorAction());

    menu.add(new Separator());

    addViewActions(menu);

    menu.add(new Separator());

    menu.add(deployOptimizedAction);
    menu.add(generateDartdocAction);

    menu.add(new Separator());

    menu.add(pubInstallAction);
    menu.add(pubUpdateAction);

    menu.add(new Separator());

    menu.add(cleanAllAction);

    Separator sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS);
    sep.setVisible(!Util.isMac());
    menu.add(sep);

    //if (Util.isCocoa()) {
    //  menu.add(arrangeWindowsItem);
    //}

    // See the comment for quit in createFileMenu
    if (!Util.isMac()) {
        menu.add(new ActionContributionItem(openPreferencesAction));
    }

    //menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));
    return menu;
}

From source file:com.google.dart.tools.deploy.DartIDEApplication.java

License:Open Source License

private void setWorkspaceLocation() {
    Location workspaceLocation = Platform.getInstanceLocation();

    File userHomeDir = new File(System.getProperty("user.home"));
    URL workspaceUrl;/*from ww  w.  j  ava2  s.  co  m*/

    try {
        if (Util.isMac()) {
            workspaceUrl = new URL("file", null,
                    System.getProperty("user.home") + "/Library/Application Support/DartEditor");
        } else if (Util.isWindows()) {
            File workspaceDir = new File(userHomeDir, "DartEditor");
            workspaceUrl = workspaceDir.toURI().toURL();
        } else {
            File workspaceDir = new File(userHomeDir, ".dartEditor");
            workspaceUrl = workspaceDir.toURI().toURL();
        }

        workspaceLocation.set(workspaceUrl, true);
    } catch (IllegalStateException e) {
        // This generally happens in a runtime workbench, when the application has not been launched
        // with -data @noDefault. workspaceLocation.set() cannot be called twice.
        //Activator.logError(e);
    } catch (IOException e) {
        Activator.logError(e);
    }
}

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

License:Open Source License

private void openPopup() {
    popup = new Popup(getWorkbenchWindow(), null);
    popup.setFilterControl(textControl);
    popup.open();//from  ww  w . j  a va2 s. co  m

    if (Util.isMac()) {
        textControl.addListener(SWT.Deactivate, new Listener() {
            @Override
            public void handleEvent(Event event) {
                //selecting the scrollbar will deactivate but in that case we don't want to close
                // TODO: bug; going from scrollbar back to text entry clears text!
                Control focusControl = event.display.getFocusControl();
                //in some cases the focus control goes null even though the text still receives
                //key events (issue 1905) and we want to *not* close the popup
                if (focusControl != null && focusControl != popup.table) {
                    popup.close();
                }
                textControl.removeListener(SWT.Deactivate, this);
            }
        });
    }

}

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

License:Open Source License

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

    boolean isWin32 = Util.isWindows();
    GridLayoutFactory.fillDefaults().extendedMargins(isWin32 ? 0 : 3, 3, 2, 2).applyTo(composite);
    Composite tableComposite = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);

    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableColumnLayout);

    table = new Table(tableComposite, SWT.SINGLE | SWT.FULL_SELECTION);
    textLayout = new TextLayout(table.getDisplay());
    textLayout.setOrientation(getDefaultOrientation());
    Font boldFont = resourceManager
            .createFont(FontDescriptor.createFrom(JFaceResources.getDialogFont()).setStyle(SWT.BOLD));
    textLayout.setFont(table.getFont());
    textLayout.setText(OmniBoxMessages.OmniBox_Providers);
    int maxProviderWidth = (int) (textLayout.getBounds().width * 1.1);
    textLayout.setFont(boldFont);/*from   w  ww . j  a  v  a 2  s.com*/
    for (int i = 0; i < providers.length; i++) {
        OmniProposalProvider provider = providers[i];
        textLayout.setText(provider.getName());
        int width = (int) (textLayout.getBounds().width * 1.1);
        if (width > maxProviderWidth) {
            maxProviderWidth = width;
        }
    }

    //TODO (pquitslund): just a placeholder column for now
    tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE),
            new ColumnWeightData(0, 3 /* maxProviderWidth) */));
    tableColumnLayout.setColumnData(new TableColumn(table, SWT.NONE), new ColumnWeightData(100, 100));

    //TODO (pquitslund): and with this goes the ability to resize...
    //    table.getShell().addControlListener(new ControlAdapter() {
    //      @Override
    //      public void controlResized(ControlEvent e) {
    //        if (!showAllMatches) {
    //          if (!resized) {
    //            resized = true;
    //            e.display.timerExec(100, new Runnable() {
    //              @Override
    //              public void run() {
    //                if (getShell() != null && !getShell().isDisposed()) {
    //                  refresh(getFilterText());
    //                }
    //                resized = false;
    //              }
    //
    //            });
    //          }
    //        }
    //      }
    //    });

    /*
     * Since the control is unfocused, we need to hijack paint events and draw our own selections.
     */
    final Color selectionColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
    table.addListener(SWT.EraseItem, new Listener() {
        @Override
        public void handleEvent(Event event) {
            event.detail &= ~SWT.HOT;
            if ((event.detail & SWT.SELECTED) == 0) {
                return; /* item not selected */
            }

            Widget item = event.item;
            if (item instanceof TableItem) {
                Object data = ((TableItem) item).getData();
                if (data instanceof OmniEntry) {
                    if (((OmniEntry) data).element instanceof HeaderElement) {
                        event.detail &= ~SWT.SELECTED;
                        return;
                    }
                }
            }

            int clientWidth = table.getClientArea().width;
            GC gc = event.gc;
            Color oldBackground = gc.getBackground();
            gc.setBackground(selectionColor);
            gc.fillRectangle(new Rectangle(0, event.y, clientWidth, event.height));
            gc.setBackground(oldBackground);
            event.detail &= ~SWT.SELECTED;
        }
    });

    table.addKeyListener(getKeyAdapter());
    table.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.ARROW_UP && table.getSelectionIndex() == 0) {
                setFilterFocus();
            } else if (e.character == SWT.ESC) {
                close();
            }
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // do nothing
        }
    });
    table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseUp(MouseEvent e) {

            if (table.getSelectionCount() < 1) {
                return;
            }

            if (e.button != 1) {
                return;
            }

            if (table.equals(e.getSource())) {
                Object o = table.getItem(new Point(e.x, e.y));
                TableItem selection = table.getSelection()[0];
                if (selection.equals(o)) {
                    handleSelection();
                }
            }
        }
    });
    table.addMouseMoveListener(new MouseMoveListener() {
        TableItem lastItem = null;

        @Override
        public void mouseMove(MouseEvent e) {
            if (table.equals(e.getSource())) {
                Object o = table.getItem(new Point(e.x, e.y));
                if (lastItem == null ^ o == null) {
                    table.setCursor(o == null ? null : table.getDisplay().getSystemCursor(SWT.CURSOR_HAND));
                }
                if (o instanceof TableItem) {
                    if (!o.equals(lastItem)) {
                        lastItem = (TableItem) o;
                        table.setSelection(new TableItem[] { lastItem });
                    }
                } else if (o == null) {
                    lastItem = null;
                }
            }
        }
    });

    table.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            handleSelection();
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (Util.isMac()) {
                handleSelection();
            }
        }
    });

    final TextStyle boldStyle;
    if (PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)) {
        boldStyle = new TextStyle(boldFont, null, null);
        // italicsFont = resourceManager.createFont(FontDescriptor.createFrom(
        // table.getFont()).setStyle(SWT.ITALIC));
    } else {
        boldStyle = null;
    }
    final TextStyle grayStyle = new TextStyle(table.getFont(), OmniBoxColors.SEARCH_ENTRY_ITEM_TEXT, null);

    Listener listener = new Listener() {
        @Override
        public void handleEvent(Event event) {
            OmniEntry entry = (OmniEntry) event.item.getData();
            if (entry != null) {
                switch (event.type) {
                case SWT.MeasureItem:
                    entry.measure(event, textLayout, resourceManager, boldStyle);
                    break;
                case SWT.PaintItem:
                    entry.paint(event, textLayout, resourceManager, boldStyle, grayStyle);
                    break;
                case SWT.EraseItem:
                    entry.erase(event);
                    break;
                }
            }
        }
    };

    table.addListener(SWT.MeasureItem, listener);
    table.addListener(SWT.EraseItem, listener);
    table.addListener(SWT.PaintItem, listener);
    //In GTK linux, the table is hungry for focus and steals it on updates
    //When the table has focus it grabs key events that are intended for the
    //search entry box; to make things right, we need to punt focus back
    //to the search box
    if (Util.isLinux()) {
        table.addFocusListener(new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                Display.getDefault().syncExec(new Runnable() {
                    @Override
                    public void run() {
                        //punt focus back to the text box
                        getFocusControl().setFocus();
                    }
                });
            }

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

    return composite;
}