Search in sources :

Example 1 with GwtNetProtocol

use of org.eclipse.kura.web.shared.model.GwtNetProtocol in project kura by eclipse.

the class PortForwardingTabUi method setModalFieldsValues.

private void setModalFieldsValues(final GwtFirewallPortForwardEntry existingEntry) {
    // set ListBoxes
    this.protocol.clear();
    for (GwtNetProtocol prot : GwtNetProtocol.values()) {
        this.protocol.addItem(prot.name());
    }
    this.enable.clear();
    for (GwtFirewallNatMasquerade masquerade : GwtFirewallNatMasquerade.values()) {
        this.enable.addItem(masquerade.name());
    }
    // populate Existing Values
    if (existingEntry != null) {
        this.input.setText(existingEntry.getInboundInterface());
        this.output.setText(existingEntry.getOutboundInterface());
        this.lan.setText(existingEntry.getAddress());
        this.external.setText(String.valueOf(existingEntry.getOutPort()));
        this.internal.setText(String.valueOf(existingEntry.getInPort()));
        this.permittedNw.setText(existingEntry.getPermittedNetwork());
        this.permittedMac.setText(existingEntry.getPermittedMAC());
        this.source.setText(existingEntry.getSourcePortRange());
        for (int i = 0; i < this.protocol.getItemCount(); i++) {
            if (existingEntry.getProtocol().equals(this.protocol.getItemText(i))) {
                this.protocol.setSelectedIndex(i);
                break;
            }
        }
        for (int i = 0; i < this.enable.getItemCount(); i++) {
            if (existingEntry.getMasquerade().equals(this.enable.getItemText(i))) {
                this.enable.setSelectedIndex(i);
                break;
            }
        }
    } else {
        this.input.reset();
        this.output.reset();
        this.lan.reset();
        this.external.reset();
        this.internal.reset();
        this.permittedNw.reset();
        this.permittedMac.reset();
        this.source.reset();
        this.protocol.setSelectedIndex(0);
        this.enable.setSelectedIndex(0);
    }
}
Also used : GwtFirewallNatMasquerade(org.eclipse.kura.web.shared.model.GwtFirewallNatMasquerade) GwtNetProtocol(org.eclipse.kura.web.shared.model.GwtNetProtocol)

Example 2 with GwtNetProtocol

use of org.eclipse.kura.web.shared.model.GwtNetProtocol 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)

Example 3 with GwtNetProtocol

use of org.eclipse.kura.web.shared.model.GwtNetProtocol in project kura by eclipse.

the class PortForwardForm method onRender.

