Ejemplo n.º 1
0
  /**
   * Set the current progress as a percentage
   *
   * @param percentage Set current percentage for the progress bar
   */
  public void setProgress(int percentage) {
    // Make sure we are error-tolerant
    if (percentage > 100) percentage = 100;
    if (percentage < 0) percentage = 0;

    // Set the internal variable
    progress = percentage;

    // Update the elements in the progress grid to
    // reflect the status
    int completed = elements * percentage / 100;
    for (int loop = 0; loop < elements; loop++) {
      Grid elm = (Grid) elementGrid.getWidget(0, loop);
      if (loop < completed) {
        elm.setStyleName("progressbar-fullbar");
        elm.addStyleName("progressbar-bar");
      } else {
        elm.setStyleName("progressbar-blankbar");
        elm.addStyleName("progressbar-bar");
      }
    }

    if (percentage > 0) {
      // Calculate the new time remaining
      long soFar = (System.currentTimeMillis() - startTime) / 1000;
      long remaining = soFar * (100 - percentage) / percentage;
      // Select the best UOM
      String remainText = secondsMessage;
      if (remaining > 120) {
        remaining = remaining / 60;
        remainText = minutesMessage;
        if (remaining > 120) {
          remaining = remaining / 60;
          remainText = hoursMessage;
        }
      }
      // Locate the position to insert out time remaining
      int pos = remainText.indexOf("{0}");
      if (pos >= 0) {
        String trail = "";
        if (pos + 3 < remainText.length()) trail = remainText.substring(pos + 3);
        remainText = remainText.substring(0, pos) + remaining + trail;
      }
      // Set the label
      remainLabel.setText(remainText);
    } else {
      // If progress is 0, reset the start time
      startTime = System.currentTimeMillis();
    }
  }
Ejemplo n.º 2
0
  /**
   * Base constructor for this widget
   *
   * @param elements The number of elements (bars) to show on the progress bar
   * @param options The display options for the progress bar
   */
  public ProgressBar(int elements, int options) {
    // Read the options and set convenience variables
    if ((options & SHOW_TIME_REMAINING) == SHOW_TIME_REMAINING) showRemaining = true;
    if ((options & SHOW_TEXT) == SHOW_TEXT) showText = true;

    // Set element count
    this.elements = elements;

    // Styling
    remainLabel.setStyleName("progressbar-remaining");
    textLabel.setStyleName("progressbar-text");

    // Initialize the progress elements
    elementGrid = new Grid(1, elements);
    elementGrid.setStyleName("progressbar-inner");
    elementGrid.setCellPadding(0);
    elementGrid.setCellSpacing(0);

    for (int loop = 0; loop < elements; loop++) {
      Grid elm = new Grid(1, 1);
      // elm.setHTML(0, 0, "&nbsp;");
      elm.setHTML(0, 0, "");
      elm.setStyleName("progressbar-blankbar");
      elm.addStyleName("progressbar-bar");
      elementGrid.setWidget(0, loop, elm);
    }

    // Create the container around the elements
    Grid containerGrid = new Grid(1, 1);
    containerGrid.setCellPadding(0);
    containerGrid.setCellSpacing(0);
    containerGrid.setWidget(0, 0, elementGrid);
    containerGrid.setStyleName("progressbar-outer");
    // containerGrid.setBorderWidth(1);

    // Set up the surrounding flex table based on the options
    int row = 0;
    if (showText) barFrame.setWidget(row++, 0, textLabel);
    barFrame.setWidget(row++, 0, containerGrid);
    if (showRemaining) barFrame.setWidget(row++, 0, remainLabel);

    barFrame.setWidth("100%");

    // Add the frame to the panel
    this.add(barFrame);

    // Initialize progress bar
    setProgress(0);
  }
