Search in sources :

Example 71 with Job

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

the class BaseContainersCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerContainer> selectedContainers = getSelectedContainers(activePart);
    final IDockerConnection connection = getCurrentConnection(activePart);
    if (connection == null || selectedContainers.isEmpty()) {
        return null;
    }
    final Job job = new Job(getJobName(selectedContainers)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            if (confirmed(selectedContainers)) {
                monitor.beginTask(getJobName(selectedContainers), selectedContainers.size());
                for (final IDockerContainer container : selectedContainers) {
                    monitor.setTaskName(getTaskName(container));
                    executeInJob(container, connection);
                    monitor.worked(1);
                }
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    // job.setPriority(Job.LONG);
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 72 with Job

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

the class RefreshCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<Job> jobs = getRefreshJobs(activePart);
    for (Job job : jobs) {
        job.setPriority(Job.LONG);
        job.setUser(true);
        job.schedule();
    }
    return null;
}
Also used : IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) Job(org.eclipse.core.runtime.jobs.Job)

Example 73 with Job

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

the class RefreshCommandHandler method getRefreshContainersJob.

private Job getRefreshContainersJob(final IDockerConnection connection) {
    if (connection == null) {
        return null;
    }
    final Job job = new Job(DVMessages.getString(CONTAINERS_REFRESH_MSG)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(CONTAINERS_REFRESH_MSG), 1);
            connection.getContainers(true);
            monitor.worked(1);
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    return job;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 74 with Job

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

the class RefreshConnectionHandler method getRefreshContainersJob.

private Job getRefreshContainersJob(final IDockerConnection connection) {
    if (connection == null) {
        return null;
    }
    final Job job = new Job(DVMessages.getString(CONTAINERS_REFRESH_MSG)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(CONTAINERS_REFRESH_MSG), 1);
            connection.getContainers(true);
            monitor.worked(1);
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    return job;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 75 with Job

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

the class ShowInSystemExplorerCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<DockerContainerVolume> volumes = CommandUtils.getSelectedVolumes(activePart);
    if (volumes == null || volumes.isEmpty()) {
        return null;
    }
    final DockerContainerVolume selectedVolume = volumes.get(0);
    final File hostFile = new File(selectedVolume.getHostPath());
    final String launchCmd = getShowInSystemExplorerCommand(hostFile);
    if (launchCmd == null) {
        return null;
    }
    final Job job = new Job(CommandMessages.getString("command.showIn.systemExplorer")) {

        // $NON-NLS-1$
        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final Process p = getLaunchProcess(launchCmd, hostFile);
                final int retCode = p.waitFor();
                if (retCode != 0 && !Util.isWindows()) {
                    Activator.log(new DockerException(CommandMessages.getFormattedString(// $NON-NLS-1$
                    "command.showIn.systemExplorer.failure.command.execute", launchCmd, Integer.toString(retCode))));
                }
            } catch (IOException | InterruptedException e) {
                Activator.logErrorMessage(CommandMessages.getFormattedString(// $NON-NLS-1$
                "command.showIn.systemExplorer.failure", launchCmd), e);
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) DockerContainerVolume(org.eclipse.linuxtools.internal.docker.ui.views.DockerExplorerContentProvider.DockerContainerVolume) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Aggregations

Job (org.eclipse.core.runtime.jobs.Job)177 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)134 IStatus (org.eclipse.core.runtime.IStatus)33 IOException (java.io.IOException)27 File (java.io.File)20 Status (org.eclipse.core.runtime.Status)20 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)20 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)20 CoreException (org.eclipse.core.runtime.CoreException)17 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)17 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 DockerException (org.eclipse.linuxtools.docker.core.DockerException)14 IFile (org.eclipse.core.resources.IFile)13 URL (java.net.URL)11 ArrayList (java.util.ArrayList)11 IPath (org.eclipse.core.runtime.IPath)10 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)9 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)9 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)8 Display (org.eclipse.swt.widgets.Display)8