예제 #1
0
  public SimpleCombos(String text) {
    super(text);
    this.setLayout(new RowLayout());
    FormPanel fp = new FormPanel();

    ComboBox comboEntryKey = ComboFactory.buildStaticCombo("ERROR_CATEGORY");
    comboEntryKey.setFieldLabel("Wybierz");
    ComboBox comboId = ComboFactory.buildStaticCombo("ERROR_CATEGORY");
    comboId.setFieldLabel("Wybierz");
    ComboBox comboValue = ComboFactory.buildStaticCombo("ERROR_CATEGORY");
    comboValue.setFieldLabel("Wybierz");
    ComboBox comboComment = ComboFactory.buildStaticCombo("ERROR_CATEGORY");
    comboComment.setFieldLabel("Wybierz");
    TextField entryKey = new TextField();
    entryKey.setFieldLabel("entryKey");
    TextField id = new TextField();
    id.setFieldLabel("id");
    TextField value = new TextField();
    value.setFieldLabel("value");
    TextField comment = new TextField();
    comment.setFieldLabel("comment");

    fp.add(comboEntryKey);
    fp.add(comboId);
    fp.add(comboValue);
    fp.add(comboComment);
    fp.add(entryKey);
    fp.add(id);
    fp.add(value);
    fp.add(comment);

    FormBinding fb = new FormBinding(fp);
    ModelExample model = new ModelExample();

    fb.bind(model);

    fb.addFieldBinding(
        new DictionaryComboBindingToStringField(
            comboEntryKey, "modelEntryKey", DictionaryEntry.EntryProperty.entryKey));
    fb.addFieldBinding(
        new DictionaryComboBindingToStringField(
            comboId, "modelId", DictionaryEntry.EntryProperty.id));
    fb.addFieldBinding(
        new DictionaryComboBindingToStringField(
            comboValue, "modelValue", DictionaryEntry.EntryProperty.value));
    fb.addFieldBinding(
        new DictionaryComboBindingToStringField(
            comboComment, "modelComment", DictionaryEntry.EntryProperty.comment));
    fb.addFieldBinding(new FieldBinding(entryKey, "modelEntryKey"));
    fb.addFieldBinding(new FieldBinding(id, "modelId"));
    fb.addFieldBinding(new FieldBinding(value, "modelValue"));
    fb.addFieldBinding(new FieldBinding(comment, "modelComment"));

    comboEntryKey.setEditable(false);
    comboEntryKey.setEmptyText("wybierz");
    this.add(fp);
  }
예제 #2
0
  public AttributeForm() {

    binding = new FormBinding(this);

    final NumberField idField = new NumberField();
    idField.setFieldLabel("ID");
    idField.setReadOnly(true);
    binding.addFieldBinding(new FieldBinding(idField, "id"));
    add(idField);

    TextField<String> nameField = new TextField<String>();
    nameField.setFieldLabel(I18N.CONSTANTS.name());
    nameField.setMaxLength(AttributeDTO.NAME_MAX_LENGTH);
    binding.addFieldBinding(new OnlyValidFieldBinding(nameField, "name"));

    add(nameField);

    hideFieldWhenNull(idField);
  }
예제 #3
0
  @Override
  protected void onRender(Element parent, int index) {
    super.onRender(parent, index);

    final Stock stock = TestData.getStocks().get(0);

    HorizontalPanel hp = new HorizontalPanel();
    hp.setSpacing(10);

    StringBuffer sb = new StringBuffer();
    sb.append("<div class=text style='line-height: 1.5em'>");
    sb.append("<b>Name:</b> {name}<br>");
    sb.append("<b>Symbol:</b> {symbol}<br>");
    sb.append("<b>Last:</b> {last}<br>");
    sb.append("<b>Change:</b> {[new Number(values.change).toFixed(2)]}<br>");
    sb.append("<b>Updated:</b> {date:date(\"MM/dd/y\")}<br>");
    sb.append("</div>");

    final XTemplate template = XTemplate.create(sb.toString());
    final HTML html = new HTML();
    html.setWidth("160px");
    template.overwrite(html.getElement(), Util.getJsObject(stock));
    hp.add(html);
    // update template when model changes
    stock.addChangeListener(
        new ChangeListener() {
          public void modelChanged(ChangeEvent event) {
            template.overwrite(html.getElement(), Util.getJsObject(stock));
          }
        });

    FormPanel panel = new FormPanel();
    panel.setHeaderVisible(false);
    panel.setWidth(350);

    TextField<String> name = new TextField<String>();
    name.setName("nameField");
    name.setFieldLabel("Name");
    panel.add(name);

    TextField<String> symbol = new TextField<String>();
    symbol.setName("symbol");
    symbol.setFieldLabel("Symbol");
    panel.add(symbol);

    NumberField open = new NumberField();
    open.setName("last");
    open.setFieldLabel("Last");
    panel.add(open);

    NumberField change = new NumberField();
    change.setName("change");
    change.setFieldLabel("Change");
    change.setFormat(NumberFormat.getDecimalFormat());
    panel.add(change);

    DateField last = new DateField();
    last.setName("date");
    last.setFieldLabel("Updated");
    panel.add(last);

    SimpleComboBox<String> scb = new SimpleComboBox<String>();
    for (Stock s : TestData.getStocks()) {
      scb.add(s.getName());
    }
    scb.setFieldLabel("Name");
    scb.setForceSelection(true);
    scb.setTypeAhead(true);
    scb.setName("company");
    scb.setTriggerAction(TriggerAction.ALL);
    panel.add(scb);

    hp.add(panel);

    FormBinding binding = new FormBinding(panel);
    // manually add bindings
    binding.addFieldBinding(new FieldBinding(name, "name"));
    binding.addFieldBinding(new FieldBinding(symbol, "symbol"));
    binding.addFieldBinding(new SimpleComboBoxFieldBinding(scb, "name"));

    // auto bind remaining fields, field name must match model property name
    binding.autoBind();
    binding.bind(stock);

    add(hp);
  }