use of org.netxms.base.MacAddress in project netxms by netxms.
the class FindMacAddress method run.
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
@Override
public void run(IAction action) {
EnterMacAddressDlg dlg = new EnterMacAddressDlg(window.getShell());
if (dlg.open() != Window.OK)
return;
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
final MacAddress macAddr = dlg.getMacAddress();
new ConsoleJob(String.format(Messages.get().FindMacAddress_JobTitle, macAddr), null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final ConnectionPoint cp = session.findConnectionPoint(macAddr);
runInUIThread(new Runnable() {
@Override
public void run() {
HostSearchResults.showConnection(cp);
}
});
}
@Override
protected String getErrorMessage() {
return String.format(Messages.get().FindMacAddress_JobError, macAddr);
}
}.start();
}
use of org.netxms.base.MacAddress in project netxms by netxms.
the class MacAddressTest method testMacAddress.
public void testMacAddress() throws Exception {
MacAddress a1 = new MacAddress();
assertEquals("00:00:00:00:00:00", a1.toString());
MacAddress a2 = new MacAddress(new byte[] { 0x02, 0x0C, (byte) 0xD4, 0x55, 0x22, 0x1A });
assertEquals("02:0C:D4:55:22:1A", a2.toString());
MacAddress a3 = MacAddress.parseMacAddress("02:0C:D4:55:22:1A");
assertEquals(a2, a3);
MacAddress a4 = MacAddress.parseMacAddress("020.CD4.552.21A");
assertEquals(a2, a4);
assertEquals("02:0C:D4:55:22:1A", a4.toString());
try {
MacAddress.parseMacAddress("bad mac string");
assertTrue(false);
} catch (MacAddressFormatException e) {
System.out.println("Exception caught: " + e.getMessage());
}
}
use of org.netxms.base.MacAddress 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()));
}
}
Aggregations