protected void onRender(Element parent, int index) {
    super.onRender(parent, index);
    setId("firewall-port-forwarding-form");
    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.firewallPortForwardFormInformation());
    FormLayout layoutAccount = new FormLayout();
    layoutAccount.setLabelWidth(LABEL_WIDTH_FORM);
    fieldSet.setLayout(layoutAccount);
    // 
    // in-bound interface
    // 
    final LabelField inboundInterfaceLabel = new LabelField();
    inboundInterfaceLabel.setName("inboundInterfaceLabel");
    inboundInterfaceLabel.setFieldLabel(MSGS.firewallPortForwardFormInboundInterface());
    inboundInterfaceLabel.setLabelSeparator(":");
    fieldSet.add(inboundInterfaceLabel, formData);
    final TextField<String> inboundInterfaceField = new TextField<String>();
    inboundInterfaceField.setAllowBlank(false);
    inboundInterfaceField.setName("interfaceName");
    inboundInterfaceField.setFieldLabel(MSGS.firewallPortForwardFormInboundInterface());
    inboundInterfaceField.setToolTip(MSGS.firewallPortForwardFormInboundInterfaceToolTip());
    inboundInterfaceField.setValidator(new TextFieldValidator(inboundInterfaceField, FieldType.ALPHANUMERIC));
    fieldSet.add(inboundInterfaceField, formData);
    // 
    // out-bound interface
    // 
    final LabelField outboundInterfaceLabel = new LabelField();
    outboundInterfaceLabel.setName("inboundInterfaceLabel");
    outboundInterfaceLabel.setFieldLabel(MSGS.firewallPortForwardFormOutboundInterface());
    outboundInterfaceLabel.setLabelSeparator(":");
    fieldSet.add(outboundInterfaceLabel, formData);
    final TextField<String> outboundInterfaceField = new TextField<String>();
    outboundInterfaceField.setAllowBlank(false);
    outboundInterfaceField.setName("interfaceName");
    outboundInterfaceField.setFieldLabel(MSGS.firewallPortForwardFormOutboundInterface());
    outboundInterfaceField.setToolTip(MSGS.firewallPortForwardFormOutboundInterfaceToolTip());
    outboundInterfaceField.setValidator(new TextFieldValidator(outboundInterfaceField, FieldType.ALPHANUMERIC));
    fieldSet.add(outboundInterfaceField, formData);
    // 
    // address
    // 
    final LabelField addressLabel = new LabelField();
    addressLabel.setName("addressLabel");
    addressLabel.setFieldLabel(MSGS.firewallPortForwardFormAddress());
    addressLabel.setLabelSeparator(":");
    fieldSet.add(addressLabel, formData);
    final TextField<String> addressField = new TextField<String>();
    addressField.setAllowBlank(false);
    addressField.setName("address");
    addressField.setFieldLabel(MSGS.firewallPortForwardFormAddress());
    addressField.setToolTip(MSGS.firewallPortForwardFormLanAddressToolTip());
    addressField.setValidator(new TextFieldValidator(addressField, FieldType.IPv4_ADDRESS));
    fieldSet.add(addressField, formData);
    // 
    // protocol
    // 
    final LabelField protocolLabel = new LabelField();
    protocolLabel.setName("protocolLabel");
    protocolLabel.setFieldLabel(MSGS.firewallPortForwardFormProtocol());
    protocolLabel.setLabelSeparator(":");
    fieldSet.add(protocolLabel, formData);
    final SimpleComboBox<String> protocolCombo = new SimpleComboBox<String>();
    protocolCombo.setName("protocolCombo");
    protocolCombo.setFieldLabel(MSGS.firewallPortForwardFormProtocol());
    protocolCombo.setEditable(false);
    protocolCombo.setTypeAhead(true);
    protocolCombo.setTriggerAction(TriggerAction.ALL);
    protocolCombo.setToolTip(MSGS.firewallPortForwardFormProtocolToolTip());
    for (GwtNetProtocol protocol : GwtNetProtocol.values()) {
        protocolCombo.add(protocol.name());
    }
    protocolCombo.setSimpleValue(GwtNetProtocol.tcp.name());
    fieldSet.add(protocolCombo, formData);
    // 
    // in port number
    // 
    final LabelField inPortLabel = new LabelField();
    inPortLabel.setName("inPortLabel");
    inPortLabel.setFieldLabel(MSGS.firewallPortForwardFormInPort());
    inPortLabel.setLabelSeparator(":");
    fieldSet.add(inPortLabel, formData);
    final TextField<String> inPortField = new TextField<String>();
    inPortField.setAllowBlank(false);
    inPortField.setName("inPort");
    inPortField.setFieldLabel(MSGS.firewallPortForwardFormInPort());
    inPortField.setToolTip(MSGS.firewallPortForwardFormExternalPortToolTip());
    inPortField.setValidator(new TextFieldValidator(inPortField, FieldType.NUMERIC));
    fieldSet.add(inPortField, formData);
    // 
    // out port number
    // 
    final LabelField outPortLabel = new LabelField();
    outPortLabel.setName("outPortLabel");
    outPortLabel.setFieldLabel(MSGS.firewallPortForwardFormOutPort());
    outPortLabel.setLabelSeparator(":");
    fieldSet.add(outPortLabel, formData);
    final TextField<String> outPortField = new TextField<String>();
    outPortField.setAllowBlank(false);
    outPortField.setName("outPort");
    outPortField.setFieldLabel(MSGS.firewallPortForwardFormOutPort());
    outPortField.setToolTip(MSGS.firewallPortForwardFormInternalPortToolTip());
    outPortField.setValidator(new TextFieldValidator(outPortField, FieldType.NUMERIC));
    fieldSet.add(outPortField, formData);
    // 
    // masquerade
    // 
    final LabelField masqueradeLabel = new LabelField();
    masqueradeLabel.setName("masqueradeLabel");
    masqueradeLabel.setFieldLabel(MSGS.firewallNatFormMasquerade());
    masqueradeLabel.setLabelSeparator(":");
    fieldSet.add(masqueradeLabel, formData);
    final SimpleComboBox<String> masqueradeCombo = new SimpleComboBox<String>();
    masqueradeCombo.setName("masqueradeCombo");
    masqueradeCombo.setFieldLabel(MSGS.firewallNatFormMasquerade());
    masqueradeCombo.setEditable(false);
    masqueradeCombo.setTypeAhead(true);
    masqueradeCombo.setTriggerAction(TriggerAction.ALL);
    masqueradeCombo.setToolTip(MSGS.firewallPortForwardFormMasqueradingToolTip());
    for (GwtFirewallNatMasquerade masquerade : GwtFirewallNatMasquerade.values()) {
        masqueradeCombo.add(masquerade.name());
    }
    masqueradeCombo.setSimpleValue(GwtFirewallNatMasquerade.no.name());
    fieldSet.add(masqueradeCombo, formData);
    // 
    // permitted network
    // 
    final LabelField permittedNetworkLabel = new LabelField();
    permittedNetworkLabel.setName("permittedNetworkLabel");
    permittedNetworkLabel.setFieldLabel(MSGS.firewallPortForwardFormPermittedNetwork());
    permittedNetworkLabel.setLabelSeparator(":");
    fieldSet.add(permittedNetworkLabel, formData);
    final TextField<String> permittedNetworkField = new TextField<String>();
    permittedNetworkField.setAllowBlank(true);
    permittedNetworkField.setName("permittedNetwork");
    permittedNetworkField.setFieldLabel(MSGS.firewallPortForwardFormPermittedNetwork());
    permittedNetworkField.setToolTip(MSGS.firewallPortForwardFormPermittedNetworkToolTip());
    permittedNetworkField.setValidator(new TextFieldValidator(permittedNetworkField, FieldType.NETWORK));
    fieldSet.add(permittedNetworkField, formData);
    // 
    // permitted MAC
    // 
    final LabelField permittedMacLabel = new LabelField();
    permittedMacLabel.setName("permittedMacLabel");
    permittedMacLabel.setFieldLabel(MSGS.firewallPortForwardFormPermittedMac());
    permittedMacLabel.setLabelSeparator(":");
    fieldSet.add(permittedMacLabel, formData);
    final TextField<String> permittedMacField = new TextField<String>();
    permittedMacField.setAllowBlank(true);
    permittedMacField.setName("permittedMac");
    permittedMacField.setFieldLabel(MSGS.firewallPortForwardFormPermittedMac());
    permittedMacField.setToolTip(MSGS.firewallPortForwardFormPermittedMacAddressToolTip());
    permittedMacField.setValidator(new TextFieldValidator(permittedMacField, FieldType.MAC_ADDRESS));
    fieldSet.add(permittedMacField, formData);
    // 
    // source port range
    // 
    final LabelField sourcePortRangeLabel = new LabelField();
    sourcePortRangeLabel.setName("sourcePortRangeLabel");
    sourcePortRangeLabel.setFieldLabel(MSGS.firewallPortForwardFormSourcePortRange());
    sourcePortRangeLabel.setLabelSeparator(":");
    fieldSet.add(sourcePortRangeLabel, formData);
    final TextField<String> sourcePortRangeField = new TextField<String>();
    sourcePortRangeField.setAllowBlank(true);
    sourcePortRangeField.setName("sourcePortRange");
    sourcePortRangeField.setFieldLabel(MSGS.firewallPortForwardFormSourcePortRange());
    sourcePortRangeField.setToolTip(MSGS.firewallPortForwardFormSourcePortRangeToolTip());
    sourcePortRangeField.setValidator(new TextFieldValidator(sourcePortRangeField, FieldType.PORT_RANGE));
    fieldSet.add(sourcePortRangeField, formData);
    // add the fieldSet to the panel
    m_formPanel.add(fieldSet);
    // disable the labels
    inboundInterfaceLabel.setVisible(false);
    outboundInterfaceLabel.setVisible(false);
    addressLabel.setVisible(false);
    protocolLabel.setVisible(false);
    inPortLabel.setVisible(false);
    outPortLabel.setVisible(false);
    masqueradeLabel.setVisible(false);
    permittedNetworkLabel.setVisible(false);
    permittedMacLabel.setVisible(false);
    sourcePortRangeLabel.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;
                }
            }
            // we need to add a new row to the open ports table
            if (m_existingEntry == null) {
                // create a new entry
                m_newEntry = new GwtFirewallPortForwardEntry();
                m_newEntry.setInboundInterface(inboundInterfaceField.getValue());
                m_newEntry.setOutboundInterface(outboundInterfaceField.getValue());
                m_newEntry.setAddress(addressField.getValue());
                m_newEntry.setProtocol(protocolCombo.getValue().getValue());
                m_newEntry.setInPort(Integer.parseInt(inPortField.getValue()));
                m_newEntry.setOutPort(Integer.parseInt(outPortField.getValue()));
                m_newEntry.setMasquerade(masqueradeCombo.getValue().getValue());
                m_newEntry.setPermittedNetwork(permittedNetworkField.getValue());
                m_newEntry.setPermittedMAC(permittedMacField.getValue());
                m_newEntry.setSourcePortRange(sourcePortRangeField.getValue());
                if (m_newEntry.getPermittedMAC() != null) {
                    MessageBox.alert(MSGS.firewallPortForwardFormNotification(), MSGS.firewallPortForwardFormNotificationMacFiltering(), null);
                }
            } else {
                // update the current entry
                m_existingEntry = new GwtFirewallPortForwardEntry();
                m_existingEntry.setInboundInterface(inboundInterfaceField.getValue());
                m_existingEntry.setOutboundInterface(outboundInterfaceField.getValue());
                m_existingEntry.setAddress(addressField.getValue());
                m_existingEntry.setProtocol(protocolCombo.getValue().getValue());
                m_existingEntry.setInPort(Integer.parseInt(inPortField.getValue()));
                m_existingEntry.setOutPort(Integer.parseInt(outPortField.getValue()));
                m_existingEntry.setMasquerade(masqueradeCombo.getValue().getValue());
                m_existingEntry.setPermittedNetwork(permittedNetworkField.getValue());
                m_existingEntry.setPermittedMAC(permittedMacField.getValue());
                m_existingEntry.setSourcePortRange(sourcePortRangeField.getValue());
                if (m_existingEntry.getPermittedMAC() != null) {
                    MessageBox.alert(MSGS.firewallPortForwardFormNotification(), MSGS.firewallPortForwardFormNotificationMacFiltering(), null);
                }
            }
            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_existingEntry != null) {
        inboundInterfaceLabel.setValue(m_existingEntry.getInboundInterface());
        inboundInterfaceField.setValue(m_existingEntry.getInboundInterface());
        inboundInterfaceField.setOriginalValue(m_existingEntry.getInboundInterface());
        outboundInterfaceLabel.setValue(m_existingEntry.getOutboundInterface());
        outboundInterfaceField.setValue(m_existingEntry.getOutboundInterface());
        outboundInterfaceField.setOriginalValue(m_existingEntry.getOutboundInterface());
        addressLabel.setValue(m_existingEntry.getAddress());
        addressField.setValue(m_existingEntry.getAddress());
        addressField.setOriginalValue(m_existingEntry.getAddress());
        protocolLabel.setValue(m_existingEntry.getProtocol());
        protocolCombo.setSimpleValue(m_existingEntry.getProtocol());
        inPortLabel.setValue(m_existingEntry.getInPort());
        inPortField.setValue(m_existingEntry.getInPort().toString());
        inPortField.setOriginalValue(m_existingEntry.getInPort().toString());
        outPortField.setValue(m_existingEntry.getOutPort().toString());
        outPortField.setOriginalValue(m_existingEntry.getOutPort().toString());
        masqueradeCombo.setSimpleValue(m_existingEntry.getMasquerade());
        permittedNetworkField.setValue(m_existingEntry.getPermittedNetwork());
        permittedNetworkField.setOriginalValue(m_existingEntry.getPermittedNetwork());
        permittedMacField.setValue(m_existingEntry.getPermittedMAC());
        permittedMacField.setOriginalValue(m_existingEntry.getPermittedMAC());
        sourcePortRangeField.setValue(m_existingEntry.getSourcePortRange());
        sourcePortRangeField.setOriginalValue(m_existingEntry.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) FlowLayout(com.extjs.gxt.ui.client.widget.layout.FlowLayout) GwtFirewallNatMasquerade(org.eclipse.kura.web.shared.model.GwtFirewallNatMasquerade) 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) GwtFirewallPortForwardEntry(org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry) 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

