Example usage for com.vaadin.ui TextField getValue

List of usage examples for com.vaadin.ui TextField getValue

Introduction

In this page you can find the example usage for com.vaadin.ui TextField getValue.

Prototype

@Override
    public String getValue() 

Source Link

Usage

From source file:com.esspl.datagen.generator.impl.ExcelDataGenerator.java

License:Open Source License

/**
  * Actual data generation logic for EXCEL present here
  *//*from   w  w w. j a  v  a2 s  . c  o  m*/
@Override
public String generate(DataGenApplication dataGenApplication, ArrayList<GeneratorBean> rowList) {
    log.debug("ExcelDataGenerator - generate() method start");
    File tempFile = null;
    try {
        tempFile = File.createTempFile("tmp", ".xls");
        WritableWorkbook workbook = Workbook.createWorkbook(tempFile);
        WritableSheet sheet = workbook.createSheet("Data Sheet", 0);

        int maxRows = Integer.parseInt(dataGenApplication.resultNum.getValue().toString());
        DataFactory df = new DataFactory();
        for (int row = 0; row < maxRows; row++) {
            int counter = 0;
            for (GeneratorBean generatorBean : rowList) {
                String data = "";
                String dataType = generatorBean.getDataType();
                int iid = generatorBean.getId();
                Item item = dataGenApplication.listing.getItem(iid);
                Select selFormat = (Select) (item.getItemProperty("Format").getValue());
                if (dataType.equalsIgnoreCase("name")) {
                    data = df.getName(selFormat.getValue().toString());
                } else if (dataType.equalsIgnoreCase("email")) {
                    data = df.getEmailAddress();
                } else if (dataType.equalsIgnoreCase("date")) {
                    HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                            .getValue());
                    PopupDateField startDate = (PopupDateField) hLayout.getComponent(0);
                    PopupDateField endDate = (PopupDateField) hLayout.getComponent(1);
                    SimpleDateFormat sdf = new SimpleDateFormat(selFormat.getValue().toString());
                    String formatedStatDate = (startDate.getValue() == null
                            || startDate.getValue().toString().equals("")) ? ""
                                    : sdf.format(startDate.getValue()).toString();
                    String formatedEndDate = (endDate.getValue() == null
                            || endDate.getValue().toString().equals("")) ? ""
                                    : sdf.format(endDate.getValue()).toString();
                    data = df.getDate(selFormat.getValue().toString(), formatedStatDate, formatedEndDate);
                } else if (dataType.equalsIgnoreCase("city")) {
                    data = df.getCity();
                } else if (dataType.equalsIgnoreCase("state/provience/county")) {
                    data = df.getState(selFormat.getValue().toString());
                } else if (dataType.equalsIgnoreCase("postal/zip")) {
                    data = df.getZipCode(selFormat.getValue().toString());
                } else if (dataType.equalsIgnoreCase("street address")) {
                    data = df.getStreetName();
                } else if (dataType.equalsIgnoreCase("title")) {
                    data = df.getPrefix();
                } else if (dataType.equalsIgnoreCase("phone/fax")) {
                    data = df.getPhoneNumber(selFormat.getValue().toString());
                } else if (dataType.equalsIgnoreCase("country")) {
                    data = df.getCountry();
                } else if (dataType.equalsIgnoreCase("random text")) {
                    HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                            .getValue());
                    TextField minLengthField = (TextField) hLayout.getComponent(0);
                    TextField maxLengthField = (TextField) hLayout.getComponent(1);
                    int minLength = (minLengthField.getValue() == null
                            || minLengthField.getValue().toString().equals("")) ? 3
                                    : Integer.parseInt(minLengthField.getValue().toString());
                    int maxLength = (maxLengthField.getValue() == null
                            || maxLengthField.getValue().toString().equals("")) ? 10
                                    : Integer.parseInt(maxLengthField.getValue().toString());
                    data = df.getRandomText(minLength, maxLength);
                } else if (dataType.equalsIgnoreCase("incremental number")) {
                    HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                            .getValue());
                    TextField startingFrom = (TextField) hLayout.getComponent(0);
                    int startNumber = (startingFrom.getValue() == null
                            || startingFrom.getValue().toString().equals("")) ? 0
                                    : Integer.parseInt(startingFrom.getValue().toString());
                    if (startNumber > 0) {
                        data = String.valueOf(row + startNumber);
                    } else {
                        data = String.valueOf(row + 1);
                    }
                } else if (dataType.equalsIgnoreCase("number range")) {
                    HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                            .getValue());
                    TextField minNumberField = (TextField) hLayout.getComponent(0);
                    TextField maxNumberField = (TextField) hLayout.getComponent(1);
                    int minNumber = (minNumberField.getValue() == null
                            || minNumberField.getValue().toString().equals("")) ? 1
                                    : Integer.parseInt(minNumberField.getValue().toString());
                    int maxNumber = (maxNumberField.getValue() == null
                            || maxNumberField.getValue().toString().equals("")) ? 1000
                                    : Integer.parseInt(maxNumberField.getValue().toString());
                    data = String.valueOf(df.getNumberBetween(minNumber, maxNumber));
                } else if (dataType.equalsIgnoreCase("alphanumeric")) {
                    HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                            .getValue());
                    TextField startingTextField = (TextField) hLayout.getComponent(0);
                    TextField lengthField = (TextField) hLayout.getComponent(1);
                    String startingText = (startingTextField.getValue() == null
                            || startingTextField.getValue().toString().equals("")) ? ""
                                    : startingTextField.getValue().toString();
                    int length = (lengthField.getValue() == null
                            || lengthField.getValue().toString().equals("")) ? 6
                                    : Integer.parseInt(lengthField.getValue().toString());
                    data = df.getAlphaNumericText(startingText, length);
                } else if (dataType.equalsIgnoreCase("maratial status")) {
                    data = df.getStatus();
                } else if (dataType.equalsIgnoreCase("department name")) {
                    data = df.getBusinessType();
                } else if (dataType.equalsIgnoreCase("company name")) {
                    data = df.getCompanyName();
                } else if (dataType.equalsIgnoreCase("fixed text")) {
                    HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                            .getValue());
                    TextField textField = (TextField) hLayout.getComponent(0);
                    String fixedText = (textField.getValue() == null
                            || textField.getValue().toString().equals("")) ? ""
                                    : textField.getValue().toString();
                    data = fixedText;
                } else if (dataType.equalsIgnoreCase("boolean flag")) {
                    data = df.getBooleanFlag();
                } else if (dataType.equalsIgnoreCase("passport number")) {
                    data = df.getPassportNumber();
                }

                //Set the Headers for first time
                if (row == 0) {
                    Colour bckcolor = Colour.BLUE_GREY;
                    WritableCellFormat cellFormat = new WritableCellFormat();
                    cellFormat.setBackground(bckcolor);
                    cellFormat.setShrinkToFit(true);

                    WritableFont font = new WritableFont(WritableFont.ARIAL);
                    font.setBoldStyle(WritableFont.BOLD);
                    cellFormat.setFont(font);

                    Label headerlabel = new Label(counter, row, generatorBean.getColumnName());
                    sheet.addCell(headerlabel);
                    WritableCell cell = sheet.getWritableCell(counter, row);
                    cell.setCellFormat(cellFormat);
                }

                //This Label is from JXL api not from VAADIN
                Label dataLabel = new Label(counter, row + 1, data);
                sheet.addCell(dataLabel);
                counter++;
            }
        }

        workbook.write();
        workbook.close();

        DataGenStreamUtil resource = new DataGenStreamUtil(dataGenApplication, "data.xls",
                "application/vnd.ms-excel", tempFile);
        dataGenApplication.getMainWindow().getWindow().open(resource, "_self");
    } catch (WriteException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return "Success";
}

