Package org.sgx.yuigwt.yui.util

Examples of org.sgx.yuigwt.yui.util.JsObject


        JsArray<JavaScriptObject> testsArr = JsArray.createArray().cast();
        JsArrayString testNames = JsArrayString.createArray().cast();

        for (Test test : tests) {
          JsObject testObj = testToJsObject(test);
          testsArr.push(testObj);
          testNames.push(test.getName());
        }

        // an autocomplete and button search box
View Full Code Here


        String errMsg = null;

        // test 1 : parse a json string

        String jsonStr1 = " {\"troop\":[{\"name\":\"Ashley\",\"age\":12},{\"name\":\"Abby\",\"age\":9}]}";
        JsObject obj1 = Y.JSON().parse(jsonStr1).cast();

        if (obj1.objGetArr("troop").length() != 2)
          errMsg = "obj1.objGetArr(\"troop\").length()!=2";

        // test 2 : parse another json string

        String jsonStr2 = "{\"data\": [ "
            + "    {\"category\":\"5/1/2010\", \"miscellaneous\":2000, \"expenses\":3700, \"revenue\":2200}, "
            + "    {\"category\":\"5/2/2010\", \"miscellaneous\":50, \"expenses\":9100, \"revenue\":100}, "
            + "    {\"category\":\"5/3/2010\", \"miscellaneous\":400, \"expenses\":1100, \"revenue\":1500}, "
            + "    {\"category\":\"5/4/2010\", \"miscellaneous\":200, \"expenses\":1900, \"revenue\":2800}, "
            + "    {\"category\":\"5/5/2010\", \"miscellaneous\":5000, \"expenses\":5000, \"revenue\":2650}"
            + "]}";

        /*
         * Note: due to GWT types restrictions, we couldn't represent the JSON.parse() reviver function using a Java JsObject (function return value can be anything).
         * Instead se define a js function inline using JsFunctionBuilder.
         */
        JsFunction reviver2 = new JsFunctionBuilder() {
          @Override
          public native final JsFunction buildFunction()/*-{
            return function(k, v) {
              if (k == "miscellaneous" && v > 500)
                return 999999;
              else
                return v;
            }
          }-*/;
        }.buildFunction();

        JsObject obj2 = Y.JSON().parse(jsonStr2, reviver2).cast();

        if (obj2.objGetArr("data").length() != 5)
          errMsg = "obj2.objGetArr(\"troop\").length()!=5";

        if (obj2.objGetArr("data").getObj(2).objGetInt("miscellaneous") != 400)
          errMsg = "obj2.objGetArr(\"data\").getObj(2).objGetInt(\"miscellaneous\")!=400 but "
              + obj2.objGetArr("data").getObj(2).objGetInt("miscellaneous");

        if (obj2.objGetArr("data").getObj(0).objGetInt("miscellaneous") != 999999)
          errMsg = "obj2.objGetArr(\"data\").getObj(0).objGetInt(\"miscellaneous\")!=999999";

        // test 3 : try to parse an invalid json string and catch the exeption.
        boolean err = false;
        try {
          JsObject obj3 = Y.JSON().parse("{blsbls: dhhdhd , , [.]}").cast();
        } catch (JavaScriptException e) {
          err = true;
          Window.alert(e + "");
        }
        if (!err)
