Example usage for com.vaadin.ui HorizontalLayout getComponent

List of usage examples for com.vaadin.ui HorizontalLayout getComponent

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout getComponent.

Prototype

public Component getComponent(int index) throws IndexOutOfBoundsException 

Source Link

Document

Returns the component at the given position.

Usage

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

License:Open Source License

/**
 * Actual data generation logic for CSV present here
 *//*from   w  ww .j a  v  a2  s  . com*/
@Override
public String generate(DataGenApplication dataGenApplication, ArrayList<GeneratorBean> rowList) {
    log.debug("CsvDataGenerator - generate() method start");
    sbCSV.setLength(0);
    int maxRows = Integer.parseInt(dataGenApplication.resultNum.getValue().toString());
    if (!dataGenApplication.csvDelimiter.getValue().toString().equals("")) {
        dataDelimeter = dataGenApplication.csvDelimiter.getValue().toString();
    }

    DataFactory df = new DataFactory();
    for (int row = 0; row < maxRows; row++) {
        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 = 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();
            }

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

        }
        addResultData(sb.toString());
    }
    log.debug("CsvDataGenerator - generate() method end");
    return getResultData();
}

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

License:Open Source License

/**
  * Actual data generation logic for EXCEL present here
  *///from  w  ww.  java  2 s .com
@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  .  jav a2  s . com
@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
 *///from  w ww. ja v  a 2 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.haulmont.cuba.web.WebWindowManager.java

License:Apache License

@Override
public void showOptionDialog(String title, String message, MessageType messageType, Action[] actions) {
    backgroundWorker.checkUIAccess();//  w ww.  j  av a2  s. com

    final com.vaadin.ui.Window window = new CubaWindow(title);

    if (ui.isTestMode()) {
        window.setCubaId("optionDialog");
        window.setId(ui.getTestIdManager().getTestId("optionDialog"));
    }
    window.setClosable(false);

    Label messageLab = new CubaLabel();
    messageLab.setValue(message);
    if (MessageType.isHTML(messageType)) {
        messageLab.setContentMode(ContentMode.HTML);
    } else {
        messageLab.setContentMode(ContentMode.TEXT);
    }
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        messageLab.setWidthUndefined();
    }

    float width;
    SizeUnit unit;
    if (messageType.getWidth() != null) {
        width = messageType.getWidth();
        unit = messageType.getWidthUnit();
    } else if (getDialogParams().getWidth() != null) {
        width = getDialogParams().getWidth();
        unit = getDialogParams().getWidthUnit();
    } else {
        SizeWithUnit size = SizeWithUnit
                .parseStringSize(app.getThemeConstants().get("cuba.web.WebWindowManager.optionDialog.width"));
        width = size.getSize();
        unit = size.getUnit();
    }

    if (messageType.getModal() != null) {
        log.warn("MessageType.modal is not supported for showOptionDialog");
    }

    getDialogParams().reset();

    window.setWidth(width, unit != null ? WebWrapperUtils.toVaadinUnit(unit) : Unit.PIXELS);
    window.setResizable(false);
    window.setModal(true);

    boolean closeOnClickOutside = false;
    if (window.isModal()) {
        if (messageType.getCloseOnClickOutside() != null) {
            closeOnClickOutside = messageType.getCloseOnClickOutside();
        }
    }
    ((CubaWindow) window).setCloseOnClickOutside(closeOnClickOutside);

    if (messageType.getMaximized() != null) {
        if (messageType.getMaximized()) {
            window.setWindowMode(WindowMode.MAXIMIZED);
        } else {
            window.setWindowMode(WindowMode.NORMAL);
        }
    }

    VerticalLayout layout = new VerticalLayout();
    layout.setStyleName("c-app-option-dialog");
    layout.setSpacing(true);
    if (messageType.getWidth() != null && messageType.getWidth() == AUTO_SIZE_PX) {
        layout.setWidthUndefined();
    }
    window.setContent(layout);

    HorizontalLayout buttonsContainer = new HorizontalLayout();
    buttonsContainer.setSpacing(true);

    boolean hasPrimaryAction = false;
    Map<Action, Button> buttonMap = new HashMap<>();
    for (Action action : actions) {
        Button button = WebComponentsHelper.createButton();
        button.setCaption(action.getCaption());
        button.addClickListener(event -> {
            try {
                action.actionPerform(null);
            } finally {
                ui.removeWindow(window);
            }
        });

        if (StringUtils.isNotEmpty(action.getIcon())) {
            button.setIcon(WebComponentsHelper.getIcon(action.getIcon()));
            button.addStyleName(WebButton.ICON_STYLE);
        }

        if (action instanceof AbstractAction && ((AbstractAction) action).isPrimary()) {
            button.addStyleName("c-primary-action");
            button.focus();

            hasPrimaryAction = true;
        }

        if (ui.isTestMode()) {
            button.setCubaId("optionDialog_" + action.getId());
            button.setId(ui.getTestIdManager().getTestId("optionDialog_" + action.getId()));
        }

        buttonsContainer.addComponent(button);
        buttonMap.put(action, button);
    }

    assignDialogShortcuts(buttonMap);

    if (!hasPrimaryAction && actions.length > 0) {
        ((Button) buttonsContainer.getComponent(0)).focus();
    }

    layout.addComponent(messageLab);
    layout.addComponent(buttonsContainer);

    layout.setExpandRatio(messageLab, 1);
    layout.setComponentAlignment(buttonsContainer, Alignment.BOTTOM_RIGHT);

    ui.addWindow(window);
    window.center();
}

