use of org.netxms.base.InetAddressEx in project netxms by netxms.
the class SubnetComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
InetAddressEx a1 = (InetAddressEx) e1;
InetAddressEx a2 = (InetAddressEx) e2;
int rc = compareIpAddresses(a1, a2);
if (rc == 0) {
rc = a1.getMask() - a2.getMask();
}
int dir = ((TableViewer) viewer).getTable().getSortDirection();
return (dir == SWT.UP) ? rc : -rc;
}
use of org.netxms.base.InetAddressEx in project netxms by netxms.
the class ObjectSearchResultComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
final AbstractObject object1 = (AbstractObject) e1;
final AbstractObject object2 = (AbstractObject) e2;
// $NON-NLS-1$
final int column = (Integer) ((SortableTableViewer) viewer).getTable().getSortColumn().getData("ID");
int result;
switch(column) {
case ObjectFinder.COL_ID:
result = Long.signum(object1.getObjectId() - object2.getObjectId());
break;
case ObjectFinder.COL_IP_ADDRESS:
InetAddressEx a1 = getIpAddress(object1);
InetAddressEx a2 = getIpAddress(object2);
result = ComparatorHelper.compareInetAddresses(a1.getAddress(), a2.getAddress());
break;
case ObjectFinder.COL_NAME:
result = object1.getObjectName().compareToIgnoreCase(object2.getObjectName());
break;
case ObjectFinder.COL_CLASS:
case ObjectFinder.COL_PARENT:
case ObjectFinder.COL_ZONE:
String t1 = ((ITableLabelProvider) ((SortableTableViewer) viewer).getLabelProvider()).getColumnText(object1, column);
String t2 = ((ITableLabelProvider) ((SortableTableViewer) viewer).getLabelProvider()).getColumnText(object2, column);
result = t1.compareToIgnoreCase(t2);
break;
default:
result = 0;
break;
}
return (((SortableTableViewer) viewer).getTable().getSortDirection() == SWT.UP) ? result : -result;
}
use of org.netxms.base.InetAddressEx in project netxms by netxms.
the class ClusterNetworks method addNetwork.
/**
* Add new cluster network
*/
private void addNetwork() {
ClusterNetworkEditDialog dlg = new ClusterNetworkEditDialog(getShell(), null, null);
if (dlg.open() == Window.OK) {
InetAddressEx n = new InetAddressEx(dlg.getAddress(), dlg.getMask());
networks.add(n);
viewer.setInput(networks.toArray());
viewer.setSelection(new StructuredSelection(n));
isModified = true;
}
}
use of org.netxms.base.InetAddressEx in project netxms by netxms.
the class NetworkServicePolling method applyChanges.
/**
* Apply changes
*
* @param isApply true if update operation caused by "Apply" button
*/
protected boolean applyChanges(final boolean isApply) {
final NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
try {
int ipPort = Integer.parseInt(port.getText());
if ((ipPort < 1) || (ipPort > 65535))
throw new NumberFormatException();
md.setIpPort(ipPort);
} catch (NumberFormatException e) {
MessageDialogHelper.openWarning(getShell(), Messages.get().NetworkServicePolling_Warning, Messages.get().NetworkServicePolling_WarningInvalidPort);
return false;
}
md.setRequiredPolls(pollCount.getSelection());
md.setServiceType(serviceType.getSelectionIndex());
String addr = ipAddress.getText().trim();
if (!addr.isEmpty()) {
try {
md.setIpAddress(new InetAddressEx(InetAddress.getByName(addr)));
} catch (UnknownHostException e) {
MessageDialogHelper.openWarning(getShell(), Messages.get().AddAddressListElementDialog_Warning, Messages.get().AddAddressListElementDialog_AddressValidationError);
return false;
}
} else {
md.setIpAddress(new InetAddressEx());
}
md.setRequest(request.getText());
md.setResponse(response.getText());
md.setPollerNode(pollerNode.getObjectId());
if (isApply)
setValid(false);
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
new ConsoleJob(Messages.get().NetworkServicePolling_JobName, null, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
session.modifyObject(md);
}
@Override
protected String getErrorMessage() {
return Messages.get().NetworkServicePolling_JobError;
}
@Override
protected void jobFinalize() {
if (isApply) {
runInUIThread(new Runnable() {
@Override
public void run() {
NetworkServicePolling.this.setValid(true);
}
});
}
}
}.start();
return true;
}
use of org.netxms.base.InetAddressEx 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