Search in sources :

Example 6 with FormLayout

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

the class FileUploadDialog method onRender.

@Override
protected void onRender(Element parent, int pos) {
    super.onRender(parent, pos);
    setLayout(new FormLayout());
    setBodyBorder(false);
    setModal(true);
    setButtons("");
    setScrollMode(Scroll.AUTO);
    setHideOnButtonClick(false);
    setSize(400, 125);
    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.setLabelWidth(50);
    m_formPanel.addListener(Events.Submit, new Listener<FormEvent>() {

        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(MSGS.fileLabel());
    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.kura.web.shared.model.GwtXSRFToken) FileUploadField(com.extjs.gxt.ui.client.widget.form.FileUploadField)

Example 7 with FormLayout

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

the class WirelessConfigTab method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FitLayout());
    setId("network-wireless");
    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);
    // 
    // Wireless Mode
    // 
    m_wirelessModeListStore = new ListStore<GwtWifiWirelessModeModel>();
    /*
        m_wirelessModeListStore.add(new GwtWifiWirelessModeModel(GwtWifiWirelessMode.netWifiWirelessModeDisabled,
                MessageUtils.get("netWifiWirelessModeDisabled"),
                MSGS.netWifiToolTipWirelessModeDisabled()));
		 */
    m_wirelessModeListStore.add(new GwtWifiWirelessModeModel(GwtWifiWirelessMode.netWifiWirelessModeStation, MessageUtils.get("netWifiWirelessModeStation"), MSGS.netWifiToolTipWirelessModeStation()));
    m_wirelessModeListStore.add(new GwtWifiWirelessModeModel(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint, MessageUtils.get("netWifiWirelessModeAccessPoint"), MSGS.netWifiToolTipWirelessModeAccessPoint()));
    /*
        m_wirelessModeListStore.add(new GwtWifiWirelessModeModel(GwtWifiWirelessMode.netWifiWirelessModeAdHoc,
                MessageUtils.get("netWifiWirelessModeAdHoc"),
                MSGS.netWifiToolTipWirelessModeAdhoc()));
		 */
    m_modeCombo = new ComboBox<GwtWifiWirelessModeModel>();
    m_modeCombo.setName("comboMode");
    m_modeCombo.setDisplayField(GwtWifiWirelessModeModel.NAME);
    m_modeCombo.setFieldLabel(MSGS.netWifiWirelessMode());
    m_modeCombo.setEditable(false);
    m_modeCombo.setTypeAhead(true);
    m_modeCombo.setTriggerAction(TriggerAction.ALL);
    m_modeCombo.addStyleName("kura-combobox");
    m_modeCombo.setStore(m_wirelessModeListStore);
    m_modeCombo.setTemplate(getTemplate());
    m_modeCombo.setValue(m_wirelessModeListStore.findModel(GwtWifiWirelessModeModel.MODE, GwtWifiWirelessMode.netWifiWirelessModeStation.name()));
    m_modeCombo.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            if (m_tcpIpConfigTab.getStatus().equals(GwtNetIfStatus.netIPv4StatusEnabledWAN) && value.equals(MessageUtils.get(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name()))) {
                return MSGS.netWifiWirelessEnabledForWANError();
            }
            return null;
        }
    });
    m_modeCombo.addSelectionChangedListener(new SelectionChangedListener<GwtWifiWirelessModeModel>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtWifiWirelessModeModel> se) {
            // Station mode selected
            if (GwtWifiWirelessMode.netWifiWirelessModeStation.equals(se.getSelectedItem().getMode())) {
                // Use values from station config
                m_activeWifiConfig = m_selectNetIfConfig.getStationWifiConfig();
            } else {
                // Use values from access point config
                m_activeWifiConfig = m_selectNetIfConfig.getAccessPointWifiConfig();
            }
            setPasswordValidation();
            setValues(false);
            refreshForm();
        }
    });
    m_modeCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipWirelessMode()));
    m_modeCombo.addPlugin(m_dirtyPlugin);
    Button ssidPickerButton = new Button("", AbstractImagePrototype.create(Resources.INSTANCE.magnifier16()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            m_wifiNetworksWindow = createWifiNetworksWindow();
            m_wifiNetworksWindow.show();
            m_wifiHotspotLoader.load();
        }
    });
    // 
    // SSID
    // 
    m_ssidField = new TextFieldWithButton<String>(ssidPickerButton, 10);
    m_ssidField.setAllowBlank(true);
    m_ssidField.setId("ssid-input");
    m_ssidField.setName("ssid");
    m_ssidField.setFieldLabel(MSGS.netWifiNetworkName());
    m_ssidField.setEnabled(true, false);
    m_ssidField.addPlugin(m_dirtyPlugin);
    m_ssidField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipNetworkName()));
    m_ssidField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_ssidField.setMaxLength(MAX_SSID_LENGTH);
    // 
    // Radio Mode
    // 
    m_radioModeCombo = new SimpleComboBox<String>();
    m_radioModeCombo.setName("radioMode");
    m_radioModeCombo.setFieldLabel(MSGS.netWifiRadioMode());
    m_radioModeCombo.setEditable(false);
    m_radioModeCombo.setTypeAhead(true);
    m_radioModeCombo.setTriggerAction(TriggerAction.ALL);
    for (GwtWifiRadioMode mode : GwtWifiRadioMode.values()) {
        if (mode != GwtWifiRadioMode.netWifiRadioModeA) {
            // we don't support 802.11a yet
            m_radioModeCombo.add(MessageUtils.get(mode.name()));
        }
    }
    m_radioModeCombo.setSimpleValue(MessageUtils.get(GwtWifiRadioMode.netWifiRadioModeBGN.name()));
    m_radioModeCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            refreshForm();
        }
    });
    m_radioModeCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipRadioMode()));
    m_radioModeCombo.addStyleName("kura-combobox");
    m_radioModeCombo.addPlugin(m_dirtyPlugin);
    // 
    // Wireless Security
    // 
    m_securityCombo = new SimpleComboBox<String>();
    m_securityCombo.setName("security");
    m_securityCombo.setFieldLabel(MSGS.netWifiWirelessSecurity());
    m_securityCombo.setEditable(false);
    m_securityCombo.setTypeAhead(true);
    m_securityCombo.setTriggerAction(TriggerAction.ALL);
    m_securityCombo.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    for (GwtWifiSecurity mode : GwtWifiSecurity.values()) {
        m_securityCombo.add(MessageUtils.get(mode.name()));
    }
    m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA2.name()));
    m_securityCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            setPasswordValidation();
            refreshForm();
        }
    });
    m_securityCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipSecurity()));
    m_securityCombo.addStyleName("kura-combobox");
    m_securityCombo.addPlugin(m_dirtyPlugin);
    Button passwordButton = new Button("", AbstractImagePrototype.create(Resources.INSTANCE.connect16()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            m_passwordField.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.hourglass16()));
            m_passwordField.setEnabled(true, false);
            gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

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

                @Override
                public void onSuccess(GwtXSRFToken token) {
                    GwtWifiConfig gwtWifiConfig = getGwtWifiConfig();
                    gwtNetworkService.verifyWifiCredentials(token, m_selectNetIfConfig.getName(), gwtWifiConfig, new AsyncCallback<Boolean>() {

                        public void onSuccess(Boolean result) {
                            Log.warn("verifyWifiCredentials() :: result=" + result);
                            if (!result.booleanValue()) {
                                m_passwordField.setValue("");
                            }
                            m_passwordField.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.connect16()));
                            m_passwordField.setEnabled(true, true);
                        }

                        public void onFailure(Throwable caught) {
                            Log.warn("verifyWifiCredentials() :: caught: " + caught.toString());
                            m_passwordField.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.connect16()));
                            m_passwordField.setEnabled(true, true);
                        }
                    });
                }
            });
        }
    });
    // 
    // Password
    // 
    m_passwordField = new TextFieldWithButton<String>(passwordButton, 10);
    m_passwordField.setId("wifi-password");
    m_passwordField.setName("password");
    m_passwordField.setFieldLabel(MSGS.netWifiWirelessPassword());
    m_passwordField.setPassword(true);
    m_passwordField.setRegex(PASSWORD_REGEX_ANY);
    m_passwordField.getMessages().setRegexText(MSGS.netWifiWirelessInvalidWPAPassword());
    m_passwordField.addPlugin(m_dirtyPlugin);
    m_passwordField.setAutoValidate(true);
    m_passwordField.setAllowBlank(false);
    m_passwordField.addKeyListener(new KeyListener() {

        @Override
        public void componentKeyUp(ComponentEvent event) {
            super.componentKeyUp(event);
            m_verifyPasswordField.validate();
        }
    });
    m_passwordField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipPassword()));
    m_passwordField.addListener(Events.OnChange, new Listener<BaseEvent>() {

        public void handleEvent(BaseEvent be) {
            setPasswordValidation();
            refreshForm();
        }
    });
    // 
    // Verify Password
    // 
    m_verifyPasswordField = new TextField<String>();
    m_verifyPasswordField.setName("verifyPassword");
    m_verifyPasswordField.setFieldLabel(MSGS.netWifiWirelessVerifyPassword());
    m_verifyPasswordField.setPassword(true);
    m_verifyPasswordField.addPlugin(m_dirtyPlugin);
    // TODO:
    m_verifyPasswordField.getMessages().setInvalidText("Invalid text 123");
    m_verifyPasswordField.setAutoValidate(true);
    m_verifyPasswordField.setAllowBlank(false);
    m_verifyPasswordField.setValidator(new Validator() {

        public String validate(Field<?> field, String value) {
            if (m_modeCombo != null && GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.equals(m_modeCombo.getValue().getMode())) {
                // Check that the verify password field matches
                if (m_passwordField == null || !value.equals(m_passwordField.getValue())) {
                    return MSGS.netWifiWirelessPasswordDoesNotMatch();
                }
            }
            return null;
        }
    });
    m_verifyPasswordField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipVerifyPassword()));
    m_verifyPasswordField.addStyleName("kura-textfield");
    // pairwise ciphers
    m_pairwiseCiphersCombo = new SimpleComboBox<String>();
    m_pairwiseCiphersCombo.setName("pairwiseCiphers");
    m_pairwiseCiphersCombo.setFieldLabel(MSGS.netWifiWirelessPairwiseCiphers());
    m_pairwiseCiphersCombo.setEditable(false);
    m_pairwiseCiphersCombo.setTypeAhead(true);
    m_pairwiseCiphersCombo.setTriggerAction(TriggerAction.ALL);
    // m_pairwiseCiphersCombo.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    for (GwtWifiCiphers ciphers : GwtWifiCiphers.values()) {
        m_pairwiseCiphersCombo.add(MessageUtils.get(ciphers.name()));
    }
    m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
    m_pairwiseCiphersCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            refreshForm();
        }
    });
    m_pairwiseCiphersCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipPairwiseCiphers()));
    m_pairwiseCiphersCombo.addStyleName("kura-combobox");
    m_pairwiseCiphersCombo.addPlugin(m_dirtyPlugin);
    // group ciphers
    m_groupCiphersCombo = new SimpleComboBox<String>();
    m_groupCiphersCombo.setName("groupCiphers");
    m_groupCiphersCombo.setFieldLabel(MSGS.netWifiWirelessGroupCiphers());
    m_groupCiphersCombo.setEditable(false);
    m_groupCiphersCombo.setTypeAhead(true);
    m_groupCiphersCombo.setTriggerAction(TriggerAction.ALL);
    // m_groupCiphersCombo.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    for (GwtWifiCiphers ciphers : GwtWifiCiphers.values()) {
        m_groupCiphersCombo.add(MessageUtils.get(ciphers.name()));
    }
    m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
    m_groupCiphersCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            refreshForm();
        }
    });
    m_groupCiphersCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipGroupCiphers()));
    m_groupCiphersCombo.addStyleName("kura-combobox");
    m_groupCiphersCombo.addPlugin(m_dirtyPlugin);
    // bgscan module
    m_bgscanModuleCombo = new SimpleComboBox<String>();
    m_bgscanModuleCombo.setName("groupCiphers");
    m_bgscanModuleCombo.setFieldLabel(MSGS.netWifiWirelessBgscanModule());
    m_bgscanModuleCombo.setEditable(false);
    m_bgscanModuleCombo.setTypeAhead(true);
    m_bgscanModuleCombo.setTriggerAction(TriggerAction.ALL);
    m_bgscanModuleCombo.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    for (GwtWifiBgscanModule module : GwtWifiBgscanModule.values()) {
        m_bgscanModuleCombo.add(MessageUtils.get(module.name()));
    }
    m_bgscanModuleCombo.setSimpleValue(MessageUtils.get(GwtWifiBgscanModule.netWifiBgscanMode_NONE.name()));
    m_bgscanModuleCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
            refreshForm();
        }
    });
    m_bgscanModuleCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipBgScan()));
    m_bgscanModuleCombo.addStyleName("kura-combobox");
    m_bgscanModuleCombo.addPlugin(m_dirtyPlugin);
    // bgscan RSSI Threshold
    m_bgscanRssiThresholdSlider = new Slider();
    m_bgscanRssiThresholdSlider.setWidth(200);
    m_bgscanRssiThresholdSlider.setIncrement(1);
    m_bgscanRssiThresholdSlider.setMinValue(-90);
    m_bgscanRssiThresholdSlider.setMaxValue(-20);
    m_bgscanRssiThresholdSlider.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipBgScanStrength()));
    m_bgscanRssiThresholdSlider.setClickToChange(false);
    m_bgscanRssiThresholdSliderField = new SliderField(m_bgscanRssiThresholdSlider);
    m_bgscanRssiThresholdSliderField.setFieldLabel(MSGS.netWifiWirelessBgscanSignalStrengthThreshold());
    // bgscan short interval
    m_bgscanShortIntervalField = new NumberField();
    m_bgscanShortIntervalField.setPropertyEditorType(Integer.class);
    m_bgscanShortIntervalField.setAllowDecimals(false);
    m_bgscanShortIntervalField.setAllowNegative(false);
    m_bgscanShortIntervalField.setAllowBlank(true);
    m_bgscanShortIntervalField.setName("bgscanShortInterval");
    m_bgscanShortIntervalField.setFieldLabel(MSGS.netWifiWirelessBgscanShortInterval());
    m_bgscanShortIntervalField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipBgScanShortInterval()));
    m_bgscanShortIntervalField.addPlugin(m_dirtyPlugin);
    // m_bgscanShortInterval.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    // bgscan long interval
    m_bgscanLongIntervalField = new NumberField();
    m_bgscanLongIntervalField.setPropertyEditorType(Integer.class);
    m_bgscanLongIntervalField.setAllowDecimals(false);
    m_bgscanLongIntervalField.setAllowNegative(false);
    m_bgscanLongIntervalField.setAllowBlank(true);
    m_bgscanLongIntervalField.setName("bgscanLongInterval");
    m_bgscanLongIntervalField.setFieldLabel(MSGS.netWifiWirelessBgscanLongInterval());
    m_bgscanLongIntervalField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipBgScanLongInterval()));
    m_bgscanLongIntervalField.addPlugin(m_dirtyPlugin);
    m_pingAccessPointRadioTrue = new Radio();
    m_pingAccessPointRadioTrue.setBoxLabel(MSGS.trueLabel());
    m_pingAccessPointRadioTrue.setItemId("true");
    m_pingAccessPointRadioTrue.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipPingAccessPoint()));
    m_pingAccessPointRadioFalse = new Radio();
    m_pingAccessPointRadioFalse.setBoxLabel(MSGS.falseLabel());
    m_pingAccessPointRadioFalse.setItemId("false");
    m_pingAccessPointRadioFalse.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipPingAccessPoint()));
    m_pingAccessPointRadioGroup = new RadioGroup();
    m_pingAccessPointRadioGroup.setName("pingAccessPoint");
    m_pingAccessPointRadioGroup.setFieldLabel(MSGS.netWifiWirelessPingAccessPoint());
    m_pingAccessPointRadioGroup.add(m_pingAccessPointRadioTrue);
    m_pingAccessPointRadioGroup.add(m_pingAccessPointRadioFalse);
    m_pingAccessPointRadioGroup.addPlugin(m_dirtyPlugin);
    m_pingAccessPointRadioGroup.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_ignoreSsidRadioTrue = new Radio();
    m_ignoreSsidRadioTrue.setBoxLabel(MSGS.trueLabel());
    m_ignoreSsidRadioTrue.setItemId("true");
    m_ignoreSsidRadioTrue.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipIgnoreSSID()));
    m_ignoreSsidRadioFalse = new Radio();
    m_ignoreSsidRadioFalse.setBoxLabel(MSGS.falseLabel());
    m_ignoreSsidRadioFalse.setItemId("false");
    m_ignoreSsidRadioFalse.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipIgnoreSSID()));
    m_ignoreSsidRadioGroup = new RadioGroup();
    m_ignoreSsidRadioGroup.setName("ignoreSSID");
    m_ignoreSsidRadioGroup.setFieldLabel(MSGS.netWifiWirelessIgnoreSSID());
    m_ignoreSsidRadioGroup.add(m_ignoreSsidRadioTrue);
    m_ignoreSsidRadioGroup.add(m_ignoreSsidRadioFalse);
    m_ignoreSsidRadioGroup.addPlugin(m_dirtyPlugin);
    m_ignoreSsidRadioGroup.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    // 
    // Channel
    // 
    GroupingStore<GwtWifiChannelModel> grtoupingStore = new GroupingStore<GwtWifiChannelModel>();
    grtoupingStore.setMonitorChanges(true);
    grtoupingStore.add(GwtWifiChannelModel.getChannels());
    grtoupingStore.groupBy("band");
    ColumnConfig channel = new ColumnConfig("name", "All Available Channels", 20);
    ColumnConfig frequency = new ColumnConfig("frequency", "Frequency (MHz)", 10);
    ColumnConfig band = new ColumnConfig("band", "Spectrum Band", 20);
    List<ColumnConfig> channelColumnConfig = new ArrayList<ColumnConfig>();
    channelColumnConfig.add(m_checkboxChannelSelectionModel.getColumn());
    channelColumnConfig.add(channel);
    channelColumnConfig.add(frequency);
    channelColumnConfig.add(band);
    final ColumnModel columnModel = new ColumnModel(channelColumnConfig);
    m_channelGroupingView = new GroupingView() {

        @Override
        protected void onMouseDown(GridEvent<ModelData> ge) {
            El hd = ge.getTarget(".x-grid-group-hd", 10);
            El target = ge.getTargetEl();
            if (hd != null && target.hasStyleName(m_uncheckedStyle) || target.hasStyleName(m_checkedStyle)) {
                boolean checked = !ge.getTargetEl().hasStyleName(m_uncheckedStyle);
                checked = !checked;
                if (checked) {
                    ge.getTargetEl().replaceStyleName(m_uncheckedStyle, m_checkedStyle);
                } else {
                    ge.getTargetEl().replaceStyleName(m_checkedStyle, m_uncheckedStyle);
                }
                Element group = (Element) findGroup(ge.getTarget());
                if (group != null) {
                    NodeList<Element> rows = El.fly(group).select(".x-grid3-row");
                    List<ModelData> temp = new ArrayList<ModelData>();
                    for (int i = 0; i < rows.getLength(); i++) {
                        Element r = rows.getItem(i);
                        int idx = findRowIndex(r);
                        ModelData m = grid.getStore().getAt(idx);
                        temp.add(m);
                    }
                    if (checked) {
                        grid.getSelectionModel().select(temp, true);
                    } else {
                        grid.getSelectionModel().deselect(temp);
                    }
                }
                return;
            }
            super.onMouseDown(ge);
        }
    };
    m_channelGroupingView.setShowGroupedColumn(false);
    m_channelGroupingView.setForceFit(true);
    m_channelGroupingView.setShowDirtyCells(true);
    m_channelGroupingView.setGroupRenderer(new GridGroupRenderer() {

        public String render(GroupColumnData data) {
            String f = columnModel.getColumnById(data.field).getHeader();
            String l = data.models.size() == 1 ? "Item" : "Items";
            return "<div class='x-grid3-group-checker'><div class='" + m_uncheckedStyle + "'> </div></div> " + f + ": " + data.group + " (" + data.models.size() + " " + l + ")";
        }
    });
    final Grid<GwtWifiChannelModel> channelGrid = new Grid<GwtWifiChannelModel>(grtoupingStore, columnModel);
    channelGrid.setView(m_channelGroupingView);
    channelGrid.setBorders(true);
    channelGrid.addPlugin(m_checkboxChannelSelectionModel);
    channelGrid.setSelectionModel(m_checkboxChannelSelectionModel);
    channelGrid.addPlugin(m_dirtyPlugin);
    m_channelPanel = new ContentPanel();
    m_channelPanel.setHeading("Select Channel(s)");
    m_channelPanel.setCollapsible(true);
    m_channelPanel.setFrame(true);
    m_channelPanel.setSize(430, 200);
    m_channelPanel.setLayout(new FitLayout());
    m_channelPanel.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
    m_channelPanel.add(channelGrid);
    m_channelPanel.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netWifiToolTipChannels()));
    m_checkboxChannelSelectionModel.addSelectionChangedListener(new SelectionChangedListener<GwtWifiChannelModel>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtWifiChannelModel> se) {
            updateSelectedChannels(se.getSelection());
        }
    });
    // Adjust the number of channels shown based on defined property
    gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

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

        @Override
        public void onSuccess(GwtXSRFToken token) {
            gwtDeviceService.findDeviceConfiguration(token, new AsyncCallback<ListLoadResult<GwtGroupedNVPair>>() {

                public void onSuccess(ListLoadResult<GwtGroupedNVPair> results) {
                    if (results != null) {
                        List<GwtGroupedNVPair> pairs = results.getData();
                        if (pairs != null) {
                            for (GwtGroupedNVPair pair : pairs) {
                                String name = pair.getName();
                                if (name != null && name.equals("devLastWifiChannel")) {
                                    int topChannel = Integer.parseInt(pair.getValue());
                                    // Remove channels 12 and 13
                                    if (topChannel < MAX_WIFI_CHANNEL) {
                                        channelGrid.getStore().remove(MAX_WIFI_CHANNEL - 1);
                                        channelGrid.getStore().remove(MAX_WIFI_CHANNEL - 2);
                                    }
                                }
                            }
                        }
                    }
                }

                public void onFailure(Throwable caught) {
                    FailureHandler.handle(caught);
                }
            });
        }
    });
    fieldSet.add(m_modeCombo, formData);
    fieldSet.add(m_ssidField, formData);
    fieldSet.add(m_radioModeCombo, formData);
    fieldSet.add(m_securityCombo, formData);
    fieldSet.add(m_passwordField, formData);
    fieldSet.add(m_verifyPasswordField, formData);
    fieldSet.add(m_pairwiseCiphersCombo, formData);
    fieldSet.add(m_groupCiphersCombo, formData);
    fieldSet.add(m_bgscanModuleCombo, formData);
    fieldSet.add(m_bgscanRssiThresholdSliderField, formData);
    fieldSet.add(m_bgscanShortIntervalField, formData);
    fieldSet.add(m_bgscanLongIntervalField, formData);
    fieldSet.add(m_pingAccessPointRadioGroup, formData);
    fieldSet.add(m_ignoreSsidRadioGroup, formData);
    fieldSet.add(m_channelPanel, formData);
    if ((m_securityCombo.getSimpleValue().equals(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA2.name()))) || (m_securityCombo.getSimpleValue().equals(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA.name()))) || (m_securityCombo.getSimpleValue().equals(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA_WPA2.name())))) {
        if (GwtWifiWirelessMode.netWifiWirelessModeStation.equals(m_modeCombo.getValue().getMode())) {
            m_pairwiseCiphersCombo.setEnabled(true);
            m_groupCiphersCombo.setEnabled(true);
        } else {
            // m_pairwiseCiphersCombo.setEnabled(false); // enable it for AP mode as well
            m_pairwiseCiphersCombo.setEnabled(true);
            m_groupCiphersCombo.setEnabled(false);
        }
    } else {
        m_pairwiseCiphersCombo.setEnabled(false);
        m_groupCiphersCombo.setEnabled(false);
    }
    m_formPanel.add(fieldSet);
    m_formPanel.setScrollMode(Scroll.AUTO);
    add(m_formPanel);
    setScrollMode(Scroll.AUTOX);
    m_initialized = true;
}
Also used : RadioGroup(com.extjs.gxt.ui.client.widget.form.RadioGroup) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) SimpleComboValue(com.extjs.gxt.ui.client.widget.form.SimpleComboValue) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GwtWifiRadioMode(org.eclipse.kura.web.shared.model.GwtWifiRadioMode) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) GroupingStore(com.extjs.gxt.ui.client.store.GroupingStore) Button(com.extjs.gxt.ui.client.widget.button.Button) TextFieldWithButton(org.eclipse.kura.web.client.util.TextFieldWithButton) NodeList(com.google.gwt.dom.client.NodeList) List(java.util.List) ArrayList(java.util.ArrayList) FormData(com.extjs.gxt.ui.client.widget.layout.FormData) NodeList(com.google.gwt.dom.client.NodeList) GroupColumnData(com.extjs.gxt.ui.client.widget.grid.GroupColumnData) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) GwtWifiChannelModel(org.eclipse.kura.web.shared.model.GwtWifiChannelModel) GridGroupRenderer(com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer) GwtWifiSecurity(org.eclipse.kura.web.shared.model.GwtWifiSecurity) ComponentEvent(com.extjs.gxt.ui.client.event.ComponentEvent) ModelData(com.extjs.gxt.ui.client.data.ModelData) FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) GwtWifiCiphers(org.eclipse.kura.web.shared.model.GwtWifiCiphers) Slider(com.extjs.gxt.ui.client.widget.Slider) El(com.extjs.gxt.ui.client.core.El) Element(com.google.gwt.user.client.Element) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) GwtGroupedNVPair(org.eclipse.kura.web.shared.model.GwtGroupedNVPair) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) GwtWifiWirelessModeModel(org.eclipse.kura.web.shared.model.GwtWifiWirelessModeModel) GroupingView(com.extjs.gxt.ui.client.widget.grid.GroupingView) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) GwtWifiConfig(org.eclipse.kura.web.shared.model.GwtWifiConfig) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) Radio(com.extjs.gxt.ui.client.widget.form.Radio) GwtWifiBgscanModule(org.eclipse.kura.web.shared.model.GwtWifiBgscanModule) SliderField(com.extjs.gxt.ui.client.widget.form.SliderField) NumberField(com.extjs.gxt.ui.client.widget.form.NumberField) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) KeyListener(com.extjs.gxt.ui.client.event.KeyListener) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) Validator(com.extjs.gxt.ui.client.widget.form.Validator)

