Search in sources :

Example 56 with FormLayout

use of com.extjs.gxt.ui.client.widget.layout.FormLayout 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 57 with FormLayout

use of com.extjs.gxt.ui.client.widget.layout.FormLayout in project kapua by eclipse.

the class DeviceTabCommand method initCommandInput.

private void initCommandInput() {
    FormData formData = new FormData("-20");
    FormLayout layout = new FormLayout();
    layout.setLabelWidth(Constants.LABEL_WIDTH_FORM);
    FieldSet fieldSet = new FieldSet();
    fieldSet.setBorders(false);
    fieldSet.setLayout(layout);
    fieldSet.setStyleAttribute("margin", "0px");
    fieldSet.setStyleAttribute("padding", "0px");
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(true);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setBorders(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setAction(SERVLET_URL);
    m_formPanel.setEncoding(Encoding.MULTIPART);
    m_formPanel.setMethod(Method.POST);
    m_formPanel.add(fieldSet);
    m_formPanel.addListener(Events.Render, new Listener<BaseEvent>() {

        public void handleEvent(BaseEvent be) {
            NodeList<com.google.gwt.dom.client.Element> nl = m_formPanel.getElement().getElementsByTagName("form");
            if (nl.getLength() > 0) {
                com.google.gwt.dom.client.Element elemForm = nl.getItem(0);
                elemForm.setAttribute("autocomplete", "off");
            }
        }
    });
    m_formPanel.setButtonAlign(HorizontalAlignment.RIGHT);
    m_buttonBar = m_formPanel.getButtonBar();
    initButtonBar();
    m_formPanel.addListener(Events.BeforeSubmit, new Listener<BaseEvent>() {

        @Override
        public void handleEvent(BaseEvent be) {
            if (!m_selectedDevice.isOnline()) {
                MessageBox.alert(MSGS.alerts(), MSGS.deviceOffline(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        m_commandInput.unmask();
                    }
                });
                be.setCancelled(true);
            }
        }
    });
    m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {

        @Override
        public void handleEvent(FormEvent be) {
            String htmlResult = be.getResultHtml();
            // 
            if (!htmlResult.startsWith("<pre")) {
                int errorMessageStartIndex = htmlResult.indexOf("<pre");
                errorMessageStartIndex = htmlResult.indexOf(">", errorMessageStartIndex) + 1;
                int errorMessageEndIndex = htmlResult.indexOf("</pre>");
                String errorMessage = htmlResult.substring(errorMessageStartIndex, errorMessageEndIndex);
                MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ":<br/>" + errorMessage, null);
                m_commandInput.unmask();
            } else {
                int outputMessageStartIndex = htmlResult.indexOf("<pre");
                outputMessageStartIndex = htmlResult.indexOf(">", outputMessageStartIndex) + 1;
                int outputMessageEndIndex = htmlResult.indexOf("</pre>");
                String output = htmlResult.substring(outputMessageStartIndex, outputMessageEndIndex);
                m_result.setValue(KapuaSafeHtmlUtils.htmlUnescape(output));
                m_commandInput.unmask();
            }
        }
    });
    m_accountField = new HiddenField<String>();
    m_accountField.setName("scopeIdString");
    fieldSet.add(m_accountField);
    m_deviceIdField = new HiddenField<String>();
    m_deviceIdField.setName("deviceIdString");
    fieldSet.add(m_deviceIdField);
    m_timeoutField = new HiddenField<Integer>();
    m_timeoutField.setName("timeout");
    fieldSet.add(m_timeoutField);
    // 
    // xsrfToken Hidden field
    // 
    xsrfTokenField = new HiddenField<String>();
    xsrfTokenField.setId("xsrfToken");
    xsrfTokenField.setName("xsrfToken");
    xsrfTokenField.setValue("");
    fieldSet.add(xsrfTokenField);
    m_commandField = new TextField<String>();
    m_commandField.setName("command");
    m_commandField.setAllowBlank(false);
    m_commandField.setFieldLabel("* " + MSGS.deviceCommandExecute());
    m_commandField.setLayoutData(layout);
    fieldSet.add(m_commandField, formData);
    m_fileUploadField = new FileUploadField();
    m_fileUploadField.setAllowBlank(true);
    m_fileUploadField.setName("file");
    m_fileUploadField.setLayoutData(layout);
    m_fileUploadField.setFieldLabel(MSGS.deviceCommandFile());
    fieldSet.add(m_fileUploadField, formData);
    m_passwordField = new TextField<String>();
    m_passwordField.setName("password");
    m_passwordField.setFieldLabel(MSGS.deviceCommandPassword());
    m_passwordField.setToolTip(MSGS.deviceCommandPasswordTooltip());
    m_passwordField.setPassword(true);
    m_passwordField.setLayoutData(layout);
    fieldSet.add(m_passwordField, formData);
    m_commandInput = m_formPanel;
    m_commandInput.mask(MSGS.deviceNoDeviceSelected());
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) Listener(com.extjs.gxt.ui.client.event.Listener) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener) NodeList(com.google.gwt.dom.client.NodeList) Element(com.google.gwt.user.client.Element) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) FileUploadField(com.extjs.gxt.ui.client.widget.form.FileUploadField) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) FormEvent(com.extjs.gxt.ui.client.event.FormEvent)