GwtNetProtocol (org.eclipse.kura.web.shared.model.GwtNetProtocol)3 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)2 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)2 Status (com.extjs.gxt.ui.client.widget.Status)2 Button (com.extjs.gxt.ui.client.widget.button.Button)2 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)2 FormPanel (com.extjs.gxt.ui.client.widget.form.FormPanel)2 LabelField (com.extjs.gxt.ui.client.widget.form.LabelField)2 SimpleComboBox (com.extjs.gxt.ui.client.widget.form.SimpleComboBox)2 TextField (com.extjs.gxt.ui.client.widget.form.TextField)2 FlowLayout (com.extjs.gxt.ui.client.widget.layout.FlowLayout)2 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)2 FormLayout (com.extjs.gxt.ui.client.widget.layout.FormLayout)2 FillToolItem (com.extjs.gxt.ui.client.widget.toolbar.FillToolItem)2 TextFieldValidator (org.eclipse.kura.web.client.util.TextFieldValidator)2 GwtFirewallNatMasquerade (org.eclipse.kura.web.shared.model.GwtFirewallNatMasquerade)2 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 GwtFirewallOpenPortEntry (org.eclipse.kura.web.shared.model.GwtFirewallOpenPortEntry)1 GwtFirewallPortForwardEntry (org.eclipse.kura.web.shared.model.GwtFirewallPortForwardEntry)1