Ejemplo n.º 3
0
 @Override
 protected void setup() {
   // Set up backwards.
   backwards = new PushButton();
   backwards.addClickHandler(
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           addMonths(-1);
         }
       });
   backwards.getUpFace().setHTML("&lsaquo;");
   backwards.setStyleName(BASE_NAME + "PreviousButton");
   forwards = new PushButton();
   forwards.getUpFace().setHTML("&rsaquo;");
   forwards.setStyleName(BASE_NAME + "NextButton");
   forwards.addClickHandler(
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           addMonths(+1);
         }
       });
   // Set up backwards year
   backwardsYear = new PushButton();
   backwardsYear.addClickHandler(
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           addMonths(-12);
         }
       });
   backwardsYear.getUpFace().setHTML("&laquo;");
   backwardsYear.setStyleName(BASE_NAME + "PreviousButton");
   forwardsYear = new PushButton();
   forwardsYear.getUpFace().setHTML("&raquo;");
   forwardsYear.setStyleName(BASE_NAME + "NextButton");
   forwardsYear.addClickHandler(
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           addMonths(+12);
         }
       });
   // Set up grid.
   grid = new Grid(1, 5);
   grid.setWidget(0, previousYearColumn, backwardsYear);
   grid.setWidget(0, previousMonthColumn, backwards);
   grid.setWidget(0, nextMonthColumn, forwards);
   grid.setWidget(0, nextYearColumn, forwardsYear);
   CellFormatter formatter = grid.getCellFormatter();
   formatter.setStyleName(0, monthColumn, BASE_NAME + "Month");
   formatter.setWidth(0, previousYearColumn, "1");
   formatter.setWidth(0, previousMonthColumn, "1");
   formatter.setWidth(0, monthColumn, "100%");
   formatter.setWidth(0, nextMonthColumn, "1");
   formatter.setWidth(0, nextYearColumn, "1");
   grid.setStyleName(BASE_NAME + "MonthSelector");
   initWidget(grid);
 }
Ejemplo n.º 4
0
  @Override
  public void setState(EditingState editingState) {
    if (this.editingState == editingState) {
      return;
    }
    this.editingState = editingState;
    if (editingState == EditingState.UNSAVED) {
      editorGrid.setStyleName(style.unsaved());
      savingIndicator.setVisible(false);

    } else if (editingState == EditingState.SAVING) {
      savingIndicator.setVisible(true);
    } else {
      editorGrid.setStyleName(resolveStyleName(cachedValue.getStatus()));
      savingIndicator.setVisible(false);
    }
  }
Ejemplo n.º 5
0
 @Override
 public void revertEditorContents() {
   List<String> cachedTargets = cachedValue.getTargets();
   for (int i = 0; i < cachedTargets.size(); i++) {
     String target = cachedTargets.get(i);
     editors.get(i).setTextAndValidate(target);
   }
   editorGrid.setStyleName(resolveStyleName(cachedValue.getStatus()));
 }
Ejemplo n.º 6
0
 @Override
 public void updateCachedTargetsAndVersion(
     List<String> targets, Integer verNum, ContentState status) {
   cachedValue =
       TransUnit.Builder.from(cachedValue)
           .setTargets(targets)
           .setVerNum(verNum)
           .setStatus(status)
           .build();
   editorGrid.setStyleName(resolveStyleName(cachedValue.getStatus()));
 }
Ejemplo n.º 7
0
  @Override
  public void setPropertyList(Map<String, Object> propertyList) {
    noRec.clear();
    map(propertyList);

    Grid grid = new Grid(noRec.keySet().size(), 2);
    grid.setWidth("100%");
    grid.setStyleName("propertyGrid");

    int i = 0;
    for (String k : noRec.keySet()) {
      if (k.equals("_id")) {
        if (noRec.get(k).substring(0, 1).equals("n")) {
          grid.setWidget(i, 0, new Label("source"));
          grid.setWidget(
              i,
              1,
              new HTML(
                  "<a target=\"_blank\" href=\"http://www.openstreetmap.org/browse/node/"
                      + noRec.get(k).substring(1, noRec.get(k).length())
                      + "\">OSM CC-By-SA</a>"));
        } else if (noRec.get(k).substring(0, 1).equals("w")) {
          grid.setWidget(i, 0, new Label("source"));
          grid.setWidget(
              i,
              1,
              new HTML(
                  "<a target=\"_blank\" href=\"http://www.openstreetmap.org/browse/way/"
                      + noRec.get(k).substring(1, noRec.get(k).length())
                      + "\">OSM CC-By-SA</a>"));
        } else if (noRec.get(k).substring(0, 1).equals("r")) {
          grid.setWidget(i, 0, new Label("source"));
          grid.setWidget(
              i,
              1,
              new HTML(
                  "<a target=\"_blank\" href=\"http://www.openstreetmap.org/browse/relation/"
                      + noRec.get(k).substring(1, noRec.get(k).length())
                      + "\">OSM CC-By-SA</a>"));
        }
      } else {
        grid.setWidget(i, 0, new Label(k));
        grid.setWidget(i, 1, new Label(noRec.get(k)));
      }

      grid.getCellFormatter().setStyleName(i, 0, "namecell");
      grid.getCellFormatter().setStyleName(i, 1, "valuecell");

      i++;
    }

    _siPa.setWidget(grid);
  }
