本文整理汇总了Java中org.eclipse.jface.operation.ModalContext类的典型用法代码示例。如果您正苦于以下问题:Java ModalContext类的具体用法?Java ModalContext怎么用?Java ModalContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModalContext类属于org.eclipse.jface.operation包,在下文中一共展示了ModalContext类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: open
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
/**
* If informations are available, opens a <em>System Information</em>
* dialog, otherwise opens a info message box.
*
* @param shell the parent shell
*
* @see #isAvailable()
*/
public static void open(final Shell shell) {
try {
shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
final SystemInformationGatherer gatherer = new SystemInformationGatherer();
ModalContext.run(gatherer, true, new NullProgressMonitor(), shell.getDisplay());
if (gatherer.getProperties() != null || gatherer.getEnv() != null || gatherer.getJvmArgs() != null) {
new SystemInformationDialog(shell, gatherer.getProperties(), gatherer.getEnv(), gatherer.getJvmArgs()).open();
}
else {
final MessageBox box = new MessageBox(shell, SWT.ICON_INFORMATION);
box.setText(JFaceMessages.get(LBL_SYSTEM_INFO_DIALOG_TITLE));
box.setMessage(JFaceMessages.get(LBL_SYSTEM_INFO_NOT_AVAILABLE));
box.open();
}
}
catch (final Exception e) {
throw new IllegalStateException(e);
}
finally {
shell.setCursor(null);
}
}
示例2: exportExternalClassFolderElement
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
private void exportExternalClassFolderElement(IJavaElement javaElement, IPath classFolderPath, IProgressMonitor progressMonitor) throws JavaModelException, InterruptedException {
if (javaElement instanceof IClassFile) {
IClassFile classFile= (IClassFile) javaElement;
IPath path= classFile.getPath();
IPath destination= path.removeFirstSegments(classFolderPath.segmentCount()).setDevice(null);
try {
((IJarBuilderExtension) fJarBuilder).writeFile(path.toFile(), destination);
} catch (CoreException e) {
handleCoreExceptionOnExport(e);
} finally {
progressMonitor.worked(1);
ModalContext.checkCanceled(progressMonitor);
}
} else if (javaElement instanceof IPackageFragment) {
IJavaElement[] children= ((IPackageFragment) javaElement).getChildren();
for (int i= 0; i < children.length; i++) {
exportExternalClassFolderElement(children[i], classFolderPath, progressMonitor);
}
}
}
示例3: exportResource
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
private void exportResource(IProgressMonitor progressMonitor, IResource resource, int leadingSegmentsToRemove) throws InterruptedException {
if (resource instanceof IContainer) {
IContainer container= (IContainer)resource;
IResource[] children;
try {
children= container.members();
} catch (CoreException e) {
// this should never happen because an #isAccessible check is done before #members is invoked
addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_errorDuringExport, BasicElementLabels.getPathLabel(container.getFullPath(), false)), e);
return;
}
for (int i= 0; i < children.length; i++)
exportResource(progressMonitor, children[i], leadingSegmentsToRemove);
} else if (resource instanceof IFile) {
try {
IPath destinationPath= resource.getFullPath().removeFirstSegments(leadingSegmentsToRemove);
progressMonitor.subTask(Messages.format(JarPackagerMessages.JarFileExportOperation_exporting, BasicElementLabels.getPathLabel(destinationPath, false)));
fJarBuilder.writeFile((IFile)resource, destinationPath);
} catch (CoreException ex) {
handleCoreExceptionOnExport(ex);
} finally {
progressMonitor.worked(1);
ModalContext.checkCanceled(progressMonitor);
}
}
}
示例4: warningGlobalSymbols
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
public static boolean[] warningGlobalSymbols(final String projectName,
final String objectName, final String objectType,
final String propertyName, final String propertyValue,
final Set<String> undefinedSymboles, final boolean showCheckBox) {
final boolean[] result = {false,false};
getDisplay().syncExec(
new Runnable() {
public void run() {
try {
int level = ModalContext.getModalLevel();
if (level > 0) {
// prevents double modal windows: dead lock on linux/gtk studio
getDisplay().syncExec(this);
return;
}
GlobalsSymbolsWarnDialog dialogGlobalSymbols = new GlobalsSymbolsWarnDialog(getDisplay().getActiveShell(), projectName,
objectName, objectType,
propertyName, propertyValue,
undefinedSymboles, showCheckBox);
dialogGlobalSymbols.open();
result[0] = dialogGlobalSymbols.getCreateAction();
result[1] = dialogGlobalSymbols.getCheckButtonSelection();
} catch (Exception e){
ConvertigoPlugin.logException(e, "Error while trying to open warning global symbols box");
}
}
}
);
return result;
}
示例5: run
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
@Override
public void run(boolean fork, boolean cancelable,
final IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
ProgressMonitorPart mpart = (ProgressMonitorPart) getProgressMonitor();
mpart.setVisible(true);
try {
ModalContext.run(runnable, fork, getProgressMonitor(), getShell()
.getDisplay());
} finally {
mpart.done();
mpart.setVisible(false);
}
}
示例6: run
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
/**
* 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);
}
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--;
}
}
示例7: internalRun
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
private void internalRun(boolean fork, final IRunnableWithProgress runnable) throws InvocationTargetException, InterruptedException {
Thread thread= Thread.currentThread();
// Do not spawn another thread if we are already in a modal context
// thread or inside a busy context thread.
if (thread instanceof ThreadContext || ModalContext.isModalContextThread(thread))
fork= false;
if (fork) {
final ThreadContext t= new ThreadContext(runnable);
t.start();
t.sync();
// Check if the separate thread was terminated by an exception
Throwable throwable= t.fThrowable;
if (throwable != null) {
if (throwable instanceof InvocationTargetException) {
throw (InvocationTargetException) throwable;
} else if (throwable instanceof InterruptedException) {
throw (InterruptedException) throwable;
} else if (throwable instanceof OperationCanceledException) {
throw new InterruptedException();
} else {
throw new InvocationTargetException(throwable);
}
}
} else {
try {
runnable.run(new NullProgressMonitor());
} catch (OperationCanceledException e) {
throw new InterruptedException();
}
}
}
示例8: run
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
/**
* 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--;
}
}
示例9: run
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
/**
* 运行线程
* @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--;
}
}
示例10: startProgress
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
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);
}
}
示例11: run
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
/**
* 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.
Map<String, 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--;
}
}
示例12: runSootDirectly
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
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());
}
}
示例13: exportFile
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
/**
* Export the passed file to the specified location
*
* @param file
* org.eclipse.core.resources.IFile
* @param location
* org.eclipse.core.runtime.IPath
*/
protected void exportFile(IFile file, IPath location) throws InterruptedException {
IPath fullPath = location.append(file.getName()).removeFileExtension().addFileExtension("moml");
monitor.subTask(file.getFullPath().toString());
String properPathString = fullPath.toOSString();
File targetFile = new File(properPathString);
if (targetFile.exists()) {
if (!targetFile.canWrite()) {
errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind("Cannot overwrite file: {0}", targetFile.getAbsolutePath()), null));
monitor.worked(1);
return;
}
if (overwriteState == OVERWRITE_NONE) {
return;
}
if (overwriteState != OVERWRITE_ALL) {
String overwriteAnswer = overwriteCallback.queryOverwrite(properPathString);
if (overwriteAnswer.equals(IOverwriteQuery.CANCEL)) {
throw new InterruptedException();
}
if (overwriteAnswer.equals(IOverwriteQuery.NO)) {
monitor.worked(1);
return;
}
if (overwriteAnswer.equals(IOverwriteQuery.NO_ALL)) {
monitor.worked(1);
overwriteState = OVERWRITE_NONE;
return;
}
if (overwriteAnswer.equals(IOverwriteQuery.ALL)) {
overwriteState = OVERWRITE_ALL;
}
}
}
try {
// 1. obtain Diagram for the file
Diagram diagram = GraphitiUiInternal.getEmfService().getDiagramFromFile(file, new ResourceSetImpl());
// 2. find root CompositeActor
CompositeActor toplevel = (CompositeActor) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
// 3. push location info of diagram model elements to the Ptolemy II model elements
pushLocations(diagram, toplevel);
// 4. exportMOML to the destination file
FileUtils.writeStringToFile(new File(fullPath.toOSString()), toplevel.getWrappedObject().exportMoML());
} catch (IOException e) {
errorTable.add(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, NLS.bind("Error exporting {0}: {1}", fullPath, e.getMessage()), e));
}
monitor.worked(1);
ModalContext.checkCanceled(monitor);
}
示例14: run
import org.eclipse.jface.operation.ModalContext; //导入依赖的package包/类
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException,
InterruptedException {
IProgressMonitor monitor = getProgressMonitor();
ModalContext.run(runnable, true, monitor, Display.getDefault());
}