Example usage for com.google.gwt.core.client JsonUtils safeEval

List of usage examples for com.google.gwt.core.client JsonUtils safeEval

Introduction

In this page you can find the example usage for com.google.gwt.core.client JsonUtils safeEval.

Prototype

public static native <T extends JavaScriptObject> T safeEval(String json) ;

Source Link

Document

Evaluates a JSON expression safely.

Usage

From source file:org.jbpm.console.ng.ht.forms.client.display.displayers.task.AbstractHumanTaskFormDisplayer.java

License:Apache License

protected void eventListener(String origin, String request) {
    if (origin == null || !origin.endsWith("//" + opener))
        return;/* w w w .  j a  va2  s .co m*/

    ActionRequest actionRequest = JsonUtils.safeEval(request);

    if (ACTION_CLAIM_TASK.equals(actionRequest.getAction()))
        claimFromDisplayer();
    else if (ACTION_START_TASK.equals(actionRequest.getAction()))
        startFromDisplayer();
    else if (ACTION_RELEASE_TASK.equals(actionRequest.getAction()))
        releaseFromDisplayer();
    else if (ACTION_SAVE_TASK.equals(actionRequest.getAction()))
        saveStateFromDisplayer();
    else if (ACTION_COMPLETE_TASK.equals(actionRequest.getAction()))
        completeFromDisplayer();
}

From source file:org.jbpm.console.ng.ht.forms.client.editors.taskform.displayers.AbstractStartProcessFormDisplayer.java

License:Apache License

protected void eventListener(String origin, String request) {
    if (origin == null || !origin.endsWith("//" + opener))
        return;//from w  w  w.j a  v  a  2s. c o  m

    ActionRequest actionRequest = JsonUtils.safeEval(request);

    if (ACTION_START_PROCESS.equals(actionRequest.getAction()))
        startProcessFromDisplayer();
}

From source file:org.jbpm.console.ng.ht.forms.client.editors.taskform.standalone.StandaloneFormDisplayPresenter.java

License:Apache License

protected void eventListener(String origin, String request) {
    if (origin == null || !origin.endsWith("//" + opener))
        return;//from  w  ww .j av  a  2 s  .co  m

    ActionRequest actionRequest = JsonUtils.safeEval(request);

    if (ACTION_START_PROCESS.equals(actionRequest.getAction()))
        startProcess();
    else if (ACTION_CLAIM_TASK.equals(actionRequest.getAction()))
        claimTask();
    else if (ACTION_START_TASK.equals(actionRequest.getAction()))
        startTask();
    else if (ACTION_RELEASE_TASK.equals(actionRequest.getAction()))
        releaseTask();
    else if (ACTION_SAVE_TASK.equals(actionRequest.getAction()))
        saveTaskState();
    else if (ACTION_COMPLETE_TASK.equals(actionRequest.getAction()))
        completeTask();
}

From source file:org.jbpm.workbench.forms.client.display.task.AbstractHumanTaskFormDisplayer.java

License:Apache License

protected void eventListener(String origin, String request) {
    if (origin == null || !origin.endsWith("//" + opener)) {
        return;//ww w  .j  a  va2s  .  c o  m
    }

    ActionRequest actionRequest = JsonUtils.safeEval(request);

    if (ACTION_CLAIM_TASK.equals(actionRequest.getAction())) {
        claimFromDisplayer();
    } else if (ACTION_START_TASK.equals(actionRequest.getAction())) {
        startFromDisplayer();
    } else if (ACTION_RELEASE_TASK.equals(actionRequest.getAction())) {
        releaseFromDisplayer();
    } else if (ACTION_SAVE_TASK.equals(actionRequest.getAction())) {
        saveStateFromDisplayer();
    } else if (ACTION_COMPLETE_TASK.equals(actionRequest.getAction())) {
        completeFromDisplayer();
    }
}

From source file:org.kie.workbench.common.forms.jbpm.client.document.DocumentFieldRendererViewImpl.java

License:Apache License

