Search in sources :

Example 11 with ScriptEditor

use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.

the class InstanceDiscovery 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);
    editor = (DataCollectionObjectEditor) getElement().getAdapter(DataCollectionObjectEditor.class);
    dco = editor.getObject();
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    discoveryMethod = WidgetHelper.createLabeledCombo(dialogArea, SWT.BORDER | SWT.READ_ONLY, Messages.get().InstanceDiscovery_Method, WidgetHelper.DEFAULT_LAYOUT_DATA);
    discoveryMethod.add(Messages.get().InstanceDiscovery_None);
    discoveryMethod.add(Messages.get().InstanceDiscovery_AgentList);
    discoveryMethod.add(Messages.get().InstanceDiscovery_AgentTable);
    discoveryMethod.add(Messages.get().InstanceDiscovery_SnmpWalkValues);
    discoveryMethod.add(Messages.get().InstanceDiscovery_SnmpWalkOids);
    discoveryMethod.add(Messages.get().InstanceDiscovery_Script);
    discoveryMethod.select(dco.getInstanceDiscoveryMethod());
    discoveryMethod.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int method = discoveryMethod.getSelectionIndex();
            discoveryData.setLabel(getDataLabel(method));
            discoveryData.setEnabled(method != DataCollectionObject.IDM_NONE);
            filterScript.setEnabled(method != DataCollectionObject.IDM_NONE);
            instanceRetentionMode.setEnabled(method != DataCollectionObject.IDM_NONE);
            instanceRetentionTime.setEnabled(method != DataCollectionObject.IDM_NONE && instanceRetentionMode.getSelectionIndex() > 0);
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    discoveryData = new LabeledText(dialogArea, SWT.NONE);
    discoveryData.setLabel(getDataLabel(dco.getInstanceDiscoveryMethod()));
    discoveryData.setText(dco.getInstanceDiscoveryData());
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    discoveryData.setLayoutData(gd);
    discoveryData.setEnabled(dco.getInstanceDiscoveryMethod() != DataCollectionObject.IDM_NONE);
    groupRetention = new Group(dialogArea, SWT.NONE);
    groupRetention.setText("Instance retention");
    gd = new GridData();
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    groupRetention.setLayoutData(gd);
    GridLayout retentionLayout = new GridLayout();
    retentionLayout.numColumns = 2;
    retentionLayout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
    groupRetention.setLayout(retentionLayout);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    instanceRetentionMode = WidgetHelper.createLabeledCombo(groupRetention, SWT.READ_ONLY, "Instance retention mode", gd);
    instanceRetentionMode.add("Server default");
    instanceRetentionMode.add("Custom");
    instanceRetentionMode.select(dco.getInstanceRetentionTime() == -1 ? 0 : 1);
    instanceRetentionMode.setEnabled(dco.getInstanceDiscoveryMethod() != DataCollectionObject.IDM_NONE);
    instanceRetentionMode.addSelectionListener(new SelectionListener() {

        /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
          */
        @Override
        public void widgetSelected(SelectionEvent e) {
            instanceRetentionTime.setEnabled(instanceRetentionMode.getSelectionIndex() == 1);
        }

        /* (non-Javadoc)
          * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
          */
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    instanceRetentionTime = WidgetHelper.createLabeledSpinner(groupRetention, SWT.BORDER, "Instance retention time (days)", 0, 100, new GridData());
    instanceRetentionTime.setSelection(dco.getInstanceRetentionTime());
    instanceRetentionTime.setEnabled(instanceRetentionMode.getSelectionIndex() > 0);
    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$1\tInstance to test\r\n\r\nReturn value:\r\n\ttrue/false to accept or reject instance without additional changes or\r\n\tarray of two or three elements to modify instance:\r\n\t\t1st element - true/false to indicate acceptance;\r\n\t\t2nd element - new instance name;\r\n\t\t3rd element - new instance display name.");
        }
    };
    filterScript = (ScriptEditor) WidgetHelper.createLabeledControl(dialogArea, SWT.BORDER, factory, Messages.get().InstanceDiscovery_FilterScript, gd);
    filterScript.addFunctions(Arrays.asList(DCI_FUNCTIONS));
    filterScript.addVariables(Arrays.asList(DCI_VARIABLES));
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    filterScript.setLayoutData(gd);
    filterScript.setText(dco.getInstanceDiscoveryFilter());
    filterScript.setEnabled(dco.getInstanceDiscoveryMethod() != DataCollectionObject.IDM_NONE);
    return dialogArea;
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) WidgetFactory(org.netxms.ui.eclipse.tools.WidgetFactory) LabeledText(org.netxms.ui.eclipse.widgets.LabeledText) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)

Example 12 with ScriptEditor

use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.