From source file:com.esspl.datagen.generator.impl.SqlDataGenerator.java

License:Open Source License

/**
 * Actual data generation logic for SQL present here
 *///from  w  w w  . j a v  a 2 s.  c om
@Override
public String generate(DataGenApplication dataGenApplication, ArrayList<GeneratorBean> rowList) {
    log.debug("SqlDataGenerator - generate() method start");
    sbCreate.setLength(0);
    sbInsert.setLength(0);
    int maxRows = Integer.parseInt(dataGenApplication.resultNum.getValue().toString());
    tableName = dataGenApplication.tblName.getValue().toString();
    database = dataGenApplication.database.getValue().toString();
    isCreateScriptRequired = Boolean.valueOf(dataGenApplication.createQuery.getValue().toString());

    if (database.equals("Sql Server")) {
        lineSeparator = "\nGO";
    } else {
        lineSeparator = ";";
    }

    //If generate create script is enabled then create script generatd
    if (isCreateScriptRequired) {
        generateCreateData(rowList);
    }

    DataFactory df = new DataFactory();
    for (int row = 0; row < maxRows; row++) {
        StringBuilder sbColumnNames = new StringBuilder();
        sbColumnNames.append("(");
        StringBuilder sb = new StringBuilder();
        for (GeneratorBean generatorBean : rowList) {
            String data = "";
            String dataType = generatorBean.getDataType();
            int iid = generatorBean.getId();
            Item item = dataGenApplication.listing.getItem(iid);
            Select selFormat = (Select) (item.getItemProperty("Format").getValue());
            if (dataType.equalsIgnoreCase("name")) {
                data = "'" + df.getName(selFormat.getValue().toString()) + "'";
            } else if (dataType.equalsIgnoreCase("email")) {
                data = "'" + df.getEmailAddress() + "'";
            } else if (dataType.equalsIgnoreCase("date")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                PopupDateField startDate = (PopupDateField) hLayout.getComponent(0);
                PopupDateField endDate = (PopupDateField) hLayout.getComponent(1);
                SimpleDateFormat sdf = new SimpleDateFormat(selFormat.getValue().toString());
                String formatedStatDate = (startDate.getValue() == null
                        || startDate.getValue().toString().equals("")) ? ""
                                : sdf.format(startDate.getValue()).toString();
                String formatedEndDate = (endDate.getValue() == null
                        || endDate.getValue().toString().equals("")) ? ""
                                : sdf.format(endDate.getValue()).toString();
                data = "to_date('"
                        + df.getDate(selFormat.getValue().toString(), formatedStatDate, formatedEndDate)
                        + "', '" + selFormat.getValue().toString() + "')";
            } else if (dataType.equalsIgnoreCase("city")) {
                data = "'" + df.getCity() + "'";
            } else if (dataType.equalsIgnoreCase("state/provience/county")) {
                data = "'" + df.getState(selFormat.getValue().toString()) + "'";
            } else if (dataType.equalsIgnoreCase("postal/zip")) {
                data = df.getZipCode(selFormat.getValue().toString());
            } else if (dataType.equalsIgnoreCase("street address")) {
                data = "'" + df.getStreetName() + "'";
            } else if (dataType.equalsIgnoreCase("title")) {
                data = "'" + df.getPrefix() + "'";
            } else if (dataType.equalsIgnoreCase("phone/fax")) {
                data = df.getPhoneNumber(selFormat.getValue().toString());
            } else if (dataType.equalsIgnoreCase("country")) {
                data = "'" + df.getCountry() + "'";
            } else if (dataType.equalsIgnoreCase("random text")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField minLengthField = (TextField) hLayout.getComponent(0);
                TextField maxLengthField = (TextField) hLayout.getComponent(1);
                int minLength = (minLengthField.getValue() == null
                        || minLengthField.getValue().toString().equals("")) ? 3
                                : Integer.parseInt(minLengthField.getValue().toString());
                int maxLength = (maxLengthField.getValue() == null
                        || maxLengthField.getValue().toString().equals("")) ? 10
                                : Integer.parseInt(maxLengthField.getValue().toString());
                data = "'" + df.getRandomText(minLength, maxLength) + "'";
            } else if (dataType.equalsIgnoreCase("incremental number")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField startingFrom = (TextField) hLayout.getComponent(0);
                int startNumber = (startingFrom.getValue() == null
                        || startingFrom.getValue().toString().equals("")) ? 0
                                : Integer.parseInt(startingFrom.getValue().toString());
                if (startNumber > 0) {
                    data = String.valueOf(row + startNumber);
                } else {
                    data = String.valueOf(row + 1);
                }
            } else if (dataType.equalsIgnoreCase("number range")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField minNumberField = (TextField) hLayout.getComponent(0);
                TextField maxNumberField = (TextField) hLayout.getComponent(1);
                int minNumber = (minNumberField.getValue() == null
                        || minNumberField.getValue().toString().equals("")) ? 1
                                : Integer.parseInt(minNumberField.getValue().toString());
                int maxNumber = (maxNumberField.getValue() == null
                        || maxNumberField.getValue().toString().equals("")) ? 1000
                                : Integer.parseInt(maxNumberField.getValue().toString());
                data = String.valueOf(df.getNumberBetween(minNumber, maxNumber));
            } else if (dataType.equalsIgnoreCase("alphanumeric")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField startingTextField = (TextField) hLayout.getComponent(0);
                TextField lengthField = (TextField) hLayout.getComponent(1);
                String startingText = (startingTextField.getValue() == null
                        || startingTextField.getValue().toString().equals("")) ? ""
                                : startingTextField.getValue().toString();
                int length = (lengthField.getValue() == null || lengthField.getValue().toString().equals(""))
                        ? 6
                        : Integer.parseInt(lengthField.getValue().toString());
                data = "'" + df.getAlphaNumericText(startingText, length) + "'";
            } else if (dataType.equalsIgnoreCase("maratial status")) {
                data = "'" + df.getStatus() + "'";
            } else if (dataType.equalsIgnoreCase("department name")) {
                data = "'" + df.getBusinessType() + "'";
            } else if (dataType.equalsIgnoreCase("company name")) {
                data = "'" + df.getCompanyName() + "'";
            } else if (dataType.equalsIgnoreCase("fixed text")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField textField = (TextField) hLayout.getComponent(0);
                String fixedText = (textField.getValue() == null || textField.getValue().toString().equals(""))
                        ? ""
                        : textField.getValue().toString();

                CheckBox cb = (CheckBox) hLayout.getComponent(1);
                if (cb.getValue() != null && Boolean.valueOf(cb.getValue().toString())) {
                    data = fixedText;
                } else {
                    data = "'" + fixedText + "'";
                }
            } else if (dataType.equalsIgnoreCase("boolean flag")) {
                data = "'" + df.getBooleanFlag() + "'";
            } else if (dataType.equalsIgnoreCase("passport number")) {
                data = "'" + df.getPassportNumber() + "'";
            }

            if (sb.length() > 0)
                sb.append(", ");
            sb.append(data);

            if (sbColumnNames.length() > 1)
                sbColumnNames.append(", ");
            sbColumnNames.append(generatorBean.getColumnName());
        }
        sbColumnNames.append(")");
        addResultData("INSERT INTO " + tableName + sbColumnNames.toString() + " VALUES(" + sb.toString() + ")");
    }

    log.debug("SqlDataGenerator - generate() method end");
    return getCreateData() + getResultData();
}

