Search in sources :

Example 1 with ColumnDefinition

use of org.netxms.client.datacollection.ColumnDefinition 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)

Example 2 with ColumnDefinition

use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.

the class TableColumns method updateColumnsFromAgent.

/**
 * Update columns from real table
 */
private void updateColumnsFromAgent(final String name, final boolean interactive, final AbstractObject queryObject) {
    final NXCSession session = ConsoleSharedData.getSession();
    ConsoleJob job = new ConsoleJob(Messages.get().TableColumns_JobName, null, Activator.PLUGIN_ID, null) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            try {
                final org.netxms.client.Table table;
                if (editor.getSourceNode() != 0) {
                    table = session.queryAgentTable(editor.getSourceNode(), name);
                } else {
                    table = session.queryAgentTable((queryObject != null) ? queryObject.getObjectId() : dci.getNodeId(), name);
                }
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        columns.clear();
                        for (int i = 0; i < table.getColumnCount(); i++) {
                            ColumnDefinition c = new ColumnDefinition(table.getColumnName(i), table.getColumnDisplayName(i));
                            c.setDataType(table.getColumnDefinition(i).getDataType());
                            c.setInstanceColumn(table.getColumnDefinition(i).isInstanceColumn());
                            columns.add(c);
                        }
                        columnList.setInput(columns.toArray());
                    }
                });
            } catch (Exception e) {
                Activator.logError("Cannot read table column definition from agent", e);
                if (interactive) {
                    final String msg = (e instanceof NXCException) ? e.getLocalizedMessage() : "Internal error";
                    runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialogHelper.openError(getShell(), "Error", String.format("Cannot read table column definition from agent (%s)", msg));
                        }
                    });
                }
            }
        }

        @Override
        protected String getErrorMessage() {
            return null;
        }
    };
    job.setUser(false);
    job.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NXCSession(org.netxms.client.NXCSession) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) NXCException(org.netxms.client.NXCException) NXCException(org.netxms.client.NXCException) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Example 3 with ColumnDefinition

use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.

the class TableColumns method editColumn.

/**
 * Edit selected threshold
 */
private void editColumn() {
    final IStructuredSelection selection = (IStructuredSelection) columnList.getSelection();
    if (selection.size() == 1) {
        final ColumnDefinition column = (ColumnDefinition) selection.getFirstElement();
        EditColumnDialog dlg = new EditColumnDialog(getShell(), column);
        if (dlg.open() == Window.OK) {
            columnList.update(column, null);
        }
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EditColumnDialog(org.netxms.ui.eclipse.datacollection.dialogs.EditColumnDialog) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Example 4 with ColumnDefinition

use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.

the class TableColumns method addColumn.

/**
 * Add new threshold
 */
private void addColumn() {
    final InputDialog idlg = new InputDialog(getShell(), Messages.get().TableColumns_NewColumn, Messages.get().TableColumns_ColumnName, "", new // $NON-NLS-1$
    IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.trim().isEmpty())
                return Messages.get().TableColumns_WarningText;
            return null;
        }
    });
    if (idlg.open() == Window.OK) {
        final ColumnDefinition column = new ColumnDefinition(idlg.getValue(), idlg.getValue());
        final EditColumnDialog dlg = new EditColumnDialog(getShell(), column);
        if (dlg.open() == Window.OK) {
            columns.add(column);
            columnList.setInput(columns.toArray());
            columnList.setSelection(new StructuredSelection(column));
        }
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) EditColumnDialog(org.netxms.ui.eclipse.datacollection.dialogs.EditColumnDialog) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Example 5 with ColumnDefinition

use of org.netxms.client.datacollection.ColumnDefinition in project netxms by netxms.

the class TableColumns method moveSelectionDown.

/**
 * Move selected element down
 */
private void moveSelectionDown() {
    final IStructuredSelection selection = (IStructuredSelection) columnList.getSelection();
    if (selection.size() != 1)
        return;
    final ColumnDefinition column = (ColumnDefinition) selection.getFirstElement();
    int index = columns.indexOf(column);
    if (index < columns.size() - 1) {
        Collections.swap(columns, index, index + 1);
        columnList.setInput(columns.toArray());
        columnList.setSelection(new StructuredSelection(column));
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ColumnDefinition(org.netxms.client.datacollection.ColumnDefinition)

Aggregations

ColumnDefinition (org.netxms.client.datacollection.ColumnDefinition)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 EditColumnDialog (org.netxms.ui.eclipse.datacollection.dialogs.EditColumnDialog)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)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