From 6b7332ee4c02ef586cfd416feb24c7ab01b93e14 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Fri, 2 Feb 2024 21:05:55 +0100 Subject: [PATCH] fix: show 'no url/binding' node, use async leafstate for component (#687) Signed-off-by: Andre Dietisheim --- .../ApplicationsTreeStructure.java | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java b/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java index 41256c35a..85a02dcce 100644 --- a/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java +++ b/src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java @@ -94,9 +94,7 @@ public Object getApplicationsRoot() { @Override public @NotNull LeafState getLeafState(@NotNull Object element) { - if (element instanceof ComponentNode) { - return LeafState.ALWAYS; - } else if (element instanceof ChartReleaseNode) { + if (element instanceof ChartReleaseNode) { return LeafState.ALWAYS; } else if (element instanceof MessageNode) { return LeafState.ALWAYS; @@ -111,8 +109,8 @@ private Object[] createComponentChildren(ComponentNode componentNode) { if (odo == null) { return new Object[] { new MessageNode<>(root, componentNode, "Could not get components") }; } - List urls = getURLs(componentNode); - List bindings = getBindings(componentNode, odo); + List> urls = getURLs(componentNode, odo); + List> bindings = getBindings(componentNode, odo); return Stream.of(urls, bindings) .filter(item -> !item.isEmpty()) .flatMap(Collection::stream) @@ -221,34 +219,47 @@ private List> load(Callable>> callable, NamespaceNo return Collections.singletonList(new MessageNode<>(namespace.getRoot(), namespace, errorMessage)); } } - private List getURLs(ComponentNode element) { - List results = new ArrayList<>(); - Odo odo = element.getRoot().getOdo().getNow(null); - if (odo == null) { - return Collections.emptyList(); - } + + private List> getURLs(ComponentNode componentNode, @NotNull Odo odo) { + List> nodes = new ArrayList<>(); try { - odo.listURLs(element.getParent().getName(), - element.getComponent().getPath(), element.getName()).forEach(url -> - results.add(new URLNode(element, url)) - ); + List urls = odo.listURLs( + componentNode.getParent().getName(), + componentNode.getComponent().getPath(), + componentNode.getName()) + .stream() + .map(url -> new URLNode(componentNode, url)) + .collect(Collectors.toList()); + if (!urls.isEmpty()) { + nodes.addAll(urls); + } else { + nodes.add(new MessageNode<>(root, componentNode, "")); + } } catch (IOException e) { LOGGER.warn(e.getLocalizedMessage(), e); } - return results; + return nodes; } - private List getBindings(ComponentNode element, @NotNull Odo odo) { - List results = new ArrayList<>(); + private List> getBindings(ComponentNode componentNode, @NotNull Odo odo) { + List> nodes = new ArrayList<>(); try { - odo.listBindings(element.getParent().getName(), - element.getComponent().getPath(), element.getName()).forEach(binding -> - results.add(new BindingNode(element, binding)) - ); + List bindings = odo.listBindings( + componentNode.getParent().getName(), + componentNode.getComponent().getPath(), + componentNode.getName()) + .stream() + .map(binding -> new BindingNode(componentNode, binding)) + .collect(Collectors.toList()); + if (!bindings.isEmpty()) { + nodes.addAll(bindings); + } else { + nodes.add(new MessageNode<>(root, componentNode, "")); + } } catch (IOException e) { LOGGER.warn(e.getLocalizedMessage(), e); } - return results; + return nodes; } private Object[] getRegistries(ApplicationsRootNode root) { @@ -318,6 +329,11 @@ public Object getParentElement(@NotNull Object element) { public void commit() { } + @Override + public boolean isToBuildChildrenInBackground(@NotNull Object element) { + return true; + } + @Override public boolean hasSomethingToCommit() { return false;