Search in sources :

Example 16 with BlurHandler

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();
        }
    });
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Span(org.gwtbootstrap3.client.ui.html.Span) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) MouseOutEvent(com.google.gwt.event.dom.client.MouseOutEvent) MouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) MouseOverEvent(com.google.gwt.event.dom.client.MouseOverEvent) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig) MouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) List(java.util.List) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) GwtNetIfConfigMode(org.eclipse.kura.web.shared.model.GwtNetIfConfigMode)

Example 17 with BlurHandler

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);
            }
        }
    });
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) TextBox(org.gwtbootstrap3.client.ui.TextBox) BlurEvent(com.google.gwt.event.dom.client.BlurEvent)

Example 18 with BlurHandler

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);
            }
        }
    });
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) TextBox(org.gwtbootstrap3.client.ui.TextBox) BlurEvent(com.google.gwt.event.dom.client.BlurEvent)

Example 19 with BlurHandler

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);
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Test(org.junit.Test)

Example 20 with BlurHandler

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 + ": @");
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) KeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler) KeyPressEvent(com.google.gwt.event.dom.client.KeyPressEvent) Test(org.junit.Test)

Aggregations

BlurHandler (com.google.gwt.event.dom.client.BlurHandler)34 BlurEvent (com.google.gwt.event.dom.client.BlurEvent)28 KeyPressEvent (com.google.gwt.event.dom.client.KeyPressEvent)10 KeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler)10 Test (org.junit.Test)9 KeyUpEvent (com.google.gwt.event.dom.client.KeyUpEvent)6 KeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler)6 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)5 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)5 Element (com.google.gwt.dom.client.Element)4 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)4 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)4 FocusEvent (com.google.gwt.event.dom.client.FocusEvent)3 FocusHandler (com.google.gwt.event.dom.client.FocusHandler)3 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)2 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 SpanElement (com.google.gwt.dom.client.SpanElement)2 KeyDownEvent (com.google.gwt.event.dom.client.KeyDownEvent)2 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)2 MouseOutEvent (com.google.gwt.event.dom.client.MouseOutEvent)2