Beispiel #1
0
  @Test
  public void testButton() {
    Form form = new Form(request);
    Button button;

    button = Button.button("OK");
    assertOut(button, "<button>OK</button>");
    assertEquals(null, button.getName());
    form.add(button);
    assertEquals(form.getName() + "_button", button.getName());

    button = Button.reset("Reset");
    button.setDisabled();
    assertOut(button, "<button type='reset' disabled>Reset</button>");

    button = Button.submit("Submit");
    button.setName("submit");
    assertOut(button, "<button type='submit' name='submit' value='Submit'>Submit</button>");
    form.add(button);
    assertEquals("submit", button.getName());
    Button defaultButton = button;
    assertSame(form.getDefaultButton(), button);

    button = Button.inputButton("OK");
    assertOut(button, "<input type='button' value='OK'>");

    button = Button.inputReset("Reset");
    assertOut(button, "<input type='reset' value='Reset'>");

    button = Button.inputSubmit("Submit");
    button.setOnClick("alert()");
    assertOut(button, "<input type='submit' value='Submit' onclick='alert()'>");
    button.end(out);
    out.assertOut("");
    form.add(button);
    assertSame(defaultButton, form.getDefaultButton());

    // misc
    assertTrue(button.read(null));
    assertEquals(Control.Category.BUTTON, button.getCategory());

    assertFalse(defaultButton.isClicked());
    setParam(form.getName(), "");
    assertTrue(defaultButton.isClicked());
    assertFalse(button.isClicked());
    setParam(form.getName(), "reload");
    assertFalse(defaultButton.isClicked());
    setParam(defaultButton.getName(), "x");
    assertFalse(defaultButton.isClicked());
    setParam(defaultButton.getName(), defaultButton.getValue());
    assertTrue(defaultButton.isClicked());

    setParam(defaultButton.getName(), null);
    assertFalse(defaultButton.isDirectlyClicked());
    setParam(defaultButton.getName(), "x");
    assertFalse(defaultButton.isDirectlyClicked());
    setParam(defaultButton.getName(), defaultButton.getValue());
    assertTrue(defaultButton.isDirectlyClicked());
  }
Beispiel #2
0
 public void addButton(Button button, Align align, int idx, String width) {
   TTabBar tb =
       align == Align.LEFT ? leftToolbar : align == Align.CENTER ? centerToolbar : rightToolbar;
   idx = idx < 0 || idx > tb.getTabCount() ? tb.getTabCount() : idx;
   tb.insertTab(button.asWidget(), idx);
   TabBar.Tab t = tb.getTab(idx);
   tabs.put(button.getName(), new TabHolder(t, button, tb));
   width = StringUtils.isEmpty(width) ? defaultWidth : width;
   GwtUtil.setStyle(button.asWidget(), "minWidth", width);
 }
  public static HtmlInput[] addButtonsToExecContext(
      IExecContext execContext, List<Button> buttons, Theme theme) {

    HtmlInput[] inputs = new HtmlInput[buttons.size()];

    int i = 0;
    for (Button button : buttons) {
      HtmlInput input = button.draw(execContext, theme);
      execContext.put(button.getName(), input);
      inputs[i++] = input;
    }
    return inputs;
  }