99import com .openfin .desktop .channel .ChannelAction ;
1010import com .openfin .desktop .channel .ChannelClient ;
1111import com .openfin .desktop .win32 .ExternalWindowObserver ;
12+ import org .json .JSONArray ;
1213import org .json .JSONObject ;
1314
1415import javax .swing .*;
@@ -24,10 +25,13 @@ public class LayoutFrame extends JFrame {
2425 private ExternalWindowObserver externalWindowObserver ;
2526 private JButton btnUndock ;
2627 private String windowName ;
28+ private ChannelClient channelClient ;
29+ private String appUuid ;
2730
2831 public LayoutFrame (DesktopConnection desktopConnection , String appUuid , String windowName ) throws DesktopException {
2932 super ();
3033 System .out .println (windowName + " being created " );
34+ this .appUuid = appUuid ;
3135 this .windowName = windowName ;
3236 this .setDefaultCloseOperation (JFrame .DO_NOTHING_ON_CLOSE );
3337 this .setPreferredSize (new Dimension (640 , 480 ));
@@ -49,6 +53,7 @@ public void onSuccess(Ack ack) {
4953 new AsyncCallback <ChannelClient >() {
5054 @ Override
5155 public void onSuccess (ChannelClient client ) {
56+ LayoutFrame .this .channelClient = client ;
5257 btnUndock .addActionListener (new ActionListener () {
5358 @ Override
5459 public void actionPerformed (ActionEvent e ) {
@@ -84,15 +89,7 @@ public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) {
8489 @ Override
8590 public void onSuccess (java .util .List <Window > result ) {
8691 if (result .size () > 0 ) {
87- boolean tabbed = false ;
88- for (Iterator <Window > iter = result .iterator (); iter .hasNext ();) {
89- Window w = iter .next ();
90- if ("layouts-service" .equals (w .getUuid ())) {
91- tabbed = true ;
92- break ;
93- }
94- }
95- LayoutFrame .this .btnUndock .setEnabled (!tabbed );
92+ checkTabbing ();
9693 } else {
9794 LayoutFrame .this .btnUndock .setEnabled (false );
9895 }
@@ -118,6 +115,30 @@ public void windowClosed(WindowEvent e) {
118115 });
119116 }
120117
118+ private void checkTabbing () {
119+ JSONObject payload = new JSONObject ();
120+ payload .put ("uuid" , appUuid );
121+ payload .put ("name" , windowName );
122+ channelClient .dispatch ("GETTABS" , payload , new AckListener () {
123+ @ Override
124+ public void onSuccess (Ack ack ) {
125+ System .out .printf ("channel GETTABS " );
126+ JSONObject data = (JSONObject ) ack .getData ();
127+ Object result = data .get ("result" );
128+ if (result != null && result instanceof JSONArray ) {
129+ JSONArray tabs = (JSONArray ) result ;
130+ LayoutFrame .this .btnUndock .setEnabled (!(tabs != null && tabs .length () > 0 ));
131+ } else {
132+ LayoutFrame .this .btnUndock .setEnabled (true );
133+ }
134+ }
135+ @ Override
136+ public void onError (Ack ack ) {
137+ System .out .printf ("channel GETTABS error " + ack .getReason ());
138+ }
139+ });
140+ }
141+
121142 public String getWindowName () {
122143 return windowName ;
123144 }
0 commit comments