Search in sources :

Example 11 with InetAddressEx

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;
}
Also used : InetAddressEx(org.netxms.base.InetAddressEx)

Example 12 with InetAddressEx

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;
}
Also used : ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) InetAddressEx(org.netxms.base.InetAddressEx) AbstractObject(org.netxms.client.objects.AbstractObject) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 13 with InetAddressEx

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;
    }
}
Also used : ClusterNetworkEditDialog(org.netxms.ui.eclipse.objectmanager.dialogs.ClusterNetworkEditDialog) InetAddressEx(org.netxms.base.InetAddressEx) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 14 with InetAddressEx

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) UnknownHostException(java.net.UnknownHostException) InetAddressEx(org.netxms.base.InetAddressEx) NXCObjectModificationData(org.netxms.client.NXCObjectModificationData) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) UnknownHostException(java.net.UnknownHostException)

Example 15 with InetAddressEx

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()));
    }
}
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

InetAddressEx (org.netxms.base.InetAddressEx)16 AbstractObject (org.netxms.client.objects.AbstractObject)4 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 AccessPoint (org.netxms.client.objects.AccessPoint)3 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 Interface (org.netxms.client.objects.Interface)2 IOException (java.io.IOException)1 Inet4Address (java.net.Inet4Address)1 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)1