Skip to content

Commit 7a9e1ac

Browse files
committed
ADAP-202: updated OpenFinDesktopDemo with new notification API
1 parent 1964613 commit 7a9e1ac

File tree

2 files changed

+25
-50
lines changed

2 files changed

+25
-50
lines changed

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

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import com.openfin.desktop.animation.AnimationTransitions;
77
import com.openfin.desktop.animation.OpacityTransition;
88
import com.openfin.desktop.animation.PositionTransition;
9+
import com.openfin.desktop.notifications.*;
10+
import com.openfin.desktop.notifications.NotificationOptions;
11+
import com.openfin.desktop.notifications.events.NotificationActionEvent;
912
import info.clearthought.layout.TableLayout;
1013

1114
import javax.swing.*;
@@ -62,6 +65,7 @@ public class OpenFinDesktopDemo extends JPanel implements ActionListener, Window
6265

6366
protected JButton createApplication;
6467
protected JButton createNotification;
68+
private Notifications notifications;
6569

6670
protected JList activeApplications;
6771
protected java.util.List<ApplicationOptions> appOptionsList;
@@ -451,6 +455,14 @@ private void createAdminApplication() throws DesktopException {
451455
updateMessagePanel("Creating InterAppBus");
452456
bus = desktopConnection.getInterApplicationBus();
453457
openfinSystem = new System(desktopConnection);
458+
459+
this.notifications = new Notifications(desktopConnection);
460+
this.notifications.addEventListener(Notifications.EVENT_TYPE_ACTION, ne ->{
461+
NotificationActionEvent actionEvent = (NotificationActionEvent) ne;
462+
NotificationActionResult actionResult = actionEvent.getResult();
463+
java.lang.System.out.println("actionResult: notificationId: " + actionEvent.getNotificationOptions().getId() + ", user clicked on btn: " + actionResult.getString("btn"));
464+
});
465+
454466
updateMessagePanel("Connected to Desktop");
455467
setMainButtonsEnabled(true);
456468

@@ -616,44 +628,17 @@ public void onError(Ack ack) {
616628
}
617629

618630
private void createNotification() throws Exception {
619-
NotificationOptions options = new NotificationOptions("http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/views/notification.html");
620-
options.setTimeout(5000);
621-
options.setMessageText("Unit test for notification");
622-
new Notification(options, new NotificationListener() {
623-
@Override
624-
public void onClick(Ack ack) {
625-
logger.debug("onClick for notification");
626-
}
627-
@Override
628-
public void onClose(Ack ack) {
629-
logger.debug("onClose for notification");
630-
}
631-
@Override
632-
public void onDismiss(Ack ack) {
633-
logger.debug("onDismiss for notification");
634-
}
635-
@Override
636-
public void onError(Ack ack) {
637-
logger.error("onError for notification");
638-
}
639-
@Override
640-
public void onMessage(Ack ack) {
641-
logger.debug("onMessage for notification");
642-
}
643-
@Override
644-
public void onShow(Ack ack) {
645-
// Known issue: this event is not being fired.
646-
// logger.debug("onShow for notification");
647-
}
648-
}, desktopConnection, new AckListener() {
649-
@Override
650-
public void onSuccess(Ack ack) {
651-
}
652-
@Override
653-
public void onError(Ack ack) {
654-
logger.error(ack.getReason());
655-
}
656-
});
631+
NotificationOptions opt = new NotificationOptions("Notification from Java", "Write once, run everywhere", "Category");
632+
opt.setSticky(NotificationOptions.STICKY_STICKY);
633+
opt.setIndicator(new NotificationIndicator(NotificationIndicator.TYPE_SUCCESS));
634+
ButtonOptions bo1 = new ButtonOptions("Button 1");
635+
bo1.setOnClick(new NotificationActionResult(new JSONObject().put("btn", "btn1")));
636+
ButtonOptions bo2 = new ButtonOptions("Button 2");
637+
bo2.setOnClick(new NotificationActionResult(new JSONObject().put("btn", "btn2")));
638+
bo2.setCta(true);
639+
opt.setButtons(bo1, bo2);
640+
641+
this.notifications.create(opt);
657642
}
658643

659644
private void testOpacity() {
@@ -685,18 +670,6 @@ private void testRoundedCorners() {
685670
e.printStackTrace();
686671
}
687672
}
688-
private void testRoundedCorners2() {
689-
this.selectedApplication.getWindow().getOptions(new AsyncCallback<WindowOptions>() {
690-
@Override
691-
public void onSuccess(WindowOptions result) {
692-
java.lang.System.out.println("getOptions: " + result.getJson().toString());
693-
int width = result.getCornerRoundingWidth() > 0 ? 0 : 10;
694-
WindowOptions options = new WindowOptions();
695-
options.setCornerRounding(width, width);
696-
selectedApplication.getWindow().updateOptions(options, null);
697-
}
698-
}, null);
699-
}
700673

701674
private void testOpacityAnimation() {
702675
this.selectedApplication.getWindow().getOptions(new AsyncCallback<WindowOptions>() {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package com.openfin.desktop.demo;public class Signer {
2+
}

0 commit comments

Comments
 (0)