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:org.xtuml.bp.model.compare.contentmergeviewer.ModelContentMergeViewer.java

License:Open Source License

protected void writeData(ICompareInput input, boolean toLeft) {
    try {/*from  w ww.j  a v a  2s.  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);
            runnable.run(new NullProgressMonitor());
            ((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:org.xtuml.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  www. j a  va2  s . 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.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.ignoreAlternateChildren = false;
            CoreExport.exportSupertypes = true;
            CoreExport.ignoreMissingPMCErrors = false;
            if (writeAsProxy) {
                CoreExport.forceWriteAsProxy = false;
            }
        }
    }
    return "";
}

From source file:org.xwiki.plugins.eclipse.util.GuiUtils.java

License:Open Source License

/**
 * Runs a time consuming operation with a progress indicator.
 * // w  w  w. j  a v  a2  s . com
 * @param operation Operation which consumes time
 * @param shell Shell associated with
 */
public static void runOperationWithProgress(IRunnableWithProgress operation, Shell shell) {
    if (XWikiConstants.PROGRESS_ON) {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        try {
            dialog.run(true, false, operation);
        } catch (InvocationTargetException e) {
            reportError(false, "Error", e.getTargetException().getMessage());
            e.printStackTrace();
        } catch (InterruptedException e) {
            reportError(false, "Internel Error", "An error occured while servicing your request.");
        } catch (Exception e) {
            reportError(false, "Internel Error", "An error occured while servicing your request.");
        }
    } else {
        try {
            operation.run(new DummyProgressMonitor());
        } catch (InvocationTargetException e) {
            reportError(false, "Error", e.getTargetException().getMessage());
            e.printStackTrace();
        } catch (InterruptedException e) {
            reportError(false, "Internel Error", "An error occured while servicing your request.");
        } catch (Exception e) {
            reportError(false, "Internel Error", "An error occured while servicing your request.");
        }
    }
}

From source file:org.yafra.rcp.commands.ConnectHandler.java

License:Apache License

@SuppressWarnings("static-access")
@Override/*w  w w.jav a  2s.co m*/
public Object execute(ExecutionEvent event) throws ExecutionException {
    glob = GlobalSettings.getSingletonObject();
    glob.setDebugmessage(" - start command connect and login");
    preferredWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    if (glob.isYafraSessionConnected()) {
        MessageDialog.openInformation(preferredWindow.getShell(), "Info",
                "You are already logged in - logoff first");
        return null;
    }
    login = new LoginDialog(preferredWindow.getShell());
    login.open();
    if (login.getReturnCode() == (int) login.OK) {
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(preferredWindow.getShell());
        IRunnableWithProgress runnable = new IRunnableWithProgress() {
            public void run(IProgressMonitor progressMonitor) throws InterruptedException {
                progressMonitor.beginTask(Lloginstartmon, IProgressMonitor.UNKNOWN);
                try {
                    // for the provider URL see as examples http://openejb.apache.org/clients.html
                    // openejb in tomee http://127.0.0.1:8080/tomee/ejb
                    // openejb standalone ejbd ejbd://localhost:4201
                    String ServerURL = new String(String.format("http://%s:8080/tomee/ejb", login.getServer()));
                    Properties prop = new Properties();
                    prop.put(glob.getEjbcontext().INITIAL_CONTEXT_FACTORY,
                            "org.apache.openejb.client.RemoteInitialContextFactory");
                    prop.put("java.naming.provider.url", ServerURL);
                    glob.setEjbcontext(new InitialContext(prop));
                    progressMonitor.worked(1);
                    glob.setDebugmessage(" - got context");
                    glob.setYafrases((YafraSessionRemote) glob.getEjbcontext().lookup("YafraSessionRemote"));
                    glob.setDebugmessage(" - got remote session class");
                    glob.getYafrases().init();
                    progressMonitor.worked(2);
                    glob.setDebugmessage(" - got remote init");
                    if (glob.getYafrases().Login(login.getUserid(), login.getPwd())) {
                        glob.setYafraSessionConnected(true);
                        glob.getStatusline().setMessage(null, "Ready - logged in");
                        glob.setDebugmessage(" - login OK");
                        GlobalSettings glob = GlobalSettings.getSingletonObject();
                        glob.setServer(login.getServer());
                        glob.setUser(login.getUserid());
                        MHIYafraUserRemote mhiuser = (MHIYafraUserRemote) glob.getEjbcontext()
                                .lookup("MHIYafraUserRemote");
                        glob.setUserModel(mhiuser.selectUser(login.getUserid()));
                        glob.setUserRoles(mhiuser.getRoles(login.getUserid()));
                    } else {
                        glob.setDebugmessage(" - login NOT OK - EXIT NOW");
                        glob.getStatusline().setMessage(null,
                                "Ready - not logged in - ERROR with login - try again");
                        glob.setYafraSessionConnected(false);
                        return;
                    }
                    glob.setDebugmessage(" - version got from server: " + glob.getYafrases().getVersion());

                    // TODO check why not returning
                    progressMonitor.done();
                } catch (Exception e) {
                    glob.setYafraSessionConnected(false);
                    progressMonitor.done();
                    Status status = new Status(IStatus.ERROR, "My Plug-in ID", 0, "EJB3 connection error", e);
                    ErrorDialog.openError(Display.getCurrent().getActiveShell(), "EJB3 connection error",
                            e.toString(), status);
                    e.printStackTrace();
                }
            };
        };
        try {
            progressDialog.open();
            runnable.run(progressDialog.getProgressMonitor());
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        progressDialog.close();
        try {
            IViewReference ref = preferredWindow.getActivePage().findViewReference("org.yafra.rcp.LoginView");
            preferredWindow.getActivePage().hideView(ref);
            preferredWindow.getActivePage().showView("org.yafra.rcp.LoginView");
        } catch (PartInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    return null;
}

From source file:org2.eclipse.php.internal.debug.ui.wizard.FragmentedWizard.java

License:Open Source License

/**
 * Cancel the client selection.//from  www.j  a  v a  2  s. co  m
 *
 * @return boolean
 */
public boolean performCancel() {
    final List list = getAllWizardFragments();
    IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                Iterator iterator = list.iterator();
                while (iterator.hasNext())
                    executeTask((WizardFragment) iterator.next(), CANCEL, monitor);
            } catch (CoreException ce) {
                throw new InvocationTargetException(ce);
            }
        }
    };

    Throwable t = null;
    try {
        if (getContainer() != null)
            getContainer().run(true, true, runnable);
        else
            runnable.run(new NullProgressMonitor());
        return true;
    } catch (InvocationTargetException te) {
        t = te.getCause();
    } catch (Exception e) {
        t = e;
    }
    //PHPUiPlugin.log(new Status(IStatus.ERROR, PHPUiPlugin.ID, 0, "Error cancelling task wizard", t)); //$NON-NLS-1$

    if (t instanceof CoreException) {
        openError(t.getLocalizedMessage(), ((CoreException) t).getStatus());
    } else
        openError(t.getLocalizedMessage());

    return false;

}

From source file:x10dt.ui.utils.LaunchUtils.java

License:Open Source License

/**
 * Finds all the the X10 main types present under the list of resources transmitted. If no resources are given, the search
 * will occur at the workspace level for all the projects that have the project nature id equals to the one given.
 * // w ww . j a va 2s . com
 * @param resources The resources representing the searching scope. Can be <b>null</b> or empty. In such case,
 * it will automatically search within the all workspace.
 * @param projectNatureId The nature id for the projects of interest in case we receive no resources.
 * @param progressService The progress service to use for running the search operation. Can be null,
 * in which case the search is executed synchronously without progress.
 * @return A non-null but possibly empty array.
 * @throws InterruptedException Occurs if the operation got canceled by end-user.
 * @throws InvocationTargetException Occurs if something wrong happened during the search. Such wrapper will contain a 
 * {@link CoreException} as its target in this case.
 */
public static ITypeInfo[] findMainTypes(final IResource[] resources, final String projectNatureId,
        final IProgressService progressService) throws InterruptedException, InvocationTargetException {
    final ITypeInfo[][] mainTypes = new ITypeInfo[1][];
    final IRunnableWithProgress runnable = new IRunnableWithProgress() {
        public void run(final IProgressMonitor monitor) throws InterruptedException {
            final IX10SearchScope searchScope;
            if (resources == null) {
                searchScope = SearchScopeFactory.createWorkspaceScope(X10SearchScope.ALL, projectNatureId);
            } else {
                searchScope = SearchScopeFactory.createSelectiveScope(X10SearchScope.ALL, resources);
            }
            mainTypes[0] = X10SearchEngine.getAllTypesWithMainMethod(searchScope, monitor);
        }
    };
    if (progressService != null) {
        progressService.busyCursorWhile(runnable);
    } else {
        runnable.run(null);
    }
    return mainTypes[0];
}