Search in sources :

Example 1 with ComponentElement

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

the class ComponentStatePropertyTester method test.

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    receiver = getComponentElement(receiver);
    if (!(receiver instanceof ComponentElement) || !(expectedValue instanceof Boolean) || args == null || args.length != 1 || !(args[0] instanceof String)) {
        return false;
    }
    ComponentElement component = (ComponentElement) receiver;
    switch(component.getWrapped().getState()) {
        case PUSHED:
            return expectedValue.equals(args[0].equals(VALUE_PUSHED));
        case NOT_PUSHED:
            return expectedValue.equals(args[0].equals(VALUE_NOT_PUSHED));
        case NO_CONTEXT:
            return expectedValue.equals(args[0].equals(VALUE_NO_CONTEXT));
    }
    return false;
}
Also used : ComponentElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement)

Example 2 with ComponentElement

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

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

the class LinkComponentHandler method execute.

@Override
public Object execute(ComponentElement component, Shell shell) throws ExecutionException {
    try {
        Odo odo = component.getRoot().getOdo();
        String projectName = component.getParent().getParent().getWrapped();
        String applicationName = component.getParent().getWrapped().getName();
        List<Component> targetComponents = odo.getComponents(projectName, applicationName).stream().filter(comp -> !comp.getName().equals(component.getWrapped().getName())).collect(Collectors.toList());
        if (targetComponents.isEmpty()) {
            MessageDialog.openError(shell, "Link component", "No component available to link to.");
        } else {
            final LinkModel<Component> model = new LinkModel<>(odo, projectName, applicationName, component.getWrapped().getName(), targetComponents);
            final IWizard linkComponentWizard = new LinkComponentWizard(model);
            if (WizardUtils.openWizardDialog(linkComponentWizard, shell) == Window.OK) {
                executeInJob("Link component", monitor -> execute(shell, model, component));
            }
        }
        return Status.OK_STATUS;
    } catch (IOException e) {
        return OpenShiftUIActivator.statusFactory().errorStatus(e);
    }
}
Also used : Component(org.jboss.tools.openshift.core.odo.Component) Shell(org.eclipse.swt.widgets.Shell) LinkComponentWizard(org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.LinkComponentWizard) IWizard(org.eclipse.jface.wizard.IWizard) Status(org.eclipse.core.runtime.Status) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Odo(org.jboss.tools.openshift.core.odo.Odo) Collectors(java.util.stream.Collectors) List(java.util.List) Window(org.eclipse.jface.window.Window) WizardUtils(org.jboss.tools.common.ui.WizardUtils) LinkModel(org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.LinkModel) ComponentElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement) LabelNotification(org.jboss.tools.common.ui.notification.LabelNotification) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) LinkComponentWizard(org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.LinkComponentWizard) IWizard(org.eclipse.jface.wizard.IWizard) Odo(org.jboss.tools.openshift.core.odo.Odo) IOException(java.io.IOException) Component(org.jboss.tools.openshift.core.odo.Component) LinkModel(org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.LinkModel)

Example 4 with ComponentElement

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

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

the class ComponentHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    ComponentElement component = UIUtils.getFirstElement(selection, ComponentElement.class);
    if (component == null) {
        // $NON-NLS-1$
        return OpenShiftUIActivator.statusFactory().cancelStatus("No component selected");
    }
    return execute(component, HandlerUtil.getActiveShell(event));
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ComponentElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement)

Aggregations

ComponentElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement)6 IOException (java.io.IOException)4 ApplicationElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement)3 ServiceElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement)3 ISelection (org.eclipse.jface.viewers.ISelection)2 Odo (org.jboss.tools.openshift.core.odo.Odo)2 ProjectElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Status (org.eclipse.core.runtime.Status)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 Window (org.eclipse.jface.window.Window)1 IWizard (org.eclipse.jface.wizard.IWizard)1 Shell (org.eclipse.swt.widgets.Shell)1 WizardUtils (org.jboss.tools.common.ui.WizardUtils)1 LabelNotification (org.jboss.tools.common.ui.notification.LabelNotification)1 Component (org.jboss.tools.openshift.core.odo.Component)1