Skip to content

Commit 515130a

Browse files
authored
ADAP-142: Added examples of docking by Layout service
* ADAP-142: Added examples of docking by Layout service
1 parent 817dcce commit 515130a

File tree

10 files changed

+732
-9
lines changed

10 files changed

+732
-9
lines changed

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: 2 additions & 2 deletions
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>
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>co.openfin</groupId>
6060
<artifactId>openfin-desktop-java-adapter</artifactId>
61-
<version>7.0.2</version>
61+
<version>7.1.1-SNAPSHOT</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>co.openfin</groupId>

release/docking.bat

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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+
REM batch to run Docking example of OpenFin and Java windows with Layout service.
2+
REM layout.html is a simple example of OpenFin window that uses Layout service.
3+
REM For this example to work, layout.html needs to be hosted by a web server and its URL needs to be configured with -Dcom.openfin.demo.layout.url
4+
5+
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 -Dcom.openfin.demo.layout.url=http://localhost:8000/layout.html com.openfin.desktop.demo.LayoutServiceDemo

release/layout.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<html>
2+
<head>
3+
<title>Openfin Layouts Included</title>
4+
<script src="https://cdn.openfin.co/services/openfin/layouts/1.0.0/openfin-layouts.js"></script>
5+
6+
<script type="text/javascript">
7+
8+
window.addEventListener("DOMContentLoaded", function() {
9+
OpenFinLayouts.snapAndDock.addEventListener('window-docked', e => {
10+
let undock = document.getElementById("undock");
11+
undock.disabled = false;
12+
});
13+
OpenFinLayouts.snapAndDock.addEventListener('window-undocked', e => {
14+
let undock = document.getElementById("undock");
15+
undock.disabled = true;
16+
});
17+
});
18+
19+
function undockMe() {
20+
OpenFinLayouts.snapAndDock.undockWindow();
21+
}
22+
</script>
23+
</head>
24+
<body style="background-color: rgb(158, 240, 222);">
25+
<script>
26+
const randomColor = () => {
27+
return '#' + ((1 << 24) * Math.random() | 0).toString(16);
28+
};
29+
30+
document.addEventListener('DOMContentLoaded', () => {
31+
document.body.style.backgroundColor = randomColor();
32+
});
33+
</script>
34+
35+
<p>Openfin Layouts Library is included via script tag in this window. Accessible with global var OpenfinLayouts</p>
36+
<div>
37+
<Button id="undock" disabled onclick="undockMe()"> Undock </Button>
38+
</div>
39+
</body></html>
352 KB
Binary file not shown.
178 KB
Binary file not shown.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
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.ChannelAction;
10+
import com.openfin.desktop.channel.ChannelClient;
11+
import com.openfin.desktop.win32.ExternalWindowObserver;
12+
import org.json.JSONObject;
13+
14+
import javax.swing.*;
15+
import java.awt.*;
16+
import java.awt.event.ActionEvent;
17+
import java.awt.event.ActionListener;
18+
import java.awt.event.WindowAdapter;
19+
import java.awt.event.WindowEvent;
20+
import java.lang.System;
21+
22+
public class LayoutFrame extends JFrame {
23+
private ExternalWindowObserver externalWindowObserver;
24+
private JButton btnUndock;
25+
private String windowName;
26+
27+
public LayoutFrame(DesktopConnection desktopConnection, String appUuid, String windowName) throws DesktopException {
28+
super();
29+
System.out.println(windowName + " being created ");
30+
this.windowName = windowName;
31+
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
32+
this.setPreferredSize(new Dimension(640, 480));
33+
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.CENTER));
34+
this.btnUndock = new JButton("undock");
35+
this.btnUndock.setEnabled(false);
36+
pnl.add(btnUndock);
37+
this.getContentPane().add(pnl);
38+
this.pack();
39+
this.setLocationRelativeTo(null);
40+
this.setVisible(true);
41+
42+
this.externalWindowObserver = new ExternalWindowObserver(desktopConnection.getPort(), appUuid, windowName,
43+
this, new AckListener() {
44+
@Override
45+
public void onSuccess(Ack ack) {
46+
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
47+
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
48+
new AsyncCallback<ChannelClient>() {
49+
@Override
50+
public void onSuccess(ChannelClient client) {
51+
btnUndock.addActionListener(new ActionListener() {
52+
@Override
53+
public void actionPerformed(ActionEvent e) {
54+
JSONObject payload = new JSONObject();
55+
payload.put("uuid", appUuid);
56+
payload.put("name", windowName);
57+
client.dispatch("UNDOCK-WINDOW", payload, null);
58+
}
59+
});
60+
61+
client.register("event", new ChannelAction() {
62+
@Override
63+
public JSONObject invoke(String action, JSONObject payload) {
64+
System.out.printf("channel event " + action);
65+
return null;
66+
}
67+
});
68+
}
69+
});
70+
}
71+
@Override
72+
public void onError(Ack ack) {
73+
System.out.println(windowName + ": unable to register external window, " + ack.getReason());
74+
}
75+
});
76+
77+
Window w = Window.wrap(appUuid, windowName, desktopConnection);
78+
w.addEventListener("group-changed", new EventListener() {
79+
@Override
80+
public void eventReceived(com.openfin.desktop.ActionEvent actionEvent) {
81+
JSONObject eventObj = actionEvent.getEventObject();
82+
w.getGroup(new AsyncCallback<java.util.List<Window>>() {
83+
@Override
84+
public void onSuccess(java.util.List<Window> result) {
85+
if (result.size() > 0) {
86+
LayoutFrame.this.btnUndock.setEnabled(true);
87+
} else {
88+
LayoutFrame.this.btnUndock.setEnabled(false);
89+
}
90+
}
91+
}, null);
92+
}
93+
}, null);
94+
95+
this.addWindowListener(new WindowAdapter() {
96+
public void windowClosing(WindowEvent e) {
97+
super.windowClosing(e);
98+
try {
99+
LayoutFrame.this.cleanup();
100+
LayoutFrame.this.dispose();
101+
} catch (Exception e1) {
102+
e1.printStackTrace();
103+
}
104+
}
105+
public void windowClosed(WindowEvent e) {
106+
super.windowClosed(e);
107+
System.out.println(windowName + " closed ");
108+
}
109+
});
110+
}
111+
112+
public String getWindowName() {
113+
return windowName;
114+
}
115+
116+
public void cleanup() {
117+
try {
118+
System.out.println(windowName + " cleaning up ");
119+
this.externalWindowObserver.dispose();
120+
} catch (Exception e) {
121+
e.printStackTrace();
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)