Search in sources :

Example 1 with TextFieldValidator

use of org.eclipse.kapua.app.console.client.util.TextFieldValidator in project kapua by eclipse.

the class AccountForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    FormData formData = new FormData("-30");
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setBodyBorder(true);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setScrollMode(Scroll.AUTOY);
    m_formPanel.setLayout(new FlowLayout());
    // //////////////////////////////////////////
    // Account Information field set
    // //////////////////////////////////////////
    FieldSet fieldSet = new FieldSet();
    fieldSet.setHeading(MSGS.accountFormInformation());
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSet.setLayout(layoutAccount);
    // 
    // Show parent account name
    // 
    final LabelField parentAccountName = new LabelField();
    parentAccountName.setName("parentAccountName");
    parentAccountName.setFieldLabel(MSGS.accountFormParentAccount());
    parentAccountName.setLabelSeparator(":");
    fieldSet.add(parentAccountName, formData);
    // 
    // Account name field
    // 
    final LabelField accountNameLabel = new LabelField();
    accountNameLabel.setName("accountNameLabel");
    accountNameLabel.setFieldLabel(MSGS.accountFormName());
    accountNameLabel.setLabelSeparator(":");
    fieldSet.add(accountNameLabel, formData);
    final TextField<String> accountNameField = new TextField<String>();
    accountNameField.setAllowBlank(false);
    accountNameField.setName("accountName");
    accountNameField.setFieldLabel("* " + MSGS.accountFormName());
    accountNameField.setValidator(new TextFieldValidator(accountNameField, FieldType.SIMPLE_NAME));
    fieldSet.add(accountNameField, formData);
    // 
    // passwords
    // 
    final TextField<String> accountPassword = new TextField<String>();
    accountPassword.setAllowBlank(false);
    accountPassword.setName("accountPassword");
    accountPassword.setFieldLabel("* " + MSGS.accountFormPassword());
    accountPassword.setValidator(new TextFieldValidator(accountPassword, FieldType.PASSWORD));
    accountPassword.setPassword(true);
    fieldSet.add(accountPassword, formData);
    // 
    // Confirm password
    // 
    final TextField<String> confirmPassword = new TextField<String>();
    confirmPassword.setAllowBlank(false);
    confirmPassword.setName("confirmPassword");
    confirmPassword.setFieldLabel("* " + MSGS.accountFormConfirmPassword());
    confirmPassword.setValidator(new ConfirmPasswordFieldValidator(confirmPassword, accountPassword));
    confirmPassword.setPassword(true);
    fieldSet.add(confirmPassword, formData);
    m_formPanel.add(fieldSet);
    // //////////////////////////////////////////
    // Deployment Information field set
    // //////////////////////////////////////////
    FieldSet fieldSetDeployment = new FieldSet();
    fieldSetDeployment.setHeading(MSGS.accountFormDeploymentInformation());
    FormLayout layoutDeployment = new FormLayout();
    layoutDeployment.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSetDeployment.setLayout(layoutDeployment);
    // 
    // broker cluster
    // 
    final LabelField accountClusterLabel = new LabelField();
    accountClusterLabel.setName("accountBrokerLabel");
    accountClusterLabel.setFieldLabel(MSGS.accountFormBrokerCluster());
    accountClusterLabel.setLabelSeparator(":");
    fieldSetDeployment.add(accountClusterLabel, formData);
    final NumberField optlock = new NumberField();
    optlock.setName("optlock");
    optlock.setEditable(false);
    optlock.setVisible(false);
    fieldSetDeployment.add(optlock, formData);
    // add the field set and reset
    m_formPanel.add(fieldSetDeployment);
    // //////////////////////////////////////////
    // Organization Information field set
    // //////////////////////////////////////////
    FieldSet fieldSetOrg = new FieldSet();
    fieldSetOrg.setHeading(MSGS.accountFormOrgInformation());
    FormLayout layoutOrg = new FormLayout();
    layoutOrg.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSetOrg.setLayout(layoutOrg);
    // 
    // Organization name
    // 
    final TextField<String> organizationName = new TextField<String>();
    organizationName.setAllowBlank(false);
    organizationName.setName("organizationName");
    organizationName.setFieldLabel("* " + MSGS.accountFormOrgName());
    fieldSetOrg.add(organizationName, formData);
    // 
    // Organization email
    // 
    final TextField<String> organizationEmail = new TextField<String>();
    organizationEmail.setAllowBlank(false);
    organizationEmail.setName("organizationEmail");
    organizationEmail.setFieldLabel("* " + MSGS.accountFormOrgEmail());
    organizationEmail.setValidator(new TextFieldValidator(organizationEmail, FieldType.EMAIL));
    fieldSetOrg.add(organizationEmail, formData);
    // //////////////////////////////////////////
    // Organization Information sub field set
    // //////////////////////////////////////////
    FieldSet organizationSubFieldSet = new FieldSet();
    organizationSubFieldSet.setHeading(MSGS.accountFormOrgMoreInformation());
    organizationSubFieldSet.setBorders(false);
    organizationSubFieldSet.setCollapsible(true);
    organizationSubFieldSet.setWidth(515);
    FormLayout organizationSubLayout = new FormLayout();
    organizationSubLayout.setLabelWidth(LABEL_WIDTH_FORM - 11);
    organizationSubFieldSet.setLayout(organizationSubLayout);
    // 
    // Other organization data
    // 
    FormData subFieldsetFormData = new FormData("-7");
    final TextField<String> organizationPersonName = new TextField<String>();
    organizationPersonName.setName("organizationPersonName");
    organizationPersonName.setFieldLabel(MSGS.accountFormOrgPersonName());
    organizationSubFieldSet.add(organizationPersonName, subFieldsetFormData);
    final TextField<String> organizationPhoneNumber = new TextField<String>();
    organizationPhoneNumber.setName("organizationPhoneNumber");
    organizationPhoneNumber.setFieldLabel(MSGS.accountFormOrgPhoneNumber());
    organizationSubFieldSet.add(organizationPhoneNumber, subFieldsetFormData);
    final TextField<String> organizationAddressLine1 = new TextField<String>();
    organizationAddressLine1.setName("organizationAddressLine1");
    organizationAddressLine1.setFieldLabel(MSGS.accountFormOrgAddress1());
    organizationSubFieldSet.add(organizationAddressLine1, subFieldsetFormData);
    final TextField<String> organizationAddressLine2 = new TextField<String>();
    organizationAddressLine2.setName("organizationAddressLine2");
    organizationAddressLine2.setFieldLabel(MSGS.accountFormOrgAddress2());
    organizationSubFieldSet.add(organizationAddressLine2, subFieldsetFormData);
    final TextField<String> organizationZipPostCode = new TextField<String>();
    organizationZipPostCode.setName("organizationZipPostCode");
    organizationZipPostCode.setFieldLabel(MSGS.accountFormOrgZipPostCode());
    organizationSubFieldSet.add(organizationZipPostCode, subFieldsetFormData);
    final TextField<String> organizationCity = new TextField<String>();
    organizationCity.setName("organizationCity");
    organizationCity.setFieldLabel(MSGS.accountFormOrgCity());
    organizationSubFieldSet.add(organizationCity, subFieldsetFormData);
    final TextField<String> organizationStateProvinceCounty = new TextField<String>();
    organizationStateProvinceCounty.setName("organizationStateProvinceCounty");
    organizationStateProvinceCounty.setFieldLabel(MSGS.accountFormOrgState());
    organizationSubFieldSet.add(organizationStateProvinceCounty, subFieldsetFormData);
    final TextField<String> organizationCountry = new TextField<String>();
    organizationCountry.setName("organizationCountry");
    organizationCountry.setFieldLabel(MSGS.accountFormOrgCountry());
    organizationSubFieldSet.add(organizationCountry, subFieldsetFormData);
    // add the field set and reset
    fieldSetOrg.add(organizationSubFieldSet);
    m_formPanel.add(fieldSetOrg);
    // 
    if (m_existingAccount == null) {
        // Show editable name, password, confirm password
        accountNameLabel.setVisible(false);
        accountClusterLabel.setVisible(false);
    } else // 
    // If is an update of an existing account
    // 
    {
        // Show parent account name and account name
        accountNameField.setVisible(false);
        accountPassword.setVisible(false);
        confirmPassword.setVisible(false);
    }
    m_status = new Status();
    m_status.setBusy(MSGS.waitMsg());
    m_status.hide();
    m_status.setAutoWidth(true);
    m_formPanel.setButtonAlign(HorizontalAlignment.LEFT);
    m_formPanel.getButtonBar().add(m_status);
    m_formPanel.getButtonBar().add(new FillToolItem());
    // 
    // Behave of Submit Button
    // 
    m_formPanel.addButton(new Button(MSGS.submitButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            // make sure all visible fields are valid before performing the action
            for (Field<?> field : m_formPanel.getFields()) {
                if (field.isVisible() && !field.isValid()) {
                    MessageBox.alert(MSGS.error(), MSGS.formErrors(), null);
                    return;
                }
            }
            // 
            // Hold the dialog until the action comes back
            m_status.show();
            m_formPanel.getButtonBar().disable();
            // 
            if (m_existingAccount == null) {
                final GwtAccountCreator gwtAccountCreator = new GwtAccountCreator();
                gwtAccountCreator.setParentAccountId(m_currentSession.getSelectedAccount().getId());
                gwtAccountCreator.setAccountName(accountNameField.getValue());
                gwtAccountCreator.setAccountPassword(accountPassword.getValue());
                // Organization data
                gwtAccountCreator.setOrganizationName(organizationName.getValue());
                gwtAccountCreator.setOrganizationPersonName(organizationPersonName.getValue());
                gwtAccountCreator.setOrganizationEmail(organizationEmail.getValue());
                gwtAccountCreator.setOrganizationPhoneNumber(organizationPhoneNumber.getValue());
                gwtAccountCreator.setOrganizationAddressLine1(organizationAddressLine1.getValue());
                gwtAccountCreator.setOrganizationAddressLine2(organizationAddressLine2.getValue());
                gwtAccountCreator.setOrganizationCity(organizationCity.getValue());
                gwtAccountCreator.setOrganizationZipPostCode(organizationZipPostCode.getValue());
                gwtAccountCreator.setOrganizationStateProvinceCounty(organizationStateProvinceCounty.getValue());
                gwtAccountCreator.setOrganizationCountry(organizationCountry.getValue());
                // 
                // Call to create an account
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtAccountService.create(token, gwtAccountCreator, new AsyncCallback<GwtAccount>() {

                            public void onFailure(Throwable caught) {
                                FailureHandler.handleFormException(m_formPanel, caught);
                                m_status.hide();
                                m_formPanel.getButtonBar().enable();
                            }

                            public void onSuccess(GwtAccount account) {
                                ConsoleInfo.display(MSGS.info(), MSGS.accountCreatedConfirmation(account.getUnescapedName()));
                                m_newAccount = account;
                                // gwtAccountUtils.loadChildAccounts();
                                hide();
                            }
                        });
                    }
                });
            } else // 
            // Update the account
            // 
            {
                // Organization data
                GwtOrganization gwtOrganization = new GwtOrganization();
                gwtOrganization.setName(organizationName.getValue());
                gwtOrganization.setPersonName(organizationPersonName.getValue());
                gwtOrganization.setEmailAddress(organizationEmail.getValue());
                gwtOrganization.setPhoneNumber(organizationPhoneNumber.getValue());
                gwtOrganization.setAddressLine1(organizationAddressLine1.getValue());
                gwtOrganization.setAddressLine2(organizationAddressLine2.getValue());
                gwtOrganization.setZipPostCode(organizationZipPostCode.getValue());
                gwtOrganization.setCity(organizationCity.getValue());
                gwtOrganization.setStateProvinceCounty(organizationStateProvinceCounty.getValue());
                gwtOrganization.setCountry(organizationCountry.getValue());
                m_existingAccount.setGwtOrganization(gwtOrganization);
                // 
                // Call to update the account
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtAccountService.update(token, m_existingAccount, new AsyncCallback<GwtAccount>() {

                            public void onFailure(Throwable caught) {
                                FailureHandler.handleFormException(m_formPanel, caught);
                                m_status.hide();
                                m_formPanel.getButtonBar().enable();
                            }

                            public void onSuccess(GwtAccount account) {
                                ConsoleInfo.display(MSGS.info(), MSGS.accountUpdatedConfirmation(account.getUnescapedName()));
                                m_existingAccount = account;
                                hide();
                            }
                        });
                    }
                });
            }
        }
    }));
    // 
    // Cancel Button
    // 
    m_formPanel.addButton(new Button(MSGS.cancelButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            hide();
        }
    }));
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    // 
    // Populate field if necessary
    // 
    parentAccountName.setValue(m_currentSession.getSelectedAccount().getName());
    if (m_existingAccount != null) {
        gwtAccountService.find(m_existingAccount.getId(), new AsyncCallback<GwtAccount>() {

            public void onFailure(Throwable caught) {
                FailureHandler.handle(caught);
            }

            public void onSuccess(GwtAccount account) {
                // set value and original value as we want to track the Dirty state
                accountNameLabel.setValue(account.getName());
                accountNameField.setValue(account.getName());
                accountNameField.setOriginalValue(account.getName());
                accountClusterLabel.setValue(account.getBrokerURL());
                organizationName.setValue(account.getGwtOrganization().getName());
                organizationName.setOriginalValue(account.getGwtOrganization().getName());
                organizationPersonName.setValue(account.getGwtOrganization().getPersonName());
                organizationPersonName.setOriginalValue(account.getGwtOrganization().getPersonName());
                organizationEmail.setValue(account.getGwtOrganization().getEmailAddress());
                organizationEmail.setOriginalValue(account.getGwtOrganization().getEmailAddress());
                organizationPhoneNumber.setValue(account.getGwtOrganization().getPhoneNumber());
                organizationPhoneNumber.setOriginalValue(account.getGwtOrganization().getPhoneNumber());
                organizationAddressLine1.setValue(account.getGwtOrganization().getAddressLine1());
                organizationAddressLine1.setOriginalValue(account.getGwtOrganization().getAddressLine1());
                organizationAddressLine2.setValue(account.getGwtOrganization().getAddressLine2());
                organizationAddressLine2.setOriginalValue(account.getGwtOrganization().getAddressLine2());
                organizationZipPostCode.setValue(account.getGwtOrganization().getZipPostCode());
                organizationZipPostCode.setOriginalValue(account.getGwtOrganization().getZipPostCode());
                organizationCity.setValue(account.getGwtOrganization().getCity());
                organizationCity.setOriginalValue(account.getGwtOrganization().getCity());
                organizationStateProvinceCounty.setValue(account.getGwtOrganization().getStateProvinceCounty());
                organizationStateProvinceCounty.setOriginalValue(account.getGwtOrganization().getStateProvinceCounty());
                organizationCountry.setValue(account.getGwtOrganization().getCountry());
                organizationCountry.setOriginalValue(account.getGwtOrganization().getCountry());
                optlock.setValue(account.getOptlock());
            }
        });
    }
    add(m_formPanel);
}
Also used : FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) Button(com.extjs.gxt.ui.client.widget.button.Button) GwtOrganization(org.eclipse.kapua.app.console.shared.model.GwtOrganization) ConfirmPasswordFieldValidator(org.eclipse.kapua.app.console.client.util.ConfirmPasswordFieldValidator) TextField(com.extjs.gxt.ui.client.widget.form.TextField) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) Status(com.extjs.gxt.ui.client.widget.Status) GwtAccount(org.eclipse.kapua.app.console.shared.model.GwtAccount) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) GwtAccountCreator(org.eclipse.kapua.app.console.shared.model.GwtAccountCreator) TextFieldValidator(org.eclipse.kapua.app.console.client.util.TextFieldValidator) FillToolItem(com.extjs.gxt.ui.client.widget.toolbar.FillToolItem) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Example 2 with TextFieldValidator

