Search in sources :

Example 81 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project sling by apache.

the class ExportWizard method performFinish.

@Override
public boolean performFinish() {
    try {
        getContainer().run(true, false, new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                final ResourceChangeCommandFactory factory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
                final Repository[] selectedServer = new Repository[1];
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            selectedServer[0] = ServerUtil.getConnectedRepository(exportPage.getServer(), monitor);
                        } catch (CoreException e) {
                            throw new RuntimeException(e);
                        }
                    }
                });
                try {
                    syncStartPoint.accept(new IResourceVisitor() {

                        @Override
                        public boolean visit(IResource resource) throws CoreException {
                            Command<?> command = factory.newCommandForAddedOrUpdated(selectedServer[0], resource);
                            if (command == null) {
                                return true;
                            }
                            Result<?> result = command.execute();
                            if (!result.isSuccess()) {
                                throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "Failed exporting: " + result.toString()));
                            }
                            return true;
                        }
                    });
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                } catch (Throwable t) {
                    t.printStackTrace();
                    throw new InvocationTargetException(t);
                }
            }
        });
        return true;
    } catch (RuntimeException | InterruptedException e) {
        exportPage.setErrorMessage(e.getMessage());
        return false;
    } catch (InvocationTargetException e) {
        exportPage.setErrorMessage(e.getCause().getMessage());
        return false;
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ResourceChangeCommandFactory(org.apache.sling.ide.eclipse.core.internal.ResourceChangeCommandFactory) IResource(org.eclipse.core.resources.IResource)

Example 82 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project sling by apache.

the class AbstractNewSlingApplicationWizard method performFinish.

/**
     * This method is called when 'Finish' button is pressed in the wizard. We will create an operation and run it using
     * wizard as execution context.
     */
public boolean performFinish() {
    try {
        // create projects
        final List<IProject> createdProjects = new ArrayList<>();
        getContainer().run(false, true, new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                createdProjects.addAll(createProjects(monitor));
            }
        });
        // configure projects
        final Projects[] projects = new Projects[1];
        getContainer().run(false, true, new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                projects[0] = configureCreatedProjects(createdProjects, monitor);
            }
        });
        // deploy the projects on server
        getContainer().run(false, true, new WorkspaceModifyOperation() {

            @Override
            protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                deployProjectsOnServer(projects[0], monitor);
            }
        });
        // ensure server is started and all modules are published
        getContainer().run(false, false, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    publishModules(createdProjects, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return false;
    } catch (InvocationTargetException e) {
        reportError(e.getTargetException());
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 83 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project azure-tools-for-java by Microsoft.

the class SrvPriCreationStatusDialog method createServicePrincipalAsync.

private void createServicePrincipalAsync() {
    try {
        class StatusTask implements IRunnableWithProgress, IListener<Status> {

            IProgressMonitor progressIndicator = null;

            @Override
            public void listen(Status status) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (progressIndicator != null) {
                            progressIndicator.setTaskName(status.getAction());
                        }
                        // if only action was set in the status - the info for progress indicator only - igonre for table
                        if (status.getResult() != null) {
                            TableItem item = new TableItem(table, SWT.NULL);
                            item.setText(new String[] { status.getAction(), status.getResult().toString(), status.getDetails() });
                        }
                    }
                });
            }

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                progressIndicator = monitor;
                monitor.beginTask("Creating Service Principal...", IProgressMonitor.UNKNOWN);
                for (String tid : tidSidsMap.keySet()) {
                    if (monitor.isCanceled()) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                TableItem item = new TableItem(table, SWT.NULL);
                                item.setText(new String[] { "!!! Canceled by user" });
                            }
                        });
                        return;
                    }
                    List<String> sidList = tidSidsMap.get(tid);
                    if (!sidList.isEmpty()) {
                        try {
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    TableItem item = new TableItem(table, SWT.NULL);
                                    item.setText(new String[] { "tenant ID: " + tid + " ===" });
                                }
                            });
                            Date now = new Date();
                            String suffix = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
                            ;
                            String authFilepath = SrvPriManager.createSp(tid, sidList, suffix, this, destinationFolder);
                            if (authFilepath != null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        listCreatedFiles.add(authFilepath);
                                        listCreatedFiles.setSelection(0);
                                    }
                                });
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            LOG.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@createServicePrincipalAsync@SrvPriCreationStatusDialog", ex));
                        }
                    }
                }
            }
        }
        new ProgressMonitorDialog(this.getShell()).run(true, true, new StatusTask());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(com.microsoft.azuretools.authmanage.srvpri.step.Status) TableItem(org.eclipse.swt.widgets.TableItem) IListener(com.microsoft.azuretools.authmanage.srvpri.report.IListener) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SimpleDateFormat(java.text.SimpleDateFormat)

