Skip to content

Commit 8cea412

Browse files
committed
ADAP-157: added examples for notification service
1 parent 2a6f7ae commit 8cea412

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>co.openfin</groupId>
6060
<artifactId>openfin-desktop-java-adapter</artifactId>
61-
<version>7.1.2</version>
61+
<version>7.1.3-SNAPSHOT</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>co.openfin</groupId>
-337 KB
Binary file not shown.
-337 KB
Binary file not shown.
1.33 MB
Binary file not shown.

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

Lines changed: 77 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
package com.openfin.desktop.demo;
88

99
import com.openfin.desktop.*;
10-
import com.openfin.desktop.ActionEvent;
1110
import com.openfin.desktop.Window;
1211
import com.openfin.desktop.channel.ChannelClient;
12+
import com.openfin.desktop.channel.NotificationClient;
13+
import com.openfin.desktop.channel.NotificationListener;
14+
import com.openfin.desktop.channel.NotificationOptions;
1315
import com.openfin.desktop.win32.ExternalWindowObserver;
1416
import com.sun.jna.Native;
1517
import info.clearthought.layout.TableLayout;
@@ -22,14 +24,17 @@
2224
import java.awt.*;
2325
import java.awt.event.*;
2426
import java.lang.System;
27+
import java.util.UUID;
2528

2629
public class LauncherBusDemo extends JFrame {
2730
private final static Logger logger = LoggerFactory.getLogger(LauncherBusDemo.class.getName());
2831
private final static String WINDOW_TITLE = "Launcher and InterAppBus Demo";
2932

3033
private DesktopConnection desktopConnection;
3134
private InterApplicationBus interApplicationBus;
35+
private NotificationClient notificationClient;
3236
private JButton btnOFApp1, btnOFApp2;
37+
private JButton btnNotification, btnToggleNotification; // button to create notifications
3338
private JButton btnUndock; // button to undock this Java window
3439
private JButton btnOFSendApp1, btnOFSendApp2; // send messages to OpenFin app via Inter App Bus
3540
private static String appUuid = "LaunchManifestDemo"; // App UUID for startup app in manifest
@@ -85,19 +90,41 @@ public void actionPerformed(java.awt.event.ActionEvent e) {
8590
}
8691
});
8792

93+
btnNotification = new JButton();
94+
btnNotification.setText("Notification");
95+
btnNotification.setEnabled(false);
96+
btnNotification.addActionListener(new ActionListener() {
97+
@Override
98+
public void actionPerformed(java.awt.event.ActionEvent e) {
99+
createNotification();
100+
}
101+
});
102+
103+
btnToggleNotification = new JButton();
104+
btnToggleNotification.setText("Toggle Notification CENTER");
105+
btnToggleNotification.setEnabled(false);
106+
btnToggleNotification.addActionListener(new ActionListener() {
107+
@Override
108+
public void actionPerformed(java.awt.event.ActionEvent e) {
109+
toggleNotificationCenter();
110+
}
111+
});
112+
88113
btnUndock = new JButton();
89114
btnUndock.setText("Undock");
90115
btnUndock.setEnabled(false);
91116

92117
JPanel topPanel = new JPanel();
93-
double size[][] = {{10, 190}, {25, 5, 25, 5, 25, 5, 25, 5, 25, 5}};
118+
double size[][] = {{10, 190}, {25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5, 25, 5}};
94119
topPanel.setLayout(new TableLayout(size));
95120

96121
topPanel.add(btnOFApp1, "1,0,1,0");
97122
topPanel.add(btnOFApp2, "1,2,1,2");
98123
topPanel.add(btnOFSendApp1, "1,4,1,4");
99124
topPanel.add(btnOFSendApp2, "1,6,1,6");
100-
topPanel.add(btnUndock, "1,8,1,8");
125+
topPanel.add(btnNotification, "1,8,1,8");
126+
topPanel.add(btnToggleNotification, "1,10,1,10");
127+
topPanel.add(btnUndock, "1,12,1,12");
101128

102129
setLayout(new BorderLayout());
103130
add(topPanel, BorderLayout.NORTH);
@@ -135,6 +162,7 @@ private void launchRuntime() {
135162
RuntimeConfiguration cfg = new RuntimeConfiguration();
136163
cfg.setRuntimeVersion("stable");
137164
cfg.setSecurityRealm("java-test");
165+
cfg.setDevToolsPort(9099);
138166
cfg.setAdditionalRuntimeArguments("--v=1 --enable-mesh "); // --v=1 => enable verbose logging by Runtime
139167
// --enable-mesh => enable multi-Runtime for the security realm
140168
// Add Layout Service to the manifest
@@ -150,6 +178,11 @@ private void launchRuntime() {
150178
layout.put("config", scfg);
151179
layout.put("manifestUrl", "https://cdn.openfin.co/services/openfin/layouts/1.0.0/app.json");
152180
serviceConfig.put(0, layout);
181+
182+
JSONObject notification = new JSONObject();
183+
notification.put("name", "notifications");
184+
serviceConfig.put(1, notification);
185+
153186
cfg.addConfigurationItem("services", serviceConfig);
154187

155188
JSONObject startupApp = new JSONObject();
@@ -170,6 +203,7 @@ public void onReady() {
170203
btnOFApp2.setEnabled(true);
171204
configAppEventListener();
172205
createEmbddedApp();
206+
createNotificationClient();
173207
}
174208

175209
@Override
@@ -394,7 +428,47 @@ public void onError(Ack ack) {
394428
e.printStackTrace();
395429
}
396430
}
431+
private void createNotificationClient() {
432+
this.notificationClient = new NotificationClient(this.desktopConnection, new AckListener() {
433+
@Override
434+
public void onSuccess(Ack ack) {
435+
btnNotification.setEnabled(true);
436+
btnToggleNotification.setEnabled(true);
437+
LauncherBusDemo.this.notificationClient.addNotificationListener(new NotificationListener() {
438+
@Override
439+
public void onClick(NotificationOptions options) {
440+
logger.info(String.format("Notification clicked %s", options.getId()));
441+
}
442+
@Override
443+
public void onButtonClick(NotificationOptions options) {
444+
logger.info(String.format("Notification button clicked %s button index %d", options.getId(),
445+
options.getButtonIndex()));
446+
}
447+
@Override
448+
public void onClose(NotificationOptions options) {
449+
logger.info(String.format("Notification closed %s", options.getId()));
450+
}
451+
});
452+
}
453+
@Override
454+
public void onError(Ack ack) {
397455

456+
}
457+
});
458+
}
459+
private void createNotification() {
460+
NotificationOptions options = new NotificationOptions();
461+
options.setId(UUID.randomUUID().toString());
462+
options.setBody("Hello From Java app");
463+
options.setTitle("Java Demo");
464+
options.setIcon("https://openfin.co/favicon.ico");
465+
options.addButton(null, "button1");
466+
options.addButton(null, "button2");
467+
this.notificationClient.create(options, null);
468+
}
469+
private void toggleNotificationCenter() {
470+
this.notificationClient.toggleNotificationCenter(null);
471+
}
398472

399473
public void cleanup() {
400474
try {

0 commit comments

Comments
 (0)