View Full Code Here

  @Override
  public void ready(final YuiContext Y) {
   
    //Y.substitute test simple   
    String template1 = "My name is {name}, and I'm {age} years old";
    final JsObject person1 = JsObject.one("name", "Sebastián Gurin")._("age", 28);
    Window.alert(Y.substitute(template1, person1));
   
    //Y.substitute test - using a function substituter
    String template2 = "My name is {name}, and I'm {age} years old and my sister name is {sister.name jaja} with {sister.age jeje} years old.";
    final JsObject person2 = JsObject.one("name", "Laura Gurin")._("age", 25);
    person1._("sister", person2);
    SubstituteCallback<String> substituter1 = new SubstituteCallback<String>() {
      @Override
      public String call(String key, String value, String param1) {
        if(value==null && key != null && key.startsWith("sister.")) {
View Full Code Here

});
}
protected void renderUi() {
  JsArray<TreeLeafConfig> leafs1 = JsArray.createArray().cast();  
  for (int i = 0; i < moduleInfo.length(); i++) {
    JsObject module = moduleInfo.get(i);
    leafs1.push(buildLeaf(module));
  }
  TreeView treeView1 = Y.newTreeView(TreeLeafConfig.create().collapsed(false)
    .label("Yui Modules metainformation").children(leafs1).id("tree1"));    
  Node treeViewParentNode = Y.one(parent.getDOMNode());
View Full Code Here

  TreeLeafConfig requiresLeaf = TreeLeafConfig.create()
    .label("requires").type("TreeView").cast();
 
  leaf.children(submodulesLeaf, useLeaf, requiresLeaf);
 
  JsObject modObj = module.objGetObj(moduleName);
 
  //do submodules
  JsObject submodules = modObj.objGetObj("submodules");
  if(submodules!=null) {
    JsArrayString submodulesNames =submodules.objProps();
    JsArray<TreeLeafConfig> submoduleChildren = JsArray.createArray().cast();
    for (int i = 0; i < submodulesNames.length(); i++) {
      String smn = submodulesNames.get(i);
      TreeLeafConfig leaf2 = TreeLeafConfig.create().label(smn).id(moduleName+"-"+smn).cast();
      submoduleChildren.push(leaf2);
View Full Code Here

    if(!debug) {
    String query2 = "select * from yui.gallery.all";
    YQLCallback yqlCallback2 = new YQLCallback() {     
      @Override
      public void call(YQLResult r) {
        JsObject o = r.query().results().objGetObj("json"); //type, count, modules, }
        JsArray<Module> modules = o.objGetObj("modules").cast();
        loadModules(modules);
        gallery.render();   
      }
    };
    JsObject yqlParams2 = JsObject.one("env", "http://datatables.org/alltables.env");  
    yqlParams2.objPut("format", "json");
    YQL yql2 = Y.newYQL(query2, yqlCallback2, yqlParams2);
    }
    else {
      //only for devel/testing - load a local copy
      String text = TestResources.instance.data1().getText();
      console.log("data length: "+text.length());
      YQLResult r = JsonUtils.unsafeEval(text);
      JsObject json = r.query().results().objGetObj("json");
      JsArray<Module> data = json.objGetObj("modules").cast();
      loadModules(data);
      gallery.render();  
    }
  }
View Full Code Here

    if (y == null || n == null || !n.inDoc())
      return; // TODO: something went wrong with the ordering

    org.sgx.yuigwt.yui.widget.Widget w = null;

    JsObject nodeConfig = getNodeConfig(n);
    if (nodeConfig == null)
      return;

    String yuiWidget = nodeConfig.objGetString(YUIWIDGET);

    if (yuiWidget == null)
      return;

    // System.out.println(yuiWidget+" - "+yuiWidget.equals("TabView"));
View Full Code Here

      data = data.replace("(((", "{").replace(")))", "}");
      JavaScriptObject configObj = JsonUtils.unsafeEval("{" + data + "}");
      return configObj.cast();
    } else {
      // TODO: check for individual data-yuiconfig-label="buttonlabel"
      JsObject config = JsObject.createObject().cast();
      // JsObject dataObj = n.getData();
      // JsArrayString props = dataObj.objProps();
      // for (int i = 0; i < props.length(); i++) {
      // String prop = props.get(i);
      //
View Full Code Here

   
    String query2 = "select * from yui.gallery.all";
    YQLCallback yqlCallback2 = new YQLCallback() {     
      @Override
      public void call(YQLResult r) {
        JsObject o = r.query().results().objGetObj("json"); //type, count, modules, }
        JsArray<JsObject> modules = o.objGetObj("modules").cast();
        JsObject module0 = modules.get(0);
        console.log("first module title is "+module0.objGetString("title"));         
      }
    };
    YQLParams yqlParams2 = YQLParams.create().env("http://datatables.org/alltables.env");
    yqlParams2.format("json")
    YQL yql2 = Y.newYQL(query2, yqlCallback2, yqlParams2);
View Full Code Here

          }
        };
        JSOnizer<Person1> jsonizer = new JSOnizer<Person1>() {
          @Override
          public JavaScriptObject jsonize(Person1 t) {
            JsObject jso = JsObject.one("name", t.getName()).objPut("age", t.getAge()).objPut("female", t.getFemale());
            return jso;
          }
        };
        CrudTestUtil<Person1> crudUtil = new CrudTestUtil<Person1>(Y, all, "Person", Person1.random());
//        crudUtil.addChangeListener(new ChangeListener<CrudExample1.Person1>() {         
View Full Code Here

TOP

Related Classes of org.sgx.yuigwt.yui.util.JsObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.