List of usage examples for com.vaadin.ui TextField getValue
@Override
public String getValue()
From source file:ru.codeinside.adm.ui.AdminApp.java
License:Mozilla Public License
private Panel buildEsiaPanel() { boolean isEsiaAuth = "true".equals(get(API.ALLOW_ESIA_LOGIN)); final TextField esiaServiceLocation = new TextField("?? ?? "); esiaServiceLocation.setValue(get(API.ESIA_SERVICE_ADDRESS)); esiaServiceLocation.setEnabled(isEsiaAuth); esiaServiceLocation.setRequired(isEsiaAuth); esiaServiceLocation.setWidth(370, Sizeable.UNITS_PIXELS); final CheckBox allowEsiaLogin = new CheckBox(" ?"); allowEsiaLogin.setValue(isEsiaAuth); allowEsiaLogin.setImmediate(true);// www. ja v a 2s .c o m allowEsiaLogin.addListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { Boolean newValue = (Boolean) valueChangeEvent.getProperty().getValue(); esiaServiceLocation.setEnabled(newValue); esiaServiceLocation.setRequired(newValue); } }); final Form form = new Form(); form.addField(API.ALLOW_ESIA_LOGIN, allowEsiaLogin); form.addField(API.ESIA_SERVICE_ADDRESS, esiaServiceLocation); form.setImmediate(true); form.setWriteThrough(false); form.setInvalidCommitted(false); Button commit = new Button("", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { form.commit(); set(API.ALLOW_ESIA_LOGIN, allowEsiaLogin.getValue()); set(API.ESIA_SERVICE_ADDRESS, esiaServiceLocation.getValue()); event.getButton().getWindow().showNotification("?? ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); } catch (Validator.InvalidValueException ignore) { } } }); Panel panel = new Panel("?? ?"); panel.setSizeFull(); panel.addComponent(form); panel.addComponent(commit); return panel; }
From source file:ru.codeinside.adm.ui.AdminApp.java
License:Mozilla Public License
private Panel buildPrintTemplatesPanel() { boolean isUseService = "true".equals(get(API.PRINT_TEMPLATES_USE_OUTER_SERVICE)); final TextField serviceLocation = new TextField("?? ??"); serviceLocation.setValue(get(API.PRINT_TEMPLATES_SERVICELOCATION)); serviceLocation.setEnabled(isUseService); serviceLocation.setRequired(isUseService); serviceLocation.setWidth(370, Sizeable.UNITS_PIXELS); final CheckBox useOuterService = new CheckBox("? ??"); useOuterService.setValue(isUseService); useOuterService.setImmediate(true);/*from w w w . ja v a2 s. co m*/ useOuterService.addListener(new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent valueChangeEvent) { Boolean newValue = (Boolean) valueChangeEvent.getProperty().getValue(); serviceLocation.setEnabled(newValue); serviceLocation.setRequired(newValue); } }); final Form form = new Form(); form.addField(API.PRINT_TEMPLATES_USE_OUTER_SERVICE, useOuterService); form.addField(API.PRINT_TEMPLATES_SERVICELOCATION, serviceLocation); form.setImmediate(true); form.setWriteThrough(false); form.setInvalidCommitted(false); Button commit = new Button("", new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { try { form.commit(); set(API.PRINT_TEMPLATES_USE_OUTER_SERVICE, useOuterService.getValue()); set(API.PRINT_TEMPLATES_SERVICELOCATION, serviceLocation.getValue()); event.getButton().getWindow().showNotification("?? ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); } catch (Validator.InvalidValueException ignore) { } } }); Panel panel = new Panel(" "); panel.setSizeFull(); panel.addComponent(form); panel.addComponent(commit); return panel; }
From source file:ru.codeinside.adm.ui.AdminApp.java
License:Mozilla Public License
private Panel createEmailDatesPanel() { VerticalLayout emailDates = new VerticalLayout(); emailDates.setSpacing(true);// ww w . j av a2 s .c om emailDates.setMargin(true); emailDates.setSizeFull(); Panel panel2 = new Panel(" ? ??", emailDates); panel2.setSizeFull(); final TextField emailToField = new TextField("e-mail ?:"); emailToField.setValue(get(API.EMAIL_TO)); emailToField.setRequired(true); emailToField.setReadOnly(true); emailToField.addValidator(new EmailValidator(" e-mail ?")); final TextField receiverNameField = new TextField("? ?:"); receiverNameField.setValue(get(API.RECEIVER_NAME)); receiverNameField.setRequired(true); receiverNameField.setReadOnly(true); final TextField emailFromField = new TextField("e-mail ?:"); emailFromField.setValue(get(API.EMAIL_FROM)); emailFromField.setRequired(true); emailFromField.setReadOnly(true); emailFromField.addValidator(new EmailValidator(" e-mail ?")); final TextField senderLoginField = new TextField(" ?:"); senderLoginField.setValue(get(API.SENDER_LOGIN)); senderLoginField.setRequired(true); senderLoginField.setReadOnly(true); final TextField senderNameField = new TextField("? ?:"); senderNameField.setValue(get(API.SENDER_NAME)); senderNameField.setRequired(true); senderNameField.setReadOnly(true); final PasswordField passwordField = new PasswordField(":"); passwordField.setValue(API.PASSWORD); passwordField.setRequired(true); passwordField.setReadOnly(true); final TextField hostField = new TextField("SMTP ?:"); String host = get(API.HOST); hostField.setValue(host == null ? "" : host); hostField.setRequired(true); hostField.setReadOnly(true); final TextField portField = new TextField(":"); String port = get(API.PORT); portField.setValue(port == null ? "" : port); portField.setRequired(true); portField.setReadOnly(true); portField.addValidator(new IntegerValidator(" ")); final CheckBox tls = new CheckBox("? TLS", AdminServiceProvider.getBoolProperty(API.TLS)); tls.setReadOnly(true); final Button save = new Button(""); save.setVisible(false); final Button cancel = new Button(""); cancel.setVisible(false); final Button change = new Button(""); final Button check = new Button(""); check.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { String emailTo = get(API.EMAIL_TO); String receiverName = get(API.RECEIVER_NAME); String hostName = get(API.HOST); String port = get(API.PORT); String senderLogin = get(API.SENDER_LOGIN); String password = get(API.PASSWORD); String emailFrom = get(API.EMAIL_FROM); String senderName = get(API.SENDER_NAME); if (emailTo.isEmpty() || receiverName.isEmpty() || hostName.isEmpty() || port.isEmpty() || senderLogin.isEmpty() || password.isEmpty() || emailFrom.isEmpty() || senderName.isEmpty()) { check.getWindow().showNotification("? ? "); return; } Email email = new SimpleEmail(); try { email.setSubject("? ?"); email.setMsg("? ?"); email.addTo(emailTo, receiverName); email.setHostName(hostName); email.setSmtpPort(Integer.parseInt(port)); email.setTLS(AdminServiceProvider.getBoolProperty(API.TLS)); email.setAuthentication(senderLogin, password); email.setFrom(emailFrom, senderName); email.setCharset("utf-8"); email.send(); } catch (EmailException e) { check.getWindow().showNotification(e.getMessage()); e.printStackTrace(); return; } check.getWindow().showNotification("? ? "); } }); change.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { emailToField.setReadOnly(false); receiverNameField.setReadOnly(false); emailFromField.setReadOnly(false); senderLoginField.setReadOnly(false); senderNameField.setReadOnly(false); passwordField.setReadOnly(false); hostField.setReadOnly(false); portField.setReadOnly(false); tls.setReadOnly(false); change.setVisible(false); check.setVisible(false); save.setVisible(true); cancel.setVisible(true); } }); save.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (StringUtils.isEmpty((String) emailToField.getValue()) || StringUtils.isEmpty((String) receiverNameField.getValue()) || StringUtils.isEmpty((String) emailFromField.getValue()) || StringUtils.isEmpty((String) senderNameField.getValue()) || StringUtils.isEmpty((String) senderLoginField.getValue()) || StringUtils.isEmpty((String) passwordField.getValue()) || StringUtils.isEmpty((String) hostField.getValue()) || portField.getValue() == null) { emailToField.getWindow().showNotification(" ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); return; } boolean errors = false; try { emailToField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } try { emailFromField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } try { portField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } if (errors) { return; } set(API.EMAIL_TO, emailToField.getValue()); set(API.RECEIVER_NAME, receiverNameField.getValue()); set(API.EMAIL_FROM, emailFromField.getValue()); set(API.SENDER_LOGIN, senderLoginField.getValue()); set(API.SENDER_NAME, senderNameField.getValue()); set(API.PASSWORD, passwordField.getValue()); set(API.HOST, hostField.getValue()); set(API.PORT, portField.getValue()); set(API.TLS, tls.getValue()); emailToField.setReadOnly(true); receiverNameField.setReadOnly(true); emailFromField.setReadOnly(true); senderLoginField.setReadOnly(true); senderNameField.setReadOnly(true); passwordField.setReadOnly(true); hostField.setReadOnly(true); portField.setReadOnly(true); tls.setReadOnly(true); save.setVisible(false); cancel.setVisible(false); change.setVisible(true); check.setVisible(true); emailToField.getWindow().showNotification("?? ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); } }); cancel.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { emailToField.setValue(get(API.EMAIL_TO)); receiverNameField.setValue(get(API.RECEIVER_NAME)); emailFromField.setValue(get(API.EMAIL_FROM)); senderLoginField.setValue(get(API.SENDER_LOGIN)); senderNameField.setValue(get(API.SENDER_NAME)); passwordField.setValue(get(API.PASSWORD)); hostField.setValue(get(API.HOST)); portField.setValue(get(API.PORT)); tls.setValue(AdminServiceProvider.getBoolProperty(API.TLS)); emailToField.setReadOnly(true); receiverNameField.setReadOnly(true); emailFromField.setReadOnly(true); senderLoginField.setReadOnly(true); senderNameField.setReadOnly(true); passwordField.setReadOnly(true); hostField.setReadOnly(true); portField.setReadOnly(true); tls.setReadOnly(true); save.setVisible(false); cancel.setVisible(false); change.setVisible(true); check.setVisible(true); } }); FormLayout fields1 = new FormLayout(); fields1.setSizeFull(); fields1.addComponent(senderLoginField); fields1.addComponent(passwordField); fields1.addComponent(hostField); fields1.addComponent(portField); fields1.addComponent(tls); FormLayout fields2 = new FormLayout(); fields2.setSizeFull(); fields2.addComponent(emailToField); fields2.addComponent(receiverNameField); fields2.addComponent(emailFromField); fields2.addComponent(senderNameField); HorizontalLayout fields = new HorizontalLayout(); fields.setSpacing(true); fields.setSizeFull(); fields.addComponent(fields1); fields.addComponent(fields2); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.addComponent(change); buttons.addComponent(save); buttons.addComponent(cancel); buttons.addComponent(check); Label label = new Label("?? "); label.addStyleName(Reindeer.LABEL_H2); emailDates.addComponent(label); emailDates.addComponent(fields); emailDates.addComponent(buttons); emailDates.setExpandRatio(fields, 1f); return panel2; }
From source file:ru.codeinside.adm.ui.AdminApp.java
License:Mozilla Public License
private Panel createMilTaskConfigPanel() { VerticalLayout mailConfig = new VerticalLayout(); mailConfig.setSpacing(true);//from w ww . j a v a2 s.c o m mailConfig.setMargin(true); mailConfig.setSizeFull(); Panel emailTaskPanel = new Panel("?? SMTP ? Email Task", mailConfig); emailTaskPanel.setSizeFull(); final TextField mtDefaultFrom = new TextField("email :"); mtDefaultFrom.setValue(get(API.MT_DEFAULT_FROM)); mtDefaultFrom.setRequired(true); mtDefaultFrom.setReadOnly(true); mtDefaultFrom.addValidator(new EmailValidator(" e-mail ?")); final TextField mtSenderLoginField = new TextField(" ?:"); mtSenderLoginField.setValue(get(API.MT_SENDER_LOGIN)); mtSenderLoginField.setRequired(true); mtSenderLoginField.setReadOnly(true); final PasswordField mtPasswordField = new PasswordField(":"); mtPasswordField.setValue(API.MT_PASSWORD); mtPasswordField.setRequired(true); mtPasswordField.setReadOnly(true); final TextField mtHostField = new TextField("SMTP ?:"); String host = get(API.MT_HOST); mtHostField.setValue(host == null ? "" : host); mtHostField.setRequired(true); mtHostField.setReadOnly(true); final TextField mtPortField = new TextField(":"); String port = get(API.MT_PORT); mtPortField.setValue(port == null ? "" : port); mtPortField.setRequired(true); mtPortField.setReadOnly(true); mtPortField.addValidator(new IntegerValidator(" ")); final CheckBox mtTls = new CheckBox("? TLS", AdminServiceProvider.getBoolProperty(API.MT_TLS)); mtTls.setReadOnly(true); final Button save = new Button(""); save.setVisible(false); final Button cancel = new Button(""); cancel.setVisible(false); final Button change = new Button(""); change.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { mtSenderLoginField.setReadOnly(false); mtDefaultFrom.setReadOnly(false); mtPasswordField.setReadOnly(false); mtHostField.setReadOnly(false); mtPortField.setReadOnly(false); mtTls.setReadOnly(false); change.setVisible(false); save.setVisible(true); cancel.setVisible(true); } }); save.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { if (StringUtils.isEmpty((String) mtSenderLoginField.getValue()) || StringUtils.isEmpty((String) mtDefaultFrom.getValue()) || StringUtils.isEmpty((String) mtPasswordField.getValue()) || StringUtils.isEmpty((String) mtHostField.getValue()) || mtPortField.getValue() == null) { mtSenderLoginField.getWindow().showNotification(" ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); return; } boolean errors = false; try { mtDefaultFrom.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } try { mtPortField.validate(); } catch (Validator.InvalidValueException ignore) { errors = true; } if (errors) { return; } set(API.MT_SENDER_LOGIN, mtSenderLoginField.getValue()); set(API.MT_DEFAULT_FROM, mtDefaultFrom.getValue()); set(API.MT_PASSWORD, mtPasswordField.getValue()); set(API.MT_HOST, mtHostField.getValue()); set(API.MT_PORT, mtPortField.getValue()); set(API.MT_TLS, mtTls.getValue()); mtSenderLoginField.setReadOnly(true); mtDefaultFrom.setReadOnly(true); mtPasswordField.setReadOnly(true); mtHostField.setReadOnly(true); mtPortField.setReadOnly(true); mtTls.setReadOnly(true); save.setVisible(false); cancel.setVisible(false); change.setVisible(true); mtSenderLoginField.getWindow().showNotification("?? ?", Window.Notification.TYPE_HUMANIZED_MESSAGE); } }); cancel.addListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { mtSenderLoginField.setValue(get(API.MT_SENDER_LOGIN)); mtDefaultFrom.setValue(get(API.MT_DEFAULT_FROM)); mtPasswordField.setValue(get(API.MT_PASSWORD)); mtHostField.setValue(get(API.MT_HOST)); mtPortField.setValue(get(API.MT_PORT)); mtTls.setValue(AdminServiceProvider.getBoolProperty(API.MT_TLS)); mtSenderLoginField.setReadOnly(true); mtDefaultFrom.setReadOnly(true); mtPasswordField.setReadOnly(true); mtHostField.setReadOnly(true); mtPortField.setReadOnly(true); mtTls.setReadOnly(true); save.setVisible(false); cancel.setVisible(false); change.setVisible(true); } }); FormLayout leftFields = new FormLayout(); leftFields.setSizeFull(); leftFields.addComponent(mtSenderLoginField); leftFields.addComponent(mtDefaultFrom); leftFields.addComponent(mtPasswordField); leftFields.addComponent(mtHostField); leftFields.addComponent(mtPortField); FormLayout rightFields = new FormLayout(); rightFields.setSizeFull(); rightFields.addComponent(mtTls); HorizontalLayout fieldsLayout = new HorizontalLayout(); fieldsLayout.setSpacing(true); fieldsLayout.setSizeFull(); fieldsLayout.addComponent(leftFields); fieldsLayout.addComponent(rightFields); fieldsLayout.setExpandRatio(leftFields, 0.6f); fieldsLayout.setExpandRatio(rightFields, 0.4f); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.addComponent(change); buttons.addComponent(save); buttons.addComponent(cancel); Label label = new Label("?? Email Task"); label.addStyleName(Reindeer.LABEL_H2); mailConfig.addComponent(label); mailConfig.addComponent(fieldsLayout); mailConfig.addComponent(buttons); mailConfig.setExpandRatio(fieldsLayout, 1f); return emailTaskPanel; }
From source file:ru.codeinside.adm.ui.employee.TableEmployee.java
License:Mozilla Public License
protected void edit(final CustomTable table) { final Item item = table.getItem(table.getValue()); final String login = (String) item.getItemProperty("login").getValue(); final UserItem userItem = AdminServiceProvider.get().getUserItem(login); final Pattern snilsPattern = Pattern.compile("\\d{11}"); final Pattern splitSnilsPattern = Pattern.compile("(\\d{3})(\\d{3})(\\d{3})(\\d{2})"); final Panel layout = new Panel(); ((Layout.SpacingHandler) layout.getContent()).setSpacing(true); layout.setSizeFull();/*from w w w.ja v a2 s . c o m*/ layout.addComponent(new Label("? ? " + login)); String widthColumn = "100px"; final PasswordField fieldPass = addPasswordField(layout, widthColumn, ""); final PasswordField fieldPassRepeat = addPasswordField(layout, widthColumn, " ?"); fieldPassRepeat.addValidator(new RepeatPasswordValidator(fieldPass)); final MaskedTextField fieldSnils = addMaskedTextField(layout, widthColumn, "?"); fieldSnils.setMask("###-###-### ##"); final TextField fieldFIO = addTextField(layout, widthColumn, ""); final String snils = userItem.getSnils() == null ? "" : userItem.getSnils(); final Matcher maskMatcher = snilsPattern.matcher(snils); final Matcher splitMatcher = splitSnilsPattern.matcher(snils); if (maskMatcher.matches()) { String maskedSnils = splitMatcher.replaceAll("$1-$2-$3 $4"); fieldSnils.setValue(maskedSnils); } fieldFIO.setValue(userItem.getFio()); HorizontalLayout l1 = new HorizontalLayout(); Label labelRole = new Label(""); labelRole.setWidth(widthColumn); l1.addComponent(labelRole); l1.setComponentAlignment(labelRole, Alignment.MIDDLE_LEFT); final OptionGroup roleOptionGroup = TableEmployee.createRoleOptionGroup(null); roleOptionGroup.setValue(userItem.getRoles()); l1.addComponent(roleOptionGroup); layout.addComponent(l1); final CertificateBlock certificateBlock = new CertificateBlock(userItem); layout.addComponent(certificateBlock); final ExecutorGroupsBlock executorGroupsBlock = new ExecutorGroupsBlock(userItem); layout.addComponent(executorGroupsBlock); final HorizontalLayout supervisorGroupsEmp = new HorizontalLayout(); supervisorGroupsEmp.setMargin(true, true, true, false); supervisorGroupsEmp.setSpacing(true); supervisorGroupsEmp .setCaption("? ? ? ?"); final FilterTable allSupervisorGroupsEmp = new FilterTable(); allSupervisorGroupsEmp.setCaption("?"); table(supervisorGroupsEmp, allSupervisorGroupsEmp); final FilterTable currentSupervisorGroupsEmp = new FilterTable(); currentSupervisorGroupsEmp.setCaption(""); table(supervisorGroupsEmp, currentSupervisorGroupsEmp); for (String groupName : AdminServiceProvider.get().getEmpGroupNames()) { for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) { if (userItem.getEmployeeGroups().contains(groupName)) { currentSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName); } else { allSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName); } } } addListener(allSupervisorGroupsEmp, currentSupervisorGroupsEmp); addListener(currentSupervisorGroupsEmp, allSupervisorGroupsEmp); layout.addComponent(supervisorGroupsEmp); final HorizontalLayout supervisorGroupsOrg = new HorizontalLayout(); supervisorGroupsOrg.setMargin(true, true, true, false); supervisorGroupsOrg.setSpacing(true); supervisorGroupsOrg .setCaption("? ? ?"); final FilterTable allSupervisorGroupsOrg = new FilterTable(); allSupervisorGroupsOrg.setCaption("?"); table(supervisorGroupsOrg, allSupervisorGroupsOrg); final FilterTable currentSupervisorGroupsOrg = new FilterTable(); currentSupervisorGroupsOrg.setCaption(""); table(supervisorGroupsOrg, currentSupervisorGroupsOrg); for (String groupName : AdminServiceProvider.get().getOrgGroupNames()) { for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) { if (userItem.getOrganizationGroups().contains(groupName)) { currentSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName); } else { allSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName); } } } addListener(allSupervisorGroupsOrg, currentSupervisorGroupsOrg); addListener(currentSupervisorGroupsOrg, allSupervisorGroupsOrg); layout.addComponent(supervisorGroupsOrg); setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp, supervisorGroupsOrg); roleOptionGroup.addListener(new Listener() { private static final long serialVersionUID = 1L; public void componentEvent(Event event) { setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp, supervisorGroupsOrg); } }); Button cancel = new Button("", new Button.ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(Button.ClickEvent event) { removeComponent(layout); addComponent(table); table.setValue(null); if (hr != null) { hr.setVisible(true); } setExpandRatio(table, 1f); } }); Button apply = new Button("", new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { String password = (String) fieldPass.getValue(); String passwordRepeat = (String) fieldPassRepeat.getValue(); if (!fieldPassRepeat.isValid() || !(password.equals(passwordRepeat))) { getWindow().showNotification( "? ? ? ?", Window.Notification.TYPE_ERROR_MESSAGE); return; } String snilsFieldValue = fieldSnils.getValue() == null ? "" : (String) fieldSnils.getValue(); String snilsValue = snilsFieldValue.replaceAll("\\D+", ""); Matcher snilsMatcher = snilsPattern.matcher(snilsValue); if (!snilsFieldValue.isEmpty() && !snilsMatcher.matches()) { getWindow().showNotification("? ", Window.Notification.TYPE_ERROR_MESSAGE); return; } if (!AdminServiceProvider.get().isUniqueSnils(login, snilsValue)) { getWindow().showNotification(" ? ", Window.Notification.TYPE_ERROR_MESSAGE); return; } String fio = (String) fieldFIO.getValue(); Set<Role> roles = (Set) roleOptionGroup.getValue(); TreeSet<String> groupExecutor = executorGroupsBlock.getGroups(); TreeSet<String> groupSupervisorEmp = new TreeSet<String>( (Collection<String>) currentSupervisorGroupsEmp.getItemIds()); TreeSet<String> groupSupervisorOrg = new TreeSet<String>( (Collection<String>) currentSupervisorGroupsOrg.getItemIds()); boolean modified = false; if (certificateBlock.isCertificateWasRemoved()) { userItem.setX509(null); modified = true; } if (!password.equals("") && password.equals(passwordRepeat)) { userItem.setPassword1(password); userItem.setPassword2(passwordRepeat); modified = true; } if (!fio.trim().equals("") && !fio.equals(userItem.getFio())) { userItem.setFio(fio); userItem.setX509(null); modified = true; } if (!snilsValue.equals(userItem.getSnils())) { userItem.setSnils(snilsValue); modified = true; } if (!roles.equals(userItem.getRoles())) { userItem.setRoles(roles); modified = true; } if (!groupExecutor.equals(userItem.getGroups())) { userItem.setGroups(groupExecutor); modified = true; } if (!groupSupervisorEmp.equals(userItem.getEmployeeGroups())) { userItem.setEmployeeGroups(groupSupervisorEmp); modified = true; } if (!groupSupervisorOrg.equals(userItem.getOrganizationGroups())) { userItem.setOrganizationGroups(groupSupervisorOrg); modified = true; } if (modified) { // TODO : userInfoPanel // if (getApplication().getUser().equals(login)) { // ((AdminApp) getApplication()).getUserInfoPanel().setRole( // userItem.getRoles().toString()); // } AdminServiceProvider.get().setUserItem(login, userItem); final Container container = table.getContainerDataSource(); if (container instanceof LazyLoadingContainer2) { ((LazyLoadingContainer2) container).fireItemSetChange(); } getWindow().showNotification(" " + login + " "); } else { getWindow().showNotification(" "); } removeComponent(layout); addComponent(table); table.setValue(null); if (hr != null) { hr.setVisible(true); } setExpandRatio(table, 1f); refresh(table); } }); cancel.setClickShortcut(KeyCode.ESCAPE, 0); HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true); buttons.addComponent(apply); buttons.addComponent(cancel); layout.addComponent(buttons); removeComponent(table); addComponent(layout); setExpandRatio(layout, 1f); }
From source file:ru.codeinside.adm.ui.TreeTableOrganization.java
License:Mozilla Public License
private Component buttonCreateEmployee(final Long id) { HorizontalLayout buttons = new HorizontalLayout(); buttons.setSpacing(true);//from w w w .j a va 2s. c o m buttons.setMargin(false, true, false, false); addComponent(buttons); Button createUser = new Button(" ?", new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { showOrganizationLabelsAndButtons(id); final VerticalLayout layout = new VerticalLayout(); layout.setMargin(true); layout.setSpacing(true); layout.setSizeFull(); panel.addComponent(layout); String widthColumn = "100px"; final TextField fieldLogin = TableEmployee.addTextField(layout, widthColumn, ""); final PasswordField fieldPass = TableEmployee.addPasswordField(layout, widthColumn, ""); final PasswordField fieldPassRepeat = TableEmployee.addPasswordField(layout, widthColumn, " "); final MaskedTextField fieldSnils = TableEmployee.addMaskedTextField(layout, widthColumn, "?"); fieldSnils.setMask("###-###-### ##"); fieldPassRepeat.addValidator(new RepeatPasswordValidator(fieldPass)); final TextField fieldFIO = TableEmployee.addTextField(layout, widthColumn, ""); HorizontalLayout l1 = new HorizontalLayout(); Label labelRole = new Label(""); labelRole.setWidth(widthColumn); l1.addComponent(labelRole); l1.setComponentAlignment(labelRole, Alignment.MIDDLE_LEFT); final OptionGroup roleOptionGroup = TableEmployee.createRoleOptionGroup(null); l1.addComponent(roleOptionGroup); layout.addComponent(l1); UserItem emptyItem = new UserItem(); emptyItem.setGroups(ImmutableSet.<String>of()); final CertificateBlock certificateBlock = new CertificateBlock(emptyItem); layout.addComponent(certificateBlock); final ExecutorGroupsBlock executorGroupsBlock = new ExecutorGroupsBlock(emptyItem); layout.addComponent(executorGroupsBlock); final HorizontalLayout supervisorGroupsEmp = new HorizontalLayout(); supervisorGroupsEmp.setMargin(true, true, true, false); supervisorGroupsEmp.setSpacing(true); supervisorGroupsEmp.setCaption( "? ? ? ?"); final FilterTable allSupervisorGroupsEmp = new FilterTable(); allSupervisorGroupsEmp.setCaption("?"); TableEmployee.table(supervisorGroupsEmp, allSupervisorGroupsEmp); final FilterTable currentSupervisorGroupsEmp = new FilterTable(); currentSupervisorGroupsEmp.setCaption(""); TableEmployee.table(supervisorGroupsEmp, currentSupervisorGroupsEmp); for (String groupName : AdminServiceProvider.get().getEmpGroupNames()) { for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) { allSupervisorGroupsEmp.addItem(new Object[] { groupName, group.getTitle() }, groupName); } } TableEmployee.addListener(allSupervisorGroupsEmp, currentSupervisorGroupsEmp); TableEmployee.addListener(currentSupervisorGroupsEmp, allSupervisorGroupsEmp); layout.addComponent(supervisorGroupsEmp); final HorizontalLayout supervisorGroupsOrg = new HorizontalLayout(); supervisorGroupsOrg.setMargin(true, true, true, false); supervisorGroupsOrg.setSpacing(true); supervisorGroupsOrg.setCaption( "? ? ?"); final FilterTable allSupervisorGroupsOrg = new FilterTable(); allSupervisorGroupsOrg.setCaption("?"); TableEmployee.table(supervisorGroupsOrg, allSupervisorGroupsOrg); final FilterTable currentSupervisorGroupsOrg = new FilterTable(); currentSupervisorGroupsOrg.setCaption(""); TableEmployee.table(supervisorGroupsOrg, currentSupervisorGroupsOrg); for (String groupName : AdminServiceProvider.get().getOrgGroupNames()) { for (Group group : AdminServiceProvider.get().findGroupByName(groupName)) { allSupervisorGroupsOrg.addItem(new Object[] { groupName, group.getTitle() }, groupName); } } TableEmployee.addListener(allSupervisorGroupsOrg, currentSupervisorGroupsOrg); TableEmployee.addListener(currentSupervisorGroupsOrg, allSupervisorGroupsOrg); layout.addComponent(supervisorGroupsOrg); TableEmployee.setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp, supervisorGroupsOrg); roleOptionGroup.addListener(new Listener() { private static final long serialVersionUID = 1L; public void componentEvent(Event event) { TableEmployee.setRolesEnabled(roleOptionGroup, certificateBlock, executorGroupsBlock, supervisorGroupsEmp, supervisorGroupsOrg); } }); HorizontalLayout l2 = new HorizontalLayout(); Label labelPrint = new Label("? ?"); labelPrint.setWidth(widthColumn); l2.addComponent(labelPrint); l2.setComponentAlignment(labelPrint, Alignment.MIDDLE_LEFT); final CheckBox checkBoxPrint = new CheckBox(); checkBoxPrint.setDescription("? ?"); l2.addComponent(checkBoxPrint); layout.addComponent(l2); HorizontalLayout layoutButton = new HorizontalLayout(); layoutButton.setSpacing(true); Button buttonUserForm = new Button("", new Button.ClickListener() { private static final long serialVersionUID = -7193894183022375021L; public void buttonClick(ClickEvent event) { if (!fieldPassRepeat.isValid()) { return; } String snilsFieldValue = fieldSnils.getValue() == null ? "" : (String) fieldSnils.getValue(); String snilsValue = snilsFieldValue.replaceAll("\\D+", ""); Pattern snilsPattern = Pattern.compile("\\d{11}"); Matcher snilsMatcher = snilsPattern.matcher(snilsValue); if (!snilsFieldValue.isEmpty() && !snilsMatcher.matches()) { getWindow().showNotification("? ", Window.Notification.TYPE_ERROR_MESSAGE); return; } String loginUser = (String) fieldLogin.getValue(); if (!AdminServiceProvider.get().isUniqueSnils(loginUser, snilsValue)) { getWindow().showNotification(" ? ", Window.Notification.TYPE_ERROR_MESSAGE); return; } String password = (String) fieldPass.getValue(); String passwordRepeat = (String) fieldPassRepeat.getValue(); String fio = (String) fieldFIO.getValue(); Set<Role> roles = (Set) roleOptionGroup.getValue(); TreeSet<String> groupExecutor = executorGroupsBlock.getGroups(); TreeSet<String> groupSupervisorEmp = new TreeSet<String>( (Collection<String>) currentSupervisorGroupsEmp.getItemIds()); TreeSet<String> groupSupervisorOrg = new TreeSet<String>( (Collection<String>) currentSupervisorGroupsOrg.getItemIds()); if (loginUser.equals("") || password.equals("") || passwordRepeat.equals("") || fio.equals("")) { getWindow().showNotification(" ? ?!", Notification.TYPE_WARNING_MESSAGE); } else if (!(password.equals(passwordRepeat))) { getWindow().showNotification(" ?!", Notification.TYPE_WARNING_MESSAGE); } else if (AdminServiceProvider.get().findEmployeeByLogin(loginUser) == null) { if (roles.contains(Role.SuperSupervisor)) { groupSupervisorEmp = new TreeSet<String>( AdminServiceProvider.get().selectGroupNamesBySocial(true)); groupSupervisorOrg = new TreeSet<String>( AdminServiceProvider.get().selectGroupNamesBySocial(false)); } String creator = getApplication().getUser().toString(); AdminServiceProvider.get().createEmployee(loginUser, password, fio, snilsValue, roles, creator, id, groupExecutor, groupSupervisorEmp, groupSupervisorOrg); showOrganization(id); getWindow().showNotification(" " + loginUser + " ?"); if (checkBoxPrint.booleanValue()) { // Create a window that contains what you want to print Window window = new Window(); window.addComponent(new Label("<h1>: " + loginUser + "</h1>\n" + "<h1>: " + password + "</h1>\n", Label.CONTENT_XHTML)); getApplication().addWindow(window); getWindow().open(new ExternalResource(window.getURL()), "_blank", 500, 200, // Width and // height Window.BORDER_NONE); window.executeJavaScript("print();"); window.executeJavaScript("self.close();"); } } else { getWindow().showNotification(" ?!", Notification.TYPE_WARNING_MESSAGE); } } }); layoutButton.addComponent(buttonUserForm); Button buttonCancel = new Button("", new Button.ClickListener() { private static final long serialVersionUID = 1L; public void buttonClick(ClickEvent event) { showOrganization(id); } }); layoutButton.addComponent(buttonCancel); layout.addComponent(layoutButton); } }); createUser.addListener(this); buttons.addComponent(createUser); return buttons; }
From source file:tad.grupo7.ccamistadeslargas.AmigosLayout.java
/** * Muestra una amistad en concreto./* w w w. ja v a2 s . c o m*/ * @param p Participante */ private void mostrarParticipante(Participante p) { //FORMULARIO POR SI SE QUIERE EDITAR EL PARTICIPANTE TextField nombre = new TextField("Nombre"); nombre.setValue(p.getNombre()); final Button eliminar = new Button("Eliminar Participante"); final Button actualizar = new Button("Actualizar Participante"); //BOTN PARA ACTUALIZAR EL PARTICIPANTE actualizar.addClickListener(clickEvent -> { if (ParticipanteDAO.read(nombre.getValue(), usuario.getId()) == null) { ParticipanteDAO.update(p.getId(), nombre.getValue()); UsuarioDAO.updateAmigo(nombre.getValue(), p.getId(), usuario.getId()); Notification n = new Notification("Amigo actualizado", Notification.Type.ASSISTIVE_NOTIFICATION); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); removeAllComponents(); mostrarAmistades(); } else { Notification n = new Notification("Ya existe un amigo con el mismo nombre", Notification.Type.WARNING_MESSAGE); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); } }); //BOTN PARA ELIMINAR EL PARTICIPANTE eliminar.addClickListener(clickEvent -> { ParticipanteDAO.delete(p.getId()); UsuarioDAO.removeAmigo(nombre.getValue(), usuario.getId()); removeAllComponents(); mostrarAmistades(); }); //AADIMOS LOS COMPONENTES FormLayout form = new FormLayout(nombre, actualizar, eliminar); VerticalLayout l = new VerticalLayout(form); l.setMargin(true); setSecondComponent(l); }
From source file:tad.grupo7.ccamistadeslargas.AmigosLayout.java
/** * Muestra el formulario para aadir una nueva amistad. *///w ww . j a v a2 s . c o m private void mostrarFormularioAddAmistad() { TextField nombre = new TextField("Nombre"); nombre.setRequired(true); final Button add = new Button("Crear Participante"); add.addStyleName(ValoTheme.BUTTON_PRIMARY); FormLayout form = new FormLayout(nombre, add); add.addClickListener(clickEvent -> { try { nombre.validate(); if (ParticipanteDAO.read(nombre.getValue(), usuario.getId()) == null) { ParticipanteDAO.create(nombre.getValue(), usuario.getId()); UsuarioDAO.addAmigo(nombre.getValue(), usuario.getId()); mostrarAmistades(); } else { Notification n = new Notification("Ya existe un amigo con el mismo nombre", Notification.Type.WARNING_MESSAGE); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); } } catch (Validator.InvalidValueException ex) { Notification n = new Notification("Error con los campos", Notification.Type.WARNING_MESSAGE); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); } }); form.setMargin(true); setSecondComponent(form); }
From source file:tad.grupo7.ccamistadeslargas.EventosLayout.java
/** * Se muestra el evento en el vertical layout derecho del splitpanel. * * @param e Recoge el evento que se quiere mostrar. *///w w w. j a v a 2 s . c o m private void mostrarEvento(Evento e) { removeAllComponents(); //T?TULO CssLayout labels = new CssLayout(); labels.addStyleName("labels"); Label l = new Label("Evento " + e.getNombre()); l.setSizeUndefined(); l.addStyleName(ValoTheme.LABEL_H2); l.addStyleName(ValoTheme.LABEL_COLORED); //FORMULARIO POR SI SE QUIERE EDITAR EL EVENTO TextField nombre = new TextField("Nombre"); nombre.setValue(e.getNombre()); nombre.setRequired(true); ComboBox divisa = new ComboBox("Divisa"); divisa.setNullSelectionAllowed(false); divisa.setRequired(true); divisa.addItem(""); divisa.addItem("$"); HorizontalLayout layouth = new HorizontalLayout(); HorizontalLayout layouth2 = new HorizontalLayout(); layouth.setSpacing(true); layouth2.setSpacing(true); final Button actualizar = new Button("Actualizar Evento"); final Button eliminar = new Button("Eliminar Evento"); final Button addPago = new Button("Aadir Pago"); final Button addParticipante = new Button("Aadir Participante"); layouth.addComponents(actualizar, eliminar); layouth2.addComponents(addPago, addParticipante); final Button hacerCuentas = new Button("Hacer las cuentas"); //BOTN PARA ACTUALIZAR EL EVENTO actualizar.addClickListener(clickEvent -> { try { nombre.validate(); divisa.validate(); if (EventoDAO.readDBObject(nombre.getValue(), usuario.getId()) == null) { EventoDAO.update(e.getId(), nombre.getValue(), divisa.getValue().toString()); Notification n = new Notification("Evento actualizado", Notification.Type.ASSISTIVE_NOTIFICATION); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); mostrarEventos(); } else { Notification n = new Notification("Ya existe un evento con ese nombre", Notification.Type.WARNING_MESSAGE); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); } } catch (Validator.InvalidValueException ex) { Notification n = new Notification("Error con los campos", Notification.Type.WARNING_MESSAGE); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); } }); //BOTN PARA QUE SALGA UNA VENTANA EMERGENTE PARA AADIR UN GASTO AL EVENTO addPago.addClickListener(clickEvent -> { mostrarFormularioAddGasto(e); }); //BOTN PARA ELIMINAR EL EVENTO eliminar.addClickListener(clickEvent -> { EventoDAO.delete(e.getId()); removeAllComponents(); mostrarEventos(); }); //BOTN PARA AADIR PARTICIPANTES addParticipante.addClickListener(clickEvent -> { mostrarFormularioAddParticipante(e); }); //BOTN PARA HACER LAS CUENTAS hacerCuentas.addClickListener(clickEvent -> { removeAllComponents(); VerticalLayout vl = new VerticalLayout(); Table tablaResumenPlusvalia = getTablaResumenPlusvalia(e); HorizontalLayout hl1 = new HorizontalLayout(tablaResumenPlusvalia); hl1.setMargin(true); hl1.setSpacing(true); vl.addComponent(hl1); for (Participante p : ParticipanteDAO.readAllFromEvento(e.getId())) { HorizontalLayout hl = new HorizontalLayout(getTablaResumenGastosPorPersona(e, p)); hl.setMargin(true); hl.setSpacing(true); vl.addComponent(hl); } setSplitPosition(100, Sizeable.UNITS_PERCENTAGE); setFirstComponent(vl); }); //TABLA CON TODOS LOS GASTOS DEL EVENTO Table tablaGastos = getTablaGastos(e); //TABLA CON TODOS LOS PARTICIPANTES DEL EVENTO Table tablaParticipantes = getTablaParticipantes(e); //AADIMOS LOS COMPONENTES FormLayout form = new FormLayout(nombre, divisa, layouth, layouth2, hacerCuentas); VerticalLayout vl = new VerticalLayout(l, form, tablaGastos, tablaParticipantes); vl.setMargin(true); setFirstComponent(vl); }
From source file:tad.grupo7.ccamistadeslargas.EventosLayout.java
/** * Se muestra un gasto para poder actualizarlo o eliminarlo. * * @param e Recoge el evento al que pertenece el gasto. *//*from w ww . j a va 2 s .co m*/ private void mostrarGasto(Gasto g, Evento e) { //T?TULO CssLayout labels = new CssLayout(); labels.addStyleName("labels"); Label l = new Label("Gasto " + g.getNombre()); l.setSizeUndefined(); l.addStyleName(ValoTheme.LABEL_H2); l.addStyleName(ValoTheme.LABEL_COLORED); //FORMULARIO POR SI SE QUIERE EDITAR EL GASTO TextField nombre = new TextField("Titulo"); nombre.setValue(g.getNombre()); nombre.setRequired(true); TextField precio = new TextField("Precio"); precio.setValue(g.getPrecio().toString()); precio.setRequired(true); final Button actualizar = new Button("Actualizar Gasto"); final Button eliminar = new Button("Eliminar Gasto"); //BOTN PARA ACTUALIZAR EL GASTO actualizar.addClickListener(clickEvent -> { try { nombre.validate(); precio.validate(); GastoDAO.update(g.getId(), nombre.getValue(), Double.valueOf(precio.getValue()), g.getIdEvento(), g.getIdPagador(), g.getDeudores()); Notification n = new Notification("Gasto actualizado", Notification.Type.ASSISTIVE_NOTIFICATION); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); setSecondComponent(null); mostrarEvento(e); } catch (Validator.InvalidValueException ex) { Notification n = new Notification("Error con los campos", Notification.Type.WARNING_MESSAGE); n.setPosition(Position.TOP_CENTER); n.show(Page.getCurrent()); } }); //BOTN PARA ELIMINAR EL GASTO eliminar.addClickListener(clickEvent -> { GastoDAO.delete(g.getId()); removeAllComponents(); mostrarEvento(e); }); //AADIMOS LOS COMPONENTES FormLayout form = new FormLayout(nombre, precio, actualizar, eliminar); VerticalLayout vl = new VerticalLayout(l, form); vl.setMargin(true); setSecondComponent(vl); }