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);
}
}
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);
}
}
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);
}
}
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();
}
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<?>);
}
Aggregations