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