Example usage for com.google.gwt.json.client JSONValue isObject

List of usage examples for com.google.gwt.json.client JSONValue isObject

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isObject.

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

From source file:eu.riscoss.client.entities.EntitiesModule.java

License:Apache License

protected void createEntity() {

    RiscossJsonClient.createEntity(entityName.getText(), layerList.getItemText(layerList.getSelectedIndex()),
            "", new JsonCallback() {
                @Override/*from   w w w .  j a  v  a  2s  . c om*/
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    entityName.setText("");
                    newEntity = response.isObject().get("name").isString().stringValue();

                    EntityInfo info = new EntityInfo(newEntity);

                    info.setLayer(JsonUtil.getValue(response, "layer", ""));

                    reloadData();

                    RiscossJsonClient.getLayerContextualInfo(
                            layerList.getItemText(layerList.getSelectedIndex()), new JsonCallback() {
                                @Override
                                public void onFailure(Method method, Throwable exception) {
                                    Window.alert(exception.getMessage());
                                }

                                @Override
                                public void onSuccess(Method method, JSONValue response) {
                                    CodecLayerContextualInfo codec = GWT.create(CodecLayerContextualInfo.class);
                                    JLayerContextualInfo jLayerContextualInfo = codec.decode(response);
                                    updateContextualInfo(jLayerContextualInfo);
                                }
                            });

                }
            });
}

From source file:eu.riscoss.client.entities.EntitiesModule.java

License:Apache License

protected void hasRiskSessions() {
    hasRisk = false;//from w  w w.j  av a 2  s  . co  m
    RiscossJsonClient.listRiskAnalysisSessions(selectedEntity, "", new JsonCallback() {
        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            if (response.isObject().get("list").isArray().size() > 0)
                hasRisk = true;
            deleteEntity();
        }
    });
}

From source file:eu.riscoss.client.entities.EntityPropertyPage.java

License:Apache License

public void saveEntityData(String newName, String newLayer) {
    newN = newName;/*from ww w  . j ava 2 s  .c  om*/
    newL = newLayer;
    RiscossJsonClient.listRiskAnalysisSessions(entity, "", new JsonCallback() {
        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            if (!newL.equals(layer) && (parentList.size() > 0 || childrenList.size() > 0)) {
                Window.alert("Entities with parents or children cannot modify the layer");
                return;
            }
            if (response == null)
                return;
            if (response.isObject() == null)
                return;
            response = response.isObject().get("list");
            if (!newL.equals(layer) && response.isArray().size() > 0) {
                Window.alert("Entities with associated risk analysis sessions cannot modify the layer");
                return;
            }
            if (!newL.equals(layer) && response.isArray().size() == 0) {
                RiscossJsonClient.editLayer(entity, newL, new JsonCallback() {
                    @Override
                    public void onFailure(Method method, Throwable exception) {
                        Window.alert(exception.getMessage());
                    }

                    @Override
                    public void onSuccess(Method method, JSONValue response) {
                        if (!newN.equals(entity)) {
                            renameAndSave(newN);
                        } else {
                            saveEntity();
                        }
                    }
                });
            } else if (newL.equals(layer)) {
                if (!newN.equals(entity)) {
                    renameAndSave(newN);
                } else {
                    saveEntity();
                }
            }
        }
    });

}

From source file:eu.riscoss.client.entities.EntityPropertyPage.java

License:Apache License

private void loadRASWidget() {
    RiscossJsonClient.listRCs(entity, new JsonCallback() {
        @Override//from w w  w  .j  a v a  2  s  .co m
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            models = new ArrayList<String>();
            for (int i = 0; i < response.isArray().size(); i++) {
                JSONObject o = (JSONObject) response.isArray().get(i);
                models.add(o.get("name").isString().stringValue());
            }
            riskTree = new TreeWidget();
            for (int i = 0; i < models.size(); ++i) {
                nextRisk = models.get(i);
                RiscossJsonClient.listRiskAnalysisSessions(entity, 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);
                            }
                        }
                        Label a = new Label("> " + risk);
                        a.setWidth("100%");
                        a.setStyleName("bold");
                        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());
                    }
                });

            }
            panel = new VerticalPanel();
            panel.add(riskTree);
            newRasPanel.setWidget(panel);
        }
    });

}

From source file:eu.riscoss.client.entities.RDCConfigurationPage.java

License:Apache License

public void setSelectedEntity(String entity) {
    this.entity = entity;
    RiscossJsonClient.listRDCs(entity, new JsonCallback() {
        @Override// w w w. j  a  va2  s .c  o  m
        public void onSuccess(Method method, JSONValue response) {
            //            Window.alert( "" + response );
            enabledMap = new JsonRDCValueMap(response);
            RiscossJsonClient.listRDCs(new JsonCallback() {
                @Override
                public void onSuccess(Method method, JSONValue response) {
                    rdcMap = new JsonRDCMap(response);
                    loadRDCs(response.isObject());
                }

                @Override
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }
            });
        }

        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }
    });

}

From source file:eu.riscoss.client.JsonEntitySummary.java

License:Apache License

public JsonEntitySummary(JSONValue val) {
    if (val != null) {
        json = val.isObject();
    }//from ww  w  .  j av a 2  s  .  com
    if (json == null)
        json = new JSONObject();

    userData = new UserData(json.get("userdata"));
}

From source file:eu.riscoss.client.JsonRDCMap.java

License:Apache License

public JsonRDCMap(JSONValue jsonValue) {
    this.json = jsonValue.isObject();
    if (this.json == null) {
        this.json = new JSONObject();
    }//from  w w w . j av  a2 s  .  com
}

From source file:eu.riscoss.client.JsonRDCMap.java

License:Apache License

JSONObject requestRDCObject(String rdcName) {
    JSONValue v = json.get(rdcName);
    if (v == null) {
        v = new JSONObject();
        json.put(rdcName, v);/*from  w  w  w.  java2 s . c o  m*/
    } else if (v.isObject() == null) {
        v = new JSONObject();
        json.put(rdcName, v);
    }
    return json.get(rdcName).isObject();
}

From source file:eu.riscoss.client.JsonRDCValueMap.java

License:Apache License

public JsonRDCValueMap(JSONValue json) {
    this.root = json.isObject();
    if (root == null)
        root = new JSONObject();
}

From source file:eu.riscoss.client.JsonRDCValueMap.java

License:Apache License

public boolean isEnabled(String rdcName) {
    JSONValue v = root.get(rdcName);
    if (v == null)
        return false;
    if (v.isObject() == null)
        return false;
    JSONObject o = v.isObject();// ww w .  ja  v  a  2  s .c o m
    if (o.get("enabled") == null)
        return false;
    if (o.get("enabled").isBoolean() == null)
        return false;
    return (o.get("enabled").isBoolean().booleanValue() == true);
}