List of usage examples for com.vaadin.ui AbstractTextField getValue
@Override
public String getValue()
From source file:at.peppol.webgui.app.components.TabInvoiceLine.java
License:Mozilla Public License
private void initElements() { invoiceLineList = parent.getInvoice().getInvoiceLine(); final GridLayout grid = new GridLayout(4, 4); final VerticalLayout outerLayout = new VerticalLayout(); hiddenContent = new VerticalLayout(); hiddenContent.setSpacing(true);//from w w w . j ava 2s .c o m hiddenContent.setMargin(true); table = new InvoiceLineTable(parent.getInvoice().getInvoiceLine()); table.setSelectable(true); table.setImmediate(true); table.setNullSelectionAllowed(false); table.setHeight(150, UNITS_PIXELS); table.setFooterVisible(false); table.addStyleName("striped strong"); //table.addListener(parent.new LinesTotalAmountListener()); //table.addListener(parent.new TaxExclusiveAmountListener()); final VerticalLayout tableContainer = new VerticalLayout(); tableContainer.addComponent(table); tableContainer.setMargin(false, true, false, false); // buttons Add, Edit, Delete final Button addBtn = new Button("Add new"); final Button editBtn = new Button("Edit selected"); final Button deleteBtn = new Button("Delete Selected"); addBtn.addListener(new Button.ClickListener() { @Override public void buttonClick(final Button.ClickEvent event) { addBtn.setEnabled(false); editBtn.setEnabled(false); deleteBtn.setEnabled(false); //addMode = true; hiddenContent.removeAllComponents(); invoiceLineItem = createInvoiceLineItem(); final Label formLabel = new Label("<h3>Adding new invoice line</h3>", Label.CONTENT_XHTML); hiddenContent.addComponent(formLabel); final Form form = createInvoiceLineMainForm(); hiddenContent.addComponent(form); HorizontalLayout h1 = new HorizontalLayout(); h1.setSpacing(true); h1.setMargin(true); // Set invoiceLine 0..N cardinality panels //final Panel itemPropertyPanel = new ItemPropertyForm ("Additional", // invoiceLineItem.getInvLineAdditionalItemPropertyList ()); final ItemPropertyForm itemPropertyPanel = new ItemPropertyForm("Additional", invoiceLineItem.getInvLineAdditionalItemPropertyList()); h1.addComponent(itemPropertyPanel); //add the allowance/charge indicator 0..N cardinality final InvoiceLineAllowanceChargeForm lineAllowanceChargePanel = new InvoiceLineAllowanceChargeForm( "", invoiceLineItem.getAllowanceCharge(), parent.getInvoice()); //add the listeners for line extension amount calculation BIIRULE_T10_R018 biirule_t10_r018 = new BIIRULE_T10_R018(invoiceLineItem, form); form.getField("Price Amount").addListener(biirule_t10_r018); form.getField("Base Quantity").addListener(biirule_t10_r018); form.getField("Invoiced Quantity").addListener(biirule_t10_r018); lineAllowanceChargePanel.getTable().addListener((ItemSetChangeListener) biirule_t10_r018); //add the listeners for VAT AE tax total amount EUGEN_T10_R018 eugen_t10_r018 = new EUGEN_T10_R018(form, "Tax Scheme ID", "Tax Category ID", "Tax Total Amount"); form.getField("Tax Scheme ID").addListener(eugen_t10_r018); form.getField("Tax Category ID").addListener(eugen_t10_r018); h1.addComponent(lineAllowanceChargePanel); HorizontalLayout h2 = new HorizontalLayout(); h2.setSpacing(true); h2.setMargin(true); final Panel lineOrderPanel = new InvoiceLineOrderForm("", invoiceLineItem.getInvLineOrderList()); h2.addComponent(lineOrderPanel); final Panel lineCommodityPanel = new InvoiceLineCommodityClassificationForm("", invoiceLineItem.getInvLineCommodityClassificationList()); h2.addComponent(lineCommodityPanel); hiddenContent.addComponent(h1); hiddenContent.addComponent(h2); // Save new line button final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(new Button("Save invoice line", new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { AbstractTextField itemName = (AbstractTextField) form.getField("Item Name"); itemName.setMaxLength(50); if (itemName.getValue().toString().length() > 50) { //itemName.setComponentError(new UserError("Item Name should not be more than 50 characters")); itemName.setValue(itemName.getValue().toString().substring(0, 49)); getWindow().showNotification("Item Name truncated to 50 chars", Notification.TYPE_TRAY_NOTIFICATION); } try { /*Collection<String> props = (Collection<String>) form.getItemPropertyIds(); List<Field> fields = new ArrayList<Field>(); for (String property : props) { fields.add(form.getField(property)); } List<BlurListener> listeners = new ArrayList<BlurListener>(); for (Field f : fields) { if (f instanceof AbstractTextField) { AbstractTextField ff = (AbstractTextField)f; listeners.addAll((Collection<BlurListener>) ff.getListeners(BlurEvent.class)); } } ValidatorsList.validateListenersNotify(listeners); form.validate();*/ Utils.validateFormFields(form); //form.commit(); // update table (and consequently add new item to invoiceList list) table.addLine(invoiceLineItem); //hide form hiddenContent.setVisible(false); //addMode = false; addBtn.setEnabled(true); editBtn.setEnabled(true); deleteBtn.setEnabled(true); //itemName.setComponentError(null); } catch (InvalidValueException e) { getWindow().showNotification("Invoice line has errors", Notification.TYPE_TRAY_NOTIFICATION); } } })); buttonLayout.addComponent(new Button("Cancel", new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { addBtn.setEnabled(true); editBtn.setEnabled(true); deleteBtn.setEnabled(true); hiddenContent.removeAllComponents(); // hide form hiddenContent.setVisible(false); addMode = false; } })); hiddenContent.addComponent(buttonLayout); // hiddenContent.setVisible(!hiddenContent.isVisible()); hiddenContent.setVisible(true); } }); editBtn.addListener(new Button.ClickListener() { @Override public void buttonClick(final Button.ClickEvent event) { final Object rowId = table.getValue(); // get the selected rows id if (rowId != null) { addBtn.setEnabled(true); editBtn.setEnabled(true); deleteBtn.setEnabled(true); final String sid = (String) table.getContainerProperty(rowId, "ID.value").getValue(); // TODO: PUT THIS IN FUNCTION BEGINS editMode = true; hiddenContent.removeAllComponents(); // get selected item invoiceLineItem = (InvoiceLineAdapter) invoiceLineList.get(table.getIndexFromID(sid)); // clone it to original item originalItem = new InvoiceLineAdapter(); cloneInvoiceLineItem(invoiceLineItem, originalItem); final Label formLabel = new Label("<h3>Editing invoice line</h3>", Label.CONTENT_XHTML); hiddenContent.addComponent(formLabel); final Form form = createInvoiceLineMainForm(); hiddenContent.addComponent(form); HorizontalLayout h1 = new HorizontalLayout(); h1.setSpacing(true); h1.setMargin(true); // Set invoiceLine 0..N cardinality panels final ItemPropertyForm itemPropertyPanel = new ItemPropertyForm("Additional", invoiceLineItem.getInvLineAdditionalItemPropertyList()); h1.addComponent(itemPropertyPanel); //add the allowance/charge indicator 0..N cardinality final InvoiceLineAllowanceChargeForm lineAllowanceChargePanel = new InvoiceLineAllowanceChargeForm( "", invoiceLineItem.getAllowanceCharge(), parent.getInvoice()); //add the listeners for line extension amount calculation BIIRULE_T10_R018 biirule_t10_r018 = new BIIRULE_T10_R018(invoiceLineItem, form); form.getField("Price Amount").addListener(biirule_t10_r018); form.getField("Base Quantity").addListener(biirule_t10_r018); lineAllowanceChargePanel.getTable().addListener((ItemSetChangeListener) biirule_t10_r018); //add the listeners for VAT AE tax total amount EUGEN_T10_R018 eugen_t10_r018 = new EUGEN_T10_R018(form, "Tax Scheme ID", "Tax Category ID", "Tax Total Amount"); form.getField("Tax Scheme ID").addListener(eugen_t10_r018); form.getField("Tax Category ID").addListener(eugen_t10_r018); h1.addComponent(lineAllowanceChargePanel); HorizontalLayout h2 = new HorizontalLayout(); h2.setSpacing(true); h2.setMargin(true); final Panel lineOrderPanel = new InvoiceLineOrderForm("", invoiceLineItem.getInvLineOrderList()); h2.addComponent(lineOrderPanel); final Panel lineCommodityPanel = new InvoiceLineCommodityClassificationForm("", invoiceLineItem.getInvLineCommodityClassificationList()); h2.addComponent(lineCommodityPanel); hiddenContent.addComponent(h1); hiddenContent.addComponent(h2); /*// Set invoiceLine 0..N cardinalily panels final Panel itemPropertyPanel = new ItemPropertyForm ("Additional", invoiceLineItem.getInvLineAdditionalItemPropertyList ()); hiddenContent.addComponent (itemPropertyPanel);*/ // Save new line button final HorizontalLayout buttonLayout = new HorizontalLayout(); buttonLayout.setSpacing(true); buttonLayout.addComponent(new Button("Save changes", new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { // update table (and consequently edit item to allowanceChargeList // list) AbstractTextField itemName = (AbstractTextField) form.getField("Item Name"); itemName.setMaxLength(50); if (itemName.getValue().toString().length() > 50) { //itemName.setComponentError(new UserError("Item Name should not be more than 50 characters")); itemName.setValue(itemName.getValue().toString().substring(0, 49)); getWindow().showNotification("Item Name truncated to 50 chars", Notification.TYPE_TRAY_NOTIFICATION); } try { /*Collection<String> props = (Collection<String>) form.getItemPropertyIds(); List<Field> fields = new ArrayList<Field>(); for (String property : props) { fields.add(form.getField(property)); } List<BlurListener> listeners = new ArrayList<BlurListener>(); for (Field f : fields) { if (f instanceof AbstractTextField) { AbstractTextField ff = (AbstractTextField)f; listeners.addAll((Collection<BlurListener>) ff.getListeners(BlurEvent.class)); } } ValidatorsList.validateListenersNotify(listeners); form.validate();*/ Utils.validateFormFields(form); //table.setInvoiceLine (sid, invoiceLineItem); table.setLine(sid, invoiceLineItem); addBtn.setEnabled(true); editBtn.setEnabled(true); deleteBtn.setEnabled(true); // hide form hiddenContent.setVisible(false); editMode = false; } catch (InvalidValueException e) { getWindow().showNotification("Invoice line has errors", Notification.TYPE_TRAY_NOTIFICATION); } } })); buttonLayout.addComponent(new Button("Cancel editing", new Button.ClickListener() { @Override public void buttonClick(final ClickEvent event) { hiddenContent.removeAllComponents(); addBtn.setEnabled(true); editBtn.setEnabled(true); deleteBtn.setEnabled(true); //table.setInvoiceLine (sid, originalItem); table.setLine(sid, originalItem); // hide form hiddenContent.setVisible(false); editMode = false; } })); hiddenContent.addComponent(buttonLayout); // hiddenContent.setVisible(!hiddenContent.isVisible()); hiddenContent.setVisible(true); // TODO: PUT THIS IN FUNCTION ENDS } else { parent.getWindow().showNotification("Info", "No table line is selected", Window.Notification.TYPE_HUMANIZED_MESSAGE); } } }); deleteBtn.addListener(new Button.ClickListener() { @Override public void buttonClick(final Button.ClickEvent event) { final Object rowId = table.getValue(); // get the selected rows id if (rowId != null) { if (table.getContainerProperty(rowId, "ID.value").getValue() != null) { final String sid = (String) table.getContainerProperty(rowId, "ID.value").getValue(); //table.removeInvoiceLine (sid); table.removeLine(sid); } } else { parent.getWindow().showNotification("Info", "No table line is selected", Window.Notification.TYPE_HUMANIZED_MESSAGE); } } }); final VerticalLayout buttonsContainer = new VerticalLayout(); buttonsContainer.setSpacing(true); buttonsContainer.addComponent(addBtn); buttonsContainer.addComponent(editBtn); buttonsContainer.addComponent(deleteBtn); final Panel outerPanel = new Panel("Invoice Line"); grid.addComponent(tableContainer, 0, 0); grid.addComponent(buttonsContainer, 1, 0); outerPanel.addComponent(grid); outerLayout.addComponent(outerPanel); // ---- HIDDEN FORM BEGINS ----- final VerticalLayout formLayout = new VerticalLayout(); formLayout.addComponent(hiddenContent); hiddenContent.setVisible(false); outerLayout.addComponent(formLayout); // ---- HIDDEN FORM ENDS ----- setLayout(outerLayout); grid.setSizeUndefined(); outerPanel.requestRepaintAll(); }
From source file:de.fatalix.bookery.view.admin.ServerSettingsLayout.java
License:Open Source License
@Override public void blur(FieldEvents.BlurEvent event) { SettingKey key = SettingKey.getEnumByKey(event.getComponent().getId()); for (AbstractTextField field : fields) { if (field.getId().equals(key.getKey())) { presenter.updateSetting(key, field.getValue()); break; }// w ww . jav a 2 s . c o m } }
From source file:edu.nps.moves.mmowgli.modules.registrationlogin.RoleSelectionPage.java
License:Open Source License
private String checkValue(AbstractTextField tf) { Object o = tf.getValue(); if (o != null) { String s = o.toString();/*from www . j a v a 2 s . c o m*/ if (s.length() > 255) // answer col in db should be glob, but until that's fixed, clamp at varchar(255) s = s.substring(0, 254); return s; } return null; }
From source file:org.vaadin.jefferson.content.TextControl.java
License:Open Source License
public String getText() { AbstractTextField presentation = getPresentation(); if (presentation == null) { return ""; }/*from w w w . j av a 2 s.c om*/ Object value = presentation.getValue(); return value == null ? "" : "" + value; }
From source file:sph.vaadin.TextFieldTrimmer.java
License:Apache License
/** * Returns the given <em>AbstractTextField</em>, with leading and trailing whitespace omitted from its value. * // ww w. j av a2 s .c om * @param tf the text field to trim. * @return the same text field trimmed. */ public static AbstractTextField trim(AbstractTextField tf) { String newVal = tf.getValue().trim(); tf.setValue(newVal); return tf; }