Example 84 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method internalInit.

/**
 * Implements the <code>init</code> method of <code>IEditorPart</code>.
 * Subclasses replacing <code>init</code> may choose to call this method in
 * their implementation.
 *
 * @param window the workbench window
 * @param site the editor's site
 * @param input the editor input for the editor being created
 * @throws PartInitException if {@link #doSetInput(IEditorInput)} fails or gets canceled
 *
 * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
 * @since 2.1
 */
protected final void internalInit(IWorkbenchWindow window, final IEditorSite site, final IEditorInput input) throws PartInitException {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            try {
                if (getDocumentProvider() instanceof IDocumentProviderExtension2) {
                    IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) getDocumentProvider();
                    extension.setProgressMonitor(monitor);
                }
                doSetInput(input);
            } catch (CoreException x) {
                throw new InvocationTargetException(x);
            } finally {
                if (getDocumentProvider() instanceof IDocumentProviderExtension2) {
                    IDocumentProviderExtension2 extension = (IDocumentProviderExtension2) getDocumentProvider();
                    extension.setProgressMonitor(null);
                }
            }
        }
    };
    try {
        // When using the progress service always a modal dialog pops up. The site should be asked for a runnable context
        // which could be the workbench window or the progress service, depending on what the site represents.
        // getSite().getWorkbenchWindow().getWorkbench().getProgressService().run(false, true, runnable);
        getSite().getWorkbenchWindow().run(false, true, runnable);
    } catch (InterruptedException x) {
    } catch (InvocationTargetException x) {
        Throwable t = x.getTargetException();
        if (t instanceof CoreException) {
            /*
                /* XXX: Remove unpacking of CoreException once the following bug is
                 *		fixed: https://bugs.eclipse.org/bugs/show_bug.cgi?id=81640
                 */
            CoreException e = (CoreException) t;
            IStatus status = e.getStatus();
            if (status.getException() != null)
                throw new PartInitException(status);
            throw new PartInitException(new Status(status.getSeverity(), status.getPlugin(), status.getCode(), status.getMessage(), t));
        }
        throw new PartInitException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_init, t));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 85 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project linuxtools by eclipse.

the class Oprofile method getModelData.

/**
 * Return a list of all the Samples in the given session.
 *
 * @param session
 *            the session for which to get samples
 * @param shell
 *            the composite shell to use for the progress dialog
 */
public static OpModelImage getModelData(String eventName, String sessionName) {
    OpModelImage image = new OpModelImage();
    final IRunnableWithProgress opxml;
    try {
        opxml = OprofileCorePlugin.getDefault().getOpxmlProvider().modelData(eventName, sessionName, image);
        opxml.run(null);
    } catch (InvocationTargetException | InterruptedException e) {
    }
    return image;
}
Also used : OpModelImage(org.eclipse.linuxtools.internal.oprofile.core.model.OpModelImage) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)417 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)397 InvocationTargetException (java.lang.reflect.InvocationTargetException)386 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)194 CoreException (org.eclipse.core.runtime.CoreException)123 ArrayList (java.util.ArrayList)86 IStatus (org.eclipse.core.runtime.IStatus)67 IOException (java.io.IOException)65 List (java.util.List)54 Status (org.eclipse.core.runtime.Status)53 IFile (org.eclipse.core.resources.IFile)51 File (java.io.File)47 Shell (org.eclipse.swt.widgets.Shell)44 IProject (org.eclipse.core.resources.IProject)40 PartInitException (org.eclipse.ui.PartInitException)32 IPath (org.eclipse.core.runtime.IPath)26 Display (org.eclipse.swt.widgets.Display)26 IResource (org.eclipse.core.resources.IResource)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 Path (org.eclipse.core.runtime.Path)23