use of com.google.gwt.event.dom.client.BlurHandler 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 com.google.gwt.event.dom.client.BlurHandler in project kie-wb-common by kiegroup.
the class AbstractRestrictedEntryTextBox method setup.
protected void setup() {
final TextBox me = this;
// Validate value as it is entered
this.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event) {
// Permit navigation
int keyCode = event.getNativeEvent().getKeyCode();
if (event.isControlKeyDown() || keyCode == KeyCodes.KEY_BACKSPACE || keyCode == KeyCodes.KEY_DELETE || keyCode == KeyCodes.KEY_LEFT || keyCode == KeyCodes.KEY_RIGHT || keyCode == KeyCodes.KEY_TAB || keyCode == KeyCodes.KEY_HOME || keyCode == KeyCodes.KEY_END) {
return;
}
// Get new value and validate
int charCode = event.getCharCode();
String oldValue = me.getValue();
String newValue = oldValue.substring(0, me.getCursorPos());
newValue = newValue + ((char) charCode);
newValue = newValue + oldValue.substring(me.getCursorPos() + me.getSelectionLength());
if (!isValidValue(newValue, false)) {
event.preventDefault();
}
}
});
// Add validation when looses focus (for when values are pasted in by users')
this.addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
final String value = me.getText();
if (!isValidValue(value, true)) {
final String validValue = makeValidValue(value);
me.setText(validValue);
ValueChangeEvent.fire(AbstractRestrictedEntryTextBox.this, validValue);
}
}
});
}
use of com.google.gwt.event.dom.client.BlurHandler in project kie-wb-common by kiegroup.
the class AbstractValidatingTextBox method setup.
protected void setup() {
final TextBox me = this;
// Validate value as it is entered
this.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(final KeyPressEvent event) {
// Permit navigation
int keyCode = getKeyCodeFromKeyPressEvent(event);
if (event.isControlKeyDown()) {
return;
}
if (!event.isShiftKeyDown()) {
if (keyCode == KeyCodes.KEY_BACKSPACE || keyCode == KeyCodes.KEY_DELETE || keyCode == KeyCodes.KEY_LEFT || keyCode == KeyCodes.KEY_RIGHT || keyCode == KeyCodes.KEY_ENTER || keyCode == KeyCodes.KEY_TAB || keyCode == KeyCodes.KEY_HOME || keyCode == KeyCodes.KEY_END) {
return;
}
}
// Get new value and validate
int charCode = event.getCharCode();
String oldValue = me.getValue();
String newValue = oldValue.substring(0, me.getCursorPos());
newValue = newValue + ((char) charCode);
newValue = newValue + oldValue.substring(me.getCursorPos() + me.getSelectionLength());
String validationError = isValidValue(newValue, false);
if (validationError != null) {
event.preventDefault();
fireValidationError(validationError);
}
}
});
// Add validation when loses focus (for when values are pasted in by user)
this.addBlurHandler(new BlurHandler() {
@Override
public void onBlur(final BlurEvent event) {
String value = me.getText();
String validationError = isValidValue(value, true);
if (validationError != null) {
fireValidationError(validationError);
String validValue = makeValidValue(value);
me.setValue(validValue);
ValueChangeEvent.fire(AbstractValidatingTextBox.this, validValue);
}
}
});
}
use of com.google.gwt.event.dom.client.BlurHandler in project kie-wb-common by kiegroup.
the class CustomDataTypeTextBoxTest method testKeyEnter.
@Test
public void testKeyEnter() {
when(textBox.getKeyCodeFromKeyPressEvent(any(KeyPressEvent.class))).thenReturn(KeyCodes.KEY_ENTER);
when(keyPressEvent.isControlKeyDown()).thenReturn(false);
when(keyPressEvent.isShiftKeyDown()).thenReturn(false);
when(keyPressEvent.getCharCode()).thenReturn((char) 13);
when(textBox.getCursorPos()).thenReturn(4);
when(textBox.getSelectionLength()).thenReturn(0);
when(textBox.getValue()).thenReturn("ab12");
when(textBox.getText()).thenReturn("ab12" + (char) 13);
textBox.setup();
verify(textBox, times(1)).addBlurHandler(blurCaptor.capture());
verify(textBox, times(1)).addKeyPressHandler(keyPressCaptor.capture());
BlurHandler blurHandler = blurCaptor.getValue();
blurHandler.onBlur(blurEvent);
verify(textBox, times(1)).isValidValue("ab12" + (char) 13, true);
verify(textBox, times(1)).makeValidValue("ab12" + (char) 13);
verify(textBox, times(1)).setValue("ab12");
KeyPressHandler keyPressHandler = keyPressCaptor.getValue();
keyPressHandler.onKeyPress(keyPressEvent);
}
use of com.google.gwt.event.dom.client.BlurHandler in project kie-wb-common by kiegroup.
the class VariableNameTextBoxTest method testSetup.
@Test
public void testSetup() {
when(textBox.getKeyCodeFromKeyPressEvent(any(KeyPressEvent.class))).thenReturn(64);
when(keyPressEvent.isControlKeyDown()).thenReturn(false);
when(keyPressEvent.isShiftKeyDown()).thenReturn(true);
when(keyPressEvent.getCharCode()).thenReturn('@');
when(textBox.getCursorPos()).thenReturn(4);
when(textBox.getSelectionLength()).thenReturn(0);
when(textBox.getValue()).thenReturn("ab12");
when(textBox.getText()).thenReturn("ab12@");
textBox.setup();
verify(textBox, times(1)).addBlurHandler(blurCaptor.capture());
verify(textBox, times(1)).addKeyPressHandler(keyPressCaptor.capture());
BlurHandler blurHandler = blurCaptor.getValue();
blurHandler.onBlur(blurEvent);
verify(textBox, times(1)).isValidValue("ab12@", true);
verify(textBox, times(1)).makeValidValue("ab12@");
verify(textBox, times(1)).setValue("ab12");
KeyPressHandler keyPressHandler = keyPressCaptor.getValue();
keyPressHandler.onKeyPress(keyPressEvent);
verify(keyPressEvent, times(1)).preventDefault();
verify(textBox, times(1)).isValidValue("ab12@", false);
verify(textBox, times(1)).fireValidationError(ERROR_REMOVED + ": @");
verify(textBox, times(1)).fireValidationError(ERROR_TYPED + ": @");
}
Aggregations