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

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

Introduction

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

Prototype

public JSONArray isArray() 

Source Link

Document

Returns a non-null reference if this JSONValue is really a JSONArray.

Usage

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

License:Apache License

private void renameAndSave(String newName) {
    newN = newName;/*from  w w  w  .j a  va2s . c o  m*/
    RiscossJsonClient.listEntities(new JsonCallback() {
        @Override
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            if (newN == null || newN.equals("")) {
                return;
            }
            //String s = RiscossUtil.sanitize(txt.getText().trim());//attention:name sanitation is not directly notified to the user
            if (!RiscossUtil.sanitize(newN).equals(newN)) {
                //info: firefox has some problem with this window, and fires assertion errors in dev mode
                Window.alert("Entity name contains prohibited characters (##,@,\") \nPlease re-enter name");
                return;
            }
            for (int i = 0; i < response.isArray().size(); i++) {
                JSONObject o = (JSONObject) response.isArray().get(i);
                if (newN.equals(o.get("name").isString().stringValue())) {
                    Window.alert("Entity name already in use.\nPlease re-enter name.");
                    return;
                }
            }
            RiscossJsonClient.renameEntity(entity, newN, new JsonCallback() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    entity = newN;
                    saveEntity();
                }
            });
        }
    });
}

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

License:Apache License

private void loadRASWidget() {
    RiscossJsonClient.listRCs(entity, new JsonCallback() {
        @Override//from   ww  w  . j ava  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.JsonUtil.java

License:Apache License

public static JSONArray getArray(JSONObject object, String key) {
    if (object == null)
        return EMPTY_ARRAY;
    JSONValue v = object.get(key);
    if (v == null)
        return EMPTY_ARRAY;
    if (v.isArray() == null)
        return EMPTY_ARRAY;
    return v.isArray();
}

From source file:eu.riscoss.client.layers.LayersComboBox.java

License:Apache License

void loadLayers() {
    RiscossJsonClient.listLayers(new JsonCallback() {
        @Override/*from   www. java 2 s. c  o  m*/
        public void onSuccess(Method method, JSONValue response) {
            for (int i = 0; i < response.isArray().size(); i++) {
                JSONObject o = (JSONObject) response.isArray().get(i);
                combo.addItem(o.get("name").isString().stringValue());
            }
        }

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

From source file:eu.riscoss.client.layers.LayersModule.java

License:Apache License

public void onModuleLoad() {
    dock.setSize("100%", "100%");

    mainView.setStyleName("mainViewLayer");
    mainView.setWidth("100%");
    mainViewEntity.setStyleName("mainViewLayer");
    mainViewEntity.setWidth("100%");
    leftPanel.setStyleName("leftPanelLayer");
    leftPanel.setWidth("400px");
    leftPanelEntity.setStyleName("margin-top");
    leftPanelEntity.setWidth("400px");
    rightPanel.setStyleName("rightPanelLayer");
    rightPanelEntity.setStyleName("rightPanelLayer");
    space.setWidth("80px");

    loadLayerTree();/*from   w w w.  j ava2  s.co  m*/

    Label title = new Label("Layer management");
    title.setStyleName("title");
    page.add(title);

    layerData = new HorizontalPanel();
    layerData.setStyleName("layerData");
    Label name = new Label("Name");
    name.setStyleName("bold");
    layerData.add(name);
    layerName.setWidth("120px");
    layerName.setStyleName("layerNameField");
    layerData.add(layerName);
    Label parent = new Label("Parent");
    parent.setStyleName("bold");
    layerData.add(parent);
    parentName.setStyleName("parentNameField");
    layerData.add(parentName);
    leftPanel.add(layerData);

    HorizontalPanel buttons = new HorizontalPanel();

    newLayer = new Button("New layer");
    newLayer.setStyleName("button");
    RiscossJsonClient.listLayers(new JsonCallback() {
        @Override
        public void onSuccess(Method method, JSONValue response) {
            newLayer.addClickHandler(new ClickWrapper<JSONArray>((JSONArray) response.isArray()) {
                @Override
                public void onClick(ClickEvent event) {
                    String name = layerName.getText().trim();

                    if (name == null || name.equals(""))
                        return;

                    //String s = RiscossUtil.sanitize(txt.getText().trim());//attention:name sanitation is not directly notified to the user
                    if (!RiscossUtil.sanitize(name).equals(name)) {
                        //info: firefox has some problem with this window, and fires assertion errors in dev mode
                        Window.alert("Name contains prohibited characters (##,@,\") \nPlease re-enter name");
                        return;
                    }

                    for (int i = 0; i < getValue().size(); i++) {
                        JSONObject o = (JSONObject) getValue().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("Layer name already in use.\nPlease re-enter name.");
                            return;
                        }
                    }

                    selectedLayer = name;
                    String parent = parentName.getValue(parentName.getSelectedIndex());
                    selectedParent = parent;
                    //                  Window.alert( "'" + parent + "': " + "[top]".equals( parent ) );
                    if ("[top]".equals(parent)) {
                        parent = "$root";
                    }

                    RiscossJsonClient.createLayer(name, parent, new JsonCallback() {
                        @Override
                        public void onFailure(Method method, Throwable exception) {
                            Window.alert(exception.getMessage());
                        }

                        @Override
                        public void onSuccess(Method method, JSONValue response) {
                            //Window.Location.reload();
                            layerName.setText("");
                            reloadPage();
                        }
                    });

                }

            });
        }

        @Override
        public void onFailure(Method method, Throwable exception) {

        }
    });

    buttons.add(newLayer);
    leftPanel.add(buttons);

    SimplePanel sp = new SimplePanel();
    sp.setWidget(tree);
    sp.setStyleName("layerList");
    leftPanel.add(searchFields());
    leftPanel.add(sp);
    mainView.add(leftPanel);
    mainView.add(rightPanel);
    leftPanel.add(leftPanelEntity);
    page.add(mainView);
    //mainViewEntity.add(leftPanelEntity);
    //mainViewEntity.add(rightPanelEntity);
    //page.add(mainViewEntity);
    page.setWidth("100%");

    save = new Button("Save");
    save.setStyleName("button");
    save.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            RiscossJsonClient.setLayerDescription(selectedLayer, description.getText(), new JsonCallback() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    saveLayerData();
                }
            });
        }
    });

    generateNewEntityButton();

    RootPanel.get().add(page);

}

