Search in sources :

Example 6 with Validator

use of com.extjs.gxt.ui.client.widget.form.Validator in project kura by eclipse.

the class DhcpNatConfigTab method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FitLayout());
    setId("network-dhcp-nat");
    FormData formData = new FormData();
    formData.setWidth(250);
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setLayout(new FlowLayout());
    m_formPanel.setStyleAttribute("min-width", "775px");
    m_formPanel.setStyleAttribute("padding-left", "30px");
    FieldSet fieldSet = new FieldSet();
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(Constants.LABEL_WIDTH_FORM);
    fieldSet.setLayout(layoutAccount);
    fieldSet.setBorders(false);
    // 
    // Tool Tip Box
    // 
    toolTipField.setText(defaultToolTip);
    fieldSet.add(toolTipField);
    // 
    // Router Mode
    // 
    m_modeCombo = new SimpleComboBox<String>();
    m_modeCombo.setName("comboMode");
    m_modeCombo.setFieldLabel(MSGS.netRouterMode());
    m_modeCombo.setEditable(false);
    m_modeCombo.setTypeAhead(true);
    m_modeCombo.setTriggerAction(TriggerAction.ALL);
    for (GwtNetRouterMode mode : GwtNetRouterMode.values()) {
        m_modeCombo.add(MessageUtils.get(mode.name()));
    }
    m_modeCombo.setSimpleValue(MessageUtils.get(GwtNetRouterMode.netRouterDchpNat.name()));
    m_modeCombo.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            if (m_tcpIpConfigTab.isDhcp() && !value.equals(MessageUtils.get(GwtNetRouterMode.netRouterOff.toString()))) {
                return MSGS.netRouterConfiguredForDhcpError();
            }
            return null;
        }
    });
    m_modeCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            refreshForm();
        }
    });
    m_modeCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipMode()));
    m_modeCombo.addStyleName("kura-combobox");
    m_modeCombo.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_modeCombo, formData);
    // 
    // DHCP Beginning Address
    // 
    m_dhcpBeginAddressField = new TextField<String>();
    m_dhcpBeginAddressField.setAllowBlank(true);
    m_dhcpBeginAddressField.setName("dhcpBeginAddress");
    m_dhcpBeginAddressField.setFieldLabel(MSGS.netRouterDhcpBeginningAddress());
    m_dhcpBeginAddressField.setRegex(IPV4_REGEX);
    m_dhcpBeginAddressField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
    m_dhcpBeginAddressField.addPlugin(m_dirtyPlugin);
    m_dhcpBeginAddressField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_dhcpBeginAddressField.addStyleName("kura-textfield");
    m_dhcpBeginAddressField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipDhcpBeginAddr()));
    fieldSet.add(m_dhcpBeginAddressField, formData);
    // 
    // DHCP Ending Address
    // 
    m_dhcpEndAddressField = new TextField<String>();
    m_dhcpEndAddressField.setAllowBlank(true);
    m_dhcpEndAddressField.setName("dhcpEndAddress");
    m_dhcpEndAddressField.setFieldLabel(MSGS.netRouterDhcpEndingAddress());
    m_dhcpEndAddressField.setRegex(IPV4_REGEX);
    m_dhcpEndAddressField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
    m_dhcpEndAddressField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipDhcpEndAddr()));
    m_dhcpEndAddressField.addStyleName("kura-textfield");
    ;
    m_dhcpEndAddressField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_dhcpEndAddressField, formData);
    // 
    // DHCP Subnet Mask
    // 
    m_dhcpSubnetMaskField = new TextField<String>();
    m_dhcpSubnetMaskField.setAllowBlank(true);
    m_dhcpSubnetMaskField.setName("dhcpSubnetMask");
    m_dhcpSubnetMaskField.setFieldLabel(MSGS.netRouterDhcpSubnetMask());
    m_dhcpSubnetMaskField.setRegex(IPV4_REGEX);
    m_dhcpSubnetMaskField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipDhcpSubnet()));
    m_dhcpSubnetMaskField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
    m_dhcpSubnetMaskField.addStyleName("kura-textfield");
    m_dhcpSubnetMaskField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_dhcpSubnetMaskField, formData);
    // 
    // DHCP Default Lease
    // 
    m_dhcpLeaseDefaultField = new NumberField();
    m_dhcpLeaseDefaultField.setPropertyEditorType(Integer.class);
    m_dhcpLeaseDefaultField.setAllowDecimals(false);
    m_dhcpLeaseDefaultField.setAllowNegative(false);
    m_dhcpLeaseDefaultField.setMaxValue(Integer.MAX_VALUE);
    m_dhcpLeaseDefaultField.setAllowBlank(true);
    m_dhcpLeaseDefaultField.setName("dhcpDefaultLease");
    m_dhcpLeaseDefaultField.setFieldLabel(MSGS.netRouterDhcpDefaultLease());
    m_dhcpLeaseDefaultField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipDhcpDefaultLeaseTime()));
    m_dhcpLeaseDefaultField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_dhcpLeaseDefaultField, formData);
    // 
    // DHCP Max Lease
    // 
    m_dhcpLeaseMaxField = new NumberField();
    m_dhcpLeaseMaxField.setPropertyEditorType(Integer.class);
    m_dhcpLeaseMaxField.setAllowDecimals(false);
    m_dhcpLeaseMaxField.setAllowNegative(false);
    m_dhcpLeaseMaxField.setMaxValue(Integer.MAX_VALUE);
    m_dhcpLeaseMaxField.setAllowBlank(true);
    m_dhcpLeaseMaxField.setName("dhcpMaxLease");
    m_dhcpLeaseMaxField.setFieldLabel(MSGS.netRouterDhcpMaxLease());
    m_dhcpLeaseMaxField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipDhcpMaxLeaseTime()));
    m_dhcpLeaseMaxField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_dhcpLeaseMaxField, formData);
    // 
    // Pass DNS
    // 
    m_passDnsRadioTrue = new Radio();
    m_passDnsRadioTrue.setBoxLabel(MSGS.trueLabel());
    m_passDnsRadioTrue.setItemId("true");
    m_passDnsRadioFalse = new Radio();
    m_passDnsRadioFalse.setBoxLabel(MSGS.falseLabel());
    m_passDnsRadioFalse.setItemId("false");
    m_passDnsRadioGroup = new RadioGroup();
    m_passDnsRadioGroup.setName("dhcpPassDns");
    m_passDnsRadioGroup.setFieldLabel(MSGS.netRouterPassDns());
    m_passDnsRadioGroup.add(m_passDnsRadioTrue);
    m_passDnsRadioGroup.add(m_passDnsRadioFalse);
    m_passDnsRadioGroup.addPlugin(m_dirtyPlugin);
    m_passDnsRadioGroup.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netRouterToolTipPassDns()));
    fieldSet.add(m_passDnsRadioGroup, formData);
    m_formPanel.add(fieldSet);
    add(m_formPanel);
    setScrollMode(Scroll.AUTO);
    m_initialized = true;
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) RadioGroup(com.extjs.gxt.ui.client.widget.form.RadioGroup) SimpleComboValue(com.extjs.gxt.ui.client.widget.form.SimpleComboValue) Radio(com.extjs.gxt.ui.client.widget.form.Radio) GwtNetRouterMode(org.eclipse.kura.web.shared.model.GwtNetRouterMode) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) Validator(com.extjs.gxt.ui.client.widget.form.Validator) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 7 with Validator

