Search in sources :

Example 1 with DataCollectionObjectListener

use of org.netxms.ui.eclipse.datacollection.api.DataCollectionObjectListener in project netxms by netxms.

the class TableColumns method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    Composite dialogArea = (Composite) super.createContents(parent);
    dci = editor.getObjectAsTable();
    editor.setCallback(new TableColumnDataProvider());
    columns = new ArrayList<ColumnDefinition>();
    for (ColumnDefinition c : dci.getColumns()) columns.add(new ColumnDefinition(c));
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    Composite columnListArea = new Composite(dialogArea, SWT.NONE);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    columnListArea.setLayoutData(gd);
    layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    columnListArea.setLayout(layout);
    new Label(columnListArea, SWT.NONE).setText(Messages.get().TableColumns_Columns);
    columnList = new TableViewer(columnListArea, 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.horizontalSpan = 2;
    columnList.getControl().setLayoutData(gd);
    setupColumnList();
    columnList.setInput(columns.toArray());
    Composite leftButtons = new Composite(columnListArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gd);
    RowLayout buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    leftButtons.setLayout(buttonsLayout);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().TableColumns_Up);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    upButton.setLayoutData(rd);
    upButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveSelectionUp();
        }
    });
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().TableColumns_Down);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    downButton.setLayoutData(rd);
    downButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveSelectionDown();
        }
    });
    Composite buttons = new Composite(columnListArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gd);
    buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    buttons.setLayout(buttonsLayout);
    queryButton = new Button(buttons, SWT.PUSH);
    queryButton.setText("&Query...");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    queryButton.setLayoutData(rd);
    queryButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            queryColumns();
        }
    });
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().TableColumns_Add);
    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) {
            addColumn();
        }
    });
    modifyButton = new Button(buttons, SWT.PUSH);
    modifyButton.setText(Messages.get().TableColumns_Edit);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    modifyButton.setLayoutData(rd);
    modifyButton.setEnabled(false);
    modifyButton.addSelectionListener(new SelectionListener() {

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

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

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteColumns();
        }
    });
    /**
     * Selection change listener for column list **
     */
    columnList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            deleteButton.setEnabled(selection.size() > 0);
            if (selection.size() == 1) {
                modifyButton.setEnabled(true);
                upButton.setEnabled(columns.indexOf(selection.getFirstElement()) > 0);
                downButton.setEnabled(columns.indexOf(selection.getFirstElement()) < columns.size() - 1);
            } else {
                modifyButton.setEnabled(false);
                upButton.setEnabled(false);
                downButton.setEnabled(false);
            }
        }
    });
    columnList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editColumn();
        }
    });
    final DataCollectionObjectListener listener = new DataCollectionObjectListener() {

        @Override
        public void onSelectItem(int origin, String name, String description, DataType dataType) {
        }

        @Override
        public void onSelectTable(int origin, String name, String description) {
            if (origin == DataCollectionObject.AGENT)
                updateColumnsFromAgent(name, false, null);
        }
    };
    dialogArea.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            editor.removeListener(listener);
        }
    });
    editor.addListener(listener);
    return dialogArea;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) DataCollectionObjectListener(org.netxms.ui.eclipse.datacollection.api.DataCollectionObjectListener) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataType(org.netxms.client.constants.DataType) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

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 TableViewer (org.eclipse.jface.viewers.TableViewer)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)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 Label (org.eclipse.swt.widgets.Label)1 DataType (org.netxms.client.constants.DataType)1 ColumnDefinition (org.netxms.client.datacollection.ColumnDefinition)1 DataCollectionObjectListener (org.netxms.ui.eclipse.datacollection.api.DataCollectionObjectListener)1