|
6 | 6 | import com.openfin.desktop.animation.AnimationTransitions; |
7 | 7 | import com.openfin.desktop.animation.OpacityTransition; |
8 | 8 | 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; |
9 | 12 | import info.clearthought.layout.TableLayout; |
10 | 13 |
|
11 | 14 | import javax.swing.*; |
@@ -62,6 +65,7 @@ public class OpenFinDesktopDemo extends JPanel implements ActionListener, Window |
62 | 65 |
|
63 | 66 | protected JButton createApplication; |
64 | 67 | protected JButton createNotification; |
| 68 | + private Notifications notifications; |
65 | 69 |
|
66 | 70 | protected JList activeApplications; |
67 | 71 | protected java.util.List<ApplicationOptions> appOptionsList; |
@@ -451,6 +455,14 @@ private void createAdminApplication() throws DesktopException { |
451 | 455 | updateMessagePanel("Creating InterAppBus"); |
452 | 456 | bus = desktopConnection.getInterApplicationBus(); |
453 | 457 | 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 | + |
454 | 466 | updateMessagePanel("Connected to Desktop"); |
455 | 467 | setMainButtonsEnabled(true); |
456 | 468 |
|
@@ -616,44 +628,17 @@ public void onError(Ack ack) { |
616 | 628 | } |
617 | 629 |
|
618 | 630 | 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); |
657 | 642 | } |
658 | 643 |
|
659 | 644 | private void testOpacity() { |
@@ -685,18 +670,6 @@ private void testRoundedCorners() { |
685 | 670 | e.printStackTrace(); |
686 | 671 | } |
687 | 672 | } |
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 | | - } |
700 | 673 |
|
701 | 674 | private void testOpacityAnimation() { |
702 | 675 | this.selectedApplication.getWindow().getOptions(new AsyncCallback<WindowOptions>() { |
|
0 commit comments