Java Code Examples for org.eclipse.jface.operation.ModalContext#run()

The following examples show how to use org.eclipse.jface.operation.ModalContext#run() . 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: TemplateSourceAuthDialog.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
	progressMon.setVisible(true);
	try {
		ModalContext.run(runnable, true, progressMon, getShell().getDisplay());
	} finally {
		progressMon.done();
		progressMon.setVisible(false);
	}
}
 
Example 2
Source File: EditConnectionDialog.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void run(IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
	progressMon.setVisible(true);
	try {
		ModalContext.run(runnable, true, progressMon, getShell().getDisplay());
	} finally {
		progressMon.done();
		progressMon.setVisible(false);
	}
}
 
Example 3
Source File: TSWizardDialog.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This implementation of IRunnableContext#run(boolean, boolean,
 * IRunnableWithProgress) blocks until the runnable has been run, regardless
 * of the value of <code>fork</code>. It is recommended that
 * <code>fork</code> is set to true in most cases. If <code>fork</code>
 * is set to <code>false</code>, the runnable will run in the UI thread
 * and it is the runnable's responsibility to call
 * <code>Display.readAndDispatch()</code> to ensure UI responsiveness.
 * 
 * UI state is saved prior to executing the long-running operation and is
 * restored after the long-running operation completes executing. Any
 * attempt to change the UI state of the wizard in the long-running
 * operation will be nullified when original UI state is restored.
 * 
 */
public void run(boolean fork, boolean cancelable,
		IRunnableWithProgress runnable) throws InvocationTargetException,
		InterruptedException {
	// The operation can only be canceled if it is executed in a separate
	// thread.
	// Otherwise the UI is blocked anyway.
	Object state = null;
	if (activeRunningOperations == 0) {
		state = aboutToStart(fork && cancelable);
	}
	activeRunningOperations++;
	try {
		if (!fork) {
			lockedUI = true;
		}
		ModalContext.run(runnable, fork, getProgressMonitor(), getShell()
				.getDisplay());
		lockedUI = false;
	} finally {
		// explicitly invoke done() on our progress monitor so that its
		// label does not spill over to the next invocation, see bug 271530
		if (getProgressMonitor() != null) {
			getProgressMonitor().done();
		}
		// Stop if this is the last one
		if (state != null) {
			timeWhenLastJobFinished= System.currentTimeMillis();
			stopped(state);
		}
		activeRunningOperations--;
	}
}
 
Example 4
Source File: HsAbstractProgressDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 运行线程
 * @param fork
 * @param cancelable
 * @param runnable
 * @throws InvocationTargetException
 * @throws InterruptedException
 *             ;
 */
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException,
		InterruptedException {
	// The operation can only be canceled if it is executed in a separate
	// thread.
	// Otherwise the UI is blocked anyway.
	Object state = null;
	if (activeRunningOperations == 0) {
		state = aboutToStart(fork && cancelable);
	}
	activeRunningOperations++;
	try {
		if (!fork) {
			lockedUI = true;
		}
		ModalContext.run(runnable, fork, getProgressMonitor(), getShell().getDisplay());
		lockedUI = false;
	} finally {
		// explicitly invoke done() on our progress monitor so that its
		// label does not spill over to the next invocation, see bug 271530
		if (getProgressMonitor() != null) {
			getProgressMonitor().done();
		}
		// Stop if this is the last one
		if (state != null) {
			timeWhenLastJobFinished = System.currentTimeMillis();
			stopped(state);
		}
		activeRunningOperations--;
	}
}
 
Example 5
Source File: TSWizardDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This implementation of IRunnableContext#run(boolean, boolean,
 * IRunnableWithProgress) blocks until the runnable has been run, regardless
 * of the value of <code>fork</code>. It is recommended that
 * <code>fork</code> is set to true in most cases. If <code>fork</code>
 * is set to <code>false</code>, the runnable will run in the UI thread
 * and it is the runnable's responsibility to call
 * <code>Display.readAndDispatch()</code> to ensure UI responsiveness.
 * 
 * UI state is saved prior to executing the long-running operation and is
 * restored after the long-running operation completes executing. Any
 * attempt to change the UI state of the wizard in the long-running
 * operation will be nullified when original UI state is restored.
 * 
 */
public void run(boolean fork, boolean cancelable,
		IRunnableWithProgress runnable) throws InvocationTargetException,
		InterruptedException {
	// The operation can only be canceled if it is executed in a separate
	// thread.
	// Otherwise the UI is blocked anyway.
	Object state = null;
	if (activeRunningOperations == 0) {
		state = aboutToStart(fork && cancelable);
	}
	activeRunningOperations++;
	try {
		if (!fork) {
			lockedUI = true;
		}
		ModalContext.run(runnable, fork, getProgressMonitor(), getShell()
				.getDisplay());
		lockedUI = false;
	} finally {
		// explicitly invoke done() on our progress monitor so that its
		// label does not spill over to the next invocation, see bug 271530
		if (getProgressMonitor() != null) {
			getProgressMonitor().done();
		}
		// Stop if this is the last one
		if (state != null) {
			timeWhenLastJobFinished= System.currentTimeMillis();
			stopped(state);
		}
		activeRunningOperations--;
	}
}
 
Example 6
Source File: SimulationControl.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void startProgress() {
	try {
		Display display = Display.getCurrent();
		SimulationProgress progress = new SimulationProgress(display,
				editor, page);
		ModalContext.run(progress, true, monitor, display);
	} catch (Exception e) {
		log.error("Could not start simulation progress", e);
	}
}
 
Example 7
Source File: SootLauncher.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
protected void runSootDirectly(String mainClass) {
	
	int length = getSootCommandList().getList().size();
	String temp [] = new String [length];
	
	getSootCommandList().getList().toArray(temp);
	
       String mainProject;
       String realMainClass;
       if(mainClass.contains(":")) {
       	String[] split = mainClass.split(":");
		mainProject = split[0];
       	realMainClass = split[1];
       } else {
       	mainProject = null;
       	realMainClass = mainClass;
       }
	
   	newProcessStarting(realMainClass,mainProject);
       
	sendSootOutputEvent(realMainClass);
	sendSootOutputEvent(" ");
	
	for (int i = 0; i < temp.length; i++) {
		
		sendSootOutputEvent(temp[i]);
		sendSootOutputEvent(" ");
	}
	sendSootOutputEvent("\n");
	
	
	IRunnableWithProgress op; 
	try {   
           op = new SootRunner(temp, Display.getCurrent(), mainClass);
          	((SootRunner)op).setParent(this);
           ModalContext.run(op, true, new NullProgressMonitor(), Display.getCurrent());
		} 
		catch (InvocationTargetException e1) {
   		// handle exception
   		System.out.println("InvocationTargetException: "+e1.getMessage());
   		System.out.println("InvocationTargetException: "+e1.getTargetException());
           System.out.println(e1.getStackTrace());
		} 
		catch (InterruptedException e2) {
   		// handle cancelation
   		System.out.println("InterruptedException: "+e2.getMessage());
		}

}