Example 8 with FormLayout

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

the class SslTab method initTabContent.

private void initTabContent() {
    LayoutContainer lcAction = new LayoutContainer();
    lcAction.setLayout(new BorderLayout());
    lcAction.setBorders(true);
    lcAction.setSize(475, -1);
    // center panel: action form
    BorderLayoutData centerData = new BorderLayoutData(LayoutRegion.CENTER, .75F);
    centerData.setSplit(false);
    centerData.setMargins(new Margins(0, 0, 0, 0));
    FormData formData = new FormData("-20");
    formData.setMargins(new Margins(0, 10, 0, 0));
    if (!UserAgentUtils.isIE()) {
        m_actionFormPanel = new FormPanel();
        m_actionFormPanel.setId("config-panel-id");
        m_actionFormPanel.setFrame(false);
        m_actionFormPanel.setBodyBorder(false);
        m_actionFormPanel.setHeaderVisible(false);
        m_actionFormPanel.setLabelWidth(Constants.LABEL_WIDTH_CONFIG_FORM);
        m_actionFormPanel.setStyleAttribute("padding", "0px");
        m_actionFormPanel.setScrollMode(Scroll.AUTO);
        m_actionFormPanel.setLayout(new FlowLayout());
        m_actionFormPanel.addListener(Events.Render, new Listener<BaseEvent>() {

            public void handleEvent(BaseEvent be) {
                NodeList<com.google.gwt.dom.client.Element> nl = m_actionFormPanel.getElement().getElementsByTagName("form");
                if (nl.getLength() > 0) {
                    com.google.gwt.dom.client.Element elemForm = nl.getItem(0);
                    elemForm.setAttribute("autocomplete", "off");
                }
            }
        });
        m_actionFormPanel.getElement().setAttribute("autocomplete", "off");
    }
    m_actionFieldSet = new FieldSet();
    m_actionFieldSet.setId("configuration-form");
    m_actionFieldSet.setBorders(false);
    m_actionFieldSet.setStyleAttribute("padding", "0px");
    m_actionFieldSet.setScrollMode(Scroll.AUTO);
    this.addListener(Events.Change, new Listener<BaseEvent>() {

        public void handleEvent(BaseEvent be) {
            m_apply.setEnabled(true);
            m_reset.setEnabled(true);
            m_dirty = true;
        }
    });
    FormLayout layout = new FormLayout();
    layout.setLabelWidth(Constants.LABEL_WIDTH_CONFIG_FORM);
    m_actionFieldSet.setLayout(layout);
    loadData();
    // 
    // Initial description
    // 
    LayoutContainer description = new LayoutContainer();
    description.setBorders(false);
    description.setLayout(new ColumnLayout());
    Label descriptionLabel = new Label(MSGS.settingsSSLConfigurationDescription());
    description.add(descriptionLabel);
    description.setStyleAttribute("padding-bottom", "10px");
    m_actionFieldSet.add(description);
    // 
    // SSL protocol
    // 
    m_protocol = new TextField<String>();
    m_protocol.setName(MSGS.settingsSSLConfigurationProtocol());
    m_protocol.setPassword(false);
    m_protocol.setAllowBlank(false);
    m_protocol.setFieldLabel(MSGS.settingsSSLConfigurationProtocol());
    m_protocol.addPlugin(m_dirtyPlugin);
    m_protocol.addPlugin(m_infoPlugin);
    m_protocol.setData("text", MSGS.settingsSSLConfigurationProtocolDescr());
    m_actionFieldSet.add(m_protocol, formData);
    // 
    // SSL hostname verification
    // 
    m_trueRadio = new Radio();
    m_trueRadio.setBoxLabel(MSGS.trueLabel());
    m_trueRadio.setItemId("true");
    m_falseRadio = new Radio();
    m_falseRadio.setBoxLabel(MSGS.falseLabel());
    m_falseRadio.setValueAttribute("false");
    m_hostnameVerification = new RadioGroup();
    m_hostnameVerification.setName(MSGS.settingsSSLConfigurationHostnameVerification());
    m_hostnameVerification.setItemId(MSGS.settingsSSLConfigurationHostnameVerification());
    m_hostnameVerification.setFieldLabel(MSGS.settingsSSLConfigurationHostnameVerification());
    m_hostnameVerification.add(m_trueRadio);
    m_hostnameVerification.add(m_falseRadio);
    m_hostnameVerification.addPlugin(m_infoPlugin);
    m_hostnameVerification.addPlugin(m_dirtyPlugin);
    m_hostnameVerification.setData("text", MSGS.settingsSSLConfigurationHostnameVerificationDescr());
    m_actionFieldSet.add(m_hostnameVerification, formData);
    // 
    // SSL keystore
    // 
    m_keystorePath = new TextField<String>();
    m_keystorePath.setName(MSGS.settingsSSLConfigurationKeystorePath());
    m_keystorePath.setPassword(false);
    m_keystorePath.setAllowBlank(false);
    m_keystorePath.setFieldLabel(MSGS.settingsSSLConfigurationKeystorePath());
    m_keystorePath.addPlugin(m_dirtyPlugin);
    m_keystorePath.addPlugin(m_infoPlugin);
    m_keystorePath.setData("text", MSGS.settingsSSLConfigurationKeystorePathDescr());
    m_actionFieldSet.add(m_keystorePath, formData);
    // 
    // SSL keystore password
    // 
    m_keystorePassword = new TextField<String>();
    m_keystorePassword.setName(MSGS.settingsSSLConfigurationKeystorePassword());
    m_keystorePassword.setPassword(true);
    m_keystorePassword.setAllowBlank(false);
    m_keystorePassword.setFieldLabel(MSGS.settingsSSLConfigurationKeystorePassword());
    m_keystorePassword.addPlugin(m_dirtyPlugin);
    m_keystorePassword.addPlugin(m_infoPlugin);
    m_keystorePassword.setData("text", MSGS.settingsSSLConfigurationKeystorePasswordDescr());
    m_actionFieldSet.add(m_keystorePassword, formData);
    // 
    // SSL cipher suites
    // 
    m_cipherSuites = new TextField<String>();
    m_cipherSuites.setName(MSGS.settingsSSLConfigurationCipherSuites());
    m_cipherSuites.setPassword(false);
    m_cipherSuites.setAllowBlank(true);
    m_cipherSuites.setFieldLabel(MSGS.settingsSSLConfigurationCipherSuites());
    m_cipherSuites.addPlugin(m_dirtyPlugin);
    m_cipherSuites.addPlugin(m_infoPlugin);
    m_cipherSuites.setData("text", MSGS.settingsSSLConfigurationCipherSuitesDescr());
    m_actionFieldSet.add(m_cipherSuites, formData);
    if (!UserAgentUtils.isIE()) {
        m_actionFormPanel.add(m_actionFieldSet, formData);
        lcAction.add(m_actionFormPanel, centerData);
    } else {
        lcAction.add(m_actionFieldSet, centerData);
    }
    m_tabContent = lcAction;
}
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) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) NodeList(com.google.gwt.dom.client.NodeList) Element(com.google.gwt.user.client.Element) Label(com.google.gwt.user.client.ui.Label) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) Radio(com.extjs.gxt.ui.client.widget.form.Radio) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) BorderLayout(com.extjs.gxt.ui.client.widget.layout.BorderLayout) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer) ColumnLayout(com.extjs.gxt.ui.client.widget.layout.ColumnLayout) Margins(com.extjs.gxt.ui.client.util.Margins)

