Search in sources :

Example 6 with Connection

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

the class PodLogsHandler method getPodFromBuild.

private IPod getPodFromBuild(ExecutionEvent event) {
    IBuild build = getSelectedElement(event, IBuild.class);
    if (build != null) {
        final String buildName = build.getName();
        Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(build);
        List<IPod> pods = connection.getResources(ResourceKind.POD, build.getNamespaceName());
        for (IPod pod : pods) {
            if (buildName.equals(pod.getAnnotation(OpenShiftAPIAnnotations.BUILD_NAME))) {
                return pod;
            }
        }
    }
    return null;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IPod(com.openshift.restclient.model.IPod) IBuild(com.openshift.restclient.model.IBuild)

Example 7 with Connection

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

the class NewProjectHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Connection connection = UIUtils.getFirstElement(selection, Connection.class);
    if (connection == null) {
        IProject project = UIUtils.getFirstElement(selection, IProject.class);
        if (project != null) {
            connection = ConnectionsRegistryUtil.getConnectionFor(project);
        }
    }
    if (connection == null) {
        // $NON-NLS-1$
        return OpenShiftUIActivator.statusFactory().cancelStatus("No connection selected");
    }
    openNewProjectDialog(connection, HandlerUtil.getActiveShell(event));
    return null;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) IProject(com.openshift.restclient.model.IProject)

Example 8 with Connection

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

the class ConnectionValidatorFactory method createBasicAuthenticationValidator.

/**
 * Returns new validator that checks that there is no connection other than the selected one
 * with host and username provided by the observable values.
 * @param pageModel
 * @param usernameObservable
 * @param urlObservable
 * @return
 */
public static MultiValidator createBasicAuthenticationValidator(ConnectionWizardPageModel pageModel, IObservableValue usernameObservable, IObservableValue<?> urlObservable) {
    return new MultiValidator() {

        @Override
        protected IStatus validate() {
            String user1 = (String) usernameObservable.getValue();
            String mHost = (String) urlObservable.getValue();
            IConnection current = pageModel.getSelectedConnection();
            for (Connection c : ConnectionsRegistrySingleton.getInstance().getAll(Connection.class)) {
                if (c != current && IAuthorizationContext.AUTHSCHEME_BASIC.equals(c.getAuthScheme())) {
                    String host = c.getHost();
                    String user = c.getUsername();
                    if (host != null && host.equals(mHost) && user != null && user.equals(user1)) {
                        return ValidationStatus.error("Connection for the server with this username already exists.");
                    }
                }
            }
            return ValidationStatus.ok();
        }
    };
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Example 9 with Connection

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

the class ConnectionValidatorFactory method createOAuthAuthenticationValidator.

/**
 * Returns new validator that checks that there is no connection other than the selected one
 * with host and token provided by the observable values.
 * @param pageModel
 * @param tokenObservable
 * @param urlObservable
 * @return
 */
public static MultiValidator createOAuthAuthenticationValidator(ConnectionWizardPageModel pageModel, IObservableValue tokenObservable, IObservableValue<?> urlObservable) {
    return new MultiValidator() {

        @Override
        protected IStatus validate() {
            String token1 = (String) tokenObservable.getValue();
            String mHost = (String) urlObservable.getValue();
            IConnection current = pageModel.getSelectedConnection();
            for (Connection c : ConnectionsRegistrySingleton.getInstance().getAll(Connection.class)) {
                if (c != current && IAuthorizationContext.AUTHSCHEME_OAUTH.equals(c.getAuthScheme())) {
                    String host = c.getHost();
                    String token = c.getToken();
                    if (host != null && host.equals(mHost) && token != null && token.equals(token1)) {
                        return ValidationStatus.error("Connection for the server with this token already exists.");
                    }
                }
            }
            return ValidationStatus.ok();
        }
    };
}
Also used : IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Example 10 with Connection

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

the class BasicAuthenticationDetailView method setSelectedConnection.

@Override
public void setSelectedConnection(IConnection conn) {
    if (conn instanceof Connection) {
        Connection selectedConnection = (Connection) conn;
        usernameObservable.setValue(selectedConnection.getUsername());
        passwordObservable.setValue(selectedConnection.getPassword());
        rememberPasswordObservable.setValue(selectedConnection.isRememberPassword());
    } else if (conn instanceof NewConnectionMarker) {
        usernameObservable.setValue(null);
        passwordObservable.setValue(null);
    }
}
Also used : NewConnectionMarker(org.jboss.tools.openshift.common.core.connection.NewConnectionMarker) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

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