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

The following are Jave code examples for showing how to use asyncExec() of the org.eclipse.swt.widgets.Display class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: neoscada   File: GeneratorView.java   Source Code and License Vote up 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
Project: neoscada   File: Activator.java   Source Code and License Vote up 6 votes
/**
 * Notify error using message box (thread safe).
 * @param message The message to display
 * @param error The error that occurred
 */
public void notifyError ( final String message, final Throwable error )
{
    final Display display = getWorkbench ().getDisplay ();

    if ( !display.isDisposed () )
    {
        display.asyncExec ( new Runnable () {

            @Override
            public void run ()
            {
                final Shell shell = getWorkbench ().getActiveWorkbenchWindow ().getShell ();
                logger.debug ( "Shell disposed: {}", shell.isDisposed () );
                if ( !shell.isDisposed () )
                {
                    final IStatus status = new OperationStatus ( IStatus.ERROR, PLUGIN_ID, 0, message + ":" + error.getMessage (), error );
                    ErrorDialog.openError ( shell, null, message, status );
                }
            }
        } );
    }
}
 
Example 3
Project: neoscada   File: FactoryEditor.java   Source Code and License Vote up 6 votes
protected void handleSetResult ( final FactoryInformation factory, final String connectionUri )
{
    final Display display = getSite ().getShell ().getDisplay ();
    if ( !display.isDisposed () )
    {
        display.asyncExec ( new Runnable () {

            @Override
            public void run ()
            {
                if ( !display.isDisposed () )
                {
                    setResult ( factory, connectionUri );
                }
            }
        } );
    }
}
 
Example 4
Project: convertigo-eclipse   File: ConvertigoPlugin.java   Source Code and License Vote up 6 votes
private static void messageBoxWithoutReturnCode(final String message, int options) {
	final Display display = getDisplay();
	
	Runnable runnable = new Runnable() {
		public void run() {
			try {
				messageBox(null, message, SWT.OK | SWT.ICON_INFORMATION);
			}
			catch (Exception e){
				ConvertigoPlugin.logException(e, "Error while trying to open message box");
			}
		};
	};
	
	if (display.getThread() != Thread.currentThread()) {
		display.asyncExec(runnable);		
	} else {
		display.syncExec(runnable);
	}
}
 
Example 5
Project: n4js   File: WorkingSetManagerBrokerImpl.java   Source Code and License Vote up 5 votes
private void asyncRefreshCommonViewer(final ProjectExplorer explorer, final boolean resetInput) {

		// do deferred initialization
		this.getWorkingSetManagers().stream()
				.filter(m -> (m instanceof IDeferredInitializer))
				.map(m -> (IDeferredInitializer) m)
				.filter(m -> m.isInitializationRequired())
				.forEach(m -> {
					m.lateInit();
				});

		final CommonViewer viewer = explorer.getCommonViewer();
		final Display d = getDisplay();
		if (!d.isDisposed()) {
			if (resetInput) {
				d.asyncExec(() -> {
					if (!viewer.getTree().isDisposed())
						viewer.setInput(viewer.getInput());
				});
			} else {
				d.asyncExec(() -> {
					if (!viewer.getTree().isDisposed())
						viewer.refresh(true);
				});
			}
		}
	}
 
Example 6
Project: AgentWorkbench   File: PlugInApplication.java   Source Code and License Vote up 5 votes
/**
 * Stop Eclipse UI.
 */
private void stopEclipseUI() {
	
	if (PlatformUI.isWorkbenchRunning()==false) return;
	
	final IWorkbench workbench = PlatformUI.getWorkbench();
	final Display display = workbench.getDisplay();
	display.asyncExec(new Runnable() {
		public void run() {
			if (!display.isDisposed()) {
				workbench.close();
			}
		}
	});
}
 
Example 7
Project: neoscada   File: ViewerLabelProvider.java   Source Code and License Vote up 5 votes
protected final void fireChangeEvent ( final Collection<?> changes )
{

    final LabelProviderChangedEvent event = new LabelProviderChangedEvent ( ViewerLabelProvider.this, changes.toArray () );
    final ILabelProviderListener[] listenerArray = ViewerLabelProvider.this.listeners.toArray ( new ILabelProviderListener[ViewerLabelProvider.this.listeners.size ()] );

    final Display display = getDisplay ();
    if ( !display.isDisposed () )
    {
        display.asyncExec ( new Runnable () {

            public void run ()
            {
                for ( final ILabelProviderListener listener : listenerArray )
                {
                    try
                    {
                        listener.labelProviderChanged ( event );
                    }
                    catch ( final Exception e )
                    {
                        Policy.getLog ().log ( new Status ( IStatus.ERROR, Policy.JFACE_DATABINDING, e.getLocalizedMessage (), e ) );
                    }
                }

            }
        } );

    }
}
 
