Search in sources :

Example 1 with IServiceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IServiceWrapper in project jbosstools-openshift by jbosstools.

the class ManageEnvironmentVariablesWizard method findReplicationController.

/**
 * If a replication controller is selected, method returns it.
 * If a deployment config is selected, method returns it.
 * If a deployment is selected, method finds a deployment config and returns it.
 * @param event
 * @return
 */
IReplicationController findReplicationController(ExecutionEvent event) {
    ISelection selection = UIUtils.getCurrentSelection(event);
    IDeploymentConfig dc = UIUtils.getFirstElement(selection, IDeploymentConfig.class);
    if (dc != null) {
        return dc;
    }
    IReplicationController rc = UIUtils.getFirstElement(selection, IReplicationController.class);
    if (rc != null) {
        return rc;
    }
    IServiceWrapper deployment = UIUtils.getFirstElement(selection, IServiceWrapper.class);
    Collection<IResourceWrapper<?, ?>> dcs = deployment.getResourcesOfKind(ResourceKind.DEPLOYMENT_CONFIG);
    if (!dcs.isEmpty()) {
        dc = (IDeploymentConfig) dcs.iterator().next().getWrapped();
        if (dc != null) {
            return dc;
        }
    }
    return null;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 2 with IServiceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IServiceWrapper in project jbosstools-openshift by jbosstools.

the class ScaleDeploymentHandler method getDeploymentConfig.

private IDeploymentConfig getDeploymentConfig(IPod pod, IResourceWrapper<?, ?> wrapper) {
    IDeploymentConfig dc = null;
    if (!ResourceUtils.isBuildPod(pod)) {
        IServiceWrapper service = ResourceWrapperUtils.getServiceWrapperFor(wrapper, serviceWrapper -> ResourceUtils.areRelated(pod, (IService) serviceWrapper.getWrapped()));
        dc = getDeploymentConfig(service);
    }
    return dc;
}
Also used : IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IService(com.openshift.restclient.model.IService)

Example 3 with IServiceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IServiceWrapper in project jbosstools-openshift by jbosstools.

the class ScaleDeploymentHandler method getDeploymentConfig.

private IDeploymentConfig getDeploymentConfig(IReplicationController rc, IResourceWrapper<?, ?> wrapper) {
    IDeploymentConfig dc = null;
    IServiceWrapper service = ResourceWrapperUtils.getServiceWrapperFor(wrapper, serviceWrapper -> ResourceUtils.areRelated(rc, (IService) serviceWrapper.getWrapped()));
    if (service != null) {
        dc = ResourceUtils.getDeploymentConfigFor(rc, ResourceWrapperUtils.getResources(service.getResourcesOfKind(ResourceKind.DEPLOYMENT_CONFIG)));
    }
    return dc;
}
Also used : IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IService(com.openshift.restclient.model.IService)

Example 4 with IServiceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IServiceWrapper 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 5 with IServiceWrapper

use of org.jboss.tools.openshift.internal.ui.models.IServiceWrapper 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)

Aggregations

IServiceWrapper (org.jboss.tools.openshift.internal.ui.models.IServiceWrapper)6 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)4 ISelection (org.eclipse.jface.viewers.ISelection)3 ResourceKind (com.openshift.restclient.ResourceKind)2 IProject (com.openshift.restclient.model.IProject)2 IReplicationController (com.openshift.restclient.model.IReplicationController)2 IService (com.openshift.restclient.model.IService)2 IRoute (com.openshift.restclient.model.route.IRoute)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AbstractHandler (org.eclipse.core.commands.AbstractHandler)2 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Dialog (org.eclipse.jface.dialogs.Dialog)2 NLS (org.eclipse.osgi.util.NLS)2 Shell (org.eclipse.swt.widgets.Shell)2 HandlerUtil (org.eclipse.ui.handlers.HandlerUtil)2