Search in sources :

Example 1 with ApplicationElement

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

the class CreateComponentHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    ApplicationElement application = null;
    ProjectElement project = UIUtils.getFirstElement(selection, ProjectElement.class);
    DevfileRegistryComponentTypeElement componentType = null;
    if (project == null) {
        application = UIUtils.getFirstElement(selection, ApplicationElement.class);
        if (application == null) {
            componentType = UIUtils.getFirstElement(selection, DevfileRegistryComponentTypeElement.class);
            if (componentType == null) {
                DevfileRegistryComponentTypeStarterElement starter = UIUtils.getFirstElement(selection, DevfileRegistryComponentTypeStarterElement.class);
                if (starter == null) {
                    // $NON-NLS-1$
                    return OpenShiftUIActivator.statusFactory().cancelStatus("No project or application selected");
                } else {
                    componentType = starter.getParent();
                }
            }
        } else {
            project = application.getParent();
        }
    }
    final Shell parent = HandlerUtil.getActiveShell(event);
    try {
        openDialog(componentType, application, project, parent);
        return Status.OK_STATUS;
    } catch (IOException e) {
        return OpenShiftUIActivator.statusFactory().errorStatus(e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) DevfileRegistryComponentTypeElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryComponentTypeElement) DevfileRegistryComponentTypeStarterElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryComponentTypeStarterElement) ISelection(org.eclipse.jface.viewers.ISelection) IOException(java.io.IOException)

Example 2 with ApplicationElement

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

the class CreateServiceHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    ApplicationElement application = null;
    ProjectElement project = UIUtils.getFirstElement(selection, ProjectElement.class);
    if (project == null) {
        application = UIUtils.getFirstElement(selection, ApplicationElement.class);
        if (application == null) {
            // $NON-NLS-1$
            return OpenShiftUIActivator.statusFactory().cancelStatus("No project or application selected");
        }
        project = application.getParent();
    }
    try {
        Odo odo = project.getParent().getOdo();
        List<ServiceTemplate> templates = odo.getServiceTemplates();
        if (!templates.isEmpty()) {
            final IWizard createServiceWizard = new CreateServiceWizard(templates, project.getWrapped(), application == null ? "" : application.getWrapped().getName(), odo);
            if (WizardUtils.openWizardDialog(createServiceWizard, HandlerUtil.getActiveShell(event)) == Window.OK) {
                if (application == null) {
                    project.refresh();
                } else {
                    application.refresh();
                }
            }
        } else {
            MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Create service", "No operators installed on your cluster, can't create services");
        }
        return Status.OK_STATUS;
    } catch (IOException e) {
        String title = "Unable to create service";
        String message = e.getMessage();
        MessageDialog.open(MessageDialog.ERROR, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message, SWT.NONE);
        return OpenShiftUIActivator.statusFactory().errorStatus(e);
    }
}
Also used : ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) ServiceTemplate(org.jboss.tools.openshift.core.odo.ServiceTemplate) ISelection(org.eclipse.jface.viewers.ISelection) IWizard(org.eclipse.jface.wizard.IWizard) Odo(org.jboss.tools.openshift.core.odo.Odo) IOException(java.io.IOException) CreateServiceWizard(org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.CreateServiceWizard)

Example 3 with ApplicationElement

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

the class DescribeHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    ComponentElement component = UIUtils.getFirstElement(selection, ComponentElement.class);
    ServiceElement service = null;
    ApplicationElement application = null;
    if (component == null) {
        service = UIUtils.getFirstElement(selection, ServiceElement.class);
        if (service == null) {
            application = UIUtils.getFirstElement(selection, ApplicationElement.class);
            if (application == null) {
                return OpenShiftUIActivator.statusFactory().cancelStatus(// $NON-NLS-1$
                "No application, component or service selected");
            }
        }
    }
    try {
        Odo odo = component != null ? component.getRoot().getOdo() : service != null ? service.getRoot().getOdo() : application.getRoot().getOdo();
        final ServiceElement fService = service;
        final ApplicationElement fApplication = application;
        executeInJob("Describe", monitor -> execute(odo, component, fService, fApplication));
        return Status.OK_STATUS;
    } catch (IOException e) {
        return OpenShiftUIActivator.statusFactory().errorStatus(e);
    }
}
Also used : ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ISelection(org.eclipse.jface.viewers.ISelection) Odo(org.jboss.tools.openshift.core.odo.Odo) IOException(java.io.IOException) ComponentElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement) ServiceElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement)

Example 4 with ApplicationElement

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

the class OpenShiftApplicationExplorerContentProvider method getChildren.

private Object[] getChildren(ApplicationElement parentElement) {
    List<Object> childs = new ArrayList<>();
    try {
        ProjectElement project = parentElement.getParent();
        ApplicationExplorerUIModel cluster = project.getParent();
        cluster.getOdo().getComponents(project.getWrapped(), parentElement.getWrapped().getName()).forEach(comp -> childs.add(new ComponentElement(comp, parentElement)));
        cluster.getOdo().getServices(project.getWrapped(), parentElement.getWrapped().getName()).forEach(service -> childs.add(new ServiceElement(service, parentElement)));
    } catch (IOException | KubernetesClientException e) {
        if (childs.isEmpty()) {
            return new Object[] { "Can't list components" };
        }
    }
    if (childs.isEmpty()) {
        childs.add(new CreateComponentMessageElement<ApplicationElement>(parentElement));
    }
    return childs.toArray();
}
Also used : ApplicationExplorerUIModel(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel) ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ComponentElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement) ServiceElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 5 with ApplicationElement

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

the class OpenShiftApplicationExplorerContentProviderTest method checkClusterWithSingleProjectAndSingleAppReturnsLinkToCreateComponent.

@Test
public void checkClusterWithSingleProjectAndSingleAppReturnsLinkToCreateComponent() throws InterruptedException, TimeoutException, IOException {
    mockProject("myproject");
    Application app = mock(Application.class);
    doReturn(Collections.singletonList(app)).when(odo).getApplications(eq("myproject"));
    Object[] childs = provider.getChildren(model);
    assertEquals(1, childs.length);
    Object element = childs[0];
    assertTrue(element instanceof ProjectElement);
    childs = provider.getChildren(element);
    assertEquals(1, childs.length);
    element = childs[0];
    assertTrue(element instanceof ApplicationElement);
    childs = provider.getChildren(element);
    assertEquals(1, childs.length);
    element = childs[0];
    assertTrue(element instanceof CreateComponentMessageElement<?>);
}
Also used : ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) Application(org.jboss.tools.openshift.core.odo.Application) Test(org.junit.Test)

Aggregations

ApplicationElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement)7 IOException (java.io.IOException)6 ProjectElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement)6 ISelection (org.eclipse.jface.viewers.ISelection)3 ComponentElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement)3 ServiceElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement)3 ArrayList (java.util.ArrayList)2 Odo (org.jboss.tools.openshift.core.odo.Odo)2 ApplicationExplorerUIModel (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel)2 StorageElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.StorageElement)2 URLElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.URLElement)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 IWizard (org.eclipse.jface.wizard.IWizard)1 Shell (org.eclipse.swt.widgets.Shell)1 Application (org.jboss.tools.openshift.core.odo.Application)1 ServiceTemplate (org.jboss.tools.openshift.core.odo.ServiceTemplate)1 DevfileRegistryComponentTypeElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryComponentTypeElement)1 DevfileRegistryComponentTypeStarterElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryComponentTypeStarterElement)1 DevfileRegistryElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryElement)1 CreateServiceWizard (org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.CreateServiceWizard)1