Search in sources :

Example 1 with SortColumnTableLabelProvider

use of org.netxms.ui.eclipse.dashboard.propertypages.helpers.SortColumnTableLabelProvider in project netxms by netxms.

the class DciSummaryTable method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    config = (DciSummaryTableConfig) getElement().getAdapter(DciSummaryTableConfig.class);
    Composite dialogArea = new Composite(parent, SWT.NONE);
    currSortingList = config.getSortingColumnList();
    GridLayout layout = new GridLayout();
    dialogArea.setLayout(layout);
    objectSelector = new ObjectSelector(dialogArea, SWT.NONE, true);
    objectSelector.setLabel(Messages.get().DciSummaryTable_BaseObject);
    objectSelector.setObjectClass(AbstractObject.class);
    objectSelector.setObjectId(config.getBaseObjectId());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    objectSelector.setLayoutData(gd);
    tableSelector = new SummaryTableSelector(dialogArea, SWT.NONE, AbstractSelector.SHOW_CLEAR_BUTTON);
    tableSelector.setLabel(Messages.get().DciSummaryTable_SummaryTable);
    tableSelector.setTableId(config.getTableId());
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    tableSelector.setLayoutData(gd);
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    refreshInterval = WidgetHelper.createLabeledSpinner(dialogArea, SWT.BORDER, Messages.get().DciSummaryTable_RefreshInterval, 0, 10000, gd);
    refreshInterval.setSelection(config.getRefreshInterval());
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    checkShowSortAndLimitFields = new Button(dialogArea, SWT.CHECK);
    checkShowSortAndLimitFields.setText("Show top N nodes");
    checkShowSortAndLimitFields.setSelection(config.isEnableSortingAndLineLimit());
    checkShowSortAndLimitFields.setLayoutData(gd);
    checkShowSortAndLimitFields.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (checkShowSortAndLimitFields.getSelection()) {
                sortTables.setSelection(null);
                buttonAdd.setEnabled(true);
                numRowsShow.setEnabled(true);
            } else {
                buttonUp.setEnabled(false);
                buttonDown.setEnabled(false);
                buttonEdit.setEnabled(false);
                buttonRemove.setEnabled(false);
                buttonAdd.setEnabled(false);
                numRowsShow.setEnabled(false);
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Composite showTopNNodes = new Composite(dialogArea, SWT.BORDER);
    layout = new GridLayout();
    showTopNNodes.setLayout(layout);
    gd = new GridData();
    gd.verticalAlignment = SWT.TOP;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    numRowsShow = WidgetHelper.createLabeledSpinner(showTopNNodes, SWT.BORDER, "Number of lines to show", 0, 10000, gd);
    numRowsShow.setSelection(config.getNumRowShown());
    numRowsShow.setEnabled(config.isEnableSortingAndLineLimit());
    Label label = new Label(showTopNNodes, SWT.NONE);
    label.setText("Sort by columns");
    final String[] columnNames = { "Name", "Sort order" };
    final int[] columnWidths = { 320, 120 };
    sortTables = new SortableTableViewer(showTopNNodes, columnNames, columnWidths, 0, 0, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.verticalSpan = 2;
    gd.heightHint = 150;
    sortTables.getTable().setLayoutData(gd);
    sortTables.setContentProvider(new ArrayContentProvider());
    sortTables.setLabelProvider(new SortColumnTableLabelProvider());
    sortTables.setInput(currSortingList);
    sortTables.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (checkShowSortAndLimitFields.getSelection()) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                int index = currSortingList.indexOf(selection.getFirstElement());
                buttonUp.setEnabled((selection.size() == 1) && (index > 0));
                buttonDown.setEnabled((selection.size() == 1) && (index >= 0) && (index < currSortingList.size() - 1));
                buttonEdit.setEnabled(selection.size() == 1);
                buttonRemove.setEnabled(selection.size() > 0);
            } else {
                buttonUp.setEnabled(false);
                buttonDown.setEnabled(false);
                buttonEdit.setEnabled(false);
                buttonRemove.setEnabled(false);
            }
        }
    });
    sortTables.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            buttonEdit.notifyListeners(SWT.Selection, new Event());
        }
    });
    Composite buttons = new Composite(showTopNNodes, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    buttons.setLayoutData(gd);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttons.setLayout(buttonLayout);
    buttonUp = new Button(buttons, SWT.PUSH);
    buttonUp.setText("UP");
    buttonUp.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonUp.setLayoutData(rd);
    buttonUp.setEnabled(false);
    buttonDown = new Button(buttons, SWT.PUSH);
    buttonDown.setText("Down");
    buttonDown.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonDown.setLayoutData(rd);
    buttonDown.setEnabled(false);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    gd.verticalIndent = WidgetHelper.OUTER_SPACING - WidgetHelper.INNER_SPACING;
    buttons.setLayoutData(gd);
    buttonAdd = new Button(buttons, SWT.PUSH);
    buttonAdd.setText("Add");
    buttonAdd.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            add();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonAdd.setLayoutData(rd);
    buttonAdd.setEnabled(config.isEnableSortingAndLineLimit());
    buttonEdit = new Button(buttons, SWT.PUSH);
    buttonEdit.setText("Edit");
    buttonEdit.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            edit();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonEdit.setLayoutData(rd);
    buttonEdit.setEnabled(false);
    buttonRemove = new Button(buttons, SWT.PUSH);
    buttonRemove.setText("Delete");
    buttonRemove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            remove();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    buttonRemove.setLayoutData(rd);
    buttonRemove.setEnabled(false);
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) SortColumnTableLabelProvider(org.netxms.ui.eclipse.dashboard.propertypages.helpers.SortColumnTableLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SummaryTableSelector(org.netxms.ui.eclipse.datacollection.widgets.SummaryTableSelector) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ObjectSelector(org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) 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)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)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 Event (org.eclipse.swt.widgets.Event)1 Label (org.eclipse.swt.widgets.Label)1 SortColumnTableLabelProvider (org.netxms.ui.eclipse.dashboard.propertypages.helpers.SortColumnTableLabelProvider)1 SummaryTableSelector (org.netxms.ui.eclipse.datacollection.widgets.SummaryTableSelector)1 ObjectSelector (org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1