Search in sources :

Example 1 with EventProcessingPolicy

use of org.netxms.client.events.EventProcessingPolicy in project netxms by netxms.

the class EventProcessingPolicyEditor method moveSelection.

/**
 * Moves rule selection
 *
 * @param anchor - where the selection is being moved
 */
public void moveSelection(RuleEditor anchor) {
    if (selection.contains(anchor)) {
        for (RuleEditor s : selection) s.setDragged(false);
        return;
    }
    List<RuleEditor> movedRuleEditors = new ArrayList<RuleEditor>();
    for (RuleEditor e : ruleEditors) {
        if (!selection.contains(e)) {
            movedRuleEditors.add(e);
            if (e.equals(anchor)) {
                RuleEditor curr = anchor;
                for (RuleEditor s : selection) {
                    movedRuleEditors.add(s);
                    s.moveBelow(curr);
                    curr = s;
                    s.setDragged(false);
                }
            }
        }
    }
    policy = new EventProcessingPolicy(movedRuleEditors.size());
    int i = 0;
    for (RuleEditor e : movedRuleEditors) {
        policy.addRule(e.getRule());
        e.setRuleNumber(++i);
    }
    ruleEditors = movedRuleEditors;
    anchor.setDragged(false);
    updateEditorAreaLayout();
    setModified(true);
}
Also used : EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy) ArrayList(java.util.ArrayList) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor)

Example 2 with EventProcessingPolicy

use of org.netxms.client.events.EventProcessingPolicy in project netxms by netxms.

the class EventProcessingPolicyEditor method savePolicy.

/**
 * Save policy to server
 */
private void savePolicy() {
    actionSave.setEnabled(false);
    new ConsoleJob(Messages.get().EventProcessingPolicyEditor_SaveJob_Title, this, Activator.PLUGIN_ID, JOB_FAMILY) {

        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            EventProcessingPolicy newPolicy = new EventProcessingPolicy(ruleEditors.size());
            for (RuleEditor editor : ruleEditors) newPolicy.addRule(editor.getRule());
            session.saveEventProcessingPolicy(policy);
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    modified = false;
                    firePropertyChange(PROP_DIRTY);
                }
            });
        }

        @Override
        protected void jobFinalize() {
            runInUIThread(new Runnable() {

                @Override
                public void run() {
                    actionSave.setEnabled(modified);
                }
            });
        }

        @Override
        protected String getErrorMessage() {
            return Messages.get().EventProcessingPolicyEditor_SaveJob_Error;
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor)

Example 3 with EventProcessingPolicy

use of org.netxms.client.events.EventProcessingPolicy in project netxms by netxms.

the class NXCSession method getEventProcessingPolicyInternal.

/**
 * Internal implementation for open/get event processing policy.
 *
 * @param readOnly true to get read-only copy of the policy
 * @return Event processing policy
 * @throws IOException  if socket I/O error occurs
 * @throws NXCException if NetXMS server returns an error or operation was timed out
 */
private EventProcessingPolicy getEventProcessingPolicyInternal(boolean readOnly) throws IOException, NXCException {
    NXCPMessage msg = newMessage(NXCPCodes.CMD_OPEN_EPP);
    msg.setFieldInt16(NXCPCodes.VID_READ_ONLY, readOnly ? 1 : 0);
    sendMessage(msg);
    NXCPMessage response = waitForRCC(msg.getMessageId());
    int numRules = response.getFieldAsInt32(NXCPCodes.VID_NUM_RULES);
    final EventProcessingPolicy policy = new EventProcessingPolicy(numRules);
    for (int i = 0; i < numRules; i++) {
        response = waitForMessage(NXCPCodes.CMD_EPP_RECORD, msg.getMessageId());
        policy.addRule(new EventProcessingPolicyRule(response, i + 1));
    }
    return policy;
}
Also used : EventProcessingPolicyRule(org.netxms.client.events.EventProcessingPolicyRule) EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy) NXCPMessage(org.netxms.base.NXCPMessage) ConnectionPoint(org.netxms.client.topology.ConnectionPoint) AccessPoint(org.netxms.client.objects.AccessPoint)

Example 4 with EventProcessingPolicy

