Example usage for org.eclipse.jface.operation IRunnableWithProgress run

List of usage examples for org.eclipse.jface.operation IRunnableWithProgress run

Introduction

In this page you can find the example usage for org.eclipse.jface.operation IRunnableWithProgress run.

Prototype

public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException;

Source Link

Document

Runs this operation.

Usage

From source file:com.mentor.nucleus.bp.model.compare.contentmergeviewer.ModelContentMergeViewer.java

License:Open Source License

protected void writeData(ICompareInput input, boolean toLeft) {
    try {//from w  ww  . j av  a 2  s. c o m
        ITypedElement destination = input.getLeft();
        Ooaofooa root = Ooaofooa.getInstance(ModelRoot.getLeftCompareRootPrefix() + input.hashCode());
        if (!toLeft) {
            destination = input.getRight();
            root = Ooaofooa.getInstance(ModelRoot.getRightCompareRootPrefix() + input.hashCode());
        }
        final NonRootModelElement rootElement = modelManager.getRootElements(destination, null, false, root,
                ModelCacheManager.getLeftKey(input))[0];
        if (destination instanceof IEditableContent) {
            // before saving copy all graphical changes that are
            // non-conflicting
            List<TreeDifference> incomingGraphicalDifferences = getIncomingGraphicalDifferences(toLeft);
            if (incomingGraphicalDifferences.size() > 0) {
                mergeIncomingGraphicalChanges(incomingGraphicalDifferences, toLeft, input);
            }
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            AbstractModelExportFactory modelExportFactory = CorePlugin.getModelExportFactory();
            IRunnableWithProgress runnable = modelExportFactory.create(root, baos, rootElement);
            CoreExport.forceProxyExport = true;
            runnable.run(new NullProgressMonitor());
            CoreExport.forceProxyExport = false;
            ((IEditableContent) destination).setContent(baos.toByteArray());
            if (destination instanceof LocalResourceTypedElement) {
                ((IFile) ((LocalResourceTypedElement) destination).getResource()).setContents(
                        new ByteArrayInputStream(baos.toByteArray()), IFile.FORCE | IFile.KEEP_HISTORY,
                        new NullProgressMonitor());
            }
            WorkspaceJob job = new WorkspaceJob("Refresh workspace content") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                    NonRootModelElement elementGlobally = (NonRootModelElement) Ooaofooa.getDefaultInstance()
                            .getInstanceList(rootElement.getClass()).getGlobal(rootElement.getInstanceKey());
                    if (elementGlobally != null) {
                        if (elementGlobally.getFile() != null) {
                            elementGlobally.getFile().refreshLocal(IFile.DEPTH_INFINITE, monitor);
                        }
                    }
                    return Status.OK_STATUS;
                }
            };
            job.schedule(1500);
        }

    } catch (FileNotFoundException e) {
        ComparePlugin.writeToLog("Unable to save merge data.", e, ModelContentMergeViewer.class);
    } catch (ModelLoadException e) {
        ComparePlugin.writeToLog("Unable to save merge data.", e, ModelContentMergeViewer.class);
    } catch (InvocationTargetException e) {
        ComparePlugin.writeToLog("Unable to save merge data.", e, ModelContentMergeViewer.class);
    } catch (InterruptedException e) {
        ComparePlugin.writeToLog("Unable to save merge data.", e, ModelContentMergeViewer.class);
    } catch (CoreException e) {
        ComparePlugin.writeToLog("Unable to save merge data.", e, ModelContentMergeViewer.class);
    }
}

From source file:com.mentor.nucleus.bp.model.compare.ModelMergeProcessor.java

License:Open Source License