use of com.extjs.gxt.ui.client.widget.form.Validator in project kura by eclipse.

the class ModemConfigTab method onRender.

protected void onRender(Element parent, int index) {
    Log.debug("ModemConfigTab - onRender()");
    super.onRender(parent, index);
    setLayout(new FitLayout());
    setId("network-modem");
    FormData formData = new FormData();
    formData.setWidth(250);
    m_formPanel = new FormPanel();
    m_formPanel.setFrame(false);
    m_formPanel.setBodyBorder(false);
    m_formPanel.setHeaderVisible(false);
    m_formPanel.setLayout(new FlowLayout());
    m_formPanel.setStyleAttribute("min-width", "775px");
    m_formPanel.setStyleAttribute("padding-left", "30px");
    FieldSet fieldSet = new FieldSet();
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(Constants.LABEL_WIDTH_FORM);
    fieldSet.setLayout(layoutAccount);
    fieldSet.setBorders(false);
    // 
    // Tool Tip Box
    // 
    toolTipField.setText(defaultToolTip);
    fieldSet.add(toolTipField);
    // 
    // Modem Model
    // 
    m_modemModel = new LabelField();
    m_modemModel.setName("modemModel");
    m_modemModel.setFieldLabel(MSGS.netModemModel());
    m_modemModel.addPlugin(m_dirtyPlugin);
    m_modemModel.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    fieldSet.add(m_modemModel, formData);
    // 
    // Network Technology
    // 
    m_networkTechnologies = new LabelField();
    m_networkTechnologies.setName("networkTechnologies");
    m_networkTechnologies.setFieldLabel(MSGS.netModemNetworkTechnology());
    m_networkTechnologies.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_networkTechnologies, formData);
    /*
        m_networkTechCombo = new SimpleComboBox<String>();
        m_networkTechCombo.setName("networkTech");
        m_networkTechCombo.setFieldLabel(MSGS.netModemNetworkTechnology());
        m_networkTechCombo.setEditable(false);
        m_networkTechCombo.setTypeAhead(true);
        m_networkTechCombo.setTriggerAction(TriggerAction.ALL);
        m_networkTechCombo.add(MSGS.unknown());
        m_networkTechCombo.setSimpleValue(MSGS.unknown());
        m_networkTechCombo.addSelectionChangedListener( new SelectionChangedListener<SimpleComboValue<String>>() {         
            @Override
            public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
                refreshForm();
            }
        });        
        m_networkTechCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipNetworkTechnology()));
        m_networkTechCombo.addStyleName("kura-combobox");
        m_networkTechCombo.addPlugin(m_dirtyPlugin);
        fieldSet.add(m_networkTechCombo, formData);
       	*/
    // 
    // Service Type
    // 
    m_connectionType = new LabelField();
    m_connectionType.setName("serviceType");
    m_connectionType.setFieldLabel(MSGS.netModemConnectionType());
    m_connectionType.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_connectionType, formData);
    // 
    // Modem Identifier
    // 
    m_modemIdField = new TextField<String>();
    m_modemIdField.setAllowBlank(true);
    m_modemIdField.setName("modemId");
    m_modemIdField.setFieldLabel(MSGS.netModemIdentifier());
    m_modemIdField.addPlugin(m_dirtyPlugin);
    m_modemIdField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_modemIdField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipModemIndentifier()));
    m_modemIdField.addStyleName("kura-textfield");
    fieldSet.add(m_modemIdField, formData);
    // 
    // Interface number
    // 
    m_ifaceNumField = new NumberField();
    m_ifaceNumField.setAllowBlank(false);
    m_ifaceNumField.setName("ifaceNum");
    m_ifaceNumField.setFieldLabel(MSGS.netModemInterfaceNum());
    m_ifaceNumField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipModemInterfaceNumber()));
    m_ifaceNumField.addPlugin(m_dirtyPlugin);
    m_ifaceNumField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            int val = Integer.parseInt(value);
            if (val < 0) {
                return MSGS.netModemInvalidInterfaceNum();
            }
            return null;
        }
    });
    fieldSet.add(m_ifaceNumField, formData);
    // 
    // Dial String
    // 
    m_dialStringField = new TextField<String>();
    m_dialStringField.setName("dialString");
    m_dialStringField.setFieldLabel(MSGS.netModemDialString());
    String dialString = "";
    String model = "";
    if (m_selectNetIfConfig != null) {
        model = m_selectNetIfConfig.getModel();
        if (model != null && model.length() > 0) {
            if (model.contains("HE910")) {
                dialString = defaultDialString.get("HE910");
            } else if (model.contains("DE910")) {
                dialString = defaultDialString.get("DE910");
            } else {
                dialString = "";
            }
        }
    }
    if (dialString.equals("")) {
        m_dialStringField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipDialStringDefault()));
    } else {
        m_dialStringField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipDialString(dialString)));
    }
    m_dialStringField.addStyleName("kura-textfield");
    m_dialStringField.setAllowBlank(false);
    m_dialStringField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_dialStringField, formData);
    // 
    // APN
    // 
    m_apnField = new TextField<String>();
    m_apnField.setName("apn");
    m_apnField.setFieldLabel(MSGS.netModemAPN());
    m_apnField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipApn()));
    m_apnField.addStyleName("kura-textfield");
    if (m_selectNetIfConfig != null) {
        for (String techType : m_selectNetIfConfig.getNetworkTechnology()) {
            if (techType.equals("HSPA") || techType.equals("HSDPA") || techType.equals("UMTS") || techType.equals("GSM_GPRS")) {
                m_apnField.setAllowBlank(false);
                break;
            }
        }
    }
    m_apnField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_apnField, formData);
    // 
    // Auth Type
    // 
    m_authTypeCombo = new SimpleComboBox<String>();
    m_authTypeCombo.setName("authTypeCombo");
    m_authTypeCombo.setFieldLabel(MSGS.netModemAuthType());
    m_authTypeCombo.setEditable(false);
    m_authTypeCombo.setTypeAhead(true);
    m_authTypeCombo.setTriggerAction(TriggerAction.ALL);
    for (GwtModemAuthType auth : GwtModemAuthType.values()) {
        m_authTypeCombo.add(MessageUtils.get(auth.name()));
    }
    m_authTypeCombo.setSimpleValue(MessageUtils.get(GwtModemAuthType.netModemAuthNONE.name()));
    m_authTypeCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            refreshForm();
        }
    });
    m_authTypeCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipAuthentication()));
    m_authTypeCombo.addStyleName("kura-combobox");
    m_authTypeCombo.addPlugin(m_dirtyPlugin);
    m_authTypeCombo.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    fieldSet.add(m_authTypeCombo, formData);
    // 
    // Username
    // 
    m_usernameField = new TextField<String>();
    m_usernameField.setAllowBlank(true);
    m_usernameField.setName("username");
    m_usernameField.setFieldLabel(MSGS.netModemUsername());
    m_usernameField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipUsername()));
    m_usernameField.addStyleName("kura-textfield");
    m_usernameField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_usernameField, formData);
    // 
    // Password
    // 
    m_passwordField = new TextField<String>();
    m_passwordField.setAllowBlank(true);
    m_passwordField.setPassword(true);
    m_passwordField.setName("password");
    m_passwordField.setFieldLabel(MSGS.netModemPassword());
    m_passwordField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipPassword()));
    m_passwordField.addStyleName("kura-textfield");
    m_passwordField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_passwordField, formData);
    // reset timeout
    m_resetTimeoutField = new NumberField();
    m_resetTimeoutField.setAllowBlank(false);
    m_resetTimeoutField.setName("resetTimeout");
    m_resetTimeoutField.setFieldLabel(MSGS.netModemResetTimeout());
    m_resetTimeoutField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipResetTimeout()));
    m_resetTimeoutField.addPlugin(m_dirtyPlugin);
    m_resetTimeoutField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_resetTimeoutField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            int val = Integer.parseInt(value);
            if ((val < 0) || (val == 1)) {
                return MSGS.netModemInvalidResetTimeout();
            }
            return null;
        }
    });
    fieldSet.add(m_resetTimeoutField, formData);
    m_persistRadioTrue = new Radio();
    m_persistRadioTrue.setBoxLabel(MSGS.trueLabel());
    m_persistRadioTrue.setItemId("true");
    m_persistRadioTrue.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipPersist()));
    m_persistRadioFalse = new Radio();
    m_persistRadioFalse.setBoxLabel(MSGS.falseLabel());
    m_persistRadioFalse.setItemId("false");
    m_persistRadioFalse.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipPersist()));
    m_persistRadioGroup = new RadioGroup();
    m_persistRadioGroup.setName("modemPersist");
    m_persistRadioGroup.setFieldLabel(MSGS.netModemPersist());
    m_persistRadioGroup.add(m_persistRadioTrue);
    m_persistRadioGroup.add(m_persistRadioFalse);
    m_persistRadioGroup.addPlugin(m_dirtyPlugin);
    m_persistRadioGroup.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    fieldSet.add(m_persistRadioGroup, formData);
    // maxfail
    m_maxFailField = new NumberField();
    m_maxFailField.setAllowBlank(false);
    m_maxFailField.setName("modemMaxFail");
    m_maxFailField.setFieldLabel(MSGS.netModemMaxFail());
    m_maxFailField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipMaxFail()));
    m_maxFailField.addPlugin(m_dirtyPlugin);
    m_maxFailField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            int val = Integer.parseInt(value);
            if (val <= 0) {
                return MSGS.netModemInvalidMaxFail();
            }
            return null;
        }
    });
    fieldSet.add(m_maxFailField, formData);
    // idle
    m_idleField = new NumberField();
    m_idleField.setAllowBlank(false);
    m_idleField.setName("modemIdle");
    m_idleField.setFieldLabel(MSGS.netModemIdle());
    m_idleField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipIdle()));
    m_idleField.addPlugin(m_dirtyPlugin);
    m_idleField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            int val = Integer.parseInt(value);
            if (val < 0) {
                return MSGS.netModemInvalidIdle();
            }
            return null;
        }
    });
    fieldSet.add(m_idleField, formData);
    // active-filter
    m_activeFilterField = new TextField<String>();
    m_activeFilterField.setAllowBlank(true);
    m_activeFilterField.setName("active-filter");
    m_activeFilterField.setFieldLabel(MSGS.netModemActiveFilter());
    m_activeFilterField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipActiveFilter()));
    m_activeFilterField.addStyleName("esf-textfield");
    m_activeFilterField.addPlugin(m_dirtyPlugin);
    fieldSet.add(m_activeFilterField, formData);
    // 
    // LCP Echo Interval
    // 
    m_lcpEchoIntervalField = new NumberField();
    m_lcpEchoIntervalField.setAllowBlank(false);
    m_lcpEchoIntervalField.setName("lcpEchoInterval");
    m_lcpEchoIntervalField.setFieldLabel(MSGS.netModemLcpEchoInterval());
    m_lcpEchoIntervalField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipLcpEchoInterval()));
    m_lcpEchoIntervalField.addPlugin(m_dirtyPlugin);
    m_lcpEchoIntervalField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_lcpEchoIntervalField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            int val = Integer.parseInt(value);
            if (val < 0) {
                return MSGS.netModemInvalidLcpEchoInterval();
            }
            return null;
        }
    });
    fieldSet.add(m_lcpEchoIntervalField, formData);
    // 
    // LCP Echo Interval
    // 
    m_lcpEchoFailureField = new NumberField();
    m_lcpEchoFailureField.setAllowBlank(false);
    m_lcpEchoFailureField.setName("lcpEchoFailure");
    m_lcpEchoFailureField.setFieldLabel(MSGS.netModemLcpEchoFailure());
    m_lcpEchoFailureField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netModemToolTipLcpEchoFailure()));
    m_lcpEchoFailureField.addPlugin(m_dirtyPlugin);
    m_lcpEchoFailureField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            int val = Integer.parseInt(value);
            if (val < 0) {
                return MSGS.netModemInvalidLcpEchoFailure();
            }
            return null;
        }
    });
    fieldSet.add(m_lcpEchoFailureField, formData);
    m_formPanel.add(fieldSet);
    m_formPanel.setScrollMode(Scroll.AUTO);
    add(m_formPanel);
    setScrollMode(Scroll.AUTOX);
    m_initialized = true;
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) RadioGroup(com.extjs.gxt.ui.client.widget.form.RadioGroup) GwtModemAuthType(org.eclipse.kura.web.shared.model.GwtModemAuthType) SimpleComboValue(com.extjs.gxt.ui.client.widget.form.SimpleComboValue) Radio(com.extjs.gxt.ui.client.widget.form.Radio) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) Validator(com.extjs.gxt.ui.client.widget.form.Validator) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 8 with Validator