From source file:eu.riscoss.client.layers.LayersModule.java

License:Apache License

private void loadLayerTree() {
    RiscossJsonClient.listLayers(new JsonCallback() {
        public void onSuccess(Method method, JSONValue response) {
            if (response.isArray() != null) {
                tree.clear();//from   w ww .  jav  a  2s  .  co  m
                TreeWidget parent = tree;
                tree.asWidget().setWidth("100%");
                for (int i = 0; i < response.isArray().size(); i++) {
                    JSONObject o = (JSONObject) response.isArray().get(i);
                    parentName.addItem(o.get("name").isString().stringValue());
                    if (i > 0)
                        nextParent = ((JSONObject) response.isArray().get(i - 1)).get("name").isString()
                                .stringValue();
                    else
                        nextParent = "[top]";
                    HorizontalPanel p = new HorizontalPanel();
                    p.setStyleName("layerListElement");

                    Anchor anchor = new Anchor(o.get("name").isString().stringValue());
                    anchor.setStyleName("layerListElement");
                    anchor.addClickHandler(new ClickWrapper<String>(o.get("name").isString().stringValue()) {
                        String parent = nextParent;

                        @Override
                        public void onClick(ClickEvent event) {
                            ppg = new LayerPropertyPage();
                            bottom.setUrl("entities.html?layer=" + getValue());
                            ppg.setParent(parent);
                            //ppg.setSelectedLayer(getValue());
                            selectedLayer = getValue();
                            newEntity.setEnabled(true);
                            loadRightPanel();
                        }
                    });

                    p.add(anchor);

                    p.setWidth("100%");

                    TreeWidget lw = new TreeWidget(p);
                    parent.addChild(lw);
                    parent = lw;
                }
                parentName.addItem("[top]");
            }
        }

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

From source file:eu.riscoss.client.layers.LayersModule.java

License:Apache License

private void loadLayerList() {
    RiscossJsonClient.searchLayers(entityQueryString, new JsonCallback() {
        @Override//from  w ww . j  a  va 2 s .  c  o  m
        public void onFailure(Method method, Throwable exception) {
            Window.alert(exception.getMessage());
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            tree.clear();
            for (int i = 0; i < response.isArray().size(); ++i) {
                String name = response.isArray().get(i).isObject().get("name").isString().stringValue();
                nextLayerName = name;
                Anchor a = new Anchor(name);
                a.setWidth("100%");
                a.setStyleName("font");
                a.addClickHandler(new ClickHandler() {
                    String name = nextLayerName;

                    @Override
                    public void onClick(ClickEvent event) {
                        selectedLayer = name;
                        loadRightPanel();
                    }
                });
                HorizontalPanel cPanel = new HorizontalPanel();
                cPanel.setStyleName("tree");
                cPanel.setWidth("100%");
                cPanel.add(a);
                TreeWidget c = new TreeWidget(cPanel);
                tree.addChild(c);

            }
        }
    });
}

From source file:eu.riscoss.client.layers.LayersModule.java

License:Apache License

private void generateNewEntityButton() {
    newEntityButton = new Button("New " + selectedLayer + " entity");
    newEntityButton.setStyleName("button");
    newEntityButton.addClickHandler(new ClickHandler() {
        @Override/*from   ww w .j  av a 2s  .co  m*/
        public void onClick(ClickEvent event) {
            String name = entityName.getText().trim();

            if (name == null || name.equals(""))
                return;

            //String s = RiscossUtil.sanitize(txt.getText().trim());//attention:name sanitation is not directly notified to the user
            if (!RiscossUtil.sanitize(name).equals(name)) {
                //info: firefox has some problem with this window, and fires assertion errors in dev mode
                Window.alert("Name contains prohibited characters (##,@,\") \nPlease re-enter name");
                return;
            }
            newName = name;

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

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    for (int i = 0; i < response.isArray().size(); i++) {
                        JSONObject o = (JSONObject) response.isArray().get(i);
                        if (newName.equals(o.get("name").isString().stringValue())) {
                            //info: firefox has some problem with this window, and fires assertion errors in dev mode
                            Window.alert("Entity name already in use.\nPlease re-enter name.");
                            return;
                        }
                    }
                    RiscossJsonClient.createEntity(newName, selectedLayer, "", new JsonCallback() {
                        @Override
                        public void onFailure(Method method, Throwable exception) {
                            Window.alert(exception.getMessage());
                        }

                        @Override
                        public void onSuccess(Method method, JSONValue response) {
                            selectedEntity = entityName.getText().trim();
                            entityName.setText("");
                            RiscossJsonClient.getLayerContextualInfo(selectedLayer, 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);
                                    reloadEntityInfo();
                                    RiscossJsonClient.listEntities(selectedLayer, new JsonCallback() {
                                        @Override
                                        public void onFailure(Method method, Throwable exception) {
                                        }

                                        @Override
                                        public void onSuccess(Method method, JSONValue response) {
                                            reloadEntityTable(response);
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
        }
    });
}

From source file:eu.riscoss.client.layers.LayersModule.java

License:Apache License

private void saveLayerData() {
    String name = nameL.getText().trim();

    if (name == null || name.equals(""))
        return;/*from www. j a  v  a2  s.com*/

    //String s = RiscossUtil.sanitize(txt.getText().trim());//attention:name sanitation is not directly notified to the user
    if (!RiscossUtil.sanitize(name).equals(name)) {
        //info: firefox has some problem with this window, and fires assertion errors in dev mode
        Window.alert("Name contains prohibited characters (##,@,\") \nPlease re-enter name");
        return;
    }

    RiscossJsonClient.listLayers(new JsonCallback() {
        @Override
        public void onFailure(Method method, Throwable exception) {
        }

        @Override
        public void onSuccess(Method method, JSONValue response) {
            for (int i = 0; i < response.isArray().size(); i++) {
                JSONObject o = (JSONObject) response.isArray().get(i);
                if (nameL.getText().trim().equals(o.get("name").isString().stringValue())
                        && !nameL.getText().trim().equals(selectedLayer)) {
                    //info: firefox has some problem with this window, and fires assertion errors in dev mode
                    Window.alert("Layer name already in use.\nPlease re-enter name.");
                    return;
                }
            }
            RiscossJsonClient.renameLayer(selectedLayer, nameL.getText().trim(), new JsonCallback() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    Window.alert(exception.getMessage());
                }

                @Override
                public void onSuccess(Method method, JSONValue response) {
                    selectedLayer = nameL.getText().trim();
                    final String s = candidateParents.getValue(candidateParents.getSelectedIndex());
                    if (!s.equals(selectedParent) && entities.size() == 0) {
                        RiscossJsonClient.editLayerParent(selectedLayer, s, new JsonCallback() {
                            @Override
                            public void onFailure(Method method, Throwable exception) {
                                Window.alert(exception.getMessage());
                            }

                            @Override
                            public void onSuccess(Method method, JSONValue response) {
                                selectedParent = s;
                                reloadPage();
                            }
                        });
                    } else if (entities.size() > 0 && !s.equals(selectedParent)) {
                        Window.alert("Layers with associated entities cannot modify the parent layer");
                        reloadPage();
                    } else
                        reloadPage();
                }
            });
        }
    });
}

From source file:eu.riscoss.client.layers.LayersModule.java

License:Apache License

private void reloadPage() {
    layerData.remove(parentName);//  w w  w  .  j  a v  a  2 s. co  m
    parentName = new ListBox();
    ppg = new LayerPropertyPage();
    bottom.setUrl("entities.html?layer=" + selectedLayer);
    ppg.setParent(selectedParent);
    //layerName.setText("");
    loadRightPanel();

    RiscossJsonClient.listLayers(new JsonCallback() {

        public void onSuccess(Method method, JSONValue response) {
            if (response.isArray() != null) {
                tree.clear();
                TreeWidget parent = tree;
                tree.asWidget().setWidth("100%");
                parentName = new ListBox();
                for (int i = 0; i < response.isArray().size(); i++) {
                    JSONObject o = (JSONObject) response.isArray().get(i);
                    parentName.addItem(o.get("name").isString().stringValue());
                    if (i > 0)
                        nextParent = ((JSONObject) response.isArray().get(i - 1)).get("name").isString()
                                .stringValue();
                    else
                        nextParent = "[top]";
                    HorizontalPanel p = new HorizontalPanel();
                    p.setStyleName("layerListElement");

                    Anchor anchor = new Anchor(o.get("name").isString().stringValue());
                    anchor.setStyleName("layerListElement");
                    anchor.addClickHandler(new ClickWrapper<String>(o.get("name").isString().stringValue()) {
                        String parent = nextParent;

                        @Override
                        public void onClick(ClickEvent event) {
                            ppg = new LayerPropertyPage();
                            bottom.setUrl("entities.html?layer=" + getValue());
                            ppg.setParent(parent);
                            selectedParent = parent;
                            //ppg.setSelectedLayer(getValue());
                            selectedLayer = getValue();
                            newEntity.setEnabled(true);
                            loadRightPanel();
                        }
                    });

                    p.add(anchor);

                    p.setWidth("100%");

                    TreeWidget lw = new TreeWidget(p);
                    parent.addChild(lw);
                    parent = lw;
                }
                parentName.addItem("[top]");
                layerData.add(parentName);
            }
        }

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

}