From source file:com.esspl.datagen.generator.impl.XmlDataGenerator.java

License:Open Source License

/**
 * Actual data generation logic for XML present here
 *///w w w . j av  a2 s .  c  o  m
@Override
public String generate(DataGenApplication dataGenApplication, ArrayList<GeneratorBean> rowList) {
    log.debug("XmlDataGenerator - generate() method start");
    int maxRows = Integer.parseInt(dataGenApplication.resultNum.getValue().toString());
    rootNodeName = dataGenApplication.rootNode.getValue().toString();
    recordNodeName = dataGenApplication.recordNode.getValue().toString();
    sbXml.setLength(0);
    sbXml.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    sbXml.append("<" + rootNodeName + ">\n");

    DataFactory df = new DataFactory();
    for (int row = 0; row < maxRows; row++) {
        StringBuilder sbColumnNames = new StringBuilder();
        sbColumnNames.append("\t<" + recordNodeName + ">\n");
        for (GeneratorBean generatorBean : rowList) {
            String data = "";
            String dataType = generatorBean.getDataType();
            int iid = generatorBean.getId();
            Item item = dataGenApplication.listing.getItem(iid);
            Select selFormat = (Select) (item.getItemProperty("Format").getValue());
            if (dataType.equalsIgnoreCase("name")) {
                data = df.getName(selFormat.getValue().toString());
            } else if (dataType.equalsIgnoreCase("email")) {
                data = df.getEmailAddress();
            } else if (dataType.equalsIgnoreCase("date")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                PopupDateField startDate = (PopupDateField) hLayout.getComponent(0);
                PopupDateField endDate = (PopupDateField) hLayout.getComponent(1);
                SimpleDateFormat sdf = new SimpleDateFormat(selFormat.getValue().toString());
                String formatedStatDate = (startDate.getValue() == null
                        || startDate.getValue().toString().equals("")) ? ""
                                : sdf.format(startDate.getValue()).toString();
                String formatedEndDate = (endDate.getValue() == null
                        || endDate.getValue().toString().equals("")) ? ""
                                : sdf.format(endDate.getValue()).toString();
                data = df.getDate(selFormat.getValue().toString(), formatedStatDate, formatedEndDate);
            } else if (dataType.equalsIgnoreCase("city")) {
                data = df.getCity();
            } else if (dataType.equalsIgnoreCase("state/provience/county")) {
                data = df.getState(selFormat.getValue().toString());
            } else if (dataType.equalsIgnoreCase("postal/zip")) {
                data = df.getZipCode(selFormat.getValue().toString());
            } else if (dataType.equalsIgnoreCase("street address")) {
                data = df.getStreetName();
            } else if (dataType.equalsIgnoreCase("title")) {
                data = df.getPrefix();
            } else if (dataType.equalsIgnoreCase("phone/fax")) {
                data = df.getPhoneNumber(selFormat.getValue().toString());
            } else if (dataType.equalsIgnoreCase("country")) {
                data = df.getCountry();
            } else if (dataType.equalsIgnoreCase("random text")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField minLengthField = (TextField) hLayout.getComponent(0);
                TextField maxLengthField = (TextField) hLayout.getComponent(1);
                int minLength = (minLengthField.getValue() == null
                        || minLengthField.getValue().toString().equals("")) ? 3
                                : Integer.parseInt(minLengthField.getValue().toString());
                int maxLength = (maxLengthField.getValue() == null
                        || maxLengthField.getValue().toString().equals("")) ? 10
                                : Integer.parseInt(maxLengthField.getValue().toString());
                data = df.getRandomText(minLength, maxLength);
            } else if (dataType.equalsIgnoreCase("incremental number")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField startingFrom = (TextField) hLayout.getComponent(0);
                int startNumber = (startingFrom.getValue() == null
                        || startingFrom.getValue().toString().equals("")) ? 0
                                : Integer.parseInt(startingFrom.getValue().toString());
                if (startNumber > 0) {
                    data = String.valueOf(row + startNumber);
                } else {
                    data = String.valueOf(row + 1);
                }
            } else if (dataType.equalsIgnoreCase("number range")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField minNumberField = (TextField) hLayout.getComponent(0);
                TextField maxNumberField = (TextField) hLayout.getComponent(1);
                int minNumber = (minNumberField.getValue() == null
                        || minNumberField.getValue().toString().equals("")) ? 1
                                : Integer.parseInt(minNumberField.getValue().toString());
                int maxNumber = (maxNumberField.getValue() == null
                        || maxNumberField.getValue().toString().equals("")) ? 1000
                                : Integer.parseInt(maxNumberField.getValue().toString());
                data = String.valueOf(df.getNumberBetween(minNumber, maxNumber));
            } else if (dataType.equalsIgnoreCase("alphanumeric")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField startingTextField = (TextField) hLayout.getComponent(0);
                TextField lengthField = (TextField) hLayout.getComponent(1);
                String startingText = (startingTextField.getValue() == null
                        || startingTextField.getValue().toString().equals("")) ? ""
                                : startingTextField.getValue().toString();
                int length = (lengthField.getValue() == null || lengthField.getValue().toString().equals(""))
                        ? 6
                        : Integer.parseInt(lengthField.getValue().toString());
                data = df.getAlphaNumericText(startingText, length);
            } else if (dataType.equalsIgnoreCase("maratial status")) {
                data = df.getStatus();
            } else if (dataType.equalsIgnoreCase("department name")) {
                data = df.getBusinessType();
            } else if (dataType.equalsIgnoreCase("company name")) {
                data = df.getCompanyName();
            } else if (dataType.equalsIgnoreCase("fixed text")) {
                HorizontalLayout hLayout = (HorizontalLayout) (item.getItemProperty("Additional Data")
                        .getValue());
                TextField textField = (TextField) hLayout.getComponent(0);
                String fixedText = (textField.getValue() == null || textField.getValue().toString().equals(""))
                        ? ""
                        : textField.getValue().toString();
                data = fixedText;
            } else if (dataType.equalsIgnoreCase("boolean flag")) {
                data = df.getBooleanFlag();
            } else if (dataType.equalsIgnoreCase("passport number")) {
                data = df.getPassportNumber();
            }

            sbColumnNames.append("\t\t<" + generatorBean.getColumnName() + ">");
            sbColumnNames.append(data);
            sbColumnNames.append("</" + generatorBean.getColumnName() + ">\n");
        }
        sbColumnNames.append("\t</" + recordNodeName + ">");
        addXmlData(sbColumnNames.toString());
    }
    sbXml.append("</" + rootNodeName + ">");
    log.debug("XmlDataGenerator - generate() method end");
    return getXmlData();
}

