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);
 }
 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);
 };
 private static JsArrayString sample() {
   if (GWT.isScript()) {
     return StackTraceCreator.createStackTrace();
   } else {
     return JavaScriptObject.createArray().cast();
   }
 }
Exemple #4
0
 private void clearImpl() {
   hashCodeMap = JavaScriptObject.createArray();
   stringMap = JavaScriptObject.createObject();
   nullSlotLive = false;
   nullSlot = null;
   size = 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;
 }
 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;
 }
 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);
 };
 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);
 }
  /**
   * 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);
    }
  }
 @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 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));
    }
  }
Exemple #12
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());
   }
 }
Exemple #13
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;
  }
  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));
    }
  }
  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));
    }
  }
  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));
    }
  }
 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;
 }
  /**
   * 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);
    }
  }
  public JsArray build() {
    JsArray array = JavaScriptObject.createArray().cast();

    buildArray(showStyleButton, array, STYLE);
    buildStyles(array);
    buildArray(showFontSizeButton, array, FONT_SIZE);
    buildArray(showColorButton, array, COLOR);
    buildPara(array);
    buildArray(showLineHeightButton, array, HEIGHT);
    buildInsert(array);
    buildArray(showInsertTableButton, array, TABLE);
    buildView(array);
    buildArray(showHelpButton, array, HELP);

    return array;
  }
 @Override
 public void fireOnSqlChange(String sql, List<Object> args) {
   JsArrayMixed jarg = (JsArrayMixed) JavaScriptObject.createArray();
   for (Object o : args) {
     if (o == null) {
       jarg.push((JavaScriptObject) null);
     } else if (o instanceof String) {
       jarg.push((String) o);
     } else if (o instanceof Date) {
       jarg.push(JsDate.create(((Date) o).getTime()));
     } else {
       throw new IllegalArgumentException("Don't know how to handle " + o);
     }
   }
   config.fireOnSqlChange(sql, jarg);
 }
 /* Factory method */
 public static TortureTestApi_methodReturningAnObject_result create() {
   return com.google.gwt.core.client.JavaScriptObject.createArray().cast();
 }
/**
 * Used to add stylesheets to the document. The one-argument versions of {@link #inject}, {@link
 * #injectAtEnd}, and {@link #injectAtStart} use {@link Scheduler#scheduleFinally} to minimize the
 * number of individual style elements created.
 *
 * <p>The api here is a bit redundant, with similarly named methods returning either <code>void
 * </code> or {@link StyleElement} &mdash; e.g., {@link #inject(String) void inject(String)} v.
 * {@link #injectStylesheet(String) StyleElement injectStylesheet(String)}. The methods that return
 * {@link StyleElement} are not guaranteed to work as expected on Internet Explorer. Because they
 * are still useful to developers on other browsers they are not deprecated, but <strong>IE
 * developers should avoid the methods with {@link StyleElement} return values</strong>.
 */
public class StyleInjector {

  /**
   * The DOM-compatible way of adding stylesheets. This implementation requires the host HTML page
   * to have a head element defined.
   */
  public static class StyleInjectorImpl {
    private static final StyleInjectorImpl IMPL = GWT.create(StyleInjectorImpl.class);

    private HeadElement head;

    public StyleElement injectStyleSheet(String contents) {
      StyleElement style = createElement(contents);
      getHead().appendChild(style);
      return style;
    }

    public StyleElement injectStyleSheetAtEnd(String contents) {
      return injectStyleSheet(contents);
    }

    public StyleElement injectStyleSheetAtStart(String contents) {
      StyleElement style = createElement(contents);
      getHead().insertBefore(style, head.getFirstChild());
      return style;
    }

    public void setContents(StyleElement style, String contents) {
      style.setInnerText(contents);
    }

    private StyleElement createElement(String contents) {
      StyleElement style = Document.get().createStyleElement();
      style.setPropertyString("language", "text/css");
      setContents(style, contents);
      return style;
    }

    private HeadElement getHead() {
      if (head == null) {
        Element elt = Document.get().getElementsByTagName("head").getItem(0);
        assert elt != null
            : "The host HTML page does not have a <head> element"
                + " which is required by StyleInjector";
        head = HeadElement.as(elt);
      }
      return head;
    }
  }

