Search in sources :

Example 31 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class OpenShiftExplorerContentProvider method getConnectionChildren.

protected Object[] getConnectionChildren(IConnectionWrapper connection) {
    switch(connection.getState()) {
        case LOADED:
            removeStub(connection);
            Object[] result = connection.getResources().toArray();
            if (result == null || result.length == 0) {
                result = new Object[] { new NewProjectLinkNode((Connection) connection.getWrapped()) };
            }
            return result;
        case LOAD_STOPPED:
            LoadingStub stub = removeStub(connection);
            if (stub != null) {
                return stub.getChildren();
            }
        default:
            connection.load(e -> handleLoadingException(connection, e));
            return new Object[] { makeStub(connection) };
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) LoadingStub(org.jboss.tools.openshift.internal.common.ui.explorer.BaseExplorerContentProvider.LoadingStub)

Example 32 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class DeployImageHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Connection connection = null;
    IProject project = null;
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    final IDockerImage image = UIUtils.getFirstElement(selection, IDockerImage.class);
    if (image == null || OpenShiftUIUtils.hasOpenShiftExplorerSelection()) {
        selection = OpenShiftUIUtils.getOpenShiftExplorerSelection();
        project = ResourceUtils.getProject(UIUtils.getFirstElement(selection, IResource.class));
        if (project != null) {
            connection = ConnectionsRegistryUtil.getConnectionFor(project);
        } else {
            connection = UIUtils.getFirstElement(selection, Connection.class);
        }
    }
    if (connection == null) {
        connection = OpenShiftUIUtils.getExplorerDefaultConnection(Connection.class);
    }
    IDockerConnection dockerConnection = null;
    if (image != null) {
        dockerConnection = image.getConnection();
    } else if (OpenShiftUIUtils.hasDockerExplorerSelection()) {
        ISelection dockerSelection = OpenShiftUIUtils.getDockerExplorerSelection();
        dockerConnection = UIUtils.getFirstElement(dockerSelection, IDockerConnection.class);
        if (dockerConnection == null) {
            // Action is originated from OpenShift Explorer, do the best to pick up Docker connection from the current selection in Docker Explorer.
            IDockerImage selectedImage = UIUtils.getFirstElement(dockerSelection, IDockerImage.class);
            if (selectedImage != null) {
                dockerConnection = selectedImage.getConnection();
            }
        }
    }
    runWizard(HandlerUtil.getActiveWorkbenchWindow(event).getShell(), dockerConnection, image, project, connection);
    return null;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) ISelection(org.eclipse.jface.viewers.ISelection) IDockerConnection(org.eclipse.linuxtools.docker.core.IDockerConnection) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IProject(com.openshift.restclient.model.IProject)

Example 33 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class OpenShiftServerEditorModel method setConnection.

public void setConnection(Connection connection, boolean executeCommand) {
    Connection previous = getConnection();
    String newUrl = connection == null ? null : getConnectionUrl(connection);
    super.setConnection(connection);
    // fire server command
    if (executeCommand)
        section.execute(new SetConnectionCommand(getServer(), previous, connection, newUrl));
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 34 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class ImportApplicationWizard method setConnection.

private void setConnection(IProject project) {
    Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(project);
    setModelConnection(connection);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 35 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class ConnectionTest method shouldReplaceExtendedProperty.

@SuppressWarnings("serial")
@Test
public void shouldReplaceExtendedProperty() throws Exception {
    // given
    Connection connection = new Connection("http://localhost", null, null);
    connection.setExtendedProperty("kung", "foo");
    connection.setExtendedProperty("foo", "bar");
    assertThat(connection.getExtendedProperties()).containsEntry("kung", "foo").containsEntry("foo", "bar");
    // when
    connection.setExtendedProperties(new HashMap<String, Object>() {

        {
            put("foo", "bar");
        }
    });
    // then
    assertThat(connection.getExtendedProperties()).hasSize(1);
    assertThat(connection.getExtendedProperties()).containsExactly(MapEntry.entry("foo", "bar"));
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Connection (org.jboss.tools.openshift.core.connection.Connection)110 Test (org.junit.Test)48 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)30 IResource (com.openshift.restclient.model.IResource)27 IProject (com.openshift.restclient.model.IProject)18 IService (com.openshift.restclient.model.IService)11 IStatus (org.eclipse.core.runtime.IStatus)11 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)9 Collection (java.util.Collection)8 List (java.util.List)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IPod (com.openshift.restclient.model.IPod)7 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IRoute (com.openshift.restclient.model.route.IRoute)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)6