Skip to content

Commit 4df6304

Browse files
committed
blob
1 parent fe8127d commit 4df6304

File tree

3 files changed

+48
-19
lines changed

3 files changed

+48
-19
lines changed

app/src/main/java/edu/wpi/first/shuffleboard/app/WidgetPaneDragHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ private boolean previewSource(GridPoint point, Dragboard dragboard) {
140140
}
141141
SourceEntry entry = DeserializationHelper.sourceFromDrag(dragboard.getContent(DataFormats.source));
142142
DataSource source = entry.get();
143-
Optional<String> componentName = Components.getDefault().pickComponentNameFor(source.getDataType());
143+
Optional<String> componentName = source.preferredWidget()
144+
.or(() -> Components.getDefault().pickComponentNameFor(source.getDataType()));
144145
Optional<DataSource<?>> dummySource = DummySource.forTypes(source.getDataType());
145146
if (componentName.isPresent() && dummySource.isPresent()) {
146147
if (tilePreviewSize == null) {

plugins/networktables/src/main/java/edu/wpi/first/shuffleboard/plugin/networktables/TabGenerator.java

+39-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package edu.wpi.first.shuffleboard.plugin.networktables;
22

3-
import com.google.gson.JsonObject;
43
import com.google.gson.JsonParser;
4+
import com.google.gson.JsonPrimitive;
55
import edu.wpi.first.shuffleboard.api.sources.DataSource;
66
import edu.wpi.first.shuffleboard.api.sources.SourceTypes;
77
import edu.wpi.first.shuffleboard.api.tab.model.ComponentModel;
@@ -40,8 +40,8 @@
4040
@SuppressWarnings("PMD.GodClass")
4141
final 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";
@@ -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

plugins/networktables/src/main/java/edu/wpi/first/shuffleboard/plugin/networktables/sources/SingleKeyNetworkTableSource.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.wpi.first.shuffleboard.plugin.networktables.sources;
22

3+
import com.google.gson.JsonElement;
34
import com.google.gson.JsonObject;
45
import com.google.gson.JsonParser;
56
import edu.wpi.first.networktables.NetworkTableEvent.Kind;
@@ -106,7 +107,12 @@ private static Optional<String> loadWidgetFromTopicProps(Topic topic) {
106107
System.err.println(metadata);
107108
JsonObject obj = parser.parse(metadata).getAsJsonObject();
108109
obj.entrySet().forEach(System.err::println);
109-
String widget = obj.get("widget").getAsString();
110+
JsonElement widgetProp = obj.get("widget");
111+
if (widgetProp == null || !widgetProp.isJsonPrimitive()) {
112+
System.err.println("Metadata widget field for topic `" + topic.getName() + "` doesn't exist or is ");
113+
return Optional.empty();
114+
}
115+
String widget = widgetProp.getAsString();
110116
System.out.println("widget = " + widget);
111117
return Optional.of(widget);
112118
} catch (Exception e) {

0 commit comments

Comments
 (0)