11package  edu .wpi .first .shuffleboard .plugin .networktables ;
22
3- import  com .google .gson .JsonObject ;
43import  com .google .gson .JsonParser ;
4+ import  com .google .gson .JsonPrimitive ;
55import  edu .wpi .first .shuffleboard .api .sources .DataSource ;
66import  edu .wpi .first .shuffleboard .api .sources .SourceTypes ;
77import  edu .wpi .first .shuffleboard .api .tab .model .ComponentModel ;
4040@ SuppressWarnings ("PMD.GodClass" )
4141final  class  TabGenerator  {
4242
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" ;
4545  public  static  final  String  PREF_COMPONENT_ENTRY_NAME  = "PreferredComponent" ;
4646  public  static  final  String  PROPERTIES_TABLE_NAME  = "Properties" ;
4747  public  static  final  String  TABS_ENTRY_KEY  = "Tabs" ;
@@ -172,8 +172,8 @@ private void metadataChanged(NetworkTableEvent event) {
172172      String  propsTableName  = metaHierarchy .get (metaHierarchy .size () - 2 );
173173      NetworkTable  propsTable  = inst .getTable (propsTableName );
174174      Map <String , Object > properties  = propsTable .getKeys ()
175-         .stream ()
176-         .collect (Collectors .toMap (t  -> t , k  -> propsTable .getEntry (k ).getValue ().getValue ()));
175+            .stream ()
176+            .collect (Collectors .toMap (t  -> t , k  -> propsTable .getEntry (k ).getValue ().getValue ()));
177177      if  (NetworkTable .basenameKey (real ).equals (tab .getTitle ())) {
178178        tab .setProperties (properties );
179179      } else  {
@@ -198,16 +198,16 @@ private void dataChanged(NetworkTableEvent event) {
198198      return ;
199199    }
200200    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+ //     }
205205    if  (name .contains ("/." )) {
206206      // The entry is metadata, but may be the only entry in a table, so make sure it's updated correctly 
207207      var  tables  = hierarchy .stream ()
208208          .takeWhile (s  -> !s .contains ("/." ))
209209          .collect (Collectors .toList ());
210-       if  (tables .size () >= 3 ) {
210+       if  (tables .size () >= 2 ) {
211211        updateFrom (tables );
212212      }
213213      return ;
@@ -222,7 +222,13 @@ private void updateFrom(List<String> tables) {
222222
223223  private  void  updateStructure (List <String > hierarchy ) {
224224    // 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 );
226232    ParentModel  parent  = tab ;
227233    int  index  = 0 ;
228234    boolean  end  = false ;
@@ -233,6 +239,9 @@ private void updateStructure(List<String> hierarchy) {
233239        continue ;
234240      }
235241      NetworkTable  table  = inst .getTable (path );
242+ //      if (table.getEntry(".widget").getType() == NetworkTableType.kString) { 
243+ //        updateWidget(parent, path); 
244+ //      } else 
236245      if  (table .getKeys ().contains (".type" )) {
237246        String  type  = table .getEntry (".type" ).getString (null );
238247        switch  (type ) {
@@ -334,14 +343,27 @@ private Map<String, Object> properties(String realPath) {
334343        props .put (k , propsTable .getEntry (k ).getValue ().getValue ());
335344      }
336345    }
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+     }
345367    return  props ;
346368  }
347369
0 commit comments