/** * DOC bessaies Comment method "buildField". * * @param fieldPart * @param messagePart * @param configBean */ private Field<?> buildPasswordField( final LayoutContainer fieldPart, final LayoutContainer messagePart, Config config) { String key = config.labelKey; TextField<String> field = new TextField<String>(); field.setName(config.name()); field.setReadOnly( !(config.editable && userBean.getRole().getRights().contains(RightsConstants.CONFIG_MANAGMENT))); field.setPassword(true); buildField(config, I18nUtils.getString(key), field, fieldPart, messagePart); bindings.add(new FieldBinding<String>(field, config.name())); return field; }
public void addOtherComponent() { fieldSet = new FieldSet(); fieldSet.setHeading("Additional Information"); fieldSet.setCheckboxToggle(true); FormLayout layout = new FormLayout(); layout.setLabelWidth(150); layout.setPadding(10); fieldSet.setLayout(layout); passAdministrationUserRole = new TextField<String>(); passAdministrationUserRole.setAllowBlank(false); passAdministrationUserRole.setFieldLabel("Password Administration"); passAdministrationUserRole.setPassword(true); fieldSet.add(passAdministrationUserRole); repeatPassAdministrationUserRole = new TextField<String>(); repeatPassAdministrationUserRole.setAllowBlank(false); repeatPassAdministrationUserRole.setFieldLabel("Repeat Password"); repeatPassAdministrationUserRole.setPassword(true); repeatPassAdministrationUserRole.setValidator( new Validator<String, Field<String>>() { public String validate(Field<String> field, String value) { if (passAdministrationUserRole.getValue() != null) { if (!field.getValue().equalsIgnoreCase(passAdministrationUserRole.getValue())) return "Attention! The two passwords must match."; } return null; } }); fieldSet.add(repeatPassAdministrationUserRole); this.formPanel.add(fieldSet); }
private TabItem createRegisterTab() { TabItem tabItem = new TabItem("Register"); FormPanel form = new FormPanel(); form.setFrame(false); form.setHeading("Create a new account."); form.setWidth(350); form.setLayout(new FlowLayout()); FieldSet fieldSet = new FieldSet(); FormLayout layout = new FormLayout(); layout.setLabelWidth(75); fieldSet.setLayout(layout); final TextField<String> nameField = new TextField<String>(); nameField.setFieldLabel("Name"); fieldSet.add(nameField); final TextField<String> passField = new TextField<String>(); passField.setPassword(true); passField.setFieldLabel("Password"); fieldSet.add(passField); final TextField<String> emailField = new TextField<String>(); emailField.setFieldLabel("Email"); fieldSet.add(emailField); form.add(fieldSet); form.setButtonAlign(HorizontalAlignment.CENTER); Button registerButton = new Button("Register"); form.addButton(registerButton); registerButton.addListener( Events.Select, new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { String name = nameField.getValue(); String pass = passField.getValue(); String email = emailField.getValue(); if (name == null || pass == null || email == null) { Info.display( "Incorrect register data", "Name, password and email must not be empty!"); return; } userService.register( name, pass, email, new AsyncCallback<UserLoginRegisterResponse>() { // @Override public void onFailure(Throwable caught) { Info.display("Error while registering account!", caught.getMessage()); } // @Override public void onSuccess(UserLoginRegisterResponse result) { if (!result.isSuccess()) { Info.display("The account not registered!", result.getMessage()); } else { User user = result.getUser(); Info.display( "Registered :)", "Registered successfuly. You've been automaticly logged in as " + user.getName() + " level: " + user.getUserType()); hide(); tabs.init(user); } } }); } }); tabItem.add(form); return tabItem; }
private TabItem createLoginTab() { TabItem tabItem = new TabItem("Login"); FormPanel form = new FormPanel(); form.setHeading("Login using existing user."); form.setWidth(350); form.setLayout(new FlowLayout()); FieldSet fieldSet = new FieldSet(); FormLayout layout = new FormLayout(); layout.setLabelWidth(75); fieldSet.setLayout(layout); final TextField<String> fieldName = new TextField<String>(); fieldName.setFieldLabel("Name"); fieldSet.add(fieldName); final TextField<String> fieldPassword = new TextField<String>(); fieldPassword.setPassword(true); fieldPassword.setFieldLabel("Password"); fieldSet.add(fieldPassword); form.add(fieldSet); form.setButtonAlign(HorizontalAlignment.CENTER); Button loginButton = new Button("Login"); form.addButton(loginButton); loginButton.addListener( Events.Select, new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final String name = fieldName.getValue(); String pass = fieldPassword.getValue(); if (name == null || pass == null) { Info.display("Loggin in Error!", "Name or password is empty!"); return; } // Sprawdza usera userService.login( name, pass, new AsyncCallback<UserLoginRegisterResponse>() { public void onSuccess(UserLoginRegisterResponse result) { if (!result.isSuccess()) { Info.display("Couldn't log in", result.getMessage()); } else { User user = result.getUser(); Info.display( "Logged in", "Logged in successfuly as " + user.getName() + " level: " + user.getUserType()); hide(); tabs.init(user); } } public void onFailure(Throwable caught) { Info.display("Error while loggin in.", caught.getMessage()); }; }); } }); tabItem.add(form); return tabItem; }
private void createForm() { FormLayout layout = new FormLayout(); layout.setLabelAlign(LabelAlign.TOP); fp.setLayout(layout); fp.setFrame(false); fp.setHeaderVisible(false); fp.setAutoWidth(true); fp.setBodyBorder(true); fp.setButtonAlign(HorizontalAlignment.CENTER); eMail = new TextField<String>(); eMail.setFieldLabel("E-mail address"); // ID eMail.setValue("*****@*****.**"); eMail.setAllowBlank(false); eMail.setRegex("^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$"); fp.add(eMail); pass = new TextField<String>(); pass.setPassword(true); pass.setValue("pass"); pass.setFieldLabel("Password"); fp.add(pass); fp.addButton(loginButton); fp.addButton(newAccountButton); loginButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { ArrayList eventData = new ArrayList(); if (!eMail.isValid()) { eventData = new ArrayList(); eventData.add("e-mail is invalid!"); Dispatcher.get().dispatch(MainEvents.login, eventData); return; } else if (eMail.getValue() == null) { eventData = new ArrayList(); eventData.add("Please enter your e-mail address!"); Dispatcher.get().dispatch(MainEvents.login, eventData); return; } else if (pass.getValue() == null) { eventData = new ArrayList(); eventData.add("Please enter the password!"); Dispatcher.get().dispatch(MainEvents.login, eventData); return; } else service = (ServiceManagerWebServiceAsync) Registry.get("guiservice"); String email = eMail.getValue(); String password = pass.getValue(); service.loginUser( email, password, new AsyncCallback<ArrayList<Object>>() { public void onFailure(Throwable caught) { System.out.println("loginUser: error"); } public void onSuccess(ArrayList<Object> result) { System.out.println("loginUser: success; result.get(0) = \n" + result.get(0)); System.out.println("loginUser: session_id = \n" + result.get(1)); session_id = (String) result.get(1); ArrayList eventData = new ArrayList(); if (!result .get(0) .equals( "User/pass are wrong! Please correct input data or register an account")) { eventData.add("Please select the option"); eventData.add(result.get(0)); Dispatcher.get().dispatch(MainEvents.login, eventData); fp.remove(eMail); fp.remove(pass); fp.clear(); remove(fp); FormLayout layout = new FormLayout(); layout.setLabelAlign(LabelAlign.TOP); fp = new FormPanel(); fp.setLayout(layout); fp.setFrame(false); fp.setHeaderVisible(false); fp.setAutoWidth(true); fp.setBodyBorder(true); fp.setButtonAlign(HorizontalAlignment.CENTER); fp.addText((String) result.get(0)); fp.addButton(logoutButton); add(fp); } else { eventData.add("You need to log in"); eventData.add(result.get(0)); Dispatcher.get().dispatch(MainEvents.newAccount, eventData); } layout(true); } }); } }); logoutButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { fp.clear(); remove(fp); FormLayout layout = new FormLayout(); layout.setLabelAlign(LabelAlign.TOP); fp = new FormPanel(); fp.setLayout(layout); fp.setFrame(false); fp.setHeaderVisible(false); fp.setAutoWidth(true); fp.setBodyBorder(true); fp.setButtonAlign(HorizontalAlignment.CENTER); fp.add(eMail); fp.add(pass); fp.addButton(loginButton); fp.addButton(newAccountButton); add(fp); layout(true); ArrayList eventData = new ArrayList(); eventData.add("You are logged out!"); eventData.add("You are logged out, " + eMail.getValue() + "!"); Dispatcher.get().dispatch(MainEvents.logout, eventData); service.logoutUser( session_id, eMail.getValue(), new AsyncCallback<Boolean>() { public void onFailure(Throwable caught) { System.out.println("logoutUser: error"); } public void onSuccess(Boolean result) { System.out.println("logoutUser: success"); } }); } }); newAccountButton.addSelectionListener( new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { ArrayList eventData = new ArrayList(); eventData.add("Please select the option"); Dispatcher.get().dispatch(MainEvents.newAccount, eventData); } }); /* skipButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { ArrayList eventData = new ArrayList(); eventData.add("Please select the option"); Dispatcher.get().dispatch(MainEvents.login, eventData); } }); */ this.add(fp); }
/** * Remember user/pass implementation <a href= * "http://stackoverflow.com/questions/1245174/is-it-possible-to-implement-cross-browser-username-password-autocomplete-in-gxt" * >based in this</a> and <a href= * "http://www.sencha.com/forum/showthread.php?72027-Auto-complete-login-form" >this</a>. */ public SignInForm(final I18nTranslationService i18n) { final Listener<FieldEvent> enterListener = new Listener<FieldEvent>() { @Override public void handleEvent(final FieldEvent fe) { if (fe.getEvent().getKeyCode() == 13) { onAcceptCallback.onSuccess(); } } }; super.addStyleName("kune-Margin-Large-trbl"); loginNickOrEmailField = new TextField<String>() { @Override protected void onRender(final Element target, final int index) { if (el() == null) { setElement(Document.get().getElementById("usernamerender")); } super.onRender(target, index); } @Override protected void setAriaState(final String stateName, final String stateValue) {} }; loginNickOrEmailField.setFieldLabel(i18n.t("Username")); loginNickOrEmailField.setName(USER_FIELD_ID); loginNickOrEmailField.setWidth(DEF_SMALL_FIELD_WIDTH); loginNickOrEmailField.setAllowBlank(false); loginNickOrEmailField.setValidationDelay(3000); loginNickOrEmailField.setId(USER_FIELD_ID); loginNickOrEmailField.setTabIndex(100); loginNickOrEmailField.addStyleName("k-lower"); loginNickOrEmailField.render(RootPanel.get(LOGIN_ID).getElement()); ComponentHelper.doAttach(loginNickOrEmailField); super.add(loginNickOrEmailField); loginNickOrEmailField.addListener(Events.OnKeyPress, enterListener); loginPassField = new TextField<String>() { @Override protected void onRender(final Element target, final int index) { if (el() == null) { final String elementId = "passwordrender"; setElement(Document.get().getElementById(elementId)); } super.onRender(target, index); } @Override protected void setAriaState(final String stateName, final String stateValue) {} }; loginPassField.setFieldLabel(i18n.t("Password")); loginPassField.setName(PASSWORD_FIELD_ID); loginPassField.setWidth(DEF_MEDIUM_FIELD_WIDTH); loginPassField.setPassword(true); loginPassField.setAllowBlank(false); loginPassField.setValidationDelay(3000); loginPassField.setId(PASSWORD_FIELD_ID); loginPassField.setTabIndex(101); loginPassField.render(RootPanel.get(LOGIN_ID).getElement()); ComponentHelper.doAttach(loginPassField); loginPassField.addListener(Events.OnKeyPress, enterListener); super.add(loginPassField); }
private FormPanel setupUserLeftForm(String title, int tabIndex) { FormPanel formPanel = new FormPanel(); formPanel.setTitle(title); formPanel.setHeaderVisible(false); formPanel.setBodyBorder(false); formPanel.setWidth(400); // formPanel.setLabelAlign(LabelAlign.TOP); // default is LEFT formPanel.setLabelWidth(150); // Name fields FieldSet namefieldSet = new FieldSet(); namefieldSet.setHeading("Username"); namefieldSet.setCollapsible(true); namefieldSet.setBorders(false); FormLayout namelayout = new FormLayout(); namelayout.setLabelWidth(150); // namelayout.setDefaultWidth(180); // It is the real function to set the textField width. // Default width is 200 namefieldSet.setLayout(namelayout); userName = new TextField<String>(); userName.setFieldLabel("Username"); userName.setAllowBlank(false); // userName.setReadOnly(true); userName.disable(); userName.setTabIndex(tabIndex++); namefieldSet.add(userName); // Password fields FieldSet passwordfieldSet = new FieldSet(); passwordfieldSet.setHeading("Password"); passwordfieldSet.setCollapsible(true); passwordfieldSet.setBorders(false); FormLayout passwordlayout = new FormLayout(); passwordlayout.setLabelWidth(150); passwordfieldSet.setLayout(passwordlayout); password = new TextField<String>(); password.setFieldLabel("Current Password"); password.setAllowBlank(false); password.setPassword(true); password.setTabIndex(tabIndex++); passwordNew = new TextField<String>(); passwordNew.setFieldLabel("New Password"); passwordNew.setPassword(true); passwordNew.setTabIndex(tabIndex++); passwordConfirm = new TextField<String>(); passwordConfirm.setFieldLabel("Confirm Password"); passwordConfirm.setPassword(true); passwordConfirm.setTabIndex(tabIndex++); passwordHint = new TextField<String>(); passwordHint.setFieldLabel("Password Hint"); passwordHint.setTabIndex(tabIndex++); passwordfieldSet.add(password); passwordfieldSet.add(passwordNew); passwordfieldSet.add(passwordConfirm); passwordfieldSet.add(passwordHint); FieldSet userInfofieldSet = new FieldSet(); userInfofieldSet.setHeading("User Info"); userInfofieldSet.setCollapsible(true); userInfofieldSet.setBorders(false); FormLayout userInfolayout = new FormLayout(); userInfolayout.setLabelWidth(150); userInfofieldSet.setLayout(userInfolayout); firstName = new TextField<String>(); firstName.setFieldLabel("First Name"); firstName.setAllowBlank(false); // firstName.setLabelStyle("font-size:12px; margin-left: 20px"); firstName.setTabIndex(tabIndex++); lastName = new TextField<String>(); lastName.setFieldLabel("Last Name"); lastName.setAllowBlank(false); lastName.setTabIndex(tabIndex++); userInfofieldSet.add(firstName); userInfofieldSet.add(lastName); formPanel.add(namefieldSet); formPanel.add(passwordfieldSet); formPanel.add(userInfofieldSet); return formPanel; }
/** * 主窗口 */ void initmainpanel() { w = new BaseFormPanel(getStore()); w.setHeaderVisible(false); Label cardno_l = new Label("卡号:"); cardno_l.setWidth("50"); Label cname_l = new Label("名字:"); cname_l.setWidth("50"); Label sex_l = new Label("性别:"); sex_l.setWidth("50"); Label edu_l = new Label("学历:"); Label bird_l = new Label("出生日期:"); Label mobil_l = new Label("手机号:"); Label idno_l = new Label("身份证号:"); Label mark_l = new Label("备注:"); cardno_t = new TextField<String>(); cardno_t.setAllowBlank(false); cardno_t.addListener(Events.Change, this); cname_t = new TextField<String>(); cname_t.setAllowBlank(false); // passwordc_t.setAllowBlank(false); // password_t.setAllowBlank(false); // // TextField<String> sex_t = new TextField<String>(); // BaseGridEditor sex_t= CodeNameMapFactory.aa(); BaseComboBoxForm<BaseModelData> sex_t = CodeNameMapFactory.createSexInput_F(); TextField<String> edu_t = new TextField<String>(); // CodeNameMapFactory codenamemap = new CodeNameMapFactory(); // BaseGridEditor<String> edu_t =codenamemap.createSexInput_G(); // createBocdeInput_F DateField bird_t = new DateField(); bird_t.setAutoWidth(true); bird_t.getPropertyEditor().setFormat(DateTimeFormat.getFormat("yyyy-M-d H:mm:ss")); TextField<String> mobil_t = new TextField<String>(); mobil_t.setAllowBlank(false); TextField<String> idno_t = new TextField<String>(); TextArea mark_t = new TextArea(); mark_t.setSize(420, 40); // TextField<String> password_t = new TextField<String>(); password_t.setPassword(true); passwordc_t.setPassword(true); // password_t.setToolTip("将光标放到此处,并由会员录入自己的密码"); ccode_t = new TextField<String>(); // ccode_t.setEnabled(false); ccode_t.setVisible(false); icode_t = new TextField<String>(); icode_t.setVisible(false); cardno_t.setName("s_cardno"); cname_t.setName("cname"); password_t.setName("password"); sex_t.setName("s_sex"); edu_t.setName("s_edu"); bird_t.setName("s_birid"); mobil_t.setName("s_mobil"); idno_t.setName("s_idno"); mark_t.setName("s_mark"); ccode_t.setName("ccode"); icode_t.setName("icode"); // password_t.setName("password"); TableLayout tl = new TableLayout(4); tl.setWidth("600"); w.setLayout(tl); TableData td = new TableData(); td.setColspan(1); // td.setWidth("2000"); td.setMargin(100); td.setPadding(5); td.setRowspan(1); TableData td2 = new TableData(); td2.setColspan(3); // td.setWidth("2000"); td2.setMargin(100); td2.setPadding(5); td2.setRowspan(1); w.add(cardno_l, td); w.add(cardno_t, td); w.add(cname_l, td); w.add(cname_t, td); w.add(mobil_l, td); w.add(mobil_t, td); w.add(sex_l, td); w.add(sex_t, td); w.add(new Label("密码:"), td); w.add(password_t, td); w.add(new Label("重新录入密码:"), td); w.add(passwordc_t, td); w.add(edu_l, td); w.add(edu_t, td); w.add(bird_l, td); w.add(bird_t, td); w.add(idno_l, td); w.add(idno_t, td); w.add(new Label(""), td); w.add(new Label(""), td); w.add(mark_l, td); w.add(mark_t, td2); w.add(new Label("销售人员:"), td); BaseComboBoxForm<BaseModelData> cbf = createBcode_filter(); cbf.setName("rbcode"); cbf.setAllowBlank(false); w.add(cbf, td2); w.add(ccode_t, td); w.add(icode_t, td); w.setBottomComponent(addfinace); addfinace.addListener(Events.Select, this); addfinace.setEnabled(false); w.inited(); // w.setAutoHeight(true); // w.setAutoWidth(true); // w.setSize(661, 300); cardno_t.addListener(Events.Change, this); cname_t.addListener(Events.Change, this); // mobil_t.addListener(Events.Change, this); cardno_t.setValidateOnBlur(true); cname_t.setValidateOnBlur(true); }
public UserDialog(User pUser) { this.user = pUser; this.setHeading(textMessages.user()); this.setModal(true); this.setLayout(new AbsoluteLayout()); this.setSize("455", "475"); this.setResizable(false); LabelField lblfldUsername = new LabelField(textMessages.username_()); add(lblfldUsername, new AbsoluteData(6, 6)); usernameTextBox = new TextField<String>(); usernameTextBox.setReadOnly(user.getId() > 0); add(usernameTextBox, new AbsoluteData(144, 6)); usernameTextBox.setSize("271px", "22px"); LabelField lblfldFullName = new LabelField(textMessages.fullname_()); add(lblfldFullName, new AbsoluteData(6, 34)); fullnameTextBox = new TextField<String>(); add(fullnameTextBox, new AbsoluteData(144, 34)); fullnameTextBox.setSize("271px", "22px"); LabelField lblfldEmail = new LabelField(textMessages.email_()); add(lblfldEmail, new AbsoluteData(6, 62)); emailTextBox = new TextField<String>(); add(emailTextBox, new AbsoluteData(144, 62)); emailTextBox.setSize("271px", "22px"); LabelField lblfldPassword = new LabelField(textMessages.password_()); add(lblfldPassword, new AbsoluteData(6, 90)); password1TextBox = new TextField<String>(); password1TextBox.setPassword(true); add(password1TextBox, new AbsoluteData(144, 90)); password1TextBox.setSize("271px", "22px"); password2TextBox = new TextField<String>(); password2TextBox.setPassword(true); add(password2TextBox, new AbsoluteData(144, 118)); password2TextBox.setSize("271px", "22px"); enabledCheckBox = new CheckBox(); enabledCheckBox.setBoxLabel(textMessages.enabled()); add(enabledCheckBox, new AbsoluteData(144, 146)); enabledCheckBox.setSize("76px", "22px"); LabelField lblfldGroups = new LabelField(textMessages.groups_()); add(lblfldGroups, new AbsoluteData(6, 170)); LabelField lblfldAvailable = new LabelField(textMessages.available()); add(lblfldAvailable, new AbsoluteData(6, 195)); LabelField lblfldMembers = new LabelField(textMessages.memberOf()); add(lblfldMembers, new AbsoluteData(233, 195)); DualListField<GroupData> membersListBox = new DualListField<GroupData>(); add(membersListBox, new AbsoluteData(6, 216)); membersListBox.setSize("424px", "183px"); ListField<GroupData> from = membersListBox.getFromList(); ListField<GroupData> to = membersListBox.getToList(); from.setSize(300, 100); from.setDisplayField(Constants.NAME); fromGroupStore = new ListStore<GroupData>(); fromGroupStore.sort(Constants.NAME, SortDir.ASC); from.setStore(fromGroupStore); to.setDisplayField(Constants.NAME); to.setSize(300, 100); toGroupStore = new ListStore<GroupData>(); toGroupStore.sort(Constants.NAME, SortDir.ASC); to.setStore(toGroupStore); Button saveButton = new Button( textMessages.save(), new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { doSave(); } }); Button cancelButton = new Button( textMessages.cancel(), new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { doCancel(); } }); setButtonAlign(HorizontalAlignment.CENTER); addButton(saveButton); addButton(cancelButton); setFields(); }