Search in sources :

Example 26 with IDockerImage

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

the class DockerExplorerContentProvider method getChildren.

@Override
public Object[] getChildren(final Object parentElement) {
    if (parentElement instanceof IDockerConnection) {
        // check the connection availability before returning the
        // 'containers' and 'images' child nodes.
        final IDockerConnection connection = (IDockerConnection) parentElement;
        if (connection.isOpen()) {
            return new Object[] { new DockerImagesCategory(connection), new DockerContainersCategory(connection) };
        } else if (connection.getState() == EnumDockerConnectionState.UNKNOWN) {
            open(connection);
            return new Object[] { new LoadingStub(connection) };
        } else if (connection.getState() == EnumDockerConnectionState.CLOSED) {
            synchronized (openRetryJobs) {
                Job job = openRetryJobs.get(connection);
                if (job == null) {
                    openRetry(connection);
                }
            }
            return new Object[] { new LoadingStub(connection) };
        }
        return new Object[0];
    } else if (parentElement instanceof DockerContainersCategory) {
        final DockerContainersCategory containersCategory = (DockerContainersCategory) parentElement;
        final IDockerConnection connection = containersCategory.getConnection();
        if (connection.isContainersLoaded()) {
            return connection.getContainers().toArray();
        }
        loadContainers(containersCategory);
        return new Object[] { new LoadingStub(containersCategory) };
    } else if (parentElement instanceof DockerImagesCategory) {
        final DockerImagesCategory imagesCategory = (DockerImagesCategory) parentElement;
        final IDockerConnection connection = imagesCategory.getConnection();
        if (connection.isImagesLoaded()) {
            // here we duplicate the images to show one org/repo with all
            // its tags per node in the tree
            final List<IDockerImage> allImages = connection.getImages();
            final List<IDockerImage> explorerImages = splitImageTagsByRepo(allImages);
            return explorerImages.toArray();
        }
        loadImages(imagesCategory);
        return new Object[] { new LoadingStub(imagesCategory) };
    } else if (parentElement instanceof IDockerContainer) {
        final DockerContainer container = (DockerContainer) parentElement;
        if (container.isInfoLoaded()) {
            final IDockerContainerInfo info = container.info();
            final IDockerNetworkSettings networkSettings = (info != null) ? info.networkSettings() : null;
            final IDockerHostConfig hostConfig = (info != null) ? info.hostConfig() : null;
            return new Object[] { new DockerContainerPortMappingsCategory(container, (networkSettings != null) ? networkSettings.ports() : Collections.<String, List<IDockerPortBinding>>emptyMap()), new DockerContainerVolumesCategory(container, (hostConfig != null) ? hostConfig.binds() : Collections.<String>emptyList()), new DockerContainerLinksCategory(container, (hostConfig != null) ? hostConfig.links() : Collections.<String>emptyList()) };
        }
        loadContainerInfo(container);
        return new Object[] { new LoadingStub(container) };
    } else if (parentElement instanceof DockerContainerLinksCategory) {
        final DockerContainerLinksCategory linksCategory = (DockerContainerLinksCategory) parentElement;
        return linksCategory.getLinks().toArray();
    } else if (parentElement instanceof DockerContainerPortMappingsCategory) {
        final DockerContainerPortMappingsCategory portMappingsCategory = (DockerContainerPortMappingsCategory) parentElement;
        return portMappingsCategory.getPortMappings().toArray();
    } else if (parentElement instanceof DockerContainerVolumesCategory) {
        final DockerContainerVolumesCategory volumesCategory = (DockerContainerVolumesCategory) parentElement;
        return volumesCategory.getVolumes().toArray();
    }
    return EMPTY;
}
Also used : IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) IDockerContainer(org.eclipse.linuxtools.docker.core.IDockerContainer) DockerContainer(org.eclipse.linuxtools.internal.docker.core.DockerContainer) IDockerNetworkSettings(org.eclipse.linuxtools.docker.core.IDockerNetworkSettings) IDockerHostConfig(org.eclipse.linuxtools.docker.core.IDockerHostConfig) IDockerPortBinding(org.eclipse.linuxtools.docker.core.IDockerPortBinding) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) Job(org.eclipse.core.runtime.jobs.Job)

Example 27 with IDockerImage

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

the class DockerImageHierarchyLabelProvider method getStyledText.

/**
 * @param image
 *            the {@link IDockerImage} to process
 * @return the {@link StyledString} to be displayed.
 */
