Search in sources :

Example 1 with ServiceElement

use of org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement 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 2 with ServiceElement

use of org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement 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 3 with ServiceElement

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

the class DeleteHandler method execute.

private void execute(Odo odo, AbstractOpenshiftUIElement<?, ?, ?> element) {
    try {
        if (element instanceof ProjectElement) {
            odo.deleteProject(((ProjectElement) element).getWrapped());
        } else if (element instanceof ApplicationElement) {
            odo.deleteApplication(((ApplicationElement) element).getParent().getWrapped(), ((ApplicationElement) element).getWrapped().getName());
        } else if (element instanceof ComponentElement) {
            ComponentElement component = (ComponentElement) element;
            odo.deleteComponent(component.getParent().getParent().getWrapped(), component.getParent().getWrapped().getName(), component.getWrapped().getPath(), component.getWrapped().getName(), component.getWrapped().getInfo().getComponentKind());
            if (component.getWrapped().hasContext()) {
                component.getRoot().removeContext(component.getWrapped().getPath());
            }
        } else if (element instanceof ServiceElement) {
            odo.deleteService(((ServiceElement) element).getParent().getParent().getWrapped(), ((ServiceElement) element).getParent().getWrapped().getName(), ((ServiceElement) element).getWrapped());
        } else if (element instanceof URLElement) {
            odo.deleteURL(((URLElement) element).getParent().getParent().getParent().getWrapped(), ((URLElement) element).getParent().getParent().getWrapped().getName(), ((URLElement) element).getParent().getWrapped().getPath(), ((URLElement) element).getParent().getWrapped().getName(), ((URLElement) element).getWrapped().getName());
        } else if (element instanceof StorageElement) {
            odo.deleteStorage(((StorageElement) element).getParent().getParent().getParent().getWrapped(), ((StorageElement) element).getParent().getParent().getWrapped().getName(), ((StorageElement) element).getParent().getWrapped().getPath(), ((StorageElement) element).getParent().getWrapped().getName(), ((StorageElement) element).getWrapped().getName());
        } else if (element instanceof DevfileRegistryElement) {
            odo.deleteDevfileRegistry(((DevfileRegistryElement) element).getWrapped().getName());
        }
        element.getParent().refresh();
    } catch (IOException e) {
        Display.getDefault().asyncExec(() -> MessageDialog.openError(Display.getDefault().getActiveShell(), "Delete", "Delete error:" + e.getLocalizedMessage()));
    }
}
Also used : DevfileRegistryElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryElement) ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) StorageElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.StorageElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) IOException(java.io.IOException) ComponentElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement) URLElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.URLElement) ServiceElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement)

Aggregations

IOException (java.io.IOException)3 ApplicationElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement)3 ComponentElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement)3 ServiceElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement)3 ProjectElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 ArrayList (java.util.ArrayList)1 ISelection (org.eclipse.jface.viewers.ISelection)1 Odo (org.jboss.tools.openshift.core.odo.Odo)1 ApplicationExplorerUIModel (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel)1 DevfileRegistryElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.DevfileRegistryElement)1 StorageElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.StorageElement)1 URLElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.URLElement)1