public void onSubmit(String results) {
    initForm();//from   w  ww  .j  a  v a2 s  .co m
    JavaScriptObject jsResponse = JsonUtils.safeEval(results);

    if (jsResponse != null) {
        JSONObject response = new JSONObject(jsResponse);
        if (response.get("document") != null) {
            JSONObject document = response.get("document").isObject();

            DocumentData data = new DocumentData(document.get("fileName").isString().stringValue(),
                    new Double(document.get("size").isNumber().doubleValue()).longValue(), null);

            data.setContentId(document.get("contentId").isString().stringValue());

            setValue(data, true);
        } else if (response.get("error").isNull() != null) {
            setValue(null, true);
        }
    }
}

From source file:org.kie.workbench.common.forms.jbpm.client.rendering.document.DocumentFieldRendererViewImpl.java

License:Apache License

public void onSubmit(String results) {
    initForm();//from  w  w w. j  a v a 2 s.  c o  m
    JavaScriptObject jsResponse = JsonUtils.safeEval(results);

    if (jsResponse != null) {
        JSONObject response = new JSONObject(jsResponse);
        if (response.get("document") != null) {
            JSONObject document = response.get("document").isObject();

            DocumentData data = new DocumentData(document.get("contentId").isString().stringValue(),
                    document.get("fileName").isString().stringValue(),
                    new Double(document.get("size").isNumber().doubleValue()).longValue(), null,
                    new Double(document.get("lastModified").isNumber().doubleValue()).longValue());

            setValue(data, true);
        } else if (response.get("error").isNull() != null) {
            setValue(null, true);
        }
    }
}

From source file:org.komodo.web.client.panels.vdb.editor.diag.tree.TreeCanvas.java

License:Open Source License

/**
 * Update the tree diagram by parsing the data and passing
 * the root node into the internal update process. 
 */// w  w w. ja va  2s.com
public void update() {
    if (this.rootObjectPath == null)
        return;

    if (LOGGER.isLoggable(Level.FINE))
        LOGGER.fine("Deriving json definition from root object"); //$NON-NLS-1$

    KomodoRpcService service = KomodoRpcService.get();
    service.deriveJsonTree(this.rootObjectPath, new IRpcServiceInvocationHandler<String>() {

        @Override
        public void onReturn(String definition) {
            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.fine("Definition of root object: " + definition); //$NON-NLS-1$

            /*
             * Parse the json of the root data. As more children
             * are added asynchronously to the root data's
             * descendants, new nodes will be added and displayed.
             */
            JavaScriptObject jsRoot = JsonUtils.safeEval(definition);
            if (jsRoot == null) {
                String msg = "Failed to safely evaluate json definition for root object"; //$NON-NLS-1$
                Window.alert(msg);
                LOGGER.severe(msg);
                return;
            }

            /*
             * Casts the js object created by the parser to a tree node.
             */
            root = jsRoot.<TreeNode>cast();

            /* Set the initial location of the root node */
            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.fine("Setting location of root object"); //$NON-NLS-1$

            root.setAttr(HTML_X, (parentWidth - 20) / 3);
            root.setAttr(HTML_Y, TOP_MARGIN);

            if (LOGGER.isLoggable(Level.FINE))
                LOGGER.fine("Collapsing root object's grandchildren"); //$NON-NLS-1$

            /* Collapse everything but root initially */
            if (root.children() != null) {
                root.children().forEach(collapseCallback);
            }

            update(root);
        }

        @Override
        public void onError(Throwable error) {
            Window.alert("An error occurred while drawing diagram. See console for more details."); //$NON-NLS-1$
            LOGGER.log(Level.SEVERE, "Exception from deriving json tree from server", error); //$NON-NLS-1$
        }
    });
}

From source file:org.nsesa.editor.gwt.editor.client.Editor.java

License:EUPL

/**
 * Configures the local//  w  w  w .ja va  2 s  .c  o m
 */
