Skip to content

Commit

Permalink
Renamed Network Tables Tree classes
Browse files Browse the repository at this point in the history
* TreeRow is now NetworkTableTreeRow
* The files have been renamed to be clearer
  • Loading branch information
Gold872 committed Dec 9, 2023
1 parent 3224e37 commit 85bf310
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import 'package:elastic_dashboard/widgets/draggable_containers/draggable_layout_
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_nt4_widget_container.dart';
import 'package:elastic_dashboard/widgets/draggable_dialog.dart';
import 'package:elastic_dashboard/widgets/editable_tab_bar.dart';
import 'package:elastic_dashboard/widgets/network_tree/network_table_tree.dart';
import 'package:elastic_dashboard/widgets/network_tree/networktables_tree.dart';
import 'package:elastic_dashboard/widgets/settings_dialog.dart';

class DashboardPage extends StatefulWidget {
Expand Down
17 changes: 9 additions & 8 deletions lib/services/shuffleboard_nt_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:elastic_dashboard/services/nt4.dart';
import 'package:elastic_dashboard/services/nt4_connection.dart';
import 'package:elastic_dashboard/services/settings.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_widget_container.dart';
import 'package:elastic_dashboard/widgets/network_tree/tree_row.dart';
import 'package:elastic_dashboard/widgets/network_tree/networktables_tree_row.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/nt4_widget.dart';

class ShuffleboardNTListener {
Expand All @@ -22,7 +22,8 @@ class ShuffleboardNTListener {

Map<String, Map<String, dynamic>> currentJsonData = {};

final TreeRow shuffleboardTreeRoot = TreeRow(topic: '/', rowName: '');
final NetworkTableTreeRow shuffleboardTreeRoot =
NetworkTableTreeRow(topic: '/', rowName: '');

ShuffleboardNTListener({this.onTabChanged, this.onWidgetAdded});

Expand Down Expand Up @@ -262,18 +263,18 @@ class ShuffleboardNTListener {
if (!shuffleboardTreeRoot.hasRow(shuffleboardTableRoot.substring(1))) {
return;
}
TreeRow shuffleboardRootRow =
NetworkTableTreeRow shuffleboardRootRow =
shuffleboardTreeRoot.getRow(shuffleboardTableRoot.substring(1));

if (!shuffleboardRootRow.hasRow(tabName)) {
return;
}
TreeRow tabRow = shuffleboardRootRow.getRow(tabName);
NetworkTableTreeRow tabRow = shuffleboardRootRow.getRow(tabName);

if (!tabRow.hasRow(componentName)) {
return;
}
TreeRow widgetRow = tabRow.getRow(componentName);
NetworkTableTreeRow widgetRow = tabRow.getRow(componentName);

bool isCameraStream = topic.name.endsWith('/.ShuffleboardURI');

Expand Down Expand Up @@ -375,7 +376,7 @@ class ShuffleboardNTListener {
}

Future<void> handleLayoutTopicAnnounce(
NT4Topic topic, TreeRow widgetRow) async {
NT4Topic topic, NetworkTableTreeRow widgetRow) async {
String name = topic.name;

List<String> tables = name.substring(1).split('/');
Expand Down Expand Up @@ -416,7 +417,7 @@ class ShuffleboardNTListener {
if (!widgetRow.hasRow(child['title'])) {
continue;
}
TreeRow childRow = widgetRow.getRow(child['title']);
NetworkTableTreeRow childRow = widgetRow.getRow(child['title']);

WidgetContainer? widgetContainer = await childRow.toWidgetContainer();
NT4Widget? widget = tryCast(widgetContainer?.child);
Expand Down Expand Up @@ -502,7 +503,7 @@ class ShuffleboardNTListener {
String topic = nt4Topic.name;

List<String> rows = topic.substring(1).split('/');
TreeRow? current;
NetworkTableTreeRow? current;
String currentTopic = '';

for (String row in rows) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:elastic_dashboard/services/nt4.dart';
import 'package:elastic_dashboard/services/nt4_connection.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_nt4_widget_container.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_widget_container.dart';
import 'package:elastic_dashboard/widgets/network_tree/tree_row.dart';
import 'package:elastic_dashboard/widgets/network_tree/networktables_tree_row.dart';

class NetworkTableTree extends StatefulWidget {
final Function(Offset globalPosition, DraggableNT4WidgetContainer widget)?
Expand All @@ -29,8 +29,8 @@ class NetworkTableTree extends StatefulWidget {
}

class _NetworkTableTreeState extends State<NetworkTableTree> {
final TreeRow root = TreeRow(topic: '/', rowName: '');
late final TreeController<TreeRow> treeController;
final NetworkTableTreeRow root = NetworkTableTreeRow(topic: '/', rowName: '');
late final TreeController<NetworkTableTreeRow> treeController;

late final Function(
Offset globalPosition, DraggableNT4WidgetContainer widget)?
Expand All @@ -46,7 +46,7 @@ class _NetworkTableTreeState extends State<NetworkTableTree> {
void initState() {
super.initState();

treeController = TreeController<TreeRow>(
treeController = TreeController<NetworkTableTreeRow>(
roots: root.children, childrenProvider: (node) => node.children);

nt4Connection.nt4Client
Expand All @@ -68,7 +68,7 @@ class _NetworkTableTreeState extends State<NetworkTableTree> {
String topic = nt4Topic.name;

List<String> rows = topic.substring(1).split('/');
TreeRow? current;
NetworkTableTreeRow? current;
String currentTopic = '';

for (String row in rows) {
Expand Down Expand Up @@ -116,9 +116,10 @@ class _NetworkTableTreeState extends State<NetworkTableTree> {

root.sort();

return TreeView<TreeRow>(
return TreeView<NetworkTableTreeRow>(
treeController: treeController,
nodeBuilder: (BuildContext context, TreeEntry<TreeRow> entry) {
nodeBuilder:
(BuildContext context, TreeEntry<NetworkTableTreeRow> entry) {
return TreeTile(
key: UniqueKey(),
entry: entry,
Expand All @@ -144,7 +145,7 @@ class TreeTile extends StatelessWidget {
this.widgetContainerBuilder,
});

final TreeEntry<TreeRow> entry;
final TreeEntry<NetworkTableTreeRow> entry;
final VoidCallback onTap;
final Function(Offset globalPosition, DraggableNT4WidgetContainer widget)?
onDragUpdate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import 'package:elastic_dashboard/widgets/nt4_widgets/nt4_widget.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/boolean_box.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/text_display.dart';

class TreeRow {
class NetworkTableTreeRow {
final String topic;
final String rowName;

final NT4Topic? nt4Topic;

List<TreeRow> children = [];
List<NetworkTableTreeRow> children = [];

TreeRow({required this.topic, required this.rowName, this.nt4Topic});
NetworkTableTreeRow(
{required this.topic, required this.rowName, this.nt4Topic});

bool hasRow(String name) {
for (TreeRow child in children) {
for (NetworkTableTreeRow child in children) {
if (child.rowName == name) {
return true;
}
Expand All @@ -38,16 +39,16 @@ class TreeRow {
return true;
}

void addRow(TreeRow row) {
void addRow(NetworkTableTreeRow row) {
if (hasRow(row.rowName)) {
return;
}

children.add(row);
}

TreeRow getRow(String name) {
for (TreeRow row in children) {
NetworkTableTreeRow getRow(String name) {
for (NetworkTableTreeRow row in children) {
if (row.rowName == name) {
return row;
}
Expand All @@ -56,9 +57,10 @@ class TreeRow {
throw Exception("Trying to retrieve a row that doesn't exist");
}

TreeRow createNewRow(
NetworkTableTreeRow createNewRow(
{required String topic, required String name, NT4Topic? nt4Topic}) {
TreeRow newRow = TreeRow(topic: topic, rowName: name, nt4Topic: nt4Topic);
NetworkTableTreeRow newRow =
NetworkTableTreeRow(topic: topic, rowName: name, nt4Topic: nt4Topic);
addRow(newRow);

return newRow;
Expand All @@ -75,7 +77,7 @@ class TreeRow {
return a.rowName.compareTo(b.rowName);
});

for (TreeRow child in children) {
for (NetworkTableTreeRow child in children) {
child.sort();
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/pages/dashboard_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import 'package:elastic_dashboard/widgets/draggable_containers/draggable_list_la
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_widget_container.dart';
import 'package:elastic_dashboard/widgets/draggable_dialog.dart';
import 'package:elastic_dashboard/widgets/editable_tab_bar.dart';
import 'package:elastic_dashboard/widgets/network_tree/network_table_tree.dart';
import 'package:elastic_dashboard/widgets/network_tree/networktables_tree.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/multi-topic/combo_box_chooser.dart';
import 'package:elastic_dashboard/widgets/nt4_widgets/single_topic/boolean_box.dart';
import 'package:elastic_dashboard/widgets/settings_dialog.dart';
Expand Down

0 comments on commit 85bf310

Please sign in to comment.