Skip to content

Commit 78dc04d

Browse files
committed
ADAP-114: added example of creating notifications
1 parent b2c2245 commit 78dc04d

File tree

1 file changed

+50
-7
lines changed

1 file changed

+50
-7
lines changed

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

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class OpenFinDesktopDemo extends JPanel implements ActionListener, Window
6161
protected JButton largerButton, smallerButton, upButton, downButton, rightButton, leftButton;
6262

6363
protected JButton createApplication;
64-
protected JButton createRfq;
64+
protected JButton createNotification;
6565

6666
protected JList activeApplications;
6767
protected java.util.List<ApplicationOptions> appOptionsList;
@@ -195,17 +195,17 @@ private JPanel layoutActionButtonPanel() {
195195
createApplication = new JButton("Create Application");
196196
createApplication.setActionCommand("create-application");
197197

198-
createRfq = new JButton("Create RFQ");
199-
createRfq.setActionCommand("create-rfq");
198+
createNotification = new JButton("Create Notification");
199+
createNotification.setActionCommand("create-notification");
200200

201201
close.addActionListener(this);
202202
launch.addActionListener(this);
203203
createApplication.addActionListener(this);
204-
createRfq.addActionListener(this);
204+
createNotification.addActionListener(this);
205205

206206
buttonPanel.add(topPanel, "0,0");
207207
buttonPanel.add(createApplication, "0,1");
208-
// buttonPanel.add(createRfq, "0,2");
208+
buttonPanel.add(createNotification, "0,2");
209209
return buttonPanel;
210210
}
211211

@@ -552,6 +552,8 @@ public void actionPerformed(ActionEvent e) {
552552
if (options != null) {
553553
createApplication(options);
554554
}
555+
} else if ("create-notification".equals(e.getActionCommand())) {
556+
createNotification();
555557
} else if ("minimize".equals(e.getActionCommand())) {
556558
if (this.selectedApplication != null) {
557559
this.selectedApplication.getWindow().minimize();
@@ -608,6 +610,47 @@ public void onError(Ack ack) {
608610
}
609611
}
610612

613+
private void createNotification() throws Exception {
614+
NotificationOptions options = new NotificationOptions("http://demoappdirectory.openf.in/desktop/config/apps/OpenFin/HelloOpenFin/views/notification.html");
615+
options.setTimeout(5000);
616+
options.setMessageText("Unit test for notification");
617+
new Notification(options, new NotificationListener() {
618+
@Override
619+
public void onClick(Ack ack) {
620+
logger.debug("onClick for notification");
621+
}
622+
@Override
623+
public void onClose(Ack ack) {
624+
logger.debug("onClose for notification");
625+
}
626+
@Override
627+
public void onDismiss(Ack ack) {
628+
logger.debug("onDismiss for notification");
629+
}
630+
@Override
631+
public void onError(Ack ack) {
632+
logger.error("onError for notification");
633+
}
634+
@Override
635+
public void onMessage(Ack ack) {
636+
logger.debug("onMessage for notification");
637+
}
638+
@Override
639+
public void onShow(Ack ack) {
640+
// Known issue: this event is not being fired.
641+
// logger.debug("onShow for notification");
642+
}
643+
}, desktopConnection, new AckListener() {
644+
@Override
645+
public void onSuccess(Ack ack) {
646+
}
647+
@Override
648+
public void onError(Ack ack) {
649+
logger.error(ack.getReason());
650+
}
651+
});
652+
}
653+
611654
private void testOpacity() {
612655
this.selectedApplication.getWindow().getOptions(new AsyncCallback<WindowOptions>() {
613656
@Override
@@ -686,7 +729,7 @@ private void setMainButtonsEnabled(boolean enabled) {
686729
close.setEnabled(enabled);
687730

688731
createApplication.setEnabled(enabled);
689-
createRfq.setEnabled(enabled);
732+
createNotification.setEnabled(enabled);
690733

691734
}
692735

@@ -701,7 +744,7 @@ private void setAppButtonsEnabled(boolean enabled) {
701744
}
702745

703746
private void createApplication(final ApplicationOptions options) {
704-
options.getMainWindowOptions().setContextMenu(false);
747+
options.getMainWindowOptions().setContextMenu(true);
705748
Application app = new Application(options, desktopConnection, new AckListener() {
706749
@Override
707750
public void onSuccess(Ack ack) {

0 commit comments

Comments
 (0)