Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 9fb4c13

Browse files
committed
fix: show 'no url/binding' node, use async leafstate for component (#687)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 3aaa623 commit 9fb4c13

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

src/main/java/org/jboss/tools/intellij/openshift/tree/application/ApplicationsTreeStructure.java

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ public Object getApplicationsRoot() {
9595

9696
@Override
9797
public @NotNull LeafState getLeafState(@NotNull Object element) {
98-
if (element instanceof ComponentNode) {
99-
return LeafState.ALWAYS;
100-
} else if (element instanceof ChartReleaseNode) {
98+
if (element instanceof ChartReleaseNode) {
10199
return LeafState.ALWAYS;
102100
} else if (element instanceof MessageNode<?>) {
103101
return LeafState.ALWAYS;
@@ -112,8 +110,8 @@ private Object[] createComponentChildren(ComponentNode componentNode) {
112110
if (odo == null) {
113111
return new Object[] { new MessageNode<>(root, componentNode, "Could not get components") };
114112
}
115-
List<URLNode> urls = getURLs(componentNode);
116-
List<BindingNode> bindings = getBindings(componentNode, odo);
113+
List<BaseNode<ComponentNode>> urls = getURLs(componentNode, odo);
114+
List<BaseNode<ComponentNode>> bindings = getBindings(componentNode, odo);
117115
return Stream.of(urls, bindings)
118116
.filter(item -> !item.isEmpty())
119117
.flatMap(Collection::stream)
@@ -226,34 +224,47 @@ private List<BaseNode<?>> load(Callable<List<BaseNode<?>>> callable, NamespaceNo
226224
return Collections.singletonList(new MessageNode<>(namespace.getRoot(), namespace, errorMessage));
227225
}
228226
}
229-
private List<URLNode> getURLs(ComponentNode element) {
230-
List<URLNode> results = new ArrayList<>();
231-
Odo odo = element.getRoot().getOdo().getNow(null);
232-
if (odo == null) {
233-
return Collections.emptyList();
234-
}
227+
228+
private List<BaseNode<ComponentNode>> getURLs(ComponentNode componentNode, @NotNull Odo odo) {
229+
List<BaseNode<ComponentNode>> nodes = new ArrayList<>();
235230
try {
236-
odo.listURLs(element.getParent().getName(),
237-
element.getComponent().getPath(), element.getName()).forEach(url ->
238-
results.add(new URLNode(element, url))
239-
);
231+
List<URLNode> urls = odo.listURLs(
232+
componentNode.getParent().getName(),
233+
componentNode.getComponent().getPath(),
234+
componentNode.getName())
235+
.stream()
236+
.map(url -> new URLNode(componentNode, url))
237+
.collect(Collectors.toList());
238+
if (!urls.isEmpty()) {
239+
nodes.addAll(urls);
240+
} else {
241+
nodes.add(new MessageNode<>(root, componentNode, "<No URLS>"));
242+
}
240243
} catch (IOException e) {
241244
LOGGER.warn(e.getLocalizedMessage(), e);
242245
}
243-
return results;
246+
return nodes;
244247
}
245248

246-
private List<BindingNode> getBindings(ComponentNode element, @NotNull Odo odo) {
247-
List<BindingNode> results = new ArrayList<>();
249+
private List<BaseNode<ComponentNode>> getBindings(ComponentNode componentNode, @NotNull Odo odo) {
250+
List<BaseNode<ComponentNode>> nodes = new ArrayList<>();
248251
try {
249-
odo.listBindings(element.getParent().getName(),
250-
element.getComponent().getPath(), element.getName()).forEach(binding ->
251-
results.add(new BindingNode(element, binding))
252-
);
252+
List<BindingNode> bindings = odo.listBindings(
253+
componentNode.getParent().getName(),
254+
componentNode.getComponent().getPath(),
255+
componentNode.getName())
256+
.stream()
257+
.map(binding -> new BindingNode(componentNode, binding))
258+
.collect(Collectors.toList());
259+
if (!bindings.isEmpty()) {
260+
nodes.addAll(bindings);
261+
} else {
262+
nodes.add(new MessageNode<>(root, componentNode, "<No Bindings>"));
263+
}
253264
} catch (IOException e) {
254265
LOGGER.warn(e.getLocalizedMessage(), e);
255266
}
256-
return results;
267+
return nodes;
257268
}
258269

259270
private Object[] getRegistries(ApplicationsRootNode root) {
@@ -323,6 +334,11 @@ public Object getParentElement(@NotNull Object element) {
323334
public void commit() {
324335
}
325336

337+
@Override
338+
public boolean isToBuildChildrenInBackground(@NotNull Object element) {
339+
return true;
340+
}
341+
326342
@Override
327343
public boolean hasSomethingToCommit() {
328344
return false;

0 commit comments

Comments
 (0)