Skip to content

Commit df7b190

Browse files
committed
ADAP-142: fixed layout demo
1 parent 419ce17 commit df7b190

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

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

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import java.awt.event.WindowAdapter;
99
import java.awt.event.WindowEvent;
1010
import java.io.IOException;
11+
import java.util.ArrayList;
12+
import java.util.List;
1113
import java.util.UUID;
1214
import java.util.concurrent.CountDownLatch;
1315

@@ -38,6 +40,7 @@
3840
public class LayoutServiceDemo implements DesktopStateListener {
3941

4042
private final static String appUuid = "layoutServiceDemo";
43+
private final static String javaConnectUuid = "layoutServiceDemoJava";
4144

4245
private DesktopConnection desktopConnection;
4346
private CountDownLatch latch = new CountDownLatch(1);
@@ -46,7 +49,8 @@ public class LayoutServiceDemo implements DesktopStateListener {
4649
private JButton btnCreateJavaWindow;
4750
private Application application;
4851

49-
JSONArray serviceConfig = new JSONArray();
52+
private JSONArray serviceConfig = new JSONArray();
53+
private List<ExternalWindowObserver> observers = new ArrayList<>();
5054

5155
LayoutServiceDemo() {
5256
try {
@@ -66,26 +70,18 @@ void createMainWindow() {
6670
@Override
6771
public void windowClosing(WindowEvent we) {
6872
try {
69-
application.close(true, new AckListener() {
70-
71-
@Override
72-
public void onSuccess(Ack ack) {
73-
mainWindow.dispose();
74-
try {
75-
desktopConnection.disconnect();
76-
}
77-
catch (DesktopException e) {
78-
e.printStackTrace();
79-
}
80-
}
81-
82-
@Override
83-
public void onError(Ack ack) {
73+
observers.forEach((o) -> {
74+
try {
75+
o.dispose();
76+
} catch (DesktopException e) {
77+
e.printStackTrace();
8478
}
8579
});
86-
80+
application.close();
81+
Thread.sleep(2000);
82+
java.lang.System.exit(0);
8783
}
88-
catch (DesktopException de) {
84+
catch (Exception de) {
8985
de.printStackTrace();
9086
}
9187
}
@@ -145,7 +141,14 @@ void launchOpenfin() throws DesktopException, DesktopIOException, IOException, I
145141
serviceConfig.put(0, layout);
146142
config.addConfigurationItem("services", serviceConfig);
147143

148-
this.desktopConnection = new DesktopConnection("LayoutServiceDemo");
144+
JSONObject startupApp = new JSONObject();
145+
startupApp.put("uuid", appUuid);
146+
startupApp.put("name", appUuid);
147+
startupApp.put("url", "about:blank");
148+
startupApp.put("autoShow", false);
149+
config.setStartupApp(startupApp);
150+
151+
this.desktopConnection = new DesktopConnection(javaConnectUuid);
149152
this.desktopConnection.connect(config, this, 60);
150153
latch.await();
151154
}
@@ -190,7 +193,7 @@ void createJavaWindow(String windowName) throws DesktopException {
190193
f.setLocationRelativeTo(null);
191194
f.setVisible(true);
192195

193-
new ExternalWindowObserver(this.desktopConnection.getPort(), appUuid, windowName, f, new AckListener() {
196+
ExternalWindowObserver observer = new ExternalWindowObserver(this.desktopConnection.getPort(), appUuid, windowName, f, new AckListener() {
194197
@Override
195198
public void onSuccess(Ack ack) {
196199
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
@@ -216,6 +219,7 @@ public void onError(Ack ack) {
216219
System.out.println(windowName + ": unable to register external window, " + ack.getReason());
217220
}
218221
});
222+
this.observers.add(observer);
219223
}
220224

221225
void createOpenfinWindow() {
@@ -244,17 +248,22 @@ public void onError(Ack ack) {
244248

245249
@Override
246250
public void onReady() {
247-
createApplication(appUuid, appUuid, "about:blank", new AckListener() {
248-
@Override
249-
public void onSuccess(Ack ack) {
250-
}
251251

252-
@Override
253-
public void onError(Ack ack) {
254-
System.out.println("error creating applicaton: " + ack.getReason());
255-
}
256-
257-
});
252+
this.application = Application.wrap(appUuid, this.desktopConnection);
253+
btnCreateOpenfinWindow.setEnabled(true);
254+
btnCreateJavaWindow.setEnabled(true);
255+
256+
// createApplication(appUuid, appUuid, "about:blank", new AckListener() {
257+
// @Override
258+
// public void onSuccess(Ack ack) {
259+
// }
260+
//
261+
// @Override
262+
// public void onError(Ack ack) {
263+
// System.out.println("error creating applicaton: " + ack.getReason());
264+
// }
265+
//
266+
// });
258267
}
259268

260269
@Override

0 commit comments

Comments
 (0)