List of usage examples for com.vaadin.ui TextField getValue
@Override
public String getValue()
From source file:com.skysql.manager.ui.MonitorsSettings.java
License:Open Source License
/** * Monitor form./*from w ww. j a v a2s. c om*/ * * @param monitor the monitor * @param title the title * @param description the description * @param button the button */ public void monitorForm(final MonitorRecord monitor, String title, String description, String button) { final TextField monitorName = new TextField("Monitor Name"); final TextField monitorDescription = new TextField("Description"); final TextField monitorUnit = new TextField("Measurement Unit"); final TextArea monitorSQL = new TextArea("SQL Statement"); final CheckBox monitorDelta = new CheckBox("Is Delta"); final CheckBox monitorAverage = new CheckBox("Is Average"); final NativeSelect validationTarget = new NativeSelect("Validate SQL on"); final NativeSelect monitorInterval = new NativeSelect("Sampling interval"); final NativeSelect monitorChartType = new NativeSelect("Default display"); secondaryDialog = new ModalWindow(title, null); UI.getCurrent().addWindow(secondaryDialog); secondaryDialog.addCloseListener(this); final VerticalLayout formContainer = new VerticalLayout(); formContainer.setMargin(new MarginInfo(true, true, false, true)); formContainer.setSpacing(false); final Form form = new Form(); formContainer.addComponent(form); form.setImmediate(false); form.setFooter(null); form.setDescription(description); String value; if ((value = monitor.getName()) != null) { monitorName.setValue(value); } form.addField("monitorName", monitorName); form.getField("monitorName").setRequired(true); form.getField("monitorName").setRequiredError("Monitor Name is missing"); monitorName.focus(); monitorName.setImmediate(true); monitorName.addValidator(new MonitorNameValidator(monitor.getName())); if ((value = monitor.getDescription()) != null) { monitorDescription.setValue(value); } monitorDescription.setWidth("24em"); form.addField("monitorDescription", monitorDescription); if ((value = monitor.getUnit()) != null) { monitorUnit.setValue(value); } form.addField("monitorUnit", monitorUnit); if ((value = monitor.getSql()) != null) { monitorSQL.setValue(value); } monitorSQL.setWidth("24em"); monitorSQL.addValidator(new SQLValidator()); form.addField("monitorSQL", monitorSQL); final String noValidation = "None - Skip Validation"; validationTarget.setImmediate(true); validationTarget.setNullSelectionAllowed(false); validationTarget.addItem(noValidation); validationTarget.select(noValidation); OverviewPanel overviewPanel = getSession().getAttribute(OverviewPanel.class); ArrayList<NodeInfo> nodes = overviewPanel.getNodes(); if (nodes == null || nodes.isEmpty()) { SystemInfo systemInfo = VaadinSession.getCurrent().getAttribute(SystemInfo.class); String systemID = systemInfo.getCurrentID(); String systemType = systemInfo.getCurrentSystem().getSystemType(); if (systemID.equals(SystemInfo.SYSTEM_ROOT)) { ClusterComponent clusterComponent = VaadinSession.getCurrent().getAttribute(ClusterComponent.class); systemID = clusterComponent.getID(); systemType = clusterComponent.getSystemType(); } nodes = new ArrayList<NodeInfo>(); for (String nodeID : systemInfo.getSystemRecord(systemID).getNodes()) { NodeInfo nodeInfo = new NodeInfo(systemID, systemType, nodeID); nodes.add(nodeInfo); } } for (NodeInfo node : nodes) { validationTarget.addItem(node.getID()); validationTarget.setItemCaption(node.getID(), node.getName()); } validationTarget.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void valueChange(ValueChangeEvent event) { nodeID = (String) event.getProperty().getValue(); validateSQL = nodeID.equals(noValidation) ? false : true; } }); form.addField("validationTarget", validationTarget); monitorDelta.setValue(monitor.isDelta()); form.addField("monitorDelta", monitorDelta); monitorAverage.setValue(monitor.isAverage()); form.addField("monitorAverage", monitorAverage); SettingsValues intervalValues = new SettingsValues(SettingsValues.SETTINGS_MONITOR_INTERVAL); String[] intervals = intervalValues.getValues(); for (String interval : intervals) { monitorInterval.addItem(Integer.parseInt(interval)); } Collection<?> validIntervals = monitorInterval.getItemIds(); if (validIntervals.contains(monitor.getInterval())) { monitorInterval.select(monitor.getInterval()); } else { SystemInfo systemInfo = getSession().getAttribute(SystemInfo.class); String defaultInterval = systemInfo.getSystemRecord(systemID).getProperties() .get(SystemInfo.PROPERTY_DEFAULTMONITORINTERVAL); if (defaultInterval != null && validIntervals.contains(Integer.parseInt(defaultInterval))) { monitorInterval.select(Integer.parseInt(defaultInterval)); } else if (!validIntervals.isEmpty()) { monitorInterval.select(validIntervals.toArray()[0]); } else { new ErrorDialog(null, "No set of permissible monitor intervals found"); } monitorInterval.setNullSelectionAllowed(false); form.addField("monitorInterval", monitorInterval); } for (UserChart.ChartType type : UserChart.ChartType.values()) { monitorChartType.addItem(type.name()); } monitorChartType .select(monitor.getChartType() == null ? UserChart.ChartType.values()[0] : monitor.getChartType()); monitorChartType.setNullSelectionAllowed(false); form.addField("monitorChartType", monitorChartType); HorizontalLayout buttonsBar = new HorizontalLayout(); buttonsBar.setStyleName("buttonsBar"); buttonsBar.setSizeFull(); buttonsBar.setSpacing(true); buttonsBar.setMargin(true); buttonsBar.setHeight("49px"); Label filler = new Label(); buttonsBar.addComponent(filler); buttonsBar.setExpandRatio(filler, 1.0f); Button cancelButton = new Button("Cancel"); buttonsBar.addComponent(cancelButton); buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT); cancelButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { form.discard(); secondaryDialog.close(); } }); Button okButton = new Button(button); okButton.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = 0x4C656F6E6172646FL; public void buttonClick(ClickEvent event) { try { form.setComponentError(null); form.commit(); monitor.setName(monitorName.getValue()); monitor.setDescription(monitorDescription.getValue()); monitor.setUnit(monitorUnit.getValue()); monitor.setSql(monitorSQL.getValue()); monitor.setDelta(monitorDelta.getValue()); monitor.setAverage(monitorAverage.getValue()); monitor.setInterval((Integer) monitorInterval.getValue()); monitor.setChartType((String) monitorChartType.getValue()); String ID; if ((ID = monitor.getID()) == null) { if (Monitors.setMonitor(monitor)) { ID = monitor.getID(); select.addItem(ID); select.select(ID); Monitors.reloadMonitors(); monitorsAll = Monitors.getMonitorsList(systemType); } } else { Monitors.setMonitor(monitor); ChartProperties chartProperties = getSession().getAttribute(ChartProperties.class); chartProperties.setDirty(true); settingsDialog.setRefresh(true); } if (ID != null) { select.setItemCaption(ID, monitor.getName()); displayMonitorRecord(ID); secondaryDialog.close(); } } catch (EmptyValueException e) { return; } catch (InvalidValueException e) { return; } catch (Exception e) { ManagerUI.error(e.getMessage()); return; } } }); buttonsBar.addComponent(okButton); buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT); VerticalLayout windowLayout = (VerticalLayout) secondaryDialog.getContent(); windowLayout.setSpacing(false); windowLayout.setMargin(false); windowLayout.addComponent(formContainer); windowLayout.addComponent(buttonsBar); }
From source file:com.snowy.NewUserSubWindow.java
public void build() { //setClosable(false); setModal(true);/*from www . ja v a 2 s. c o m*/ setResizable(false); setResponsive(true); setDraggable(false); FormLayout fl = new FormLayout(); fl.setMargin(true); //fl.setSizeFull(); fl.setSizeUndefined(); fl.setSpacing(true); TextField uname = new TextField("Username"); uname.setRequired(true); //uname.addValidator(null); fl.addComponent(uname); TextField email = new TextField("Email"); email.setRequired(true); email.addValidator(new EmailValidator("A Valid Email is Required")); fl.addComponent(email); PasswordField pf1 = new PasswordField("Password"); pf1.setRequired(true); pf1.addValidator(new StringLengthValidator("Password must be between 8 and 60 characters", 8, 60, false)); fl.addComponent(pf1); PasswordField pf2 = new PasswordField("Confirm Password"); pf2.setRequired(true); pf2.addValidator((Object value) -> { if (!pf2.getValue().equals(pf1.getValue())) { throw new InvalidValueException("Passwords Must Match"); } }); //pf2.setImmediate(true); fl.addComponent(pf2); Button b = new Button("Submit"); b.addClickListener((Button.ClickEvent e) -> { if (uname.isValid() && email.isValid() && pf1.isValid() && pf2.isValid()) { String result = d.createUser(uname.getValue(), pf2.getValue(), email.getValue()); if (result.equals("Creation Sucess")) { fl.removeAllComponents(); fl.addComponent(new Label("User Created Sucessfully")); fl.addComponent(new Button("Close", (ee) -> { this.close(); })); } else { Notification.show(result); } } else { b.setComponentError(new UserError("Issues with required fields")); } //d.close(); }); fl.addComponent(b); setContent(fl); }
From source file:com.squadd.views.ChatView.java
private void buildLayout() { VerticalLayout chatAndFooter = new VerticalLayout(); chatAndFooter.setHeight("90%"); VerticalLayout contacts = new VerticalLayout(); contacts.setSizeFull();/*from w w w . jav a 2s .c om*/ contactsPanel.setHeight("800px"); contactsPanel.setWidth("300px"); contactsPanel.setContent(contactsLayout); contacts.addComponent(contactsPanel); contacts.setHeight("90%"); TextField idTo = new TextField("idTo"); idTo.setWidth("200px"); Button setIdTo = new Button("set"); setIdTo.setWidth("100px"); HorizontalLayout setUserToId = new HorizontalLayout(); Button.ClickListener st = new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (!idTo.getValue().equals("")) { UserInfoBean newUserTo = new UserInfoBean(); newUserTo.setId(Integer.parseInt(idTo.getValue())); newUserTo.setName("id" + idTo.getValue()); control.setUserTo(newUserTo); if (footer.isVisible() == false) { footer.setVisible(true); } UserInfoFace look = new UserInfoFace(newUserTo, control, footer); Panel panel = look.getUserPanel(); boolean exists = false; for (int i = 0; i < contactsLayout.getComponentCount(); i++) { if (contactsLayout.getComponent(i).getClass() == Panel.class) { Panel pan = (Panel) contactsLayout.getComponent(i); if ((!(pan.getId() == null)) && pan.getId().equals(idTo.getValue())) { exists = true; } } } if (exists == false) { contactsLayout.addComponent(panel); } control.clearChat(); control.updateChatLog(10); } idTo.clear(); } }; setIdTo.addClickListener(st); setUserToId.addComponents(idTo, setIdTo); setUserToId.setComponentAlignment(setIdTo, Alignment.BOTTOM_CENTER); contacts.addComponent(setUserToId); mainLayout.addComponents(contacts); footer.setVisible(false);///////// chatAndFooter.addComponents(chatPanel, footer); chatLayout = new VerticalLayout(); chatPanel.setHeight("750px"); chatPanel.setWidth("900px"); chatPanel.setContent(chatLayout); chatInput = new TextField(); chatInput.setWidthUndefined(); footer.addComponent(chatInput); chatInput.focus(); send.setWidth("120px"); footer.addComponent(send); clear.setWidth("120px"); footer.addComponent(clear); update.setWidth("120px"); footer.addComponent(update); footer.setHeight("50px"); footer.setWidth("900px"); chatInput.setWidth("100%"); footer.setExpandRatio(chatInput, 1f); chatAndFooter.setExpandRatio(chatPanel, 1f); mainLayout.addComponents(chatAndFooter); mainLayout.setExpandRatio(chatAndFooter, 1f); control.loadFriends(); }
From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java
private VerticalLayout getEUDContainer() { if (cBtnEditCancel != null) cBtnEditCancel.setVisible(false); HashMap<Integer, String> profToID = new HashMap<>(); profToID.put(1, "MATS_ADMIN_USER_PROFILE"); profToID.put(3, "MATS_FINANCIAL_CONTROLLER_USER_PROFILE"); profToID.put(4, "MATS_CUSTOMER_CARE_USER_PROFILE"); profToID.put(6, "MATS_SUPER_AGENT_USER_PROFILE"); profToID.put(7, "MATS_SUB_AGENT_USER_PROFILE"); profToID.put(11, "MATS_DEALER_USER_PROFILE"); profToID.put(15, "MATS_SERVICE_PROVIDER_USER_PROFILE"); VerticalLayout cAgentInfo = new VerticalLayout(); cAgentInfo.setMargin(new MarginInfo(true, false, true, false)); cAgentInfo.setStyleName("c_details_test"); cAgentInfo.setSizeUndefined();/*from w w w . j a v a2 s . co m*/ VerticalLayout cBasic = new VerticalLayout(); Label lbB = new Label("Basic"); lbB.setStyleName("lb_frm_add_user"); cBasic.addComponent(lbB); TextField tF = new TextField("First Name"); tFFN = tF; tFFN.setRequired(true); tF.setValue("Paul"); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cBasic.addComponent(tF); tF = new TextField("Middle Name"); tF.setValue("Pwndz"); tFMN = tF; tFMN.setRequired(true); cBasic.addComponent(tF); tF = new TextField("Last Name"); tF.setValue("Kigozi"); tFLN = tF; tFLN.setRequired(true); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cBasic.addComponent(tF); OptionGroup opt = new OptionGroup("Gender"); opt.addItem("FEMALE"); // opt.setItemCaption(1, "Female"); opt.addItem("MALE"); // opt.setItemCaption(2, "Male"); opt.select("MALE"); optSex = opt; optSex.setRequired(true); arrLAllFormFields.add(opt); arrLAllEditableFields.add(opt); arrLTfEditableVals.add(opt.getValue().toString()); cBasic.addComponent(opt); ComboBox combo = new ComboBox("Prefix"); combo.addItem("Mr. "); combo.addItem("Mrs. "); combo.addItem("Dr. "); combo.addItem("Eng. "); combo.addItem("Prof. "); comboPref = combo; comboPref.select("Eng. "); arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cBasic.addComponent(combo); combo = new ComboBox("Suffix"); combo.addItem("Ph.D"); combo.addItem("M.B.A"); combo.addItem("RA"); combo.addItem("CISA "); combo.select("Ph.D"); comboSuff = combo; arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cBasic.addComponent(combo); combo = new ComboBox("Language"); combo.addItem(1); combo.select(1); combo.setItemCaption(1, "en-US"); combo.addItem(2); combo.setItemCaption(2, "en-UK"); combo.addItem(3); combo.setItemCaption(3, "fr"); comboLang = combo; comboLang.setRequired(true); arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cBasic.addComponent(combo); tF = new TextField("Occupation"); tF.setValue("Software Engineer"); tFOcc = tF; tFOcc.setRequired(true); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cBasic.addComponent(tF); tF = new TextField("Employer"); tF.setValue("Swifta"); tFEmp = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cBasic.addComponent(tF); PopupDateField dF = new PopupDateField("DoB"); cal = Calendar.getInstance(); cal.set(1988, 11, 12); dF.setValue(cal.getTime()); dFDoB = dF; arrLAllFormFields.add(dF); arrLAllEditableFields.add(dF); arrLTfEditableVals.add(dF.getValue().toString()); cBasic.addComponent(dF); combo = new ComboBox("Country"); comboCountry = combo; comboCountry.setRequired(true); cBasic.addComponent(combo); combo = new ComboBox("State"); comboState = combo; comboState.setRequired(true); comboState.setNullSelectionAllowed(false); arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cBasic.addComponent(combo); combo = new ComboBox("Local Government"); // combo.addItem(1); // combo.setItemCaption(1, "Ca. LG"); // combo.select(1); comboLG = combo; comboLG.setRequired(true); arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cBasic.addComponent(combo); /* * if (!(strUserType.equals("CCO") || strUserType.equals("BA"))) { * * cBasic.addComponent(dF); * * combo.addItem("Passport"); combo.addItem("Voter's Card"); * combo.addItem("Driving License"); combo.addItem("National ID"); * combo.addItem("Residential ID"); cBasic.addComponent(combo); * * tF = new TextField("ID No."); cBasic.addComponent(tF); * * combo = new ComboBox("State"); cBasic.addComponent(combo); * * combo = new ComboBox("Country"); cBasic.addComponent(combo); } */ VerticalLayout cC = new VerticalLayout(); HorizontalLayout cBAndCAndAcc = new HorizontalLayout(); cBAndCAndAcc.addComponent(cBasic); cBAndCAndAcc.addComponent(cC); VerticalLayout cCompany = new VerticalLayout(); // Label lbC = new Label("Company"); Label lbC = new Label("Identification"); lbC.setStyleName("lb_frm_add_user"); combo = new ComboBox("ID Type"); combo.addItem("Passport Number"); combo.addItem("National Registration Identification Number"); combo.addItem("Drivers License Number"); combo.addItem("Identification Card"); combo.addItem("Employer Identification Number"); combo.select("Passport Number"); comboIDType = combo; comboIDType.setRequired(true); arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cCompany.addComponent(combo); tF = new TextField("ID No."); tF.setValue("001"); tFIDNo = tF; tFIDNo.setRequired(true); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cCompany.addComponent(tF); tF = new TextField("Issuer"); tFIssuer = tF; tFIssuer.setValue("Republic of Uganda"); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cCompany.addComponent(tF); dF = new PopupDateField("Issue Date"); // cal = Calendar.getInstance(); cal.set(12, 12, 12); dF.setValue(cal.getTime()); dFDoI = dF; arrLAllFormFields.add(dF); arrLAllEditableFields.add(dF); arrLTfEditableVals.add(dF.getValue().toString()); cCompany.addComponent(dF); dF = new PopupDateField("Expiry Date"); // cal = Calendar.getInstance(); cal.set(14, 12, 12); dF.setValue(cal.getTime()); dF.setValue(cal.getTime()); dFDoE = dF; dFDoE.setRequired(true); dFDoE.setImmediate(true); arrLAllFormFields.add(dF); arrLAllEditableFields.add(dF); arrLTfEditableVals.add(dF.getValue().toString()); cCompany.addComponent(dF); cC.addComponent(cCompany); VerticalLayout pC = new VerticalLayout(); lbC = new Label("Primary Contacts"); HorizontalLayout cLbc = new HorizontalLayout(); cLbc.setSizeUndefined(); cLbc.setMargin(new MarginInfo(true, false, false, false)); cLbc.addComponent(lbC); pC.addComponent(cLbc); tF = new TextField("Mobile Phone No."); tF.setValue("+256704191152"); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); tFPMNo = tF; pC.addComponent(tF); tF = new TextField("Alt. Phone No."); tF.setValue("+1704191152"); tFPANo = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); pC.addComponent(tF); tF = new TextField("Email Address"); tF.setValue("pwndz172@gmail.com"); tFPEmail = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); pC.addComponent(tF); cC.addComponent(pC); VerticalLayout sC = new VerticalLayout(); lbC = new Label("Secondary Contacts"); cLbc = new HorizontalLayout(); cLbc.setSizeUndefined(); cLbc.setMargin(new MarginInfo(true, false, false, false)); cLbc.addComponent(lbC); sC.addComponent(cLbc); tF = new TextField("Mobile Phone No."); tF.setValue("+256804191152"); tFSMNo = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); sC.addComponent(tF); tF = new TextField("Alt. Phone No."); tF.setValue("+1804191152"); tFSANo = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); sC.addComponent(tF); tF = new TextField("E-mail Address"); tF.setValue("pkigozi@swifta.com"); tFSEmail = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); sC.addComponent(tF); cC.addComponent(sC); VerticalLayout physicalC = new VerticalLayout(); lbC = new Label("Physical Address"); cLbc = new HorizontalLayout(); cLbc.setSizeUndefined(); cLbc.setMargin(new MarginInfo(true, false, false, false)); cLbc.addComponent(lbC); physicalC.addComponent(cLbc); tF = new TextField("Street"); tF.setValue("Yusuf Lule Rd."); tFStreet = tF; tFStreet.setRequired(true); physicalC.addComponent(tF); tF = new TextField("Postal Code"); tF.setValue("23"); tFPostalCode = tF; physicalC.addComponent(tF); tF = new TextField("City"); tF.setValue("Kampala"); tFCity = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); tFCity.setRequired(true); physicalC.addComponent(tF); tF = new TextField("Province"); tF.setValue("Central"); tFProv = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); physicalC.addComponent(tF); cC.addComponent(physicalC); /* * || strUserType.equals("BA"))) { tF = new TextField("Fax"); * cC.addComponent(tF); // strAccTypeCaption = Hierarch } */ /* * tF = new TextField("E-mail Address"); cC.addComponent(tF); * * tF = new TextField("Physical Address"); cC.addComponent(tF); */ VerticalLayout cAcc = new VerticalLayout(); Label lbAcc = new Label("Account"); lbAcc.setStyleName("lb_frm_add_user"); cAcc.addComponent(lbAcc); ComboBox comboHierarchy = null; comboHierarchy = new ComboBox("Profile"); Set<Entry<Integer, String>> set = profToID.entrySet(); for (Entry<Integer, String> e : set) { comboHierarchy.addItem(e.getKey()); comboHierarchy.setItemCaption(e.getKey(), e.getValue()); } comboHierarchy.select(1); comboProfile = comboHierarchy; comboProfile.setRequired(true); arrLAllFormFields.add(comboProfile); arrLAllEditableFields.add(comboProfile); arrLTfEditableVals.add((comboProfile.getValue() == null) ? "" : comboProfile.getValue().toString()); cAcc.addComponent(comboHierarchy); final VerticalLayout cLBody = new VerticalLayout(); tF = new TextField("Username"); tF.setValue("Livepwndz"); tFUN = tF; tFUN.setRequired(true); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cLBody.addComponent(tF); tF = new TextField("MSISDN"); tF.setValue("+256774191152"); tFMSISDN = tF; tFMSISDN.setRequired(true); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cLBody.addComponent(tF); // / tF = new TextField("PIN"); // / cLBody.addComponent(tF); tF = new TextField("Email"); tFAccEmail = tF; tFAccEmail.setRequired(true); tFAccEmail.setValue("ppounds1@gmail.com"); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cLBody.addComponent(tF); combo = new ComboBox("Bank Domain"); combo.addItem("Stanbic Bank"); combo.select("Stanbic Bank"); comboBDomain = combo; arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cLBody.addComponent(combo); combo = new ComboBox("Bank Code ID"); combo.addItem("001"); combo.select("001"); comboBID = combo; arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cLBody.addComponent(combo); tF = new TextField("Bank Account"); tF.setValue("00232333452315"); tFBAcc = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); // tFBAcc.setValidationVisible(true); // tFBAcc.addValidator(new NoNull()); cLBody.addComponent(tF); combo.addItem(1); combo.setItemCaption(1, "US Dollars"); combo.select(1); comboCur = combo; arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); cLBody.addComponent(combo); tF = new TextField("Clearing Number"); tF.setValue("00212"); tFClrNo = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cLBody.addComponent(tF); Label lbAccRec = new Label("Account Recovery"); HorizontalLayout cLbAccRec = new HorizontalLayout(); cLbAccRec.setSizeUndefined(); cLbAccRec.setMargin(new MarginInfo(true, false, false, false)); cLbAccRec.addComponent(lbAccRec); // cLBody.addComponent(cLbAccRec); combo = new ComboBox("Security Question"); combo.addItem(1); combo.addItem(2); combo.addItem(3); combo.setItemCaption(1, "What is your grandfather's last name?"); combo.setItemCaption(2, "What was your favorite junior school teacher's name?"); combo.setItemCaption(3, "What was one of your nicknames in school?"); combo.select(2); comboSecQn = combo; arrLAllFormFields.add(combo); arrLAllEditableFields.add(combo); arrLTfEditableVals.add((combo.getValue() == null) ? "" : combo.getValue().toString()); // cLBody.addComponent(combo); tF = new TextField("Answer"); tF.setValue("Mrs. X"); tFSecAns = tF; arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); // cLBody.addComponent(tF); CheckBox chk = new CheckBox("I accept the terms" + " and conditons."); chcTAndC = chk; chk.setStyleName("check_t_and_c"); chk.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = 1L; @Override public void valueChange(ValueChangeEvent event) { // Notification.show(event.getProperty().getValue().toString()); } }); comboCountry.addFocusListener(new FocusListener() { private static final long serialVersionUID = -5162384967736354225L; @Override public void focus(FocusEvent event) { if (isCSelected) return; Set<Entry<Integer, String>> es = (Set<Entry<Integer, String>>) getCountries().entrySet(); if (es.size() == 0) return; Iterator<Entry<Integer, String>> itr = es.iterator(); comboCountry.setNullSelectionAllowed(false); while (itr.hasNext()) { Entry<Integer, String> e = (Entry<Integer, String>) itr.next(); comboCountry.addItem(e.getKey()); comboCountry.setItemCaption(e.getKey(), e.getValue()); } comboCountry.select(null); isCSelected = true; } }); comboCountry.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = -404551290095133508L; @Override public void valueChange(ValueChangeEvent event) { comboState.removeAllItems(); comboLG.removeAllItems(); if (comboCountry.getValue() == null) return; Set<Entry<Integer, String>> es = (Set<Entry<Integer, String>>) getStates( Integer.valueOf(comboCountry.getValue().toString())).entrySet(); if (es.isEmpty()) { return; } Iterator<Entry<Integer, String>> itr = es.iterator(); while (itr.hasNext()) { Entry<Integer, String> e = itr.next(); comboState.addItem(e.getKey()); comboState.setItemCaption(e.getKey(), e.getValue()); } comboState.select(null); } }); comboState.addFocusListener(new FocusListener() { private static final long serialVersionUID = 892516817835461278L; @Override public void focus(FocusEvent event) { Object c = comboCountry.getValue(); if (c == null) { Notification.show("Please select country first", Notification.Type.WARNING_MESSAGE); comboCountry.focus(); return; } } }); comboState.addValueChangeListener(new ValueChangeListener() { private static final long serialVersionUID = 8849241310354979908L; @Override public void valueChange(ValueChangeEvent event) { comboLG.removeAllItems(); if (comboState.getValue() == null) return; Set<Entry<Integer, String>> esl = (Set<Entry<Integer, String>>) getLGs( Integer.valueOf(comboState.getValue().toString())).entrySet(); if (esl.isEmpty()) { return; } Iterator<Entry<Integer, String>> itrl = esl.iterator(); while (itrl.hasNext()) { Entry<Integer, String> e = itrl.next(); comboLG.addItem(e.getKey()); comboLG.setItemCaption(e.getKey(), e.getValue()); } } }); comboLG.addFocusListener(new FocusListener() { private static final long serialVersionUID = 8925916817835461278L; @Override public void focus(FocusEvent event) { Object s = comboState.getValue(); if (comboCountry.getValue() == null) { Notification.show("Please select country first", Notification.Type.WARNING_MESSAGE); comboCountry.focus(); return; } if (s == null) { Notification.show("Please select state first", Notification.Type.WARNING_MESSAGE); comboState.focus(); return; } } }); HorizontalLayout cChk = new HorizontalLayout(); cChk.setSizeUndefined(); cChk.setMargin(new MarginInfo(true, false, true, false)); cChk.addComponent(chk); // cLBody.addComponent(cChk); final VerticalLayout cRBody = new VerticalLayout(); String strNameCap = "Username"; tF = new TextField(strNameCap); arrLAllFormFields.add(tF); arrLAllEditableFields.add(tF); arrLTfEditableVals.add(tF.getValue()); cRBody.addComponent(tF); HorizontalLayout cAccBody = new HorizontalLayout(); cAccBody.addComponent(cLBody); cAccBody.addComponent(cRBody); cLBody.setStyleName("c_body_visible"); cRBody.setStyleName("c_body_invisible"); cAcc.addComponent(cAccBody); cBAndCAndAcc.addComponent(cAcc); cC.setMargin(new MarginInfo(false, true, false, true)); cAgentInfo.addComponent(cBAndCAndAcc); final String btnSaveId = "save"; final String btnEditId = "edit"; final Button btnEdit = new Button(); btnEdit.setIcon(FontAwesome.SAVE); btnEdit.setId(btnSaveId); btnEdit.setStyleName("btn_link"); final Button btnCancel = new Button(); btnCancel.setVisible(true); btnCancel.setIcon(FontAwesome.UNDO); btnCancel.setStyleName("btn_link"); final HorizontalLayout cBtnSR = new HorizontalLayout(); cBtnSR.addComponent(btnEdit); cBtnSR.addComponent(btnCancel); // cBtnEditCancel cAcc.addComponent(cBtnSR); btnEdit.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -935880570210949227L; @Override public void buttonClick(ClickEvent event) { /* * Prepare all Editable fields (Entire form) for editing. */ if (event.getButton().getId().equals(btnEditId)) { /* * By Default, btnCancel is not visible, until btnEdit is * clicked. Only until then is it added and visible. */ if (!btnCancel.isVisible()) { event.getButton().setId(btnSaveId); event.getButton().setIcon(FontAwesome.SAVE); btnCancel.setVisible(true); cBtnSR.addComponent(btnCancel); } enableEditableFormFields(arrLAllEditableFields); } else { if (event.getButton().getId().equals(btnSaveId)) { /* * * * * * commit (save) changes i.e, send changes back to the * server. */ try { validateAndSave(); // cUPersonalDetails.removeAllComponents(); // cUPersonalDetails.addComponent(getUDContainer()); // Notification.show("Details successfully saved.", // Notification.Type.WARNING_MESSAGE); } catch (Exception e) { // Notification.show("Hello"); return; } // Remove undo button (btnCancel) btnCancel.setVisible(false); // Reset all Editable fields to readOnly after saving to // the server // disableEditableFields(arrLAllEditableFields); // Reset btnEdit id to btnIdEdit and caption(icon) to // FontAwesome.EDIT btnEdit.setId(btnEditId); btnEdit.setIcon(FontAwesome.EDIT); btnEdit.setVisible(false); // Reset Edit status to false uDetailsEditStatus = false; } } } }); btnCancel.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -8179030387969880920L; @Override public void buttonClick(ClickEvent event) { resetForm(arrLAllEditableFields, arrLTfEditableVals); btnEdit.setId(btnEditId); btnEdit.setIcon(FontAwesome.EDIT); btnEdit.setVisible(false); btnCancel.setVisible(false); } }); return cAgentInfo; }
From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java
private void addLinkUserContainer() { VerticalLayout cDeletePrompt = new VerticalLayout(); cPlaceholder.addComponent(cDeletePrompt); cPlaceholder.setComponentAlignment(cDeletePrompt, Alignment.MIDDLE_CENTER); // cDeletePrompt.setWidth("100%"); cDeletePrompt.setStyleName("c_link"); cDeletePrompt.setSpacing(true);//from w ww . j av a 2s . com String username = curUser; Label lbActivationPrompt = new Label( "<span style='text-align: center;'>Please enter Child Username to link to " + username + "'s Account</span>"); lbActivationPrompt.setContentMode(ContentMode.HTML); lbActivationPrompt.setWidth("300px"); lbActivationPrompt.setStyleName("lb_link_user"); cDeletePrompt.addComponent(lbActivationPrompt); cDeletePrompt.setComponentAlignment(lbActivationPrompt, Alignment.TOP_LEFT); VerticalLayout frmDeleteReason = new VerticalLayout(); frmDeleteReason.setSizeUndefined(); frmDeleteReason.setSpacing(true); frmDeleteReason.setMargin(true); cDeletePrompt.addComponent(frmDeleteReason); cDeletePrompt.setComponentAlignment(frmDeleteReason, Alignment.TOP_CENTER); tFU = new TextField("Child Username"); tFU.setRequired(true); final ComboBox comboUProf = new ComboBox("Select Profile"); comboUProf.setNullSelectionAllowed(false); comboUProf.setRequired(true); comboUProf.addItem(8); comboUProf.setItemCaption(8, "DEPOSIT_ONLY"); comboUProf.addItem(9); comboUProf.setItemCaption(9, "DEPOSIT_AND_WITHDRAWAL"); comboUProf.select(8); final TextField tFP = new TextField("Parent Account ID"); tFP.setValue(username); tFP.setEnabled(false); final TextField tFInitUser = new TextField("Initiating User"); tFInitUser.setValue(UI.getCurrent().getSession().getAttribute("user").toString()); tFInitUser.focus(); tFInitUser.setEnabled(false); frmDeleteReason.addComponent(tFU); frmDeleteReason.addComponent(comboUProf); frmDeleteReason.addComponent(tFP); frmDeleteReason.addComponent(tFInitUser); HorizontalLayout cPopupBtns = new HorizontalLayout(); cPopupBtns.setSizeUndefined(); cPopupBtns.setSpacing(true); final Button btnCancel = new Button(); btnCancel.setIcon(FontAwesome.UNDO); btnCancel.setStyleName("btn_link"); btnCancel.setDescription("Cancel"); final Button btnSet = new Button("Link"); btnSet.setDescription("Link specified account."); btnSet.setIcon(FontAwesome.LINK); cPopupBtns.addComponent(btnSet); cPopupBtns.addComponent(btnCancel); frmDeleteReason.addComponent(cPopupBtns); cDeletePrompt.setComponentAlignment(frmDeleteReason, Alignment.MIDDLE_CENTER); btnSet.setClickShortcut(KeyCode.ENTER, null); btnSet.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -6318666715385643538L; @Override public void buttonClick(ClickEvent event) { tFU.validate(); btnSet.setEnabled(false); btnCancel.setEnabled(false); Button btn = event.getButton(); if (ums == null) ums = new UserManagementService(); btn.setEnabled(false); String strResponse = null; try { strResponse = UserManagementService.linkUser(tFP.getValue(), new Integer(comboUProf.getValue().toString()), tFInitUser.getValue(), tFU.getValue()); if (strResponse.equals("The operation was successful and completed")) { updateLinksTable(tFU.getValue()); cPlaceholder.setVisible(false); tFU.setValue(""); btnLink.setVisible(true); NotifCustom.show("Link", strResponse); } else { NotifCustom.show("Link", strResponse); } } catch (RemoteException e) { e.printStackTrace(); } btnSet.setEnabled(true); btnCancel.setEnabled(true); } }); btnCancel.addClickListener(new ClickListener() { private static final long serialVersionUID = 7161821652386306043L; @Override public void buttonClick(ClickEvent event) { btnLink.setVisible(true); cPlaceholder.setVisible(false); } }); }
From source file:com.swifta.mats.web.usermanagement.UserDetailsModule.java
private HorizontalLayout getPC() { VerticalLayout cAgentInfo = new VerticalLayout(); final HorizontalLayout cPlaceholder = new HorizontalLayout(); cAgentInfo.setMargin(new MarginInfo(true, true, true, true)); cAgentInfo.setStyleName("c_details_test"); final VerticalLayout cLBody = new VerticalLayout(); cLBody.setStyleName("c_body_visible"); tb = new Table("Linked child accounts"); // addLinksTable(); final VerticalLayout cAllProf = new VerticalLayout(); HorizontalLayout cProfActions = new HorizontalLayout(); final FormLayout cProfName = new FormLayout(); cProfName.setStyleName("frm_profile_name"); cProfName.setSizeUndefined();/*from w w w . j a v a 2 s .c o m*/ final Label lbProf = new Label(); final TextField tFProf = new TextField(); lbProf.setCaption("Profile Name: "); lbProf.setValue("Certified Authorized User."); tFProf.setCaption(lbProf.getCaption()); cProfName.addComponent(lbProf); final Button btnEdit = new Button(); btnEdit.setIcon(FontAwesome.EDIT); btnEdit.setStyleName("btn_link"); btnEdit.setDescription("Edit profile name"); final Button btnCancel = new Button(); btnCancel.setIcon(FontAwesome.UNDO); btnCancel.setStyleName("btn_link"); btnCancel.setDescription("Cancel Profile name editting."); Button btnAdd = new Button("+"); // btnAdd.setIcon(FontAwesome.EDIT); btnAdd.setStyleName("btn_link"); btnAdd.setDescription("Set new profile"); Button btnRemove = new Button("-"); // btnRemove.setIcon(FontAwesome.EDIT); btnRemove.setStyleName("btn_link"); btnRemove.setDescription("Remove current profile"); // cProf.addComponent(cProfName); cProfActions.addComponent(btnEdit); cProfActions.addComponent(btnCancel); cProfActions.addComponent(btnAdd); cProfActions.addComponent(btnRemove); btnCancel.setVisible(false); cAllProf.addComponent(cProfName); cAllProf.addComponent(cProfActions); cAllProf.setComponentAlignment(cProfActions, Alignment.TOP_CENTER); cLBody.addComponent(cAllProf); // cLBody.addComponent(tb); tb.setSelectable(true); cAgentInfo.addComponent(cLBody); btnLink = new Button("Add New Link"); btnLink.setIcon(FontAwesome.LINK); btnLink.setDescription("Link new account."); // cLBody.addComponent(btnLink); // cLBody.setComponentAlignment(btnLink, Alignment.TOP_LEFT); btnLink.addClickListener(new LinkClickHandler()); cPlaceholder.setVisible(false); addLinkUserContainer(); cPlaceholder.setWidth("100%"); cLBody.addComponent(cPlaceholder); cLBody.setComponentAlignment(cPlaceholder, Alignment.TOP_CENTER); HorizontalLayout c = new HorizontalLayout(); c.addComponent(cAgentInfo); btnEdit.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -8427226211153164650L; @Override public void buttonClick(ClickEvent event) { if (btnEdit.getIcon().equals(FontAwesome.EDIT)) { tFProf.setValue(lbProf.getValue()); tFProf.selectAll(); cProfName.replaceComponent(lbProf, tFProf); btnEdit.setIcon(FontAwesome.SAVE); btnCancel.setVisible(true); return; } else if (btnEdit.getIcon().equals(FontAwesome.SAVE)) { lbProf.setValue(tFProf.getValue()); cProfName.replaceComponent(tFProf, lbProf); btnEdit.setIcon(FontAwesome.EDIT); btnCancel.setVisible(false); return; } lbProf.setValue(tFProf.getValue()); cProfName.replaceComponent(tFProf, lbProf); btnEdit.setIcon(FontAwesome.EDIT); btnCancel.setVisible(false); } }); btnCancel.addClickListener(new Button.ClickListener() { private static final long serialVersionUID = -2870045546205986347L; @Override public void buttonClick(ClickEvent event) { cProfName.replaceComponent(tFProf, lbProf); btnEdit.setIcon(FontAwesome.EDIT); btnCancel.setVisible(false); } }); btnAdd.addClickListener(new AddProfileHandler(cAllProf, cPlaceholder)); btnRemove.addClickListener(new RemoveProfileHandler(pop)); return c; }
From source file:com.tenforce.lodms.extractors.views.CkanExtractorConfigDialog.java
public CkanExtractorConfigDialog(CkanExtractorConfig config) { this.config = config; availablePackages = new BeanItemContainer(String.class); form.setFormFieldFactory(new CkanExtractFieldFactory()); form.setItemDataSource(new BeanItem<CkanExtractorConfig>(this.config)); form.setVisibleItemProperties(new String[] { "baseUri", "httpMethod", "publisher", "title", "description", "license", "predicatePrefix", "subjectPrefix", "ignoredKeys", "allDatasets", "packageIds" }); final TextField uriField = (TextField) form.getField("baseUri"); final TextField predicateField = (TextField) form.getField("predicatePrefix"); final TextField subjectField = (TextField) form.getField("subjectPrefix"); final TwinColSelect datasetSelector = (TwinColSelect) form.getField("packageIds"); datasetSelector.setVisible(!config.getAllDatasets()); datasetSelector.setContainerDataSource(availablePackages); uriField.addListener(new Property.ValueChangeListener() { @Override//from w w w.j a v a 2s . com public void valueChange(Property.ValueChangeEvent valueChangeEvent) { String uri = (String) uriField.getValue(); if (!uri.endsWith("/")) { uriField.setValue(uri + '/'); return; } predicateField.setValue(uri + "predicate/"); subjectField.setValue(uri + "dataset/"); } }); form.getField("allDatasets").addListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { if (Boolean.FALSE.equals(event.getProperty().getValue())) { String uri = (String) uriField.getValue(); datasetSelector.setValue(null); addPackageIdsToSelect( CkanDataSetList.getPackageIds(uri + "api/3/", getConfig().getHttpMethod())); datasetSelector.setVisible(true); } else { datasetSelector.setVisible(false); } } }); addComponent(form); }
From source file:com.trivago.mail.pigeon.web.components.groups.ModalAddNewGroup.java
License:Apache License
public ModalAddNewGroup(final GroupList gl) { super();//from w ww . ja v a 2s . c om setModal(true); setWidth("300px"); setClosable(false); Panel rootPanel = new Panel("Add new group"); VerticalLayout verticalLayout = new VerticalLayout(); VerticalLayout formLayout = new VerticalLayout(); final TextField tfName = new TextField("Name"); verticalLayout.addComponent(tfName); HorizontalLayout buttonLayout = new HorizontalLayout(); Button saveButton = new Button("Save"); Button cancelButton = new Button("Cancel"); saveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { if (tfName.getValue().equals("")) { tfName.setComponentError(new UserError("Name must not be empty")); } else { tfName.setComponentError(null); } /* TODO XXX check for existing group: no duplicates! */ if (!tfName.getValue().equals("")) { tfName.setComponentError(null); long groupId = Util.generateId(); try { RecipientGroup g = new RecipientGroup(groupId, tfName.getValue().toString()); event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); event.getButton().getWindow().getParent().showNotification("Saved successfully", Notification.TYPE_HUMANIZED_MESSAGE); gl.getBeanContainer().addItem(g.getId(), g); // The group select could be placed anywhere but must be reloaded to reflect the changes. GroupSelectBox.reloadSelect(); } catch (RuntimeException e) { // Should never happen ... hopefully :D } } event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); verticalLayout.addComponent(formLayout); verticalLayout.addComponent(buttonLayout); rootPanel.addComponent(verticalLayout); this.addComponent(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.mail.ModalAddNewsletter.java
License:Apache License
public ModalAddNewsletter(final NewsletterList nl) { super();/* www.ja v a2 s. co m*/ setModal(true); setWidth("600px"); setClosable(false); Panel rootPanel = new Panel("Add new Newsletter"); final VerticalLayout verticalLayout = new VerticalLayout(); final SenderSelectBox senderSelectBox = new SenderSelectBox(); final HorizontalLayout buttonLayout = new HorizontalLayout(); final GroupSelectBox groupSelectBox = new GroupSelectBox(); final UploadTextFileComponent uploadTextfile = new UploadTextFileComponent(); final UploadHtmlFileComponent uploadHtmlfile = new UploadHtmlFileComponent(); final TemplateSelectBox templateSelectBox = new TemplateSelectBox(); final TextField tfSubject = new TextField("Subject"); final DateField tfSendDate = new DateField("Send Date"); final Button cancelButton = new Button("Cancel"); final Button saveButton = new Button("Send"); tfSendDate.setInvalidAllowed(false); tfSendDate.setResolution(DateField.RESOLUTION_MIN); tfSendDate.setValue(new Date()); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); saveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { boolean hasError = false; // Validation if (tfSubject.getValue().equals("") && templateSelectBox.getSelectedTemplate() == null) { hasError = true; tfSubject.setComponentError( new UserError("Subject cannot be empty if you do not choose a template.")); } else { tfSubject.setComponentError(null); } if (tfSendDate.getValue() == null) { hasError = true; tfSendDate.setComponentError(new UserError("Date cannot be empty")); } else { tfSendDate.setComponentError(null); } if (templateSelectBox.getSelectedTemplate() == null) { if (!uploadTextfile.isUploadFinished()) { hasError = true; uploadTextfile.setComponentError( new UserError("You must provide a text file if you do not choose a template")); } else { uploadTextfile.setComponentError(null); } if (!uploadHtmlfile.isUploadFinished()) { hasError = true; uploadHtmlfile.setComponentError( new UserError("You must provide a html file if you do not choose a template")); } else { uploadHtmlfile.setComponentError(null); } } if (senderSelectBox.getSelectedSender() == 0) { hasError = true; senderSelectBox.setComponentError(new UserError("You must select a sender")); } else { senderSelectBox.setComponentError(null); } if (groupSelectBox.getSelectedGroup() == 0) { hasError = true; groupSelectBox.setComponentError(new UserError("You must select a recipient group")); } else { groupSelectBox.setComponentError(null); } log.debug("Has Error: " + hasError); if (!hasError) { log.info("No validation errors found, processing request"); long mailId = Util.generateId(); try { Sender s = new Sender(senderSelectBox.getSelectedSender()); String text; String html; String subject; if (templateSelectBox.getSelectedTemplate() == null) { text = uploadTextfile.getTextData(); html = uploadHtmlfile.getHtmlData(); subject = tfSubject.getValue().toString(); } else { MailTemplate mt = new MailTemplate(templateSelectBox.getSelectedTemplate()); text = mt.getText(); html = mt.getHtml(); subject = mt.getSubject(); } Mail m = new Mail(mailId, text, html, (Date) tfSendDate.getValue(), subject, s); QueueNewsletter queueNewsletter = new QueueNewsletter(); queueNewsletter.queueNewsletter(m, s, new RecipientGroup(groupSelectBox.getSelectedGroup())); event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); event.getButton().getWindow().getParent().showNotification("Queued successfully", Notification.TYPE_HUMANIZED_MESSAGE); nl.getBeanContainer().addItem(m.getId(), m); } catch (RuntimeException e) { log.error("RuntimeException", e); event.getButton().getApplication().getMainWindow().showNotification( "An error occured: " + e.getLocalizedMessage(), Notification.TYPE_ERROR_MESSAGE); } } } }); buttonLayout.setSpacing(true); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); Panel metaData = new Panel("Basic Data"); metaData.addComponent(tfSendDate); verticalLayout.addComponent(metaData); verticalLayout.addComponent(senderSelectBox); verticalLayout.addComponent(groupSelectBox); verticalLayout.addComponent(templateSelectBox); verticalLayout.addComponent(tfSubject); verticalLayout.addComponent(uploadTextfile); verticalLayout.addComponent(uploadHtmlfile); verticalLayout.addComponent(buttonLayout); rootPanel.addComponent(verticalLayout); this.addComponent(rootPanel); }
From source file:com.trivago.mail.pigeon.web.components.sender.ModalAddNewSender.java
License:Apache License
public ModalAddNewSender(final SenderList sl) { super();//from www. ja va 2s.com setClosable(false); setModal(true); setWidth("300px"); Panel rootPanel = new Panel("Add new Sender"); final VerticalLayout verticalLayout = new VerticalLayout(); final TextField tfName = new TextField("Name"); final TextField tfFromMail = new TextField("From E-Mail"); final TextField tfReplyTo = new TextField("ReplyTo E-Mail"); verticalLayout.addComponent(tfName); verticalLayout.addComponent(tfFromMail); verticalLayout.addComponent(tfReplyTo); HorizontalLayout buttonLayout = new HorizontalLayout(); Button saveButton = new Button("Save"); Button cancelButton = new Button("Cancel"); cancelButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); } }); saveButton.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (tfName.getValue().equals("")) { tfName.setComponentError(new UserError("Name must not be empty")); } else { tfName.setComponentError(null); } if (tfFromMail.getValue().equals("")) { tfFromMail.setComponentError(new UserError("From E-Mail must not be empty")); } else { tfFromMail.setComponentError(null); } if (tfReplyTo.getValue().equals("")) { tfReplyTo.setComponentError(new UserError("Reply-To E-Mail must not be empty")); } else { tfReplyTo.setComponentError(null); } if (!tfName.getValue().equals("") && !tfFromMail.getValue().equals("") && !tfReplyTo.getValue().equals("")) { tfName.setComponentError(null); tfFromMail.setComponentError(null); tfReplyTo.setComponentError(null); long senderId = Util.generateId(); try { Sender s = new Sender(senderId, tfFromMail.getValue().toString(), tfReplyTo.getValue().toString(), tfName.getValue().toString()); event.getButton().getWindow().setVisible(false); event.getButton().getWindow().getParent().removeComponent(event.getButton().getWindow()); event.getButton().getWindow().getParent().showNotification("Saved successfully", Notification.TYPE_HUMANIZED_MESSAGE); sl.getBeanContainer().addItem(s.getId(), s); // The sender select could be placed anywhere but must be reloaded to reflect the changes. SenderSelectBox.reloadSelect(); } catch (RuntimeException e) { // Should never happen ... hopefully :D } } } }); buttonLayout.setSpacing(true); buttonLayout.addComponent(saveButton); buttonLayout.addComponent(cancelButton); verticalLayout.addComponent(buttonLayout); rootPanel.addComponent(verticalLayout); this.addComponent(rootPanel); }