Example 8
Project: openaudible   File: SWTAsync.java   Source Code and License Vote up 5 votes
public static void slow(SWTAsync t) {
    t.logTimeStats = false;
    if (inDisplayThread()) {
        t.run();
    } else {
        Display d2 = Application.display;
        d2.asyncExec(t);
    }
}
 
Example 9
Project: neoscada   File: ConfirmationDialogFuture.java   Source Code and License Vote up 5 votes
public ConfirmationDialogFuture ( final Display display, final Shell parentShell, final Callback[] callbacks, final String dialogTitle )
{
    display.asyncExec ( new Runnable () {

        @Override
        public void run ()
        {
            openDialog ( display, parentShell, callbacks, dialogTitle );
        }
    } );
}
 
Example 10
Project: convertigo-eclipse   File: ProjectDeployDialog.java   Source Code and License Vote up 5 votes
public void setTextLabel(String text) {
	final Display display = getParentShell().getDisplay();
	final String labelText = text;
	display.asyncExec(new Runnable() {
		public void run() {
			if (!labelProgression.isDisposed())
				labelProgression.setText(labelText);
		}
	});
}
 
Example 11
Project: openaudible   File: SWTAsync.java   Source Code and License Vote up 5 votes
public static void run(Display d, SWTAsync t) {
    if (inDisplayThread()) {
        t.run();
    } else {
        d.asyncExec(t);
    }
}
 
Example 12
Project: eclipse-plugin-commander   File: CommanderHandler.java   Source Code and License Vote up 5 votes
private Consumer<QuickAccessElement> resolvedAction(Display display, PersistedWorkingSet<QuickAccessElement> historyStore) {
	return (item) -> {
		display.asyncExec(item::execute);
		historyStore.addToHistory(item);
		historyStore.save();
	};
}
 
Example 13
Project: openaudible   File: SWTAsync.java   Source Code and License Vote up 5 votes
public static void run(SWTAsync t) {

        if (inDisplayThread()) {
            t.run();
        } else {
            Display d2 = Application.display;
            d2.asyncExec(t);
        }
    }
 
Example 14
Project: pgcodekeeper   File: UiSync.java   Source Code and License Vote up 5 votes
public static void exec(Display d, Runnable r) {
    try {
        d.asyncExec(r);
    } catch (SWTException ex) {
        if (ex.code != SWT.ERROR_WIDGET_DISPOSED) {
            throw ex;
        }
        // do nothing: UI is already dead
    }
}
 
Example 15
Project: BiglyBT   File: BuddyPluginView.java   Source Code and License Vote up 5 votes
@Override
public void
openChat(
	final ChatInstance chat )
{
	final Display display = Display.getDefault();

	if ( display.isDisposed()){

		return;
	}

	display.asyncExec(
		new Runnable()
		{
			@Override
			public void
			run()
			{
				if ( display.isDisposed()){

					return;
				}

				BuddyPluginViewBetaChat.createChatWindow( BuddyPluginView.this, plugin, chat );
			}
		});
}
 
Example 16
Project: eZooKeeper   File: SwtThreadSafeDelegatingInvocationHandler.java   Source Code and License Vote up 4 votes
@Override
protected Object subInvoke(Object proxy, Method method, Object[] args) throws Throwable {

    Display currentDisplay = Display.getCurrent();
    Display widgetDisplay = null;

    Widget widget = getWidget();
    if (widget != null) {
        if (widget.isDisposed()) {
            // System.err.println("ERROR:  Invoking: " + method.getName() + " on Widget: " + widget +
            // " which is disposed.");
            return null;
        }
        widgetDisplay = widget.getDisplay();
    }

    if (currentDisplay == null && widgetDisplay == null) {
        // The current thread is not a UI thread but no widget display was provided so...
        return baseInvoke(proxy, method, args);
    }
    else if (currentDisplay != null && (widgetDisplay == null || currentDisplay == widgetDisplay)) {
        // Current thread is the widget's UI thread (or at least *a* UI thread).
        return baseInvoke(proxy, method, args);
    }
    else {
        // Current thread is not the widget's UI thread.

        IBaseInvokeRunnable runnable = createBaseInvokeRunnable(proxy, method, args);

        if (isAsync()) {
            widgetDisplay.asyncExec(runnable);
            return null;
        }

        widgetDisplay.syncExec(runnable);
        Throwable error = runnable.getError();
        if (error != null) {
            throw error;
        }
        return runnable.getResult();
    }
}
 
