Search in sources :

Example 1 with IPAddressValidator

use of org.netxms.ui.eclipse.tools.IPAddressValidator in project netxms by netxms.

the class CreateInterfaceDialog method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@Override
protected void okPressed() {
    physicalPort = checkIsPhy.getSelection();
    if (!WidgetHelper.validateTextInput(nameField, new ObjectNameValidator(), null) || !WidgetHelper.validateTextInput(macAddrField, new MacAddressValidator(true), null) || !WidgetHelper.validateTextInput(ipAddrField, new IPAddressValidator(true), null) || !WidgetHelper.validateTextInput(ipMaskField, new IPNetMaskValidator(true), null) || (physicalPort && !WidgetHelper.validateTextInput(slotField, new NumericTextFieldValidator(0, 4096), null)) || (physicalPort && !WidgetHelper.validateTextInput(portField, new NumericTextFieldValidator(0, 4096), null)))
        return;
    try {
        name = nameField.getText().trim();
        macAddress = macAddrField.getText().trim().isEmpty() ? new MacAddress() : MacAddress.parseMacAddress(macAddrField.getText());
        // $NON-NLS-1$
        InetAddress addr = ipAddrField.getText().trim().isEmpty() ? InetAddress.getByName("0.0.0.0") : InetAddress.getByName(ipAddrField.getText());
        ipAddress = new InetAddressEx(addr, getMaskBits(ipMaskField.getText().trim(), addr instanceof Inet4Address ? 32 : 128));
        slot = physicalPort ? Integer.parseInt(slotField.getText()) : 0;
        port = physicalPort ? Integer.parseInt(portField.getText()) : 0;
        super.okPressed();
    } catch (Exception e) {
        // $NON-NLS-1$
        MessageDialogHelper.openError(getShell(), Messages.get().CreateInterfaceDialog_Error, String.format("Internal error: %s", e.getMessage()));
    }
}
Also used : MacAddressValidator(org.netxms.ui.eclipse.tools.MacAddressValidator) IPAddressValidator(org.netxms.ui.eclipse.tools.IPAddressValidator) ObjectNameValidator(org.netxms.ui.eclipse.tools.ObjectNameValidator) NumericTextFieldValidator(org.netxms.ui.eclipse.tools.NumericTextFieldValidator) Inet4Address(java.net.Inet4Address) IPNetMaskValidator(org.netxms.ui.eclipse.tools.IPNetMaskValidator) InetAddressEx(org.netxms.base.InetAddressEx) MacAddress(org.netxms.base.MacAddress) InetAddress(java.net.InetAddress) UnknownHostException(java.net.UnknownHostException)

Aggregations

Inet4Address (java.net.Inet4Address)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 InetAddressEx (org.netxms.base.InetAddressEx)1 MacAddress (org.netxms.base.MacAddress)1 IPAddressValidator (org.netxms.ui.eclipse.tools.IPAddressValidator)1 IPNetMaskValidator (org.netxms.ui.eclipse.tools.IPNetMaskValidator)1 MacAddressValidator (org.netxms.ui.eclipse.tools.MacAddressValidator)1 NumericTextFieldValidator (org.netxms.ui.eclipse.tools.NumericTextFieldValidator)1 ObjectNameValidator (org.netxms.ui.eclipse.tools.ObjectNameValidator)1