public static StyledString getStyledText(final IDockerImage image) {
    final Map<String, List<String>> imageTagsByRepo = DockerImage.extractTagsByRepo(image.repoTags());
    final List<String> imageRepos = new ArrayList<>(imageTagsByRepo.keySet());
    Collections.sort(imageRepos);
    final StyledString result = new StyledString();
    imageRepos.forEach(repo -> {
        result.append(repo);
        final List<String> tags = imageTagsByRepo.get(repo);
        final String joinedTags = tags.stream().collect(// $NON-NLS-1$
        Collectors.joining(", "));
        result.append(':');
        // $NON-NLS-1$
        result.append(joinedTags, StyledString.COUNTER_STYLER);
        result.append(' ');
    });
    // TODO: remove the cast to 'DockerImage' once the 'shortId()'
    // method is in the public API
    // $NON-NLS-1$
    result.append('(', StyledString.QUALIFIER_STYLER).append(((DockerImage) image).shortId(), StyledString.QUALIFIER_STYLER).append(')', // $NON-NLS-1$
    StyledString.QUALIFIER_STYLER);
    return result;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DockerImage(org.eclipse.linuxtools.internal.docker.core.DockerImage) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString)

Example 28 with IDockerImage

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

the class DockerImagesView method createTableViewer.

private void createTableViewer(final Composite container) {
    search = new Text(container, SWT.SEARCH | SWT.ICON_SEARCH);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(search);
    search.addModifyListener(onSearch());
    Composite tableArea = new Composite(container, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(tableArea);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(tableArea);
    final TableColumnLayout tableLayout = new TableColumnLayout();
    tableArea.setLayout(tableLayout);
    this.viewer = new TableViewer(tableArea, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    this.viewer.setContentProvider(new DockerImagesContentProvider());
    final Table table = viewer.getTable();
    GridLayoutFactory.fillDefaults().numColumns(1).margins(0, 0).applyTo(table);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(table);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    // 'Image' column
    final TableViewerColumn idColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "ID"));
    setLayout(idColumn, tableLayout, 150);
    idColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                // for image id, remove any sha256 digest prefix
                // and truncate to max of 12 characters
                String imageId = ((IDockerImage) element).id();
                if (// $NON-NLS-1$
                imageId.startsWith("sha256:"))
                    imageId = imageId.substring(7);
                if (imageId.length() > 12) {
                    return imageId.substring(0, 12);
                }
                return imageId;
            }
            return super.getText(element);
        }
    });
    // 'Repo/Tags' column
    final TableViewerColumn tagsColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "TAGS"));
    setLayout(tagsColumn, tableLayout, 150);
    tagsColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                final IDockerImage image = (IDockerImage) element;
                final StringBuilder messageBuilder = new StringBuilder();
                for (Iterator<String> iterator = image.repoTags().iterator(); iterator.hasNext(); ) {
                    final String repoTag = iterator.next();
                    messageBuilder.append(repoTag);
                    if (iterator.hasNext()) {
                        messageBuilder.append('\n');
                    }
                }
                return messageBuilder.toString();
            }
            return super.getText(element);
        }
    });
    // 'Creation Date' column
    final TableViewerColumn creationDateColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "CREATED"));
    setLayout(creationDateColumn, tableLayout, 150);
    creationDateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                return LabelProviderUtils.toCreatedDate(Long.parseLong(((IDockerImage) element).created()));
            }
            return super.getText(element);
        }
    });
    // 'Virtual Size' column
    final TableViewerColumn virtsizeColumn = createColumn(DVMessages.getString(// $NON-NLS-1$
    "VIRTSIZE"));
    setLayout(virtsizeColumn, tableLayout, 150);
    virtsizeColumn.setLabelProvider(new SpecialColumnLabelProvider() {

        @Override
        public String getText(final Object element) {
            if (element instanceof IDockerImage) {
                Long size = ((IDockerImage) element).virtualSize();
                if (size <= 0)
                    // $NON-NLS-1$
                    return "0";
                final String[] units = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "B", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "kB", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "MB", "GB", // $NON-NLS-1$ //$NON-NLS-2$
                "TB" };
                int digitGroups = (int) (Math.log10(size) / Math.log10(1000));
                return new DecimalFormat("#,##0.#").format(// $NON-NLS-1$
                size / Math.pow(1000, digitGroups)) + " " + units[digitGroups];
            }
            return super.getText(element);
        }

        @Override
        public String getCompareText(final Object element) {
            // and not the shortened value with units appended.
            if (element instanceof IDockerImage) {
                return // $NON-NLS-1$
                new DecimalFormat("000000000000000000000000").format((((IDockerImage) element).virtualSize()));
            }
            return super.getText(element);
        }
    });
    // comparator
    final DockerImagesComparator comparator = new DockerImagesComparator(this.viewer);
    comparator.setColumn(creationDateColumn.getColumn());
    // Set column a second time so we reverse the order and default to most
    // currently created containers first
    comparator.setColumn(creationDateColumn.getColumn());
    viewer.setComparator(comparator);
    // apply search filter
    this.viewer.addFilter(getImagesFilter());
    setConnection(CommandUtils.getCurrentConnection(null));
    // get the current selection in the tableviewer
    getSite().setSelectionProvider(viewer);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) DecimalFormat(java.text.DecimalFormat) Text(org.eclipse.swt.widgets.Text) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Iterator(java.util.Iterator) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 29 with IDockerImage

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

