Search in sources :

Example 1 with TableThreshold

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

the class TableThresholds method editThreshold.

/**
 * Edit selected threshold
 */
private void editThreshold() {
    final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
    if (selection.size() == 1) {
        final TableThreshold t = (TableThreshold) selection.getFirstElement();
        EditTableThresholdDialog dlg = new EditTableThresholdDialog(getShell(), t, editor.getCallback());
        if (dlg.open() == Window.OK) {
            thresholdList.update(t, null);
        }
    }
}
Also used : EditTableThresholdDialog(org.netxms.ui.eclipse.datacollection.dialogs.EditTableThresholdDialog) TableThreshold(org.netxms.client.datacollection.TableThreshold) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with TableThreshold

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

the class TableThresholds method moveSelectionDown.

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

Example 3 with TableThreshold

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

the class TableThresholds 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();
    thresholds = new ArrayList<TableThreshold>();
    for (TableThreshold t : dci.getThresholds()) thresholds.add(new TableThreshold(t));
    // Initiate loading of event manager plugin if it was not loaded before
    // $NON-NLS-1$
    Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    Composite thresholdListArea = 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;
    thresholdListArea.setLayoutData(gd);
    layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    thresholdListArea.setLayout(layout);
    new Label(thresholdListArea, SWT.NONE).setText(Messages.get().TableThresholds_Thresholds);
    thresholdList = new TableViewer(thresholdListArea, 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;
    thresholdList.getControl().setLayoutData(gd);
    setupThresholdList();
    thresholdList.setInput(thresholds.toArray());
    Composite leftButtons = new Composite(thresholdListArea, 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().TableThresholds_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().TableThresholds_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(thresholdListArea, 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);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().TableThresholds_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) {
            addThreshold();
        }
    });
    duplicateButton = new Button(buttons, SWT.PUSH);
    duplicateButton.setText("Duplicate");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    duplicateButton.setLayoutData(rd);
    duplicateButton.setEnabled(false);
    duplicateButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            duplicateThreshold();
        }
    });
    modifyButton = new Button(buttons, SWT.PUSH);
    modifyButton.setText(Messages.get().TableThresholds_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) {
            editThreshold();
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().TableThresholds_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) {
            deleteThresholds();
        }
    });
    /**
     * Selection change listener for thresholds list **
     */
    thresholdList.addSelectionChangedListener(new ISelectionChangedListener() {

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

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editThreshold();
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) EventTemplate(org.netxms.client.events.EventTemplate) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableThreshold(org.netxms.client.datacollection.TableThreshold) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 4 with TableThreshold

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

the class TableThresholds method addThreshold.

/**
 * Add new threshold
 */
private void addThreshold() {
    final TableThreshold t = new TableThreshold();
    final EditTableThresholdDialog dlg = new EditTableThresholdDialog(getShell(), t, editor.getCallback());
    if (dlg.open() == Window.OK) {
        thresholds.add(t);
        thresholdList.setInput(thresholds.toArray());
        thresholdList.setSelection(new StructuredSelection(t));
    }
}
Also used : EditTableThresholdDialog(org.netxms.ui.eclipse.datacollection.dialogs.EditTableThresholdDialog) TableThreshold(org.netxms.client.datacollection.TableThreshold) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 5 with TableThreshold

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

the class DciLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    DataCollectionObject dci = (DataCollectionObject) element;
    switch(columnIndex) {
        case DataCollectionEditor.COLUMN_ID:
            return Long.toString(dci.getId());
        case DataCollectionEditor.COLUMN_ORIGIN:
            return originTexts.get(dci.getOrigin());
        case DataCollectionEditor.COLUMN_DESCRIPTION:
            return dci.getDescription();
        case DataCollectionEditor.COLUMN_PARAMETER:
            return dci.getName();
        case DataCollectionEditor.COLUMN_DATATYPE:
            if (dci instanceof DataCollectionItem)
                return DataCollectionDisplayInfo.getDataTypeName(((DataCollectionItem) dci).getDataType());
            return Messages.get().DciLabelProvider_Table;
        case DataCollectionEditor.COLUMN_INTERVAL:
            if (dci.isUseAdvancedSchedule())
                return Messages.get().DciLabelProvider_CustomSchedule;
            if (dci.getPollingInterval() <= 0)
                return Messages.get().DciLabelProvider_Default;
            return Integer.toString(dci.getPollingInterval());
        case DataCollectionEditor.COLUMN_RETENTION:
            if ((dci.getFlags() & DataCollectionItem.DCF_NO_STORAGE) != 0)
                return Messages.get().DciLabelProvider_None;
            int days = dci.getRetentionTime();
            if (days <= 0)
                return Messages.get().DciLabelProvider_Default;
            return Integer.toString(days) + ((days == 1) ? Messages.get().DciLabelProvider_Day : Messages.get().DciLabelProvider_Days);
        case DataCollectionEditor.COLUMN_STATUS:
            return statusTexts.get(dci.getStatus());
        case DataCollectionEditor.COLUMN_THRESHOLD:
            StringBuilder thresholds = new StringBuilder();
            if ((dci instanceof DataCollectionItem)) {
                ArrayList<Threshold> list = ((DataCollectionItem) dci).getThresholds();
                for (int i = 0; i < list.size(); i++) {
                    Threshold tr = list.get(i);
                    int f = tr.getFunction();
                    StringBuilder text = new StringBuilder(ThresholdLabelProvider.FUNCTIONS[f]);
                    text.append(tr.getSampleCount());
                    // $NON-NLS-1$
                    text.append(") ");
                    if (f != Threshold.F_SCRIPT) {
                        text.append(ThresholdLabelProvider.OPERATIONS[tr.getOperation()]);
                        text.append(' ');
                        text.append(tr.getValue());
                    }
                    thresholds.append(text);
                    if (i < list.size() - 1)
                        // $NON-NLS-1$
                        thresholds.append(", ");
                }
            }
            if ((dci instanceof DataCollectionTable)) {
                List<TableThreshold> list = ((DataCollectionTable) dci).getThresholds();
                for (int i = 0; i < list.size(); i++) {
                    thresholds.append(list.get(i).getConditionAsText());
                    if (i + 1 != list.size())
                        // $NON-NLS-1$
                        thresholds.append(", ");
                }
            }
            return thresholds.toString();
        case DataCollectionEditor.COLUMN_TEMPLATE:
            if (dci.getTemplateId() == 0)
                return null;
            AbstractObject object = session.findObjectById(dci.getTemplateId());
            if (object == null)
                return Messages.get().DciLabelProvider_Unknown;
            if (!(object instanceof Template))
                return object.getObjectName();
            Set<AbstractObject> parents = object.getAllParents(null);
            StringBuilder sb = new StringBuilder();
            for (AbstractObject parent : parents) {
                sb.append(parent.getObjectName());
                // $NON-NLS-1$
                sb.append("/");
            }
            sb.append(object.getObjectName());
            return sb.toString();
    }
    return null;
}
Also used : DataCollectionObject(org.netxms.client.datacollection.DataCollectionObject) AbstractObject(org.netxms.client.objects.AbstractObject) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) TableThreshold(org.netxms.client.datacollection.TableThreshold) DataCollectionTable(org.netxms.client.datacollection.DataCollectionTable) Threshold(org.netxms.client.datacollection.Threshold) TableThreshold(org.netxms.client.datacollection.TableThreshold) Template(org.netxms.client.objects.Template)

Aggregations

TableThreshold (org.netxms.client.datacollection.TableThreshold)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 EditTableThresholdDialog (org.netxms.ui.eclipse.datacollection.dialogs.EditTableThresholdDialog)2 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 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 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)1 DataCollectionObject (org.netxms.client.datacollection.DataCollectionObject)1