From source file:com.etest.serviceprovider.TQCoverageServiceImpl.java

@Override
public void calculateMaxItems(Grid grid, TextField totalItems) {
    Collection c = grid.getContainerDataSource().getItemIds();
    Iterator iterator = c.iterator();
    while (iterator.hasNext()) {
        Item item = grid.getContainerDataSource().getItem(iterator.next());

        if (item.getItemProperty("Proportion(%)").getValue() != null) {
            item.getItemProperty("Max Items")
                    .setValue(CommonUtilities.roundOffToWholeNumber((CommonUtilities.convertStringToDouble(
                            item.getItemProperty("Proportion(%)").getValue().toString()) / 100)
                            * CommonUtilities.convertStringToDouble(totalItems.getValue().trim())));
        }/*from w  ww  .ja v  a 2 s.c  om*/
    }
}

From source file:com.etest.view.tq.TQCoverageUI.java

Window getPickWindow(Item item, String propertyId) {
    Window sub = new Window("Field Value: ");
    sub.setWidth("150px");
    sub.setModal(true);// w  w w.  j a va  2s.c  om
    sub.center();
    sub.setResizable(false);

    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);
    v.setSpacing(true);

    TextField field = new CommonTextField("Enter Value..", "Enter a Value: ");
    v.addComponent(field);

    Button button = new Button("CLOSE");
    button.setWidth("100%");
    button.setIcon(FontAwesome.TASKS);
    button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener((Button.ClickEvent event) -> {
        boolean isNumeric = CommonUtilities.isNumeric(field.getValue().trim());
        if (!isNumeric) {
            return;
        }

        boolean isGreaterThanInTB = tq.isGreaterThanInTB(item, propertyId, field.getValue().trim());
        if (isGreaterThanInTB) {
            Notification.show("Not allowed to exceed in total Items in Test Bank!",
                    Notification.Type.ERROR_MESSAGE);
            return;
        } else {
            item.getItemProperty(CommonUtilities.replaceStringTBToPick(propertyId))
                    .setValue(CommonUtilities.convertStringToInt(field.getValue()));
            footer.getCell(CommonUtilities.replaceStringTBToPick(propertyId)).setText(String.valueOf(
                    tq.calculateTotalPickItems(grid, CommonUtilities.replaceStringTBToPick(propertyId))));
        }
        sub.close();
    });
    v.addComponent(button);
    v.setComponentAlignment(button, Alignment.BOTTOM_CENTER);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.etest.view.tq.TQCoverageUI.java

