use of org.netxms.client.datacollection.Threshold in project netxms by netxms.
the class Thresholds method createContents.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
// 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");
Composite dialogArea = (Composite) super.createContents(parent);
dci = editor.getObjectAsItem();
thresholds = new ArrayList<Threshold>(dci.getThresholds().size());
for (Threshold t : dci.getThresholds()) thresholds.add(new Threshold(t));
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
instance = new LabeledText(dialogArea, SWT.NONE);
instance.setLabel(Messages.get().Thresholds_Instance);
instance.setText(dci.getInstance());
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
instance.setLayoutData(gd);
if (// DCI created by instance discovery
dci.getTemplateId() == dci.getNodeId())
instance.getTextControl().setEditable(false);
checkAllThresholds = new Button(dialogArea, SWT.CHECK);
checkAllThresholds.setText(Messages.get().Thresholds_ProcessAll);
checkAllThresholds.setSelection(dci.isProcessAllThresholds());
Composite thresholdArea = new Composite(dialogArea, SWT.NONE);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.horizontalSpan = 2;
thresholdArea.setLayoutData(gd);
layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.INNER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
layout.numColumns = 2;
thresholdArea.setLayout(layout);
new Label(thresholdArea, SWT.NONE).setText(Messages.get().Thresholds_Thresholds);
thresholdList = new TableViewer(thresholdArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
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(thresholdArea, 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().Thresholds_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().Thresholds_Down);
downButton.setEnabled(false);
downButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
moveDown();
}
});
Composite buttons = new Composite(thresholdArea, 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().Thresholds_Add);
RowData 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().Thresholds_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().Thresholds_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();
int index = thresholds.indexOf(selection.getFirstElement());
upButton.setEnabled((selection.size() == 1) && (index > 0));
downButton.setEnabled((selection.size() == 1) && (index >= 0) && (index < thresholds.size() - 1));
modifyButton.setEnabled(selection.size() == 1);
deleteButton.setEnabled(selection.size() > 0);
duplicateButton.setEnabled(selection.size() > 0);
}
});
thresholdList.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
editThreshold();
}
});
return dialogArea;
}
use of org.netxms.client.datacollection.Threshold in project netxms by netxms.
the class Thresholds method duplicateThreshold.
/**
* Duplicate selected threshold
*/
@SuppressWarnings("unchecked")
private void duplicateThreshold() {
final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
if (selection.size() > 0) {
List<Threshold> list = selection.toList();
for (Threshold t : list) {
thresholds.add(thresholds.indexOf(t) + 1, new Threshold(t));
thresholdList.setInput(thresholds.toArray());
}
}
}
use of org.netxms.client.datacollection.Threshold in project netxms by netxms.
the class Thresholds method editThreshold.
/**
* Edit selected threshold
*/
private void editThreshold() {
final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
if (selection.size() == 1) {
final Threshold threshold = (Threshold) selection.getFirstElement();
EditThresholdDialog dlg = new EditThresholdDialog(getShell(), threshold);
if (dlg.open() == Window.OK) {
thresholdList.update(threshold, null);
}
}
}
use of org.netxms.client.datacollection.Threshold in project netxms by netxms.
the class Thresholds method moveDown.
/**
* Move currently selected threshold down
*/
private void moveDown() {
final IStructuredSelection selection = (IStructuredSelection) thresholdList.getSelection();
if (selection.size() == 1) {
final Threshold threshold = (Threshold) selection.getFirstElement();
int index = thresholds.indexOf(threshold);
if ((index < thresholds.size() - 1) && (index >= 0)) {
Collections.swap(thresholds, index + 1, index);
thresholdList.setInput(thresholds.toArray());
thresholdList.setSelection(new StructuredSelection(threshold));
}
}
}
Aggregations