From source file:com.studiodojo.qwikinvoice.QwikInvoiceApplication.java

License:Apache License

/**
 * @param aClass/*from  w w w  .  ja va 2 s  .  co m*/
 */
public void showPanel(Class aClass) {
    Panel mainPanel = (Panel) this.mainWindow.getContent();
    HorizontalLayout appLayout = (HorizontalLayout) mainPanel.getContent();
    VerticalLayout mainLayout = (VerticalLayout) appLayout.getComponent(0); // the ApplicationLayout has one component which is the VerticalLayout 'mainLayout'
    IApplicationPanel panel = this.map.get(aClass);
    if (panel != null || !(aClass.equals(this.activePanel.getClass()))) {
        try {
            Log.info("Loading panel");
            /*
             * mainLayout.getComponent(0) = Title
             * mainLayout.getComponent(1) = Menubar
             * mainLayout.getComponent(2) = IApplicationPanel
             */
            ((IApplicationPanel) mainLayout.getComponent(2)).validate(); //make sure it's safe to navigate off the panel (opportunity to save data)
            panel.init(this.theSession, this);
            mainLayout.replaceComponent(mainLayout.getComponent(2), (Component) panel);
            this.activePanel = panel;
        } catch (Exception e) {
            this.mainWindow.getWindow().showNotification(e.getMessage(), e.getMessage(),
                    Notification.TYPE_ERROR_MESSAGE);
        }
    } else
        Log.warning("Panel does not exist");
}

From source file:com.studiodojo.qwikinvoice.QwikInvoiceApplication.java

License:Apache License

/**
 * Return <code>true</code> is the specified component is the IApplicationPanel instance that is visible
 * @param aClass// www  .  j a v a  2  s .  c  o m
 * @return
 */
private boolean isPanelVisable(Class aClass) {
    HorizontalLayout appLayout = (HorizontalLayout) this.mainWindow.getContent();
    VerticalLayout mainLayout = (VerticalLayout) appLayout.getComponent(0); // the ApplicationLayout has one component which is the VerticalLayout 'mainLayout'
    if (mainLayout.getComponent(2).equals((Component) this.map.get(aClass)))
        return true;
    else
        return false;
}

From source file:de.symeda.sormas.ui.caze.CaseContactsView.java

License:Open Source License

