1
1
package edu .wpi .first .shuffleboard .plugin .networktables ;
2
2
3
- import com .google .gson .JsonObject ;
4
3
import com .google .gson .JsonParser ;
4
+ import com .google .gson .JsonPrimitive ;
5
5
import edu .wpi .first .shuffleboard .api .sources .DataSource ;
6
6
import edu .wpi .first .shuffleboard .api .sources .SourceTypes ;
7
7
import edu .wpi .first .shuffleboard .api .tab .model .ComponentModel ;
40
40
@ SuppressWarnings ("PMD.GodClass" )
41
41
final class TabGenerator {
42
42
43
- public static final String ROOT_TABLE_NAME = "/Shuffleboard " ;
44
- public static final String METADATA_TABLE_NAME = ROOT_TABLE_NAME + "/.metadata" ;
43
+ public static final String ROOT_TABLE_NAME = "" ;
44
+ public static final String METADATA_TABLE_NAME = ROOT_TABLE_NAME + "/Shuffleboard/ .metadata" ;
45
45
public static final String PREF_COMPONENT_ENTRY_NAME = "PreferredComponent" ;
46
46
public static final String PROPERTIES_TABLE_NAME = "Properties" ;
47
47
public static final String TABS_ENTRY_KEY = "Tabs" ;
@@ -198,16 +198,16 @@ private void dataChanged(NetworkTableEvent event) {
198
198
return ;
199
199
}
200
200
List <String > hierarchy = NetworkTable .getHierarchy (name );
201
- if (hierarchy .size () < 3 ) {
202
- // Not enough data
203
- return ;
204
- }
201
+ // if (hierarchy.size() < 3) {
202
+ // // Not enough data
203
+ // return;
204
+ // }
205
205
if (name .contains ("/." )) {
206
206
// The entry is metadata, but may be the only entry in a table, so make sure it's updated correctly
207
207
var tables = hierarchy .stream ()
208
208
.takeWhile (s -> !s .contains ("/." ))
209
209
.collect (Collectors .toList ());
210
- if (tables .size () >= 3 ) {
210
+ if (tables .size () >= 2 ) {
211
211
updateFrom (tables );
212
212
}
213
213
return ;
@@ -222,7 +222,13 @@ private void updateFrom(List<String> tables) {
222
222
223
223
private void updateStructure (List <String > hierarchy ) {
224
224
// 0='/', 1='/Shuffleboard', 2='/Shuffleboard/<Tab>'
225
- TabModel tab = tabs .getTab (NetworkTable .basenameKey (hierarchy .get (2 )));
225
+ String tabName ;
226
+ if (hierarchy .get (1 ).equals ("/Shuffleboard" )) {
227
+ tabName = NetworkTable .basenameKey (hierarchy .get (2 ));
228
+ } else {
229
+ tabName = NetworkTable .basenameKey (hierarchy .get (1 ));
230
+ }
231
+ TabModel tab = tabs .getTab (tabName );
226
232
ParentModel parent = tab ;
227
233
int index = 0 ;
228
234
boolean end = false ;
@@ -233,6 +239,9 @@ private void updateStructure(List<String> hierarchy) {
233
239
continue ;
234
240
}
235
241
NetworkTable table = inst .getTable (path );
242
+ // if (table.getEntry(".widget").getType() == NetworkTableType.kString) {
243
+ // updateWidget(parent, path);
244
+ // } else
236
245
if (table .getKeys ().contains (".type" )) {
237
246
String type = table .getEntry (".type" ).getString (null );
238
247
switch (type ) {
@@ -334,14 +343,27 @@ private Map<String, Object> properties(String realPath) {
334
343
props .put (k , propsTable .getEntry (k ).getValue ().getValue ());
335
344
}
336
345
}
337
- String metadata = inst .getTopic (realPath ).getProperties ();
338
- JsonParser parser = new JsonParser ();
339
- var obj = parser .parse (metadata ).getAsJsonObject ();
340
- obj .entrySet ().forEach (entry -> {
341
- System .out .println ("TabGenerator.properties : " + entry );
342
- props .put (entry .getKey (), entry .getValue ().getAsString ());
343
- });
344
-
346
+ if (!inst .getTopic (realPath ).exists ()) {
347
+ var propsTable = inst .getTable (realPath );
348
+ for (String k : propsTable .getKeys ()) {
349
+ props .put (k , propsTable .getEntry (k ).getValue ().getValue ());
350
+ }
351
+ } else {
352
+ String metadata = inst .getTopic (realPath ).getProperties ();
353
+ JsonParser parser = new JsonParser ();
354
+ var obj = parser .parse (metadata ).getAsJsonObject ();
355
+ obj .entrySet ().forEach (entry -> {
356
+ System .out .println ("TabGenerator.properties : " + entry );
357
+ JsonPrimitive primitive = entry .getValue ().getAsJsonPrimitive ();
358
+ if (primitive .isBoolean ()) {
359
+ props .put (entry .getKey (), primitive .getAsBoolean ());
360
+ } else if (primitive .isNumber ()) {
361
+ props .put (entry .getKey (), primitive .getAsNumber ());
362
+ } else {
363
+ props .put (entry .getKey (), primitive .getAsString ());
364
+ }
365
+ });
366
+ }
345
367
return props ;
346
368
}
347
369
0 commit comments