use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.
the class SummaryTableFilter method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
table = (DciSummaryTable) getElement().getAdapter(DciSummaryTable.class);
Composite dialogArea = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.widthHint = 0;
gd.heightHint = 0;
final WidgetFactory factory = new WidgetFactory() {
@Override
public Control createControl(Composite parent, int style) {
return new ScriptEditor(parent, style, SWT.H_SCROLL | SWT.V_SCROLL, false, "Variables:\r\n\t$object\tcurrent object\r\n\t$node\tcurrent object if it's class is Node\r\n\r\nReturn value: true to include current object into this summary table");
}
};
filter = (ScriptEditor) WidgetHelper.createLabeledControl(dialogArea, SWT.BORDER, factory, Messages.get().SummaryTableFilter_FilterScript, gd);
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
filter.setLayoutData(gd);
filter.setText(table.getNodeFilter());
return dialogArea;
}
use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.
the class Transformation 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);
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
if (editor.getObject() instanceof DataCollectionItem) {
deltaCalculation = WidgetHelper.createLabeledCombo(dialogArea, SWT.BORDER | SWT.READ_ONLY, Messages.get().Transformation_Step1, WidgetHelper.DEFAULT_LAYOUT_DATA);
deltaCalculation.add(Messages.get().Transformation_DeltaNone);
deltaCalculation.add(Messages.get().Transformation_DeltaSimple);
deltaCalculation.add(Messages.get().Transformation_DeltaAvgPerSec);
deltaCalculation.add(Messages.get().Transformation_DeltaAvgPerMin);
deltaCalculation.select(editor.getObjectAsItem().getDeltaCalculation());
}
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.widthHint = 0;
gd.heightHint = 0;
final WidgetFactory factory = new WidgetFactory() {
@Override
public Control createControl(Composite parent, int style) {
return new ScriptEditor(parent, style, SWT.H_SCROLL | SWT.V_SCROLL, true, "Variables:\r\n\t$1\t\t\tvalue to transform (after delta calculation);\r\n\t$dci\t\t\tthis DCI object;\r\n\t$isCluster\ttrue if DCI is on cluster;\r\n\t$node\t\tcurrent node object (null if DCI is not on the node);\r\n\t$object\t\tcurrent object.\r\n\r\nReturn value: transformed DCI value or null to keep original value.");
}
};
transformationScript = (ScriptEditor) WidgetHelper.createLabeledControl(dialogArea, SWT.BORDER, factory, (editor.getObject() instanceof DataCollectionItem) ? Messages.get().Transformation_Step2 : Messages.get().Transformation_Script, gd);
transformationScript.addFunctions(Arrays.asList(DCI_FUNCTIONS));
transformationScript.addVariables(Arrays.asList(DCI_VARIABLES));
gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
transformationScript.setLayoutData(gd);
transformationScript.setText(editor.getObject().getTransformationScript());
if (editor.getObject() instanceof DataCollectionItem) {
testScriptButton = new Button(transformationScript.getParent(), SWT.PUSH);
testScriptButton.setText(Messages.get().Transformation_Test);
gd = new GridData();
gd.horizontalAlignment = SWT.RIGHT;
gd.widthHint = WidgetHelper.BUTTON_WIDTH_HINT;
testScriptButton.setLayoutData(gd);
testScriptButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
TestTransformationDlg dlg = new TestTransformationDlg(getShell(), editor.getObject().getNodeId(), transformationScript.getText());
dlg.open();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
}
return dialogArea;
}
use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.
the class RuleEditor method createConditionControl.
/**
* Create condition summary control
*
* @param parent
* @param rule
* @return
*/
private Control createConditionControl(Composite parent, final EventProcessingPolicyRule rule) {
Composite clientArea = new Composite(parent, SWT.NONE);
clientArea.setBackground(SharedColors.getColor(SharedColors.RULE_EDITOR_BACKGROUND, getDisplay()));
GridLayout layout = new GridLayout();
layout.verticalSpacing = 0;
clientArea.setLayout(layout);
boolean needAnd = false;
if (((rule.getSources().size() > 0) && rule.isSourceInverted()) || ((rule.getSources().size() == 0) && (rule.getEvents().size() > 0) && rule.isEventsInverted()))
createLabel(clientArea, 0, true, Messages.get().RuleEditor_IF_NOT, null);
else
createLabel(clientArea, 0, true, Messages.get().RuleEditor_IF, null);
/* source */
if (rule.getSources().size() > 0) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleSourceObjects#0");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_SourceIs, needAnd, rule.isSourceInverted(), listener);
for (Long id : rule.getSources()) {
CLabel clabel = createCLabel(clientArea, 2, false);
clabel.addMouseListener(listener);
AbstractObject object = session.findObjectById(id);
if (object != null) {
clabel.setText(object.getObjectName());
clabel.setImage(labelProvider.getImage(object));
} else {
// $NON-NLS-1$ //$NON-NLS-2$
clabel.setText("[" + id.toString() + "]");
clabel.setImage(SharedIcons.IMG_UNKNOWN_OBJECT);
}
}
needAnd = true;
}
/* events */
if (rule.getEvents().size() > 0) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleEvents#10");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_EventIs, needAnd, rule.isEventsInverted(), listener);
List<EventObject> sortedEvents = new ArrayList<EventObject>(rule.getEvents().size());
for (Long code : rule.getEvents()) {
EventObject event = session.findEventObjectByCode(code);
if (event == null) {
event = new EventTemplate(code);
((EventTemplate) event).setSeverity(Severity.UNKNOWN);
// $NON-NLS-1$ //$NON-NLS-2$
event.setName("<" + code.toString() + ">");
}
sortedEvents.add(event);
}
Collections.sort(sortedEvents, new Comparator<EventObject>() {
@Override
public int compare(EventObject t1, EventObject t2) {
return t1.getName().compareToIgnoreCase(t2.getName());
}
});
for (EventObject e : sortedEvents) {
CLabel clabel = createCLabel(clientArea, 2, false);
clabel.addMouseListener(listener);
clabel.setText(e.getName());
if (e instanceof EventTemplate)
clabel.setImage(StatusDisplayInfo.getStatusImage(((EventTemplate) e).getSeverity()));
else
clabel.setImage(SharedIcons.IMG_CONTAINER);
}
needAnd = true;
}
/* severity */
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_ANY) != EventProcessingPolicyRule.SEVERITY_ANY) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleSeverityFilter#20");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_SeverityIs, needAnd, false, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_NORMAL) != 0)
addSeverityLabel(clientArea, Severity.NORMAL, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_WARNING) != 0)
addSeverityLabel(clientArea, Severity.WARNING, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_MINOR) != 0)
addSeverityLabel(clientArea, Severity.MINOR, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_MAJOR) != 0)
addSeverityLabel(clientArea, Severity.MAJOR, listener);
if ((rule.getFlags() & EventProcessingPolicyRule.SEVERITY_CRITICAL) != 0)
addSeverityLabel(clientArea, Severity.CRITICAL, listener);
needAnd = true;
}
/* script */
if ((rule.getScript() != null) && !rule.getScript().isEmpty()) {
// $NON-NLS-1$
final MouseListener listener = createMouseListener("org.netxms.ui.eclipse.epp.propertypages.RuleFilterScript#30");
addConditionGroupLabel(clientArea, Messages.get().RuleEditor_ScriptIs, needAnd, false, listener);
ScriptEditor scriptEditor = new ScriptEditor(clientArea, SWT.BORDER, SWT.NONE);
GridData gd = new GridData();
gd.horizontalIndent = INDENT * 2;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
scriptEditor.setLayoutData(gd);
scriptEditor.setText(rule.getScript());
scriptEditor.getTextWidget().setEditable(false);
scriptEditor.getTextWidget().addMouseListener(listener);
}
return clientArea;
}
use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.
the class ScriptEditDialog method createDialogArea.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
editor = new ScriptEditor(area, SWT.BORDER, SWT.H_SCROLL | SWT.V_SCROLL, true, hints);
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.widthHint = 600;
gd.heightHint = 400;
editor.setLayoutData(gd);
editor.setText(script);
return area;
}
use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.
the class AutoBind method createContents.
/* (non-Javadoc)
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createContents(Composite parent) {
Composite dialogArea = new Composite(parent, SWT.NONE);
object = (Container) getElement().getAdapter(Container.class);
if (// Paranoid check
object == null)
return dialogArea;
initialFlags = object.getFlags();
initialAutoBindFilter = object.getAutoBindFilter();
GridLayout layout = new GridLayout();
layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
layout.marginWidth = 0;
layout.marginHeight = 0;
dialogArea.setLayout(layout);
// Enable/disable check box
checkboxEnableBind = new Button(dialogArea, SWT.CHECK);
checkboxEnableBind.setText(Messages.get().AutoBind_AutoBind);
checkboxEnableBind.setSelection(object.isAutoBindEnabled());
checkboxEnableBind.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
@Override
public void widgetSelected(SelectionEvent e) {
if (checkboxEnableBind.getSelection()) {
filterSource.setEnabled(true);
filterSource.setFocus();
checkboxEnableUnbind.setEnabled(true);
} else {
filterSource.setEnabled(false);
checkboxEnableUnbind.setEnabled(false);
}
}
});
checkboxEnableUnbind = new Button(dialogArea, SWT.CHECK);
checkboxEnableUnbind.setText(Messages.get().AutoBind_AUtoUnbind);
checkboxEnableUnbind.setSelection(object.isAutoUnbindEnabled());
checkboxEnableUnbind.setEnabled(object.isAutoBindEnabled());
// Filtering script
Label label = new Label(dialogArea, SWT.NONE);
label.setText(Messages.get().AutoBind_Script);
GridData gd = new GridData();
gd.verticalIndent = WidgetHelper.DIALOG_SPACING;
label.setLayoutData(gd);
filterSource = new ScriptEditor(dialogArea, SWT.BORDER, SWT.H_SCROLL | SWT.V_SCROLL, true, "Variables:\r\n\t$node\tnode being tested (null if object is not a node).\r\n\t$object\tobject being tested.\r\n\r\nReturn value: true to bind node to this container, false to unbind, null to make no changes.");
filterSource.setText(object.getAutoBindFilter());
filterSource.setEnabled(object.isAutoBindEnabled());
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.verticalAlignment = SWT.FILL;
gd.widthHint = 0;
gd.heightHint = 0;
filterSource.setLayoutData(gd);
return dialogArea;
}
Aggregations