Search in sources :

Example 51 with IDockerConnection

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

the class ShowInWebBrowserCommandHandler method execute.

@Override
public Object execute(final ExecutionEvent event) {
    final IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
    final List<IDockerPortMapping> portMappings = getSelectedPortMappings(activePart);
    if (portMappings == null || portMappings.isEmpty()) {
        return null;
    }
    final Job job = new Job(// $NON-NLS-1$
    CommandMessages.getString("command.showIn.webBrowser")) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            try {
                final IDockerConnection currentConnection = getCurrentConnection(activePart);
                final IDockerPortMapping selectedPort = portMappings.get(0);
                final URI connectionURI = new URI(currentConnection.getUri());
                if (// $NON-NLS-1$
                "tcp".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "unix".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "http".equalsIgnoreCase(connectionURI.getScheme()) || // $NON-NLS-1$
                "https".equalsIgnoreCase(connectionURI.getScheme())) {
                    final String host = // $NON-NLS-1$
                    "unix".equalsIgnoreCase(connectionURI.getScheme()) ? "127.0.0.1" : // $NON-NLS-1$
                    connectionURI.getHost();
                    final URL location = new // $NON-NLS-1$
                    URL(// $NON-NLS-1$
                    "http", // $NON-NLS-1$
                    host, selectedPort.getPublicPort(), // $NON-NLS-1$
                    "/");
                    openLocationInWebBrowser(location);
                }
            } catch (URISyntaxException | MalformedURLException e) {
                Activator.logErrorMessage(CommandMessages.getString(// $NON-NLS-1$
                "command.showIn.webBrowser.failure"), e);
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MalformedURLException(java.net.MalformedURLException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) URISyntaxException(java.net.URISyntaxException) IDockerPortMapping(org.eclipse.linuxtools.docker.core.IDockerPortMapping) Job(org.eclipse.core.runtime.jobs.Job) URI(java.net.URI) URL(java.net.URL)

Example 52 with IDockerConnection

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

the class NewDockerConnectionSWTBotTest method configureTCPConnection.

private IDockerConnection configureTCPConnection(final String connectionName, final String host) {
    final DockerClient client = MockDockerClientFactory.build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from(connectionName, client).withTCPConnectionSettings(host, null);
    DockerConnectionManagerUtils.configureConnectionManager(dockerConnection);
    return dockerConnection;
}
Also used : IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) DockerClient(com.spotify.docker.client.DockerClient)

Example 53 with IDockerConnection

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

the class DeployImagePage method createDockerConnectionInfoControl.

private void createDockerConnectionInfoControl(Composite parent, DataBindingContext dbc) {
    Label lblConnection = createDockerConnectionLabel(parent);
    final Text connectionText = new Text(parent, SWT.READ_ONLY | SWT.NO_FOCUS);
    connectionText.setBackground(lblConnection.getBackground());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(NUM_COLUMS - 1, 1).grab(true, false).applyTo(connectionText);
    final IObservableValue<String> connnectionTextObservable = WidgetProperties.text(SWT.None).observe(connectionText);
    final IObservableValue<IDockerConnection> connnectionObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model);
    ValueBindingBuilder.bind(connnectionTextObservable).notUpdatingParticipant().to(connnectionObservable).converting(new ObjectToStringConverter(IDockerConnection.class) {

        ConnectionColumLabelProvider labelProvider = new ConnectionColumLabelProvider();

        @Override
        public Object convert(Object source) {
            return (source instanceof IDockerConnection) ? dockerConnectionToString((IDockerConnection) source) : "";
        }
    }).in(dbc);
}
Also used : ConnectionColumLabelProvider(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionColumLabelProvider) Label(org.eclipse.swt.widgets.Label) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ObjectToStringConverter(org.eclipse.core.internal.databinding.conversion.ObjectToStringConverter) Text(org.eclipse.swt.widgets.Text)

Example 54 with IDockerConnection

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

the class DeployImageWizard method getPushImageToRegistryJob.

private static PushImageToRegistryJob getPushImageToRegistryJob(final IDeployImageParameters model) {
    final IDockerConnection dockerConnection = model.getDockerConnection();
    final String imageName = model.getImageName();
    final String deployProjectName = model.getProject().getName();
    final IRegistryAccount registryAccount = new IRegistryAccount() {

        @Override
        public String getServerAddress() {
            return model.getTargetRegistryLocation();
        }

        @Override
        public String getUsername() {
            return model.getTargetRegistryUsername();
        }

        @Override
        public char[] getPassword() {
            return model.getTargetRegistryPassword().toCharArray();
        }

        @Override
        public String getEmail() {
            return null;
        }

        @Override
        public List<IRepositoryTag> getTags(String arg0) throws DockerException {
            return null;
        }

        @Override
        public boolean isVersion2() {
            return false;
        }

        @Override
        public List<IDockerImageSearchResult> getImages(String arg0) throws DockerException {
            return null;
        }
    };
    return new PushImageToRegistryJob(dockerConnection, registryAccount, deployProjectName, imageName);
}
Also used : IRepositoryTag(org.eclipse.linuxtools.docker.core.IRepositoryTag) IDockerImageSearchResult(org.eclipse.linuxtools.docker.core.IDockerImageSearchResult) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IRegistryAccount(org.eclipse.linuxtools.docker.core.IRegistryAccount) PushImageToRegistryJob(org.jboss.tools.openshift.internal.core.docker.PushImageToRegistryJob)

Example 55 with IDockerConnection

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

the class DeployImagePage method createDockerConnectionControl.

private void createDockerConnectionControl(Composite parent, DataBindingContext dbc) {
    createDockerConnectionLabel(parent);
    StructuredViewer connectionViewer = new ComboViewer(parent);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(NUM_COLUMS - 2, 1).applyTo(connectionViewer.getControl());
    connectionViewer.setContentProvider(new ObservableListContentProvider());
    connectionViewer.setLabelProvider(new ObservableTreeItemLabelProvider() {

        @Override
        public String getText(Object element) {
            return (element instanceof IDockerConnection) ? dockerConnectionToString((IDockerConnection) element) : "";
        }
    });
    connectionViewer.setInput(BeanProperties.list(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTIONS).observe(model));
    IObservableValue<IDockerConnection> dockerConnectionObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model);
    DockerConnectionStatusProvider validator = new DockerConnectionStatusProvider(dockerConnectionObservable);
    IObservableValue<?> selectedConnectionObservable = ViewerProperties.singleSelection().observe(connectionViewer);
    Binding selectedConnectionBinding = ValueBindingBuilder.bind(selectedConnectionObservable).converting(new ObservableTreeItem2ModelConverter(IDockerConnection.class)).validatingAfterConvert(validator).to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).in(dbc);
    ControlDecorationSupport.create(selectedConnectionBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Button newDockerConnectionButton = new Button(parent, SWT.PUSH);
    newDockerConnectionButton.setText("New...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(newDockerConnectionButton);
    UIUtils.setDefaultButtonWidth(newDockerConnectionButton);
    newDockerConnectionButton.addSelectionListener(onNewDockerConnectionClicked());
    dbc.addValidationStatusProvider(validator);
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableTreeItemLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer)

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