Example #1
0
 private void clearImpl() {
   hashCodeMap = JavaScriptObject.createArray();
   stringMap = JavaScriptObject.createObject();
   nullSlotLive = false;
   nullSlot = null;
   size = 0;
 }
Example #2
0
  private static void copyJSOProperties(
      JavaScriptObject newJso, JavaScriptObject oldJso, boolean deep) {
    for (Map.Entry<String, Object> entry : JavaScriptObjects.entrySet(oldJso)) {

      if (JsoProperties.PARENT_NODE_FIELD.equals(entry.getKey())) {
        // Nothing to do : new cloned node does not have any parent
      } else if (JsoProperties.STYLE_OBJECT_FIELD.equals(entry.getKey())) {
        setupStyle(newJso, (Style) entry.getValue());
      } else if (JsoProperties.NODE_LIST_FIELD.equals(entry.getKey())) {
        Node newNode = newJso.cast();
        Node oldNode = oldJso.cast();
        setupChildNodes(newNode, oldNode, deep);
      } else if (JsoProperties.ELEM_PROPERTIES.equals(entry.getKey())) {
        PropertyContainer newPc =
            JavaScriptObjects.getObject(newJso, JsoProperties.ELEM_PROPERTIES);
        PropertyContainer oldPc =
            JavaScriptObjects.getObject(oldJso, JsoProperties.ELEM_PROPERTIES);

        for (Map.Entry<String, Object> entry2 : oldPc.entrySet()) {
          newPc.put(entry2.getKey(), entry2.getValue());
        }
      } else if (JavaScriptObject.class.isInstance(entry.getValue())) {
        JavaScriptObject oldChildJso = (JavaScriptObject) entry.getValue();
        JavaScriptObject newChildJso = JavaScriptObjects.newObject(oldChildJso.getClass());
        copyJSOProperties(newChildJso, oldChildJso, deep);
        JavaScriptObjects.setProperty(newJso, entry.getKey(), newChildJso);
      } else {
        // copy the property, which should be a String or a primitive type (or
        // corresponding wrapper object)
        JavaScriptObjects.setProperty(newJso, entry.getKey(), entry.getValue());
      }
    }
  }
  public List<String> getFilenames() {
    ArrayList<String> result = new ArrayList<String>();

    JavaScriptObject rawFileList = getElement().getPropertyJSO("files");
    if (rawFileList == null) {
      result.add(InputElement.as(getElement()).getValue()); // IE does not support multiple-select
    } else {
      FileList fileList = rawFileList.cast();
      for (int i = 0; i < fileList.getLength(); ++i) {
        result.add(fileList.item(i).getName());
      }
    }

    return result;
  }
Example #4
0
 /**
  * Creates a JavaScript array and fills it with the objects from a Java array.
  *
  * @param array The source Java array.
  * @return The created JavaScript array.
  */
 public static JsArray<JavaScriptObject> toJSArray(Object[] array) {
   JsArray<JavaScriptObject> jsArray = JavaScriptObject.createArray().cast();
   for (int i = 0; i < array.length; i++) {
     add(jsArray, array[i]);
   }
   return jsArray;
 }
Example #5
0
 public final void setTimeAsArray(String key, Date value) {
   JsArrayInteger jsArray = JavaScriptObject.createArray().cast();
   jsArray.set(0, value.getHours());
   jsArray.set(1, value.getMinutes());
   jsArray.set(2, value.getSeconds());
   set(key, jsArray);
 };
  @Override
  public void start(AcceptsOneWidget panel, EventBus eventBus) {
    this.eventBus = eventBus;

    display.setPresenter(this);
    panel.setWidget(display);
    this.eventBus = eventBus;
    handlerRegistration(eventBus);
    if (repositoryUri == null || repositoryUri.length() == 0 || repositoryUri.equals("null")) {
      this.repo = JavaScriptObject.createObject().<Repository>cast();
      display.setData(this.repo);
    } else {
      display.setData(this.repo);
      getRepo(this.repositoryUri);
      fetchFiles(repositoryUri, this.prefix);
      CacheManager.EventConstructor change =
          new CacheManager.EventConstructor() {
            @Override
            public RepoUpdate newInstance(String key) {
              return new RepoUpdate();
            }
          };
      cacheManager.register(repositoryUri, "repoContent", change);
    }
  }
Example #7
0
 private static JavaScriptObject toJSOArray(DataClass[] array) {
   final JavaScriptObject arrayJSO = JavaScriptObject.createArray();
   for (int i = 0; i < array.length; i++) {
     JSOHelper.setArrayValue(arrayJSO, i, array[i].getJsObj());
   }
   return arrayJSO;
 }
