Skip to content

Commit eef62da

Browse files
committed
ADAP-158: added examples for Layout Workspace
1 parent 8cea412 commit eef62da

File tree

3 files changed

+82
-22
lines changed

3 files changed

+82
-22
lines changed
27.3 KB
Binary file not shown.
42.4 KB
Binary file not shown.

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

Lines changed: 82 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import com.openfin.desktop.*;
1010
import com.openfin.desktop.Window;
11-
import com.openfin.desktop.channel.ChannelClient;
12-
import com.openfin.desktop.channel.NotificationClient;
11+
import com.openfin.desktop.channel.*;
1312
import com.openfin.desktop.channel.NotificationListener;
1413
import com.openfin.desktop.channel.NotificationOptions;
1514
import com.openfin.desktop.win32.ExternalWindowObserver;
@@ -28,7 +27,6 @@
2827

2928
public class LauncherBusDemo extends JFrame {
3029
private final static Logger logger = LoggerFactory.getLogger(LauncherBusDemo.class.getName());
31-
private final static String WINDOW_TITLE = "Launcher and InterAppBus Demo";
3230

3331
private DesktopConnection desktopConnection;
3432
private InterApplicationBus interApplicationBus;
@@ -37,6 +35,7 @@ public class LauncherBusDemo extends JFrame {
3735
private JButton btnNotification, btnToggleNotification; // button to create notifications
3836
private JButton btnUndock; // button to undock this Java window
3937
private JButton btnOFSendApp1, btnOFSendApp2; // send messages to OpenFin app via Inter App Bus
38+
private JButton btnGenerateWorkSpace, btnRestoreWorkSpace;
4039
private static String appUuid = "LaunchManifestDemo"; // App UUID for startup app in manifest
4140
private final String app1Uuid = "Layout Client1"; // defined in layoutclient1.json
4241
private final String app2Uuid = "Layout Client2"; // defined in layoutclient2.json
@@ -46,6 +45,8 @@ public class LauncherBusDemo extends JFrame {
4645
private final String embedUuid = "Embed Client";
4746
Application embeddedApp; // OpenFin app to be embedded in Java canvas
4847

48+
private LayoutClient layoutClient; // client for Layout service
49+
private JSONObject lastSavedWorkspace;
4950
private ExternalWindowObserver externalWindowObserver; // required for Layout service to control Java window
5051
protected java.awt.Canvas embedCanvas; // required for embedding OpenFin window
5152

@@ -110,12 +111,32 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
110111
}
111112
});
112113

114+
btnGenerateWorkSpace = new JButton();
115+
btnGenerateWorkSpace.setText("Generate WorkSpace");
116+
btnGenerateWorkSpace.setEnabled(false);
117+
btnGenerateWorkSpace.addActionListener(new ActionListener() {
118+
@Override
119+
public void actionPerformed(java.awt.event.ActionEvent e) {
120+
generateWorkSpace();
121+
}
122+
});
123+
124+
btnRestoreWorkSpace = new JButton();
125+
btnRestoreWorkSpace.setText("Restore WorkSpace");
126+
btnRestoreWorkSpace.setEnabled(false);
127+
btnRestoreWorkSpace.addActionListener(new ActionListener() {
128+
@Override
129+
public void actionPerformed(java.awt.event.ActionEvent e) {
130+
restoreWorkSpace();
131+
}
132+
});
133+
113134
btnUndock = new JButton();
114135
btnUndock.setText("Undock");
115136
btnUndock.setEnabled(false);
116137

117138
JPanel topPanel = new JPanel();
118-
double size[][] = {{10, 190}, {25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5}};
139+
double size[][] = {{10, 190}, {25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5}};
119140
topPanel.setLayout(new TableLayout(size));
120141

121142
topPanel.add(btnOFApp1, "1,0,1,0");
@@ -124,7 +145,9 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
124145
topPanel.add(btnOFSendApp2, "1,6,1,6");
125146
topPanel.add(btnNotification, "1,8,1,8");
126147
topPanel.add(btnToggleNotification, "1,10,1,10");
127-
topPanel.add(btnUndock, "1,12,1,12");
148+
topPanel.add(btnGenerateWorkSpace, "1,12,1,12");
149+
topPanel.add(btnRestoreWorkSpace, "1,14,1,14");
150+
topPanel.add(btnUndock, "1,16,1,16");
128151