Window getMaxItemsWindow(Item item, double previousValue) {
    Window sub = new Window("Field Value: ");
    sub.setWidth("150px");
    sub.setModal(true);/*from   w ww  . j a v  a 2 s .c o m*/
    sub.center();
    sub.setResizable(false);

    VerticalLayout v = new VerticalLayout();
    v.setWidth("100%");
    v.setMargin(true);
    v.setSpacing(true);

    TextField field = new CommonTextField("Enter Value..", "Enter a Value: ");
    v.addComponent(field);

    Button button = new Button("CLOSE");
    button.setWidth("100%");
    button.setIcon(FontAwesome.TASKS);
    button.addStyleName(ValoTheme.BUTTON_PRIMARY);
    button.addStyleName(ValoTheme.BUTTON_SMALL);
    button.addClickListener((Button.ClickEvent event) -> {
        boolean isNumeric = CommonUtilities.isNumeric(field.getValue().trim());
        if (!isNumeric) {
            return;
        }

        item.getItemProperty("Max Items").setValue(CommonUtilities.convertStringToDouble(field.getValue()));
        if (tq.calculateTotalMaxItems(grid) == CommonUtilities
                .convertStringToDouble(totalItems.getValue().trim())) {
            footer.getCell("Max Items").setText(String.valueOf(tq.calculateTotalMaxItems(grid)));
        } else {
            item.getItemProperty("Max Items").setValue(previousValue);
            footer.getCell("Max Items").setText(String.valueOf(tq.calculateTotalMaxItems(grid)));
            ShowErrorNotification.warning("Total Max Items should be equal to Total Test Items");
            return;
        }

        sub.close();
    });
    v.addComponent(button);
    v.setComponentAlignment(button, Alignment.BOTTOM_CENTER);

    sub.setContent(v);
    sub.getContent().setHeightUndefined();

    return sub;
}