Example #8
0
 public final void set(String key, List<JSOModel> values) {
   JsArray<JSOModel> array = JavaScriptObject.createArray().cast();
   for (int i = 0; i < values.size(); i++) {
     array.set(i, values.get(i));
   }
   setArray(key, array);
 }
Example #9
0
 public static Field create(String column, Operator operator, String value) {
   Field result = JavaScriptObject.createObject().cast();
   result.column(column);
   result.operator(operator);
   result.value(value);
   return result;
 }
 private static JsArrayString sample() {
   if (GWT.isScript()) {
     return StackTraceCreator.createStackTrace();
   } else {
     return JavaScriptObject.createArray().cast();
   }
 }
Example #11
0
 public final void setDateAsArray(String key, Date value) {
   JsArrayInteger jsArray = JavaScriptObject.createArray().cast();
   jsArray.set(0, value.getYear());
   jsArray.set(1, value.getMonth());
   jsArray.set(2, value.getDate());
   set(key, jsArray);
 };
Example #12
0
 public static final String toJson(List<JSOModel> values) {
   JsArray<JSOModel> arrayVals = JavaScriptObject.createArray().cast();
   int idx = 0;
   for (JSOModel model : values) {
     arrayVals.set(idx++, model);
   }
   return toJson(arrayVals);
 }
 protected AreaChartData createChartData() {
   String[] labelsArray = new String[labels.size()];
   labels.toArray(labelsArray);
   AreaChartData data = JavaScriptObject.createObject().cast();
   data.setLabels(labelsArray);
   data.setSeries(series);
   return data;
 }
  /**
   * Get the people from the server, convert them to JSON, and feed them back to the handler.
   *
   * @param ntids the ntids.
   * @param callbackIndex the callback index.
   */
  public static void bulkGetPeople(final String[] ntids, final int callbackIndex) {
    Session.getInstance()
        .getEventBus()
        .addObserver(
            GotBulkEntityResponseEvent.class,
            new Observer<GotBulkEntityResponseEvent>() {
              public void update(final GotBulkEntityResponseEvent arg1) {
                List<String> ntidList = Arrays.asList(ntids);
                JsArray<JavaScriptObject> personJSONArray =
                    (JsArray<JavaScriptObject>) JavaScriptObject.createArray();
                int count = 0;

                if (ntidList.size() == arg1.getResponse().size()) {
                  boolean notCorrectResponse = false;
                  for (Serializable person : arg1.getResponse()) {
                    PersonModelView personMV = (PersonModelView) person;
                    if (ntidList.contains(personMV.getAccountId())) {
                      AvatarUrlGenerator urlGen = new AvatarUrlGenerator(EntityType.PERSON);
                      String imageUrl =
                          urlGen.getSmallAvatarUrl(personMV.getId(), personMV.getAvatarId());

                      JsArrayString personJSON = (JsArrayString) JavaScriptObject.createObject();
                      personJSON.set(0, personMV.getAccountId());
                      personJSON.set(1, personMV.getDisplayName());
                      personJSON.set(2, imageUrl);

                      personJSONArray.set(count, personJSON);
                      count++;
                    } else {
                      notCorrectResponse = true;
                      break;
                    }
                  }
                  if (!notCorrectResponse) {
                    callGotBulkPeopleCallback(personJSONArray, callbackIndex);
                  }
                }
              }
            });

    ArrayList<StreamEntityDTO> entities = new ArrayList<StreamEntityDTO>();

    for (int i = 0; i < ntids.length; i++) {
      StreamEntityDTO dto = new StreamEntityDTO();
      dto.setUniqueIdentifier(ntids[i]);
      dto.setType(EntityType.PERSON);
      entities.add(dto);
    }

    if (ntids.length == 0) {
      JsArray<JavaScriptObject> personJSONArray =
          (JsArray<JavaScriptObject>) JavaScriptObject.createArray();
      callGotBulkPeopleCallback(personJSONArray, callbackIndex);
    } else {
      BulkEntityModel.getInstance().fetch(entities, false);
    }
  }