  /**
   * IE doesn't allow manipulation of a style element through DOM methods. There is also a
   * hard-coded limit on the number of times that createStyleSheet can be called before IE6 starts
   * throwing exceptions.
   */
  public static class StyleInjectorImplIE extends StyleInjectorImpl {

    /** The maximum number of style tags that can be handled by IE. */
    private static final int MAX_STYLE_SHEETS = 30;

    /**
     * A cache of the lengths of the current style sheets. A value of 0 indicates that the length
     * has not yet been retrieved.
     */
    private static int[] styleSheetLengths = new int[MAX_STYLE_SHEETS];

    private static native int getDocumentStyleCount() /*-{
      return $doc.styleSheets.length;
    }-*/;

    private static native StyleElement getDocumentStyleSheet(int index) /*-{
      return $doc.styleSheets[index];
    }-*/;

    private static native int getDocumentStyleSheetLength(int index) /*-{
      return $doc.styleSheets[index].cssText.length;
    }-*/;

    public native void appendContents(StyleElement style, String contents) /*-{
      style.cssText += contents;
    }-*/;

    @Override
    public StyleElement injectStyleSheet(String contents) {
      int numStyles = getDocumentStyleCount();
      if (numStyles < MAX_STYLE_SHEETS) {
        // Just create a new style element and add it to the list
        return createNewStyleSheet(contents);
      } else {
        /*
         * Find shortest style element to minimize re-parse time in the general
         * case.
         *
         * We cache the lengths of the style sheets in order to avoid expensive
         * calls to retrieve their actual contents. Note that if another module
         * or script makes changes to the style sheets that we are unaware of,
         * the worst that will happen is that we will choose a style sheet to
         * append to that is not actually of minimum size.
         */
        int shortestLen = Integer.MAX_VALUE;
        int shortestIdx = -1;
        for (int i = 0; i < numStyles; i++) {
          int len = styleSheetLengths[i];
          if (len == 0) {
            // Cache the length
            len = styleSheetLengths[i] = getDocumentStyleSheetLength(i);
          }
          if (len <= shortestLen) {
            shortestLen = len;
            shortestIdx = i;
          }
        }
        styleSheetLengths[shortestIdx] += contents.length();
        return appendToStyleSheet(shortestIdx, contents, true);
      }
    }

    @Override
    public StyleElement injectStyleSheetAtEnd(String contents) {
      int documentStyleCount = getDocumentStyleCount();
      if (documentStyleCount == 0) {
        return createNewStyleSheet(contents);
      }

      return appendToStyleSheet(documentStyleCount - 1, contents, true);
    }

    @Override
    public StyleElement injectStyleSheetAtStart(String contents) {
      if (getDocumentStyleCount() == 0) {
        return createNewStyleSheet(contents);
      }

      return appendToStyleSheet(0, contents, false); // prepend
    }

    public native void prependContents(StyleElement style, String contents) /*-{
      style.cssText = contents + style.cssText;
    }-*/;

    private StyleElement appendToStyleSheet(int idx, String contents, boolean append) {
      StyleElement style = getDocumentStyleSheet(idx);
      if (append) {
        appendContents(style, contents);
      } else {
        prependContents(style, contents);
      }
      return style;
    }

    private native StyleElement createElement() /*-{
      return $doc.createStyleSheet();
    }-*/;

    private StyleElement createNewStyleSheet(String contents) {
      StyleElement style = createElement();
      style.setCssText(contents);
      return style;
    }
  }

  private static final JsArrayString toInject = JavaScriptObject.createArray().cast();
  private static final JsArrayString toInjectAtEnd = JavaScriptObject.createArray().cast();
  private static final JsArrayString toInjectAtStart = JavaScriptObject.createArray().cast();

  private static ScheduledCommand flusher =
      new ScheduledCommand() {
        public void execute() {
          if (needsInjection) {
            flush(null);
          }
        }
      };

  private static boolean needsInjection = false;

  /**
   * Add a stylesheet to the document.
   *
   * @param css the CSS contents of the stylesheet
   */
  public static void inject(String css) {
    inject(css, false);
  }

  /**
   * Add a stylesheet to the document.
   *
   * @param css the CSS contents of the stylesheet
   * @param immediate if <code>true</code> the DOM will be updated immediately instead of just
   *     before returning to the event loop. Using this option excessively will decrease
   *     performance, especially if used with an inject-css-on-init coding pattern
   */
  public static void inject(String css, boolean immediate) {
    toInject.push(css);
    inject(immediate);
  }

