Skip to content

Commit

Permalink
blob
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlight220 committed Feb 20, 2023
1 parent f658ed8 commit c6c75e9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ default WidgetModel getOrCreate(String path,
throw new IllegalArgumentException("The child specified by the path '" + path + "' is not a widget");
}
existingChild.setDisplayType(displayType);
System.out.println("Set properties of " + existingChild.getPath() + " to " + properties);
existingChild.setProperties(properties);
return (WidgetModel) existingChild;
}
Expand Down
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 @@ -40,8 +40,8 @@
@SuppressWarnings("PMD.GodClass")
final class TabGenerator {

public static final String ROOT_TABLE_NAME = "/Shuffleboard";
public static final String METADATA_TABLE_NAME = ROOT_TABLE_NAME + "/.metadata";
public static final String ROOT_TABLE_NAME = "";
public static final String METADATA_TABLE_NAME = ROOT_TABLE_NAME + "/Shuffleboard/.metadata";
public static final String PREF_COMPONENT_ENTRY_NAME = "PreferredComponent";
public static final String PROPERTIES_TABLE_NAME = "Properties";
public static final String TABS_ENTRY_KEY = "Tabs";
Expand Down Expand Up @@ -172,8 +172,8 @@ private void metadataChanged(NetworkTableEvent event) {
String propsTableName = metaHierarchy.get(metaHierarchy.size() - 2);
NetworkTable propsTable = inst.getTable(propsTableName);
Map<String, Object> properties = propsTable.getKeys()
.stream()
.collect(Collectors.toMap(t -> t, k -> propsTable.getEntry(k).getValue().getValue()));
.stream()
.collect(Collectors.toMap(t -> t, k -> propsTable.getEntry(k).getValue().getValue()));
if (NetworkTable.basenameKey(real).equals(tab.getTitle())) {
tab.setProperties(properties);
} else {
Expand All @@ -198,16 +198,16 @@ private void dataChanged(NetworkTableEvent event) {
return;
}
List<String> hierarchy = NetworkTable.getHierarchy(name);
if (hierarchy.size() < 3) {
// Not enough data
return;
}
// if (hierarchy.size() < 3) {
// // Not enough data
// return;
// }
if (name.contains("/.")) {
// The entry is metadata, but may be the only entry in a table, so make sure it's updated correctly
var tables = hierarchy.stream()
.takeWhile(s -> !s.contains("/."))
.collect(Collectors.toList());
if (tables.size() >= 3) {
if (tables.size() >= 2) {
updateFrom(tables);
}
return;
Expand All @@ -222,7 +222,13 @@ private void updateFrom(List<String> tables) {

private void updateStructure(List<String> hierarchy) {
// 0='/', 1='/Shuffleboard', 2='/Shuffleboard/<Tab>'
TabModel tab = tabs.getTab(NetworkTable.basenameKey(hierarchy.get(2)));
String tabName;
if (hierarchy.get(1).equals("/Shuffleboard")) {
tabName = NetworkTable.basenameKey(hierarchy.get(2));
} else {
tabName = NetworkTable.basenameKey(hierarchy.get(1));
}
TabModel tab = tabs.getTab(tabName);
ParentModel parent = tab;
int index = 0;
boolean end = false;
Expand All @@ -233,6 +239,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 @@ -334,14 +343,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 @@ -106,7 +107,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 c6c75e9

Please sign in to comment.