Search in sources :

Example 21 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project linuxtools by eclipse.

the class OpenInHierarchyViewCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // retrieve the selected image
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final IDockerConnection2 currentConnection = (IDockerConnection2) CommandUtils.getCurrentConnection(activePart);
    // run a job to retrieve the image hierarchy
    final RetrieveImageHierarchyJob retrieveImageHierarchyJob = new RetrieveImageHierarchyJob(currentConnection, CommandUtils.getSelectedElement(activePart));
    retrieveImageHierarchyJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            // input
            if (retrieveImageHierarchyJob.getImageHierarchy() == null) {
                Activator.logWarningMessage(CommandMessages.getString(// $NON-NLS-1$
                "command.showIn.imageHierarchyView.failure.missingHierarchy"));
            }
            Display.getDefault().asyncExec(() -> {
                try {
                    final DockerImageHierarchyView dockerImageHierarchyView = (DockerImageHierarchyView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(DockerImageHierarchyView.VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
                    dockerImageHierarchyView.setConnection((IDockerConnection) currentConnection);
                    dockerImageHierarchyView.show(retrieveImageHierarchyJob.getImageHierarchy());
                } catch (PartInitException e) {
                    Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
                    "command.showIn.imageHierarchyView.failure"), e);
                }
            });
        }
    });
    retrieveImageHierarchyJob.schedule();
    // 
    return null;
}
Also used : RetrieveImageHierarchyJob(org.eclipse.linuxtools.internal.docker.ui.jobs.RetrieveImageHierarchyJob) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) PartInitException(org.eclipse.ui.PartInitException) IDockerConnection2(org.eclipse.linuxtools.docker.core.IDockerConnection2) DockerImageHierarchyView(org.eclipse.linuxtools.internal.docker.ui.views.DockerImageHierarchyView)

Example 22 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project knime-core by knime.

the class InstallMissingNodesJob method startInstallJob.

private void startInstallJob(final Set<IInstallableUnit> featuresToInstall) {
    final ProvisioningUI provUI = ProvisioningUI.getDefaultUI();
    Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
    final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(provUI);
    loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
    loadJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(final IJobChangeEvent event) {
            if (PlatformUI.isWorkbenchRunning() && event.getResult().isOK()) {
                Display.getDefault().asyncExec(() -> {
                    if (Display.getDefault().isDisposed()) {
                        NodeLogger.getLogger("Display disposed, aborting install action");
                        // fixes AP-8376, AP-8380, AP-7184
                        return;
                    }
                    provUI.getPolicy().setRepositoriesVisible(false);
                    provUI.openInstallWizard(featuresToInstall, new InstallOperation(provUI.getSession(), featuresToInstall), loadJob);
                    provUI.getPolicy().setRepositoriesVisible(true);
                });
            }
        }
    });
    loadJob.setUser(true);
    loadJob.schedule();
}
Also used : ProvisioningUI(org.eclipse.equinox.p2.ui.ProvisioningUI) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) InstallOperation(org.eclipse.equinox.p2.operations.InstallOperation) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Example 23 with JobChangeAdapter

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

the class IndexerWizardPage method updateInputs.

private void updateInputs() {
    if (updateInputFilesJob != null) {
        updateInputFilesJob.cancel();
    }
    inputPaths = Collections.emptyList();
    setPageComplete(false);
    vwrInputs.setInput(inputPaths);
    lblInputCount.setText(String.format("%d resources found", inputPaths.size()));
    lblInputCount.getParent().layout(new Control[] { lblInputCount });
    final String resourcePattern = this.resourcePattern;
    final Display display = getShell().getDisplay();
    if (baseDir == null)
        return;
    updateInputFilesJob = new SearchFilesJob(baseDir, resourcePattern);
    updateInputFilesJob.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void done(IJobChangeEvent event) {
            final IStatus status = updateInputFilesJob.getSearchResult();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    inputPaths = updateInputFilesJob.getPaths();
                    if (inputPaths == null)
                        inputPaths = Collections.emptyList();
                    if (status.isOK())
                        vwrInputs.setInput(updateInputFilesJob.getPaths());
                    else
                        // The error/warning status is displayed in the table instead of the path list
                        vwrInputs.setInput(Collections.singleton(status));
                    lblInputCount.setText(String.format("%d resources found", inputPaths.size()));
                    lblInputCount.getParent().layout(new Control[] { lblInputCount });
                    validate();
                }
            });
        }
    });
    updateInputFilesJob.setSystem(true);
    updateInputFilesJob.schedule(500);
    vwrInputs.setInput(Collections.singleton(new Status(IStatus.INFO, Plugin.PLUGIN_ID, 0, Messages.IndexerWizardPage_checking, null)));
    lblInputCount.setText("...");
    lblInputCount.getParent().layout(new Control[] { lblInputCount });
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Display(org.eclipse.swt.widgets.Display)