Example #15
0
 private void testGet() {
   JavaScriptObject obj = JavaScriptObject.createObject();
   Array<?> fruits = Array.fromObjects(true, 5.6, "Apple", obj);
   assertEquals(true, fruits.getBoolean(0));
   assertEquals(5.6, fruits.getNumber(1));
   assertEquals("Apple", fruits.getString(2));
   assertEquals(obj, fruits.getObject(3));
   assertEquals(obj, fruits.getObject(3));
 }
  private void buildView(JsArray array) {
    JsArray view = JavaScriptObject.createArray().cast();

    addToValueArray(showFullScreenButton, view, FULL_SCREEN);
    addToValueArray(showCodeViewButton, view, CODE_VIEW);

    if (!view.toString().isEmpty()) {
      array.push(toJSArray(VIEW, view));
    }
  }
 public void showMessage(final String message) {
   final CMDialogOptionsOverlay options = JavaScriptObject.createObject().cast();
   options.setBottom(true);
   final CMDialogOverlay dialog = this.editorOverlay.getDialog();
   if (dialog != null) {
     dialog.openNotification(message, options);
   } else {
     Log.info(CodeMirrorEditorWidget.class, message);
   }
 }
 @SuppressWarnings("unchecked")
 @Override
 public void setPath(List<HasLatLng> path) {
   JsArray<JavaScriptObject> pathJsArr =
       (JsArray<JavaScriptObject>) JavaScriptObject.createArray();
   for (HasLatLng latLng : path) {
     pathJsArr.push(latLng.getJso());
   }
   PolylineImpl.impl.setPath(jso, pathJsArr);
 }
  private void buildPara(JsArray array) {
    JsArray para = JavaScriptObject.createArray().cast();

    addToValueArray(showUnorderedListButton, para, UL);
    addToValueArray(showOrderedListButton, para, OL);
    addToValueArray(showParagraphButton, para, PARAGRAPH);

    if (!para.toString().isEmpty()) {
      array.push(toJSArray(PARA, para));
    }
  }
Example #20
0
  public static JsArrayInteger toArray(Set<OrgUnitDTO> children) {
    if (children == null) {
      return null;
    }

    final JsArrayInteger array = (JsArrayInteger) JavaScriptObject.createArray();
    for (final OrgUnitDTO child : children) {
      array.push(child.getId());
    }
    return array;
  }
Example #21
0
 public JavaScriptObject toNative() {
   JavaScriptObject o = JavaScriptObject.createObject();
   JsUtil.put(o, "rootLabel", getRootLabel());
   JsUtil.put(o, "offsetAngle", getOffsetAngle());
   JsUtil.put(o, "levelWidths", JsUtil.toJsArray(getLevelWidths()));
   JsUtil.put(o, "colors", JsUtil.toJsArray(getColors()));
   JsUtil.put(o, "gradients", JsUtil.toJsArray(getGradients()));
   JsUtil.put(o, "stroke", getStroke());
   JsUtil.put(o, "strokewidth", getStrokeWidth());
   return o;
 }
Example #22
0
 /**
  * Returns a JavaScriptObject object with info of the uploaded files. It's useful in the exported
  * version of the library.
  */
 public JavaScriptObject getData() {
   if (multiple) {
     JsArray<JavaScriptObject> ret = JavaScriptObject.createArray().cast();
     for (UploadedInfo info : serverMessage.getUploadedInfos()) {
       ret.push(getDataInfo(info));
     }
     return ret;
   } else {
     return getDataInfo(getServerInfo());
   }
 }
  private void buildInsert(JsArray array) {
    JsArray insert = JavaScriptObject.createArray().cast();

    addToValueArray(showInsertPictureButton, insert, PICTURE);
    addToValueArray(showInsertLinkButton, insert, LINK);
    addToValueArray(showInsertVideoButton, insert, VIDEO);

    if (!insert.toString().isEmpty()) {
      array.push(toJSArray(INSERT, insert));
    }
  }
