Search in sources :

Example 1 with ScriptEditor

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;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) WidgetFactory(org.netxms.ui.eclipse.tools.WidgetFactory) GridData(org.eclipse.swt.layout.GridData) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)

Example 2 with ScriptEditor

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

Example 3 with ScriptEditor

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;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) Composite(org.eclipse.swt.widgets.Composite) EventTemplate(org.netxms.client.events.EventTemplate) ArrayList(java.util.ArrayList) EventObject(org.netxms.client.events.EventObject) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor) GridLayout(org.eclipse.swt.layout.GridLayout) MouseListener(org.eclipse.swt.events.MouseListener) AbstractObject(org.netxms.client.objects.AbstractObject) GridData(org.eclipse.swt.layout.GridData)

Example 4 with ScriptEditor

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)

Example 5 with ScriptEditor

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;
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)

Aggregations

ScriptEditor (org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)15 Composite (org.eclipse.swt.widgets.Composite)14 GridData (org.eclipse.swt.layout.GridData)13 GridLayout (org.eclipse.swt.layout.GridLayout)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Label (org.eclipse.swt.widgets.Label)7 Button (org.eclipse.swt.widgets.Button)5 FillLayout (org.eclipse.swt.layout.FillLayout)4 ModifyEvent (org.eclipse.swt.events.ModifyEvent)3 ModifyListener (org.eclipse.swt.events.ModifyListener)3 WidgetFactory (org.netxms.ui.eclipse.tools.WidgetFactory)3 SashForm (org.eclipse.swt.custom.SashForm)2 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)2 Section (org.eclipse.ui.forms.widgets.Section)2 ArrayList (java.util.ArrayList)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1