Search in sources :

Example 1 with DashboardElementsLabelProvider

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

the class DashboardElements 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 = (Dashboard) getElement().getAdapter(Dashboard.class);
    if (// Paranoid check
    object == null)
        return dialogArea;
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    columnCount = new LabeledSpinner(dialogArea, SWT.NONE);
    columnCount.setLabel(Messages.get().DashboardElements_NumColumns);
    columnCount.setRange(1, 128);
    columnCount.setSelection(object.getNumColumns());
    GridData gridData = new GridData();
    gridData.horizontalAlignment = SWT.LEFT;
    gridData.horizontalSpan = 2;
    columnCount.setLayoutData(gridData);
    final String[] columnNames = { Messages.get().DashboardElements_Type, Messages.get().DashboardElements_Span, "Height" };
    final int[] columnWidths = { 150, 60, 90 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new DashboardElementsLabelProvider());
    elements = copyElements(object.getElements());
    viewer.setInput(elements.toArray());
    gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    gridData.horizontalSpan = 2;
    viewer.getControl().setLayoutData(gridData);
    Composite leftButtons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginLeft = 0;
    leftButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gridData);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().DashboardElements_Up);
    upButton.setEnabled(false);
    upButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveUp();
        }
    });
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().DashboardElements_Down);
    downButton.setEnabled(false);
    downButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveDown();
        }
    });
    Composite rightButtons = new Composite(dialogArea, SWT.NONE);
    buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginWidth = 0;
    buttonLayout.marginRight = 0;
    rightButtons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    rightButtons.setLayoutData(gridData);
    addButton = new Button(rightButtons, SWT.PUSH);
    addButton.setText(Messages.get().DashboardElements_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    editButton = new Button(rightButtons, SWT.PUSH);
    editButton.setText(Messages.get().DashboardElements_Edit);
    editButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    editXmlButton = new Button(rightButtons, SWT.PUSH);
    editXmlButton.setText(Messages.get().DashboardElements_EditXML);
    editXmlButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    deleteButton = new Button(rightButtons, SWT.PUSH);
    deleteButton.setText(Messages.get().DashboardElements_Delete);
    deleteButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            int index = elements.indexOf(selection.getFirstElement());
            upButton.setEnabled((selection.size() == 1) && (index > 0));
            downButton.setEnabled((selection.size() == 1) && (index >= 0) && (index < elements.size() - 1));
            editButton.setEnabled(selection.size() == 1);
            deleteButton.setEnabled(selection.size() > 0);
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editButton.notifyListeners(SWT.Selection, new Event());
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DashboardElementsLabelProvider(org.netxms.ui.eclipse.dashboard.propertypages.helpers.DashboardElementsLabelProvider) LabeledSpinner(org.netxms.ui.eclipse.widgets.LabeledSpinner) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) 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)

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 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 DashboardElementsLabelProvider (org.netxms.ui.eclipse.dashboard.propertypages.helpers.DashboardElementsLabelProvider)1 LabeledSpinner (org.netxms.ui.eclipse.widgets.LabeledSpinner)1 SortableTableViewer (org.netxms.ui.eclipse.widgets.SortableTableViewer)1