From source file:com.github.peholmst.springsecuritydemo.ui.LoginView.java

License:Apache License

@SuppressWarnings("serial")
protected void init() {
    final Panel loginPanel = new Panel();
    loginPanel.setCaption(getApplication().getMessage("login.title"));
    ((VerticalLayout) loginPanel.getContent()).setSpacing(true);

    final TextField username = new TextField(getApplication().getMessage("login.username"));
    username.setWidth("100%");
    loginPanel.addComponent(username);//from w  ww .jav a2s.co m

    final TextField password = new TextField(getApplication().getMessage("login.password"));
    password.setSecret(true);
    password.setWidth("100%");
    loginPanel.addComponent(password);

    final Button loginButton = new Button(getApplication().getMessage("login.button"));
    loginButton.setStyleName("primary");
    // TODO Make it possible to submit the form by pressing <Enter> in any
    // of the text fields
    loginPanel.addComponent(loginButton);
    ((VerticalLayout) loginPanel.getContent()).setComponentAlignment(loginButton, Alignment.MIDDLE_RIGHT);
    loginButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            final Authentication auth = new UsernamePasswordAuthenticationToken(username.getValue(),
                    password.getValue());
            try {
                if (logger.isDebugEnabled()) {
                    logger.debug("Attempting authentication for user '" + auth.getName() + "'");
                }
                Authentication returned = getAuthenticationManager().authenticate(auth);
                if (logger.isDebugEnabled()) {
                    logger.debug("Authentication for user '" + auth.getName() + "' succeeded");
                }
                fireEvent(new LoginEvent(LoginView.this, returned));
            } catch (BadCredentialsException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Bad credentials for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.badCredentials.title"),
                        getApplication().getMessage("login.badCredentials.descr"),
                        Notification.TYPE_WARNING_MESSAGE);
            } catch (DisabledException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Account disabled for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.disabled.title"),
                        getApplication().getMessage("login.disabled.descr"), Notification.TYPE_WARNING_MESSAGE);
            } catch (LockedException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Account locked for user '" + auth.getName() + "'", e);
                }
                getWindow().showNotification(getApplication().getMessage("login.locked.title"),
                        getApplication().getMessage("login.locked.descr"), Notification.TYPE_WARNING_MESSAGE);
            } catch (Exception e) {
                if (logger.isErrorEnabled()) {
                    logger.error("Error while attempting authentication for user '" + auth.getName() + "'");
                }
                ExceptionUtils.handleException(getWindow(), e);
            }
        }
    });

    HorizontalLayout languages = new HorizontalLayout();
    languages.setSpacing(true);
    final Button.ClickListener languageListener = new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            Locale locale = (Locale) event.getButton().getData();
            if (logger.isDebugEnabled()) {
                logger.debug("Changing locale to [" + locale + "] and restarting the application");
            }
            getApplication().setLocale(locale);
            getApplication().close();
        }
    };
    for (Locale locale : getApplication().getSupportedLocales()) {
        if (!getLocale().equals(locale)) {
            final Button languageButton = new Button(getApplication().getLocaleDisplayName(locale));
            languageButton.setStyleName(Button.STYLE_LINK);
            languageButton.setData(locale);
            languageButton.addListener(languageListener);
            languages.addComponent(languageButton);
        }
    }
    loginPanel.addComponent(languages);

    loginPanel.setWidth("300px");

    final HorizontalLayout viewLayout = new HorizontalLayout();
    viewLayout.addComponent(loginPanel);
    viewLayout.setComponentAlignment(loginPanel, Alignment.MIDDLE_CENTER);
    viewLayout.setSizeFull();
    viewLayout.setMargin(true);

    setCompositionRoot(viewLayout);
    setSizeFull();
}

