use of org.eclipse.kura.web.shared.model.GwtNetIfConfigMode in project kura by eclipse.
the class TabTcpIpUi method initForm.
// ---------------Private Methods------------
private void initForm() {
// Labels
this.labelStatus.setText(MSGS.netIPv4Status());
this.labelConfigure.setText(MSGS.netIPv4Configure());
this.labelIp.setText(MSGS.netIPv4Address());
this.labelSubnet.setText(MSGS.netIPv4SubnetMask());
this.labelGateway.setText(MSGS.netIPv4Gateway());
this.labelDns.setText(MSGS.netIPv4DNSServers());
this.labelSearch.setText(MSGS.netIPv4SearchDomains());
for (GwtNetIfConfigMode mode : GwtNetIfConfigMode.values()) {
this.configure.addItem(MessageUtils.get(mode.name()));
}
// Populate status list
if (this.selectedNetIfConfig != null && this.selectedNetIfConfig.getHwTypeEnum() == GwtNetIfType.MODEM) {
if (this.status != null) {
this.status.clear();
this.status.addItem(MessageUtils.get("netIPv4StatusDisabled"));
this.status.addItem(MessageUtils.get("netIPv4StatusEnabledWAN"));
}
} else {
if (this.status != null) {
this.status.clear();
this.status.addItem(MessageUtils.get("netIPv4StatusDisabled"));
this.status.addItem(MessageUtils.get("netIPv4StatusEnabledLAN"));
this.status.addItem(MessageUtils.get("netIPv4StatusEnabledWAN"));
}
}
// SetTooltips
// Status
this.status.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.status.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ModemToolTipStatus()));
}
}
});
this.status.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
this.status.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
setDirty(true);
TabTcpIpUi.this.tabs.adjustInterfaceTabs();
refreshForm();
resetValidations();
// changed to WAN
if (isWanEnabled()) {
EntryClassUi.showWaitModal();
TabTcpIpUi.this.gwtNetworkService.findNetInterfaceConfigurations(new AsyncCallback<List<GwtNetInterfaceConfig>>() {
@Override
public void onFailure(Throwable caught) {
EntryClassUi.hideWaitModal();
FailureHandler.handle(caught);
}
@Override
public void onSuccess(List<GwtNetInterfaceConfig> result) {
EntryClassUi.hideWaitModal();
for (GwtNetInterfaceConfig config : result) {
if (config.getStatusEnum().equals(GwtNetIfStatus.netIPv4StatusEnabledWAN) && !config.getName().equals(TabTcpIpUi.this.selectedNetIfConfig.getName())) {
logger.log(Level.SEVERE, "Error: Status Invalid");
TabTcpIpUi.this.wanModal.show();
break;
}
}
}
});
}
}
});
// Configure
this.configure.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.configure.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipConfigure()));
}
}
});
this.configure.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
this.configure.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
setDirty(true);
TabTcpIpUi.this.tabs.adjustInterfaceTabs();
refreshForm();
resetValidations();
}
});
// Initial view of configure
if (this.configure.getSelectedItemText().equalsIgnoreCase(VMSGS.netIPv4ConfigModeDHCP())) {
// Using DHCP selected
this.ip.setEnabled(false);
this.subnet.setEnabled(false);
this.gateway.setEnabled(false);
this.renew.setEnabled(true);
} else if (this.configure.getSelectedItemText().equalsIgnoreCase(VMSGS.netIPv4ConfigModeManual())) {
// Manually selected
this.ip.setEnabled(true);
this.subnet.setEnabled(true);
this.gateway.setEnabled(true);
this.renew.setEnabled(false);
}
// IP Address
this.ip.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.ip.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipAddress()));
}
}
});
this.ip.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
this.ip.addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
setDirty(true);
if (!TabTcpIpUi.this.ip.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex()) || !(TabTcpIpUi.this.ip.getText().trim().length() > 0)) {
TabTcpIpUi.this.groupIp.setValidationState(ValidationState.ERROR);
TabTcpIpUi.this.helpIp.setText(MSGS.netIPv4InvalidAddress());
} else {
TabTcpIpUi.this.groupIp.setValidationState(ValidationState.NONE);
TabTcpIpUi.this.helpIp.setText("");
}
}
});
// Subnet Mask
this.subnet.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.subnet.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipSubnetMask()));
}
}
});
this.subnet.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
this.subnet.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
setDirty(true);
if (!TabTcpIpUi.this.subnet.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex()) && TabTcpIpUi.this.subnet.getText().trim().length() > 0) {
TabTcpIpUi.this.groupSubnet.setValidationState(ValidationState.ERROR);
TabTcpIpUi.this.helpSubnet.setText(MSGS.netIPv4InvalidAddress());
} else {
TabTcpIpUi.this.groupSubnet.setValidationState(ValidationState.NONE);
TabTcpIpUi.this.helpSubnet.setText("");
}
}
});
// Gateway
this.gateway.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.gateway.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipGateway()));
}
}
});
this.gateway.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
this.gateway.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
setDirty(true);
if (!TabTcpIpUi.this.gateway.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex()) && TabTcpIpUi.this.gateway.getText().trim().length() > 0) {
TabTcpIpUi.this.groupGateway.setValidationState(ValidationState.ERROR);
TabTcpIpUi.this.helpGateway.setText(MSGS.netIPv4InvalidAddress());
} else {
TabTcpIpUi.this.groupGateway.setValidationState(ValidationState.NONE);
TabTcpIpUi.this.helpGateway.setText("");
}
}
});
// DNS Servers
this.dns.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.dns.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipDns()));
}
}
});
this.dns.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
this.dns.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
setDirty(true);
if (TabTcpIpUi.this.dns.getText().trim().length() == 0) {
TabTcpIpUi.this.groupDns.setValidationState(ValidationState.NONE);
TabTcpIpUi.this.helpDns.setText("");
return;
}
String regex = "[\\s,;\\n\\t]+";
String[] aDnsServers = TabTcpIpUi.this.dns.getText().trim().split(regex);
boolean validDnsList = true;
for (String dnsEntry : aDnsServers) {
if ((dnsEntry.length() > 0) && !dnsEntry.matches(FieldType.IPv4_ADDRESS.getRegex())) {
validDnsList = false;
break;
}
}
if (!validDnsList) {
TabTcpIpUi.this.groupDns.setValidationState(ValidationState.ERROR);
TabTcpIpUi.this.helpDns.setText(MSGS.netIPv4InvalidAddress());
} else {
TabTcpIpUi.this.groupDns.setValidationState(ValidationState.NONE);
TabTcpIpUi.this.helpDns.setText("");
}
/*
if (!TabTcpIpUi.this.dns.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex())
&& TabTcpIpUi.this.dns.getText().trim().length() > 0) {
TabTcpIpUi.this.groupDns.setValidationState(ValidationState.ERROR);
TabTcpIpUi.this.helpDns.setText(MSGS.netIPv4InvalidAddress());
} else {
TabTcpIpUi.this.groupDns.setValidationState(ValidationState.NONE);
TabTcpIpUi.this.helpDns.setText("");
}
*/
}
});
// Renew DHCP Lease
this.renew.setText(MSGS.netIPv4RenewDHCPLease());
this.renew.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
EntryClassUi.showWaitModal();
TabTcpIpUi.this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
EntryClassUi.hideWaitModal();
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
TabTcpIpUi.this.gwtNetworkService.renewDhcpLease(token, TabTcpIpUi.this.selectedNetIfConfig.getName(), new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable ex) {
EntryClassUi.hideWaitModal();
FailureHandler.handle(ex);
}
@Override
public void onSuccess(Void result) {
refresh();
EntryClassUi.hideWaitModal();
}
});
}
});
}
});
this.renew.addMouseOverHandler(new MouseOverHandler() {
@Override
public void onMouseOver(MouseOverEvent event) {
if (TabTcpIpUi.this.renew.isEnabled()) {
TabTcpIpUi.this.helpText.clear();
TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipRenew()));
}
}
});
this.renew.addMouseOutHandler(new MouseOutHandler() {
@Override
public void onMouseOut(MouseOutEvent event) {
resetHelp();
}
});
}
use of org.eclipse.kura.web.shared.model.GwtNetIfConfigMode in project kura by eclipse.
the class TcpIpConfigTab method onRender.
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FitLayout());
setId("network-tcpip");
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");
m_fieldSet = new FieldSet();
FormLayout layoutAccount = new FormLayout();
layoutAccount.setLabelWidth(Constants.LABEL_WIDTH_FORM);
m_fieldSet.setLayout(layoutAccount);
m_fieldSet.setBorders(false);
//
// Enabled
//
initializeStatusListStore();
//
// Tool Tip Box
//
toolTipField.setText(defaultToolTip);
m_fieldSet.add(toolTipField);
//
// Status Combo
//
m_statusCombo = new ComboBox<GwtNetIfStatusModel>();
m_statusCombo.setName("comboStatus");
m_statusCombo.setDisplayField(GwtNetIfStatusModel.NAME);
m_statusCombo.setFieldLabel(MSGS.netIPv4Status());
m_statusCombo.setEditable(false);
m_statusCombo.setStore(m_statusListStore);
m_statusCombo.setTemplate(getTemplate());
m_statusCombo.setTypeAhead(true);
m_statusCombo.setTriggerAction(TriggerAction.ALL);
m_statusCombo.setValue(m_statusListStore.findModel(GwtNetIfStatusModel.STATUS, GwtNetIfStatus.netIPv4StatusDisabled.name()));
m_statusCombo.addSelectionChangedListener(new SelectionChangedListener<GwtNetIfStatusModel>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtNetIfStatusModel> se) {
m_netInterfaceConfigTabs.adjustInterfaceTabs();
refreshForm();
// Check for other WAN interfaces if current interface is changed to WAN
if (isWanEnabled()) {
m_formPanel.mask(MSGS.waiting());
gwtNetworkService.findNetInterfaceConfigurations(new AsyncCallback<ListLoadResult<GwtNetInterfaceConfig>>() {
public void onFailure(Throwable caught) {
m_formPanel.unmask();
;
}
public void onSuccess(ListLoadResult<GwtNetInterfaceConfig> result) {
for (GwtNetInterfaceConfig config : result.getData()) {
if (config.getStatusEnum().equals(GwtNetIfStatus.netIPv4StatusEnabledWAN) && !config.getName().equals(m_selectNetIfConfig.getName())) {
m_statusCombo.fireEvent(Events.Invalid);
}
}
m_formPanel.unmask();
;
}
});
} else {
FormUtils.removeWarningFieldIcon(m_statusCombo);
}
}
});
m_statusCombo.addStyleName("kura-combobox");
m_statusCombo.addPlugin(m_dirtyPlugin);
m_statusCombo.addPlugin(m_warningPlugin);
m_fieldSet.add(m_statusCombo, formData);
//
// Configure IP
//
m_configureCombo = new SimpleComboBox<String>();
m_configureCombo.setName("comboConfigure");
m_configureCombo.setFieldLabel(MSGS.netIPv4Configure());
m_configureCombo.setEditable(false);
m_configureCombo.setTypeAhead(true);
m_configureCombo.setTriggerAction(TriggerAction.ALL);
m_configureCombo.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
// show account status combo box
for (GwtNetIfConfigMode mode : GwtNetIfConfigMode.values()) {
m_configureCombo.add(MessageUtils.get(mode.name()));
}
if ((m_selectNetIfConfig != null) && (m_selectNetIfConfig.getHwTypeEnum() == GwtNetIfType.MODEM)) {
m_statusListStore.remove(m_statusListStore.findModel(GwtNetIfStatusModel.STATUS, GwtNetIfStatus.netIPv4StatusEnabledLAN.name()));
}
m_configureCombo.setSimpleValue(MessageUtils.get(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name()));
m_configureCombo.addSelectionChangedListener(new SelectionChangedListener<SimpleComboValue<String>>() {
@Override
public void selectionChanged(SelectionChangedEvent<SimpleComboValue<String>> se) {
m_netInterfaceConfigTabs.adjustInterfaceTabs();
refreshForm();
}
});
m_configureCombo.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipConfigure()));
m_configureCombo.addStyleName("kura-combobox");
m_configureCombo.addPlugin(m_dirtyPlugin);
m_fieldSet.add(m_configureCombo, formData);
//
// IP Address
//
m_ipAddressField = new TextField<String>();
m_ipAddressField.setAllowBlank(true);
m_ipAddressField.setName("ipAddress");
m_ipAddressField.setFieldLabel(MSGS.netIPv4Address());
m_ipAddressField.setRegex(IPV4_REGEX);
m_ipAddressField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
m_ipAddressField.addPlugin(m_dirtyPlugin);
m_ipAddressField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipAddress()));
m_ipAddressField.addStyleName("kura-textfield");
m_fieldSet.add(m_ipAddressField, formData);
//
// Subnet mask
//
m_subnetMaskField = new TextField<String>();
m_subnetMaskField.setAllowBlank(true);
m_subnetMaskField.setName("subnetMask");
m_subnetMaskField.setFieldLabel(MSGS.netIPv4SubnetMask());
m_subnetMaskField.setRegex(IPV4_REGEX);
m_subnetMaskField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
m_subnetMaskField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipSubnetMask()));
m_subnetMaskField.addStyleName("kura-textfield");
m_subnetMaskField.addPlugin(m_dirtyPlugin);
m_fieldSet.add(m_subnetMaskField, formData);
//
// Gateway
//
m_gatewayField = new TextField<String>();
m_gatewayField.setAllowBlank(true);
m_gatewayField.setName("gateway");
m_gatewayField.setFieldLabel(MSGS.netIPv4Gateway());
m_gatewayField.setRegex(IPV4_REGEX);
m_gatewayField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
m_gatewayField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipGateway()));
m_gatewayField.addStyleName("kura-textfield");
m_gatewayField.addPlugin(m_dirtyPlugin);
m_fieldSet.add(m_gatewayField, formData);
//
// Renew DHCP Lease
//
Button renewDHCP = new Button(MSGS.netIPv4RenewDHCPLease(), // no image
null, new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
gwtNetworkService.renewDhcpLease(token, m_selectNetIfConfig.getName(), new AsyncCallback<Void>() {
public void onSuccess(Void result) {
update();
Log.debug("successfully renewed DHCP lease");
}
public void onFailure(Throwable caught) {
Log.debug("caught: " + caught.toString());
FailureHandler.handle(caught);
}
});
}
});
}
});
m_renewDHCPButton = new AdapterField(renewDHCP);
m_renewDHCPButton.setId("net-ipv4-renew-dhcp");
m_renewDHCPButton.setLabelSeparator("");
m_renewDHCPButton.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipRenew()));
FormData formDataButton = new FormData();
formDataButton.setWidth(150);
m_renewDHCPButton.addPlugin(m_dirtyPlugin);
m_fieldSet.add(m_renewDHCPButton, formDataButton);
//
// DNS read-only (for DHCP)
//
m_dnsReadOnlyField = new TextArea();
m_dnsReadOnlyField.setAllowBlank(true);
m_dnsReadOnlyField.setName("dnsReadOnlyServers");
m_dnsReadOnlyField.setFieldLabel(MSGS.netIPv4DNSServers());
m_dnsReadOnlyField.setEnabled(false);
m_dnsReadOnlyField.setHeight("1.5em");
m_dnsReadOnlyField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
m_dnsReadOnlyField.setStyleAttribute("margin-bottom", "0px");
m_dnsReadOnlyField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipDns()));
m_fieldSet.add(m_dnsReadOnlyField, formData);
//
// DNS
//
m_dnsField = new TextArea();
m_dnsField.setAllowBlank(true);
m_dnsField.setName("dnsServers");
m_dnsField.setFieldLabel(MSGS.netIPv4DNSServers());
m_dnsField.setRegex("((" + IPV4_REGEX + ")[\\s,;\\n\\r\\t]*)+");
m_dnsField.getMessages().setRegexText(MSGS.netIPv4InvalidAddress());
m_dnsField.addListener(Events.OnMouseOver, new MouseOverListener(MSGS.netIPv4ToolTipDns()));
m_dnsField.addListener(Events.OnChange, new Listener<FieldEvent>() {
// Hide the DNS entry from the DHCP server if a custom DNS entry is added
public void handleEvent(FieldEvent be) {
TextArea t = (TextArea) be.getField();
if (t.getValue() == null || t.getValue().isEmpty()) {
showReadOnlyDns();
} else {
hideReadOnlyDns();
}
}
});
m_dnsField.addPlugin(m_dirtyPlugin);
m_fieldSet.add(m_dnsField, formData);
//
// Search Domains
//
m_domainsField = new TextArea();
m_domainsField.setAllowBlank(true);
m_domainsField.setName("searchDomains");
m_domainsField.setFieldLabel(MSGS.netIPv4SearchDomains());
m_domainsField.setStyleAttribute("margin-top", Constants.LABEL_MARGIN_TOP_SEPARATOR);
m_domainsField.addPlugin(m_dirtyPlugin);
m_fieldSet.add(m_domainsField, formData);
m_formPanel.add(m_fieldSet);
add(m_formPanel);
setScrollMode(Scroll.AUTO);
m_initialized = true;
}
Aggregations