Java Code Examples for org.eclipse.swt.widgets.Display#asyncExec()

The following examples show how to use org.eclipse.swt.widgets.Display#asyncExec() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@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 2
Source Project: neoscada   File: GeneratorView.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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 3
Source Project: birt   File: ResourceAction.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
@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
/**
 * 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 Project: goclipse   File: SWTUtil.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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
/**
 * 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 8
@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 9
/**
 * 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 10
Source Project: tracecompass   File: SDWidget.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@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 11
@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 12
@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 13
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 14
/**
 * 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
/**
 * 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 16
/**
 * 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 17
Source Project: typescript.java   File: DialogField.java    License: MIT License 5 votes vote down vote up
/**
 * 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 18
Source Project: EasyShell   File: Utils.java    License: Eclipse Public License 2.0 5 votes vote down vote up
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 19
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;
		}

	}
}
 
Example 20
Source Project: pentaho-kettle   File: JobGridDelegate.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 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();
    }
  } );

}