Search in sources :

Example 31 with IRoute

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

the class SelectedRoutePreference method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShell(event);
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    final IRoute route = UIUtils.getFirstElement(currentSelection, IRoute.class);
    // Open route
    if (route != null) {
        return openBrowser(shell, route);
    }
    IServiceWrapper service = UIUtils.getFirstElement(currentSelection, IServiceWrapper.class);
    if (service != null) {
        new RouteOpenerJob(service.getWrapped().getNamespaceName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = service.getResourcesOfKind(ResourceKind.ROUTE).stream().map(r -> (IRoute) r.getWrapped()).collect(Collectors.toList());
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    // Open Project
    final IProject project = UIUtils.getFirstElement(currentSelection, IProject.class);
    if (project != null) {
        new RouteOpenerJob(project.getName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = project.getResources(ResourceKind.ROUTE);
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    // Open Connection
    final IConnection connection = UIUtils.getFirstElement(currentSelection, IConnection.class);
    if (connection != null) {
        return openBrowser(shell, connection.getHost());
    }
    return nothingToOpenDialog(shell);
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) StringUtils(org.apache.commons.lang.StringUtils) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) IProject(com.openshift.restclient.model.IProject) ArrayList(java.util.ArrayList) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IStatus(org.eclipse.core.runtime.IStatus) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) Map(java.util.Map) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) Shell(org.eclipse.swt.widgets.Shell) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) BrowserUtility(org.jboss.tools.foundation.ui.util.BrowserUtility) SelectRouteDialog(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Dialog(org.eclipse.jface.dialogs.Dialog) IRoute(com.openshift.restclient.model.route.IRoute) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IRoute(com.openshift.restclient.model.route.IRoute) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IProject(com.openshift.restclient.model.IProject)

Example 32 with IRoute

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

the class SelectedRoutePreference method getSelectedRoute.

public IRoute getSelectedRoute(List<IRoute> routes) {
    String key = getKey(routes);
    if (choices.containsKey(key)) {
        String selectedRoute = choices.get(key);
        for (IRoute route : routes) {
            if (selectedRoute.equals(getKey(route))) {
                // move item to most recent
                history.remove(key);
                history.add(key);
                return route;
            }
        }
    }
    return null;
}
Also used : IRoute(com.openshift.restclient.model.route.IRoute)

Example 33 with IRoute

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

the class EditDefaultRouteHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShell(event);
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    IServiceWrapper service = UIUtils.getFirstElement(currentSelection, IServiceWrapper.class);
    if (service != null) {
        new RouteOpenerJob(service.getWrapped().getNamespaceName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = service.getResourcesOfKind(ResourceKind.ROUTE).stream().map(r -> (IRoute) r.getWrapped()).collect(Collectors.toList());
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    final IProject project = UIUtils.getFirstElement(currentSelection, IProject.class);
    if (project != null) {
        new RouteOpenerJob(project.getName(), shell) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                this.routes = project.getResources(ResourceKind.ROUTE);
                return Status.OK_STATUS;
            }
        }.schedule();
        return Status.OK_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Shell(org.eclipse.swt.widgets.Shell) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) SelectRouteDialog(org.jboss.tools.openshift.internal.ui.dialog.SelectRouteDialog) Status(org.eclipse.core.runtime.Status) ExecutionException(org.eclipse.core.commands.ExecutionException) Collectors(java.util.stream.Collectors) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IProject(com.openshift.restclient.model.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) List(java.util.List) IStatus(org.eclipse.core.runtime.IStatus) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) Dialog(org.eclipse.jface.dialogs.Dialog) IRoute(com.openshift.restclient.model.route.IRoute) UIUpdatingJob(org.jboss.tools.openshift.internal.common.ui.job.UIUpdatingJob) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IRoute(com.openshift.restclient.model.route.IRoute) IProject(com.openshift.restclient.model.IProject)

Example 34 with IRoute

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

the class ResourceUtilsTest method serviceAndRouteWithSameNameShouldBeRelated.

public void serviceAndRouteWithSameNameShouldBeRelated() {
    // given
    IRoute route = mock(IRoute.class);
    when(route.getServiceName()).thenReturn("42");
    IService service = mock(IService.class);
    when(service.getName()).thenReturn("42");
    // when
    // then
    assertThat(areRelated(route, service)).isTrue();
}
Also used : IRoute(com.openshift.restclient.model.route.IRoute) IService(com.openshift.restclient.model.IService)

Aggregations

IRoute (com.openshift.restclient.model.route.IRoute)34 Test (org.junit.Test)15 IService (com.openshift.restclient.model.IService)10 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 List (java.util.List)6 ResourceKind (com.openshift.restclient.ResourceKind)5 Connection (org.jboss.tools.openshift.core.connection.Connection)5 IProject (com.openshift.restclient.model.IProject)4 IResource (com.openshift.restclient.model.IResource)4 Collection (java.util.Collection)4 CoreException (org.eclipse.core.runtime.CoreException)4 NLS (org.eclipse.osgi.util.NLS)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 AbstractHandler (org.eclipse.core.commands.AbstractHandler)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 IStatus (org.eclipse.core.runtime.IStatus)3 ISelection (org.eclipse.jface.viewers.ISelection)3