protected void configure() {
    try {
        RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, CONFIGURATION_FILE);

        requestBuilder.sendRequest("", new RequestCallback() {
            @Override
            public void onResponseReceived(Request req, Response resp) {
                final JavaScriptObject configuration;
                try {
                    configuration = JsonUtils.safeEval(resp.getText());
                    clientFactory.setConfiguration(configuration);
                    // configuration ok -- continue
                    LOG.log(Level.INFO, "Successfully read " + CONFIGURATION_FILE);
                } catch (Exception e) {
                    LOG.log(Level.WARNING,
                            "Could parse " + CONFIGURATION_FILE + ", configuration will be empty.", e);
                } finally {
                    // continue with the loading
                    onModuleLoadDeferred();
                }
            }

            @Override
            public void onError(Request res, Throwable throwable) {
                // handle errors
                LOG.log(Level.INFO, "Could not read " + CONFIGURATION_FILE + ", configuration will be empty.",
                        throwable);
                clientFactory.setConfiguration(JavaScriptObject.createObject());
                // configuration failed -- ignore
                onModuleLoadDeferred();
            }
        });
    } catch (RequestException e) {
        LOG.log(Level.SEVERE, "Could not execute GET request to retrieve " + CONFIGURATION_FILE, e);
        clientFactory.setConfiguration(JavaScriptObject.createObject());
        // configuration failed -- ignore
        onModuleLoadDeferred();
    }
}

From source file:org.openremote.client.console.ConsolePresenter.java

License:Open Source License

protected DOM addWidget(Flow flow, Node node, DOM container, String instanceId) {
    LOG.debug("Adding widget: " + node);
    if (node.getProperties() == null) {
        LOG.debug("Node has no properties, skipping...");
        return container;
    }/*from   w ww . jav a  2s .c  o m*/

    JavaScriptObject widgetProperties;
    try {
        widgetProperties = JsonUtils.safeEval(node.getProperties());
    } catch (Exception ex) {
        LOG.warn("Node '" + node + "' has invalid widget properties: " + node.getProperties());
        return container;
    }

    String widgetComponent = (String) ((JsMapFromStringTo) widgetProperties).get("component");
    if (widgetComponent == null) {
        LOG.debug("Widget node has no widget component property: " + node.getProperties());
        return container;
    }

    LOG.debug("Creating widget component: " + widgetComponent);
    View widget = JsUtil.createView(getView(), widgetComponent);

    widget.toggleClass("consoleWidget", true, (elemental.dom.Node) widget);
    widget.set("nodeId", node.getId());
    widget.set("nodeLabel", node.getDefaultedLabel());
    widget.set("persistentPropertyPaths", node.getPersistentPropertyPaths());

    if (widget.get("onWidgetPropertiesChanged") != null) {
        widget.set("widgetProperties", widgetProperties);
    }

    container.appendChild(JsUtil.asElementalElement(widget));

    // Continue manipulating the local DOM of the widget!
    DOM widgetDOM = getDOMRoot(widget);

    for (Slot slot : node.findPropertySlots()) {
        // If this is a source slot without any wires attached, we don't need to add it
        if (slot.isOfType(Slot.TYPE_SOURCE) && flow.findWiresAttachedToSlot(slot.getId()).length == 0)
            continue;
        widgetDOM.appendChild(createWidgetSlot(slot, instanceId));
    }

    return widgetDOM;
}

From source file:org.openremote.client.shell.flowcontrol.FlowControlPresenter.java

License:Open Source License