private static String copyExternal(ModelRoot modelRoot, Object element, boolean writeAsProxy,
        boolean forceProxies) {
    if (element instanceof NonRootModelElement) {
        // there is a strange special case situation
        // for Supertype/Subtype associations, it exists
        // because during a copy with the supertype included
        // the Association must be included, which in turn
        // includes the subtype parts even if not selected for
        // a copy Therefore we must add the O_OBJ to the selection
        // to get around this limitation here if the element is
        // the subtype object
        ModelClass_c[] clazzes = null;/*from   w w w  .  j av a 2s .  c  o  m*/
        if (element instanceof Association_c) {
            ClassAsSubtype_c[] subtypes = ClassAsSubtype_c.getManyR_SUBsOnR213(
                    SubtypeSupertypeAssociation_c.getOneR_SUBSUPOnR206((Association_c) element));
            if (subtypes != null && subtypes.length != 0) {
                clazzes = ModelClass_c.getManyO_OBJsOnR201(ClassInAssociation_c
                        .getManyR_OIRsOnR203(ReferringClassInAssoc_c.getManyR_RGOsOnR205(subtypes)));
                for (ModelClass_c clazz : clazzes) {
                    Selection.getInstance().addToSelection(clazz);
                }
            }
        } else if (element instanceof ClassAsSubtype_c) {
            ModelClass_c clazz = ModelClass_c.getOneO_OBJOnR201(ClassInAssociation_c
                    .getOneR_OIROnR203(ReferringClassInAssoc_c.getOneR_RGOOnR205((ClassAsSubtype_c) element)));
            Selection.getInstance().addToSelection(clazz);
            clazzes = new ModelClass_c[] { clazz };
        }
        NonRootModelElement[] elements = new NonRootModelElement[] { (NonRootModelElement) element };
        if (!writeAsProxy) {
            NonRootModelElement[] specialElements = includeSpecialElements(element, modelRoot);
            // the stream export logic writes the supertype for
            // an element if that element is the one selected
            // we actually need to export (not just write the sql statement)
            // the supertype, so if this element has a supertype use it instead
            // however, only do this if the supertype does not already exist
            NonRootModelElement supertype = getLastSupertype((NonRootModelElement) element);
            Object existingObject = findObjectInDestination(modelRoot, supertype);
            if (existingObject == null) {
                // include the supertype
                element = supertype;
            }
            NonRootModelElement[] originalElements = new NonRootModelElement[] {
                    (NonRootModelElement) element };
            elements = new NonRootModelElement[originalElements.length + specialElements.length];
            System.arraycopy(originalElements, 0, elements, 0, originalElements.length);
            if (specialElements.length != 0) {
                System.arraycopy(specialElements, 0, elements, originalElements.length, specialElements.length);
            }
        }
        CoreExport.forceProxyExport = forceProxies;
        CoreExport.ignoreAlternateChildren = true;
        CoreExport.exportSupertypes = false;
        CoreExport.ignoreMissingPMCErrors = true;
        if (writeAsProxy) {
            CoreExport.forceWriteAsProxy = true;
        }
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            String streamContents = "";
            ;
            IRunnableWithProgress progress = CorePlugin.getStreamExportFactory().create(out, elements, true,
                    false, true);
            progress.run(new NullProgressMonitor());
            out.close();
            streamContents = new String(out.toByteArray());
            return streamContents;
        } catch (InvocationTargetException e) {
            ComparePlugin.writeToLog("Unable to copy external data.", e, CorePlugin.class);
        } catch (InterruptedException e) {
            ComparePlugin.writeToLog("Unable to copy external data.", e, CorePlugin.class);
        } catch (IOException e) {
            ComparePlugin.writeToLog("Unable to copy external data.", e, CorePlugin.class);
        } finally {
            // if the clazz is not null then remove from the
            // selection
            if (clazzes != null && clazzes.length != 0) {
                for (ModelClass_c clazz : clazzes) {
                    Selection.getInstance().removeFromSelection(clazz);
                }
            }
            CoreExport.forceProxyExport = false;
            CoreExport.ignoreAlternateChildren = false;
            CoreExport.exportSupertypes = true;
            CoreExport.ignoreMissingPMCErrors = false;
            if (writeAsProxy) {
                CoreExport.forceWriteAsProxy = false;
            }
        }
    }
    return "";
}

From source file:com.microsoft.tfs.client.common.ui.framework.runnable.BusyIndicatorRunnableContext.java

License:Open Source License

