Example usage for com.google.gwt.json.client JSONNumber JSONNumber

List of usage examples for com.google.gwt.json.client JSONNumber JSONNumber

Introduction

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

Prototype

public JSONNumber(double value) 

Source Link

Document

Creates a new JSONNumber from the double value.

Usage

From source file:org.onebusaway.webapp.gwt.notification.NotificationStateDAO.java

License:Apache License

private JSONObject getNodeAsJSONObject(NotificationStateNode node) {
    JSONObject obj = new JSONObject();
    obj.put(KEY_ID, new JSONString(node.getStopId()));
    obj.put(KEY_INDEX, new JSONNumber(node.getIndex()));
    obj.put(KEY_STATE, getStateAsJSONObject(node.getState()));
    return obj;/*  w  w  w .ja v a2s  .  c o  m*/
}

From source file:org.onebusaway.webapp.gwt.notification.NotificationStateDAO.java

License:Apache License

private JSONObject getStateAsJSONObject(NotificationState state) {
    JSONObject obj = new JSONObject();
    obj.put(KEY_MINUTES_BEFORE, new JSONNumber(state.getMinutesBefore()));
    JSONArray methods = new JSONArray();
    int index = 0;
    for (NotificationMethodState methodState : state.getMethodStates()) {
        JSONObject methodObject = getMethodStateAsJSONObject(methodState);
        methods.set(index++, methodObject);
    }//from  www.j a  v a2 s  . c om
    obj.put(KEY_METHODS, methods);
    return obj;
}

From source file:org.opennms.features.vaadin.topology.gwt.client.GraphJSONConverter.java

License:Open Source License

private static JSONValue getVertex(GWTVertex vertex) {
    JSONArray array = new JSONArray();
    array.set(0, new JSONString("vertex"));

    JSONObject obj = new JSONObject();
    obj.put("id", new JSONString(vertex.getId()));
    obj.put("x", new JSONNumber(vertex.getX()));
    obj.put("y", new JSONNumber(vertex.getY()));

    array.set(1, obj);// w  ww. j av  a  2  s . com
    return array;
}

From source file:org.openremote.app.client.interop.chartjs.ChartUtil.java

License:Open Source License

static public JavaScriptObject convertData(NumberDatapoint[] numberDatapoints) {
    JSONArray array = new JSONArray();
    for (int i = 0; i < numberDatapoints.length; i++) {
        NumberDatapoint numberDatapoint = numberDatapoints[i];
        Number number = numberDatapoint.getNumber();
        if (number != null) {
            array.set(i, new JSONNumber(number.doubleValue()));
        } else {//  w  w  w  . j  a v a 2 s .c  o m
            array.set(i, null);
        }
    }
    return array.getJavaScriptObject();
}

From source file:org.overlord.gadgets.web.client.widgets.AddTabForm.java

License:Open Source License

public void addNewTab() {
    String name = tabName.getValue();
    String colNum = layoutColumns.getValue(layoutColumns.getSelectedIndex());

    Log.debug("the tab name is: " + name + ", and the colNum is: " + colNum + ", the userId : "
            + currentUser.getUserId());//from   w  w w.ja  v a2 s. c  o m

    JSONObject postData = new JSONObject();
    postData.put("name", new JSONString(name));
    postData.put("columns", new JSONNumber(Long.valueOf(colNum)));

    RestfulInvoker.invoke(RequestBuilder.POST, URLBuilder.getAddPageURL(currentUser.getUserId()),
            postData.toString(), new RestfulInvoker.Response() {

                public void onResponseReceived(Request request, Response response) {
                    Log.debug("The response is: " + response.getText() + ", and the currentUser is : "
                            + currentUser);
                    String newPageId = response.getText();
                    PortalLayout portal = new PortalLayout(newPageId,
                            Integer.valueOf(layoutColumns.getValue(layoutColumns.getSelectedIndex())));
                    tab.insertTab(newPageId, tabName.getValue(), portal);
                    tabName.setValue("");
                    currentUser.setCurrentPage(Long.valueOf(newPageId));
                }
            });

}

From source file:org.parseplatform.client.Subscription.java

License:Open Source License

public void on(String event, final ParseAsyncCallback<ParseObject> callback) {
    //throw new RuntimeException("Websocket is not yet connected");
    final String subcribeOp = event;
    socket = new Websocket("ws://" + Parse.getUri());
    socket.open();//from w ww  . ja v a  2  s.  co  m
    socket.addListener(new WebsocketListener() {
        @Override
        public void onClose() {
            //                    Browser.getWindow().getConsole().log("onClose");
        }

        @Override
        public void onMessage(String s) {
            //                    Browser.getWindow().getConsole().log("Message: " + s);
            JSONObject message = (JSONObject) JSONParser.parseStrict(s);
            if ((message.get("op") != null) && (message.get("op").isString() != null)) {
                String op = message.get("op").isString().stringValue();
                if (op.equalsIgnoreCase("connected")) {
                    setIsConnected(true);
                    JSONObject connect = new JSONObject();
                    connect.put("op", new JSONString("subscribe"));
                    connect.put("requestId", new JSONNumber(1L));
                    JSONObject query = new JSONObject();
                    query.put("className", new JSONString("Order"));
                    query.put("where", new Where("status", new JSONString("new")));
                    connect.put("query", query);
                    socket.send(connect.toString());
                } else if (op.equalsIgnoreCase("enter") || op.equalsIgnoreCase("create")
                        || op.equalsIgnoreCase("leave")) {
                    if (subcribeOp.equals(op)) {
                        JSONObject jsonObject = message.get("object").isObject();
                        ParseObject parseObject = new ParseObject(className, jsonObject);
                        callback.onSuccess(parseObject);
                    }
                } else if (op.equalsIgnoreCase("update")) {
                    if (subcribeOp.equals(op)) {
                        JSONObject jsonObject = message.get("object").isObject();
                        ParseObject parseObject = new ParseObject(className, jsonObject);
                        callback.onSuccess(parseObject);
                    }
                }
            }
        }

        @Override
        public void onOpen() {
            //                    Browser.getWindow().getConsole().log("onOpen");
            JSONObject connect = new JSONObject();
            connect.put("op", new JSONString("connect"));
            connect.put("applicationId", new JSONString(Parse.X_Parse_Application_Id));
            connect.put("restAPIKey", new JSONString(Parse.X_Parse_REST_API_Key));
            socket.send(connect.toString());
        }
    });
}