  /**
   * Add stylesheet data to the document as though it were declared after all stylesheets previously
   * created by {@link #inject(String)}.
   *
   * @param css the CSS contents of the stylesheet
   */
  public static void injectAtEnd(String css) {
    injectAtEnd(css, false);
  }

  /**
   * Add stylesheet data to the document as though it were declared after all stylesheets previously
   * created by {@link #inject(String)}.
   *
   * @param css the CSS contents of the stylesheet
   * @param immediate if <code>true</code> the DOM will be updated immediately instead of just
   *     before returning to the event loop. Using this option excessively will decrease
   *     performance, especially if used with an inject-css-on-init coding pattern
   */
  public static void injectAtEnd(String css, boolean immediate) {
    toInjectAtEnd.push(css);
    inject(immediate);
  }

  /**
   * Add stylesheet data to the document as though it were declared before all stylesheets
   * previously created by {@link #inject(String)}.
   *
   * @param css the CSS contents of the stylesheet
   */
  public static void injectAtStart(String css) {
    injectAtStart(css, false);
  }

  /**
   * Add stylesheet data to the document as though it were declared before all stylesheets
   * previously created by {@link #inject(String)}.
   *
   * @param css the CSS contents of the stylesheet
   * @param immediate if <code>true</code> the DOM will be updated immediately instead of just
   *     before returning to the event loop. Using this option excessively will decrease
   *     performance, especially if used with an inject-css-on-init coding pattern
   */
  public static void injectAtStart(String css, boolean immediate) {
    toInjectAtStart.unshift(css);
    inject(immediate);
  }

  /**
   * Add a stylesheet to the document.
   *
   * <p>The returned StyleElement cannot be implemented consistently across all browsers.
   * Specifically, <strong>applications that need to run on Internet Explorer should not use this
   * method. Call {@link #inject(String)} instead.</strong>
   *
   * @param contents the CSS contents of the stylesheet
   * @return the StyleElement that contains the newly-injected CSS (unreliable on Internet Explorer)
   */
  public static StyleElement injectStylesheet(String contents) {
    toInject.push(contents);
    return flush(toInject);
  }

  /**
   * Add stylesheet data to the document as though it were declared after all stylesheets previously
   * created by {@link #injectStylesheet(String)}.
   *
   * <p>The returned StyleElement cannot be implemented consistently across all browsers.
   * Specifically, <strong>applications that need to run on Internet Explorer should not use this
   * method. Call {@link #injectAtEnd(String)} instead.</strong>
   *
   * @param contents the CSS contents of the stylesheet
   * @return the StyleElement that contains the newly-injected CSS (unreliable on Internet Explorer)
   */
  public static StyleElement injectStylesheetAtEnd(String contents) {
    toInjectAtEnd.push(contents);
    return flush(toInjectAtEnd);
  }

  /**
   * Add stylesheet data to the document as though it were declared before any stylesheet previously
   * created by {@link #injectStylesheet(String)}.
   *
   * <p>The returned StyleElement cannot be implemented consistently across all browsers.
   * Specifically, <strong>applications that need to run on Internet Explorer should not use this
   * method. Call {@link #injectAtStart(String, boolean)} instead.</strong>
   *
   * @param contents the CSS contents of the stylesheet
   * @return the StyleElement that contains the newly-injected CSS (unreliable on Internet Explorer)
   */
  public static StyleElement injectStylesheetAtStart(String contents) {
    toInjectAtStart.unshift(contents);
    return flush(toInjectAtStart);
  }

  /**
   * Replace the contents of a previously-injected stylesheet. Updating the stylesheet in-place is
   * typically more efficient than removing a previously-created element and adding a new one.
   *
   * <p>This method should be used with some caution as StyleInjector may recycle StyleElements on
   * certain browsers. Specifically, <strong>applications that need to run on Internet Explorer
   * should not use this method. </strong>
   *
   * @param style a StyleElement previously-returned from {@link #injectStylesheet(String)}.
   * @param contents the new contents of the stylesheet.
   */
  public static void setContents(StyleElement style, String contents) {
    StyleInjectorImpl.IMPL.setContents(style, contents);
  }

