List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:eu.riscoss.client.riskanalysis.RASPanel.java
License:Apache License
public void checkLastRiskSession() { RiscossJsonClient.listRiskAnalysisSessions(entity, riskConf, new JsonCallback() { @Override/* w w w.ja v a2 s . c o m*/ public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { if (response == null) return; if (response.isObject() == null) return; response = response.isObject().get("list"); CodecRASInfo codec = GWT.create(CodecRASInfo.class); if (response.isArray() != null) { for (int i = 0; i < response.isArray().size(); i++) { JRASInfo info = codec.decode(response.isArray().get(i)); RiscossJsonClient.getSessionSummary(info.getId(), new JsonCallback() { @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { JsonRiskAnalysis ras = new JsonRiskAnalysis(response); Date d = getDate(ras.getDate()); if (d.after(currentDate) && !ras.getID().equals(RASID)) { mostCurrentSession = ras.getID(); buttons2.clear(); buttons.remove(mitigation); if (inputButtons != null) inputButtons.clear(); Label l = new Label("Current session is not the last one."); Anchor a = new Anchor("Click here to see last execution results."); buttons2.add(l); buttons2.add(a); a.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { Window.Location.replace("riskanalysis.jsp?id=" + mostCurrentSession); } }); } } }); } } } }); }
From source file:eu.riscoss.client.riskanalysis.RASPanel.java
License:Apache License
public void onSaveAndRunClicked() { buttons2.add(running);/*from w w w. java2 s .com*/ RiscossJsonClient.rerunRiskAnalysisSession(selectedRAS, "", new RiscossJsonClient.JsonWaitWrapper(new JsonCallback() { @Override public void onSuccess(Method method, JSONValue response) { // Window.alert( "" + response ); try { RiscossJsonClient.getSessionSummary(selectedRAS, new JsonCallback() { @Override public void onSuccess(Method method, JSONValue response) { loadRASSummary(new JsonRiskAnalysis(response)); } @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } }); // report = new RiskAnalysisReport(); r.showResults(sessionSummary, response.isObject()); if (r.getEvidence()) inputDataInfo(response.isObject().get("input")); } catch (Exception ex) { Window.alert(ex.getMessage() + "\n" + response); } } @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } })); }
From source file:eu.riscoss.client.riskanalysis.RASPanel.java
License:Apache License
public void reloadPanel() { buttons2.add(running);// w w w. ja va2 s. co m RiscossJsonClient.rerunRiskAnalysisSession(selectedRAS, "", new RiscossJsonClient.JsonWaitWrapper(new JsonCallback() { @Override public void onSuccess(Method method, JSONValue response) { // report = new RiskAnalysisReport(); r.showResults(sessionSummary, response.isObject()); buttons2.remove(running); if (r.getEvidence()) inputDataInfo(response.isObject().get("input")); } @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } })); }
From source file:eu.riscoss.client.riskanalysis.RASPanel.java
License:Apache License
protected void onUpdateIsClicked() { RiscossJsonClient.updateSessionData(selectedRAS, new JsonCallback() { @Override//from w ww. j a v a 2 s .c o m public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { buttons2.add(running); RiscossJsonClient.rerunRiskAnalysisSession(selectedRAS, "", new RiscossJsonClient.JsonWaitWrapper(new JsonCallback() { @Override public void onSuccess(Method method, JSONValue response) { // Window.alert( "" + response ); try { RiscossJsonClient.getSessionSummary(selectedRAS, new JsonCallback() { @Override public void onSuccess(Method method, JSONValue response) { loadRASSummary(new JsonRiskAnalysis(response)); } @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } }); // report = new RiskAnalysisReport(); r.showResults(sessionSummary, response.isObject()); if (r.getEvidence()) inputDataInfo(response.isObject().get("input")); } catch (Exception ex) { Window.alert(ex.getMessage() + "\n" + response); } } @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } })); } }); }
From source file:eu.riscoss.client.riskanalysis.RASSelectionPanel.java
License:Apache License
public void loadRASList(String entity, String rc) { this.selectedEntity = entity; this.selectedRC = rc; dataProvider.getList().clear();//ww w . ja v a2 s .co m // new Resource( GWT.getHostPageBaseURL() + "api/analysis/" + RiscossJsonClient.getDomain() + "/session/list") // .addQueryParam( "entity", entity ).addQueryParam( "rc", rc ) RiscossJsonClient.listRiskAnalysisSessions(entity, rc, new JsonCallback() { public void onSuccess(Method method, JSONValue response) { if (response == null) return; if (response.isObject() == null) return; response = response.isObject().get("list"); if (response.isArray() != null) { for (int i = 0; i < response.isArray().size(); i++) { JRASInfo info = codec.decode(response.isArray().get(i)); dataProvider.getList().add(info); // JSONObject o = (JSONObject)response.isArray().get( i ); // dataProvider.getList().add( // new RASInfo( o ) ); } } } public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } }); }
From source file:eu.riscoss.client.riskanalysis.RiskAnalysisWizard.java
License:Apache License
public void generateRiskTree() { rightPanel.clear();//from w w w .j a v a2 s . co m riskTree = new TreeWidget(); for (int i = 0; i < models.size(); ++i) { nextRisk = models.get(i); RiscossJsonClient.listRiskAnalysisSessions(selectedEntity, models.get(i), new JsonCallback() { String risk = nextRisk; public void onSuccess(Method method, JSONValue response) { if (response == null) return; if (response.isObject() == null) return; response = response.isObject().get("list"); List<JRASInfo> riskSessions = new ArrayList<>(); CodecRASInfo codec = GWT.create(CodecRASInfo.class); if (response.isArray() != null) { for (int i = 0; i < response.isArray().size(); i++) { JRASInfo info = codec.decode(response.isArray().get(i)); riskSessions.add(info); } } Anchor a = new Anchor("> " + risk); a.setWidth("100%"); a.setStyleName("font"); a.addClickHandler(new ClickHandler() { String name = risk; @Override public void onClick(ClickEvent event) { setSelectedRiskConf(name); } }); HorizontalPanel cPanel = new HorizontalPanel(); cPanel.setStyleName("tree"); cPanel.setWidth("100%"); cPanel.add(a); TreeWidget c = new TreeWidget(cPanel); riskTree.addChild(c); for (int i = 0; i < riskSessions.size(); ++i) { risksses = riskSessions.get(i).getName(); Anchor b = new Anchor(risksses); b.setWidth("100%"); b.setStyleName("font"); b.addClickHandler(new ClickHandler() { String name = risksses; int k = count; @Override public void onClick(ClickEvent event) { setSelectedRiskSes(name, k); } }); list.add(riskSessions.get(i)); ++count; HorizontalPanel dPanel = new HorizontalPanel(); dPanel.setStyleName("tree"); dPanel.setWidth("100%"); dPanel.add(b); TreeWidget d = new TreeWidget(dPanel); c.addChild(d); } } public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } }); } Label rL = new Label("Risk Analysis"); rL.setStyleName("smallTitle"); rightPanel.add(rL); rightPanel.add(riskTree); }
From source file:eu.riscoss.client.riskanalysis.WhatIfAnalysisModule.java
License:Apache License
protected void loadModel(JSONValue response) { HorizontalPanel h = new HorizontalPanel(); h.setSize("100%", "100%"); VerticalPanel left1 = new VerticalPanel(); VerticalPanel left2 = new VerticalPanel(); VerticalPanel left3 = new VerticalPanel(); right1 = new VerticalPanel(); resPanel = new VerticalPanel(); JSONObject jo = response.isObject(); if (jo == null) return;//from w w w . j a v a 2s . c o m if (jo.get("inputs") != null) { JSONArray inputs = jo.get("inputs").isArray(); for (int i = 0; i < inputs.size(); i++) { JSONObject jinput = inputs.get(i).isObject(); IndicatorWidget iw = new IndicatorWidget(jinput); if (i < inputs.size() / 3) left1.add(iw); else if (i >= inputs.size() / 3 && i < 2 * inputs.size() / 3) left2.add(iw); else left3.add(iw); iw.addListener(new IndicatorWidget.Listener() { @Override public void IndicatorValueChanged() { runAnalysis(); } }); indicatorWidgets.put(jinput.get("id").isString().stringValue(), iw); } } Label whatIf = new Label("What-if results"); Label riskSes = new Label("Risk session results"); whatIf.setStyleName("columnTitle"); whatIf.setWidth("100%"); riskSes.setStyleName("columnTitle"); riskSes.setWidth("100%"); right1.add(whatIf); resPanel.add(riskSes); if (jo.get("outputs") != null) { JSONArray inputs = jo.get("outputs").isArray(); for (int i = 0; i < inputs.size(); i++) { JSONObject jinput = inputs.get(i).isObject(); IndicatorWidget rw = new IndicatorWidget(jinput); // RiskWidget rw = new RiskWidget( jinput ); // rw.setValue( "0", "0" ); right1.add(rw); riskWidgets.put(jinput.get("label").isString().stringValue(), rw); } } if (sid != null) { for (JWhatIfItem item : jWhatIfData.items.values()) { for (String id : item.values.keySet()) { if (indicatorWidgets.containsKey(id)) { String s = item.values.get(id); JSONObject json = JSONParser.parseLenient(s).isObject(); String value = json.get("value").isString().stringValue(); indicatorWidgets.get(id).setValue(value); } } } generateRiskSessionResults(); } left1.setSpacing(10); left2.setSpacing(10); left3.setSpacing(10); h.add(left1); h.add(left2); h.add(left3); h.add(right1); if (sid != null) h.add(resPanel); right1.setSpacing(20); right1.setStyleName("rightPanelLayer"); resPanel.setSpacing(20); resPanel.setStyleName("rightPanelLayer"); contentPanel.setWidget(h); ready = true; runAnalysis(); }
From source file:eu.riscoss.client.riskanalysis.WhatIfAnalysisModule.java
License:Apache License
protected void generateRiskSessionResults() { RiscossJsonClient.getSessionResults(sid, new JsonCallback() { @Override//from www . j av a 2 s . c o m public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { JSONArray results = response.isObject().get("hresults").isObject().get("results").isArray(); for (int i = 0; i < results.size(); ++i) { JSONObject jinput = results.get(i).isObject(); IndicatorWidget rw = new IndicatorWidget(jinput); Double d = jinput.get("e").isObject().get("e").isNumber().doubleValue(); rw.setValue(String.valueOf(d)); // RiskWidget rw = new RiskWidget( jinput ); // rw.setValue( "0", "0" ); if (jinput.get("type").isString().stringValue().equals("Goal")) riskSessionWidgetsGoals.put(jinput.get("label").isString().stringValue(), rw); else riskSessionWidgetsRisks.put(jinput.get("label").isString().stringValue(), rw); } for (IndicatorWidget rw : riskSessionWidgetsGoals.values()) { resPanel.add(rw); } for (IndicatorWidget rw : riskSessionWidgetsRisks.values()) { resPanel.add(rw); } sortSimulation(); } }); }
From source file:eu.riscoss.client.riskanalysis.WhatIfAnalysisModule.java
License:Apache License
protected void runAnalysis() { buttons.add(running);//from ww w .j a v a2 s. com if (!ready) { buttons.remove(running); return; } ready = false; JSONObject values = readIndicators(); RiscossJsonClient.runWhatIfAnalysis(models, values, new JsonCallback() { @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); ready = true; } @Override public void onSuccess(Method method, JSONValue object) { ready = true; if (object.isObject() == null) return; JSONArray response = object.isObject().get("results").isArray(); for (int i = 0; i < response.isArray().size(); i++) { JSONObject v = response.isArray().get(i).isObject(); IndicatorWidget rw = riskWidgets.get(v.get("id").isString().stringValue()); if (rw == null) continue; if ("evidence".equals(v.get("datatype").isString().stringValue())) { rw.setValue(v); // rw.setValue( v.get( "p" ).isString().stringValue(), v.get( "m" ).isString().stringValue() ); } else if ("distribution".equals(v.get("datatype").isString().stringValue())) { rw.setValue(v); } } buttons.remove(running); } }); }
From source file:eu.riscoss.client.riskconfs.RiskConfsModule.java
License:Apache License
public void onModuleLoad() { exportJS();/*from w ww.java2s . co m*/ tablePanel = new VerticalPanel(); spTable = new SimplePanel(); RiscossJsonClient.listRCs(new JsonCallback() { public void onSuccess(Method method, JSONValue response) { riskconfsList = response; loadRiskConfsTable(response); } public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } }); rightPanel2 = new SimplePanel(); rightPanel2.setSize("100%", "100%"); mainView.setStyleName("mainViewLayer"); mainView.setWidth("100%"); leftPanel.setStyleName("leftPanelLayer"); leftPanel.setWidth("400px"); //leftPanel.setHeight("100%"); rightPanel.setStyleName("rightPanelLayer"); Label title = new Label("Risk configuration management"); title.setStyleName("title"); page.add(title); HorizontalPanel data = new HorizontalPanel(); data.setStyleName("layerData"); Label name = new Label("Name"); name.setStyleName("text"); data.add(name); riskConfName.setWidth("120px"); riskConfName.setStyleName("layerNameField"); data.add(riskConfName); leftPanel.add(data); Button newRisk = new Button("New configuration"); newRisk.setStyleName("button"); newRisk.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent arg0) { String name = riskConfName.getText().trim(); for (int i = 0; i < riskconfsList.isArray().size(); i++) { JSONObject o = (JSONObject) riskconfsList.isArray().get(i); if (name.equals(o.get("name").isString().stringValue())) { //info: firefox has some problem with this window, and fires assertion errors in dev mode Window.alert("Model name already in use.\nPlease rename file."); return; } } if (name == null || "".equals(name)) return; while (!RiscossUtil.sanitize(name).equals(name)) { name = Window.prompt("Name contains prohibited characters (##,@,\") \nRe-enter name:", ""); if (name == null || "".equals(name)) return; } RiscossJsonClient.createRC(name, new JsonCallback() { @Override public void onFailure(Method method, Throwable exception) { Window.alert(exception.getMessage()); } @Override public void onSuccess(Method method, JSONValue response) { dataProvider.getList() .add(new RCInfo(response.isObject().get("name").isString().stringValue())); //Window.Location.reload(); } }); onRCSelected(name); riskConfName.setText(""); } }); leftPanel.add(newRisk); leftPanel.add(searchFields()); leftPanel.add(spTable); mainView.add(leftPanel); mainView.add(rightPanel); page.add(mainView); page.setWidth("100%"); save = new Button("Save"); save.setStyleName("button"); save.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { saveRiskConfData(); } }); RootPanel.get().add(page); }