protected java.sql.Date getDate(String s) { try { return new java.sql.Date(((DateField) map.get(s)).getValue().getTime()); } catch (Exception ex) { return null; } }
public TableEditorWindow(final Table table, final Object value, Object... dates) { for (Object o : dates) dates2.add(o); VerticalLayout content = new VerticalLayout(); Object[] columns = table.getVisibleColumns(); String[] headers = table.getColumnHeaders(); int n = columns.length; for (int i = 0; i < n; ++i) { HorizontalLayout lay = new HorizontalLayout(); Label l = new Label(headers[i]); lay.addComponent(l); Component field = dates2.contains(columns[i]) ? new DateField() : new TextField(); lay.addComponent(field); map.put(columns[i], field); content.addComponent(lay); lay.setComponentAlignment(l, Alignment.MIDDLE_LEFT); lay.setComponentAlignment(field, Alignment.MIDDLE_RIGHT); } if (value != null) { Item item = table.getItem(value); for (Object o : columns) { Object val = item.getItemProperty(o).getValue(); if (dates2.contains(o)) { ((DateField) map.get(o)).setValue((Date) val); } else { ((TextField) map.get(o)).setValue(val.toString()); } } } save = new Button("Записать"); content.addComponent(save); save.addClickListener( new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { if (actionPerformed()) close(); } }); setContent(content); }
protected void replaceToCombo(String key, Container container, String defaultValue) { final TextField field = (TextField) map.get(key); HorizontalLayout layout = (HorizontalLayout) field.getParent(); field.setVisible(false); final ComboBox comboBox = new ComboBox("", container); comboBox.setImmediate(true); comboBox.setNullSelectionAllowed(false); comboBox.addValueChangeListener( new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { field.setValue((String) comboBox.getValue()); } }); if (container.containsId(field.getValue())) { comboBox.select(field.getValue()); } else { field.setValue(defaultValue); comboBox.select(defaultValue); } layout.addComponent(comboBox, 1); }
protected void setNotNull(String key) { if (map.containsKey(key)) setNotNull((AbstractField) map.get(key)); }
protected String getString(String s) { return ((TextField) map.get(s)).getValue(); }