Skip to content

Commit 4c25353

Browse files
authored
23850 Add getComponentState() and setComponentState() to JavaFxExample (#20)
* Add getComponetState() and setComponenetState() for linked linker channel and symbol data * Fix base on Andy comments
1 parent b71e2e5 commit 4c25353

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/main/java/com/chartiq/finsemble/example/JavaExample.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ public void error(ConnectionEventGenerator from, Exception e) {
162162
setDraggable();
163163
setDropable();
164164

165+
//GetComponentState
166+
final JSONArray getComponentStateFields = new JSONArray(){{
167+
put("Finsemble_Linker");
168+
put("symbol");
169+
}};
170+
final JSONObject getComponentStateParam = new JSONObject(){{
171+
put("fields", getComponentStateFields);
172+
}};
173+
fsbl.getClients().getWindowClient().getComponentState(getComponentStateParam, this::handleGetComponentStateCb);
165174
} catch (Exception ex) {
166175
LOGGER.log(Level.SEVERE, "Error initializing Finsemble connection", ex);
167176
appendMessage("Error initializing Finsemble connection: " + ex.getMessage());
@@ -270,6 +279,11 @@ private void handleSymbol(JSONObject err, JSONObject res) {
270279
final String symbol = res.has("data") && res.getJSONObject("data").has("data") ?
271280
res.getJSONObject("data").getString("data") :
272281
"";
282+
final JSONObject param = new JSONObject() {{
283+
put("field", "symbol");
284+
put("value", symbol);
285+
}};
286+
fsbl.getClients().getWindowClient().setComponentState(param, (e, r) -> { });
273287
Platform.runLater(() -> symbolLabel.setText(symbol));
274288
}
275289
}
@@ -378,6 +392,29 @@ private void setFormEnable(boolean enabled) {
378392
dockingCheckbox.setDisable(!enabled);
379393
}
380394

395+
private void handleGetComponentStateCb(JSONObject err, JSONObject res) {
396+
if(err!=null){
397+
fsbl.getClients().getLogger().error(err.toString());
398+
}else{
399+
//Set subscribe linker channel
400+
if (res.has("Finsemble_Linker")) {
401+
final JSONArray channelToLink = res.getJSONArray("Finsemble_Linker");
402+
for (int i = 0; i < channelToLink.length(); i++) {
403+
Button tempBtn = (Button) window.getScene().lookup("#" + channelToLink.getString(i) + "Button");
404+
Platform.runLater(() -> tempBtn.fire());
405+
}
406+
}
407+
408+
//Set symbol value
409+
if(res.has("symbol")) {
410+
final String symbol = res.getString("symbol");
411+
if (!symbol.equals("")) {
412+
Platform.runLater(() -> symbolLabel.setText(symbol));
413+
}
414+
}
415+
}
416+
}
417+
381418
private void setDraggable() {
382419
//Add emitters
383420
Map<String, Function> emitters = new HashMap<>();

0 commit comments

Comments
 (0)