use of org.eclipse.kapua.app.console.client.util.TextFieldValidator in project kapua by eclipse.

the class DeviceForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    FormData formData = new FormData("-20");
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setWidth(310);
    m_formPanel.setScrollMode(Scroll.AUTOY);
    m_formPanel.setStyleAttribute("padding-bottom", "0px");
    m_formPanel.setLayout(new FlowLayout());
    // Device general info fieldset
    FieldSet fieldSet = new FieldSet();
    FormLayout layout = new FormLayout();
    layout.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
    fieldSet.setLayout(layout);
    fieldSet.setHeading(MSGS.deviceFormFieldsetGeneralInfo());
    // Device Client ID
    clientIdLabel = new LabelField();
    clientIdLabel.setFieldLabel(MSGS.deviceFormClientID());
    clientIdLabel.setLabelSeparator(":");
    clientIdLabel.setWidth(225);
    fieldSet.add(clientIdLabel, formData);
    clientIdField = new TextField<String>();
    clientIdField.setAllowBlank(false);
    clientIdField.setName("clientID");
    clientIdField.setFieldLabel(MSGS.deviceFormClientID());
    clientIdField.setValidator(new TextFieldValidator(clientIdField, FieldType.DEVICE_CLIENT_ID));
    clientIdField.setWidth(225);
    fieldSet.add(clientIdField, formData);
    // Display name
    displayNameField = new TextField<String>();
    displayNameField.setAllowBlank(true);
    displayNameField.setName("displayName");
    displayNameField.setFieldLabel(MSGS.deviceFormDisplayName());
    displayNameField.setWidth(225);
    fieldSet.add(displayNameField, formData);
    // Device Status
    statusCombo = new SimpleComboBox<GwtDeviceQueryPredicates.GwtDeviceStatus>();
    statusCombo.setName("status");
    statusCombo.setFieldLabel(MSGS.deviceFormStatus());
    statusCombo.setEditable(false);
    statusCombo.setTriggerAction(TriggerAction.ALL);
    statusCombo.setEmptyText(MSGS.deviceFilteringPanelStatusEmptyText());
    statusCombo.add(GwtDeviceQueryPredicates.GwtDeviceStatus.ENABLED);
    statusCombo.add(GwtDeviceQueryPredicates.GwtDeviceStatus.DISABLED);
    fieldSet.add(statusCombo, formData);
    // Tag fieldset
    FieldSet fieldSetTags = new FieldSet();
    FormLayout layoutTags = new FormLayout();
    layoutTags.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
    fieldSetTags.setLayout(layoutTags);
    fieldSetTags.setHeading(MSGS.deviceFormFieldsetTags());
    ContentPanel panel = new ContentPanel();
    panel.setBorders(false);
    panel.setBodyBorder(false);
    panel.setHeaderVisible(false);
    panel.setLayout(new RowLayout(Orientation.HORIZONTAL));
    panel.setBodyStyle("background-color:transparent");
    panel.setHeight(35);
    // Device Custom attributes fieldset
    FormLayout layoutSecurityOptions = new FormLayout();
    layoutSecurityOptions.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
    FieldSet fieldSetSecurityOptions = new FieldSet();
    fieldSetSecurityOptions.setLayout(layoutSecurityOptions);
    fieldSetSecurityOptions.setHeading(MSGS.deviceFormFieldsetSecurityOptions());
    // Provisioned Credentials Tight
    credentialsTightCombo = new SimpleComboBox<String>();
    credentialsTightCombo.setName("provisionedCredentialsTight");
    credentialsTightCombo.setEditable(false);
    credentialsTightCombo.setTypeAhead(false);
    credentialsTightCombo.setAllowBlank(false);
    credentialsTightCombo.setFieldLabel(MSGS.deviceFormProvisionedCredentialsTight());
    credentialsTightCombo.setToolTip(MSGS.deviceFormProvisionedCredentialsTightTooltip());
    credentialsTightCombo.setTriggerAction(TriggerAction.ALL);
    fieldSetSecurityOptions.add(credentialsTightCombo, formData);
    credentialsTightCombo.add(GwtDeviceCredentialsTight.INHERITED.getLabel());
    credentialsTightCombo.add(GwtDeviceCredentialsTight.LOOSE.getLabel());
    credentialsTightCombo.add(GwtDeviceCredentialsTight.STRICT.getLabel());
    credentialsTightCombo.setSimpleValue(GwtDeviceCredentialsTight.INHERITED.getLabel());
    // Device User
    RpcProxy<ListLoadResult<GwtUser>> deviceUserProxy = new RpcProxy<ListLoadResult<GwtUser>>() {

        @Override
        protected void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtUser>> callback) {
            gwtUserService.findAll(m_currentSession.getSelectedAccount().getId(), callback);
        }
    };
    BaseListLoader<ListLoadResult<GwtUser>> deviceUserLoader = new BaseListLoader<ListLoadResult<GwtUser>>(deviceUserProxy);
    ListStore<GwtUser> deviceUserStore = new ListStore<GwtUser>(deviceUserLoader);
    deviceUserCombo = new ComboBox<GwtUser>();
    deviceUserCombo.setName("deviceUserCombo");
    deviceUserCombo.setEditable(false);
    deviceUserCombo.setTypeAhead(false);
    deviceUserCombo.setAllowBlank(false);
    deviceUserCombo.setFieldLabel(MSGS.deviceFormDeviceUser());
    deviceUserCombo.setTriggerAction(TriggerAction.ALL);
    deviceUserCombo.setStore(deviceUserStore);
    deviceUserCombo.setDisplayField("username");
    deviceUserCombo.setValueField("id");
    fieldSetSecurityOptions.add(deviceUserCombo, formData);
    // Allow credential change
    allowCredentialsChangeCheckbox = new CheckBox();
    allowCredentialsChangeCheckbox.setName("allowNewUnprovisionedDevicesCheckbox");
    allowCredentialsChangeCheckbox.setFieldLabel(MSGS.deviceFormAllowCredentialsChange());
    allowCredentialsChangeCheckbox.setToolTip(MSGS.deviceFormAllowCredentialsChangeTooltip());
    allowCredentialsChangeCheckbox.setBoxLabel("");
    fieldSetSecurityOptions.add(allowCredentialsChangeCheckbox, formData);
    // Device Custom attributes fieldset
    FieldSet fieldSetCustomAttributes = new FieldSet();
    FormLayout layoutCustomAttributes = new FormLayout();
    layoutCustomAttributes.setLabelWidth(Constants.LABEL_WIDTH_DEVICE_FORM);
    fieldSetCustomAttributes.setLayout(layoutCustomAttributes);
    fieldSetCustomAttributes.setHeading(MSGS.deviceFormFieldsetCustomAttributes());
    // Custom Attribute #1
    customAttribute1Field = new TextField<String>();
    customAttribute1Field.setName("customAttribute1");
    customAttribute1Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute1());
    customAttribute1Field.setWidth(225);
    fieldSetCustomAttributes.add(customAttribute1Field, formData);
    // Custom Attribute #2
    customAttribute2Field = new TextField<String>();
    customAttribute2Field.setName("customAttribute2");
    customAttribute2Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute2());
    customAttribute2Field.setWidth(225);
    fieldSetCustomAttributes.add(customAttribute2Field, formData);
    // Custom Attribute #3
    customAttribute3Field = new TextField<String>();
    customAttribute3Field.setName("customAttribute3");
    customAttribute3Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute3());
    customAttribute3Field.setWidth(225);
    fieldSetCustomAttributes.add(customAttribute3Field, formData);
    // Custom Attribute #4
    customAttribute4Field = new TextField<String>();
    customAttribute4Field.setName("customAttribute4");
    customAttribute4Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute4());
    customAttribute4Field.setWidth(225);
    fieldSetCustomAttributes.add(customAttribute4Field, formData);
    // Custom Attribute #5
    customAttribute5Field = new TextField<String>();
    customAttribute5Field.setName("customAttribute5");
    customAttribute5Field.setFieldLabel("* " + MSGS.deviceFormCustomAttribute5());
    customAttribute5Field.setWidth(225);
    fieldSetCustomAttributes.add(customAttribute5Field, formData);
    // Optlock
    optlock = new NumberField();
    optlock.setName("optlock");
    optlock.setEditable(false);
    optlock.setVisible(false);
    fieldSet.add(optlock, formData);
    m_formPanel.add(fieldSet);
    m_formPanel.add(fieldSetTags);
    m_formPanel.add(fieldSetSecurityOptions);
    m_formPanel.add(fieldSetCustomAttributes);
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    Button submitButton = new Button(MSGS.deviceFormSubmitButton());
    submitButton.addListener(Events.OnClick, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            // make sure all visible fields are valid before performing the action
            for (Field<?> field : m_formPanel.getFields()) {
                if (field.isVisible() && !field.isValid()) {
                    MessageBox.alert(MSGS.error(), MSGS.formErrors(), null);
                    return;
                }
            }
            if (m_selectedDevice == null) {
                final GwtDeviceCreator gwtDeviceCreator = new GwtDeviceCreator();
                gwtDeviceCreator.setScopeId(m_currentSession.getSelectedAccount().getId());
                gwtDeviceCreator.setClientId(clientIdField.getValue());
                gwtDeviceCreator.setDisplayName(displayNameField.getValue());
                // Security Options
                gwtDeviceCreator.setGwtCredentialsTight(credentialsTightCombo.getSimpleValue());
                gwtDeviceCreator.setGwtPreferredUserId(deviceUserCombo.getValue().getId());
                // Custom attributes
                gwtDeviceCreator.setCustomAttribute1(unescapeValue(customAttribute1Field.getValue()));
                gwtDeviceCreator.setCustomAttribute2(unescapeValue(customAttribute2Field.getValue()));
                gwtDeviceCreator.setCustomAttribute3(unescapeValue(customAttribute3Field.getValue()));
                gwtDeviceCreator.setCustomAttribute4(unescapeValue(customAttribute4Field.getValue()));
                gwtDeviceCreator.setCustomAttribute5(unescapeValue(customAttribute5Field.getValue()));
                // 
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtDeviceService.createDevice(token, gwtDeviceCreator, new AsyncCallback<GwtDevice>() {

                            @Override
                            public void onFailure(Throwable caught) {
                                FailureHandler.handle(caught);
                            }

                            public void onSuccess(final GwtDevice gwtDevice) {
                                // 
                                // Getting XSRF token
                                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                                    @Override
                                    public void onFailure(Throwable ex) {
                                        FailureHandler.handle(ex);
                                    }

                                    @Override
                                    public void onSuccess(GwtXSRFToken token) {
                                        hide();
                                        ConsoleInfo.display(MSGS.info(), MSGS.deviceUpdateSuccess());
                                    }
                                });
                            }
                        });
                    }
                });
            } else // Edit
            {
                // General info
                m_selectedDevice.setDisplayName(unescapeValue(displayNameField.getValue()));
                m_selectedDevice.setGwtDeviceStatus(statusCombo.getSimpleValue().name());
                // Security Options
                m_selectedDevice.setCredentialsTight(GwtDeviceCredentialsTight.getEnumFromLabel(credentialsTightCombo.getSimpleValue()).name());
                m_selectedDevice.setCredentialsAllowChange(allowCredentialsChangeCheckbox.getValue());
                m_selectedDevice.setDeviceUserId(deviceUserCombo.getValue().getId());
                // Custom attributes
                m_selectedDevice.setCustomAttribute1(unescapeValue(customAttribute1Field.getValue()));
                m_selectedDevice.setCustomAttribute2(unescapeValue(customAttribute2Field.getValue()));
                m_selectedDevice.setCustomAttribute3(unescapeValue(customAttribute3Field.getValue()));
                m_selectedDevice.setCustomAttribute4(unescapeValue(customAttribute4Field.getValue()));
                m_selectedDevice.setCustomAttribute5(unescapeValue(customAttribute5Field.getValue()));
                // Optlock
                m_selectedDevice.setOptlock(optlock.getValue().intValue());
                // 
                // Getting XSRF token
                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                    @Override
                    public void onFailure(Throwable ex) {
                        FailureHandler.handle(ex);
                    }

                    @Override
                    public void onSuccess(GwtXSRFToken token) {
                        gwtDeviceService.updateAttributes(token, m_selectedDevice, new AsyncCallback<GwtDevice>() {

                            public void onFailure(Throwable caught) {
                                FailureHandler.handle(caught);
                            }

                            public void onSuccess(GwtDevice gwtDevice) {
                                // 
                                // Getting XSRF token
                                gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                                    @Override
                                    public void onFailure(Throwable ex) {
                                        FailureHandler.handle(ex);
                                    }

                                    @Override
                                    public void onSuccess(GwtXSRFToken token) {
                                        hide();
                                        ConsoleInfo.display(MSGS.info(), m_selectedDevice == null ? MSGS.deviceCreationSuccess() : MSGS.deviceUpdateSuccess());
                                    }
                                });
                            }
                        });
                    }
                });
            }
        }
    });
    Button cancelButton = new Button(MSGS.deviceFormCancelButton());
    cancelButton.addListener(Events.OnClick, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            hide();
        }
    });
    m_formPanel.addButton(submitButton);
    m_formPanel.addButton(cancelButton);
    add(m_formPanel);
    // Hide components according to NEW/EDIT mode
    makeNewEditAppearance();
    // Populate fields if we are in EDIT mode
    if (m_selectedDevice != null) {
        populateFields();
    }
}
Also used : FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) GwtDeviceCreator(org.eclipse.kapua.app.console.shared.model.GwtDeviceCreator) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) BaseListLoader(com.extjs.gxt.ui.client.data.BaseListLoader) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListStore(com.extjs.gxt.ui.client.store.ListStore) Field(com.extjs.gxt.ui.client.widget.form.Field) TextField(com.extjs.gxt.ui.client.widget.form.TextField) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) GwtDevice(org.eclipse.kapua.app.console.shared.model.GwtDevice) Button(com.extjs.gxt.ui.client.widget.button.Button) RowLayout(com.extjs.gxt.ui.client.widget.layout.RowLayout) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) CheckBox(com.extjs.gxt.ui.client.widget.form.CheckBox) GwtUser(org.eclipse.kapua.app.console.shared.model.GwtUser) TextFieldValidator(org.eclipse.kapua.app.console.client.util.TextFieldValidator)

