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); }
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); }
public void resetState() { formPanel.setReadOnly(true); saveButton.setVisible(false); cancelButton.setVisible(false); updateButton.setVisible(true); updateButton.disable(); resetButton.setVisible(true); resetButton.disable(); if (permitedEnterprise.getCanAdd()) { addButton.enable(); } else { addButton.disable(); } if (permitedEnterprise.getCanUpdate()) { editButton.enable(); } else { editButton.disable(); } if (permitedEnterprise.getCanDelete()) { deleteButton.enable(); } else { deleteButton.disable(); } formPanel.reset(); if (grid.getSelectionModel().getSelection().size() > 0) { formBindings.bind((BeanModel) grid.getSelectionModel().getSelection().get(0)); } else { formBindings.unbind(); if (permitedEnterprise.getCanAdd()) { addButton.enable(); } else { addButton.disable(); } editButton.disable(); deleteButton.disable(); } }
private FormPanel createForm() { final FormPanel panel = new FormPanel(); panel.setLabelWidth(100); panel.setHeaderVisible(false); TextField<String> code = new TextField<String>(); code.setName("containerNo"); code.setFieldLabel("集装箱号"); code.setAllowBlank(false); panel.add(code); final ComboBox<BeanModel> size = new ComboBox<BeanModel>(); size.setTabIndex(9); size.setName("size"); size.setForceSelection(true); size.setEmptyText("请选择..."); size.setDisplayField("size"); size.setFieldLabel("尺寸"); size.setStore(containerSizeStore); size.setTypeAhead(true); size.setTriggerAction(TriggerAction.ALL); size.setAllowBlank(false); panel.add(size); size.addListener( Events.Blur, new Listener<FieldEvent>() { @Override public void handleEvent(FieldEvent be) { formBindings.getModel().set("valentNum", size.getValue().get("valentNum")); } }); ComboBox<BeanModel> type = new ComboBox<BeanModel>(); type.setTabIndex(9); type.setName("type"); type.setForceSelection(true); type.setEmptyText("请选择..."); type.setDisplayField("code"); type.setFieldLabel("类型"); type.setStore(ironChestStore); type.setTypeAhead(true); type.setTriggerAction(TriggerAction.ALL); panel.add(type); ComboBox<BeanModel> bracket = new ComboBox<BeanModel>(); bracket.setTabIndex(9); bracket.setName("bracket"); bracket.setForceSelection(true); bracket.setEmptyText("请选择..."); bracket.setDisplayField("code"); bracket.setFieldLabel("车架编号"); bracket.setStore(bracketStore); bracket.setTypeAhead(true); bracket.setTriggerAction(TriggerAction.ALL); panel.add(bracket); formBindings = new FormBinding(panel, true); formBindings .getBinding(size) .setConverter( new Converter() { @Override public Object convertFieldValue(Object value) { if (value == null) { return null; } return ((BeanModel) value).get("code").toString(); } @Override public Object convertModelValue(Object value) { if (value != null) { return containerSizeStore.findModel("code", (String) value); } else { return null; } } }); formBindings .getBinding(type) .setConverter( new Converter() { @Override public Object convertFieldValue(Object value) { if (value == null) { return null; } return ((BeanModel) value).get("code").toString(); } @Override public Object convertModelValue(Object value) { if (value != null) { return ironChestStore.findModel("code", (String) value); } else { return null; } } }); formBindings .getBinding(bracket) .setConverter( new Converter() { @Override public Object convertFieldValue(Object value) { if (value == null) { return null; } return ((BeanModel) value).get("code").toString(); } @Override public Object convertModelValue(Object value) { if (value != null) { return bracketStore.findModel("code", (String) value); } else { return null; } } }); formBindings.setStore((Store<BeanModel>) grid.getStore()); panel.setReadOnly(true); panel.setButtonAlign(HorizontalAlignment.CENTER); saveButton = new Button("保存"); saveButton.setVisible(false); saveButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { if (!panel.isValid()) return; save(); } }); panel.addButton(saveButton); cancelButton = new Button("取消"); cancelButton.setVisible(false); cancelButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { resetState(); } }); panel.addButton(cancelButton); updateButton = new Button("更新"); updateButton.disable(); updateButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { if (!panel.isValid()) return; update(); } }); panel.addButton(updateButton); resetButton = new Button("取消"); resetButton.disable(); resetButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { store.rejectChanges(); resetState(); } }); panel.addButton(resetButton); panel.setBorders(false); panel.setBodyBorder(false); return panel; }
@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); }