From source file:com.github.wolfie.sessionguard.SessionguardApplication.java

License:Apache License

@Override
public void init() {
    final VerticalLayout mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);/* w w w . j  av a  2s.c  o  m*/
    final Window mainWindow = new Window("Sessionguard Application", mainLayout);

    final int sessionTimeout = ((WebApplicationContext) getContext()).getHttpSession().getMaxInactiveInterval()
            / 60;

    final Label label = new Label(
            "This application has a " + sessionTimeout + "-minute session, with a timeout warning of "
                    + WARNING_PERIOD_MINS + " minutes session time left.");
    mainWindow.addComponent(label);
    setMainWindow(mainWindow);
    final SessionGuard sessionGuard = new SessionGuard();
    sessionGuard.setTimeoutWarningPeriod(WARNING_PERIOD_MINS);
    mainWindow.addComponent(sessionGuard);

    mainWindow.addComponent(new Button("Switch to keepalive", new Button.ClickListener() {
        private static final long serialVersionUID = -4423285632350279761L;
        private boolean keepalive = false;

        public void buttonClick(final ClickEvent event) {
            keepalive = !keepalive;
            sessionGuard.setKeepalive(keepalive);
            event.getButton().setCaption(keepalive ? "Switch to timeout message" : "Switch to keepalive");
        }
    }));

    final TextField warningXhtmlField = new TextField("Change warning XHTML");
    warningXhtmlField.setWidth("100%");
    warningXhtmlField.setValue(sessionGuard.getTimeoutWarningXHTML());
    warningXhtmlField.setImmediate(true);
    warningXhtmlField.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -5236596836421389890L;

        public void valueChange(final ValueChangeEvent event) {
            sessionGuard.setTimeoutWarningXHTML((String) warningXhtmlField.getValue());
            getMainWindow().showNotification("Warning string changed");
        }
    });
    mainWindow.addComponent(warningXhtmlField);

}