129152
setLayout(new BorderLayout());
130153
add(topPanel, BorderLayout.NORTH);
@@ -203,6 +226,7 @@ public void onReady() {
203226
btnOFApp2.setEnabled(true);
204227
configAppEventListener();
205228
createEmbddedApp();
229+
createLayoutClient();
206230
createNotificationClient();
207231
}
208232

@@ -284,24 +308,13 @@ private void createExternalWindowObserver() {
284308
new AckListener() {
285309
@Override
286310
public void onSuccess(Ack ack) {
287-
ExternalWindowObserver observer = (ExternalWindowObserver) ack.getSource();
288-
observer.getDesktopConnection().getChannel().connect("of-layouts-service-v1",
289-
new AsyncCallback<ChannelClient>() {
290-
@Override
291-
public void onSuccess(ChannelClient client) {
292-
btnUndock.addActionListener(new ActionListener() {
293-
@Override
294-
public void actionPerformed(java.awt.event.ActionEvent e) {
295-
JSONObject payload = new JSONObject();
296-
payload.put("uuid", appUuid);
297-
payload.put("name", windowName);
298-
client.dispatch("UNDOCK-WINDOW", payload, null);
299-
}
300-
});
301-
}
302-
});
311+
btnUndock.addActionListener(new ActionListener() {
312+
@Override
313+
public void actionPerformed(java.awt.event.ActionEvent e) {
314+
LauncherBusDemo.this.layoutClient.undockWindow(appUuid, windowName, null);
315+
}
316+
});
303317
}
304-
305318
@Override
306319
public void onError(Ack ack) {
307320
System.out.println(windowName + ": unable to register external window, " + ack.getReason());
@@ -428,6 +441,19 @@ public void onError(Ack ack) {
428441
e.printStackTrace();
429442
}
430443
}
444+
private void createLayoutClient() {
445+
this.layoutClient = new LayoutClient(this.desktopConnection, new AckListener() {
446+
@Override
447+
public void onSuccess(Ack ack) {
448+
btnGenerateWorkSpace.setEnabled(true);
449+
btnRestoreWorkSpace.setEnabled(true);
450+
createExternalWindowObserver();
451+
}
452+
@Override
453+
public void onError(Ack ack) {
454+
}
455+
});
456+
}
431457
private void createNotificationClient() {
432458
this.notificationClient = new NotificationClient(this.desktopConnection, new AckListener() {
433459
@Override
@@ -470,6 +496,40 @@ private void toggleNotificationCenter() {
470496
this.notificationClient.toggleNotificationCenter(null);
471497
}
472498

499+
private void generateWorkSpace() {
500+
this.layoutClient.generateWorkspace(new AsyncCallback<JSONObject>() {
501+
@Override
502+
public void onSuccess(JSONObject result) {
503+
LauncherBusDemo.this.lastSavedWorkspace = result;
504+
logger.info(String.format("Current workspace %s", result.toString()));
505+
}
506+
},
507+
new AckListener() {
508+
@Override
509+
public void onSuccess(Ack ack) {
510+
}
511+
@Override
512+
public void onError(Ack ack) {
513+
logger.error(String.format("Error generating workspace %s", ack.getReason()));
514+
}
515+
});
516+
}
517+
518+
private void restoreWorkSpace() {
519+
if (this.lastSavedWorkspace != null) {
520+
this.layoutClient.retoreWorkspace(this.lastSavedWorkspace, new AckListener() {
521+
@Override
522+
public void onSuccess(Ack ack) {
523+
}
524+
525+
@Override
526+
public void onError(Ack ack) {
527+
logger.error(String.format("Error restoring workspace %s", ack.getReason()));
528+
}
529+
});
530+
}
531+
}
532+
473533
public void cleanup() {
474534
try {
475535
if (this.externalWindowObserver != null) {

0 commit comments

Comments
 (0)