  /** The <code>which</code> parameter is used to support the deprecated API. */
  private static StyleElement flush(JavaScriptObject which) {
    StyleElement toReturn = null;
    StyleElement maybeReturn;

    if (toInjectAtStart.length() != 0) {
      String css = toInjectAtStart.join("");
      maybeReturn = StyleInjectorImpl.IMPL.injectStyleSheetAtStart(css);
      if (toInjectAtStart == which) {
        toReturn = maybeReturn;
      }
      toInjectAtStart.setLength(0);
    }

    if (toInject.length() != 0) {
      String css = toInject.join("");
      maybeReturn = StyleInjectorImpl.IMPL.injectStyleSheet(css);
      if (toInject == which) {
        toReturn = maybeReturn;
      }
      toInject.setLength(0);
    }

    if (toInjectAtEnd.length() != 0) {
      String css = toInjectAtEnd.join("");
      maybeReturn = StyleInjectorImpl.IMPL.injectStyleSheetAtEnd(css);
      if (toInjectAtEnd == which) {
        toReturn = maybeReturn;
      }
      toInjectAtEnd.setLength(0);
    }

    needsInjection = false;
    return toReturn;
  }

  private static void inject(boolean immediate) {
    if (immediate) {
      flush(null);
    } else {
      schedule();
    }
  }

  private static void schedule() {
    if (!needsInjection) {
      needsInjection = true;
      Scheduler.get().scheduleFinally(flusher);
    }
  }