public HorizontalLayout createStatusFilterBar() {
    HorizontalLayout statusFilterLayout = new HorizontalLayout();
    statusFilterLayout.setSpacing(true);
    statusFilterLayout.setWidth("100%");
    statusFilterLayout.addStyleName(CssStyles.VSPACE_3);

    statusButtons = new HashMap<>();

    Button statusAll = new Button(I18nProperties.getCaption(Captions.all), e -> {
        criteria.contactStatus(null);/*from  w w w . jav  a  2 s  .  co  m*/
        navigateTo(criteria);
    });
    CssStyles.style(statusAll, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER);
    statusAll.setCaptionAsHtml(true);
    statusFilterLayout.addComponent(statusAll);
    statusButtons.put(statusAll, I18nProperties.getCaption(Captions.all));
    activeStatusButton = statusAll;

    for (ContactStatus status : ContactStatus.values()) {
        Button statusButton = new Button(status.toString(), e -> {
            criteria.contactStatus(status);
            navigateTo(criteria);
        });
        statusButton.setData(status);
        CssStyles.style(statusButton, ValoTheme.BUTTON_BORDERLESS, CssStyles.BUTTON_FILTER,
                CssStyles.BUTTON_FILTER_LIGHT);
        statusButton.setCaptionAsHtml(true);
        statusFilterLayout.addComponent(statusButton);
        statusButtons.put(statusButton, status.toString());
    }
    statusFilterLayout
            .setExpandRatio(statusFilterLayout.getComponent(statusFilterLayout.getComponentCount() - 1), 1);

    // Bulk operation dropdown
    if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
        statusFilterLayout.setWidth(100, Unit.PERCENTAGE);

        MenuBar bulkOperationsDropdown = new MenuBar();
        MenuItem bulkOperationsItem = bulkOperationsDropdown
                .addItem(I18nProperties.getCaption(Captions.bulkActions), null);

        Command changeCommand = selectedItem -> {
            ControllerProvider.getContactController().showBulkContactDataEditComponent(
                    grid.asMultiSelect().getSelectedItems(), getCaseRef().getUuid());
        };
        bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkEdit), VaadinIcons.ELLIPSIS_H,
                changeCommand);

        Command cancelFollowUpCommand = selectedItem -> {
            ControllerProvider.getContactController()
                    .cancelFollowUpOfAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                        public void run() {
                            grid.deselectAll();
                            grid.reload();
                        }
                    });
        };
        bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkCancelFollowUp), VaadinIcons.CLOSE,
                cancelFollowUpCommand);

        Command lostToFollowUpCommand = selectedItem -> {
            ControllerProvider.getContactController().setAllSelectedItemsToLostToFollowUp(
                    grid.asMultiSelect().getSelectedItems(), new Runnable() {
                        public void run() {
                            grid.deselectAll();
                            grid.reload();
                        }
                    });
        };
        bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkLostToFollowUp), VaadinIcons.UNLINK,
                lostToFollowUpCommand);

        Command deleteCommand = selectedItem -> {
            ControllerProvider.getContactController()
                    .deleteAllSelectedItems(grid.asMultiSelect().getSelectedItems(), new Runnable() {
                        public void run() {
                            grid.deselectAll();
                            grid.reload();
                        }
                    });
        };
        bulkOperationsItem.addItem(I18nProperties.getCaption(Captions.bulkDelete), VaadinIcons.TRASH,
                deleteCommand);

        statusFilterLayout.addComponent(bulkOperationsDropdown);
        statusFilterLayout.setComponentAlignment(bulkOperationsDropdown, Alignment.TOP_RIGHT);
        statusFilterLayout.setExpandRatio(bulkOperationsDropdown, 1);
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_EXPORT)) {
        Button exportButton = new Button(I18nProperties.getCaption(Captions.export));
        exportButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        exportButton.setIcon(VaadinIcons.DOWNLOAD);

        StreamResource streamResource = new GridExportStreamResource(grid, "sormas_contacts",
                "sormas_contacts_" + DateHelper.formatDateForExport(new Date()) + ".csv");
        FileDownloader fileDownloader = new FileDownloader(streamResource);
        fileDownloader.extend(exportButton);

        statusFilterLayout.addComponent(exportButton);
        statusFilterLayout.setComponentAlignment(exportButton, Alignment.MIDDLE_RIGHT);
        if (!UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
            statusFilterLayout.setExpandRatio(exportButton, 1);
        }
    }

    if (UserProvider.getCurrent().hasUserRight(UserRight.CONTACT_CREATE)) {
        newButton = new Button(
                I18nProperties.getPrefixCaption(ContactDto.I18N_PREFIX, Captions.contactNewContact));
        newButton.addStyleName(ValoTheme.BUTTON_PRIMARY);
        newButton.setIcon(VaadinIcons.PLUS_CIRCLE);
        newButton.addClickListener(e -> ControllerProvider.getContactController().create(this.getCaseRef()));
        statusFilterLayout.addComponent(newButton);
        statusFilterLayout.setComponentAlignment(newButton, Alignment.MIDDLE_RIGHT);
    }

    statusFilterLayout.addStyleName("top-bar");
    activeStatusButton = statusAll;
    return statusFilterLayout;
}

From source file:edu.nps.moves.mmowgli.modules.userprofile.UserProfileMyIdeasPanel2.java

License:Open Source License

private void setCheck(HorizontalLayout row, boolean show) {
    Component c = row.getComponent(1); // second
    Component check = row.getComponent(0);
    if (!show) { // want to hide
        if (c instanceof Label)
            return; // I'm already hiding
        check.setVisible(false);//from   w w w  .  j a va2  s  .  c  o m
        Label sp;
        row.addComponent(sp = new Label(), 1);
        sp.setWidth("12px");
    } else { // want to show
        if (!(c instanceof Label))
            return; //I'm already showing
        check.setVisible(true);
        row.removeComponent(c);
    }
}

From source file:fi.vtt.RVaadin.RContainer.java

License:Apache License

/**
 * A function to get the values from a parameter layout generated by
 * {@link RContainer#getParameterLayout}. This function ban be useful when
 * e.g. the range of the parameters is only a subset of R^n (say, we must
 * always have p[0] <= p[1]). The parameters can be forced to match the
 * domain with {@link RContainer#setParameterLayoutValues}.
 * //from  w w  w . j  av a  2  s  . co m
 * @param hl
 *            HorizontalLayout obtained from
 *            {@link RContainer#getParameterLayout}
 * @return the parameter values in the layout as double[]
 */
public double[] getParameterLayoutValues(HorizontalLayout hl) {

    int n = countParametersInLayout(hl);

    /*
     * The parameter layout listener takes care that no illegal value can be
     * added to the list. Hence, it is safe to loop over the values and cast
     * them to doubles.
     */
    double p[] = new double[n];

    for (int i = 0; i < n; i++) {
        p[i] = Double.valueOf(((TextField) hl.getComponent(i)).getValue().toString());
    }

    return p;
}