@Override
public void run(final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {
    BusyIndicator.showWhile(display, new Runnable() {
        @Override//from  w w  w  .ja  v a  2s. com
        public void run() {
            try {
                runnable.run(new NullProgressMonitor());
            } catch (final InvocationTargetException e) {
                throw new RuntimeException(e);
            } catch (final InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
}

From source file:com.mobilesorcery.sdk.core.MoSyncBuilder.java

License:Open Source License

public static IRunnableWithProgress createBuildJob(final IProject project, final IBuildSession buildSession,
        final List<IBuildVariant> variantsToBuild) {
    return new IRunnableWithProgress() {

        @Override/*from  w  w  w  .ja va  2  s  .co m*/
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(MessageFormat.format("Building {0} variants", variantsToBuild.size()),
                    variantsToBuild.size());

            for (IBuildVariant variantToBuild : variantsToBuild) {
                SubProgressMonitor jobMonitor = new SubProgressMonitor(monitor, 1);
                if (!monitor.isCanceled()) {
                    IRunnableWithProgress buildJob = createBuildJob(project, buildSession, variantToBuild);
                    buildJob.run(jobMonitor);
                }
            }
        }
    };
}

From source file:com.mobilesorcery.sdk.finalizer.core.FinalizerParser.java

License:Open Source License

public void execute(Reader script, IProgressMonitor monitor)
        throws IOException, ParseException, InvocationTargetException, InterruptedException {
    ArrayList<IBuildVariant> variantsToBuild = new ArrayList<IBuildVariant>();

    MoSyncProject project = MoSyncProject.create(this.project);
    //autoSwitchConfiguration(project);

    int lineNo = 1;
    LineNumberReader lines = new LineNumberReader(script);
    for (String line = lines.readLine(); line != null; line = lines.readLine()) {
        IProfile profileToBuild = parse(project, line, lineNo);
        if (profileToBuild != null) {
            IBuildConfiguration cfg = this.cfgId == null ? project.getActiveBuildConfiguration()
                    : project.getBuildConfiguration(cfgId);
            IBuildVariant variant = MoSyncBuilder.getVariant(project, profileToBuild, cfg);
            variantsToBuild.add(variant);
        }//from  w w w  .  j a  v  a 2 s  . c o  m
        lineNo++;
    }

    if (variantsToBuild.isEmpty()) {
        throw new ParseException(Messages.FinalizerParser_ParseError_0, 0);
    }
    IBuildSession buildSession = MoSyncBuilder.createFinalizerBuildSession(variantsToBuild);
    IRunnableWithProgress buildJob = MoSyncBuilder.createBuildJob(project.getWrappedProject(), buildSession,
            variantsToBuild);
    buildJob.run(monitor);
}

From source file:com.nextep.designer.ui.dialogs.TitleAreaDialogWrapper.java

License:Open Source License

@Override
public void run(boolean block, boolean cancelable, final IRunnableWithProgress runnable) {
    Job j = new Job("Processing") {

        @Override// w  w w.  j  ava 2 s .co  m
        protected IStatus run(IProgressMonitor monitor) {
            try {
                runnable.run(monitor);
            } catch (InvocationTargetException e) {
                throw new ErrorException(e);
            } catch (InterruptedException e) {
                throw new ErrorException(e);
            }
            return Status.OK_STATUS;
        }
    };
    j.schedule();
    if (block) {
        //
        IStatus status = null;
        final Display display = Display.getDefault();
        while (status == null) {
            while (!display.isDisposed() && display.readAndDispatch()) {
            }
            status = j.getResult();
        }
    }
}

From source file:com.nokia.sdt.editor.EditorServices.java

License:Open Source License

/**
 * Run a task, showing a progress dialog only when the workbench
 * is up and no editors are open, when we presume that load times 
 * will be much longer./* w  ww  .  ja v a2 s.c om*/
 * @param shell
 * @param runWithStatus
 * @return null for success, else IStatus for error
 */
public static IStatus runWithProgressAndStatus(Shell shell,
        final IRunnableWithProgressAndStatus runWithStatus) {
    final IStatus status[] = { null };
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            status[0] = runWithStatus.run(monitor);
        }
    };

    try {
        // the first load is likely to take long, so show a dialog in this case
        if (!stiflingProgress && !EditorServices.isAnyEditorOpen() && EditorServices.isEditorVisible(shell))
            new ProgressMonitorDialog(shell).run(false, false, runnable);
        else
            runnable.run(new NullProgressMonitor());

        if (status[0] == null || status[0] == Status.OK_STATUS)
            return null;
        else
            return status[0];
    } catch (Exception e) {
        return Logging.newStatus(UIModelPlugin.getDefault(), e);
    }

}

From source file:com.siteview.mde.internal.ui.correction.java.QuickFixProcessor.java

License:Open Source License

private void handleImportNotFound(IInvocationContext context, IProblemLocation problemLocation,
        final Collection result) {
    CompilationUnit cu = context.getASTRoot();
    ASTNode selectedNode = problemLocation.getCoveringNode(cu);
    if (selectedNode != null) {
        ASTNode node = getParent(selectedNode);
        String className = null;/*from  ww w .  ja v a  2 s.  c om*/
        String packageName = null;
        if (node == null) {
            if (selectedNode instanceof SimpleName) {
                ITypeBinding typeBinding = ((SimpleName) selectedNode).resolveTypeBinding();
                className = typeBinding.getBinaryName();
                packageName = typeBinding.getPackage().getName();
            }
        } else if (node instanceof ImportDeclaration) {
            // Find import declaration which is the problem
            className = ((ImportDeclaration) node).getName().getFullyQualifiedName();

            // always add the search repositories proposal
            int lastPeriod = className.lastIndexOf('.'); // if there is no period assume we are importing a single name package
            packageName = className.substring(0, lastPeriod >= 0 ? lastPeriod : className.length());
            result.add(JavaResolutionFactory.createSearchRepositoriesProposal(packageName));
        }

        if (className != null && packageName != null) {
            IProject project = cu.getJavaElement().getJavaProject().getProject();
            // only try to find proposals on Plug-in Projects
            if (!WorkspaceModelManager.isPluginProject(project))
                return;

            // create a collector that will create IJavaCompletionProposals and load them into 'result'
            AbstractClassResolutionCollector collector = createCollector(result);
            IRunnableWithProgress findOperation = new FindClassResolutionsOperation(project, className,
                    collector);
            try {
                findOperation.run(new NullProgressMonitor());
            } catch (InvocationTargetException e) {
            } catch (InterruptedException e) {
            }
        }
    }
}

From source file:com.siteview.mde.internal.ui.correction.java.UnresolvedImportFixProcessor.java

License:Open Source License

public ClasspathFixProposal[] getFixImportProposals(IJavaProject project, String name) throws CoreException {
    if (!WorkspaceModelManager.isPluginProject(project.getProject()))
        return new ClasspathFixProposal[0];
    ClasspathFixCollector collector = new ClasspathFixCollector();
    IRunnableWithProgress findOperation = new FindClassResolutionsOperation(project.getProject(), name,
            collector);//from   ww w  . ja  v a2 s  .  c om
    try {
        findOperation.run(new NullProgressMonitor());
    } catch (InvocationTargetException e) {
    } catch (InterruptedException e) {
    }
    return collector.getProposals();
}

From source file:com.vectrace.MercurialEclipse.MercurialEclipsePlugin.java

License:Open Source License

/**
 * Creates a busy cursor and runs the specified runnable. May be called from a non-UI thread.
 *
 * @param parent//from   w  ww.j a  va2  s .c  o m
 *            the parent Shell for the dialog
 * @param cancelable
 *            if true, the dialog will support cancelation
 * @param runnable
 *            the runnable
 *
 * @exception InvocationTargetException
 *                when an exception is thrown from the runnable
 * @exception InterruptedException
 *                when the progress monitor is cancelled
 */
public static void runWithProgress(Shell parent, boolean cancelable, final IRunnableWithProgress runnable)
        throws InvocationTargetException, InterruptedException {

    boolean createdShell = false;
    Shell myParent = parent;
    try {
        if (myParent == null || myParent.isDisposed()) {
            Display display = Display.getCurrent();
            if (display == null) {
                // cannot provide progress (not in UI thread)
                runnable.run(new NullProgressMonitor());
                return;
            }
            // get the active shell or a suitable top-level shell
            myParent = display.getActiveShell();
            if (myParent == null) {
                myParent = new Shell(display);
                createdShell = true;
            }
        }
        // pop up progress dialog after a short delay
        final Exception[] holder = new Exception[1];
        BusyIndicator.showWhile(myParent.getDisplay(), new Runnable() {
            public void run() {
                try {
                    runnable.run(new NullProgressMonitor());
                } catch (InvocationTargetException e) {
                    holder[0] = e;
                } catch (InterruptedException e) {
                    holder[0] = e;
                }
            }
        });
        if (holder[0] != null) {
            if (holder[0] instanceof InvocationTargetException) {
                throw (InvocationTargetException) holder[0];
            }
            throw (InterruptedException) holder[0];

        }
        // new TimeoutProgressMonitorDialog(parent, TIMEOUT).run(true
        // /*fork*/, cancelable, runnable);
    } finally {
        if (createdShell) {
            parent.dispose();
        }
    }
}