Skip to content

Commit 2069153

Browse files
committed
ADAP-142: Fixed few issues in layout service docking demo
1 parent df7b190 commit 2069153

7 files changed

Lines changed: 140 additions & 71 deletions

File tree

RELEASENOTES-ADAPTER.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Version 7.1.1
2+
3+
## New Features
4+
* Added Channel API
5+
* Requires JDK1.8+
6+
17
# Version 7.0.2
28

39
## Bug Fixes

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>co.openfin</groupId>
88
<artifactId>openfin-desktop-java-example</artifactId>
9-
<version>6.0.1.3-SNAPSHOT</version>
9+
<version>7.1.1</version>
1010
<packaging>jar</packaging>
1111

1212
<name>openfin-desktop-java-example</name>

release/docking.bat

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
if "%1" == "" (
2-
set MainClass="com.openfin.desktop.demo.OpenFinDockingDemo"
3-
) else (
4-
set MainClass="%1"
5-
)
6-
java -cp openfin-desktop-java-example-6.0.0.3.jar;openfin-desktop-java-adapter-6.0.0.3-SNAPSHOT.jar;openfin-snap-dock-1.0.0.1.jar;TableLayout-20050920.jar;jna-4.1.0.jar;jna-platform-4.1.0.jar;json-20140107.jar;slf4j-api-1.7.5.jar;slf4j-jdk14-1.6.1.jar;websocket-api-9.3.12.v20160915.jar;websocket-client-9.3.12.v20160915.jar;websocket-common-9.3.12.v20160915.jar;jetty-io-9.3.12.v20160915.jar;jetty-util-9.3.12.v20160915.jar -Djava.util.logging.config.file=logging.properties -Dcom.openfin.demo.version=5.44.12.27 -Dcom.openfin.temp=%LocalAppData%\OpenFin\temp %MainClass%
1+
java -cp openfin-desktop-java-example-7.1.1.jar;openfin-desktop-java-adapter-7.1.1-SNAPSHOT.jar;openfin-snap-dock-1.0.0.1.jar;TableLayout-20050920.jar;jna-4.1.0.jar;jna-platform-4.1.0.jar;json-20140107.jar;slf4j-api-1.7.5.jar;slf4j-jdk14-1.6.1.jar;websocket-api-9.3.12.v20160915.jar;websocket-client-9.3.12.v20160915.jar;websocket-common-9.3.12.v20160915.jar;jetty-io-9.3.12.v20160915.jar;jetty-util-9.3.12.v20160915.jar -Djava.util.logging.config.file=logging.properties com.openfin.desktop.demo.LayoutServiceDemo
1 Byte
Binary file not shown.
176 KB
Binary file not shown.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
package com.openfin.desktop.demo;
2+
3+
/**
4+
* Example of Java window that can be managed by OpenFin layout service for snap&dock
5+
*/
6+
7+
import com.openfin.desktop.*;
8+
import com.openfin.desktop.Window;
9+
import com.openfin.desktop.channel.ChannelClient;
10+
import com.openfin.desktop.win32.ExternalWindowObserver;
11+
import org.json.JSONObject;
12+
13+
import javax.swing.*;
14+
import java.awt.*;
15+
import java.awt.event.ActionEvent;
16+
import java.awt.event.ActionListener;
17+
import java.awt.event.WindowAdapter;
18+
import java.awt.event.WindowEvent;
19+
import java.lang.System;
20+
21+
public class LayoutFrame extends JFrame {
22+
private ExternalWindowObserver externalWindowObserver;
23+
private JButton btnUndock;
24+
private String windowName;
25+
26+
public LayoutFrame(DesktopConnection desktopConnection, String appUuid, String windowName) throws DesktopException {
27+
super();
28+
System.out.println(windowName + " being created ");
29+
this.windowName = windowName;
30+
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
31+
this.setPreferredSize(new Dimension(640, 480));
32+
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
33+
this.btnUndock = new JButton("undock");
34+
this.btnUndock.setEnabled(false);
35+
pnl.add(btnUndock);
36+
this.getContentPane().add(pnl);
37+
this.pack();
38+
this.setLocationRelativeTo(null);
39+
this.setVisible(true);
40+
41+
this.externalWindowObserver = new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName,
42+
this, new AckListener() {
43+
@Override
44+
public void onSuccess(Ack ack) {
45+
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
46+
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
47+
new AsyncCallback<ChannelClient>() {
48+
@Override
49+
public void onSuccess(ChannelClient client) {
50+
btnUndock.addActionListener(new ActionListener() {
51+
@Override
52+
public void actionPerformed(ActionEvent e) {
53+
JSONObject payload = new JSONObject();
54+
payload.put("uuid", appUuid);
55+
payload.put("name", windowName);
56+
client.dispatch("UNDOCK-WINDOW", payload, null);
57+
}
58+
});
59+
}
60+
});
61+
}
62+
@Override
63+
public void onError(Ack ack) {
64+
System.out.println(windowName + ": unable to register external window, " + ack.getReason());
65+
}
66+
});
67+
68+
Window w = Window.wrap(appUuid, windowName, desktopConnection);
69+
w.addEventListener("group-changed", new EventListener() {
70+
@Override
71+
public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) {
72+
JSONObject eventObj = actionEvent.getEventObject();
73+
String reason = eventObj.getString("reason");
74+
if ("leave".equals(reason)) {
75+
LayoutFrame.this.btnUndock.setEnabled(false);
76+
} else {
77+
LayoutFrame.this.btnUndock.setEnabled(true);
78+
}
79+
}
80+
}, null);
81+
82+
this.addWindowListener(new WindowAdapter() {
83+
public void windowClosing(WindowEvent e) {
84+
super.windowClosing(e);
85+
try {
86+
LayoutFrame.this.cleanup();
87+
LayoutFrame.this.dispose();
88+
} catch (Exception e1) {
89+
e1.printStackTrace();
90+
}
91+
}
92+
public void windowClosed(WindowEvent e) {
93+
super.windowClosed(e);
94+
System.out.println(windowName + " closed ");
95+
}
96+
});
97+
}
98+
99+
public String getWindowName() {
100+
return windowName;
101+
}
102+
103+
public void cleanup() {
104+
try {
105+
System.out.println(windowName + " cleaning up ");
106+
this.externalWindowObserver.dispose();
107+
} catch (Exception e) {
108+
e.printStackTrace();
109+
}
110+
}
111+
}

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