Example 17
Project: convertigo-eclipse   File: ProjectDeployDialog.java   Source Code and License Vote up 4 votes
private void deploy() throws EngineException, RemoteAdminException {
	try {
		String projectName = ConvertigoPlugin.projectManager.currentProject.getName();

		setTextLabel("Archive creation");
		ConvertigoPlugin.logDebug("Creation of the archive...");
		try {				
			if (listTestCasesSelected.size() > 0) {
				CarUtils.makeArchive(ConvertigoPlugin.projectManager.currentProject, listTestCasesSelected);
			} else {
				CarUtils.makeArchive(ConvertigoPlugin.projectManager.currentProject);
			}
		}
		catch(com.twinsoft.convertigo.engine.EngineException e) {
			throw new com.twinsoft.convertigo.engine.EngineException("The archive creation has failed: (EngineException) "+ e.getMessage());
		}
	
		ConvertigoPlugin.logDebug("Archive successfully generated!");
           
		setTextLabel("Authenticating to the Convertigo server");
		
		if (convertigoServer.indexOf('/') == -1) convertigoServer += "/convertigo";
		
		RemoteAdmin remoteAdmin = new RemoteAdmin(convertigoServer, isHttps, trustAllCertificates);

		ConvertigoPlugin.logDebug("Trying to connect to the Convertigo remote server...");
    		ConvertigoPlugin.logDebug("Username: " + convertigoUserName);
		ConvertigoPlugin.logDebug("Password: " + "**************");

		setTextLabel("Connection to the Convertigo server");
	   
		remoteAdmin.login(convertigoUserName, convertigoUserPassword);
		
		setTextLabel("Deployment of the archive on the Convertigo server");
           
		File file = new File(Engine.PROJECTS_PATH + "/" + projectName + ".car");
		
		remoteAdmin.deployArchive(file,bAssembleXsl);

		bFinished = true;

		ConvertigoPlugin.logDebug("Deployment successfull!");
	}
	finally {
		final Display display = getParentShell().getDisplay();
		if (display != null)
			display.asyncExec(new Runnable() {
				public void run() {
					if (bFinished) {
						setTextLabel("The archive deployment has been correctly done.");
						if (getButton(IDialogConstants.OK_ID) != null) {
							getButton(IDialogConstants.OK_ID).setEnabled(false);
							getButton(IDialogConstants.CANCEL_ID).setText("Finish");
						}
					}
					else {
						if (getButton(IDialogConstants.OK_ID) != null)
							getButton(IDialogConstants.OK_ID).setEnabled(true);
						setTextLabel("Progression");
					}
				}
			});
	}
}
 
Example 18
Project: openaudible   File: SWTAsync.java   Source Code and License Vote up 4 votes
public static void queueRun(SWTAsync t) {
    Display d2 = Application.display;
    d2.asyncExec(t);
}
 
Example 19
Project: Hydrograph   File: ResourceChangeListener.java   Source Code and License Vote up 4 votes
public boolean visit(IResourceDelta delta) {
	if (delta == null)
		return true;

	IEditorInput editorInput = editorPart.getEditorInput();
	if (editorInput instanceof FileEditorInput) {

		if (!delta.getResource().equals(
				((FileEditorInput) editorInput).getFile())) {
			return true;
		}
	} else {
		return true; // this is not an input type our editor handles
	}

	if (delta.getKind() == IResourceDelta.REMOVED) {
		if ((IResourceDelta.MOVED_TO & delta.getFlags()) == 0) {

			/*
			 *  * if the file was deleted NOTE: The case where an open,
			 * unsaved file is deleted being handled by the PartListener
			 * added to the Workbench in the initialize() method.
			 */

			if (!editorPart.isDirty()) {
				closeEditorDoNotSave();
			}
		}

		else { // else if it was moved or renamed
			final IFile newFile = ResourcesPlugin.getWorkspace()
					.getRoot().getFile(delta.getMovedToPath());

			Display display = editorPart.getSite().getShell().getDisplay();
			display.asyncExec(new Runnable() {
				public void run() {
					((ELTGraphicalEditor)editorPart).setInput(new FileEditorInput(newFile));
				}
			});
		}
	}
	return false;
}
 
Example 20
Project: xcalendar   File: SwtUtils.java   Source Code and License Vote up 4 votes
public static void async(@Nullable Display display, Runnable task) {
	if(display == null) display = getDisplay(); display.asyncExec(task);
}