Example 3 with TextFieldValidator

use of org.eclipse.kapua.app.console.client.util.TextFieldValidator in project kapua by eclipse.

the class UserForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    FormData formData = new FormData("0");
    // Create separate tabs
    m_tabsPanel = new TabPanel();
    m_tabsPanel.setPlain(true);
    m_tabsPanel.setBorders(false);
    m_tabsPanel.setBodyBorder(false);
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setBorders(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setLayout(new FitLayout());
    m_formPanel.setPadding(0);
    m_formPanel.add(m_tabsPanel);
    // 
    // User info tab
    // 
    FieldSet infoFieldSet = new FieldSet();
    infoFieldSet.setHeading(MSGS.userFormInfo());
    infoFieldSet.setBorders(true);
    infoFieldSet.setStyleAttribute("margin", "0px 10px 0px 10px");
    FormLayout layout = new FormLayout();
    layout.setLabelWidth(Constants.LABEL_WIDTH_FORM);
    infoFieldSet.setLayout(layout);
    username = new TextField<String>();
    username.setAllowBlank(false);
    username.setName("userName");
    username.setFieldLabel("* " + MSGS.userFormName());
    username.setValidator(new TextFieldValidator(username, FieldType.NAME));
    infoFieldSet.add(username, formData);
    password = new TextField<String>();
    password.setAllowBlank(false);
    password.setName("password");
    password.setFieldLabel("* " + MSGS.userFormPassword());
    password.setValidator(new PasswordFieldValidator(password));
    password.setPassword(true);
    infoFieldSet.add(password, formData);
    confirmPassword = new TextField<String>();
    confirmPassword.setAllowBlank(false);
    confirmPassword.setName("confirmPassword");
    confirmPassword.setFieldLabel("* " + MSGS.userFormConfirmPassword());
    confirmPassword.setValidator(new ConfirmPasswordFieldValidator(confirmPassword, password));
    confirmPassword.setPassword(true);
    infoFieldSet.add(confirmPassword, formData);
    LabelField tooltip = new LabelField();
    tooltip.setValue(MSGS.userFormPasswordTooltip());
    tooltip.setStyleAttribute("margin-top", "-5px");
    tooltip.setStyleAttribute("color", "gray");
    tooltip.setStyleAttribute("font-size", "10px");
    infoFieldSet.add(tooltip, formData);
    displayName = new TextField<String>();
    displayName.setName("displayName");
    displayName.setFieldLabel(MSGS.userFormDisplayName());
    infoFieldSet.add(displayName, formData);
    email = new TextField<String>();
    email.setName("userEmail");
    email.setFieldLabel(MSGS.userFormEmail());
    email.setValidator(new TextFieldValidator(email, FieldType.EMAIL));
    infoFieldSet.add(email, formData);
    phoneNumber = new TextField<String>();
    phoneNumber.setName("phoneNumber");
    phoneNumber.setFieldLabel(MSGS.userFormPhoneNumber());
    infoFieldSet.add(phoneNumber, formData);
    optlock = new NumberField();
    optlock.setName("optlock");
    optlock.setEditable(false);
    optlock.setVisible(false);
    infoFieldSet.add(optlock, formData);
    // status field set
    FormLayout userLayout = new FormLayout();
    userLayout.setLabelWidth(Constants.LABEL_WIDTH_FORM);
    statusFieldSet = new FieldSet();
    statusFieldSet.setBorders(true);
    statusFieldSet.setStyleAttribute("margin", "5px 10px 0px 10px");
    statusFieldSet.setHeading(MSGS.userFormStatus());
    statusFieldSet.setLayout(userLayout);
    statusCombo = new SimpleComboBox<String>();
    statusCombo.setName("comboStatus");
    statusCombo.setFieldLabel(MSGS.userFormStatus());
    statusCombo.setLabelSeparator(":");
    statusCombo.setEditable(false);
    statusCombo.setTypeAhead(true);
    statusCombo.setTriggerAction(TriggerAction.ALL);
    // show account status combo box
    for (GwtUserStatus status : GwtUserStatus.values()) {
        statusCombo.add(MessageUtils.get(status.name()));
    }
    statusCombo.setSimpleValue(MessageUtils.get(GwtUserStatus.ENABLED.name()));
    statusFieldSet.add(statusCombo, formData);
    m_tabUserInfo = new TabItem(MSGS.userFormInformation());
    m_tabUserInfo.setBorders(false);
    m_tabUserInfo.setStyleAttribute("background-color", "#E8E8E8");
    m_tabUserInfo.setScrollMode(Scroll.AUTOY);
    m_tabUserInfo.add(infoFieldSet);
    m_tabUserInfo.add(statusFieldSet);
    m_tabsPanel.add(m_tabUserInfo);
    // button bar
    m_status = new Status();
    m_status.setBusy(MSGS.waitMsg());
    m_status.hide();
    m_status.setAutoWidth(true);
    submitButton = new Button(MSGS.submitButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (!m_formPanel.isValid()) {
                return;
            }
            // Hold the dialog until the action comes back
            m_status.show();
            m_formPanel.getButtonBar().disable();
            submitAccount();
        }
    });
    Button cancelButton = new Button(MSGS.cancelButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            hide();
        }
    });
    m_formPanel.getButtonBar().add(m_status);
    m_formPanel.getButtonBar().add(new FillToolItem());
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    m_formPanel.addButton(submitButton);
    m_formPanel.addButton(cancelButton);
    loadUser();
    add(m_formPanel);
    setEditability();
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) TabPanel(com.extjs.gxt.ui.client.widget.TabPanel) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) GwtUserStatus(org.eclipse.kapua.app.console.shared.model.GwtUser.GwtUserStatus) Status(com.extjs.gxt.ui.client.widget.Status) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) TabItem(com.extjs.gxt.ui.client.widget.TabItem) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) Button(com.extjs.gxt.ui.client.widget.button.Button) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) ConfirmPasswordFieldValidator(org.eclipse.kapua.app.console.client.util.ConfirmPasswordFieldValidator) TextFieldValidator(org.eclipse.kapua.app.console.client.util.TextFieldValidator) GwtUserStatus(org.eclipse.kapua.app.console.shared.model.GwtUser.GwtUserStatus) ConfirmPasswordFieldValidator(org.eclipse.kapua.app.console.client.util.ConfirmPasswordFieldValidator) PasswordFieldValidator(org.eclipse.kapua.app.console.client.util.PasswordFieldValidator) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FillToolItem(com.extjs.gxt.ui.client.widget.toolbar.FillToolItem) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Aggregations

Button (com.extjs.gxt.ui.client.widget.button.Button)3 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)3 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)3 LabelField (com.extjs.gxt.ui.client.widget.form.LabelField)3 NumberField (com.extjs.gxt.ui.client.widget.form.NumberField)3 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)3 FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)3 TextFieldValidator (org.eclipse.kapua.app.console.client.util.TextFieldValidator)3 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)2 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)2 Status (com.extjs.gxt.ui.client.widget.Status)2 TextField (com.extjs.gxt.ui.client.widget.form.TextField)2 FlowLayout (com.extjs.gxt.ui.client.widget.layout.FlowLayout)2 FillToolItem (com.extjs.gxt.ui.client.widget.toolbar.FillToolItem)2 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)2 ConfirmPasswordFieldValidator (org.eclipse.kapua.app.console.client.util.ConfirmPasswordFieldValidator)2 GwtXSRFToken (org.eclipse.kapua.app.console.shared.model.GwtXSRFToken)2 BaseListLoader (com.extjs.gxt.ui.client.data.BaseListLoader)1 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1