Ejemplo n.º 8
0
  @Override
  protected void onInitUI() {
    super.onInitUI();

    tokenLabel = new CopyableLabel("");
    tokenLabel.addStyleName(Gerrit.RESOURCES.css().oauthToken());

    expiresLabel = new Label("");
    expiresLabel.addStyleName(Gerrit.RESOURCES.css().oauthExpires());

    grid = new Grid(2, 2);
    grid.setStyleName(Gerrit.RESOURCES.css().infoBlock());
    grid.addStyleName(Gerrit.RESOURCES.css().oauthInfoBlock());
    add(grid);

    expiredNote = new Label(Util.C.labelOAuthExpired());
    expiredNote.setVisible(false);
    add(expiredNote);

    row(grid, 0, Util.C.labelOAuthToken(), tokenLabel);
    row(grid, 1, Util.C.labelOAuthExpires(), expiresLabel);

    CellFormatter fmt = grid.getCellFormatter();
    fmt.addStyleName(0, 0, Gerrit.RESOURCES.css().topmost());
    fmt.addStyleName(0, 1, Gerrit.RESOURCES.css().topmost());
    fmt.addStyleName(1, 0, Gerrit.RESOURCES.css().bottomheader());

    flow = new FlowPanel();
    flow.setStyleName(Gerrit.RESOURCES.css().oauthPanel());
    add(flow);

    Label netrcLabel = new Label(Util.C.labelOAuthNetRCEntry());
    netrcLabel.setStyleName(Gerrit.RESOURCES.css().oauthPanelNetRCHeading());
    flow.add(netrcLabel);
    netrcValue = new CopyableLabel("");
    netrcValue.setStyleName(Gerrit.RESOURCES.css().oauthPanelNetRCEntry());
    flow.add(netrcValue);

    Label cookieLabel = new Label(Util.C.labelOAuthGitCookie());
    cookieLabel.setStyleName(Gerrit.RESOURCES.css().oauthPanelCookieHeading());
    flow.add(cookieLabel);
    cookieValue = new CopyableLabel("");
    cookieValue.setStyleName(Gerrit.RESOURCES.css().oauthPanelCookieEntry());
    flow.add(cookieValue);
  }
Ejemplo n.º 9
0
  @Override
  public void setValueAndCreateNewEditors(TransUnit transUnit) {
    cachedValue = transUnit;

    editors.clear();
    List<String> cachedTargets = cachedValue.getTargets();
    if (cachedTargets == null) {
      cachedTargets = Lists.newArrayList("");
    }
    editorGrid.resize(cachedTargets.size(), COLUMNS);
    int rowIndex = 0;
    for (String target : cachedTargets) {
      Editor editor = new Editor(target, rowIndex, listener, transUnit.getId());
      editor.setEnableSpellCheck(listener.getConfigState().isSpellCheckEnabled());
      editorGrid.setWidget(rowIndex, 0, editor);
      editors.add(editor);
      rowIndex++;
    }
    editorGrid.setStyleName(resolveStyleName(cachedValue.getStatus()));
    editingState = EditingState.SAVED;
  }