Example 58 with FormLayout

use of com.extjs.gxt.ui.client.widget.layout.FormLayout 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)

Example 59 with FormLayout

use of com.extjs.gxt.ui.client.widget.layout.FormLayout in project kapua by eclipse.

the class UserManageForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    // 
    // Permission tab
    // 
    FormLayout permissionsLayout = new FormLayout();
    permissionsLayout.setLabelWidth(Constants.LABEL_WIDTH_FORM);
    permissionsFieldSet = new FieldSet();
    permissionsFieldSet.setBorders(false);
    permissionsFieldSet.setLayout(permissionsLayout);
    // permissions table columns
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    final CheckBoxSelectionModel<GwtUserPermission> sm = new CheckBoxSelectionModel<GwtUserPermission>();
    configs.add(sm.getColumn());
    ColumnConfig column = new ColumnConfig("accountPermission", MSGS.userPermissionsPermissionName(), 270);
    column.setAlignment(HorizontalAlignment.LEFT);
    configs.add(column);
    // Permissions table
    m_columnModel = new ColumnModel(configs);
    // 
    // Initial empty values
    List<GwtUserPermission> gwtUserPermissions = GwtUserPermission.getAllPermissions(m_accountId);
    MemoryProxy<List<GwtUserPermission>> proxy = new MemoryProxy<List<GwtUserPermission>>(gwtUserPermissions);
    ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy);
    ListStore<GwtUserPermission> permissions = new ListStore<GwtUserPermission>(loader);
    loader.load();
    // Grid
    m_permisssionGrid = new EditorGrid<GwtUserPermission>(permissions, m_columnModel);
    m_permisssionGrid.setBorders(true);
    m_permisssionGrid.setStripeRows(true);
    m_permisssionGrid.getView().setAutoFill(true);
    m_permisssionGrid.setWidth(440);
    m_permisssionGrid.setHeight(374);
    m_permisssionGrid.setAutoExpandColumn("accountPermission");
    m_permisssionGrid.setSelectionModel(sm);
    m_permisssionGrid.addPlugin(sm);
    LabelField permissionsField = new LabelField();
    permissionsField.setFieldLabel(MSGS.userFormPermissions());
    permissionsFieldSet.add(permissionsField, formData);
    permissionsFieldSet.add(m_permisssionGrid, formData);
    m_tabUserPermission = new TabItem(MSGS.userFormAccess());
    m_tabUserPermission.setBorders(false);
    m_tabUserPermission.setStyleAttribute("background-color", "#E8E8E8");
    m_tabUserPermission.setScrollMode(Scroll.AUTOY);
    m_tabUserPermission.add(permissionsFieldSet);
    m_tabUserPermission.setLayout(new FitLayout());
    m_tabsPanel.add(m_tabUserPermission);
    add(m_formPanel);
}
Also used : FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) ModelData(com.extjs.gxt.ui.client.data.ModelData) GwtUserPermission(org.eclipse.kapua.app.console.shared.model.GwtUserPermission) CheckBoxSelectionModel(com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) ArrayList(java.util.ArrayList) MemoryProxy(com.extjs.gxt.ui.client.data.MemoryProxy) BaseListLoader(com.extjs.gxt.ui.client.data.BaseListLoader) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) ListStore(com.extjs.gxt.ui.client.store.ListStore) TabItem(com.extjs.gxt.ui.client.widget.TabItem) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) ArrayList(java.util.ArrayList) List(java.util.List) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 60 with FormLayout

