Example usage for com.vaadin.ui AbstractTextField setValue

List of usage examples for com.vaadin.ui AbstractTextField setValue

Introduction

In this page you can find the example usage for com.vaadin.ui AbstractTextField setValue.

Prototype

@Override
public void setValue(String value) 

Source Link

Document

Sets the value of this text field.

Usage

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 ww  .ja  v a 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

public void loadData() {
    for (AbstractTextField field : fields) {
        SettingKey key = SettingKey.getEnumByKey(field.getId());
        AppSetting setting = presenter.loadSetting(key);
        field.setValue(setting.getConfigurationValue());
    }//  w w w .ja v a  2 s  . c  om
    checkSolr();
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.ActionPlanPageTabPanel.java

License:Open Source License

protected void setValueIfNonNull(AbstractTextField comp, String s) {
    if (s != null)
        comp.setValue(s);
}

From source file:edu.nps.moves.mmowgli.modules.actionplans.MediaPanel.java

License:Open Source License

private void setValueIfNonNull(AbstractTextField comp, String s) {
    if (s != null)
        comp.setValue(s);
}

From source file:edu.nps.moves.mmowgli.modules.administration.AbstractGameBuilderPanel.java

License:Open Source License

private void populateEditLine(EditLine eLine) {
    if (eLine.fieldName != null) {
        try {//w w  w .  java2  s.  c  o  m
            Class<? extends Object> hiCls = eLine.getter.getDeclaringClass();
            if (eLine.ta instanceof AbstractTextField) {
                Method getter = hiCls.getDeclaredMethod("get" + eLine.fieldName, (Class<?>[]) null);
                Object dbObj = eLine.getter.invoke(null, new Object[] { eLine.objId });
                AbstractTextField atf = (AbstractTextField) eLine.ta;
                boolean origRo = atf.isReadOnly();
                atf.setReadOnly(false);
                Object val = getter.invoke(dbObj, (Object[]) null);
                atf.setValue(val == null ? "" : val.toString());
                atf.setReadOnly(origRo);
            } else if (eLine.ta instanceof CheckBox) {
                CheckBox cb = (CheckBox) eLine.ta;
                Method getter = hiCls.getDeclaredMethod("is" + eLine.fieldName, (Class<?>[]) null);
                Object dbObj = eLine.getter.invoke(null, new Object[] { eLine.objId });
                boolean origRo = cb.isReadOnly();
                cb.setReadOnly(false);
                Object val = getter.invoke(dbObj, (Object[]) null);
                ((CheckBox) eLine.ta).setValue(val == null ? Boolean.FALSE : (Boolean) val);
                cb.setReadOnly(origRo);
            }
        } catch (Exception exc) {
            System.err.println("Programming error in AbstractGameBuilderPanel.populateEditLine: "
                    + exc.getClass().getSimpleName() + ": " + exc.getLocalizedMessage());
            exc.printStackTrace();
        }
    }
}

From source file:org.opennms.features.vaadin.dashboard.config.ui.WallboardEditor.java

License:Open Source License

/**
 * Constructor used for instantiating a new object.
 *
 * @param dashletSelector the {@link DashletSelector} to be used
 * @param wallboard       the associated {@link Wallboard} instance
 *///from   w  ww  .j a  v a 2 s.c  o m
public WallboardEditor(DashletSelector dashletSelector, Wallboard wallboard) {
    /**
     * Setting the member fields
     */
    this.m_dashletSelector = dashletSelector;
    this.m_wallboard = wallboard;

    /**
     * Adding the {@link DashletSpec} instances
     */
    for (DashletSpec dashletSpec : wallboard.getDashletSpecs()) {
        addDashletSpec(dashletSpec);
    }

    /**
     * Setting up layout component and adding text field and button
     */
    setMargin(true);

    HorizontalLayout upperHorizontalLayout = new HorizontalLayout();
    Label label = new Label("Ops Board configuration");
    label.addStyleName("configuration-title");
    upperHorizontalLayout.addComponent(label);

    upperHorizontalLayout.addComponent(label);
    Button helpButton = new Button("Help");
    helpButton.setDescription("Display help and usage");

    helpButton.setStyleName("small");
    helpButton.addClickListener(new HelpClickListener(this, m_dashletSelector));

    upperHorizontalLayout.addComponent(helpButton);
    upperHorizontalLayout.setWidth(100, Unit.PERCENTAGE);

    upperHorizontalLayout.setComponentAlignment(label, Alignment.MIDDLE_LEFT);
    upperHorizontalLayout.setComponentAlignment(helpButton, Alignment.MIDDLE_RIGHT);

    addComponent(upperHorizontalLayout);

    HorizontalLayout horizontalLayout = new HorizontalLayout();

    final Button addButton = new Button("Add dashlet");

    addButton.setStyleName("small");
    addButton.setDescription("Add a new dashlet instance");
    addButton.addClickListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent clickEvent) {
            addDashletSpec(new DashletSpec());
        }
    });

    final TextField titleField = new TextField();
    titleField.setDescription("Title for this Ops Board configuration");
    titleField.setValue(wallboard.getTitle());
    titleField.setImmediate(true);
    titleField.addValidator(new AbstractStringValidator("Title must be unique") {
        @Override
        protected boolean isValidValue(String s) {
            return (!WallboardProvider.getInstance().containsWallboard(s)
                    || WallboardProvider.getInstance().getWallboard(s).equals(m_wallboard)) && !"".equals(s);
        }
    });

    titleField.addTextChangeListener(new FieldEvents.TextChangeListener() {
        public void textChange(FieldEvents.TextChangeEvent textChangeEvent) {
            AbstractTextField source = (AbstractTextField) textChangeEvent.getSource();
            source.setValue(textChangeEvent.getText());
            if (source.isValid()) {
                m_tab.setCaption(textChangeEvent.getText());
                m_wallboard.setTitle(textChangeEvent.getText());
                WallboardProvider.getInstance().save();
                ((WallboardConfigUI) getUI()).notifyMessage("Data saved", "Title");
            }
        }
    });

    titleField.setCaption("Title");

    final Button previewButton = new Button("Preview");
    previewButton.setDescription("Preview this Ops Board configuration");
    previewButton.setStyleName("small");
    previewButton.addClickListener(new PreviewClickListener(this, m_wallboard));

    /**
     * Adding the layout components to this component
     */
    FormLayout formLayout1 = new FormLayout();
    formLayout1.addComponent(titleField);
    horizontalLayout.addComponent(formLayout1);

    FormLayout formLayout2 = new FormLayout();
    formLayout2.addComponent(addButton);
    horizontalLayout.addComponent(formLayout2);

    FormLayout formLayout3 = new FormLayout();
    formLayout3.addComponent(previewButton);
    horizontalLayout.addComponent(formLayout3);

    addComponent(horizontalLayout);
    addComponent(m_verticalLayout);
}

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.
 * /*  w  w  w . j  a  v  a  2  s .c o m*/
 * @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;
}