Search in sources :

Example 66 with Job

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

the class ConnectionInfoPropertySection method updateConnectionInfo.

private void updateConnectionInfo(final IDockerConnection connection) {
    // Set the tree empty while we wait for the real data
    if (getTreeViewer() != null) {
        getTreeViewer().setInput(null);
        getTreeViewer().expandAll();
    }
    final Job loadConnectionInfoJob = new Job(DVMessages.getString(LoadingConnectionInfo)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            monitor.beginTask(DVMessages.getString(LoadingConnectionInfo), 1);
            if (connection.getState() != EnumDockerConnectionState.ESTABLISHED) {
                return Status.OK_STATUS;
            }
            try {
                final IDockerConnectionInfo info = connection.getInfo();
                Display.getDefault().asyncExec(() -> {
                    if (info != null && getTreeViewer() != null) {
                        getTreeViewer().setInput(info);
                        getTreeViewer().expandAll();
                    }
                });
            } catch (DockerException e) {
                Activator.log(e);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    loadConnectionInfoJob.schedule();
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDockerConnectionInfo(org.eclipse.linuxtools.docker.core.IDockerConnectionInfo) Job(org.eclipse.core.runtime.jobs.Job)

Example 67 with Job

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

the class DockerExplorerContentProvider method loadContainers.

/**
 * Call the {@link IDockerConnection#getContainers(boolean)} in a background
 * job to avoid blocking the UI.
 *
 * @param containersCategory
 *            the selected {@link DockerContainersCategory}
 */
private void loadContainers(final DockerContainersCategory containersCategory) {
    final Job loadContainersJob = new LoadingJob(// $NON-NLS-1$
    DVMessages.getString("ContainersLoadJob.msg"), containersCategory) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            containersCategory.getConnection().getContainers(true);
            return Status.OK_STATUS;
        }
    };
    loadContainersJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 68 with Job

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

the class DockerImagesContentProvider method loadImages.

/**
 * Call the {@link IDockerConnection#getImages(boolean)} in a background job
 * to avoid blocking the UI.
 *
 * @param connection
 *            the selected {@link DockerConnection}
 */
private void loadImages(final IDockerConnection connection) {
    final Job loadImagesJob = new Job(DVMessages.getFormattedString("ImagesLoadJob.msg", connection.getUri())) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            connection.getImages(true);
            Display.getDefault().asyncExec(() -> {
                viewer.refresh();
            });
            return Status.OK_STATUS;
        }
    };
    loadImagesJob.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 69 with Job

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

the class DockerImagesView method changeEvent.

@Override
public void changeEvent(final IDockerConnection connection, final int type) {
    if (type == IDockerConnectionManagerListener.UPDATE_SETTINGS_EVENT) {
        final Job refreshJob = new Job(DVMessages.getString("ImagesRefresh.msg")) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                connection.getImages(true);
                return Status.OK_STATUS;
            }
        };
        refreshJob.addJobChangeListener(new JobChangeAdapter() {

            @Override
            public void done(IJobChangeEvent event) {
                Display.getDefault().asyncExec(() -> refreshViewTitle());
            }
        });
        refreshJob.schedule();
    } else if (type == IDockerConnectionManagerListener.RENAME_EVENT) {
        Display.getDefault().asyncExec(() -> refreshViewTitle());
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job)

Example 70 with Job

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

the class DockerImagesView method setConnection.

private void setConnection(final IDockerConnection connection) {
    if (connection != null && connection.equals(this.connection)) {
        return;
    }
    if (this.connection != null) {
        this.connection.removeImageListener(this);
    }
    this.connection = connection;
    if (this.viewer != null && this.connection != null) {
        final Job refreshJob = new Job(DVMessages.getString("ImagesRefresh.msg")) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                connection.getImages(true);
                connection.addImageListener(DockerImagesView.this);
                Display.getDefault().asyncExec(() -> {
                    if (!viewer.getControl().isDisposed()) {
                        viewer.setInput(connection);
                        refreshViewTitle();
                    }
                });
                return Status.OK_STATUS;
            }
        };
        refreshJob.schedule();
    } else if (this.viewer != null) {
        viewer.setInput(new IDockerContainer[0]);
        form.setText(DVMessages.getString(NoConnectionSelected));
    }
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

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