use of com.extjs.gxt.ui.client.widget.layout.FormLayout in project kapua by eclipse.

the class FileUploadDialog method onRender.

@Override
protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);
    setLayout(new FormLayout());
    setBodyBorder(false);
    // setButtonAlign(HorizontalAlignment.CENTER); // Must be called beforehand
    setModal(true);
    setButtons("");
    setAutoWidth(true);
    setScrollMode(Scroll.AUTO);
    setHideOnButtonClick(false);
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setAction(m_url);
    m_formPanel.setEncoding(Encoding.MULTIPART);
    m_formPanel.setMethod(Method.POST);
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {

        @Override
        public void handleEvent(FormEvent be) {
            String htmlResponse = be.getResultHtml();
            if (htmlResponse == null || htmlResponse.isEmpty()) {
                MessageBox.info(MSGS.information(), MSGS.fileUploadSuccess(), null);
            } else {
                String errMsg = htmlResponse;
                int startIdx = htmlResponse.indexOf("<pre>");
                int endIndex = htmlResponse.indexOf("</pre>");
                if (startIdx != -1 && endIndex != -1) {
                    errMsg = htmlResponse.substring(startIdx + 5, endIndex);
                }
                MessageBox.alert(MSGS.error(), MSGS.fileUploadFailure() + ": " + errMsg, null);
            }
            hide();
        }
    });
    m_fileUploadField = new FileUploadField();
    m_fileUploadField.setAllowBlank(false);
    m_fileUploadField.setName("uploadedFile");
    m_fileUploadField.setFieldLabel("File");
    m_formPanel.add(m_fileUploadField);
    if (m_hiddenFields != null) {
        for (HiddenField<?> hf : m_hiddenFields) {
            m_formPanel.add(hf);
        }
    }
    // 
    // xsrfToken Hidden field
    // 
    gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

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

        @Override
        public void onSuccess(GwtXSRFToken token) {
            xsrfTokenField.setValue(token.getToken());
        }
    });
    xsrfTokenField = new HiddenField<String>();
    xsrfTokenField.setId("xsrfToken");
    xsrfTokenField.setName("xsrfToken");
    xsrfTokenField.setValue("");
    m_formPanel.add(xsrfTokenField);
    // 
    add(m_formPanel);
}
Also used : FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) FormEvent(com.extjs.gxt.ui.client.event.FormEvent) GwtXSRFToken(org.eclipse.kapua.app.console.shared.model.GwtXSRFToken) FileUploadField(com.extjs.gxt.ui.client.widget.form.FileUploadField)

Aggregations

FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)61 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)37 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)29 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)26 Button (com.extjs.gxt.ui.client.widget.button.Button)24 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)19 FlowLayout (com.extjs.gxt.ui.client.widget.layout.FlowLayout)18 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)15 GPSecureStringTextField (org.geosdi.geoplatform.gui.configuration.GPSecureStringTextField)15 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)12 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)11 LabelField (com.extjs.gxt.ui.client.widget.form.LabelField)10 NumberField (com.extjs.gxt.ui.client.widget.form.NumberField)9 CheckBox (com.extjs.gxt.ui.client.widget.form.CheckBox)7 TextField (com.extjs.gxt.ui.client.widget.form.TextField)7 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)6 Margins (com.extjs.gxt.ui.client.util.Margins)6 Label (com.extjs.gxt.ui.client.widget.Label)6 Radio (com.extjs.gxt.ui.client.widget.form.Radio)6 RadioGroup (com.extjs.gxt.ui.client.widget.form.RadioGroup)6