Lines changed: 21 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
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;
13-
import java.util.UUID;
11+
import java.util.*;
1412
import java.util.concurrent.CountDownLatch;
1513

1614
import javax.swing.BorderFactory;
@@ -50,14 +48,24 @@ public class LayoutServiceDemo implements DesktopStateListener {
5048
private Application application;
5149

5250
private JSONArray serviceConfig = new JSONArray();
53-
private List<ExternalWindowObserver> observers = new ArrayList<>();
51+
private Map<String, LayoutFrame> childFrames = new HashMap();
52+
private WindowAdapter childFrameCleanListener;
5453

5554
LayoutServiceDemo() {
5655
try {
5756
this.createMainWindow();
5857
this.launchOpenfin();
58+
59+
this.childFrameCleanListener = new WindowAdapter() {
60+
@Override
61+
public void windowClosed(WindowEvent e) {
62+
super.windowClosed(e);
63+
LayoutFrame frame = (LayoutFrame) e.getWindow();
64+
childFrames.remove(frame.getWindowName());
65+
}
66+
};
5967
}
60-
catch (DesktopException | DesktopIOException | IOException | InterruptedException e) {
68+
catch (Exception e) {
6169
e.printStackTrace();
6270
}
6371
}
@@ -70,12 +78,8 @@ void createMainWindow() {
7078
@Override
7179
public void windowClosing(WindowEvent we) {
7280
try {
73-
observers.forEach((o) -> {
74-
try {
75-
o.dispose();
76-
} catch (DesktopException e) {
77-
e.printStackTrace();
78-
}
81+
childFrames.values().forEach(frame -> {
82+
frame.cleanup();
7983
});
8084
application.close();
8185
Thread.sleep(2000);
@@ -99,7 +103,7 @@ public void actionPerformed(ActionEvent e) {
99103
@Override
100104
public void actionPerformed(ActionEvent e) {
101105
try {
102-
createJavaWindow(UUID.randomUUID().toString());
106+
createJavaWindow();
103107
}
104108
catch (DesktopException e1) {
105109
e1.printStackTrace();
@@ -180,46 +184,11 @@ public void onError(Ack ack) {
180184
});
181185
}
182186

183-
void createJavaWindow(String windowName) throws DesktopException {
184-
final JButton btnUndock = new JButton("undock");
185-
186-
JFrame f = new JFrame();
187-
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
188-
f.setPreferredSize(new Dimension(640, 480));
189-
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
190-
pnl.add(btnUndock);
191-
f.getContentPane().add(pnl);
192-
f.pack();
193-
f.setLocationRelativeTo(null);
194-
f.setVisible(true);
195-
196-
ExternalWindowObserver observer = new ExternalWindowObserver(this.desktopConnection.getPort(), appUuid, windowName, f, new AckListener() {
197-
@Override
198-
public void onSuccess(Ack ack) {
199-
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
200-
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
201-
new AsyncCallback<ChannelClient>() {
202-
@Override
203-
public void onSuccess(ChannelClient client) {
204-
btnUndock.addActionListener(new ActionListener() {
205-
@Override
206-
public void actionPerformed(ActionEvent e) {
207-
JSONObject payload = new JSONObject();
208-
payload.put("uuid", appUuid);
209-
payload.put("name", windowName);
210-
client.dispatch("UNDOCK-WINDOW", payload, null);
211-
}
212-
});
213-
}
214-
});
215-
}
216-
217-
@Override
218-
public void onError(Ack ack) {
219-
System.out.println(windowName + ": unable to register external window, " + ack.getReason());
220-
}
221-
});
222-
this.observers.add(observer);
187+
void createJavaWindow() throws DesktopException {
188+
String windowName = UUID.randomUUID().toString();
189+
LayoutFrame frame = new LayoutFrame(this.desktopConnection, appUuid, windowName);
190+
this.childFrames.put(windowName, frame);
191+
frame.addWindowListener(this.childFrameCleanListener);
223192
}
224193

225194
void createOpenfinWindow() {
@@ -252,18 +221,6 @@ public void onReady() {
252221
this.application = Application.wrap(appUuid, this.desktopConnection);
253222
btnCreateOpenfinWindow.setEnabled(true);
254223
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-
// });
267224
}
268225

269226
@Override

0 commit comments

Comments
 (0)