11package edu .wpi .grip .ui .pipeline ;
22
33import com .google .common .annotations .VisibleForTesting ;
4+ import com .google .common .eventbus .Subscribe ;
45import com .google .inject .Inject ;
56import com .google .inject .assistedinject .Assisted ;
67import edu .wpi .grip .core .OutputSocket ;
78import edu .wpi .grip .core .Socket ;
89import edu .wpi .grip .core .SocketHint ;
10+ import edu .wpi .grip .core .events .SocketPreviewChangedEvent ;
911import edu .wpi .grip .ui .Controller ;
1012import edu .wpi .grip .ui .annotations .ParametrizedController ;
13+ import javafx .beans .InvalidationListener ;
1114import javafx .fxml .FXML ;
1215import javafx .scene .Node ;
1316import javafx .scene .control .Label ;
@@ -40,7 +43,8 @@ public class OutputSocketController implements Controller {
4043 @ FXML
4144 private StackPane handlePane ;
4245
43- private SocketHandleView .Factory socketHandleFactory ;
46+ private final SocketHandleView .Factory socketHandleFactory ;
47+ private final InvalidationListener previewListener ;
4448
4549 /**
4650 * The "handle" is a simple shape next ot the socket identifier that shows whether or not there is a connection
@@ -59,6 +63,7 @@ public interface Factory {
5963 OutputSocketController (SocketHandleView .Factory socketHandleFactory , @ Assisted OutputSocket socket ) {
6064 this .socketHandleFactory = checkNotNull (socketHandleFactory , "Socket Handle factory can not be null" );
6165 this .socket = checkNotNull (socket , "The output socket can not be null" );
66+ this .previewListener = value -> this .socket .setPreviewed (this .preview .isSelected ());
6267 }
6368
6469 @ FXML
@@ -70,7 +75,7 @@ public void initialize() {
7075
7176 // Show a button to choose if we want to preview the socket or not
7277 this .preview .setSelected (this .socket .isPreviewed ());
73- this .preview .selectedProperty ().addListener (value -> this . socket . setPreviewed ( this . preview . isSelected ()) );
78+ this .preview .selectedProperty ().addListener (previewListener );
7479
7580 SocketHint <?> socketHint = this .socket .getSocketHint ();
7681
@@ -87,6 +92,19 @@ public SocketHandleView getHandle() {
8792 return this .handle ;
8893 }
8994
95+ @ Subscribe
96+ public void onSocketPreviewChangedEvent (SocketPreviewChangedEvent event ) {
97+ if (event .getSocket ().equals (socket )) {
98+ // Only try to update the button if the two aren't the same
99+ // This really should only happen we deserialize the pipeline
100+ if (event .getSocket ().isPreviewed () != preview .isSelected ()) {
101+ preview .selectedProperty ().removeListener (previewListener );
102+ preview .setSelected (event .getSocket ().isPreviewed ());
103+ preview .selectedProperty ().addListener (previewListener );
104+ }
105+ }
106+ }
107+
90108 @ VisibleForTesting
91109 ToggleButton previewButton () {
92110 return preview ;
0 commit comments