Search in sources :

Example 81 with Job

use of org.eclipse.core.runtime.jobs.Job in project tdi-studio-se by Talend.

the class ExportProjectsAsAction method run.

@Override
public void run() {
    // Refresh Navigator view before export operation, see bug 4595
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("ExportCommandAction.refreshWorkspace")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(ExportProjectsAsAction.this.getToolTipText(), IProgressMonitor.UNKNOWN);
            try {
                ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, null);
            } catch (CoreException e) {
                e.printStackTrace();
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.setPriority(Job.BUILD);
    job.schedule();
    initializeExternalLibraries();
    Shell activeShell = Display.getCurrent().getActiveShell();
    TalendZipFileExportWizard docWizard = new TalendZipFileExportWizard();
    WizardDialog dialog = new WizardDialog(activeShell, docWizard);
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    if (brandingService.isPoweredbyTalend()) {
        //$NON-NLS-1$
        docWizard.setWindowTitle(Messages.getString("ExportProjectsAsAction.actionTitle"));
    } else {
        docWizard.setWindowTitle(Messages.getString("ExportProjectsAsAction.actionTitleForOthers", //$NON-NLS-1$
        brandingService.getShortProductName()));
    }
    dialog.create();
    dialog.open();
    clearExternalLibraries();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Shell(org.eclipse.swt.widgets.Shell) CoreException(org.eclipse.core.runtime.CoreException) TalendZipFileExportWizard(org.talend.repository.ui.wizards.newproject.copyfromeclipse.TalendZipFileExportWizard) IBrandingService(org.talend.core.ui.branding.IBrandingService) Job(org.eclipse.core.runtime.jobs.Job) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 82 with Job

use of org.eclipse.core.runtime.jobs.Job in project bndtools by bndtools.

the class ImportBndWorkspaceWizard method performFinish.

@Override
public boolean performFinish() {
    final ImportSettings importSettings = new ImportSettings(mainPage.getSelectedFolder(), mainPage.isDeleteSettings(), mainPage.isInferExecutionEnvironment());
    // create the new project operation
    final WorkspaceModifyOperation op = new WorkspaceModifyOperation() {

        @Override
        protected void execute(IProgressMonitor monitor) throws CoreException {
            try {
                importProjects(importSettings, monitor);
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error during import of Bnd workspace!", e));
            }
        }
    };
    Job importJob = new Job("Import Bnd Workspace") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                op.run(monitor);
            } catch (InvocationTargetException e) {
                Throwable t = e.getCause();
                if (t instanceof CoreException && ((CoreException) t).getStatus().getException() != null) {
                    // unwrap the cause of the CoreException
                    t = ((CoreException) t).getStatus().getException();
                }
                return new Status(Status.ERROR, Plugin.PLUGIN_ID, "Could not finish import job for Bnd Workspace!", t);
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    importJob.schedule();
    try {
        // Prompt to switch to the BndTools perspective
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        IPerspectiveDescriptor currentPerspective = window.getActivePage().getPerspective();
        if (!"bndtools.perspective".equals(currentPerspective.getId())) {
            if (MessageDialog.openQuestion(getShell(), "Bndtools Perspective", "Switch to the Bndtools perspective?")) {
                this.workbench.showPerspective("bndtools.perspective", window);
            }
        }
    } catch (WorkbenchException e) {
        error("Unable to switch to BndTools perspective", e);
    }
    return true;
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) WorkbenchException(org.eclipse.ui.WorkbenchException) WorkbenchException(org.eclipse.ui.WorkbenchException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IPerspectiveDescriptor(org.eclipse.ui.IPerspectiveDescriptor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

Job (org.eclipse.core.runtime.jobs.Job)82 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)57 IStatus (org.eclipse.core.runtime.IStatus)20 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)17 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)17 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 IOException (java.io.IOException)14 Status (org.eclipse.core.runtime.Status)12 File (java.io.File)11 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 Shell (org.eclipse.swt.widgets.Shell)4