Search in sources :

Example 1 with AddressListLabelProvider

use of org.netxms.ui.eclipse.objectbrowser.dialogs.helpers.AddressListLabelProvider 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)

Aggregations

HashSet (java.util.HashSet)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Table (org.eclipse.swt.widgets.Table)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 InetAddressEx (org.netxms.base.InetAddressEx)1 AbstractObject (org.netxms.client.objects.AbstractObject)1 Interface (org.netxms.client.objects.Interface)1 AddressListElement (org.netxms.ui.eclipse.objectbrowser.dialogs.helpers.AddressListElement)1 AddressListLabelProvider (org.netxms.ui.eclipse.objectbrowser.dialogs.helpers.AddressListLabelProvider)1