From source file:com.liferay.mail.vaadin.FolderTree.java

License:Open Source License

public void handleAccountAction(AccountAction action) {
    final Long accountId = action.getAccountId();
    if (accountId == null) {
        return;/* ww w.  ja  v  a  2 s  .c  o m*/
    }

    if (Lang.get("create-folder").equals(action.getCaption())) {
        String title = Lang.get("create-folder");
        String message = Lang.get("please-enter-a-folder-name");
        final ConfirmDialog confirm = new ConfirmDialog(Lang.get("confirm"), title, message);
        final TextField newNameField = new TextField();
        newNameField.setNullRepresentation("");
        newNameField.setValue("new folder");
        confirm.addExtraComponent(newNameField);

        confirm.addConfirmButtonListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                String newName = (String) newNameField.getValue();
                if (newName != null && !"".equals(newName)) {
                    confirm.closeDialog();

                    addFolder(accountId, newName);

                    synchronizeAccount(accountId, Controller.get());
                    refresh();
                } else {
                    Controller.get().showError(Lang.get("please-enter-a-folder-name"));
                }
            }
        });

        Controller.get().getApplication().getMainWindow().addWindow(confirm);
    }
}

From source file:com.liferay.mail.vaadin.FolderTree.java

License:Open Source License

public void handleFolderAction(FolderAction action) {
    final Folder folder = action.getFolder();
    if (folder == null) {
        return;/*  www  .  j av a  2  s  .  c  om*/
    }

    if (Lang.get("rename-folder").equals(action.getCaption())) {
        String title = Lang.get("rename-folder");
        String message = Lang.get("please-enter-a-new-folder-name");
        final ConfirmDialog confirm = new ConfirmDialog(Lang.get("confirm"), title, message);
        final TextField newNameField = new TextField();
        newNameField.setNullRepresentation("");
        newNameField.setValue(folder.getDisplayName());
        confirm.addExtraComponent(newNameField);

        confirm.addConfirmButtonListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                String newName = (String) newNameField.getValue();
                if (newName != null && !"".equals(newName)) {
                    confirm.closeDialog();

                    renameFolder(folder.getFolderId(), newName);

                    synchronizeAccount(folder.getAccountId(), Controller.get());
                    refresh();
                } else {
                    Controller.get().showError(Lang.get("please-enter-a-new-folder-name"));
                }
            }
        });

        Controller.get().getApplication().getMainWindow().addWindow(confirm);
    } else if (Lang.get("delete-folder").equals(action.getCaption())) {
        final ConfirmDialog confirm = new ConfirmDialog(Lang.get("confirm"), Lang.get("delete-folder"),
                Lang.get("are-you-sure-you-want-to-delete-this-folder"));

        confirm.addConfirmButtonListener(new ClickListener() {

            public void buttonClick(ClickEvent event) {
                confirm.closeDialog();

                deleteFolder(folder.getFolderId());

                synchronizeAccount(folder.getAccountId(), Controller.get());
                refresh();
            }
        });

        Controller.get().getApplication().getMainWindow().addWindow(confirm);
    }
}