  /** Utility class. */
  private StyleInjector() {}
}
 /** Construct a {@link JsLightArrayInteger} */
 public JsLightArrayInteger() {
   this(JavaScriptObject.createArray());
 }
  @SuppressWarnings("deprecation")
  public JsJobTrigger getJsJobTrigger() {
    JsJobTrigger jsJobTrigger = JsJobTrigger.instance();

    ScheduleType scheduleType = scheduleEditorWizardPanel.getScheduleType();
    Date startDate = scheduleEditorWizardPanel.getStartDate();
    String startTime = scheduleEditorWizardPanel.getStartTime();

    int startHour = getStartHour(startTime);
    int startMin = getStartMin(startTime);
    int startYear = startDate.getYear();
    int startMonth = startDate.getMonth();
    int startDay = startDate.getDate();
    Date startDateTime = new Date(startYear, startMonth, startDay, startHour, startMin);

    Date endDate = scheduleEditorWizardPanel.getEndDate();
    MonthOfYear monthOfYear = scheduleEditor.getRecurrenceEditor().getSelectedMonth();
    List<DayOfWeek> daysOfWeek = scheduleEditor.getRecurrenceEditor().getSelectedDaysOfWeek();
    Integer dayOfMonth = scheduleEditor.getRecurrenceEditor().getSelectedDayOfMonth();
    WeekOfMonth weekOfMonth = scheduleEditor.getRecurrenceEditor().getSelectedWeekOfMonth();

    if (isBlockoutDialog) {
      jsJobTrigger.setBlockDuration(calculateBlockoutDuration());
    } else {
      // blockDuration is only valid for blockouts
      jsJobTrigger.setBlockDuration(new Long(-1));
    }

    if (scheduleType == ScheduleType.RUN_ONCE) { // Run once types
      jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$
      jsJobTrigger.setRepeatInterval(0);
      jsJobTrigger.setRepeatCount(0);
      jsJobTrigger.setNativeStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
    } else if ((scheduleType == ScheduleType.SECONDS)
        || (scheduleType == ScheduleType.MINUTES)
        || (scheduleType == ScheduleType.HOURS)) {
      int repeatInterval = 0;
      try { // Simple Trigger Types
        repeatInterval = Integer.parseInt(scheduleEditorWizardPanel.getRepeatInterval());
      } catch (Exception e) {
        // ignored
      }
      jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$
      jsJobTrigger.setRepeatInterval(repeatInterval);
      jsJobTrigger.setRepeatCount(-1);
      jsJobTrigger.setNativeStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
      if (endDate != null) {
        jsJobTrigger.setNativeEndTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
      }
    } else if (scheduleType == ScheduleType.DAILY) {
      if (scheduleEditor.getRecurrenceEditor().isEveryNDays()) {
        int repeatInterval = 0;
        try { // Simple Trigger Types
          repeatInterval = Integer.parseInt(scheduleEditorWizardPanel.getRepeatInterval());
        } catch (Exception e) {
          // ignored
        }
        jsJobTrigger.setType("simpleJobTrigger"); // $NON-NLS-1$
        jsJobTrigger.setRepeatInterval(repeatInterval);
        jsJobTrigger.setRepeatCount(-1);
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      } else {
        JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray();
        int i = 0;
        for (DayOfWeek dayOfWeek : daysOfWeek) {
          jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1);
        }
        JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startHour);
        JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startMin);
        JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, 0);

        jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
        jsJobTrigger.setDayOfWeekRecurrences(jsDaysOfWeek);
        jsJobTrigger.setHourRecurrences(hours);
        jsJobTrigger.setMinuteRecurrences(minutes);
        jsJobTrigger.setSecondRecurrences(seconds);
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      }
    } else if (scheduleType == ScheduleType.CRON) { // Cron jobs
      jsJobTrigger.setType("cronJobTrigger"); // $NON-NLS-1$
    } else if ((scheduleType == ScheduleType.WEEKLY) && (daysOfWeek.size() > 0)) {
      JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray();
      int i = 0;
      for (DayOfWeek dayOfWeek : daysOfWeek) {
        jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1);
      }
      JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
      hours.set(0, startHour);
      JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
      hours.set(0, startMin);
      JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
      hours.set(0, 0);

      jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
      jsJobTrigger.setDayOfWeekRecurrences(jsDaysOfWeek);
      jsJobTrigger.setHourRecurrences(hours);
      jsJobTrigger.setMinuteRecurrences(minutes);
      jsJobTrigger.setSecondRecurrences(seconds);
      jsJobTrigger.setNativeStartTime(
          DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
      if (endDate != null) {
        jsJobTrigger.setNativeEndTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
      }
    } else if ((scheduleType == ScheduleType.MONTHLY)
        || ((scheduleType == ScheduleType.YEARLY) && (monthOfYear != null))) {
      jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$

      if (dayOfMonth != null) {
        JsArrayInteger jsDaysOfMonth = (JsArrayInteger) JavaScriptObject.createArray();
        jsDaysOfMonth.set(0, dayOfMonth);

        JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startHour);
        JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startMin);
        JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, 0);

        jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
        if (monthOfYear != null) {
          JsArrayInteger jsMonthsOfYear = (JsArrayInteger) JavaScriptObject.createArray();
          jsMonthsOfYear.set(0, monthOfYear.ordinal() + 1);
          jsJobTrigger.setMonthlyRecurrences(jsMonthsOfYear);
        }
        jsJobTrigger.setDayOfMonthRecurrences(jsDaysOfMonth);
        jsJobTrigger.setHourRecurrences(hours);
        jsJobTrigger.setMinuteRecurrences(minutes);
        jsJobTrigger.setSecondRecurrences(seconds);
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      } else if ((daysOfWeek.size() > 0) && (weekOfMonth != null)) {
        JsArrayInteger jsDaysOfWeek = (JsArrayInteger) JavaScriptObject.createArray();
        int i = 0;
        for (DayOfWeek dayOfWeek : daysOfWeek) {
          jsDaysOfWeek.set(i++, dayOfWeek.ordinal() + 1);
        }

        JsArrayInteger hours = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startHour);
        JsArrayInteger minutes = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, startMin);
        JsArrayInteger seconds = (JsArrayInteger) JavaScriptObject.createArray();
        hours.set(0, 0);

        jsJobTrigger.setType("complexJobTrigger"); // $NON-NLS-1$
        if (monthOfYear != null) {
          JsArrayInteger jsMonthsOfYear = (JsArrayInteger) JavaScriptObject.createArray();
          jsMonthsOfYear.set(0, monthOfYear.ordinal() + 1);
          jsJobTrigger.setMonthlyRecurrences(jsMonthsOfYear);
        }
        jsJobTrigger.setHourRecurrences(hours);
        jsJobTrigger.setMinuteRecurrences(minutes);
        jsJobTrigger.setSecondRecurrences(seconds);
        jsJobTrigger.setQualifiedDayOfWeek(daysOfWeek.get(0).name());
        jsJobTrigger.setDayOfWeekQualifier(weekOfMonth.name());
        jsJobTrigger.setNativeStartTime(
            DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(startDateTime));
        if (endDate != null) {
          jsJobTrigger.setNativeEndTime(
              DateTimeFormat.getFormat(PredefinedFormat.ISO_8601).format(endDate));
        }
      }
    }
    return jsJobTrigger;
  }
  private void handleWizardPanels(final JSONObject schedule, final JsJobTrigger trigger) {
    if (hasParams) {
      showScheduleParamsDialog(trigger, schedule);
    } else if (isEmailConfValid) {
      showScheduleEmailDialog(schedule);
    } else {
      // submit
      JSONObject scheduleRequest = (JSONObject) JSONParser.parseStrict(schedule.toString());

      if (editJob != null) {
        JSONArray scheduleParams = new JSONArray();

        for (int i = 0; i < editJob.getJobParams().length(); i++) {
          JsJobParam param = editJob.getJobParams().get(i);
          JsArrayString paramValue = (JsArrayString) JavaScriptObject.createArray().cast();
          paramValue.push(param.getValue());
          JsSchedulingParameter p = (JsSchedulingParameter) JavaScriptObject.createObject().cast();
          p.setName(param.getName());
          p.setType("string"); // $NON-NLS-1$
          p.setStringValue(paramValue);
          scheduleParams.set(i, new JSONObject(p));
        }

        scheduleRequest.put("jobParameters", scheduleParams); // $NON-NLS-1$

        String actionClass =
            editJob.getJobParamValue("ActionAdapterQuartzJob-ActionClass"); // $NON-NLS-1$
        if (!StringUtils.isEmpty(actionClass)) {
          scheduleRequest.put("actionClass", new JSONString(actionClass)); // $NON-NLS-1$
        }
      }

      RequestBuilder scheduleFileRequestBuilder =
          new RequestBuilder(RequestBuilder.POST, contextURL + "api/scheduler/job"); // $NON-NLS-1$
      scheduleFileRequestBuilder.setHeader(
          "Content-Type", "application/json"); // $NON-NLS-1$//$NON-NLS-2$
      scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");

      try {
        scheduleFileRequestBuilder.sendRequest(
            scheduleRequest.toString(),
            new RequestCallback() {
              public void onError(Request request, Throwable exception) {
                MessageDialogBox dialogBox =
                    new MessageDialogBox(
                        Messages.getString("error"),
                        exception.toString(),
                        false,
                        false,
                        true); //$NON-NLS-1$
                dialogBox.center();
                setDone(false);
              }

              public void onResponseReceived(Request request, Response response) {
                if (response.getStatusCode() == 200) {
                  setDone(true);
                  ScheduleRecurrenceDialog.this.hide();
                  if (callback != null) {
                    callback.okPressed();
                  }
                  if (showSuccessDialog) {
                    if (!PerspectiveManager.getInstance()
                        .getActivePerspective()
                        .getId()
                        .equals(PerspectiveManager.SCHEDULES_PERSPECTIVE)) {
                      ScheduleCreateStatusDialog successDialog = new ScheduleCreateStatusDialog();
                      successDialog.center();
                    } else {
                      MessageDialogBox dialogBox =
                          new MessageDialogBox(
                              Messages.getString("scheduleUpdatedTitle"),
                              Messages.getString(
                                  "scheduleUpdatedMessage"), //$NON-NLS-1$ //$NON-NLS-2$
                              false,
                              false,
                              true);
                      dialogBox.center();
                    }
                  }
                } else {
                  MessageDialogBox dialogBox =
                      new MessageDialogBox(
                          Messages.getString("error"), // $NON-NLS-1$
                          response.getText(),
                          false,
                          false,
                          true);
                  dialogBox.center();
                  setDone(false);
                }
              }
            });
      } catch (RequestException e) {
        MessageDialogBox dialogBox =
            new MessageDialogBox(
                Messages.getString("error"),
                e.toString(), // $NON-NLS-1$
                false,
                false,
                true);
        dialogBox.center();
        setDone(false);
      }

      setDone(true);
    }
  }
Exemple #26
0
 public void clear() {
   // create a new array
   array = JavaScriptObject.createArray().cast();
 }
Exemple #27
0
 public BitSet() {
   // create a new array
   array = JavaScriptObject.createArray().cast();
 }
 private static NodeList<Element> getElementsByTagName(String tag, Node ctx) {
   if (ctx == null) {
     return JavaScriptObject.createArray().cast();
   }
   return ((Element) ctx).getElementsByTagName(tag);
 }
 public NodeList<Element> select(String selector, Node context) {
   JsArray<Element> results = JavaScriptObject.createArray().cast();
   return select(selector, context, results, null).cast();
 }
 @Override
 public void dataClear() {
   labels.clear();
   series = JavaScriptObject.createArray().cast();
 }