@@ -37,6 +37,7 @@ public class ApplicationsTreeStructure extends AbstractTreeStructure implements
37
37
private final ApplicationsRootNode root ;
38
38
39
39
private final MutableModel <Object > mutableModelSupport = new MutableModelSupport <>();
40
+ private DevfileRegistriesNode registries ;
40
41
41
42
private final AtomicBoolean initialized = new AtomicBoolean (false );
42
43
@@ -58,22 +59,39 @@ public class ApplicationsTreeStructure extends AbstractTreeStructure implements
58
59
private static final Icon URL_ICON = IconLoader .findIcon ("/images/url-node.png" , ApplicationsTreeStructure .class );
59
60
private static final Icon URL_SECURE_ICON = IconLoader .findIcon ("/images/url-node-secure.png" , ApplicationsTreeStructure .class );
60
61
62
+ private static final Icon COMPONENT_TYPE_ICON = IconLoader .findIcon ("/images/component-type-light.png" , ApplicationsTreeStructure .class );
63
+
64
+ private static final Icon STARTER_ICON = IconLoader .findIcon ("/images/start-project-light.png" , ApplicationsTreeStructure .class );
65
+
66
+ private static final Icon REGISTRY_ICON = IconLoader .findIcon ("/images/registry.svg" , ApplicationsTreeStructure .class );
67
+
61
68
public ApplicationsTreeStructure (Project project ) {
62
69
this .project = project ;
63
70
this .root = new ApplicationsRootNode (project , this );
71
+ this .registries = new DevfileRegistriesNode (root );
64
72
}
65
73
66
74
@ Override
67
75
public @ NotNull Object getRootElement () {
76
+ return this ;
77
+ }
78
+
79
+ public Object getApplicationsRoot () {
68
80
if (!initialized .getAndSet (true )) {
69
- root .initializeOdo ().thenAccept (tkn -> fireModified (root ));
81
+ root .initializeOdo ().thenAccept (odo -> {
82
+ fireModified (root );
83
+ fireModified (registries );
84
+ });
70
85
}
71
86
return root ;
72
87
}
73
88
74
89
@ NotNull
75
90
@ Override
76
91
public Object [] getChildElements (@ NotNull Object element ) {
92
+ if (element == this ) {
93
+ return new Object [] {getApplicationsRoot (), registries };
94
+ }
77
95
Odo odo = root .getOdo ();
78
96
if (odo != null ) {
79
97
if (element instanceof ApplicationsRootNode ) {
@@ -84,6 +102,12 @@ public Object[] getChildElements(@NotNull Object element) {
84
102
return getComponentsAndServices ((ApplicationNode ) element );
85
103
} else if (element instanceof ComponentNode ) {
86
104
return getStoragesAndURLs ((ComponentNode ) element );
105
+ } else if (element instanceof DevfileRegistriesNode ) {
106
+ return getRegistries (root , odo );
107
+ } else if (element instanceof DevfileRegistryNode ) {
108
+ return getRegistryComponentTypes ((DevfileRegistryNode ) element );
109
+ } else if (element instanceof DevfileRegistryComponentTypeNode ) {
110
+ return getRegistryComponentTypeStarters ((DevfileRegistryComponentTypeNode ) element );
87
111
}
88
112
}
89
113
return new Object [0 ];
@@ -164,19 +188,50 @@ private Object[] getStoragesAndURLs(ComponentNode element) {
164
188
return results .toArray ();
165
189
}
166
190
191
+ private Object [] getRegistries (ApplicationsRootNode root , Odo odo ) {
192
+ List <DevfileRegistryNode > result = new ArrayList <>();
193
+
194
+ try {
195
+ odo .listDevfileRegistries ().forEach (registry -> result .add (new DevfileRegistryNode (root , registries , registry )));
196
+ } catch (IOException e ) {}
197
+ return result .toArray ();
198
+ }
199
+
200
+ private Object [] getRegistryComponentTypes (DevfileRegistryNode element ) {
201
+ List <DevfileRegistryComponentTypeNode > result = new ArrayList <>();
202
+ try {
203
+ element .getRoot ().getOdo ().getComponentTypes (element .getName ()).forEach (type -> result .add (new DevfileRegistryComponentTypeNode (root , element , type )));
204
+ } catch (IOException e ) {}
205
+ return result .toArray ();
206
+ }
207
+
208
+ private Object [] getRegistryComponentTypeStarters (DevfileRegistryComponentTypeNode element ) {
209
+ List <DevfileRegistryComponentTypeStarterNode > result = new ArrayList <>();
210
+ try {
211
+ element .getRoot ().getOdo ().getComponentTypeInfo (element .getName ()).getStarters ().forEach (starter -> result .add (new DevfileRegistryComponentTypeStarterNode (element .getRoot (), element , starter )));
212
+ } catch (IOException e ) {}
213
+ return result .toArray ();
214
+ }
215
+
167
216
@ Override
168
217
public Object getParentElement (@ NotNull Object element ) {
169
218
if (element instanceof ParentableNode ) {
170
219
return ((ParentableNode ) element ).getParent ();
171
220
}
221
+ if (element instanceof ApplicationsRootNode ) {
222
+ return this ;
223
+ }
172
224
return null ;
173
225
}
174
226
175
227
@ Override
176
228
public NodeDescriptor createDescriptor (@ NotNull Object element , @ Nullable NodeDescriptor parentDescriptor ) {
177
- if (element instanceof ApplicationsRootNode ) {
178
- Odo odo = ((ApplicationsRootNode ) element ).getOdo ();
179
- return new LabelAndIconDescriptor (project , element , () -> odo != null ? odo .getMasterUrl ().toString () : "Loading" , CLUSTER_ICON ,
229
+ if (element == this ) {
230
+ return new LabelAndIconDescriptor (project , element , "Root" , null , parentDescriptor );
231
+ }
232
+ else if (element instanceof ApplicationsRootNode ) {
233
+ ApplicationsRootNode root = (ApplicationsRootNode ) element ;
234
+ return new LabelAndIconDescriptor (project , element , () -> root .getOdo () != null ?root .getOdo ().getMasterUrl ().toString ():"Loading" , CLUSTER_ICON ,
180
235
parentDescriptor );
181
236
} else if (element instanceof NamespaceNode ) {
182
237
return new LabelAndIconDescriptor (project , element , ((NamespaceNode ) element )::getName , NAMESPACE_ICON ,
@@ -198,11 +253,19 @@ public NodeDescriptor createDescriptor(@NotNull Object element, @Nullable NodeDe
198
253
URL url = ((URLNode ) element ).getUrl ();
199
254
return new LabelAndIconDescriptor (project , element ,
200
255
() -> url .getName () + " (" + url .getPort () + ") (" + url .getState () + ')' ,
201
- () -> url .isSecure () ? URL_SECURE_ICON : URL_ICON , parentDescriptor );
202
- } else if (element instanceof MessageNode <?>) {
203
- return new LabelAndIconDescriptor (project , element , ((MessageNode <?>) element ).getName (), null , parentDescriptor );
256
+ () -> url .isSecure ()?URL_SECURE_ICON :URL_ICON , parentDescriptor );
257
+ } else if (element instanceof MessageNode ) {
258
+ return new LabelAndIconDescriptor (project , element ,((MessageNode )element ).getName (), null , parentDescriptor );
259
+ } else if (element instanceof DevfileRegistriesNode ) {
260
+ return new LabelAndIconDescriptor (project , element , "Devfile registries" , REGISTRY_ICON , parentDescriptor );
261
+ } else if (element instanceof DevfileRegistryNode ) {
262
+ return new LabelAndIconDescriptor (project , element , ((DevfileRegistryNode )element ).getName (), ((DevfileRegistryNode )element ).getRegistry ().getURL (), REGISTRY_ICON , parentDescriptor );
263
+ } else if (element instanceof DevfileRegistryComponentTypeNode ) {
264
+ return new LabelAndIconDescriptor (project , element , ((DevfileRegistryComponentTypeNode )element ).getName (), ((DevfileRegistryComponentTypeNode )element ).getComponentType ().getDescription (), COMPONENT_TYPE_ICON , parentDescriptor );
265
+ } else if (element instanceof DevfileRegistryComponentTypeStarterNode ) {
266
+ return new LabelAndIconDescriptor (project , element , ((DevfileRegistryComponentTypeStarterNode )element ).getName (), ((DevfileRegistryComponentTypeStarterNode )element ).getStarter ().getDescription (), STARTER_ICON , parentDescriptor );
204
267
}
205
- return null ;
268
+ return new LabelAndIconDescriptor ( project , element , element . toString (), null , parentDescriptor ) ;
206
269
}
207
270
208
271
@ Override
0 commit comments