Search in sources :

Example 6 with ApplicationExplorerUIModel

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

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

the class OpenShiftApplicationExplorerContentProvider method getChildren.

private Object[] getChildren(ComponentElement parentElement) {
    try {
        List<Object> childs = new ArrayList<>();
        ApplicationElement application = parentElement.getParent();
        ProjectElement project = application.getParent();
        ApplicationExplorerUIModel cluster = project.getParent();
        cluster.getOdo().getStorages(project.getWrapped(), application.getWrapped().getName(), parentElement.getWrapped().getPath(), parentElement.getWrapped().getName()).forEach(storage -> childs.add(new StorageElement(storage, parentElement)));
        cluster.getOdo().listURLs(project.getWrapped(), application.getWrapped().getName(), parentElement.getWrapped().getPath(), parentElement.getWrapped().getName()).forEach(url -> childs.add(new URLElement(url, parentElement)));
        return childs.toArray();
    } catch (IOException e) {
        return new Object[] { "Can't list storages or urls" };
    }
}
Also used : ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ApplicationExplorerUIModel(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel) StorageElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.StorageElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URLElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.URLElement)

Example 8 with ApplicationExplorerUIModel

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

the class DeleteHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    AbstractOpenshiftUIElement<?, ?, ?> element = UIUtils.getFirstElement(selection, AbstractOpenshiftUIElement.class);
    if (element == null) {
        return OpenShiftUIActivator.statusFactory().cancelStatus(// $NON-NLS-1$
        "No element selected");
    }
    try {
        String label = getLabel(element);
        if (MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), String.join(" ", "Delete", label), String.join(" ", "Are you sure to delete", label, "?"))) {
            Odo odo = ((ApplicationExplorerUIModel) element.getRoot()).getOdo();
            executeInJob("Delete", monitor -> execute(odo, element));
        }
        return Status.OK_STATUS;
    } catch (IOException e) {
        return OpenShiftUIActivator.statusFactory().errorStatus(e);
    }
}
Also used : ApplicationExplorerUIModel(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel) ISelection(org.eclipse.jface.viewers.ISelection) Odo(org.jboss.tools.openshift.core.odo.Odo) IOException(java.io.IOException)

Example 9 with ApplicationExplorerUIModel

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

the class LoginHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    ApplicationExplorerUIModel cluster = UIUtils.getFirstElement(selection, ApplicationExplorerUIModel.class);
    if (cluster == null) {
        // $NON-NLS-1$
        return OpenShiftUIActivator.statusFactory().cancelStatus("No cluster selected");
    }
    try {
        openDialog(HandlerUtil.getActiveShell(event), cluster);
        return Status.OK_STATUS;
    } catch (IOException e) {
        throw new ExecutionException(e.getLocalizedMessage(), e);
    }
}
Also used : ApplicationExplorerUIModel(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel) ISelection(org.eclipse.jface.viewers.ISelection) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 10 with ApplicationExplorerUIModel

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

the class OpenShiftApplicationExplorerContentProviderTest method setup.

@Before
public void setup() throws Exception {
    odo = mock(Odo.class);
    ClusterClient info = mock(ClusterClient.class);
    doReturn(odo).when(info).getOdo();
    OdoCliFactory factory = mock(OdoCliFactory.class);
    doReturn(CompletableFuture.completedFuture(odo)).when(factory).getOdo();
    this.model = new ApplicationExplorerUIModel(info) {

        @Override
        protected OdoCliFactory getFactory() {
            return factory;
        }
    };
    this.provider = new OpenShiftApplicationExplorerContentProvider(model) {
    };
}
Also used : ClusterClient(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel.ClusterClient) ApplicationExplorerUIModel(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel) OdoCliFactory(org.jboss.tools.openshift.internal.ui.odo.OdoCliFactory) OpenShiftApplicationExplorerContentProvider(org.jboss.tools.openshift.internal.ui.applicationexplorer.OpenShiftApplicationExplorerContentProvider) Odo(org.jboss.tools.openshift.core.odo.Odo) Before(org.junit.Before)

Aggregations

ApplicationExplorerUIModel (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel)12 IOException (java.io.IOException)8 ISelection (org.eclipse.jface.viewers.ISelection)8 ExecutionException (org.eclipse.core.commands.ExecutionException)5 Odo (org.jboss.tools.openshift.core.odo.Odo)3 ArrayList (java.util.ArrayList)2 Shell (org.eclipse.swt.widgets.Shell)2 ApplicationElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement)2 ProjectElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 IProject (org.eclipse.core.resources.IProject)1 IWizard (org.eclipse.jface.wizard.IWizard)1 BrowserUtility (org.jboss.tools.foundation.ui.util.BrowserUtility)1 OpenShiftApplicationExplorerContentProvider (org.jboss.tools.openshift.internal.ui.applicationexplorer.OpenShiftApplicationExplorerContentProvider)1 ClusterClient (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationExplorerUIModel.ClusterClient)1 ComponentElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ComponentElement)1 ServiceElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ServiceElement)1 StorageElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.StorageElement)1 URLElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.URLElement)1 OdoCliFactory (org.jboss.tools.openshift.internal.ui.odo.OdoCliFactory)1