Search in sources :

Example 71 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class DockerConnectionWatcher method selectionChanged.

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    final ITreeSelection treeSelection = (ITreeSelection) selection;
    if (treeSelection.isEmpty()) {
        setConnection(null);
        return;
    }
    final Object firstSegment = treeSelection.getPaths()[0].getFirstSegment();
    if (firstSegment instanceof IDockerConnection) {
        setConnection((IDockerConnection) firstSegment);
    }
}
Also used : ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Example 72 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class DockerConnectionWatcher method loadConnection.

// Load the previously selected connection at start-up
private IDockerConnection loadConnection() {
    IDockerConnection connection = null;
    final IPath stateLocation = Activator.getDefault().getStateLocation();
    final File connectionFile = stateLocation.append(CONNECTION_FILE_NAME).toFile();
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        if (connectionFile.exists()) {
            Document d = db.parse(connectionFile);
            Element e = d.getDocumentElement();
            // Get the stored configuration data
            // $NON-NLS-1$
            NodeList connectionNodes = e.getElementsByTagName("connection");
            if (connectionNodes == null || connectionNodes.getLength() == 0) {
                return null;
            }
            Node n = connectionNodes.item(0);
            NamedNodeMap attrs = n.getAttributes();
            // $NON-NLS-1$
            Node nameNode = attrs.getNamedItem("name");
            // $NON-NLS-1$
            Node uriNode = attrs.getNamedItem("uri");
            // $NON-NLS-1$
            Node usernameNode = attrs.getNamedItem("username");
            if (uriNode != null) {
                String uri = uriNode.getNodeValue();
                String name = nameNode.getNodeValue();
                String username = null;
                if (usernameNode != null) {
                    username = usernameNode.getNodeValue();
                }
                IDockerConnection[] connections = DockerConnectionManager.getInstance().getConnections();
                for (IDockerConnection c : connections) {
                    if (c.getUri().equals(uri)) {
                        if (c.getName().equals(name)) {
                            if (c.getUsername() == null || c.getUsername().equals(username)) {
                                connection = c;
                                break;
                            }
                        }
                    }
                }
            }
        }
    } catch (ParserConfigurationException | SAXException | IOException e) {
        Activator.log(e);
    }
    return connection;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) IPath(org.eclipse.core.runtime.IPath) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) File(java.io.File)

Example 73 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class BaseImagesCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerImage> selectedImages = getSelectedImages(activePart);
    final IDockerConnection connection = getCurrentConnection(activePart);
    if (connection == null || selectedImages.isEmpty()) {
        Activator.log(new DockerException(CommandMessages.getString(// $NON-NLS-1$
        "Command.missing.selection.failure")));
        return null;
    }
    final Job job = new Job(getJobName(selectedImages)) {

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

Example 74 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class CommitContainerCommandHandler method performCommitContainer.

private void performCommitContainer(final ContainerCommit wizard, final IDockerConnection connection, final IDockerContainer container) {
    final Job commitContainerJob = new Job(DVMessages.getString(COMMIT_CONTAINER_JOB_TITLE)) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            final String tag = wizard.getTag();
            final String repo = wizard.getRepo();
            final String author = wizard.getAuthor();
            final String comment = wizard.getComment();
            monitor.beginTask(DVMessages.getString(COMMIT_CONTAINER_MSG), 1);
            // commit the Container and then update the list of Images
            try {
                ((DockerConnection) connection).commitContainer(container.id(), repo, tag, comment, author);
                monitor.worked(1);
            } catch (DockerException e) {
                Display.getDefault().syncExec(() -> MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), DVMessages.getFormattedString(ERROR_COMMITTING_CONTAINER, tag), e.getMessage()));
            } finally {
                monitor.done();
            }
            return Status.OK_STATUS;
        }
    };
    commitContainerJob.schedule();
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerException(org.eclipse.linuxtools.docker.core.DockerException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 75 with IDockerConnection

use of org.eclipse.linuxtools.docker.core.IDockerConnection in project linuxtools by eclipse.

the class ConfigureLabelsCommandHandler method execute.

@SuppressWarnings("unused")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final ConfigureLabels wizard = new ConfigureLabels();
    final boolean configureLabels = CommandUtils.openWizard(wizard, HandlerUtil.getActiveShell(event));
    if (configureLabels) {
        Map<String, String> labels = wizard.getConfigureLabels();
        StringBuffer buffer = new StringBuffer();
        for (Entry<String, String> entry : labels.entrySet()) {
            buffer.append(entry.getKey());
            // $NON-NLS-1$
            buffer.append('=');
            buffer.append(entry.getValue());
            buffer.append('\u00a0');
        }
        IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
        preferences.put(CONTAINER_FILTER_LABELS, buffer.toString());
        IDockerConnection connection = CommandUtils.getCurrentConnection(null);
        // force refresh
        connection.getContainers(true);
    }
    return null;
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ConfigureLabels(org.eclipse.linuxtools.internal.docker.ui.wizards.ConfigureLabels) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection)

Aggregations

IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)90 DockerException (org.eclipse.linuxtools.docker.core.DockerException)24 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)20 Job (org.eclipse.core.runtime.jobs.Job)17 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)16 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)15 Test (org.junit.Test)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)9 File (java.io.File)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)8 IPath (org.eclipse.core.runtime.IPath)7 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 List (java.util.List)5 IDockerConnectionStorageManager (org.eclipse.linuxtools.docker.core.IDockerConnectionStorageManager)5 RunConsole (org.eclipse.linuxtools.internal.docker.ui.consoles.RunConsole)5 DockerClient (com.spotify.docker.client.DockerClient)4 HashMap (java.util.HashMap)4