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.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

@Override
public void setShinyViewerType(int viewerType, ServerRequestCallback<Void> requestCallback) {
    JSONArray params = new JSONArray();
    params.set(0, new JSONNumber(viewerType));
    sendRequest(RPC_SCOPE, SET_SHINY_VIEWER_TYPE, params, requestCallback);
}

From source file:org.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

@Override
public void registerUserToken(String serverName, String accountName, int userId, RSConnectPreAuthToken token,
        ServerRequestCallback<Void> requestCallback) {
    JSONArray params = new JSONArray();
    params.set(0, new JSONString(serverName));
    params.set(1, new JSONString(accountName));
    params.set(2, new JSONNumber(userId));
    params.set(3, new JSONString(token.getToken()));
    params.set(4, new JSONString(token.getPrivateKey()));
    sendRequest(RPC_SCOPE, REGISTER_USER_TOKEN, params, requestCallback);
}

From source file:org.rstudio.studio.client.server.remote.RemoteServer.java

License:Open Source License

@Override
public void renderRmd(String file, int line, String format, String encoding, boolean asTempfile,
        boolean asShiny, ServerRequestCallback<Boolean> requestCallback) {
    JSONArray params = new JSONArray();
    params.set(0, new JSONString(file));
    params.set(1, new JSONNumber(line));
    params.set(2, new JSONString(StringUtil.notNull(format)));
    params.set(3, new JSONString(encoding));
    params.set(4, JSONBoolean.getInstance(asTempfile));
    params.set(5, JSONBoolean.getInstance(asShiny));
    sendRequest(RPC_SCOPE, RENDER_RMD, params, requestCallback);
}

From source file:org.rstudio.studio.client.workbench.views.plots.ui.manipulator.ManipulatorControlSlider.java

License:Open Source License

public ManipulatorControlSlider(String variable, double value, Manipulator.Slider slider,
        ManipulatorChangedHandler changedHandler) {
    super(variable, slider, changedHandler);

    // get manipulator styles
    ManipulatorStyles styles = ManipulatorResources.INSTANCE.manipulatorStyles();

    // containing panel
    VerticalPanel panel = new VerticalPanel();

    // setup caption panel and add it
    HorizontalPanel captionPanel = new HorizontalPanel();

    Label captionLabel = new Label();
    captionLabel.setStyleName(styles.captionLabel());
    captionLabel.setText(getLabel() + ":");
    captionPanel.add(captionLabel);//from   w ww. j  ava2s  .co  m
    final Label valueLabel = new Label();
    valueLabel.setStyleName(styles.sliderValueLabel());
    captionPanel.add(valueLabel);
    panel.add(captionPanel);

    // create with range and custom formatter
    final double min = slider.getMin();
    final double max = slider.getMax();
    final double range = max - min;
    sliderBar_ = new SliderBar(min, max, this);

    // show labels only at the beginning and end
    sliderBar_.setNumLabels(1);

    // set step size (default to 1 or continuous decimal as appropriate)
    double step = slider.getStep();
    if (step == -1) {
        // short range or decimals means continous decimal
        if (range < 2 || hasDecimals(max) || hasDecimals(min))
            step = range / 250; // ~ one step per pixel
        else
            step = 1;
    }
    sliderBar_.setStepSize(step);

    // optional tick marks 
    if (slider.getTicks()) {
        double numTicks = range / step;
        if (numTicks <= 25) // no more than 25 ticks
            sliderBar_.setNumTicks(new Double(numTicks).intValue());
        else
            sliderBar_.setNumTicks(1);
    } else {
        // always at beginning and end
        sliderBar_.setNumTicks(1);
    }

    // update label on change
    sliderBar_.addChangeListener(new ChangeListener() {
        @Override
        public void onChange(Widget sender) {
            valueLabel.setText(formatLabel(sliderBar_, sliderBar_.getCurrentValue()));
        }
    });
    sliderBar_.setCurrentValue(value);

    // fire changed even on slide completed
    sliderBar_.addSlideCompletedListener(new ChangeListener() {
        @Override
        public void onChange(Widget sender) {
            ManipulatorControlSlider.this.onValueChanged(new JSONNumber(sliderBar_.getCurrentValue()));
        }

    });

    // add slider bar and fully initialize widget
    panel.add(sliderBar_);
    initWidget(panel);
    addControlStyle(styles.slider());
}

