Skip to content

Commit ca6d2d6

Browse files
committed
aDAP-142 listens to group change events to enable/disable undock button in javafx window.
1 parent 4507e84 commit ca6d2d6

1 file changed

Lines changed: 57 additions & 35 deletions

File tree

src/main/java/com/openfin/desktop/demo/LayoutServiceDemo.java

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
import com.openfin.desktop.DesktopException;
4040
import com.openfin.desktop.DesktopIOException;
4141
import com.openfin.desktop.DesktopStateListener;
42+
import com.openfin.desktop.EventListener;
4243
import com.openfin.desktop.RuntimeConfiguration;
44+
import com.openfin.desktop.Window;
4345
import com.openfin.desktop.WindowOptions;
4446
import com.openfin.desktop.channel.ChannelAction;
4547
import com.openfin.desktop.channel.ChannelClient;
@@ -216,61 +218,81 @@ void createJavaWindow() throws DesktopException {
216218
frame.addWindowListener(this.childFrameCleanListener);
217219
}
218220

219-
void createJavaFxWindow() {
221+
void createJavaFxWindow() {
220222
String windowName = UUID.randomUUID().toString();
221-
javafx.application.Platform.runLater(new Runnable() {
223+
javafx.application.Platform.runLater(new Runnable() {
222224
@Override
223225
public void run() {
224-
Button undock = new Button("undock");
225-
226+
Button btnUndock = new Button("undock");
227+
btnUndock.setDisable(true);
228+
226229
StackPane secondaryLayout = new StackPane();
227-
secondaryLayout.getChildren().add(undock);
228-
230+
secondaryLayout.getChildren().add(btnUndock);
231+
229232
Scene secondScene = new Scene(secondaryLayout, 230, 100);
230-
233+
231234
// New window (Stage)
232235
Stage newWindow = new Stage();
233236
newWindow.setTitle(windowName);
234237
newWindow.setScene(secondScene);
235-
238+
236239
// Set position of second window, related to primary window.
237240
newWindow.setX(200);
238241
newWindow.setY(150);
239-
newWindow.show();
240-
241-
try {
242-
new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, newWindow, new AckListener() {
242+
newWindow.show();
243243

244-
@Override
245-
public void onSuccess(Ack ack) {
246-
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
247-
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
248-
new AsyncCallback<ChannelClient>() {
249-
@Override
250-
public void onSuccess(ChannelClient client) {
251-
undock.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
252-
@Override
253-
public void handle(javafx.event.ActionEvent e) {
254-
JSONObject payload = new JSONObject();
255-
payload.put("uuid", appUuid);
256-
payload.put("name", windowName);
257-
client.dispatch("UNDOCK-WINDOW", payload, null);
244+
try {
245+
new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, newWindow,
246+
new AckListener() {
247+
@Override
248+
public void onSuccess(Ack ack) {
249+
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
250+
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
251+
new AsyncCallback<ChannelClient>() {
252+
@Override
253+
public void onSuccess(ChannelClient client) {
254+
btnUndock.setOnAction(new EventHandler<javafx.event.ActionEvent>() {
255+
@Override
256+
public void handle(javafx.event.ActionEvent e) {
257+
JSONObject payload = new JSONObject();
258+
payload.put("uuid", appUuid);
259+
payload.put("name", windowName);
260+
client.dispatch("UNDOCK-WINDOW", payload, null);
261+
}
262+
});
258263
}
259264
});
260-
}
261-
});
265+
}
266+
267+
@Override
268+
public void onError(Ack ack) {
269+
}
270+
});
271+
272+
Window w = Window.wrap(appUuid, windowName, desktopConnection);
273+
w.addEventListener("group-changed", new EventListener() {
274+
@Override
275+
public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) {
276+
JSONObject eventObj = actionEvent.getEventObject();
277+
w.getGroup(new AsyncCallback<java.util.List<Window>>() {
278+
@Override
279+
public void onSuccess(java.util.List<Window> result) {
280+
if (result.size() > 0) {
281+
btnUndock.setDisable(false);
282+
} else {
283+
btnUndock.setDisable(true);
284+
}
285+
}
286+
}, null);
262287
}
288+
}, null);
263289

264-
@Override
265-
public void onError(Ack ack) {
266-
267-
}});
268290
} catch (DesktopException e) {
269291
e.printStackTrace();
270292
}
271-
}
272-
});
273-
}
293+
}
294+
});
295+
}
274296

275297
void createOpenfinWindow() {
276298
try {

0 commit comments

Comments
 (0)