use of org.netxms.client.events.EventProcessingPolicy in project netxms by netxms.

the class EventProcessingPolicyTest method testGetPolicy.

public void testGetPolicy() throws Exception {
    final NXCSession session = connect();
    EventProcessingPolicy p = session.getEventProcessingPolicy();
    for (EventProcessingPolicyRule r : p.getRules()) System.out.println("  " + r.getGuid() + " " + r.getComments());
    session.disconnect();
}
Also used : EventProcessingPolicyRule(org.netxms.client.events.EventProcessingPolicyRule) EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy)

Example 5 with EventProcessingPolicy

use of org.netxms.client.events.EventProcessingPolicy in project netxms by netxms.

the class RuleSelectionDialog method createDialogArea.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createDialogArea(Composite parent) {
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    Composite dialogArea = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout();
    layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
    layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
    layout.horizontalSpacing = WidgetHelper.OUTER_SPACING;
    layout.numColumns = 2;
    dialogArea.setLayout(layout);
    filterText = new FilterText(dialogArea, SWT.NONE, null, false);
    GridData gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    filterText.setLayoutData(gd);
    // $NON-NLS-1$
    final String filterString = settings.get("SelectRule.Filter");
    if (filterString != null)
        filterText.setText(filterString);
    viewer = new TableViewer(dialogArea, SWT.BORDER | SWT.FULL_SELECTION | (multiSelection ? SWT.MULTI : SWT.SINGLE) | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    TableColumn column = new TableColumn(viewer.getTable(), SWT.LEFT);
    column.setText("Rule #");
    column.setWidth(60);
    column = new TableColumn(viewer.getTable(), SWT.LEFT);
    column.setText("Rule Name");
    column.setWidth(250);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setComparator(new RuleComparator());
    viewer.setLabelProvider(new RuleLabelProvider());
    filter = new RuleListFilter();
    if (filterString != null)
        filter.setFilterString(filterString);
    viewer.addFilter(filter);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.horizontalSpan = 2;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.heightHint = 350;
    viewer.getTable().setLayoutData(gd);
    filterText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            filter.setFilterString(filterText.getText());
            viewer.refresh();
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            RuleSelectionDialog.this.okPressed();
        }
    });
    if (rulesCache == null) {
        viewer.getTable().setEnabled(false);
        getButton(IDialogConstants.OK_ID).setEnabled(false);
        final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
        ConsoleJob job = new ConsoleJob(Messages.get().RuleSelectionDialog_JobTitle, null, Activator.PLUGIN_ID, null) {

            @Override
            protected void runInternal(IProgressMonitor monitor) throws Exception {
                final EventProcessingPolicy policy = session.getEventProcessingPolicy();
                runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        viewer.getTable().setEnabled(true);
                        getButton(IDialogConstants.OK_ID).setEnabled(true);
                        viewer.setInput(policy.getRules().toArray());
                    }
                });
            }

            @Override
            protected String getErrorMessage() {
                return Messages.get().RuleSelectionDialog_JobError;
            }
        };
        job.setUser(false);
        job.start();
    } else {
        viewer.setInput(rulesCache.toArray());
    }
    return dialogArea;
}
Also used : RuleComparator(org.netxms.ui.eclipse.epp.dialogs.helpers.RuleComparator) NXCSession(org.netxms.client.NXCSession) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) RuleListFilter(org.netxms.ui.eclipse.epp.dialogs.helpers.RuleListFilter) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RuleLabelProvider(org.netxms.ui.eclipse.epp.dialogs.helpers.RuleLabelProvider) EventProcessingPolicy(org.netxms.client.events.EventProcessingPolicy) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) FilterText(org.netxms.ui.eclipse.widgets.FilterText) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

EventProcessingPolicy (org.netxms.client.events.EventProcessingPolicy)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 EventProcessingPolicyRule (org.netxms.client.events.EventProcessingPolicyRule)2 RuleEditor (org.netxms.ui.eclipse.epp.widgets.RuleEditor)2 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)2 ArrayList (java.util.ArrayList)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 NXCPMessage (org.netxms.base.NXCPMessage)1 NXCSession (org.netxms.client.NXCSession)1 AccessPoint (org.netxms.client.objects.AccessPoint)1