public FlowControlPresenter(FlowControlView view) {
    super(view);/*from  w w  w .  ja va  2 s .  c  o  m*/

    addListener(ShortcutEvent.class, event -> {
        if (flow == null)
            return;
        if (event.getKey() == 82) {
            getView().toggleFlowControl();
        } else if (event.getKey() == 83) {
            redeployFlow();
        }
    });

    addPrepareListener(ShellCloseEvent.class, this::vetoIfDirty);

    addPrepareListener(FlowEditEvent.class, this::vetoIfDirty);

    addListener(FlowEditEvent.class, event -> {

        flow = event.getFlow();
        notifyPath("flow");

        setFlowUnsaved(event.isUnsaved());
        setFlowDirty(flowUnsaved);

        setDependencies();

        setFlowStatusDetail(new FlowStatusDetail("REQUESTING FLOW STATUS..."));
        dispatch(new ServerSendEvent(new FlowRequestStatusEvent(flow.getId())));

        sendConsoleRefresh(flow);
    });

    addListener(FlowDeletedEvent.class, event -> {
        flow = null;
        notifyPathNull("flow");
        sendConsoleRefresh(null);
    });

    addListener(NodeSelectedEvent.class, event -> {
        selectedNodeId = event.getNodeId();
        notifyPath("selectedNodeId");
    });

    addListener(SessionOpenedEvent.class, event -> {
        dispatch(new ServerSendEvent(new FlowRequestStatusEvent()));
    });

    addListener(FlowStatusEvent.class, event -> {
        if (event.matches(flow)) {
            setFlowStatusDetail(new FlowStatusDetail(event.getPhase()));
        }
    });

    addListener(FlowDeploymentFailureEvent.class, event -> {
        // TODO Better flow deployment failure handling
        if (!event.getPhase().equals(FlowDeploymentPhase.NOT_FOUND)) {
            dispatch(new ShowFailureEvent(
                    "Deployment failure during phase: " + event.getPhase() + " - " + event.getMessage(),
                    10000));
        }

        if (event.matches(flow)) {
            setFlowStatusDetail(new FlowStatusDetail(event));
        }
    });

    addListener(FlowRuntimeFailureEvent.class, event -> {
        // TODO should probably do more when a flow fails at runtime
        dispatch(new ShowFailureEvent(event.getMessage(), 10000));
    });

    addListener(FlowModifiedEvent.class, event -> {
        setFlowStatusDetail(flowStatusDetail);
        setFlowDirty(true);
        if (event.isNotifyConsole()) {
            sendConsoleRefresh(event.getFlow());
        }
    });

    addListener(NodeCreateEvent.class, event -> {
        if (event.matches(flow)) {
            new CreateNodeProcedure(flow.getId(), event.getNodeType(), node -> {

                if (event.getLabel() != null && event.getLabel().length() > 0) {
                    node.setLabel(event.getLabel());
                }

                // TODO Awful
                if (event.getNodeProperties() != null && event.getNodeProperties().length() > 0) {
                    JsMapFromStringTo existingProperties = node.getProperties() != null
                            ? JsonUtils.safeEval(node.getProperties())
                            : JsMapFromStringTo.create();
                    JsMapFromStringTo additionalProperties = JsonUtils.safeEval(event.getNodeProperties());
                    JsArrayOfString additionalKeys = additionalProperties.keys();
                    for (int i = 0; i < additionalKeys.length(); i++) {
                        String key = additionalKeys.get(i);
                        existingProperties.put(key, additionalProperties.get(key));
                    }
                    node.setProperties(JsonUtils.stringify(existingProperties));
                }

                new AddNodeProcedure(event.getPositionX(), event.getPositionY(),
                        event.isApplyPositionAsProperties(), true).accept(node);
            }).call();
        }
    });

    addListener(SubflowNodeCreateEvent.class, event -> {
        if (event.matches(flow)) {
            // Can't add current flow as subflow
            if (flow.getId().equals(event.getSubflowId())) {
                return;
            }
            new CreateSubflowNodeProcedure(flow.getId(), event.getSubflowId(), new AddNodeProcedure(
                    event.getPositionX(), event.getPositionY(), event.isApplyPositionAsProperties(), true))
                            .call();
        }
    });

    addListener(NodeSelectedEvent.class, event -> {
        if (flow != null) {
            Node node = flow.findNode(event.getNodeId());
            if (node != null) {
                dispatch(new NodeEditEvent(flow, node));
            }
        }
    });

    addListener(ConsoleWidgetModifiedEvent.class, event -> {
        if (flow != null) {
            Node node = flow.findNode(event.getNodeId());
            if (node != null) {
                node.setProperties(event.getNodeProperties());
                dispatch(new FlowModifiedEvent(flow, false));
                if (node.getId().equals(selectedNodeId)) {
                    dispatch(new NodePropertiesRefreshEvent(node.getId()));
                }
            }
        }
    });

    addListener(NodeDeleteEvent.class, event -> {
        new DeleteNodeProcedure(event.getNode()).call();
    });

    addListener(NodeDeletedEvent.class, event -> {
        if (event.getNode().getId().equals(selectedNodeId)) {
            selectedNodeId = null;
            notifyPathNull("selectedNodeId");
        }
    });

    addListener(NodeDuplicateEvent.class, event -> {
        if (event.matches(flow)) {
            new DuplicateNodeProcedure(flow.getId(), event.getNode()).call();
        }
    });
}