Search in sources :

Example 1 with ObjectSearchResultLabelProvider

use of org.netxms.ui.eclipse.objectbrowser.views.helpers.ObjectSearchResultLabelProvider in project netxms by netxms.

the class ObjectFinder method createPartControl.

/* (non-Javadoc)
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
@Override
public void createPartControl(Composite parent) {
    session = ConsoleSharedData.getSession();
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    parent.setLayout(layout);
    Composite conditionGroup = new Composite(parent, SWT.NONE);
    conditionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    layout = new GridLayout();
    layout.numColumns = session.isZoningEnabled() ? 3 : 2;
    conditionGroup.setLayout(layout);
    /**
     * Full text search **
     */
    Composite fullTextSearchGroup = new Composite(conditionGroup, SWT.NONE);
    fullTextSearchGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    layout = new GridLayout();
    fullTextSearchGroup.setLayout(layout);
    text = new LabeledText(fullTextSearchGroup, SWT.NONE);
    text.setLabel("Search string");
    text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
    TraverseListener traverseListener = new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN)
                startSearch();
        }
    };
    text.addTraverseListener(traverseListener);
    Group searchModeGroup = new Group(fullTextSearchGroup, SWT.NONE);
    searchModeGroup.setText("Search mode");
    layout = new GridLayout();
    searchModeGroup.setLayout(layout);
    radioPlainText = new Button(searchModeGroup, SWT.RADIO);
    radioPlainText.setText("&Normal");
    radioPlainText.setSelection(true);
    radioPattern = new Button(searchModeGroup, SWT.RADIO);
    radioPattern.setText("&Pattern (* = any string, ? = any character)");
    radioRegularExpression = new Button(searchModeGroup, SWT.RADIO);
    radioRegularExpression.setText("&Regular expression");
    /**
     * Class filter **
     */
    Composite classFilterGroup = new Composite(conditionGroup, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.verticalSpan = 2;
    classFilterGroup.setLayoutData(gd);
    layout = new GridLayout();
    classFilterGroup.setLayout(layout);
    Label classFilterTitle = new Label(classFilterGroup, SWT.NONE);
    classFilterTitle.setText("Class filter");
    classList = CheckboxTableViewer.newCheckList(classFilterGroup, SWT.BORDER | SWT.CHECK);
    classList.setContentProvider(new ArrayContentProvider());
    classList.setInput(OBJECT_CLASSES);
    classList.setAllChecked(true);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.heightHint = 100;
    classList.getTable().setLayoutData(gd);
    Composite classListButtons = new Composite(classFilterGroup, SWT.NONE);
    RowLayout rlayout = new RowLayout();
    rlayout.marginLeft = 0;
    classListButtons.setLayout(rlayout);
    Button selectAll = new Button(classListButtons, SWT.PUSH);
    selectAll.setText("Select &all");
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    selectAll.setLayoutData(rd);
    selectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            classList.setAllChecked(true);
        }
    });
    Button clearAll = new Button(classListButtons, SWT.PUSH);
    clearAll.setText("&Clear all");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    clearAll.setLayoutData(rd);
    clearAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            classList.setAllChecked(false);
        }
    });
    /**
     * Zone filter **
     */
    if (session.isZoningEnabled()) {
        Composite zoneFilterGroup = new Composite(conditionGroup, SWT.NONE);
        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        gd.verticalSpan = 2;
        zoneFilterGroup.setLayoutData(gd);
        layout = new GridLayout();
        zoneFilterGroup.setLayout(layout);
        Label zoneFilterTitle = new Label(zoneFilterGroup, SWT.NONE);
        zoneFilterTitle.setText("Zone filter");
        zoneList = CheckboxTableViewer.newCheckList(zoneFilterGroup, SWT.BORDER | SWT.CHECK);
        zoneList.setContentProvider(new ArrayContentProvider());
        List<Zone> zones = session.getAllZones();
        zoneList.setLabelProvider(new WorkbenchLabelProvider());
        zoneList.setInput(zones);
        zoneList.setAllChecked(true);
        gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        gd.heightHint = 100;
        zoneList.getTable().setLayoutData(gd);
        Composite zoneListButtons = new Composite(zoneFilterGroup, SWT.NONE);
        rlayout = new RowLayout();
        rlayout.marginLeft = 0;
        zoneListButtons.setLayout(rlayout);
        selectAll = new Button(zoneListButtons, SWT.PUSH);
        selectAll.setText("Select &all");
        rd = new RowData();
        rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
        selectAll.setLayoutData(rd);
        selectAll.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                zoneList.setAllChecked(true);
            }
        });
        clearAll = new Button(zoneListButtons, SWT.PUSH);
        clearAll.setText("&Clear all");
        rd = new RowData();
        rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
        clearAll.setLayoutData(rd);
        clearAll.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                zoneList.setAllChecked(false);
            }
        });
    }
    /**
     * IP filter **
     */
    Group ipFilterGroup = new Group(conditionGroup, SWT.NONE);
    ipFilterGroup.setText("IP Range");
    ipFilterGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    layout = new GridLayout();
    layout.numColumns = 3;
    ipFilterGroup.setLayout(layout);
    ipRangeStart = new Text(ipFilterGroup, SWT.BORDER);
    ipRangeStart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    ipRangeStart.addTraverseListener(traverseListener);
    new Label(ipFilterGroup, SWT.NONE).setText(" - ");
    ipRangeEnd = new Text(ipFilterGroup, SWT.BORDER);
    ipRangeEnd.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    ipRangeEnd.addTraverseListener(traverseListener);
    /**
     * Search button **
     */
    Button searchButton = new Button(conditionGroup, SWT.PUSH);
    searchButton.setText("&Search");
    gd = new GridData(SWT.LEFT, SWT.BOTTOM, true, false);
    gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
    searchButton.setLayoutData(gd);
    searchButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    final String[] names = { "ID", "Class", "Name", "IP Address", "Parent", "Zone" };
    final int[] widths = { 90, 120, 300, 250, 300, 200 };
    results = new SortableTableViewer(parent, names, widths, 0, SWT.UP, SWT.MULTI | SWT.FULL_SELECTION);
    if (!ConsoleSharedData.getSession().isZoningEnabled())
        results.removeColumnById(COL_ZONE);
    results.setContentProvider(new ArrayContentProvider());
    results.setLabelProvider(new ObjectSearchResultLabelProvider());
    results.setComparator(new ObjectSearchResultComparator());
    results.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final IDialogSettings settings = Activator.getDefault().getDialogSettings();
    WidgetHelper.restoreTableViewerSettings(results, settings, "ResultTable");
    results.getTable().addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            WidgetHelper.saveTableViewerSettings(results, settings, "ResultTable");
        }
    });
    getSite().setSelectionProvider(results);
    createResultsContextMenu();
    activateContext();
    createActions();
    contributeToActionBars();
}
Also used : Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TraverseEvent(org.eclipse.swt.events.TraverseEvent) Label(org.eclipse.swt.widgets.Label) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ObjectSearchResultComparator(org.netxms.ui.eclipse.objectbrowser.views.helpers.ObjectSearchResultComparator) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) ObjectSearchResultLabelProvider(org.netxms.ui.eclipse.objectbrowser.views.helpers.ObjectSearchResultLabelProvider) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) TraverseListener(org.eclipse.swt.events.TraverseListener) Zone(org.netxms.client.objects.Zone) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowData (org.eclipse.swt.layout.RowData)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)1 Zone (org.netxms.client.objects.Zone)1