From source file:org.sakaiproject.gradebook.gwt.client.gxt.controller.ServiceController.java

License:Educational Community License

private void onUpdateGradeMap(final GradeMapUpdate event) {
    Gradebook selectedGradebook = Registry.get(AppConstants.CURRENT);
    final Record record = event.record;

    String gradebookUid = selectedGradebook.getGradebookUid();
    String gradebookId = String.valueOf(selectedGradebook.getGradebookId());
    String letterGrade = (null != record) ? (String) record.get(GradeMapKey.S_LTR_GRD.name()) : null;

    RestBuilder builder = RestBuilder.getInstance(Method.PUT, GWT.getModuleBaseURL(),
            AppConstants.REST_FRAGMENT, AppConstants.GRADE_MAP_FRAGMENT, gradebookUid, gradebookId,
            letterGrade);/*from   w w  w  .j a va 2 s. c o  m*/

    Double value = record == null ? null : (Double) event.value;
    Double startValue = record == null ? null : (Double) event.startValue;

    JSONObject json = new JSONObject();
    if (value != null)
        json.put(AppConstants.VALUE_CONSTANT, new JSONNumber(value.doubleValue()));
    if (startValue != null)
        json.put(AppConstants.START_VALUE_CONSTANT, new JSONNumber(startValue.doubleValue()));

    builder.sendRequest(204, 400, json.toString(), new RestCallback() {

        @Override
        public void onFailure(Request request, Throwable exception) {
            super.onFailure(request, exception);
            Dispatcher.forwardEvent(GradebookEvents.GradeScaleUpdateError.getEventType());
            record.reject(false);
        }

        @Override
        public void onSuccess(Request request, Response response) {
            Gradebook selectedGradebook = Registry.get(AppConstants.CURRENT);
            Dispatcher.forwardEvent(GradebookEvents.RefreshGradeScale.getEventType(), selectedGradebook);
            record.commit(false);
        }

    });
}

From source file:org.sakaiproject.gradebook.gwt.client.gxt.controller.ServiceController.java

License:Educational Community License

private void onUpdateGradeRecord(final GradeRecordUpdate event) {

    final Gradebook selectedGradebook = Registry.get(AppConstants.CURRENT);

    ClassType classType = DataTypeConversionUtil.lookupClassType(event.property,
            selectedGradebook.getGradebookItemModel().getGradeType());

    final Record record = event.record;
    if ((event.oldValue == null || event.oldValue.equals(""))
            && (event.value == null || event.value.equals("")))
        return;//from   w w  w. j a  v a 2  s  . c  om

    final UserEntityUpdateAction<ModelData> action = new UserEntityUpdateAction<ModelData>(selectedGradebook,
            record.getModel(), event.property, classType, event.value, event.oldValue);

    String gradebookUid = selectedGradebook.getGradebookUid();
    String entity = null;
    String studentUid = (String) record.getModel().get(LearnerKey.S_UID.name());
    String itemId = (String) event.property;

    JSONObject json = new JSONObject();

    switch (classType) {
    case BOOLEAN:
        if (event.value != null)
            json.put(AppConstants.BOOL_VALUE_CONSTANT,
                    JSONBoolean.getInstance(DataTypeConversionUtil.checkBoolean((Boolean) event.value)));
        if (event.oldValue != null)
            json.put(AppConstants.BOOL_START_VALUE_CONSTANT,
                    JSONBoolean.getInstance(DataTypeConversionUtil.checkBoolean((Boolean) event.oldValue)));
        entity = AppConstants.EXCUSE_FRAGMENT;
        break;
    case STRING:
        if (event.value != null)
            json.put(AppConstants.STR_VALUE_CONSTANT, new JSONString((String) event.value));
        if (event.oldValue != null)
            json.put(AppConstants.STR_START_VALUE_CONSTANT, new JSONString((String) event.oldValue));
        json.put(AppConstants.NUMERIC_FRAGMENT, JSONBoolean.getInstance(false));
        entity = AppConstants.STRING_FRAGMENT;
        break;
    case DOUBLE:
        if (event.value != null)
            json.put(AppConstants.VALUE_CONSTANT, new JSONNumber((Double) event.value));
        if (event.oldValue != null)
            json.put(AppConstants.START_VALUE_CONSTANT, new JSONNumber((Double) event.oldValue));
        json.put(AppConstants.NUMERIC_FRAGMENT, JSONBoolean.getInstance(true));
        entity = AppConstants.NUMERIC_FRAGMENT;
        break;
    }

    if (event.property.startsWith(AppConstants.COMMENT_TEXT_FLAG))
        entity = "comment";

    RestBuilder builder = RestBuilder.getInstance(Method.PUT, GWT.getModuleBaseURL(),
            AppConstants.REST_FRAGMENT, AppConstants.LEARNER_FRAGMENT, entity, gradebookUid, itemId,
            Base64.encode(studentUid));

    builder.sendRequest(200, 400, json.toString(), new RestCallback() {

        public void onError(Request request, Throwable exception) {
            super.onError(request, exception);
            record.beginEdit();
            onUpdateGradeRecordFailure(event, exception);
            record.endEdit();
        }

        public void onFailure(Request request, Throwable exception) {
            record.beginEdit();
            onUpdateGradeRecordFailure(event, exception);
            record.endEdit();
        }

        public void onSuccess(Request request, Response response) {

            EntityOverlay overlay = JsonUtil.toOverlay(response.getText());
            LearnerModel result = new LearnerModel(overlay);

            record.beginEdit();
            onUpdateGradeRecordSuccess(event, result);
            record.endEdit();

            Dispatcher.forwardEvent(GradebookEvents.LearnerGradeRecordUpdated.getEventType(), action);
        }

    });
}