Example 24 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project yamcs-studio by yamcs.

the class PreloadingRepositoryHandler method doExecuteAndLoad.

void doExecuteAndLoad() {
    if (preloadRepositories()) {
        // cancel any load that is already running
        Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
        final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
        setLoadJobProperties(loadJob);
        if (waitForPreload()) {
            loadJob.addJobChangeListener(new JobChangeAdapter() {

                public void done(IJobChangeEvent event) {
                    if (PlatformUI.isWorkbenchRunning())
                        if (event.getResult().isOK()) {
                            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    doExecute(loadJob);
                                }
                            });
                        }
                }
            });
            loadJob.setUser(true);
            loadJob.schedule();
        } else {
            loadJob.setSystem(true);
            loadJob.setUser(false);
            loadJob.schedule();
            doExecute(null);
        }
    } else {
        doExecute(null);
    }
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Example 25 with JobChangeAdapter

use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project translationstudio8 by heartsome.

the class PreloadingRepositoryHandler method doExecuteAndLoad.

void doExecuteAndLoad() {
    if (preloadRepositories()) {
        // cancel any load that is already running
        final IStatus[] checkStatus = new IStatus[1];
        Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
        final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI()) {

            public IStatus runModal(IProgressMonitor monitor) {
                SubMonitor sub = SubMonitor.convert(monitor, getProgressTaskName(), 1000);
                IStatus status = super.runModal(sub.newChild(500));
                if (status.getSeverity() == IStatus.CANCEL)
                    return status;
                if (status.getSeverity() != IStatus.OK) {
                    // 记录检查错误
                    checkStatus[0] = status;
                    return Status.OK_STATUS;
                }
                try {
                    doPostLoadBackgroundWork(sub.newChild(500));
                } catch (OperationCanceledException e) {
                    return Status.CANCEL_STATUS;
                }
                return status;
            }
        };
        setLoadJobProperties(loadJob);
        loadJob.setName(P2UpdateUtil.CHECK_UPDATE_JOB_NAME);
        if (waitForPreload()) {
            loadJob.addJobChangeListener(new JobChangeAdapter() {

                public void done(IJobChangeEvent event) {
                    if (PlatformUI.isWorkbenchRunning())
                        if (event.getResult().isOK()) {
                            PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {

                                public void run() {
                                    if (checkStatus[0] != null) {
                                        // 提示连接异常
                                        P2UpdateUtil.openConnectErrorInfoDialog(getShell(), P2UpdateUtil.INFO_TYPE_CHECK);
                                        return;
                                    }
                                    doExecute(loadJob);
                                }
                            });
                        }
                }
            });
            loadJob.setUser(true);
            loadJob.schedule();
        } else {
            loadJob.setSystem(true);
            loadJob.setUser(false);
            loadJob.schedule();
            doExecute(null);
        }
    } else {
        doExecute(null);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) SubMonitor(org.eclipse.core.runtime.SubMonitor) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) LoadMetadataRepositoryJob(org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)

Aggregations

IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)52 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)52 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)20 Job (org.eclipse.core.runtime.jobs.Job)20 IStatus (org.eclipse.core.runtime.IStatus)12 IFile (org.eclipse.core.resources.IFile)7 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)6 File (java.io.File)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 LoadMetadataRepositoryJob (org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)3 Status (org.eclipse.core.runtime.Status)3 DataSourceJob (org.jkiss.dbeaver.runtime.jobs.DataSourceJob)3 AnalyseBundleResolutionJob (bndtools.tasks.AnalyseBundleResolutionJob)2 FileOutputStream (java.io.FileOutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2