|
39 | 39 | import com.openfin.desktop.DesktopException; |
40 | 40 | import com.openfin.desktop.DesktopIOException; |
41 | 41 | import com.openfin.desktop.DesktopStateListener; |
| 42 | +import com.openfin.desktop.EventListener; |
42 | 43 | import com.openfin.desktop.RuntimeConfiguration; |
| 44 | +import com.openfin.desktop.Window; |
43 | 45 | import com.openfin.desktop.WindowOptions; |
44 | 46 | import com.openfin.desktop.channel.ChannelAction; |
45 | 47 | import com.openfin.desktop.channel.ChannelClient; |
@@ -216,61 +218,81 @@ void createJavaWindow() throws DesktopException { |
216 | 218 | frame.addWindowListener(this.childFrameCleanListener); |
217 | 219 | } |
218 | 220 |
|
219 | | - void createJavaFxWindow() { |
| 221 | + void createJavaFxWindow() { |
220 | 222 | String windowName = UUID.randomUUID().toString(); |
221 | | - javafx.application.Platform.runLater(new Runnable() { |
| 223 | + javafx.application.Platform.runLater(new Runnable() { |
222 | 224 | @Override |
223 | 225 | public void run() { |
224 | | - Button undock = new Button("undock"); |
225 | | - |
| 226 | + Button btnUndock = new Button("undock"); |
| 227 | + btnUndock.setDisable(true); |
| 228 | + |
226 | 229 | StackPane secondaryLayout = new StackPane(); |
227 | | - secondaryLayout.getChildren().add(undock); |
228 | | - |
| 230 | + secondaryLayout.getChildren().add(btnUndock); |
| 231 | + |
229 | 232 | Scene secondScene = new Scene(secondaryLayout, 230, 100); |
230 | | - |
| 233 | + |
231 | 234 | // New window (Stage) |
232 | 235 | Stage newWindow = new Stage(); |
233 | 236 | newWindow.setTitle(windowName); |
234 | 237 | newWindow.setScene(secondScene); |
235 | | - |
| 238 | + |
236 | 239 | // Set position of second window, related to primary window. |
237 | 240 | newWindow.setX(200); |
238 | 241 | newWindow.setY(150); |
239 | | - newWindow.show(); |
240 | | - |
241 | | - try { |
242 | | - new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName, newWindow, new AckListener() { |
| 242 | + newWindow.show(); |
243 | 243 |
|
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 | + }); |
258 | 263 | } |
259 | 264 | }); |
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); |
262 | 287 | } |
| 288 | + }, null); |
263 | 289 |
|
264 | | - @Override |
265 | | - public void onError(Ack ack) { |
266 | | - |
267 | | - }}); |
268 | 290 | } catch (DesktopException e) { |
269 | 291 | e.printStackTrace(); |
270 | 292 | } |
271 | | - } |
272 | | - }); |
273 | | - } |
| 293 | + } |
| 294 | + }); |
| 295 | + } |
274 | 296 |
|
275 | 297 | void createOpenfinWindow() { |
276 | 298 | try { |
|
0 commit comments