From source file:org.sonatype.nexus.gwt.ui.client.data.JSONResourceParser.java

License:Open Source License

private JSONValue parseObject(Object value) {
    JSONValue json = null;/* w w  w .j  a va2  s  . c  o  m*/
    if (value instanceof String) {
        json = new JSONString((String) value);
    } else if (value instanceof Boolean) {
        json = JSONBoolean.getInstance(((Boolean) value).booleanValue());
    } else if (value instanceof Number) {
        json = new JSONNumber(((Number) value).doubleValue());
    }
    return json == null ? JSONNull.getInstance() : json;
}

From source file:org.spiffyui.spsample.client.UnitTestPanel.java

License:Apache License

private static void jsonTests() {
    expect(16);//from w ww . j  a  va  2  s.co  m

    String testString = "Test String";

    JSONObject obj = new JSONObject();
    obj.put("stringVal", new JSONString(testString));
    obj.put("intVal", new JSONNumber(99));
    obj.put("intStringVal", new JSONString("99"));
    obj.put("booleanVal", JSONBoolean.getInstance(true));
    obj.put("booleanStringVal", new JSONString("true"));
    obj.put("dateStringVal", new JSONString("1293373801745"));

    /*
     String tests
     */
    ok(testString.equals(JSONUtil.getStringValue(obj, "stringVal")),
            "Getting string value should be Test String.  It was " + JSONUtil.getStringValue(obj, "stringVal"));

    ok(testString.equals(JSONUtil.getStringValueIgnoreCase(obj, "stringval")),
            "Getting string value ignore case should be Test String.  It was "
                    + JSONUtil.getStringValueIgnoreCase(obj, "stringval"));

    ok(testString.equals(JSONUtil.getStringValue(obj, "stringValBogus", testString)),
            "Getting string value with default should be Test String.  It was "
                    + JSONUtil.getStringValue(obj, "stringValBogus", testString));

    ok(null == JSONUtil.getStringValue(obj, "stringValBogus"),
            "Getting string value with no default should be Test String.  It was "
                    + JSONUtil.getStringValue(obj, "stringValBogus"));

    /*
     int tests
     */
    ok(99 == JSONUtil.getIntValue(obj, "intVal"),
            "Getting int value should be 99.  It was " + JSONUtil.getIntValue(obj, "intVal"));

    ok(99 == JSONUtil.getIntValue(obj, "intValBogus", 99),
            "Getting int value with default should be 99.  It was "
                    + JSONUtil.getIntValue(obj, "intValBogus", 99));

    ok(-1 == JSONUtil.getIntValue(obj, "intValBogus"),
            "Getting int value with no default should be -1.  It was "
                    + JSONUtil.getIntValue(obj, "intValBogus"));

    ok(99 == JSONUtil.getIntValue(obj, "intStringVal"),
            "Getting int value with string parsing should be 99.  It was "
                    + JSONUtil.getIntValue(obj, "intStringVal"));

    /*
     boolean tests
     */
    ok(JSONUtil.getBooleanValue(obj, "booleanVal"),
            "Getting boolean value should be true.  It was " + JSONUtil.getBooleanValue(obj, "booleanVal"));

    ok(!JSONUtil.getBooleanValue(obj, "booleanBogusVal"),
            "Getting boolean value with no default should be true.  It was "
                    + JSONUtil.getBooleanValue(obj, "booleanBogusVal"));

    ok(JSONUtil.getBooleanValue(obj, "booleanStringVal"),
            "Getting boolean value with string parsing should be true.  It was "
                    + JSONUtil.getBooleanValue(obj, "booleanStringVal"));

    /*
     Date tests
     */
    ok(null != JSONUtil.getDateValue(obj, "dateStringVal"),
            "Getting Date value should be a valid object.  It was "
                    + JSONUtil.getDateValue(obj, "dateStringVal"));

    ok("12/26/2010 9:30 AM"
            .equals(JSDateUtil.getShortDateTime(getOffsetDate(JSONUtil.getDateValue(obj, "dateStringVal")))),
            "Getting Date value short date and time should be 12/26/2010 9:30 AM.  It was "
                    + JSDateUtil.getShortDateTime(getOffsetDate(JSONUtil.getDateValue(obj, "dateStringVal"))));

    ok(null == JSONUtil.getDateValue(obj, "dateStringBogusVal"),
            "Getting Date value of invalid field should be null.  It was "
                    + JSONUtil.getDateValue(obj, "dateStringBogusVal"));

    /*
     Case ignoring tests
     */
    ok(JSONUtil.containsKeyIgnoreCase(obj, "StRiNgVaL"),
            "The object should contain the key StRiNgVaL when ignoring case and contains key was "
                    + JSONUtil.containsKeyIgnoreCase(obj, "StRiNgVaL"));

    ok(null != JSONUtil.getIgnoreCase(obj, "StRiNgVaL"),
            "The object should return a value for the key StRiNgVaL when ignoring case.  The value was "
                    + JSONUtil.getIgnoreCase(obj, "StRiNgVaL"));
}