Example 9 with FormLayout

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

the class HardwareConfigTab method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FitLayout());
    setId("network-hardware");
    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.setScrollMode(Scroll.AUTOY);
    m_formPanel.setLayout(new FlowLayout());
    m_formPanel.setStyleAttribute("padding-left", "30px");
    FieldSet fieldSet = new FieldSet();
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(Constants.LABEL_WIDTH_FORM + 20);
    fieldSet.setLayout(layoutAccount);
    fieldSet.setBorders(false);
    // state
    m_stateField = new LabelField();
    m_stateField.setFieldLabel(MSGS.netHwState());
    fieldSet.add(m_stateField, formData);
    // name
    m_nameField = new LabelField();
    m_nameField.setFieldLabel(MSGS.netHwName());
    fieldSet.add(m_nameField, formData);
    // type
    m_typeField = new LabelField();
    m_typeField.setFieldLabel(MSGS.netHwType());
    fieldSet.add(m_typeField, formData);
    // hardware address
    m_addressField = new LabelField();
    m_addressField.setFieldLabel(MSGS.netHwAddress());
    fieldSet.add(m_addressField, formData);
    // serial num
    m_serialField = new LabelField();
    m_serialField.setFieldLabel(MSGS.netHwSerial());
    fieldSet.add(m_serialField, formData);
    // driver
    m_driverField = new LabelField();
    m_driverField.setFieldLabel(MSGS.netHwDriver());
    fieldSet.add(m_driverField, formData);
    // driver version
    m_versionField = new LabelField();
    m_versionField.setFieldLabel(MSGS.netHwVersion());
    fieldSet.add(m_versionField, formData);
    // firmware version
    m_firmwareField = new LabelField();
    m_firmwareField.setFieldLabel(MSGS.netHwFirmware());
    fieldSet.add(m_firmwareField, formData);
    // mtu
    m_mtuField = new LabelField();
    m_mtuField.setFieldLabel(MSGS.netHwMTU());
    fieldSet.add(m_mtuField, formData);
    // usb device
    m_usbField = new LabelField();
    m_usbField.setFieldLabel(MSGS.netHwUSBDevice());
    fieldSet.add(m_usbField, formData);
    // RSSI
    m_rssiField = new LabelField();
    m_rssiField.setFieldLabel(MSGS.netHwSignalStrength());
    fieldSet.add(m_rssiField, formData);
    m_formPanel.add(fieldSet);
    add(m_formPanel);
    m_initialized = true;
}
Also used : FormData(com.extjs.gxt.ui.client.widget.layout.FormData) FormLayout(com.extjs.gxt.ui.client.widget.layout.FormLayout) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) FormPanel(com.extjs.gxt.ui.client.widget.form.FormPanel) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout)

