Skip to content

Commit 9486245

Browse files
authored
ADAP-170: add fdc3 example (openfin#28)
* ADAP-170: FDC3 examples * ADAP-170: more changes in FDC3 example * ADAP-170: more in FDC3 example
1 parent a942748 commit 9486245

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class FDC3Example implements DesktopStateListener {
2626
private JButton btnFindIntent;
2727
private JButton btnFindContextIntent;
2828
private JButton btnBroadcast;
29+
private JButton btnJoinRed;
2930
private JButton btnIntentListener;
3031

3132
private JTextArea output; // show output of API
@@ -118,6 +119,16 @@ public void actionPerformed(ActionEvent e) {
118119
this.btnBroadcast.setEnabled(false);
119120
pnl.add(btnBroadcast);
120121

122+
this.btnJoinRed = new JButton("Join Red channel");
123+
this.btnJoinRed.addActionListener(new ActionListener() {
124+
@Override
125+
public void actionPerformed(ActionEvent e) {
126+
joinRed();
127+
}
128+
});
129+
this.btnJoinRed.setEnabled(false);
130+
pnl.add(btnJoinRed);
131+
121132
this.btnIntentListener = new JButton("Register an intent listener");
122133
this.btnIntentListener.addActionListener(new ActionListener() {
123134
@Override
@@ -163,20 +174,13 @@ void launchOpenfin() throws DesktopException, DesktopIOException, IOException, I
163174
// serviceConfig.put(0, layout);
164175
// config.addConfigurationItem("services", serviceConfig);
165176

166-
// JSONObject startupApp = new JSONObject();
167-
// startupApp.put("uuid", appUuid);
168-
// startupApp.put("name", appUuid);
169-
// startupApp.put("url", "about:blank");
170-
// startupApp.put("autoShow", false);
171-
// config.setStartupApp(startupApp);
172-
173177
this.desktopConnection = new DesktopConnection(javaConnectUuid);
174178
this.desktopConnection.connect(config, this, 60);
175179
}
176180

177181
@Override
178182
public void onReady() {
179-
this.fdc3Client = new FDC3Client(this.desktopConnection);
183+
this.fdc3Client = FDC3Client.getInstance(this.desktopConnection);
180184
this.fdc3Client.connect("JavaFDC3Demo", new AckListener() {
181185
@Override
182186
public void onSuccess(Ack ack) {
@@ -185,13 +189,14 @@ public void onSuccess(Ack ack) {
185189
btnFindIntent.setEnabled(true);
186190
btnFindContextIntent.setEnabled(true);
187191
btnBroadcast.setEnabled(true);
192+
btnJoinRed.setEnabled(true);
188193
btnIntentListener.setEnabled(true);
189194
addContextListener();
190195
output.setText(String.format("Connected to FDC3 service"));
191196
}
192197
@Override
193198
public void onError(Ack ack) {
194-
output.setText(String.format("Failed t0 Connect to FDC3 service"));
199+
output.setText(String.format("Failed to Connect to FDC3 service"));
195200
}
196201
});
197202
}
@@ -269,6 +274,31 @@ public void onError(Ack ack) {
269274
});
270275
}
271276

277+
private void joinRed() {
278+
279+
this.fdc3Client.getChannelById("red", new AsyncCallback<Channel>() {
280+
@Override
281+
public void onSuccess(Channel channel) {
282+
if (channel != null) {
283+
channel.join(new AckListener() {
284+
@Override
285+
public void onSuccess(Ack ack) {
286+
if (ack.isSuccessful()) {
287+
output.setText(String.format("Joined red channel"));
288+
} else {
289+
output.setText(String.format("Failed to join red channel %s", ack.getReason()));
290+
}
291+
}
292+
@Override
293+
public void onError(Ack ack) {
294+
output.setText(String.format("Failed to join red channel %s", ack.getReason()));
295+
}
296+
});
297+
}
298+
}
299+
});
300+
}
301+
272302
private void addIntentListener() {
273303
fdc3Client.addIntentListener("fdc3.ViewChart", new IntentListener() {
274304
@Override

0 commit comments

Comments
 (0)