From source file:org.thechiselgroup.biomixer.client.visualization_component.matrix.NeoD3MatrixWidget.java

License:Apache License

public void updateView(HashSet<VisualItem> concepts, UnionResourceSet mappingResources) {
    /*-/*w  w w .  j  ava  2  s  .  co m*/
     * (Trick: this dash prevents code formatting from clobbering my layout below!)
     * (The @ formatter stuff I tried malfunctioned...)
     * 
     * We need to convert our Java structures to json.
     * The D3 will want the concepts as "nodes" and the mappings as "links".
     * The links will have numerically addressed "source" and "target" each,
     * relative to the index of the nodes in question.
     * The data format expected by D3 is like below:
     * 
     * {
     *      "nodes":[
     *         {"name":"CHEBI_48961","group":0}, 
     *         {"name":"GO_0009493","group":1}, 
     *         {"name":"CHEBI_38553","group":0}, 
     *         {"name":"GO_0005489","group":1}, 
     *         {"name":"D000456","group":2}, 
     *         {"name":"Alga","group":4}
     *     ],
     *     "links":[
     *         {"source":0, "target":1, "value": 1},
     *         {"source":2, "target":3, "value": 1},
     *         {"source":120, "target":119, "value": 1},
     *         {"source":126, "target":125, "value": 1},
     *         {"source":94, "target":118, "value": 1}
     *     ]
     *  }
     * 
     */

    // Converting this is horrible. Part of the problem is that the links
    // use array indices rather than the string reference.
    // The other problem is that the links are separated from their nodes.
    // In the original RESTreturn values, the links are embedded in the
    // nodes, essentially.

    HashMap<String, Integer> conceptIndices = new HashMap<String, Integer>();

    // Start of json
    // StringBuilderImpl jsonStrBuilder = new StringBuilderImpl();
    // jsonStrBuilder.append("{");
    JSONObject jsonObj = new JSONObject();

    MatrixJsonData matrixJsonData = MatrixJsonData.createMatrixJsonData();

    // jsonStrBuilder.append("\"nodes\":[");

    JSONArray jsonNodeArray = new JSONArray();
    jsonObj.put("nodes", jsonNodeArray);

    JsArray<JavaScriptObject> jsNodeArray = JavaScriptObject.createArray().cast();

    for (VisualItem visItem : concepts) {
        if (!(visItem.getDisplayObject() instanceof ConceptMatrixItem)) {
            // Remove when concepts are the only things coming through, not mappings
            continue;
        }
        ConceptMatrixItem displayObject = visItem.getDisplayObject();

        // jsonStrBuilder.append("{\"name\":"+displayObject.getConceptFullId()+",");
        // jsonStrBuilder.append("\"group\":"+getGroupForOntology(displayObject.getOntologyId()));
        // jsonStrBuilder.append("},");

        JSONObject nodeObject = new JSONObject();
        nodeObject.put("name", new JSONString(displayObject.getLabel()));
        nodeObject.put("uri", new JSONString(displayObject.getConceptFullId()));
        nodeObject.put("group", new JSONNumber(getGroupForOntology(displayObject.getOntologyId())));
        int index = jsonNodeArray.size();
        jsonNodeArray.set(index, nodeObject);

        int addedIndex = matrixJsonData.pushNode(displayObject.getLabel(), displayObject.getConceptFullId(),
                getGroupForOntology(displayObject.getOntologyId()));

        assert (addedIndex == index);

        conceptIndices.put(visItem.getResources().getFirstElement().getUri(), index);
    }
    // jsonStrBuilder.append("], ");

    // jsonStrBuilder.append("\"links\":[");

    JSONArray jsonLinkArray = new JSONArray();
    jsonObj.put("links", jsonLinkArray);

    for (Resource mappingResource : mappingResources) {
        assert Mapping.isMapping(mappingResource);
        String sourceUri = (String) mappingResource.getValue(Mapping.SOURCE_CONCEPT_URI);
        String targetUri = (String) mappingResource.getValue(Mapping.TARGET_CONCEPT_URI);

        JSONObject linkObject = new JSONObject();
        linkObject.put("source", new JSONNumber(conceptIndices.get(sourceUri)));
        // new JSONString(sourceUri));
        linkObject.put("target", new JSONNumber(conceptIndices.get(targetUri)));
        // new JSONString(targetUri));

        linkObject.put("target", new JSONNumber(1));
        jsonLinkArray.set(jsonLinkArray.size(), linkObject);

        int addedIndex = matrixJsonData.pushLink(conceptIndices.get(sourceUri), conceptIndices.get(targetUri),
                1);

        // jsonStrBuilder.append("{");
        // jsonStrBuilder.append("\"source\":"+sourceUri+",");
        // jsonStrBuilder.append("\"target\":"+targetUri+",");
        // jsonStrBuilder.append("\"value\":1");
        // jsonStrBuilder.append("},");
    }
    // jsonStrBuilder.append("]");

    // End of json
    // jsonStrBuilder.append("}");

    // matrixJsonData is preferable to jsonObj and to using a string builder.
    jsInterface.applyD3Layout(this.getElement(), matrixJSONContextObject, matrixJsonData);
    // jsonObj.toString()); // Old way
    // jsonStrBuilder.toString()); // Yet older way

}

From source file:org.vaadin.alump.masonry.client.MasonryPanel.java

License:Apache License

protected static JSONObject createMasonryProperties(int columnWidth) {
    JSONObject obj = new JSONObject();
    if (columnWidth == 0) {
        obj.put("columnWidth", new JSONString("." + GRID_SIZE_CLASSNAME));
    } else {/*  w  w  w .ja va 2 s.  c o  m*/
        obj.put("columnWidth", new JSONNumber(columnWidth));
    }
    obj.put("itemSelector", new JSONString("." + ITEM_CLASSNAME));
    return obj;
}