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);
}
}
}
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));
}
}
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;
}
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));
}
}
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;
}
Aggregations