public static CellEditor createPropertyEditor( final IServiceLocator serviceLocator, Composite parent, DBPPropertySource source, DBPPropertyDescriptor property) { if (source == null) { return null; } final Object object = source.getEditableValue(); if (!property.isEditable(object)) { return null; } CellEditor cellEditor = UIUtils.createCellEditor(parent, object, property); if (cellEditor != null) { final Control editorControl = cellEditor.getControl(); UIUtils.addFocusTracker(serviceLocator, UIUtils.INLINE_WIDGET_EDITOR_ID, editorControl); editorControl.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { UIUtils.removeFocusTracker(serviceLocator, editorControl); } }); } return cellEditor; }
public static boolean isParent(Control parent, Control child) { for (Control c = child; c != null; c = c.getParent()) { if (c == parent) { return true; } } return false; }
public static void enableWithChildren(Composite composite, boolean enable) { composite.setEnabled(enable); for (Control child : composite.getChildren()) { if (child instanceof Composite) { enableWithChildren((Composite) child, enable); } else { child.setEnabled(enable); } } }
/** * Determine whether this control or any of it's child has focus * * @param control control to check * @return true if it has focus */ public static boolean hasFocus(Control control) { Control focusControl = control.getDisplay().getFocusControl(); if (focusControl == null) { return false; } for (Control fc = focusControl; fc != null; fc = fc.getParent()) { if (fc == control) { return true; } } return false; }
public static void postEvent(Control ownerControl, final Event event) { final Display display = ownerControl.getDisplay(); display.asyncExec( new Runnable() { @Override public void run() { display.post(event); } }); }
public static void enableHostEditorKeyBindingsSupport( final IWorkbenchPartSite partSite, Control control) { if (!(partSite.getPart() instanceof AbstractTextEditor)) { return; } final boolean[] activated = new boolean[] {false}; control.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) { if (!activated[0]) { UIUtils.enableHostEditorKeyBindings(partSite, false); activated[0] = true; } } @Override public void focusLost(FocusEvent e) { if (activated[0]) { UIUtils.enableHostEditorKeyBindings(partSite, true); activated[0] = false; } } }); control.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { if (activated[0]) { UIUtils.enableHostEditorKeyBindings(partSite, true); activated[0] = false; } } }); }
public static void drawMessageOverControl( Control control, PaintEvent e, String message, int offset) { Rectangle bounds = control.getBounds(); Point ext = e.gc.textExtent(message); e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + offset); }
public static boolean isInDialog(Control control) { return control.getShell().getData() instanceof org.eclipse.jface.dialogs.Dialog; }