the class RuleFilterScript method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    editor = (RuleEditor) getElement().getAdapter(RuleEditor.class);
    rule = editor.getRule();
    Composite dialogArea = new Composite(parent, SWT.NONE);
    dialogArea.setLayout(new FillLayout());
    scriptEditor = new ScriptEditor(dialogArea, SWT.BORDER, SWT.H_SCROLL | SWT.V_SCROLL, false, "Global variables:\r\n\t$object\tevent source object\r\n\t$node\tevent source object if it's class is Node\r\n\t$event\tevent being processed\r\nLocal variables:\r\n\tEVENT_CODE\t\tevent's code\r\n\tSEVERITY\t\tevent's severity as number\r\n\tSEVERITY_TEXT\tevent's severity as text\r\n\tOBJECT_ID\t\tevent source object's ID\r\n\tEVENT_TEXT\t\tevent's message text\r\n\tUSER_TAG\t\tevent's user tag\r\n\r\nReturn value: true to pass event through rule filter");
    scriptEditor.setText(rule.getScript());
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) FillLayout(org.eclipse.swt.layout.FillLayout) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)

Example 13 with ScriptEditor

use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.

the class ConditionScript 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 = (Condition) getElement().getAdapter(Condition.class);
    if (// Paranoid check
    object == null)
        return dialogArea;
    initialScript = object.getScript();
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    // Script
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText(Messages.get().ConditionScript_Script);
    filterSource = new ScriptEditor(dialogArea, SWT.BORDER, SWT.H_SCROLL | SWT.V_SCROLL, false, "Variables:\r\n\t$values\tarray containing values for configured DCIs (in same order as DCIs are listed in configuration)\r\n\r\nReturn value: true/false to indicate if condition is active or not");
    filterSource.setText(object.getScript());
    GridData 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) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) ScriptEditor(org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor)

Example 14 with ScriptEditor

use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.

the class AutoApply 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 = (Template) getElement().getAdapter(Template.class);
    if (// Paranoid check
    object == null)
        return dialogArea;
    initialFlags = object.getFlags();
    initialApplyFilter = object.getAutoApplyFilter();
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    // Enable/disable check box
    checkboxEnableApply = new Button(dialogArea, SWT.CHECK);
    checkboxEnableApply.setText(Messages.get().AutoApply_AutoApply);
    checkboxEnableApply.setSelection(object.isAutoApplyEnabled());
    checkboxEnableApply.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (checkboxEnableApply.getSelection()) {
                filterSource.setEnabled(true);
                filterSource.setFocus();
                checkboxEnableRemove.setEnabled(true);
            } else {
                filterSource.setEnabled(false);
                checkboxEnableRemove.setEnabled(false);
            }
        }
    });
    // Enable/disable check box
    checkboxEnableRemove = new Button(dialogArea, SWT.CHECK);
    checkboxEnableRemove.setText(Messages.get().AutoApply_AutoRemove);
    checkboxEnableRemove.setSelection(object.isAutoRemoveEnabled());
    checkboxEnableRemove.setEnabled(object.isAutoApplyEnabled());
    // Filtering script
    Label label = new Label(dialogArea, SWT.NONE);
    label.setText(Messages.get().AutoApply_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.\r\n\r\nReturn value: true to apply this template to node, false to remove, null to make no changes.");
    filterSource.setText(object.getAutoApplyFilter());
    filterSource.setEnabled(object.isAutoApplyEnabled());
    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)

Example 15 with ScriptEditor

use of org.netxms.ui.eclipse.nxsl.widgets.ScriptEditor in project netxms by netxms.

the class AutoDeploy 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 = (AgentPolicy) getElement().getAdapter(AgentPolicy.class);
    if (// Paranoid check
    object == null)
        return dialogArea;
    initialFlags = object.getFlags();
    initialAutoDeployFilter = object.getAutoDeployFilter();
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    // Enable/disable check box
    checkboxEnableDeploy = new Button(dialogArea, SWT.CHECK);
    checkboxEnableDeploy.setText("Deploy this policy automatically to nodes selected by filter");
    checkboxEnableDeploy.setSelection(object.isAutoDeployEnabled());
    checkboxEnableDeploy.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (checkboxEnableDeploy.getSelection()) {
                filterSource.setEnabled(true);
                filterSource.setFocus();
                checkboxEnableUninstall.setEnabled(true);
            } else {
                filterSource.setEnabled(false);
                checkboxEnableUninstall.setEnabled(false);
            }
        }
    });
    checkboxEnableUninstall = new Button(dialogArea, SWT.CHECK);
    checkboxEnableUninstall.setText("Uninstall this policy automatically when node no longer passes through filter");
    checkboxEnableUninstall.setSelection(object.isAutoUninstallEnabled());
    checkboxEnableUninstall.setEnabled(object.isAutoDeployEnabled());
    // 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 deploy this policy onto node, false to uninstall, null to make no changes.");
    filterSource.setText(object.getAutoDeployFilter());
    filterSource.setEnabled(object.isAutoDeployEnabled());
    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