Skip to content

Commit ab09d06

Browse files
committed
updated code to use FinEvent
1 parent 27d8944 commit ab09d06

2 files changed

Lines changed: 22 additions & 13 deletions

File tree

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public void onClose(String reason) {
4747
});
4848
}
4949

50-
private void createChannelClient( ) {
50+
/**
51+
* Create a channel client that invokes "getValue", "increment" and "incrementBy
52+
* n" actions
53+
*/
54+
private void createChannelClient() {
5155
logger.info("creating channel client");
5256
fin.Channel.connect(CHANNEL_NAME).thenAccept(client->{
5357
logger.info("channel client connected");
@@ -73,10 +77,14 @@ private void createChannelClient( ) {
7377
});
7478
}
7579

80+
/**
81+
* Create a provider that supports "getValue", "increment" and "incrementBy n"
82+
* actions
83+
*/
7684
private void createChannelProvider() {
7785
logger.info("creating channel provider");
7886
fin.Channel.addChannelDisconnectListener(e->{
79-
if (Objects.equals(CHANNEL_NAME, e.getString("channelName"))) {
87+
if (Objects.equals(CHANNEL_NAME, e.getEventObject().getString("channelName"))) {
8088
logger.info("provider disconnected");
8189
fin.disconnect();
8290
}

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import javax.swing.tree.DefaultTreeModel;
5151
import javax.swing.tree.TreePath;
5252

53+
import com.openfin.desktop.FinEvent;
5354
import com.openfin.desktop.FinEventListener;
5455
import com.openfin.desktop.FinLauncher;
5556
import com.openfin.desktop.FinLayoutObject;
@@ -666,7 +667,7 @@ void addViewNode(DefaultMutableTreeNode winNode, Identity viewIdentity) {
666667
FinWindowObject window = (FinWindowObject) winNode.getUserObject();
667668
DefaultMutableTreeNode viewNode = new DefaultMutableTreeNode(view);
668669
window.addEventListener("view-detached", e -> {
669-
JsonObject vId = e.getJsonObject("viewIdentity");
670+
JsonObject vId = e.getEventObject().getJsonObject("viewIdentity");
670671
if (Objects.equals(viewIdentity.getUuid(), vId.getString("uuid"))
671672
&& Objects.equals(viewIdentity.getName(), vId.getString("name"))) {
672673
this.deleteViewNode(viewNode);
@@ -691,15 +692,15 @@ void addWindowNode(DefaultMutableTreeNode platformNode, Identity winIdentity) {
691692
DefaultMutableTreeNode node = new DefaultMutableTreeNode(window);
692693
platform.addEventListener("window-closed", e -> {
693694
System.out.println("window-closed: " + e);
694-
String uuid = e.getString("uuid");
695-
String name = e.getString("name");
695+
String uuid = e.getEventObject().getString("uuid");
696+
String name = e.getEventObject().getString("name");
696697
if (Objects.equals(winIdentity.getUuid(), uuid) && Objects.equals(winIdentity.getName(), name)) {
697698
deleteWindowNode(node);
698699
}
699700
});
700701
window.addEventListener("view-attached", e -> {
701702
System.out.println("view-attached: " + e);
702-
addViewNode(node, FinBeanUtils.fromJsonObject(e.getJsonObject("viewIdentity"), Identity.class));
703+
addViewNode(node, FinBeanUtils.fromJsonObject(e.getEventObject().getJsonObject("viewIdentity"), Identity.class));
703704
});
704705
SwingUtilities.invokeLater(() -> {
705706
this.platformTreeModel.insertNodeInto(node, platformNode, platformNode.getChildCount());
@@ -723,9 +724,9 @@ void addPlatformNode(String uuid) {
723724
DefaultMutableTreeNode node = new DefaultMutableTreeNode(platform);
724725
FinEventListener listener = new FinEventListener() {
725726
@Override
726-
public void onEvent(JsonObject e) {
727+
public void onEvent(FinEvent e) {
727728
System.out.println("application-closed: " + e);
728-
String eUuid = e.getString("uuid");
729+
String eUuid = e.getEventObject().getString("uuid");
729730
if (Objects.equals(uuid, eUuid)) {
730731
deletePlatformNode(node);
731732
fin.System.removeEventListener("application-closed", this);
@@ -735,8 +736,8 @@ public void onEvent(JsonObject e) {
735736
fin.System.addEventListener("application-closed", listener);
736737
platform.addEventListener("window-created", e -> {
737738
System.out.println("window-created: " + e);
738-
String eUuid = e.getString("uuid");
739-
String eName = e.getString("name");
739+
String eUuid = e.getEventObject().getString("uuid");
740+
String eName = e.getEventObject().getString("name");
740741
addWindowNode(node, new Identity(eUuid, eName));
741742
});
742743
this.platformTreeModel.insertNodeInto(node, this.rootNode, this.rootNode.getChildCount());
@@ -759,14 +760,14 @@ public void onClose(String reason) {
759760
this.fin = fin;
760761
fin.System.addEventListener("application-platform-api-ready", e -> {
761762
System.out.println("application-platform-api-ready: " + e);
762-
String uuid = e.getString("uuid");
763+
String uuid = e.getEventObject().getString("uuid");
763764
addPlatformNode(uuid);
764765
});
765766

766767
fin.System.addEventListener("window-created", e -> {
767768
System.out.println("system::window-created: " + e);
768-
String uuid = e.getString("uuid");
769-
String name = e.getString("name");
769+
String uuid = e.getEventObject().getString("uuid");
770+
String name = e.getEventObject().getString("name");
770771
});
771772

772773
SwingUtilities.invokeLater(() -> {

0 commit comments

Comments
 (0)