Example #24
0
 private ImportCommandOptionsDto createImportCommandOptionsDto(@Nullable String selectedFile) {
   ImportCommandOptionsDto dto = ImportCommandOptionsDto.create();
   dto.setDestination(importConfig.getDestinationDatasourceName());
   if (importConfig.isArchiveMove()) {
     dto.setArchive(importConfig.getArchiveDirectory());
     JsArrayString selectedFiles = JavaScriptObject.createArray().cast();
     selectedFiles.push(selectedFile);
     dto.setFilesArray(selectedFiles);
   }
   if (importConfig.isIdentifierSharedWithUnit()) {
     dto.setUnit(importConfig.getUnit());
     dto.setForce(false);
     dto.setIgnore(true);
   }
   JsArrayString selectedTables = JavaScriptObject.createArray().cast();
   for (String tableName : comparedDatasourcesReportPresenter.getSelectedTables()) {
     selectedTables.push(importConfig.getTransientDatasourceName() + "." + tableName);
   }
   dto.setTablesArray(selectedTables);
   return dto;
 }
  private void buildStyles(JsArray array) {
    JsArray styles = JavaScriptObject.createArray().cast();

    addToValueArray(showBoldButton, styles, BOLD);
    addToValueArray(showItalicButton, styles, ITALIC);
    addToValueArray(showUnderlineButton, styles, UNDERLINE);
    addToValueArray(showClearButton, styles, CLEAR);

    if (!styles.toString().isEmpty()) {
      array.push(toJSArray(STYLE, styles));
    }
  }
  /**
   * A DisplayList represented using a native JavaScript array, and updated via the JavaScript
   * push() method.
   */
  @SuppressWarnings("unused")
  private static class JSArrayDisplayList {
    private JavaScriptObject jso = JavaScriptObject.createArray();

    public void begin() {
      jso = JavaScriptObject.createArray();
    }

    public native void cmd(String cmd) /*-{
      this.@com.google.gwt.emultest.benchmarks.java.lang.StringBufferBenchmark$JSArrayDisplayList::jso.push(cmd, 0);
    }-*/;

    public native void cmd(String cmd, int a) /*-{
      this.@com.google.gwt.emultest.benchmarks.java.lang.StringBufferBenchmark$JSArrayDisplayList::jso.push(cmd, 1, a);
    }-*/;

    public native void cmd(String cmd, int a, int b) /*-{
      this.@com.google.gwt.emultest.benchmarks.java.lang.StringBufferBenchmark$JSArrayDisplayList::jso.push(cmd, 2, a, b);
    }-*/;

    public native void cmd(String cmd, int a, int b, int c) /*-{
      this.@com.google.gwt.emultest.benchmarks.java.lang.StringBufferBenchmark$JSArrayDisplayList::jso.push(cmd, 3, a, b, c);
    }-*/;

    public native String end() /*-{
      return this.@com.google.gwt.emultest.benchmarks.java.lang.StringBufferBenchmark$JSArrayDisplayList::jso.join('');
    }-*/;

    public void fill() {
      cmd("F");
    }

    public void lineTo(int x, int y) {
      cmd("L", 0, 0);
    }

    public void moveTo(int x, int y) {
      cmd("M", 0, 0);
    }

    public void rotate(int angle) {
      cmd("R", angle);
    }

    public void stroke() {
      cmd("S");
    }

    public void translate(int x, int y) {
      cmd("T", x, y);
    }
  }
Example #27
0
 private void testPush() {
   Array<String> fruits =
       Array.create(Arrays.asList("Banana", "Orange", "Apple", "Mango", "Orange", "Lemon"));
   assertEquals(7, fruits.push("Other"));
   assertEquals("Other", fruits.getString(6));
   assertEquals(8, fruits.push(true));
   assertEquals(true, fruits.getBoolean(7));
   assertEquals(9, fruits.push(5.6));
   assertEquals(5.6, fruits.getNumber(8));
   JavaScriptObject obj = JavaScriptObject.createObject();
   assertEquals(10, fruits.push(obj));
   assertEquals(obj, fruits.getObject(9));
 }
Example #28
0
 private JavaScriptObject getDataInfo(UploadedInfo info) {
   return info == null
       ? JavaScriptObject.createObject()
       : getDataImpl(
           info.fileUrl,
           info.field,
           info.name,
           Utils.basename(info.name),
           serverRawResponse,
           info.message,
           getStatus().toString(),
           info.size);
 }
Example #29
0
  public static HighchartConfig createFromServerSideString(String confStr, String jsonState) {
    HighchartConfig conf;
    if (confStr != null) {
      conf = (HighchartConfig) JSONParser.parseLenient(confStr).isObject().getJavaScriptObject();
      conf.prepare();
    } else {
      conf = JavaScriptObject.createObject().cast();
    }
    if (jsonState != null) {
      merge(conf, jsonState);
    }

    return conf;
  }
Example #30
0
  @Override
  public void start(AcceptsOneWidget panel, EventBus eventBus) {
    this.eventBus = eventBus;

    display.setPresenter(this);
    panel.setWidget(display);
    if (repositoryUri == null || repositoryUri.length() == 0 || repositoryUri.equals("null")) {
      this.repo = JavaScriptObject.createObject().<Repository>cast();
      display.setData(this.repo);
    } else {
      display.setData(this.repo);
      getRepo();
    }
  }