Example 10 with FormLayout

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

the class OpenPortForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setId("firewall-open-port-form-wrapper");
    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());
    FieldSet fieldSet = new FieldSet();
    fieldSet.setHeading(MSGS.firewallOpenPortFormInformation());
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSet.setLayout(layoutAccount);
    // 
    // port (or range of ports) to be opened for inbound connections
    // 
    final LabelField portLabel = new LabelField();
    portLabel.setName("portLabel");
    portLabel.setFieldLabel(MSGS.firewallOpenPortFormPort());
    portLabel.setLabelSeparator(":");
    fieldSet.add(portLabel, formData);
    final TextField<String> portField = new TextField<String>();
    portField.setAllowBlank(false);
    portField.setName("port");
    portField.setFieldLabel(MSGS.firewallOpenPortFormPort());
    portField.setValidator(new TextFieldValidator(portField, FieldType.PORT_RANGE));
    portField.setToolTip(MSGS.firewallOpenPortFormPortToolTip());
    fieldSet.add(portField, formData);
    // 
    // protocol
    // 
    final LabelField protocolLabel = new LabelField();
    protocolLabel.setName("protocolLabel");
    protocolLabel.setFieldLabel(MSGS.firewallOpenPortFormProtocol());
    protocolLabel.setLabelSeparator(":");
    fieldSet.add(protocolLabel, formData);
    final SimpleComboBox<String> protocolCombo = new SimpleComboBox<String>();
    protocolCombo.setName("protocolCombo");
    protocolCombo.setFieldLabel(MSGS.firewallOpenPortFormProtocol());
    protocolCombo.setEditable(false);
    protocolCombo.setTypeAhead(true);
    protocolCombo.setTriggerAction(TriggerAction.ALL);
    for (GwtNetProtocol protocol : GwtNetProtocol.values()) {
        protocolCombo.add(protocol.name());
    }
    protocolCombo.setSimpleValue(GwtNetProtocol.tcp.name());
    protocolCombo.setToolTip(MSGS.firewallOpenPortFormProtocolToolTip());
    fieldSet.add(protocolCombo, formData);
    // 
    // permitted network
    // 
    final TextField<String> permittedNetworkField = new TextField<String>();
    permittedNetworkField.setAllowBlank(true);
    permittedNetworkField.setName("permittedNetwork");
    permittedNetworkField.setFieldLabel(MSGS.firewallOpenPortFormPermittedNetwork());
    permittedNetworkField.setValidator(new TextFieldValidator(permittedNetworkField, FieldType.NETWORK));
    permittedNetworkField.setToolTip(MSGS.firewallOpenPortFormPermittedNetworkToolTip());
    fieldSet.add(permittedNetworkField, formData);
    // 
    // permitted network interface
    // 
    m_permittedInterfaceName = new TextField<String>();
    m_permittedInterfaceName.setAllowBlank(true);
    m_permittedInterfaceName.setName("permittedInterfaceName");
    m_permittedInterfaceName.setFieldLabel(MSGS.firewallOpenPortFormPermittedInterfaceName());
    m_permittedInterfaceName.setValidator(new TextFieldValidator(m_permittedInterfaceName, FieldType.ALPHANUMERIC));
    m_permittedInterfaceName.setToolTip(MSGS.firewallOpenPortFormPermittedInterfaceToolTip());
    m_permittedInterfaceName.addListener(Events.Change, new Listener<FieldEvent>() {

        public void handleEvent(FieldEvent be) {
            if (be.getValue() != null) {
                m_unpermittedInterfaceName.disable();
            } else {
                m_unpermittedInterfaceName.enable();
            }
        }
    });
    fieldSet.add(m_permittedInterfaceName, formData);
    // 
    // unpermitted network interface
    // 
    m_unpermittedInterfaceName = new TextField<String>();
    m_unpermittedInterfaceName.setAllowBlank(true);
    m_unpermittedInterfaceName.setName("unpermittedInterfaceName");
    m_unpermittedInterfaceName.setFieldLabel(MSGS.firewallOpenPortFormUnpermittedInterfaceName());
    m_unpermittedInterfaceName.setValidator(new TextFieldValidator(m_unpermittedInterfaceName, FieldType.ALPHANUMERIC));
    m_unpermittedInterfaceName.setToolTip(MSGS.firewallOpenPortFormUnpermittedInterfaceToolTip());
    m_unpermittedInterfaceName.addListener(Events.Change, new Listener<FieldEvent>() {

        public void handleEvent(FieldEvent be) {
            if (be.getValue() != null) {
                m_permittedInterfaceName.disable();
            } else {
                m_permittedInterfaceName.enable();
            }
        }
    });
    fieldSet.add(m_unpermittedInterfaceName, formData);
    // 
    // permitted MAC
    // 
    final TextField<String> permittedMacField = new TextField<String>();
    permittedMacField.setAllowBlank(true);
    permittedMacField.setName("permittedMac");
    permittedMacField.setFieldLabel(MSGS.firewallOpenPortFormPermittedMac());
    permittedMacField.setValidator(new TextFieldValidator(permittedMacField, FieldType.MAC_ADDRESS));
    permittedMacField.setToolTip(MSGS.firewallOpenPortFormPermittedMacAddress());
    fieldSet.add(permittedMacField, formData);
    // 
    // source port range
    // 
    final TextField<String> sourcePortRangeField = new TextField<String>();
    sourcePortRangeField.setAllowBlank(true);
    sourcePortRangeField.setName("sourcePortRange");
    sourcePortRangeField.setFieldLabel(MSGS.firewallOpenPortFormSourcePortRange());
    sourcePortRangeField.setValidator(new TextFieldValidator(sourcePortRangeField, FieldType.PORT_RANGE));
    sourcePortRangeField.setToolTip(MSGS.firewallOpenPortFormSourcePortRangeToolTip());
    fieldSet.add(sourcePortRangeField, formData);
    // add the fieldSet to the panel
    m_formPanel.add(fieldSet);
    // disable the labels
    portLabel.setVisible(false);
    protocolLabel.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());
    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()) {
                    return;
                }
            }
            Log.debug("Open port fields are visible and valid...");
            // we need to add a new row to the open ports table
            if (m_existingOpenPortEntry == null) {
                // create a new entry
                m_newOpenPortEntry = new GwtFirewallOpenPortEntry();
                m_newOpenPortEntry.setPortRange(portField.getValue());
                m_newOpenPortEntry.setProtocol(protocolCombo.getValue().getValue());
                if (permittedNetworkField.getValue() != null) {
                    m_newOpenPortEntry.setPermittedNetwork(permittedNetworkField.getValue());
                } else {
                    m_newOpenPortEntry.setPermittedNetwork("0.0.0.0/0");
                }
                if (m_permittedInterfaceName.getValue() != null) {
                    m_newOpenPortEntry.setPermittedInterfaceName(m_permittedInterfaceName.getValue());
                }
                if (m_unpermittedInterfaceName.getValue() != null) {
                    m_newOpenPortEntry.setUnpermittedInterfaceName(m_unpermittedInterfaceName.getValue());
                }
                if (permittedMacField.getValue() != null) {
                    m_newOpenPortEntry.setPermittedMAC(permittedMacField.getValue());
                }
                if (sourcePortRangeField.getValue() != null) {
                    m_newOpenPortEntry.setSourcePortRange(sourcePortRangeField.getValue());
                }
            } else {
                // update the current entry
                m_existingOpenPortEntry = new GwtFirewallOpenPortEntry();
                m_existingOpenPortEntry.setPortRange(portField.getValue());
                m_existingOpenPortEntry.setProtocol(protocolCombo.getValue().getValue());
                if (permittedNetworkField.getValue() != null) {
                    m_existingOpenPortEntry.setPermittedNetwork(permittedNetworkField.getValue());
                } else {
                    m_existingOpenPortEntry.setPermittedNetwork("0.0.0.0/0");
                }
                if (m_permittedInterfaceName.getValue() != null) {
                    m_existingOpenPortEntry.setPermittedInterfaceName(m_permittedInterfaceName.getValue());
                }
                if (m_unpermittedInterfaceName.getValue() != null) {
                    m_existingOpenPortEntry.setUnpermittedInterfaceName(m_unpermittedInterfaceName.getValue());
                }
                if (permittedMacField.getValue() != null) {
                    m_existingOpenPortEntry.setPermittedMAC(permittedMacField.getValue());
                }
                if (sourcePortRangeField.getValue() != null) {
                    m_existingOpenPortEntry.setSourcePortRange(sourcePortRangeField.getValue());
                }
            }
            m_isCanceled = false;
            hide();
        }
    }));
    m_formPanel.addButton(new Button(MSGS.cancelButton(), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            m_isCanceled = true;
            hide();
        }
    }));
    m_formPanel.setButtonAlign(HorizontalAlignment.CENTER);
    // populate if necessary
    if (m_existingOpenPortEntry != null) {
        portLabel.setValue(m_existingOpenPortEntry.getPortRange());
        portField.setValue(m_existingOpenPortEntry.getPortRange());
        portField.setOriginalValue(m_existingOpenPortEntry.getPortRange());
        protocolLabel.setValue(m_existingOpenPortEntry.getProtocol());
        protocolCombo.setSimpleValue(m_existingOpenPortEntry.getProtocol());
        permittedNetworkField.setValue(m_existingOpenPortEntry.getPermittedNetwork());
        permittedNetworkField.setOriginalValue(m_existingOpenPortEntry.getPermittedNetwork());
        m_permittedInterfaceName.setValue(m_existingOpenPortEntry.getPermittedInterfaceName());
        m_permittedInterfaceName.setOriginalValue(m_existingOpenPortEntry.getPermittedInterfaceName());
        m_unpermittedInterfaceName.setValue(m_existingOpenPortEntry.getUnpermittedInterfaceName());
        m_unpermittedInterfaceName.setOriginalValue(m_existingOpenPortEntry.getUnpermittedInterfaceName());
        permittedMacField.setValue(m_existingOpenPortEntry.getPermittedMAC());
        permittedMacField.setOriginalValue(m_existingOpenPortEntry.getPermittedMAC());
        sourcePortRangeField.setValue(m_existingOpenPortEntry.getSourcePortRange());
        sourcePortRangeField.setOriginalValue(m_existingOpenPortEntry.getSourcePortRange());
    }
    add(m_formPanel);
}
Also used : 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) SimpleComboBox(com.extjs.gxt.ui.client.widget.form.SimpleComboBox) GwtFirewallOpenPortEntry(org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry) FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) FieldEvent(com.extjs.gxt.ui.client.event.FieldEvent) GwtNetProtocol(org.eclipse.kura.web.shared.model.GwtNetProtocol) 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) TextField(com.extjs.gxt.ui.client.widget.form.TextField) TextFieldValidator(org.eclipse.kura.web.client.util.TextFieldValidator) LabelField(com.extjs.gxt.ui.client.widget.form.LabelField) FillToolItem(com.extjs.gxt.ui.client.widget.toolbar.FillToolItem) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

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