Search in sources :

Example 21 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class ImportApplicationWizard method init.

@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
    if (model.getConnection() != null && model.getSelectedItem() != null) {
        return;
    }
    Connection connection = UIUtils.getFirstElement(selection, Connection.class);
    if (connection != null) {
        model.setConnection(connection);
    } else {
        IResource resource = UIUtils.getFirstElement(selection, IResource.class);
        if (resource != null) {
            setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(resource));
            model.setSelectedItem(resource);
        } else {
            IProject project = UIUtils.getFirstElement(selection, IProject.class);
            if (project != null) {
                setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(project));
                model.setSelectedItem(project);
            }
        }
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject)

Example 22 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class OpenShiftServiceRequirement method createService.

private IService createService(String serviceName, ITemplate template, String projectName, Connection connection) {
    LOGGER.debug(NLS.bind("Creating service in project {0} on server {1} using template {2}", new Object[] { projectName, connection.getHost(), template.getName() }));
    IProject project = OpenShift3NativeResourceUtils.getProject(projectName, connection);
    assertNotNull(project);
    CreateApplicationFromTemplateJob job = new CreateApplicationFromTemplateJob(project, template);
    job.schedule();
    new WaitWhile(new JobIsRunning(new Matcher[] { CoreMatchers.sameInstance(job) }), TimePeriod.LONG);
    new WaitUntil(new NamedResourceExist(ResourceKind.SERVICE, serviceName, projectName, connection), TimePeriod.VERY_LONG);
    return connection.getResource(ResourceKind.SERVICE, projectName, serviceName);
}
Also used : WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) BaseMatcher(org.hamcrest.BaseMatcher) Matcher(org.hamcrest.Matcher) NamedResourceExist(org.jboss.tools.openshift.reddeer.condition.core.NamedResourceExist) JobIsRunning(org.eclipse.reddeer.workbench.core.condition.JobIsRunning) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil) CreateApplicationFromTemplateJob(org.jboss.tools.openshift.internal.ui.job.CreateApplicationFromTemplateJob) IProject(com.openshift.restclient.model.IProject)

Example 23 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class OpenShiftServerExtendedProperties method getWelcomePageUrl.

@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
    String welcomePageUrl = null;
    try {
        // Get connection explicitly to report failure. Try and connect right now to know if it fails.
        // Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
        Connection connection = OpenShiftServerUtils.getConnection(server);
        if (connection == null || !connection.connect()) {
            throw new GetWelcomePageURLException("Connection is not established.");
        }
        IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
        if (resource == null) {
            throw new GetWelcomePageURLException("Resource is missing.");
        }
        IProject project = resource.getProject();
        if ((project != null) && (resource instanceof IService)) {
            List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
            IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
            if (route == null) {
                route = getRoute(routes);
            }
            // Reporting route == null is implemented in getRoute.
            if (route != null) {
                welcomePageUrl = route.getURL();
            }
        }
    } catch (OpenShiftException e) {
        throw new GetWelcomePageURLException(e.getMessage(), e);
    }
    return welcomePageUrl;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService)

Example 24 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class OpenShiftExplorerLabelProvider method getText.

@Override
public String getText(Object element) {
    if (element instanceof IProject) {
        IProject project = (IProject) element;
        String name = project.getName();
        if (org.apache.commons.lang.StringUtils.isNotEmpty(project.getDisplayName())) {
            String[] parts = new String[] { project.getDisplayName(), name };
            applyEllipses(parts);
            name = parts[0] + " (" + parts[1] + ")";
        }
        return name;
    }
    return super.getText(element);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) IProject(com.openshift.restclient.model.IProject)

Example 25 with IProject

use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.

the class ProjectViewerComparator method compare.

/**
 * Compares only projects. Other objects always go after projects and equal to each other.
 * When applied to sorting a mixed array, projects go to the beginning of the array and are sorted,
 * other objects go to the end without change in order.
 * Project named 'default' is always the first.
 * Projects with name prefixed 'openshift' go after 'default' and before all other projects.
 * Finally, projects are compared by label provider, or if it is not available then by name.
 */
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
    boolean isProject1 = (e1 instanceof IProject);
    boolean isProject2 = (e2 instanceof IProject);
    if (!isProject1 || !isProject2) {
        return (isProject1) ? -1 : (isProject2) ? LAST : 0;
    }
    IProject projectOne = (IProject) e1;
    IProject projectTwo = (IProject) e2;
    final String name1 = projectOne.getName();
    final String name2 = projectTwo.getName();
    if (DEFAULT_PROJECT.equals(name1)) {
        return -1;
    }
    if (DEFAULT_PROJECT.equals(name2)) {
        return 1;
    }
    if (name1.startsWith(OPENSHIFT_PROJECT) && !name2.startsWith(OPENSHIFT_PROJECT)) {
        return -1;
    }
    if (!name1.startsWith(OPENSHIFT_PROJECT) && name2.startsWith(OPENSHIFT_PROJECT)) {
        return 1;
    }
    if (labelProvider != null) {
        return labelProvider.getText(e1).compareTo(labelProvider.getText(e2));
    }
    return name1.compareTo(name2);
}
Also used : IProject(com.openshift.restclient.model.IProject)

Aggregations

IProject (com.openshift.restclient.model.IProject)49 Test (org.junit.Test)18 Connection (org.jboss.tools.openshift.core.connection.Connection)16 IResource (com.openshift.restclient.model.IResource)13 ArrayList (java.util.ArrayList)8 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)7 ResourceKind (com.openshift.restclient.ResourceKind)6 IStatus (org.eclipse.core.runtime.IStatus)6 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)6 List (java.util.List)5 ISelection (org.eclipse.jface.viewers.ISelection)5 IService (com.openshift.restclient.model.IService)4 IRoute (com.openshift.restclient.model.route.IRoute)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3