From source file:org.pentaho.mantle.client.commands.RunInBackgroundCommand.java

License:Open Source License

@SuppressWarnings("deprecation")
protected JSONObject getJsonSimpleTrigger(int repeatCount, int interval, Date startDate, Date endDate) {
    JSONObject trigger = new JSONObject();
    trigger.put("repeatInterval", new JSONNumber(interval)); //$NON-NLS-1$
    trigger.put("repeatCount", new JSONNumber(repeatCount)); //$NON-NLS-1$
    trigger.put("startTime", //$NON-NLS-1$
            startDate != null/*from w w w .j ava  2  s  .  c  o m*/
                    ? new JSONString(DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDate))
                    : JSONNull.getInstance());
    if (endDate != null) {
        endDate.setHours(23);
        endDate.setMinutes(59);
        endDate.setSeconds(59);
    }
    trigger.put("endTime", endDate == null ? JSONNull.getInstance() //$NON-NLS-1$
            : new JSONString(DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate)));
    return trigger;
}

From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog.java

License:Open Source License

protected JSONObject getJsonSimpleTrigger(int repeatCount, int interval, Date startDate, Date endDate) {
    JSONObject trigger = new JSONObject();
    trigger.put("uiPassParam", new JSONString(scheduleEditorWizardPanel.getScheduleType().name())); //$NON-NLS-1$
    trigger.put("repeatInterval", new JSONNumber(interval)); //$NON-NLS-1$
    trigger.put("repeatCount", new JSONNumber(repeatCount)); //$NON-NLS-1$
    addJsonStartEnd(trigger, startDate, endDate);
    return trigger;
}

From source file:org.pentaho.mantle.client.dialogs.scheduling.ScheduleRecurrenceDialog.java

License:Open Source License

protected boolean addBlockoutPeriod(final JSONObject schedule, final JsJobTrigger trigger, String urlSuffix) {
    String url = ScheduleHelper.getFullyQualifiedURL() + "api/scheduler/blockout/" + urlSuffix; //$NON-NLS-1$

    RequestBuilder addBlockoutPeriodRequest = new RequestBuilder(RequestBuilder.POST, url);
    addBlockoutPeriodRequest.setHeader("accept", "text/plain"); //$NON-NLS-1$ //$NON-NLS-2$
    addBlockoutPeriodRequest.setHeader("Content-Type", "application/json"); //$NON-NLS-1$ //$NON-NLS-2$
    addBlockoutPeriodRequest.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

    // Create a unique blockout period name
    final Long duration = trigger.getBlockDuration();
    final String blockoutPeriodName = trigger.getScheduleType() + Random.nextInt() + ":" + //$NON-NLS-1$
    /* PentahoSessionHolder.getSession().getName() */"admin" + ":" + duration; //$NON-NLS-1$ //$NON-NLS-2$

    // Add blockout specific parameters
    JSONObject addBlockoutParams = schedule;
    addBlockoutParams.put("jobName", new JSONString(blockoutPeriodName)); //$NON-NLS-1$
    addBlockoutParams.put("duration", new JSONNumber(duration)); //$NON-NLS-1$
    addBlockoutParams.put("timeZone", new JSONString(scheduleEditorWizardPanel.getTimeZone()));

    try {//from   w  ww  .j av  a  2s . co  m
        addBlockoutPeriodRequest.sendRequest(addBlockoutParams.toString(), new RequestCallback() {
            @Override
            public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        exception.toString(), false, false, true);
                dialogBox.center();
                setDone(false);
            }

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == Response.SC_OK) {
                    if (null != callback) {
                        callback.okPressed();
                    }
                }
            }
        });
    } catch (RequestException e) {
        // ignored
    }

    return true;
}

From source file:org.pentaho.mantle.client.solutionbrowser.filepicklist.FavoritePickItem.java

License:Open Source License

public JSONObject toJson() {
    JSONObject jso = new JSONObject();
    jso.put("fullPath", new JSONString(fullPath));
    if (lastUse != null) {
        jso.put("title", new JSONString(title));
        jso.put("lastUse", new JSONNumber(lastUse));
    }/*  w  w w. j a v a  2  s. c om*/
    return jso;
}