the class JavaAppInContainerLaunchDelegate method launch.

/* (non-Javadoc)
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    // $NON-NLS-1$
    monitor.beginTask(NLS.bind("{0}...", new String[] { configuration.getName() }), 3);
    // check for cancellation
    if (monitor.isCanceled()) {
        return;
    }
    String connectionURI = configuration.getAttribute(JavaLaunchConfigurationConstants.CONNECTION_URI, (String) null);
    String imageID = configuration.getAttribute(JavaLaunchConfigurationConstants.IMAGE_ID, (String) null);
    List<String> extraDirs = configuration.getAttribute(JavaLaunchConfigurationConstants.DIRS, Arrays.asList(new String[0]));
    try {
        DockerConnection conn = (DockerConnection) DockerConnectionManager.getInstance().getConnectionByUri(connectionURI);
        if (conn == null) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_connection_not_found_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_connection_not_found_text, connectionURI));
                }
            });
            return;
        } else if (!conn.isOpen()) {
            try {
                conn.open(false);
            } catch (DockerException e) {
            }
            if (!conn.isOpen()) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_connection_not_active_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_connection_not_active_text, connectionURI));
                    }
                });
                return;
            }
        }
        IDockerImage img = conn.getImage(imageID);
        if (img == null) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_image_not_found_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_image_not_found_text, imageID));
                }
            });
            return;
        }
        // randomized port between 1025 and 65535
        int port = ILaunchManager.DEBUG_MODE.equals(mode) ? (int) ((65535 - 1025) * Math.random()) + 1025 : -1;
        monitor.subTask(Messages.JavaAppInContainerLaunchDelegate_Verifying_launch_attributes____1);
        String mainTypeName = verifyMainTypeName(configuration);
        IVMInstall vm = new ContainerVMInstall(configuration, img, port);
        ContainerVMRunner runner = new ContainerVMRunner(vm);
        File workingDir = verifyWorkingDirectory(configuration);
        String workingDirName = null;
        if (workingDir != null) {
            workingDirName = workingDir.getAbsolutePath();
        }
        runner.setAdditionalDirectories(extraDirs);
        // Environment variables
        String[] envp = getEnvironment(configuration);
        // Program & VM arguments
        String pgmArgs = getProgramArguments(configuration);
        String vmArgs = getVMArguments(configuration);
        ExecutionArguments execArgs = new ExecutionArguments(vmArgs, pgmArgs);
        // VM-specific attributes
        Map<String, Object> vmAttributesMap = getVMSpecificAttributesMap(configuration);
        // Classpath
        String[] classpath = getClasspath(configuration);
        if (Platform.OS_WIN32.equals(Platform.getOS())) {
            for (int i = 0; i < classpath.length; i++) {
                classpath[i] = UnixFile.convertDOSPathToUnixPath(classpath[i]);
            }
        }
        // Create VM config
        VMRunnerConfiguration runConfig = new VMRunnerConfiguration(mainTypeName, classpath);
        runConfig.setProgramArguments(execArgs.getProgramArgumentsArray());
        runConfig.setEnvironment(envp);
        List<String> finalVMArgs = new ArrayList<>(Arrays.asList(execArgs.getVMArgumentsArray()));
        if (ILaunchManager.DEBUG_MODE.equals(mode)) {
            double version = getJavaVersion(conn, img);
            if (version < 1.5) {
                // $NON-NLS-1$
                finalVMArgs.add("-Xdebug");
                // $NON-NLS-1$
                finalVMArgs.add("-Xnoagent");
            }
            // check if java 1.4 or greater
            if (version < 1.4) {
                // $NON-NLS-1$
                finalVMArgs.add("-Djava.compiler=NONE");
            }
            if (version < 1.5) {
                // $NON-NLS-1$
                finalVMArgs.add("-Xrunjdwp:transport=dt_socket,server=y,address=" + port);
            } else {
                // $NON-NLS-1$
                finalVMArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,address=" + port);
            }
        }
        runConfig.setVMArguments(finalVMArgs.toArray(new String[0]));
        runConfig.setWorkingDirectory(workingDirName);
        runConfig.setVMSpecificAttributesMap(vmAttributesMap);
        // Bootpath
        runConfig.setBootClassPath(getBootpath(configuration));
        // check for cancellation
        if (monitor.isCanceled()) {
            return;
        }
        // stop in main
        prepareStopInMain(configuration);
        // done the verification phase
        monitor.worked(1);
        monitor.subTask(Messages.JavaAppInContainerLaunchDelegate_Creating_source_locator____2);
        // set the default source locator if required
        setDefaultSourceLocator(launch, configuration);
        monitor.worked(1);
        // Launch the configuration - 1 unit of work
        runner.run(runConfig, launch, monitor);
        // check for cancellation
        if (monitor.isCanceled()) {
            return;
        }
        if (ILaunchManager.DEBUG_MODE.equals(mode)) {
            while (runner.getIPAddress() == null || !runner.isListening()) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
            IDockerContainerInfo info = runner.getContainerInfo();
            // $NON-NLS-1$
            String configName = info.name().startsWith("/") ? info.name().substring(1) : info.name();
            ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
            ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_REMOTE_JAVA_APPLICATION);
            ILaunchConfiguration cfgForAttach = type.newInstance(null, configName);
            ILaunchConfigurationWorkingCopy wc = cfgForAttach.getWorkingCopy();
            String ip = runner.getIPAddress();
            // Can we reach it ? Or is it on a different network.
            if (!isListening(ip, port)) {
                // If the daemon is reachable via TCP it should forward traffic.
                if (conn.getSettings() instanceof TCPConnectionSettings) {
                    ip = ((TCPConnectionSettings) conn.getSettings()).getAddr();
                    if (!isListening(ip, port)) {
                        // Try to find some network interface that's listening
                        ip = getIPAddressListening(port);
                        if (!isListening(ip, port)) {
                            ip = null;
                        }
                    }
                } else {
                    ip = null;
                }
            }
            if (ip == null) {
                String imageName = conn.getImage(imageID).repoTags().get(0);
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.JavaAppInContainerLaunchDelegate_session_unreachable_title, Messages.bind(Messages.JavaAppInContainerLaunchDelegate_session_unreachable_text, new Object[] { imageName, imageID, runner.getIPAddress() }));
                    }
                });
                return;
            }
            Map<String, String> map = new HashMap<>();
            // $NON-NLS-1$
            map.put("hostname", ip);
            // $NON-NLS-1$
            map.put("port", String.valueOf(port));
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, map);
            String projectName = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String) null);
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
            wc.doSave();
            DebugUITools.launch(cfgForAttach, ILaunchManager.DEBUG_MODE);
        }
    } finally {
        monitor.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) VMRunnerConfiguration(org.eclipse.jdt.launching.VMRunnerConfiguration) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) DockerException(org.eclipse.linuxtools.docker.core.DockerException) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) TCPConnectionSettings(org.eclipse.linuxtools.internal.docker.core.TCPConnectionSettings) IVMInstall(org.eclipse.jdt.launching.IVMInstall) ExecutionArguments(org.eclipse.jdt.launching.ExecutionArguments) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerContainerInfo(org.eclipse.linuxtools.docker.core.IDockerContainerInfo) File(java.io.File)

Example 30 with IDockerImage

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

the class JavaImageTab method createControl.

@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    composite.setLayout(layout);
    composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));
    Label connLbl = new Label(composite, SWT.NONE);
    connLbl.setText(Messages.ImageSelectionDialog_connection_label);
    connCmb = new ComboViewer(composite, SWT.READ_ONLY);
    connCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    connCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            for (IDockerConnection conn : DockerConnectionManager.getInstance().getAllConnections()) {
                try {
                    ((DockerConnection) conn).open(false);
                } catch (DockerException e) {
                }
            }
            return DockerConnectionManager.getInstance().getAllConnections().stream().filter(c -> c.isOpen()).toArray(size -> new IDockerConnection[size]);
        }
    });
    // $NON-NLS-1$
    connCmb.setInput("place_holder");
    Label imageLbl = new Label(composite, SWT.NONE);
    imageLbl.setText(Messages.ImageSelectionDialog_image_label);
    imageCmb = new ComboViewer(composite, SWT.READ_ONLY);
    imageCmb.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false));
    imageCmb.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            IDockerConnection conn = (IDockerConnection) inputElement;
            if (conn == null || conn.getImages() == null) {
                return new Object[0];
            } else {
                return conn.getImages().stream().filter(// $NON-NLS-1$
                i -> !i.repoTags().get(0).equals("<none>:<none>")).toArray(size -> new IDockerImage[size]);
            }
        }
    });
    imageCmb.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            IDockerImage img = (IDockerImage) element;
            return img.repoTags().get(0);
        }
    });
    imageCmb.setInput(null);
    connCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerConnection conn = (IDockerConnection) sel.getFirstElement();
            selectedConnection = conn;
            imageCmb.setInput(conn);
            updateLaunchConfigurationDialog();
        }
    });
    imageCmb.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = event.getStructuredSelection();
            IDockerImage img = (IDockerImage) sel.getFirstElement();
            selectedImage = img;
            updateLaunchConfigurationDialog();
        }
    });
    Group dirGroup = new Group(composite, SWT.NONE);
    dirGroup.setText(Messages.JavaImageTab_additional_dirs);
    dirGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    dirGroup.setLayout(new GridLayout(2, false));
    directoryList = new List(dirGroup, SWT.SINGLE | SWT.V_SCROLL);
    directoryList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2));
    directoryList.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeButton.setEnabled(true);
        }
    });
    addButton = createPushButton(dirGroup, Messages.JavaImageTab_button_add, null);
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(getShell());
            String directory = dialog.open();
            if (directory != null && !listContains(directoryList, directory)) {
                directoryList.add(directory);
                updateLaunchConfigurationDialog();
            }
        }
    });
    removeButton = createPushButton(dirGroup, Messages.JavaImageTab_button_remove, null);
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int i = directoryList.getSelectionIndex();
            if (i >= 0) {
                directoryList.remove(i);
                updateLaunchConfigurationDialog();
            }
            if (directoryList.getItemCount() == 0) {
                removeButton.setEnabled(false);
            }
        }
    });
    removeButton.setEnabled(false);
    setControl(composite);
}
Also used : DockerException(org.eclipse.linuxtools.docker.core.DockerException) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Arrays(java.util.Arrays) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) CoreException(org.eclipse.core.runtime.CoreException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) AbstractLaunchConfigurationTab(org.eclipse.debug.ui.AbstractLaunchConfigurationTab) Composite(org.eclipse.swt.widgets.Composite) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) DockerException(org.eclipse.linuxtools.docker.core.DockerException) GridData(org.eclipse.swt.layout.GridData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Button(org.eclipse.swt.widgets.Button) DockerConnectionManager(org.eclipse.linuxtools.docker.core.DockerConnectionManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Group(org.eclipse.swt.widgets.Group) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) SWT(org.eclipse.swt.SWT) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) List(org.eclipse.swt.widgets.List) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(org.eclipse.swt.widgets.List) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)41 IDockerConnection (org.eclipse.linuxtools.docker.core.IDockerConnection)16 DockerException (org.eclipse.linuxtools.docker.core.DockerException)10 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 IDockerImageHierarchyNode (org.eclipse.linuxtools.docker.core.IDockerImageHierarchyNode)7 List (java.util.List)6 CoreException (org.eclipse.core.runtime.CoreException)6 IDockerHostConfig (org.eclipse.linuxtools.docker.core.IDockerHostConfig)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)5 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5 HashMap (java.util.HashMap)4 Map (java.util.Map)3 Job (org.eclipse.core.runtime.jobs.Job)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 IDockerContainerConfig (org.eclipse.linuxtools.docker.core.IDockerContainerConfig)3 IDockerImageInfo (org.eclipse.linuxtools.docker.core.IDockerImageInfo)3 DockerContainerConfig (org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig)3