List of usage examples for com.vaadin.ui TextField getValue
@Override
public String getValue()
From source file:com.esofthead.mycollab.module.project.view.milestone.ToggleMilestoneSummaryField.java
License:Open Source License
private void updateFieldValue(TextField editField) { removeComponent(editField);/*w w w . j a va2 s . c o m*/ addComponent(titleLinkLbl); addComponent(buttonControls); addStyleName("editable-field"); String newValue = editField.getValue(); if (StringUtils.isNotBlank(newValue) && !newValue.equals(milestone.getName())) { milestone.setName(newValue); titleLinkLbl.setValue(buildMilestoneLink()); MilestoneService milestoneService = AppContextUtil.getSpringBean(MilestoneService.class); milestoneService.updateSelectiveWithSession(BeanUtility.deepClone(milestone), AppContext.getUsername()); } isRead = !isRead; }
From source file:com.esofthead.mycollab.module.project.view.ProjectAddBaseTemplateWindow.java
License:Open Source License
public ProjectAddBaseTemplateWindow() { super(AppContext.getMessage(ProjectI18nEnum.OPT_CREATE_PROJECT_FROM_TEMPLATE)); this.setModal(true); this.setClosable(true); this.setResizable(false); this.setWidth("550px"); MVerticalLayout content = new MVerticalLayout(); GridFormLayoutHelper gridFormLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(1, 3); final TemplateProjectComboBox templateProjectComboBox = new TemplateProjectComboBox(); Button helpBtn = new Button(""); helpBtn.setIcon(FontAwesome.QUESTION_CIRCLE); helpBtn.addStyleName(UIConstants.BUTTON_ACTION); helpBtn.setDescription(AppContext.getMessage(ProjectI18nEnum.OPT_MARK_TEMPLATE_HELP)); gridFormLayoutHelper/*from www. ja v a2 s .c o m*/ .addComponent( new MHorizontalLayout().withFullWidth().with(templateProjectComboBox, helpBtn) .expand(templateProjectComboBox), AppContext.getMessage(ProjectI18nEnum.FORM_TEMPLATE), 0, 0); final TextField prjNameField = new TextField(); gridFormLayoutHelper.addComponent(prjNameField, AppContext.getMessage(GenericI18Enum.FORM_NAME), 0, 1); final TextField prjKeyField = new TextField(); gridFormLayoutHelper.addComponent(prjKeyField, AppContext.getMessage(ProjectI18nEnum.FORM_SHORT_NAME), 0, 2); MHorizontalLayout buttonControls = new MHorizontalLayout(); content.with(gridFormLayoutHelper.getLayout(), buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT); Button okBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_OK), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { SimpleProject templatePrj = (SimpleProject) templateProjectComboBox.getValue(); if (templatePrj == null) { NotificationUtil.showErrorNotification( AppContext.getMessage(ProjectI18nEnum.ERROR_MUST_CHOOSE_TEMPLATE_PROJECT)); return; } String newPrjName = prjNameField.getValue(); if (newPrjName.length() == 0) { NotificationUtil.showErrorNotification("Project name must be not null"); return; } String newPrjKey = prjKeyField.getValue(); if (newPrjKey.length() > 3 || newPrjKey.length() == 0) { NotificationUtil .showErrorNotification("Project key must be not null and less than 3 characters"); return; } ProjectTemplateService projectTemplateService = AppContextUtil .getSpringBean(ProjectTemplateService.class); if (projectTemplateService != null) { Integer newProjectId = projectTemplateService.cloneProject(templatePrj.getId(), newPrjName, newPrjKey, AppContext.getAccountId(), AppContext.getUsername()); EventBusFactory.getInstance().post(new ProjectEvent.GotoMyProject(this, new PageActionChain(new ProjectScreenData.Goto(newProjectId)))); close(); } } }); okBtn.setIcon(FontAwesome.SAVE); okBtn.addStyleName(UIConstants.BUTTON_ACTION); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { close(); } }); cancelBtn.addStyleName(UIConstants.BUTTON_OPTION); buttonControls.with(cancelBtn, okBtn); this.setContent(content); }
From source file:com.esofthead.mycollab.module.project.view.task.components.ToggleTaskSummaryField.java
License:Open Source License
private void updateFieldValue(TextField editField) { removeComponent(editField);/* w w w. j a v a 2s .c o m*/ addComponent(titleLinkLbl); addComponent(buttonControls); addStyleName("editable-field"); String newValue = editField.getValue(); if (StringUtils.isNotBlank(newValue) && !newValue.equals(task.getTaskname())) { task.setTaskname(newValue); titleLinkLbl.setValue(buildTaskLink()); ProjectTaskService taskService = AppContextUtil.getSpringBean(ProjectTaskService.class); taskService.updateSelectiveWithSession(BeanUtility.deepClone(task), AppContext.getUsername()); } isRead = !isRead; }
From source file:com.esofthead.mycollab.shell.view.SetupNewInstanceView.java
License:Open Source License
public SetupNewInstanceView() { this.setDefaultComponentAlignment(Alignment.TOP_CENTER); MVerticalLayout content = new MVerticalLayout().withWidth("600px"); this.with(content); content.with(ELabel.h2("Last step, you are almost there!").withWidthUndefined()); content.with(ELabel.h3("All fields are required *").withStyleName("overdue").withWidthUndefined()); content.with(// ww w .ja v a2 s . c o m new ELabel(AppContext.getMessage(ShellI18nEnum.OPT_SUPPORTED_LANGUAGES_INTRO), ContentMode.HTML) .withStyleName(UIConstants.META_COLOR)); GridFormLayoutHelper formLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(2, 8, "200px"); formLayoutHelper.getLayout().setWidth("600px"); final TextField adminField = formLayoutHelper.addComponent(new TextField(), "Admin email", 0, 0); final PasswordField passwordField = formLayoutHelper.addComponent(new PasswordField(), "Admin password", 0, 1); final PasswordField retypePasswordField = formLayoutHelper.addComponent(new PasswordField(), "Retype Admin password", 0, 2); final DateFormatField dateFormatField = formLayoutHelper.addComponent( new DateFormatField(SimpleBillingAccount.DEFAULT_DATE_FORMAT), AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_YYMMDD_FORMAT), AppContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 3); final DateFormatField shortDateFormatField = formLayoutHelper.addComponent( new DateFormatField(SimpleBillingAccount.DEFAULT_SHORT_DATE_FORMAT), AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_MMDD_FORMAT), AppContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 4); final DateFormatField longDateFormatField = formLayoutHelper.addComponent( new DateFormatField(SimpleBillingAccount.DEFAULT_LONG_DATE_FORMAT), AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_HUMAN_DATE_FORMAT), AppContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 5); final TimeZoneSelectionField timeZoneSelectionField = formLayoutHelper.addComponent( new TimeZoneSelectionField(false), AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_TIMEZONE), 0, 6); timeZoneSelectionField.setValue(TimeZone.getDefault().getID()); final LanguageSelectionField languageBox = formLayoutHelper.addComponent(new LanguageSelectionField(), AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_LANGUAGE), 0, 7); languageBox.setValue(Locale.US.toLanguageTag()); content.with(formLayoutHelper.getLayout()); Button installBtn = new Button("Setup", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent clickEvent) { String adminName = adminField.getValue(); String password = passwordField.getValue(); String retypePassword = retypePasswordField.getValue(); if (!StringUtils.isValidEmail(adminName)) { NotificationUtil.showErrorNotification("Invalid email value"); return; } if (!password.equals(retypePassword)) { NotificationUtil.showErrorNotification("Password is not match"); return; } String dateFormat = dateFormatField.getValue(); String shortDateFormat = shortDateFormatField.getValue(); String longDateFormat = longDateFormatField.getValue(); if (!isValidDayPattern(dateFormat) || !isValidDayPattern(shortDateFormat) || !isValidDayPattern(longDateFormat)) { NotificationUtil.showErrorNotification("Invalid date format"); return; } String language = languageBox.getValue(); String timezoneDbId = timeZoneSelectionField.getValue(); BillingAccountMapper billingAccountMapper = AppContextUtil .getSpringBean(BillingAccountMapper.class); BillingAccountExample ex = new BillingAccountExample(); ex.createCriteria().andIdEqualTo(AppContext.getAccountId()); List<BillingAccount> billingAccounts = billingAccountMapper.selectByExample(ex); BillingAccount billingAccount = billingAccounts.get(0); billingAccount.setDefaultlanguagetag(language); billingAccount.setDefaultyymmddformat(dateFormat); billingAccount.setDefaultmmddformat(shortDateFormat); billingAccount.setDefaulthumandateformat(longDateFormat); billingAccount.setDefaulttimezone(timezoneDbId); billingAccountMapper.updateByPrimaryKey(billingAccount); BillingAccountService billingAccountService = AppContextUtil .getSpringBean(BillingAccountService.class); billingAccountService.createDefaultAccountData(adminName, password, timezoneDbId, language, true, true, AppContext.getAccountId()); ((DesktopApplication) UI.getCurrent()).doLogin(adminName, password, false); } }); installBtn.addStyleName(UIConstants.BUTTON_ACTION); content.with(installBtn).withAlign(installBtn, Alignment.TOP_RIGHT); }
From source file:com.esofthead.mycollab.vaadin.ui.BuildCriterionComponent.java
License:Open Source License
private void buildSaveFilterBox() { filterBox.removeAllComponents();/*from w w w. j a v a2 s .c om*/ final TextField queryTextField = new TextField(); queryTextField.setWidth("125px"); filterBox.addComponent(queryTextField); Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { String queryText = queryTextField.getValue(); saveSearchCriteria(queryText); } }); saveBtn.setStyleName(UIConstants.THEME_GREEN_LINK); saveBtn.setIcon(FontAwesome.SAVE); filterBox.addComponent(saveBtn); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { buildFilterBox(null); } }); cancelBtn.addStyleName(UIConstants.THEME_GRAY_LINK); filterBox.addComponent(cancelBtn); }
From source file:com.esofthead.mycollab.vaadin.ui.MailFormWindow.java
License:Open Source License
private void initUI() { GridLayout mainLayout = new GridLayout(1, 5); mainLayout.setWidth("100%"); mainLayout.setMargin(true);//from w w w. jav a 2 s . c om mainLayout.setSpacing(true); CssLayout inputPanel = new CssLayout(); inputPanel.setWidth("100%"); inputPanel.setStyleName("mail-panel"); inputLayout = new GridLayout(3, 4); inputLayout.setSpacing(true); inputLayout.setWidth("100%"); inputLayout.setColumnExpandRatio(0, 1.0f); inputPanel.addComponent(inputLayout); mainLayout.addComponent(inputPanel); tokenFieldMailTo = new EmailTokenField(); tokenFieldMailTo.setRequired(true); inputLayout.addComponent(createTextFieldMail("To:", tokenFieldMailTo), 0, 0); if (lstMail != null) { for (String mail : lstMail) { if (StringUtils.isNotBlank(mail)) { if (mail.indexOf("<") > -1) { String strMail = mail.substring(mail.indexOf("<") + 1, mail.lastIndexOf(">")); if (strMail != null && !strMail.equalsIgnoreCase("null")) { tokenFieldMailTo.addToken(mail); } } else { tokenFieldMailTo.addToken(mail); } } } } final TextField subject = new TextField(); subject.setRequired(true); subject.setWidth("100%"); subjectField = createTextFieldMail("Subject:", subject); inputLayout.addComponent(subjectField, 0, 1); initButtonLinkCcBcc(); ccField = createTextFieldMail("Cc:", tokenFieldMailCc); bccField = createTextFieldMail("Bcc:", tokenFieldMailBcc); final RichTextArea noteArea = new RichTextArea(); noteArea.setWidth("100%"); noteArea.setHeight("200px"); mainLayout.addComponent(noteArea, 0, 1); mainLayout.setComponentAlignment(noteArea, Alignment.MIDDLE_CENTER); HorizontalLayout controlsLayout = new HorizontalLayout(); controlsLayout.setWidth("100%"); final AttachmentPanel attachments = new AttachmentPanel(); attachments.setWidth("500px"); MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments); uploadExt.addComponent(attachments); controlsLayout.addComponent(uploadExt); controlsLayout.setExpandRatio(uploadExt, 1.0f); controlsLayout.setSpacing(true); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { MailFormWindow.this.close(); } }); cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK); controlsLayout.addComponent(cancelBtn); controlsLayout.setComponentAlignment(cancelBtn, Alignment.MIDDLE_RIGHT); Button sendBtn = new Button("Send", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { if (tokenFieldMailTo.getListRecipient().size() <= 0 || subject.getValue().equals("")) { NotificationUtil.showErrorNotification( "To Email field and Subject field must be not empty! Please fulfil them before sending email."); return; } if (AppContext.getSession().getEmail() != null && AppContext.getSession().getEmail().length() > 0) { ExtMailService systemMailService = ApplicationContextUtil.getSpringBean(ExtMailService.class); List<File> listFile = attachments.getListFile(); List<EmailAttachementSource> emailAttachmentSource = null; if (listFile != null && listFile.size() > 0) { emailAttachmentSource = new ArrayList<EmailAttachementSource>(); for (File file : listFile) { emailAttachmentSource.add(new FileEmailAttachmentSource(file)); } } systemMailService.sendHTMLMail(AppContext.getSession().getEmail(), AppContext.getSession().getDisplayName(), tokenFieldMailTo.getListRecipient(), tokenFieldMailCc.getListRecipient(), tokenFieldMailBcc.getListRecipient(), subject.getValue().toString(), noteArea.getValue().toString(), emailAttachmentSource); MailFormWindow.this.close(); } else { NotificationUtil.showErrorNotification( "Your email is empty value, please fulfil it before sending email!"); } } }); sendBtn.setStyleName(UIConstants.THEME_GREEN_LINK); controlsLayout.addComponent(sendBtn); controlsLayout.setComponentAlignment(sendBtn, Alignment.MIDDLE_RIGHT); mainLayout.addComponent(controlsLayout, 0, 2); this.setContent(mainLayout); }
From source file:com.esofthead.mycollab.vaadin.web.ui.BuildCriterionComponent.java
License:Open Source License
private void buildSaveFilterBox() { filterBox.removeAllComponents();// w w w.j av a 2 s. c om final TextField queryTextField = new TextField(); filterBox.addComponent(queryTextField); Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { String queryText = queryTextField.getValue(); saveSearchCriteria(queryText); } }); saveBtn.setStyleName(UIConstants.BUTTON_ACTION); saveBtn.setIcon(FontAwesome.SAVE); filterBox.addComponent(saveBtn); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { buildFilterBox(null); } }); cancelBtn.addStyleName(UIConstants.BUTTON_OPTION); filterBox.addComponent(cancelBtn); }
From source file:com.esofthead.mycollab.vaadin.web.ui.MailFormWindow.java
License:Open Source License
private void initUI() { GridLayout mainLayout = new GridLayout(1, 5); mainLayout.setWidth("100%"); mainLayout.setMargin(true);// ww w. j a va 2 s.c o m mainLayout.setSpacing(true); CssLayout inputPanel = new CssLayout(); inputPanel.setWidth("100%"); inputPanel.setStyleName("mail-panel"); inputLayout = new GridLayout(3, 4); inputLayout.setSpacing(true); inputLayout.setWidth("100%"); inputLayout.setColumnExpandRatio(0, 1.0f); inputPanel.addComponent(inputLayout); mainLayout.addComponent(inputPanel); tokenFieldMailTo = new EmailTokenField(); inputLayout.addComponent(createTextFieldMail("To:", tokenFieldMailTo), 0, 0); if (lstMail != null) { for (String mail : lstMail) { if (StringUtils.isNotBlank(mail)) { if (mail.indexOf("<") > -1) { String strMail = mail.substring(mail.indexOf("<") + 1, mail.lastIndexOf(">")); if (strMail != null && !strMail.equalsIgnoreCase("null")) { } } else { } } } } final TextField subject = new TextField(); subject.setRequired(true); subject.setWidth("100%"); subjectField = createTextFieldMail("Subject:", subject); inputLayout.addComponent(subjectField, 0, 1); initButtonLinkCcBcc(); ccField = createTextFieldMail("Cc:", tokenFieldMailCc); bccField = createTextFieldMail("Bcc:", tokenFieldMailBcc); final RichTextArea noteArea = new RichTextArea(); noteArea.setWidth("100%"); noteArea.setHeight("200px"); mainLayout.addComponent(noteArea, 0, 1); mainLayout.setComponentAlignment(noteArea, Alignment.MIDDLE_CENTER); HorizontalLayout controlsLayout = new HorizontalLayout(); controlsLayout.setWidth("100%"); final AttachmentPanel attachments = new AttachmentPanel(); attachments.setWidth("500px"); MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments); uploadExt.addComponent(attachments); controlsLayout.addComponent(uploadExt); controlsLayout.setExpandRatio(uploadExt, 1.0f); controlsLayout.setSpacing(true); Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL), new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { MailFormWindow.this.close(); } }); cancelBtn.setStyleName(UIConstants.BUTTON_OPTION); controlsLayout.addComponent(cancelBtn); controlsLayout.setComponentAlignment(cancelBtn, Alignment.MIDDLE_RIGHT); Button sendBtn = new Button("Send", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { if (tokenFieldMailTo.getListRecipient().size() <= 0 || subject.getValue().equals("")) { NotificationUtil.showErrorNotification( "To Email field and Subject field must be not empty! Please fulfil them before sending email."); return; } if (AppContext.getUser().getEmail() != null && AppContext.getUser().getEmail().length() > 0) { ExtMailService systemMailService = AppContextUtil.getSpringBean(ExtMailService.class); List<File> listFile = attachments.files(); List<EmailAttachmentSource> emailAttachmentSource = null; if (listFile != null && listFile.size() > 0) { emailAttachmentSource = new ArrayList<>(); for (File file : listFile) { emailAttachmentSource.add(new FileEmailAttachmentSource(file)); } } systemMailService.sendHTMLMail(AppContext.getUser().getEmail(), AppContext.getUser().getDisplayName(), tokenFieldMailTo.getListRecipient(), tokenFieldMailCc.getListRecipient(), tokenFieldMailBcc.getListRecipient(), subject.getValue(), noteArea.getValue(), emailAttachmentSource); MailFormWindow.this.close(); } else { NotificationUtil.showErrorNotification( "Your email is empty value, please fulfil it before sending email!"); } } }); sendBtn.setIcon(FontAwesome.SEND); sendBtn.setStyleName(UIConstants.BUTTON_ACTION); controlsLayout.addComponent(sendBtn); controlsLayout.setComponentAlignment(sendBtn, Alignment.MIDDLE_RIGHT); mainLayout.addComponent(controlsLayout, 0, 2); this.setContent(mainLayout); }
From source file:com.esspl.datagen.DataGenApplication.java
License:Open Source License
@SuppressWarnings("rawtypes") public void generateButtonClick(Button.ClickEvent event) { log.debug("DataGenApplication - generateButtonClick() start"); if (resultNum.getValue() == null || StringUtils.isNullOrEmpty(resultNum.getValue().toString())) { getMainWindow().showNotification("Number of result field cannot be blank!", Notification.TYPE_ERROR_MESSAGE); log.info("DataGenApplication - No. Of result field is blank"); return;//from ww w.ja va 2 s .co m } else if (!StringUtils.isNumber(resultNum.getValue().toString())) { getMainWindow().showNotification("Number of results must be an Integer!", Notification.TYPE_ERROR_MESSAGE); log.info("DataGenApplication - No. Of results is Text"); return; } else if (Integer.parseInt(resultNum.getValue().toString()) > 5000) { getMainWindow().showNotification("Number of results cannot be more than 5000!", Notification.TYPE_ERROR_MESSAGE); log.info("DataGenApplication - No. Of results is greater than 5000"); return; } String dataOption = generateType.getValue().toString(); if (dataOption.equalsIgnoreCase("sql")) { if (tblName.getValue() == null || tblName.getValue().toString().equals("")) { getMainWindow().showNotification("Table Name cannot be blank!", Notification.TYPE_ERROR_MESSAGE); log.info("DataGenApplication - Table name field is blank"); return; } } else if (dataOption.equalsIgnoreCase("xml")) { if (rootNode.getValue() == null || rootNode.getValue().toString().equals("") || recordNode.getValue() == null || recordNode.getValue().toString().equals("")) { getMainWindow().showNotification("Root Node and Record Node cannot be blank!", Notification.TYPE_ERROR_MESSAGE); log.info("DataGenApplication - Root Node and Record Node field is blank"); return; } } rowList.clear(); for (Iterator i = listing.getItemIds().iterator(); i.hasNext();) { log.debug("DataGenApplication - Populating GeneratorBean for row- " + i); int iid = (Integer) i.next(); Item item = listing.getItem(iid); //get the data from grid and populate the GeneratorBean. TextField tf = (TextField) (item.getItemProperty("Column Name").getValue()); Select sel = (Select) (item.getItemProperty("Data Type").getValue()); if (tf.getValue() != null && !tf.getValue().toString().equals("")) { if (sel.getValue() == null) { getMainWindow().showNotification("Select the Data Type for row - " + iid, 3); return; } GeneratorBean bean = new GeneratorBean(); bean.setId(iid); bean.setColumnName(tf.getValue().toString()); bean.setDataType(sel.getValue().toString()); rowList.add(bean); } } if (rowList.size() == 0) { getMainWindow().showNotification("Provide at leat one column to generate data.", 2); return; } //If EXCEL option is selected then no need to open Dialog box. Directly build the Excel sheet by using JExcel Api if (dataOption.equalsIgnoreCase("excel")) { log.debug("DataGenApplication - generateButtonClick() - Generating Excel Sheet"); Generator genrator = new ExcelDataGenerator(); genrator.generate(this, rowList); return; } // Create the result window... resultWindow = new ResultView(this, rowList); resultWindow.setModal(true); resultWindow.setResizable(false); resultWindow.setCaption("Generated Data"); getMainWindow().addWindow(resultWindow); log.debug("DataGenApplication - generateButtonClick() end"); }
From source file:com.esspl.datagen.generator.impl.CsvDataGenerator.java
License:Open Source License
/** * Actual data generation logic for CSV present here *///from w w w . jav a2 s . c o m @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(); }