Java Code Examples for org.eclipse.swt.widgets.Display#asyncExec()
The following examples show how to use
org.eclipse.swt.widgets.Display#asyncExec() .
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: GeneratorView.java From neoscada with Eclipse Public License 1.0 | 6 votes |
private void triggerErrorLabel ( final String string ) { final Display d = this.errorLabel.getDisplay (); if ( !d.isDisposed () ) { d.asyncExec ( new Runnable () { @Override public void run () { if ( !GeneratorView.this.errorLabel.isDisposed () ) { GeneratorView.this.errorLabel.setText ( string ); } } } ); } }
Example 2
Source File: PyConfigureExceptionDialog.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override public void run() { try { sleep(300); } catch (InterruptedException e) { // ignore } if (!monitor.isCanceled()) { Display display = Display.getDefault(); display.asyncExec(new Runnable() { @Override public void run() { if (!monitor.isCanceled() && filterPatternField != null && !filterPatternField.isDisposed()) { doFilterUpdate(monitor); } } }); } }
Example 3
Source File: ResourceAction.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Refreshes all resources. */ protected void refreshAll( ) { Display display = getShell( ).getDisplay( ); display.asyncExec( new Runnable( ) { /* * (non-Javadoc) * * @see java.lang.Runnable#run() */ public void run( ) { if ( viewerPage != null ) { viewerPage.refreshRoot( ); } } } ); }
Example 4
Source File: AbstractNewSarlElementWizard.java From sarl with Apache License 2.0 | 6 votes |
@Override public boolean performFinish() { final int size = this.page.asyncCreateType(); final IResource resource = this.page.getResource(); if (resource != null) { selectAndReveal(resource); final Display display = getShell().getDisplay(); display.asyncExec(() -> { final IEditorPart editor; try { editor = IDE.openEditor(JavaPlugin.getActivePage(), (IFile) resource); if (editor instanceof ITextEditor) { final ITextEditor textEditor = (ITextEditor) editor; final ISelectionProvider selectionProvider = textEditor.getSelectionProvider(); final ISelection selection = new TextSelection(size - 2, 0); selectionProvider.setSelection(selection); } } catch (PartInitException e) { throw new RuntimeException(e); } }); return true; } return false; }
Example 5
Source File: TypeHierarchyViewPart.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Called from ITypeHierarchyLifeCycleListener. * Can be called from any thread * @param typeHierarchy Hierarchy that has changed * @param changedTypes Types in the hierarchy that have change or <code>null</code> if the full hierarchy has changed */ protected void doTypeHierarchyChanged(final TypeHierarchyLifeCycle typeHierarchy, final IType[] changedTypes) { if (!fIsVisible) { fNeedRefresh= true; return; } if (fIsRefreshRunnablePosted) { return; } Display display= getDisplay(); if (display != null) { fIsRefreshRunnablePosted= true; display.asyncExec(new Runnable() { public void run() { try { if (fPagebook != null && !fPagebook.isDisposed()) { doTypeHierarchyChangedOnViewers(changedTypes); } } finally { fIsRefreshRunnablePosted= false; } } }); } }
Example 6
Source File: SWTUtil.java From goclipse with Eclipse Public License 1.0 | 6 votes |
/** * Post {@link Control#setFocus()} on the UI thread, if current thread not UI thread. */ public static void post_setFocus(final Text control) { if(!isOkToUse(control)) { return; } Display display = control.getDisplay(); if(display == Display.getCurrent()) { control.setFocus(); } else { display.asyncExec(new Runnable() { @Override public void run() { if(!control.isDisposed()) { control.setFocus(); } } }); } }
Example 7
Source File: AbstractFileStore.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override public IWorkbenchPart open() { final Display display = Display.getDefault(); final boolean[] done = new boolean[1]; display.asyncExec(() -> { fireFileStoreEvent(new FileStoreChangeEvent(EventType.PRE_OPEN, this)); try { activePart = doOpen(); } catch (Throwable e) { done[0] = true; } registerPartListener(activePart, getActiveWindow()); fireFileStoreEvent(new FileStoreChangeEvent(EventType.POST_OPEN, AbstractFileStore.this)); done[0] = true; }); while (!done[0]) { display.syncExec(display::readAndDispatch); } return activePart; }
Example 8
Source File: XtextStyledTextHighlightingReconciler.java From statecharts with Eclipse Public License 1.0 | 6 votes |
/** * Refreshes the highlighting. */ public void refresh() { if (calculator != null) { styledTextXtextAdapter.getXtextDocument().readOnly( new IUnitOfWork.Void<XtextResource>() { @Override public void process(XtextResource state) throws Exception { modelChanged(state); } }); } else { Display display = Display.getDefault(); display.asyncExec(presenter.createSimpleUpdateRunnable()); } }
Example 9
Source File: CommandConsoleFactoryImpl.java From eclipse with Apache License 2.0 | 5 votes |
@Override public OutputStream createErrorStream() { // Get the error stream for the given console (a stream that print in red). final MessageConsoleStream errorStream = console.newMessageStream(); Display display = Display.getCurrent(); if (display == null) { display = Display.getDefault(); } display.asyncExec(() -> errorStream.setColor(new Color(null, 255, 0, 0))); return errorStream; }
Example 10
Source File: Utils.java From EasyShell with Eclipse Public License 2.0 | 5 votes |
public static void executeCommand(final IWorkbench workbench, final String commandName, final Map<String, Object> params, boolean asynch) { if (asynch) { Display display = workbench == null ? Display.getDefault() : workbench.getDisplay(); display.asyncExec( new Runnable(){ @Override public void run() { executeCommand(workbench, commandName, params); } }); } else { executeCommand(workbench, commandName, params); } }
Example 11
Source File: DialogField.java From typescript.java with MIT License | 5 votes |
/** * Posts <code>setFocus</code> to the display event queue. */ public void postSetFocusOnDialogField(Display display) { if (display != null) { display.asyncExec( new Runnable() { public void run() { setFocus(); } } ); } }
Example 12
Source File: CommonLineNumberRulerColumn.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Triggers a redraw in the display thread. * * @since 3.0 */ protected final void doPostRedraw() { if (fCanvas != null && !fCanvas.isDisposed()) { Display d= fCanvas.getDisplay(); if (d != null) { synchronized (fRunnableLock) { if (fIsRunnablePosted) return; fIsRunnablePosted= true; } d.asyncExec(fRunnable); } } }
Example 13
Source File: XtextDocument.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Run the model listeners on the UI thread. * * @note Some of the {@link IXtextModelListener}s assume that the {@link XtextDocument} that is associated with the model is not * changing while they run. To achieve this, we run the {@link IXtextModelListener}s on the UI thread. */ private void notifyModelListenersOnUiThread() { Display display = PlatformUI.getWorkbench().getDisplay(); if (Thread.currentThread() == display.getThread()) { // We are already running on the display thread. Run the listeners immediately. notifyModelListeners(getState()); } else { display.asyncExec(() -> { XtextDocument.this.tryReadOnly(((XtextResource resource) -> { notifyModelListeners(resource); return null; })); }); } }
Example 14
Source File: HighlightingReconciler.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * Refreshes the highlighting. */ public void refresh() { if (oldCalculator != null || newCalculator != null) { new Job("calculating highlighting") { @Override protected IStatus run(IProgressMonitor monitor) { XtextSourceViewer mySourceViewer = sourceViewer; if (mySourceViewer != null) { IXtextDocument document = mySourceViewer.getXtextDocument(); if (document != null) { document.tryReadOnly(new CancelableUnitOfWork<Void,XtextResource>() { @Override public java.lang.Void exec(XtextResource state, CancelIndicator cancelIndicator) throws Exception { beforeRefresh(state, cancelIndicator); modelChanged(state, cancelIndicator); return null; } }); } } return Status.OK_STATUS; } }.schedule(); } else { Display display = getDisplay(); display.asyncExec(presenter.createSimpleUpdateRunnable()); } }
Example 15
Source File: EditorAreaDropAdapter.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void drop(final DropTargetEvent event) { Display d = window.getShell().getDisplay(); final IWorkbenchPage page = window.getActivePage(); if (page != null) { d.asyncExec(new Runnable() { public void run() { asyncDrop(event, page); } }); } }
Example 16
Source File: CopiedOverviewRuler.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override public void update() { if (fCanvas != null && !fCanvas.isDisposed()) { Display d = fCanvas.getDisplay(); if (d != null) { synchronized (fRunnableLock) { if (fIsRunnablePosted) { return; } fIsRunnablePosted = true; } d.asyncExec(fRunnable); } } }
Example 17
Source File: SDWidget.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public void run() { Display display = Display.getDefault(); if ((display == null) || (display.isDisposed())) { return; } display.asyncExec(() -> { if (fSdWidget.isDisposed()) { return; } fSdWidget.fDragX += fDeltaX; fSdWidget.fDragY += fDeltaY; fSdWidget.scrollBy(fDeltaX, fDeltaY); }); }
Example 18
Source File: FixedHighlightingReconciler.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Refreshes the highlighting. */ @Override public void refresh() { if (oldCalculator != null || newCalculator != null) { IDocument document = editor != null ? editor.getDocument() : sourceViewer.getDocument(); if (document instanceof IXtextDocument) { Job job = new Job("Calculating highlighting") { //$NON-NLS-1$ @Override protected IStatus run(final IProgressMonitor monitor) { ((XtextDocument) document).readOnly(new CancelableUnitOfWork<Void, XtextResource>() { @Override public java.lang.Void exec(final XtextResource state, final CancelIndicator cancelIndicator) throws Exception { beforeRefresh(state, cancelIndicator); modelChanged(state, cancelIndicator); return null; } }); return Status.OK_STATUS; } }; job.setSystem(true); job.schedule(); } } else { Display display = getDisplay(); display.asyncExec(presenter.createSimpleUpdateRunnable()); } }
Example 19
Source File: JobGridDelegate.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Add the controls to the tab */ private void addControls() { // Create the tree table... wTree = new Tree( jobGraph.extraViewTabFolder, SWT.V_SCROLL | SWT.H_SCROLL ); wTree.setHeaderVisible( true ); TreeMemory.addTreeListener( wTree, STRING_CHEF_LOG_TREE_NAME ); TreeColumn column1 = new TreeColumn( wTree, SWT.LEFT ); column1.setText( BaseMessages.getString( PKG, "JobLog.Column.JobJobEntry" ) ); column1.setWidth( 200 ); TreeColumn column2 = new TreeColumn( wTree, SWT.LEFT ); column2.setText( BaseMessages.getString( PKG, "JobLog.Column.Comment" ) ); column2.setWidth( 200 ); TreeColumn column3 = new TreeColumn( wTree, SWT.LEFT ); column3.setText( BaseMessages.getString( PKG, "JobLog.Column.Result" ) ); column3.setWidth( 100 ); TreeColumn column4 = new TreeColumn( wTree, SWT.LEFT ); column4.setText( BaseMessages.getString( PKG, "JobLog.Column.Reason" ) ); column4.setWidth( 200 ); TreeColumn column5 = new TreeColumn( wTree, SWT.LEFT ); column5.setText( BaseMessages.getString( PKG, "JobLog.Column.Filename" ) ); column5.setWidth( 200 ); TreeColumn column6 = new TreeColumn( wTree, SWT.RIGHT ); column6.setText( BaseMessages.getString( PKG, "JobLog.Column.Nr" ) ); column6.setWidth( 50 ); TreeColumn column7 = new TreeColumn( wTree, SWT.RIGHT ); column7.setText( BaseMessages.getString( PKG, "JobLog.Column.LogDate" ) ); column7.setWidth( 120 ); FormData fdTree = new FormData(); fdTree.left = new FormAttachment( 0, 0 ); fdTree.top = new FormAttachment( 0, 0 ); fdTree.right = new FormAttachment( 100, 0 ); fdTree.bottom = new FormAttachment( 100, 0 ); wTree.setLayoutData( fdTree ); final Timer tim = new Timer( "JobGrid: " + jobGraph.getMeta().getName() ); TimerTask timtask = new TimerTask() { public void run() { Display display = jobGraph.getDisplay(); if ( display != null && !display.isDisposed() ) { display.asyncExec( new Runnable() { public void run() { // Check if the widgets are not disposed. // This happens is the rest of the window is not yet disposed. // We ARE running in a different thread after all. // // TODO: add a "auto refresh" check box somewhere if ( !wTree.isDisposed() ) { refreshTreeTable(); } } } ); } } }; tim.schedule( timtask, 10L, 2000L ); // refresh every 2 seconds... jobGraph.jobLogDelegate.getJobLogTab().addDisposeListener( new DisposeListener() { public void widgetDisposed( DisposeEvent disposeEvent ) { tim.cancel(); } } ); }
Example 20
Source File: MultiPageReportEditor.java From birt with Eclipse Public License 1.0 | 4 votes |
protected void confirmSave( ) { if ( fIsHandlingActivation ) return; if ( !isExistModelFile( ) && !isClose ) { // Thread.dumpStack( ); fIsHandlingActivation = true; MessageDialog dialog = new MessageDialog( UIUtil.getDefaultShell( ), Messages.getString( "MultiPageReportEditor.ConfirmTitle" ), //$NON-NLS-1$ null, Messages.getString( "MultiPageReportEditor.SaveConfirmMessage" ), //$NON-NLS-1$ MessageDialog.QUESTION, new String[]{ Messages.getString( "MultiPageReportEditor.SaveButton" ), Messages.getString( "MultiPageReportEditor.CloseButton" )}, 0 ); //$NON-NLS-1$ //$NON-NLS-2$ try { if ( dialog.open( ) == 0 ) { doSave( null ); isClose = false; } else { Display display = getSite( ).getShell( ).getDisplay( ); display.asyncExec( new Runnable( ) { public void run( ) { closeEditor( false ); } } ); isClose = true; } } finally { fIsHandlingActivation = false; needReset = false; needReload = false; } } }