1 11 package org.eclipse.ui.internal.forms.widgets; 12 import org.eclipse.swt.dnd.DragSource; 13 import org.eclipse.swt.dnd.DropTarget; 14 import org.eclipse.swt.widgets.Caret; 15 import org.eclipse.swt.widgets.Control; 16 import org.eclipse.swt.widgets.Display; 17 import org.eclipse.swt.widgets.Menu; 18 import org.eclipse.swt.widgets.ScrollBar; 19 import org.eclipse.swt.widgets.Shell; 20 import org.eclipse.swt.widgets.Widget; 21 22 25 public class SWTUtil { 26 27 32 public static Display getStandardDisplay() { 33 Display display; 34 display = Display.getCurrent(); 35 if (display == null) 36 display = Display.getDefault(); 37 return display; 38 } 39 40 46 public static Shell getShell(Widget widget) { 47 if (widget instanceof Control) 48 return ((Control) widget).getShell(); 49 if (widget instanceof Caret) 50 return ((Caret) widget).getParent().getShell(); 51 if (widget instanceof DragSource) 52 return ((DragSource) widget).getControl().getShell(); 53 if (widget instanceof DropTarget) 54 return ((DropTarget) widget).getControl().getShell(); 55 if (widget instanceof Menu) 56 return ((Menu) widget).getParent().getShell(); 57 if (widget instanceof ScrollBar) 58 return ((ScrollBar) widget).getParent().getShell(); 59 60 return null; 61 } 62 } 63 | Popular Tags |