Skip to content

Commit

Permalink
blob; revert loading tabs based on tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlight220 committed Mar 29, 2023
1 parent bfbc54f commit 30f5025
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ private boolean previewSource(GridPoint point, Dragboard dragboard) {
}
SourceEntry entry = DeserializationHelper.sourceFromDrag(dragboard.getContent(DataFormats.source));
DataSource source = entry.get();
Optional<String> componentName = Components.getDefault().pickComponentNameFor(source.getDataType());
Optional<String> componentName = source.preferredWidget()
.or(() -> Components.getDefault().pickComponentNameFor(source.getDataType()));
Optional<DataSource<?>> dummySource = DummySource.forTypes(source.getDataType());
if (componentName.isPresent() && dummySource.isPresent()) {
if (tilePreviewSize == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.wpi.first.shuffleboard.plugin.networktables;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import edu.wpi.first.shuffleboard.api.sources.DataSource;
import edu.wpi.first.shuffleboard.api.sources.SourceTypes;
import edu.wpi.first.shuffleboard.api.tab.model.ComponentModel;
Expand Down Expand Up @@ -238,6 +238,9 @@ private void updateStructure(List<String> hierarchy) {
continue;
}
NetworkTable table = inst.getTable(path);
// if (table.getEntry(".widget").getType() == NetworkTableType.kString) {
// updateWidget(parent, path);
// } else
if (table.getKeys().contains(".type")) {
String type = table.getEntry(".type").getString(null);
switch (type) {
Expand Down Expand Up @@ -339,14 +342,27 @@ private Map<String, Object> properties(String realPath) {
props.put(k, propsTable.getEntry(k).getValue().getValue());
}
}
String metadata = inst.getTopic(realPath).getProperties();
JsonParser parser = new JsonParser();
var obj = parser.parse(metadata).getAsJsonObject();
obj.entrySet().forEach(entry -> {
System.out.println("TabGenerator.properties : " + entry);
props.put(entry.getKey(), entry.getValue().getAsString());
});

if (!inst.getTopic(realPath).exists()) {
var propsTable = inst.getTable(realPath);
for (String k : propsTable.getKeys()) {
props.put(k, propsTable.getEntry(k).getValue().getValue());
}
} else {
String metadata = inst.getTopic(realPath).getProperties();
JsonParser parser = new JsonParser();
var obj = parser.parse(metadata).getAsJsonObject();
obj.entrySet().forEach(entry -> {
System.out.println("TabGenerator.properties : " + entry);
JsonPrimitive primitive = entry.getValue().getAsJsonPrimitive();
if (primitive.isBoolean()) {
props.put(entry.getKey(), primitive.getAsBoolean());
} else if (primitive.isNumber()) {
props.put(entry.getKey(), primitive.getAsNumber());
} else {
props.put(entry.getKey(), primitive.getAsString());
}
});
}
return props;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.wpi.first.shuffleboard.plugin.networktables.sources;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import edu.wpi.first.networktables.NetworkTableEvent.Kind;
Expand Down Expand Up @@ -109,7 +110,12 @@ private static Optional<String> loadWidgetFromTopicProps(Topic topic) {
System.err.println(metadata);
JsonObject obj = parser.parse(metadata).getAsJsonObject();
obj.entrySet().forEach(System.err::println);
String widget = obj.get("widget").getAsString();
JsonElement widgetProp = obj.get("widget");
if (widgetProp == null || !widgetProp.isJsonPrimitive()) {
System.err.println("Metadata widget field for topic `" + topic.getName() + "` doesn't exist or is ");
return Optional.empty();
}
String widget = widgetProp.getAsString();
System.out.println("widget = " + widget);
return Optional.of(widget);
} catch (Exception e) {
Expand Down

0 comments on commit 30f5025

Please sign in to comment.