Search in sources :

Example 6 with InetAddressEx

use of org.netxms.base.InetAddressEx in project netxms by netxms.

the class IPAddressSelectionDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    dialogArea.setLayout(layout);
    // Label label = new Label(dialogArea, SWT.NONE);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 300;
    gd.widthHint = 250;
    viewer.getControl().setLayoutData(gd);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ComparatorHelper.compareInetAddresses(((AddressListElement) e1).address, ((AddressListElement) e2).address);
        }
    });
    viewer.setLabelProvider(new AddressListLabelProvider());
    final Table table = viewer.getTable();
    table.setHeaderVisible(true);
    TableColumn tc = new TableColumn(table, SWT.LEFT);
    tc.setText(Messages.get().IPAddressSelectionDialog_IPAddress);
    tc.setWidth(90);
    tc = new TableColumn(table, SWT.LEFT);
    tc.setText(Messages.get().IPAddressSelectionDialog_Interface);
    tc.setWidth(150);
    Set<AddressListElement> addrList = new HashSet<AddressListElement>();
    for (AbstractObject o : node.getChildsAsArray()) {
        if (o instanceof Interface) {
            for (InetAddressEx a : ((Interface) o).getIpAddressList()) {
                if (a.isValidUnicastAddress()) {
                    addrList.add(new AddressListElement((Interface) o, a.getAddress()));
                }
            }
        }
    }
    viewer.setInput(addrList.toArray());
    return dialogArea;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) AddressListLabelProvider(org.netxms.ui.eclipse.objectbrowser.dialogs.helpers.AddressListLabelProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableColumn(org.eclipse.swt.widgets.TableColumn) AddressListElement(org.netxms.ui.eclipse.objectbrowser.dialogs.helpers.AddressListElement) GridLayout(org.eclipse.swt.layout.GridLayout) InetAddressEx(org.netxms.base.InetAddressEx) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) AbstractObject(org.netxms.client.objects.AbstractObject) TableViewer(org.eclipse.jface.viewers.TableViewer) Interface(org.netxms.client.objects.Interface) HashSet(java.util.HashSet)

Example 7 with InetAddressEx

use of org.netxms.base.InetAddressEx in project netxms by netxms.

the class ClusterNetworks method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = new Composite(parent, SWT.NONE);
    object = (Cluster) getElement().getAdapter(Cluster.class);
    if (// Paranoid check
    object == null)
        return dialogArea;
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    final String[] columnNames = { Messages.get().ClusterNetworks_ColAddress, Messages.get().ClusterNetworks_ColMask };
    final int[] columnWidths = { 150, 150 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new NetworkListLabelProvider());
    viewer.setComparator(new NetworkListComparator());
    networks = new ArrayList<InetAddressEx>(object.getSyncNetworks().size());
    for (InetAddressEx n : object.getSyncNetworks()) networks.add(new InetAddressEx(n));
    viewer.setInput(networks.toArray());
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    viewer.getControl().setLayoutData(gridData);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    buttons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gridData);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().ClusterNetworks_Add);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            addNetwork();
        }
    });
    editButton = new Button(buttons, SWT.PUSH);
    editButton.setText(Messages.get().ClusterNetworks_Modify);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    editButton.setLayoutData(rd);
    editButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            editNetwork();
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().ClusterNetworks_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteNetwork();
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editButton.notifyListeners(SWT.Selection, new Event());
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            editButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) NetworkListComparator(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.NetworkListComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) NetworkListLabelProvider(org.netxms.ui.eclipse.objectmanager.propertypages.helpers.NetworkListLabelProvider) InetAddressEx(org.netxms.base.InetAddressEx) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 8 with InetAddressEx

use of org.netxms.base.InetAddressEx in project netxms by netxms.

the class ClusterNetworks method editNetwork.

/**
 * Edit currently selected network
 */
private void editNetwork() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    if (selection.size() != 1)
        return;
    InetAddressEx n = (InetAddressEx) selection.getFirstElement();
    ClusterNetworkEditDialog dlg = new ClusterNetworkEditDialog(getShell(), n.getAddress(), n.maskFromBits());
    if (dlg.open() == Window.OK) {
        n.setAddress(dlg.getAddress());
        n.setMask(InetAddressEx.bitsInMask(dlg.getMask()));
        viewer.update(n, null);
        isModified = true;
    }
}
Also used : ClusterNetworkEditDialog(org.netxms.ui.eclipse.objectmanager.dialogs.ClusterNetworkEditDialog) InetAddressEx(org.netxms.base.InetAddressEx) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 9 with InetAddressEx

use of org.netxms.base.InetAddressEx in project netxms by netxms.

the class VPNSubnets method addTargetAddressListElement.

/**
 * Add element to subnet list
 */
private void addTargetAddressListElement(TableViewer elementList, List<InetAddressEx> elements) {
    AddSubnetDialog dlg = new AddSubnetDialog(getShell());
    if (dlg.open() == Window.OK) {
        InetAddressEx subnet = dlg.getSubnet();
        if (!elements.contains(subnet)) {
            elements.add(subnet);
            elementList.setInput(elements.toArray());
            modified = true;
        }
    }
}
Also used : AddSubnetDialog(org.netxms.ui.eclipse.objectmanager.dialogs.AddSubnetDialog) InetAddressEx(org.netxms.base.InetAddressEx)

Example 10 with InetAddressEx

use of org.netxms.base.InetAddressEx in project netxms by netxms.

the class AddSubnetDialog method okPressed.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
	 */
@Override
protected void okPressed() {
    try {
        InetAddress a = InetAddress.getByName(address.getText().trim());
        subnet = new InetAddressEx(a, mask.getSelection());
    } catch (UnknownHostException e) {
        MessageDialogHelper.openWarning(getShell(), Messages.get().AddAddressListElementDialog_Warning, Messages.get().AddAddressListElementDialog_AddressValidationError);
        return;
    }
    super.okPressed();
}
Also used : UnknownHostException(java.net.UnknownHostException) InetAddressEx(org.netxms.base.InetAddressEx) InetAddress(java.net.InetAddress)

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