use of com.extjs.gxt.ui.client.widget.form.Validator in project kapua by eclipse.

the class DateRangeSelector method showCustomDateRangeDialog.

private void showCustomDateRangeDialog() {
    Date end = m_endDate;
    Date start = m_startDate;
    if (end == null) {
        end = new Date();
    }
    if (start == null) {
        start = new Date(end.getTime() - 24L * 60L * 60L * 1000L);
    }
    final Dialog dialog = new Dialog();
    dialog.setBodyBorder(false);
    dialog.setHeading(MSGS.dataDateRangeCustomTitle());
    dialog.setWidth(300);
    dialog.setHeight(200);
    dialog.setHideOnButtonClick(true);
    dialog.setButtons(Dialog.OKCANCEL);
    dialog.setHideOnButtonClick(false);
    FormData formData = new FormData("-20");
    final FormPanel form = new FormPanel();
    form.setHeaderVisible(false);
    final DateField startDateField = new DateField();
    startDateField.setFieldLabel(MSGS.dataDateRangeStartDate());
    startDateField.setAllowBlank(false);
    startDateField.setValue(start);
    startDateField.setEditable(false);
    form.add(startDateField, formData);
    final TimeField startTimeField = new TimeField();
    startTimeField.setFormat(DateTimeFormat.getFormat("HH:mm"));
    startTimeField.setTriggerAction(TriggerAction.ALL);
    startTimeField.setFieldLabel(MSGS.dataDateRangeStartTime());
    startTimeField.setAllowBlank(false);
    startTimeField.setDateValue(start);
    startTimeField.setEditable(false);
    form.add(startTimeField, formData);
    final DateField endDateField = new DateField();
    endDateField.setFieldLabel(MSGS.dataDateRangeStopDate());
    endDateField.setAllowBlank(false);
    endDateField.setValue(end);
    endDateField.setEditable(false);
    form.add(endDateField, formData);
    final TimeField endTimeField = new TimeField();
    endTimeField.setFormat(DateTimeFormat.getFormat("HH:mm"));
    endTimeField.setTriggerAction(TriggerAction.ALL);
    endTimeField.setFieldLabel(MSGS.dataDateRangeStopTime());
    endTimeField.setAllowBlank(false);
    endTimeField.setDateValue(end);
    endTimeField.setEditable(false);
    form.add(endTimeField, formData);
    startDateField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (startDateField.getValue().after(endDateField.getValue())) {
                return MSGS.dataDateRangeInvalidStartDate();
            }
            return null;
        }
    });
    endDateField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (endDateField.getValue().before(startDateField.getValue())) {
                return MSGS.dataDateRangeInvalidStopDate();
            }
            return null;
        }
    });
    startTimeField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (startDateField.getValue().equals(endDateField.getValue()) && startTimeField.getDateValue().after(endTimeField.getDateValue())) {
                return MSGS.dataDateRangeInvalidStartTime();
            }
            return null;
        }
    });
    endTimeField.setValidator(new Validator() {

        @Override
        public String validate(Field<?> field, String value) {
            if (startDateField.getValue().equals(endDateField.getValue()) && endTimeField.getDateValue().before(startTimeField.getDateValue())) {
                return MSGS.dataDateRangeInvalidStopTime();
            }
            return null;
        }
    });
    dialog.add(form);
    dialog.getButtonById("ok").addSelectionListener(new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent ce) {
            if (form.isValid()) {
                long lStartDate = startDateField.getValue().getTime();
                lStartDate = lStartDate + (long) startTimeField.getValue().getHour() * 60L * 60L * 1000L + (long) startTimeField.getValue().getMinutes() * 60L * 1000L;
                m_startDate = new Date(lStartDate);
                long lEndDate = endDateField.getValue().getTime();
                lEndDate = lEndDate + (long) endTimeField.getValue().getHour() * 60L * 60L * 1000L + (long) endTimeField.getValue().getMinutes() * 60L * 1000L;
                m_endDate = new Date(lEndDate);
                DateTimeFormat dtf = DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_SHORT);
                StringBuilder sb = new StringBuilder();
                sb.append(dtf.format(m_startDate)).append(" - ").append(dtf.format(m_endDate));
                m_dateRange.setText(sb.toString());
                dialog.hide();
                if (m_listener != null) {
                    m_listener.onUpdate();
                }
            }
        }
    });
    dialog.getButtonById("cancel").addSelectionListener(new SelectionListener<ButtonEvent>() {

        public void componentSelected(ButtonEvent ce) {
            dialog.hide();
        }
    });
    dialog.show();
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) Date(java.util.Date) TimeField(com.extjs.gxt.ui.client.widget.form.TimeField) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) Dialog(com.extjs.gxt.ui.client.widget.Dialog) DateField(com.extjs.gxt.ui.client.widget.form.DateField) Validator(com.extjs.gxt.ui.client.widget.form.Validator) DateTimeFormat(com.google.gwt.i18n.client.DateTimeFormat)

Aggregations

Validator (com.extjs.gxt.ui.client.widget.form.Validator)8 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)4 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)4 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)4 FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)4 NumberField (com.extjs.gxt.ui.client.widget.form.NumberField)3 Radio (com.extjs.gxt.ui.client.widget.form.Radio)3 RadioGroup (com.extjs.gxt.ui.client.widget.form.RadioGroup)3 SimpleComboValue (com.extjs.gxt.ui.client.widget.form.SimpleComboValue)3 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)3 FlowLayout (com.extjs.gxt.ui.client.widget.layout.FlowLayout)3 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)2 LabelField (com.extjs.gxt.ui.client.widget.form.LabelField)2 El (com.extjs.gxt.ui.client.core.El)1 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)1 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 ComponentEvent (com.extjs.gxt.ui.client.event.ComponentEvent)1 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 KeyListener (com.extjs.gxt.ui.client.event.KeyListener)1