List of usage examples for org.eclipse.jface.util Util isLinux
public static boolean isLinux()
From source file:com.google.dart.tools.ui.omni.BasePopupDialog.java
License:Open Source License
@Override protected void configureShell(Shell shell) { GridLayoutFactory.fillDefaults().margins(0, 0).spacing(5, 5).applyTo(shell); shell.addListener(SWT.Deactivate, new Listener() { @Override// w w w . j a va 2 s .c o m public void handleEvent(Event event) { /* * Close if we are deactivating and have no child shells. If we have child shells, we are * deactivating due to their opening. On X, we receive this when a menu child (such as the * system menu) of the shell opens, but I have not found a way to distinguish that case * here. Hence bug #113577 still exists. */ if (listenToDeactivate && event.widget == getShell() && getShell().getShells().length == 0) { asyncClose(); } else { /* * We typically ignore deactivates to work around platform-specific event ordering. Now * that we've ignored whatever we were supposed to, start listening to deactivates. * Example issues can be found in https://bugs.eclipse.org/bugs/show_bug.cgi?id=123392 */ if (!Util.isLinux()) { listenToDeactivate = true; } } } }); // Set this true whenever we activate. It may have been turned // off by a menu or secondary popup showing. shell.addListener(SWT.Activate, new Listener() { @Override public void handleEvent(Event event) { //TODO (pquitslund): in progress... // // ignore this event if we have launched a child // if (event.widget == getShell() && getShell().getShells().length == 0) { // listenToDeactivate = true; // // Typically we start listening for parent deactivate after // // we are activated, except on the Mac, where the deactivate // // is received after activate. // // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=100668 // listenToParentDeactivate = !Util.isMac(); // } } }); if ((getShellStyle() & SWT.ON_TOP) != 0 && shell.getParent() != null) { parentDeactivateListener = new Listener() { @Override public void handleEvent(Event event) { if (listenToParentDeactivate) { asyncClose(); } else { // Our first deactivate, now start listening on the Mac. listenToParentDeactivate = listenToDeactivate; } } }; shell.getParent().addListener(SWT.Deactivate, parentDeactivateListener); } shell.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent event) { handleDispose(); } }); }
From source file:com.google.dart.tools.ui.omni.OmniBoxColors.java
License:Open Source License
private static int getSearchResultBackgroundColorId() { //the info background is uglier on Mac/Windows but plays nicer with Linux themes (like Radiance) return Util.isLinux() ? SWT.COLOR_INFO_BACKGROUND : SWT.COLOR_LIST_BACKGROUND; }
From source file:com.google.dart.tools.ui.omni.OmniBoxControlContribution.java
License:Open Source License
private Text createTextControl(Composite parent) { Text text = new Text(parent, SEARCH_BOX_STYLE_BITS); text.setToolTipText(OmniBoxMessages.OmniBoxControlContribution_control_tooltip); if (Util.isLinux()) { GridDataFactory.fillDefaults().indent(0, 1).grab(true, true).applyTo(text); }// w w w. ja v a2s . c om // Disables the default context menu for native SWT text boxes text.setMenu(new Menu(parent)); return text; }
From source file:com.google.dart.tools.ui.omni.OmniBoxControlContribution.java
License:Open Source License
private void handleFocusLost() { //re-enable global keybinding handlers ((IBindingService) PlatformUI.getWorkbench().getService(IBindingService.class)).setKeyFilterEnabled(true); //GTK linux requires special casing to handle the case where a click //outside the search box (or popup) should cause the popup to close //We identify this case by keying off focus changes --- if focus //is transfered to another control we trigger a close if (Util.isLinux()) { //Exec async to ensure that it occurs after the focus change Display.getDefault().asyncExec(new Runnable() { @Override/*from w ww. ja v a 2 s. co m*/ public void run() { Control focusControl = Display.getDefault().getFocusControl(); if (focusControl != textControl && popup != null && focusControl != popup.table) { popup.close(); } } }); } if (popupClosed()) { setWatermarkText(); } }
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 w w.ja v a 2 s . c o m 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; }
From source file:com.google.dart.tools.ui.update.SettingsControlContribution.java
License:Open Source License
public void createControl(Composite composite) { ToolBar toolBar = new ToolBar(composite, SWT.NONE); settingsButton = new ToolItem(toolBar, SWT.DROP_DOWN | SWT.NO_TRIM); settingsButton.setImage(updateState.getButtonImage()); settingsButton.setToolTipText(updateState.getTooltipText()); settingsButton.addSelectionListener(new SelectionAdapter() { @Override//from w w w . j a va2s .c om public void widgetSelected(SelectionEvent e) { updateState.performAction(controlContribution.getWorkbenchWindow()); } }); if (Util.isLinux()) { GridDataFactory.fillDefaults().indent(0, 1).grab(true, true).applyTo(toolBar); } composite.addDisposeListener(this); UpdateManager updateManager = UpdateCore.getUpdateManager(); updateManager.addListener(this); }
From source file:com.google.dart.tools.update.core.internal.UpdateUtils.java
License:Open Source License
@SuppressWarnings("static-access") private static OS getOS() { if (Util.isMac()) { return OS.OSX; }/* www. j ava 2 s. co m*/ if (Util.isLinux()) { return OS.LINUX; } if (Util.isWindows()) { return OS.WIN; } return OS.UNKNOWN; }
From source file:com.liferay.ide.server.ui.util.ServerUIUtil.java
License:Open Source License
public static void openInSystemExplorer(String systemCommand, File file) throws IOException { if (Util.isLinux() || Util.isMac()) { Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", systemCommand }, null, file); } else {/* w ww. ja va 2 s . co m*/ Runtime.getRuntime().exec(systemCommand, null, file); } }
From source file:com.mobilesorcery.sdk.internal.OSTester.java
License:Open Source License
@Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { try {//ww w . j ava 2s. c o m String os = System.getProperty("os.name"); String arg = (String) args[0]; if (OS_REGEXP_PROP.equals(property)) { Pattern p = Pattern.compile(arg); return p.matcher(os).matches(); } else if (OS_FAMILY_PROP.equals(property)) { if (WIN.equals(arg)) { return Util.isWindows(); } else if (MAC.equals(arg)) { return Util.isMac(); } else if (LINUX.equals(arg)) { return Util.isLinux(); } } } catch (Exception e) { CoreMoSyncPlugin.getDefault().log(e); } return false; }
From source file:eclipse.spellchecker.preferences.OptionsConfigurationBlock.java
License:Open Source License
protected Button addCheckBoxWithLink(Composite parent, final String label, Key key, String[] values, int indent, int widthHint, final SelectionListener listener) { LinkControlData data = new LinkControlData(key, values); GridData gd = new GridData(GridData.FILL, GridData.FILL, true, false); gd.horizontalSpan = 3;//from w w w.j a v a 2 s .c om gd.horizontalIndent = indent; Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; layout.horizontalSpacing = 0; layout.numColumns = 2; composite.setLayout(layout); composite.setLayoutData(gd); final Button checkBox = new Button(composite, SWT.CHECK); checkBox.setFont(JFaceResources.getDialogFont()); gd = new GridData(GridData.FILL, GridData.CENTER, false, false); int offset = Util.isMac() ? -4 : Util.isLinux() ? -2 : /* Windows et al. */ 3; gd.widthHint = checkBox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + offset; checkBox.setLayoutData(gd); checkBox.setData(data); checkBox.addSelectionListener(getSelectionListener()); checkBox.getAccessible().addAccessibleListener(new AccessibleAdapter() { @Override public void getName(AccessibleEvent e) { e.result = LegacyActionTools.removeMnemonics(label.replaceAll("</?[aA][^>]*>", "")); //$NON-NLS-1$ //$NON-NLS-2$ } }); gd = new GridData(GridData.FILL, GridData.CENTER, true, false); gd.widthHint = widthHint; Link link = new Link(composite, SWT.NONE); link.setText(label); link.setLayoutData(gd); link.setData(key); data.setLink(link); // toggle checkbox when user clicks unlinked text in link: final boolean[] linkSelected = { false }; link.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { linkSelected[0] = true; if (listener != null) { listener.widgetSelected(e); } } }); link.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { linkSelected[0] = false; } @Override public void mouseUp(MouseEvent e) { if (!linkSelected[0]) { checkBox.setSelection(!checkBox.getSelection()); checkBox.setFocus(); linkSelected[0] = false; controlChanged(checkBox); } } }); link.addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_MNEMONIC && e.doit == true) { e.detail = SWT.TRAVERSE_NONE; checkBox.setSelection(!checkBox.getSelection()); checkBox.setFocus(); linkSelected[0] = false; controlChanged(checkBox); } } }); makeScrollableCompositeAware(link); makeScrollableCompositeAware(checkBox); updateCheckBox(checkBox); fCheckBoxes.add(checkBox); fLinks.add(link); return checkBox; }