Ejemplo n.º 10
0
  @Override
  protected Widget createContents(int start, int count, List<T> list) {
    int limit = list.size();
    int cells = padToFullPage() ? Math.max(count, limit) : limit;
    Grid grid = new Grid((int) Math.ceil(cells / (float) _cols), Math.min(_cols, cells));
    grid.setStyleName("Grid");
    grid.setCellPadding(0);
    grid.setCellSpacing(0);
    grid.setWidth("100%");

    for (int ii = 0; ii < limit; ii++) {
      int row = (ii / _cols), col = (ii % _cols);
      T item = ii >= list.size() ? null : list.get(ii);
      Widget widget = createWidget(item);
      if (widget != null) {
        grid.setWidget(row, col, widget);
      }
      formatCell(grid.getCellFormatter(), row, col, limit);
      formatCell(grid.getCellFormatter(), row, col, item);
    }

    return grid;
  }
Ejemplo n.º 11
0
  private Grid addWalrusEntry(int row, WalrusInfoWeb walrusInfo) {
    final ArrayList<String> properties = walrusInfo.getProperties();
    int numProperties = properties.size() / 4;
    Grid g = new Grid(1 + numProperties, 2);
    g.setStyleName("euca-table");
    g.setCellPadding(4);

    int i = 0; // row 1
    g.setWidget(i, 0, new Label("Walrus host:"));
    g.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
    HorizontalPanel p = new HorizontalPanel();
    p.setSpacing(0);
    g.setWidget(i, 1, p);
    final TextBox walrusHost_box = new TextBox();
    walrusHost_box.addChangeListener(new ChangeCallback(this, row));
    walrusHost_box.setVisibleLength(35);
    walrusHost_box.setText(walrusInfo.getHost());
    p.add(walrusHost_box);
    p.add(new EucaButton("Deregister", new DeleteCallback(this, row)));

    for (int propIdx = 0; propIdx < numProperties; ++propIdx) {
      i++; // next row
      if ("KEYVALUE".equals(properties.get(4 * propIdx))) {
        g.setWidget(i, 0, new Label(properties.get(4 * propIdx + 1) + ": "));
        g.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        final TextBox propTextBox = new TextBox();
        propTextBox.addChangeListener(new ChangeCallback(this, row));
        propTextBox.setVisibleLength(30);
        propTextBox.setText(properties.get(4 * propIdx + 2));
        propTextBox.addFocusListener(new FocusHandler(this.hint, this.warningMessage));
        g.setWidget(i, 1, propTextBox);
      } else if ("KEYVALUEHIDDEN".equals(properties.get(4 * propIdx))) {
        g.setWidget(i, 0, new Label(properties.get(4 * propIdx + 1) + ": "));
        g.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        final TextBox propTextBox = new PasswordTextBox();
        propTextBox.addChangeListener(new ChangeCallback(this, row));
        propTextBox.setVisibleLength(30);
        propTextBox.setText(properties.get(4 * propIdx + 2));
        propTextBox.addFocusListener(new FocusHandler(this.hint, this.warningMessage));
        g.setWidget(i, 1, propTextBox);
      } else if ("BOOLEAN".equals(properties.get(4 * propIdx))) {
        final int index = propIdx;
        final CheckBox propCheckbox = new CheckBox();
        g.getCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT);
        g.setWidget(i, 0, propCheckbox);
        if (Boolean.parseBoolean(properties.get(4 * index + 2))) {
          propCheckbox.setChecked(true);
        } else {
          propCheckbox.setChecked(false);
        }
        propCheckbox.addClickListener(
            new ClickListener() {
              public void onClick(Widget sender) {
                if (((CheckBox) sender).isChecked()) {
                  properties.set(4 * index + 2, String.valueOf(true));
                } else {
                  properties.set(4 * index + 2, String.valueOf(false));
                }
              }
            });
        g.setWidget(i, 1, new Label(properties.get(propIdx * 4 + 1)));
      }
    }
    return g;
  }
 @Override
 public void setThemes(String theme) {
   transUnitTable.setStyleName("transUnitTable");
   transUnitTable.addStyleName(theme);
 }