Java Code Examples for org.eclipse.swt.widgets.Control#getShell()
The following examples show how to use
org.eclipse.swt.widgets.Control#getShell() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SWTUtil.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent) */ @Override public void mouseDown(MouseEvent e) { Control theControl = (Control) e.widget; Display display = theControl.getDisplay(); Shell tip = new Shell(theControl.getShell(), SWT.ON_TOP | SWT.TOOL); tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FillLayout layout = new FillLayout(); layout.marginHeight = 1; layout.marginWidth = 2; tip.setLayout(layout); Label label = new Label(tip, SWT.NONE); label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); label.setText(theControl.getToolTipText()); label.addMouseTrackListener(this); Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle rect = theControl.getBounds(); Point pt = theControl.getParent().toDisplay(rect.x, rect.y); tip.setBounds(pt.x, pt.y, size.x, size.y); tip.setVisible(true); }
Example 2
Source File: GridToolTip.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Creates an inplace tooltip. * * @param parent parent control. */ public GridToolTip(final Control parent) { super(parent, SWT.NONE); shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); parent.addListener(SWT.Dispose, new Listener() { public void handleEvent(Event arg0) { shell.dispose(); dispose(); } }); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { onPaint(e.gc); } }); }
Example 3
Source File: ExpressionDialogCellEditor.java From birt with Eclipse Public License 1.0 | 6 votes |
String openDialogBox( Control cellEditorWindow, String oldValue ) { ExpressionBuilder dialog = new ExpressionBuilder( cellEditorWindow.getShell( ), oldValue ); dialog.setExpressionProvier( new ExpressionProvider( itemHandle ) ); if ( dialog.open( ) == Dialog.OK ) { String newValue = dialog.getResult( ); if ( !newValue.equals( oldValue ) ) { return newValue; } } setFocus( ); return null; }
Example 4
Source File: GridToolTip.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * Creates an inplace tooltip. * * @param parent parent control. */ public GridToolTip(final Control parent) { super(parent, SWT.NONE); shell = new Shell(parent.getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS | SWT.TOOL); shell.setBackground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); parent.addListener(SWT.Dispose, new Listener() { public void handleEvent(Event arg0) { shell.dispose(); dispose(); } }); shell.addListener(SWT.Paint, new Listener() { public void handleEvent(Event e) { onPaint(e.gc); } }); }
Example 5
Source File: Utils.java From EasyShell with Eclipse Public License 2.0 | 6 votes |
private static void showToolTipSWTwidget(Control control, int style, String title, String message) { ToolTip tooltip = new ToolTip(control.getShell(), /*SWT.BALLOON | */ style); tooltip.setAutoHide(true); tooltip.setLocation(control.toDisplay(control.getSize().x/2, control.getSize().y + 5)); tooltip.setText(title); tooltip.setMessage(message); tooltip.setVisible(true); }
Example 6
Source File: ContentAssistant.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Installs this closer on it's viewer's text widget. */ protected void install() { Control control = fContentAssistSubjectControlAdapter.getControl(); fControl = control; if (Helper.okToUse(control)) { Shell shell = control.getShell(); fShell = shell; shell.addControlListener(this); control.addMouseListener(this); control.addFocusListener(this); /* * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors */ control.addDisposeListener(this); } if (fViewer != null) { fViewer.addViewportListener(this); } }
Example 7
Source File: CompareDialog.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
protected Control createDialogArea(Composite parent2) { Composite parent= (Composite) super.createDialogArea(parent2); Control c= compareEditorInput.createContents(parent); c.setLayoutData(new GridData(GridData.FILL_BOTH)); // Assert.isTrue(! compareEditorInput.getCompareConfiguration().isLeftEditable()); // Assert.isTrue(! compareEditorInput.getCompareConfiguration().isRightEditable()); Shell shell= c.getShell(); shell.setText(compareEditorInput.getTitle()); shell.setImage(compareEditorInput.getTitleImage()); PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.COMPARE_DIALOG); applyDialogFont(parent); return parent; }
Example 8
Source File: FileComboBoxCellEditor.java From ice with Eclipse Public License 1.0 | 5 votes |
/** * Open the dialog box for the button. * * @param cellEditorWindow * @return */ protected Object openDialogBox(Control cellEditorWindow) { FileDialog fileDialog = new FileDialog(cellEditorWindow.getShell()); fileDialog.setText("Select a file to import into ICE workspace"); return fileDialog.open(); }
Example 9
Source File: CommentEditor.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override protected Object openDialogBox(Control control) { Box box = new Box(control.getShell(), oldValue); if (box.open() != Dialog.OK) return null; String newValue = box.value; if (Objects.equals(oldValue, newValue)) return null; exchange.description = newValue; updateContents(newValue); editor.setDirty(true); return null; }
Example 10
Source File: EmbeddedEditorSite.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public Shell getShell() { // Compatibility: This method should not be used outside the UI // thread... but since this condition // was not always in the JavaDoc, we still try to return our best guess // about the shell if it is // called from the wrong thread. Display currentDisplay = Display.getCurrent(); if (currentDisplay == null) { // Uncomment this to locate places that try to access the shell from // a background thread // WorkbenchPlugin.log(new Exception("Error: // IWorkbenchSite.getShell() was called outside the UI thread. Fix // this code.")); //$NON-NLS-1$ return getWorkbenchWindow().getShell(); } Control control = (Control) getMWindow().getWidget(); if (control != null && !control.isDisposed()) { return control.getShell(); } // likely means the part has been destroyed, return the parent window's // shell, we don't just arbitrarily return the workbench window's shell // because we may be in a detached window MWindow window = e4Context.get(MWindow.class); return window == null ? getWorkbenchWindow().getShell() : (Shell) window.getWidget(); }
Example 11
Source File: OpenWithQuickMenu.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
private void show( Control focusControl, Point location ) { Menu quickMenu = new Menu( focusControl.getShell() ); OpenWithMenu openWithMenu = new OpenWithMenu( workbenchPage, file ); openWithMenu.fill( quickMenu, 0 ); quickMenu.setLocation( location ); quickMenu.addListener( SWT.Hide, createMenuCloseListener( openWithMenu ) ); quickMenu.setVisible( true ); }
Example 12
Source File: DummyEditorSite.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public Shell getShell() { // Compatibility: This method should not be used outside the UI // thread... but since this condition // was not always in the JavaDoc, we still try to return our best guess // about the shell if it is // called from the wrong thread. final Display currentDisplay = Display.getCurrent(); if (currentDisplay == null) { // Uncomment this to locate places that try to access the shell from // a background thread // WorkbenchPlugin.log(new Exception("Error: // IWorkbenchSite.getShell() was called outside the UI thread. Fix // this code.")); //$NON-NLS-1$ final IWorkbenchWindow workbenchWindow = getWorkbenchWindow(); if (workbenchWindow != null) { return workbenchWindow.getShell(); } return null; } IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); MWindow window = null; if (activeWorkbenchWindow != null) { window = ((WorkbenchWindow) activeWorkbenchWindow).getModel(); final Control control = (Control) window.getWidget(); if (control != null && !control.isDisposed()) { return control.getShell(); } } // likely means the part has been destroyed, return the parent window's // shell, we don't just arbitrarily return the workbench window's shell // because we may be in a detached window return window == null ? getWorkbenchWindow().getShell() : (Shell) window.getWidget(); }
Example 13
Source File: ShellDocker.java From BiglyBT with GNU General Public License v2.0 | 5 votes |
public ShellDocker(Control anchorControl, Shell dockedShell) { if (null == anchorControl || anchorControl.isDisposed()) { throw new NullPointerException("anchorControl cannot be null or disposed"); } if (null == dockedShell || dockedShell.isDisposed()) { throw new NullPointerException("dockedShell cannot be null or disposed"); } this.anchorControl = anchorControl; this.dockedShell = dockedShell; mainShell = anchorControl.getShell(); }
Example 14
Source File: ContactSelectionDialogCellEditor.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
@Override protected Object openDialogBox(Control cellEditorWindow){ ContactSelectionDialog dialog = new ContactSelectionDialog(cellEditorWindow.getShell(), IContact.class, title, message); if (getValue() instanceof IContact) { // TODO pre select } if (dialog.open() == Dialog.OK) { return dialog.getSelection(); } return null; }
Example 15
Source File: TSWizardDialog.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * About to start a long running operation triggered through the wizard. * Shows the progress monitor and disables the wizard's buttons and * controls. * * @param enableCancelButton * <code>true</code> if the Cancel button should be enabled, * and <code>false</code> if it should be disabled * @return the saved UI state */ private Object aboutToStart(boolean enableCancelButton) { Map savedState = null; if (getShell() != null) { // Save focus control Control focusControl = getShell().getDisplay().getFocusControl(); if (focusControl != null && focusControl.getShell() != getShell()) { focusControl = null; } boolean needsProgressMonitor = wizard.needsProgressMonitor(); // Set the busy cursor to all shells. Display d = getShell().getDisplay(); waitCursor = new Cursor(d, SWT.CURSOR_WAIT); setDisplayCursor(waitCursor); if (useCustomProgressMonitorPart) { cancelButton.removeSelectionListener(cancelListener); // Set the arrow cursor to the cancel component. arrowCursor = new Cursor(d, SWT.CURSOR_ARROW); cancelButton.setCursor(arrowCursor); } // Deactivate shell savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton); if (focusControl != null) { savedState.put(FOCUS_CONTROL, focusControl); } // Activate cancel behavior. if (needsProgressMonitor) { if (enableCancelButton || useCustomProgressMonitorPart) { progressMonitorPart.attachToCancelComponent(cancelButton); } progressMonitorPart.setVisible(true); } // Install traverse listener once in order to implement 'Enter' and 'Space' key blocking if (timeWhenLastJobFinished == -1) { timeWhenLastJobFinished= 0; getShell().addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) { // We want to ignore the keystroke when we detect that it has been received within the // delay period after the last operation has finished. This prevents the user from accidentally // hitting "Enter" or "Space", intending to cancel an operation, but having it processed exactly // when the operation finished, thus traversing the wizard. If there is another operation still // running, the UI is locked anyway so we are not in this code. This listener should fire only // after the UI state is restored (which by definition means all jobs are done. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=287887 if (timeWhenLastJobFinished != 0 && System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) { e.doit= false; return; } timeWhenLastJobFinished= 0; }} }); } } return savedState; }
Example 16
Source File: HsAbstractProgressDialog.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * 运行任务的准备工作 * @return UI状态 */ @SuppressWarnings("rawtypes") private Object aboutToStart(boolean enableCancelButton) { Map savedState = null; if (getShell() != null) { // Save focus control Control focusControl = getShell().getDisplay().getFocusControl(); if (focusControl != null && focusControl.getShell() != getShell()) { focusControl = null; } boolean needsProgressMonitor = needsProgressMonitor(); // 设置Shell的鼠标状态 Display d = getShell().getDisplay(); waitCursor = new Cursor(d, SWT.CURSOR_WAIT); setDisplayCursor(waitCursor); if (useCustomProgressMonitorPart) { cancelButton.removeSelectionListener(cancelListener); // 设置取消按钮的鼠标状态 arrowCursor = new Cursor(d, SWT.CURSOR_ARROW); cancelButton.setCursor(arrowCursor); } // Deactivate shell savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton); if (focusControl != null) { savedState.put(FOCUS_CONTROL, focusControl); } // Activate cancel behavior. if (needsProgressMonitor) { if (enableCancelButton || useCustomProgressMonitorPart) { progressMonitorPart.attachToCancelComponent(cancelButton); } progressMonitorPart.setVisible(true); } if (timeWhenLastJobFinished == -1) { timeWhenLastJobFinished = 0; // 忽略键盘事件( enter space)在最后一个任务完成之前 getShell().addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) { if (timeWhenLastJobFinished != 0 && System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) { e.doit = false; return; } timeWhenLastJobFinished = 0; } } }); } } return savedState; }
Example 17
Source File: TSWizardDialog.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * About to start a long running operation triggered through the wizard. * Shows the progress monitor and disables the wizard's buttons and * controls. * * @param enableCancelButton * <code>true</code> if the Cancel button should be enabled, * and <code>false</code> if it should be disabled * @return the saved UI state */ private Object aboutToStart(boolean enableCancelButton) { Map savedState = null; if (getShell() != null) { // Save focus control Control focusControl = getShell().getDisplay().getFocusControl(); if (focusControl != null && focusControl.getShell() != getShell()) { focusControl = null; } boolean needsProgressMonitor = wizard.needsProgressMonitor(); // Set the busy cursor to all shells. Display d = getShell().getDisplay(); waitCursor = new Cursor(d, SWT.CURSOR_WAIT); setDisplayCursor(waitCursor); if (useCustomProgressMonitorPart) { cancelButton.removeSelectionListener(cancelListener); // Set the arrow cursor to the cancel component. arrowCursor = new Cursor(d, SWT.CURSOR_ARROW); cancelButton.setCursor(arrowCursor); } // Deactivate shell savedState = saveUIState(useCustomProgressMonitorPart && needsProgressMonitor && enableCancelButton); if (focusControl != null) { savedState.put(FOCUS_CONTROL, focusControl); } // Activate cancel behavior. if (needsProgressMonitor) { if (enableCancelButton || useCustomProgressMonitorPart) { progressMonitorPart.attachToCancelComponent(cancelButton); } progressMonitorPart.setVisible(true); } // Install traverse listener once in order to implement 'Enter' and 'Space' key blocking if (timeWhenLastJobFinished == -1) { timeWhenLastJobFinished= 0; getShell().addTraverseListener(new TraverseListener() { public void keyTraversed(TraverseEvent e) { if (e.detail == SWT.TRAVERSE_RETURN || (e.detail == SWT.TRAVERSE_MNEMONIC && e.keyCode == 32)) { // We want to ignore the keystroke when we detect that it has been received within the // delay period after the last operation has finished. This prevents the user from accidentally // hitting "Enter" or "Space", intending to cancel an operation, but having it processed exactly // when the operation finished, thus traversing the wizard. If there is another operation still // running, the UI is locked anyway so we are not in this code. This listener should fire only // after the UI state is restored (which by definition means all jobs are done. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=287887 if (timeWhenLastJobFinished != 0 && System.currentTimeMillis() - timeWhenLastJobFinished < RESTORE_ENTER_DELAY) { e.doit= false; return; } timeWhenLastJobFinished= 0; }} }); } } return savedState; }
Example 18
Source File: ClipboardCopy.java From BiglyBT with GNU General Public License v2.0 | 4 votes |
public static void addCopyToClipMenu( final Control control, final copyToClipProvider provider ) { MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY ); if ( ml != null ){ control.removeMouseListener( ml ); } ml = new MouseAdapter() { @Override public void mouseDown( MouseEvent e ) { if ( control.isDisposed()){ return; } final String text = provider.getText(); if ( control.getMenu() != null || text == null || text.length() == 0 ){ return; } if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){ return; } final Menu menu = new Menu(control.getShell(),SWT.POP_UP); MenuItem item = new MenuItem( menu,SWT.NONE ); item.setData( MENU_ITEM_KEY, "" ); String msg_text_id; if ( provider instanceof copyToClipProvider2 ){ msg_text_id = ((copyToClipProvider2)provider).getMenuResource(); }else{ msg_text_id = "label.copy.to.clipboard"; } item.setText( MessageText.getString( msg_text_id )); item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent arg0) { new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()}); } }); control.setMenu( menu ); menu.addMenuListener( new MenuAdapter() { @Override public void menuHidden( MenuEvent arg0 ) { if ( control.getMenu() == menu ){ control.setMenu( null ); } } }); menu.setVisible( true ); } }; control.setData( MOUSE_LISTENER_KEY, ml ); control.addMouseListener( ml ); }
Example 19
Source File: ComboBoxDimensionCellEditor.java From birt with Eclipse Public License 1.0 | 4 votes |
protected Object openDialogBox(Control cellEditorWindow) { DimensionBuilderDialog dialog = new DimensionBuilderDialog( cellEditorWindow.getShell()); DimensionValue value; try { value = StringUtil.parseInput((String) comboBox.getText(), ULocale .getDefault()); } catch (PropertyValueException e) { value = null; } dialog.setUnitNames(units); dialog.setUnitName(unitName); if (value != null) { dialog.setMeasureData(new Double(value.getMeasure())); } if (Window.OK == dialog.open()) { deactivate(); String newValue = null; Double doubleValue = 0.0; if (dialog.getMeasureData() instanceof Double) { doubleValue = (Double) dialog.getMeasureData(); } else if (dialog.getMeasureData() instanceof DimensionValue) { doubleValue = ((DimensionValue) dialog.getMeasureData()) .getMeasure(); } DimensionValue dValue = new DimensionValue(doubleValue, dialog .getUnitName()); if (dValue != null) { newValue = dValue.toDisplayString(); } return newValue; } else { comboBox.setFocus(); return null; } }
Example 20
Source File: DimensionCellEditor.java From birt with Eclipse Public License 1.0 | 4 votes |
protected Object openDialogBox( Control cellEditorWindow ) { DimensionBuilderDialog dialog = new DimensionBuilderDialog( cellEditorWindow.getShell( ) ); DimensionValue value; try { value = StringUtil.parseInput( (String) this.getDefaultText( ) .getText( ), ULocale.getDefault( ) ); } catch ( PropertyValueException e ) { value = null; } dialog.setUnitNames( units ); dialog.setUnitName( unitName ); if ( value != null ) { dialog.setMeasureData( new Double( value.getMeasure( ) ) ); } inProcessing = 1; if ( dialog.open( ) == Window.OK ) { deactivate( ); inProcessing = 0; String newValue = null; Double doubleValue = 0.0; if ( dialog.getMeasureData( ) instanceof Double ) { doubleValue = (Double) dialog.getMeasureData( ); } else if ( dialog.getMeasureData( ) instanceof DimensionValue ) { doubleValue = ( (DimensionValue) dialog.getMeasureData( ) ).getMeasure( ); } DimensionValue dValue = new DimensionValue( doubleValue, dialog.getUnitName( ) ); if ( dValue != null ) { newValue = dValue.toDisplayString( ); } return newValue; } else { getDefaultText( ).setFocus( ); getDefaultText( ).selectAll( ); } inProcessing = 0; return null; }