Search in sources :

Example 1 with TestTransformationDlg

use of org.netxms.ui.eclipse.datacollection.dialogs.TestTransformationDlg 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;
}
Also used : TestTransformationDlg(org.netxms.ui.eclipse.datacollection.dialogs.TestTransformationDlg) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) WidgetFactory(org.netxms.ui.eclipse.tools.WidgetFactory) Button(org.eclipse.swt.widgets.Button) DataCollectionItem(org.netxms.client.datacollection.DataCollectionItem) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

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 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)1 TestTransformationDlg (org.netxms.ui.eclipse.datacollection.dialogs.TestTransformationDlg)1 ScriptEditor (org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)1 WidgetFactory (org.netxms.ui.eclipse.tools.WidgetFactory)1