Java Code Examples for org.eclipse.swt.widgets.Control#setFocus()
The following examples show how to use
org.eclipse.swt.widgets.Control#setFocus() .
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: InternalCompositeTable.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Makes sure that the focused row is visible * * @return true if the display needed to be scrolled; false otherwise */ public boolean doMakeFocusedRowVisible() { if (numRowsVisible < 1) { return false; } int topRowDelta = computeTopRowDelta(currentRow); if (topRowDelta == 0) { return false; } // currentRow += -1 * topRowDelta; doSetTopRow(topRow + topRowDelta, currentRow + (-1 * topRowDelta)); Control control = getControl(currentColumn, currentRow); if (control != null) { control.setFocus(); // ?? Can I get away with avoiding asyncExec here ?? } return true; }
Example 2
Source File: VTracker.java From nebula with Eclipse Public License 2.0 | 6 votes |
private static boolean setFocusFromPrev(Control control) { Control c = null; Composite parent = control.getParent(); if(parent == null) { c = control; } else { Control[] ca = parent.getTabList(); for(int i = 0; i < ca.length; i++) { if(ca[i] == control) { if(i == ca.length-1) { c = ca[0]; } else { c = ca[i+1]; } break; } } } if(c != null) { c.setFocus(); } return false; }
Example 3
Source File: VTracker.java From nebula with Eclipse Public License 2.0 | 6 votes |
private static boolean setFocusFromNext(Control control) { Control c = null; Composite parent = control.getParent(); if(parent == null) { c = control; } else { Control[] ca = parent.getTabList(); for(int i = 0; i < ca.length; i++) { if(ca[i] == control) { if(i == 0) { c = ca[ca.length-1]; } else { c = ca[i-1]; } break; } } } if(c != null) { c.setFocus(); } return false; }
Example 4
Source File: TSWizardDialog.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * A long running operation triggered through the wizard was stopped either * by user input or by normal end. Hides the progress monitor and restores * the enable state wizard's buttons and controls. * * @param savedState * the saved UI state as returned by <code>aboutToStart</code> * @see #aboutToStart */ private void stopped(Object savedState) { if (getShell() != null && !getShell().isDisposed()) { if (wizard.needsProgressMonitor()) { progressMonitorPart.setVisible(false); progressMonitorPart.removeFromCancelComponent(cancelButton); } Map state = (Map) savedState; restoreUIState(state); setDisplayCursor(null); if (useCustomProgressMonitorPart) { cancelButton.addSelectionListener(cancelListener); cancelButton.setCursor(null); arrowCursor.dispose(); arrowCursor = null; } waitCursor.dispose(); waitCursor = null; Control focusControl = (Control) state.get(FOCUS_CONTROL); if (focusControl != null && !focusControl.isDisposed()) { focusControl.setFocus(); } } }
Example 5
Source File: HsAbstractProgressDialog.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 任务终止 * @param savedState * ; */ private void stopped(Object savedState) { if (getShell() != null && !getShell().isDisposed()) { if (needsProgressMonitor()) { progressMonitorPart.setVisible(false); progressMonitorPart.removeFromCancelComponent(cancelButton); } Map state = (Map) savedState; restoreUIState(state); setDisplayCursor(null); if (useCustomProgressMonitorPart) { cancelButton.addSelectionListener(cancelListener); cancelButton.setCursor(null); arrowCursor.dispose(); arrowCursor = null; } waitCursor.dispose(); waitCursor = null; Control focusControl = (Control) state.get(FOCUS_CONTROL); if (focusControl != null && !focusControl.isDisposed()) { focusControl.setFocus(); } } }
Example 6
Source File: ModulaSearchResultPage.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
protected void showMatch( Match match, int currentOffset , int currentLength, boolean activate ) throws PartInitException { if (match instanceof ModulaSymbolMatch) { try { ModulaSymbolMatch em = (ModulaSymbolMatch)match; IFile f = em.getFile(); IWorkbenchPage page = WorkbenchUtils.getActivePage(); IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(f.getName()); IEditorPart ep = page.openEditor(new FileEditorInput(f), desc.getId()); ITextEditor te = (ITextEditor)ep; Control ctr = (Control)te.getAdapter(Control.class); ctr.setFocus(); te.selectAndReveal(em.getOffset(), em.getLength()); } catch (Exception e) { e.printStackTrace(); } } }
Example 7
Source File: OptionsConfigurationBlock.java From typescript.java with MIT License | 6 votes |
public void selectOption(Key key) { Control control = findControl(key); if (control != null) { if (!fExpandedComposites.isEmpty()) { ExpandableComposite expandable = getParentExpandableComposite(control); if (expandable != null) { for (int i = 0; i < fExpandedComposites.size(); i++) { ExpandableComposite curr = (ExpandableComposite) fExpandedComposites.get(i); curr.setExpanded(curr == expandable); } expandedStateChanged(expandable); } } control.setFocus(); } }
Example 8
Source File: TypeHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Selects an member in the methods list or in the current hierarchy. * @param member The member to select */ public void selectMember(IMember member) { fSelectInEditor= false; if (member.getElementType() != IJavaElement.TYPE) { Control methodControl= fMethodsViewer.getControl(); if (methodControl != null && !methodControl.isDisposed()) { methodControl.setFocus(); } fMethodsViewer.setSelection(new StructuredSelection(member), true); } else { Control viewerControl= getCurrentViewer().getControl(); if (viewerControl != null && !viewerControl.isDisposed()) { viewerControl.setFocus(); } if (!member.equals(fSelectedType)) { getCurrentViewer().setSelection(new StructuredSelection(member), true); } } fSelectInEditor= true; }
Example 9
Source File: OptionsConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void selectOption(Key key) { Control control= findControl(key); if (control != null) { if (!fExpandableComposites.isEmpty()) { ExpandableComposite expandable= getParentExpandableComposite(control); if (expandable != null) { for (int i= 0; i < fExpandableComposites.size(); i++) { ExpandableComposite curr= fExpandableComposites.get(i); curr.setExpanded(curr == expandable); } expandedStateChanged(expandable); } } control.setFocus(); } }
Example 10
Source File: TSWizardDialog.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * A long running operation triggered through the wizard was stopped either * by user input or by normal end. Hides the progress monitor and restores * the enable state wizard's buttons and controls. * * @param savedState * the saved UI state as returned by <code>aboutToStart</code> * @see #aboutToStart */ private void stopped(Object savedState) { if (getShell() != null && !getShell().isDisposed()) { if (wizard.needsProgressMonitor()) { progressMonitorPart.setVisible(false); progressMonitorPart.removeFromCancelComponent(cancelButton); } Map state = (Map) savedState; restoreUIState(state); setDisplayCursor(null); if (useCustomProgressMonitorPart) { cancelButton.addSelectionListener(cancelListener); cancelButton.setCursor(null); arrowCursor.dispose(); arrowCursor = null; } waitCursor.dispose(); waitCursor = null; Control focusControl = (Control) state.get(FOCUS_CONTROL); if (focusControl != null && !focusControl.isDisposed()) { focusControl.setFocus(); } } }
Example 11
Source File: OptionsConfigurationBlock.java From birt with Eclipse Public License 1.0 | 5 votes |
public void selectOption( Key key ) { Control control = findControl( key ); if ( control != null ) { control.setFocus( ); } }
Example 12
Source File: LayeredDisplayDecorator.java From gama with GNU General Public License v3.0 | 5 votes |
public void toggleFullScreen() { if (isFullScreen()) { if (interactiveConsoleVisible) { toggleInteractiveConsole(); } view.controlToSetFullScreen().setParent(normalParentOfFullScreenControl); createOverlay(); normalParentOfFullScreenControl.layout(true, true); destroyFullScreenShell(); adaptToolbar(); view.setFocus(); } else { fullScreenShell = createFullScreenShell(); if (DEBUG.IS_ON()) { DEBUG.SECTION(" FULLSCREEN WITH SIZE " + fullScreenShell.getSize()); } normalParentOfFullScreenControl = view.controlToSetFullScreen().getParent(); final Control display = view.controlToSetFullScreen(); display.setParent(fullScreenShell); createOverlay(); adaptToolbar(); fullScreenShell.layout(true, true); fullScreenShell.setVisible(true); view.fullScreenSet(); display.setFocus(); } }
Example 13
Source File: RelPanel.java From Rel with Apache License 2.0 | 5 votes |
private void focusOnSelectedTab() { CTabItem selectedItem = tabFolder.getSelection(); if (selectedItem != null) { Control tabControl = selectedItem.getControl(); if (tabControl != null && !tabControl.isDisposed()) tabControl.setFocus(); } }
Example 14
Source File: DbTreeTab.java From Rel with Apache License 2.0 | 5 votes |
public void ready() { relPanel.getTabFolder().setSelection(this); relPanel.fireDbTreeTabchangeEvent(); if (isDisposed()) return; Control control = getControl(); if (!control.isDisposed()) control.setFocus(); }
Example 15
Source File: BalloonNotification.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Opens a notification window next to a control. The notification window will show the given * title as the title of the balloon, The given text as the description. * * <p>The window will be hidden automatically after the value specified in the timeout expires * * <p><b>Note:</b> The balloon window is always anchored to the given control at position (0,0). * Specifying the balloon window anchor is relative to this point. * * <p>TODO wrap the contents so the balloon notification does not expand across two screens for a * long text. OR even better: do not show long notifications. users tend to ignore them anyway! * * @param control the control, next to where the widget will appear * @param anchor the anchor of the balloon window * @param title the title of the balloon * @param text the text to display as contents */ public static void showNotification(Control control, int anchor, String title, String text) { if (control != null && control.isDisposed()) { control = null; } /* * show message at least 8 secs, but show it longer for longer messages * Referenced by wikipedia, a user can read 2,5 words per second so we * approximate 400ms per word */ int timeout = Math.max(8000, text.split("\\s").length * 400); // close all previous balloon notifications like it is done in // windows to prevent overlapping of multiple balloons... BalloonNotification.removeAllActiveNotifications(); final BalloonWindow window = new BalloonWindow( control != null ? control.getShell() : null, SWT.NO_FOCUS | SWT.TOOL | SWT.TITLE); window.setAnchor(anchor); windows.add(window); /* * Note: if you add SWT.CLOSE to the style of the BalloonWindow, it will * only be closed when directly clicking on the close icon (x) and * therefore break user expectations. FIXME: find out a way to display * the closing X AND make the bubble close on any click anywhere on it. */ window.setText(title); /* * Adding the text to the contents. Pack() is required so the size of * the composite is recalculated, else the contents won't show */ Composite content = window.getContents(); content.setLayout(new FillLayout()); Label message = new Label(content, SWT.NONE); message.setText(text); content.pack(true); message.setBackground(WHITE); message.setForeground(BLACK); // make window close when clicking on balloon text, too window.addSelectionControl(message); // Locate the balloon to the widget location if (control != null) { Point widgetLocation = control.toDisplay(new Point(0, 0)); window.setLocation(widgetLocation); } // Runnable that will close the window after time has been expired final Runnable closeWindow = ThreadUtils.wrapSafe( log, new Runnable() { @Override public void run() { final Shell shell = window.getShell(); if (shell.isDisposed()) return; window.close(); } }); window.getShell().getDisplay().timerExec(timeout, closeWindow); Display display = control != null ? control.getDisplay() : Display.getCurrent(); Control lastControlWithFocus = display != null ? display.getFocusControl() : null; window.open(); if (lastControlWithFocus != null) lastControlWithFocus.setFocus(); }
Example 16
Source File: ModulaOutlinePage.java From xds-ide with Eclipse Public License 1.0 | 4 votes |
private void selectElementInEditor(ISelection selection, boolean isSelect) { if (editor == null) { return; } if (selection.isEmpty()) editor.resetHighlightRange(); else { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object firstElement = structuredSelection.getFirstElement(); if (firstElement instanceof ISourceBound) { ISourceBound sourceBound = (ISourceBound) firstElement; try { if (isSelect) { Control ctr = (Control) editor.getAdapter(Control.class); ctr.setFocus(); } ITextBinding sourceBinding = sourceBound.getSourceBinding(); if (sourceBinding != null) { ITextRegion identifierRegion = sourceBinding.getNameTextRegion(); if (identifierRegion != null) { editor.selectAndReveal(identifierRegion.getOffset(), identifierRegion.getLength()); } ITextRegion elementRegion = sourceBinding.getDeclarationTextRegion(); if (elementRegion != null) { editor.setHighlightRange(elementRegion.getOffset(), elementRegion.getLength(), false); if ((identifierRegion == null) && (firstElement instanceof IXdsSyntheticElement)) { // syntactic elements like "import list" have not name text region at all. editor.selectAndReveal(elementRegion.getOffset(), elementRegion.getLength()); } } } } catch (IllegalArgumentException x) { editor.resetHighlightRange(); } } } }
Example 17
Source File: ReferenceSearchViewPage.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
@Override public void setFocus() { Control control = viewer.getControl(); if (control != null && !control.isDisposed()) control.setFocus(); }
Example 18
Source File: XViewerEditAdapter.java From nebula with Eclipse Public License 2.0 | 4 votes |
boolean handleEditEvent(Event event) { if (klickedColumn == null || klickedCell == null) { return false; } final Control c; try { XViewerColumn xColumn = xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId()); if (xColumn instanceof ExtendedViewerColumn) { ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn; CellEditDescriptor ced = extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass()); if (ced != null) { if (ced.getControl() == null) { return false; } if (ced.getAction() != null && !ced.getAction().isEnabled()) { return false; } if (!converter.isValid(ced, klickedCell.getElement())) { return false; } c = factory.createControl(ced, xv); if (c == null) { return false; } } else { return false; } } else { return false; } if (((TreeItem) event.item) != null) { Listener myListener = e-> { switch (e.type) { case SWT.FocusOut: // set new value getInput(c); c.dispose(); break; case SWT.Verify: c.setBounds(klickedCell.getBounds()); break; case SWT.Traverse: boolean neighbor = false; switch (e.detail) { case SWT.TRAVERSE_RETURN: // set new value getInput(c); //$FALL-THROUGH$ case SWT.TRAVERSE_ESCAPE: c.dispose(); e.doit = false; break; case SWT.TRAVERSE_TAB_NEXT: getInput(c); neighbor = getNeighbor(ViewerCell.RIGHT, true); e.doit = false; c.dispose(); Event eN = new Event(); eN.type = SWT.Selection; eN.widget = xv.getTree(); if (neighbor) { eN.item = klickedCell.getItem(); } doHandleEvent(eN); break; case SWT.TRAVERSE_TAB_PREVIOUS: getInput(c); neighbor = getNeighbor(ViewerCell.LEFT, true); e.doit = false; c.dispose(); Event eP = new Event(); eP.type = SWT.Selection; eP.widget = xv.getTree(); if (neighbor) { eP.item = klickedCell.getItem(); } doHandleEvent(eP); break; } } }; c.addListener(SWT.FocusOut, myListener); c.addListener(SWT.Traverse, myListener); c.addListener(SWT.Verify, myListener); // set old value setInput(c); c.setFocus(); return true; } } catch (Exception ex) { return false; } return false; }
Example 19
Source File: CTreeEditor.java From nebula with Eclipse Public License 2.0 | 4 votes |
public void layout() { if (tree.isDisposed()) return; if (item == null || item.isDisposed()) return; int columnCount = tree.getColumnCount(); if (columnCount == 0 && column != 0) return; if (columnCount > 0 && (column < 0 || column >= columnCount)) return; Control editor = getEditor(); if(editor == null || editor.isDisposed()) return; Rectangle cell = item.getCell(column).getBounds(); Rectangle ca = item.getCell(column).getClientArea(); cell.x += ca.x; cell.width = ca.width - 1; cell.y += 1; cell.height -= 2; int bwidth = getEditor().getBorderWidth(); cell.x -= bwidth; cell.y -= bwidth; cell.width -= 2*bwidth; cell.height -= 2*bwidth; Image[] images = ((CTreeCell) item.getCell(column)).getImages(); if(images.length > 0) { Image img = images[images.length-1]; Rectangle rect = img == null ? new Rectangle(cell.x,cell.y,0,0) : img.getBounds(); cell.x = rect.x + rect.width; cell.width -= rect.width; } Rectangle area = tree.getClientArea(); if (cell.x < area.x + area.width) { if (cell.x + cell.width > area.x + area.width) { cell.width = area.x + area.width - cell.x; } } Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight); if (grabHorizontal) { if (tree.getColumnCount() == 0) { // Bounds of tree item only include the text area - stretch out to include // entire client area cell.width = area.x + area.width - cell.x; } editorRect.width = Math.max(cell.width, minimumWidth); } if (grabVertical) { editorRect.height = Math.max(cell.height, minimumHeight); } if (horizontalAlignment == SWT.RIGHT) { editorRect.x += cell.width - editorRect.width; } else if (horizontalAlignment == SWT.LEFT) { // do nothing - cell.x is the right answer } else { // default is CENTER editorRect.x += (cell.width - editorRect.width)/2; } // don't let the editor overlap with the +/- of the tree editorRect.x = Math.max(cell.x, editorRect.x); if (verticalAlignment == SWT.BOTTOM) { editorRect.y += cell.height - editorRect.height; } else if (verticalAlignment == SWT.TOP) { // do nothing - cell.y is the right answer } else { // default is CENTER editorRect.y += (cell.height - editorRect.height)/2; } if(editor == null || editor.isDisposed()) return; boolean hadFocus = editor.getVisible () && editor.isFocusControl(); // this doesn't work because // resizing the column takes the focus away // before we get here editor.setBounds (editorRect); if(hadFocus) { if (editor == null || editor.isDisposed()) return; editor.setFocus (); } editor.moveAbove(null); }