Search in sources :

Example 1 with EventObject

use of org.netxms.client.events.EventObject 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 2 with EventObject

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

the class EventSelector method selectionButtonHandler.

/* (non-Javadoc)
	 * @see org.netxms.ui.eclipse.widgets.AbstractSelector#selectionButtonHandler()
	 */
@Override
protected void selectionButtonHandler() {
    EventSelectionDialog dlg = new EventSelectionDialog(getShell(), false);
    dlg.enableMultiSelection(false);
    if (dlg.open() == Window.OK) {
        long prevEventCode = eventCode;
        EventObject[] events = dlg.getSelectedEvents();
        if (events.length > 0) {
            eventCode = events[0].getCode();
            setText(events[0].getName());
            if (events[0] instanceof EventTemplate)
                setImage(StatusDisplayInfo.getStatusImage(((EventTemplate) events[0]).getSeverity()));
            else
                setImage(SharedIcons.IMG_CONTAINER);
            getTextControl().setToolTipText(generateToolTipText(events[0]));
        } else {
            eventCode = 0;
            setText(Messages.get().EventSelector_None);
            setImage(null);
            getTextControl().setToolTipText(null);
        }
        if (prevEventCode != eventCode)
            fireModifyListeners();
    }
}
Also used : EventTemplate(org.netxms.client.events.EventTemplate) EventObject(org.netxms.client.events.EventObject) EventSelectionDialog(org.netxms.ui.eclipse.eventmanager.dialogs.EventSelectionDialog)

Example 3 with EventObject

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

the class EventConditionEditor method selectEvent.

/**
 * Select event
 */
private void selectEvent() {
    EventSelectionDialog dlg = new EventSelectionDialog(getShell(), false);
    dlg.enableMultiSelection(false);
    if (dlg.open() == Window.OK) {
        EventObject[] events = dlg.getSelectedEvents();
        if (events.length > 0) {
            eventCode = events[0].getCode();
            objectName.setText(events[0].getName());
            objectName.setImage(labelProvider.getImage(events[0]));
        } else {
            eventCode = 0;
            objectName.setText(EMPTY_SELECTION_TEXT);
            objectName.setImage(null);
        }
    }
}
Also used : EventObject(org.netxms.client.events.EventObject) EventSelectionDialog(org.netxms.ui.eclipse.eventmanager.dialogs.EventSelectionDialog)

Example 4 with EventObject

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

the class EventObjectList method refreshView.

/**
 * Refresh view
 */
private void refreshView() {
    new ConsoleJob(Messages.get().EventConfigurator_OpenJob_Title, null, Activator.PLUGIN_ID, JOB_FAMILY) {

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#getErrorMessage()
          */
        @Override
        protected String getErrorMessage() {
            return Messages.get().EventConfigurator_OpenJob_Error;
        }

        /* (non-Javadoc)
          * @see org.netxms.ui.eclipse.jobs.ConsoleJob#runInternal(org.eclipse.core.runtime.IProgressMonitor)
          */
        @Override
        protected void runInternal(IProgressMonitor monitor) throws Exception {
            final List<EventObject> list = session.getEventObjects();
            runInUIThread(new Runnable() {

                /* (non-Javadoc)
                * @see java.lang.Runnable#run()
                */
                @Override
                public void run() {
                    eventObjects = new HashMap<Long, EventObject>(list.size());
                    for (final EventObject o : list) {
                        if ((o instanceof EventGroup) && !showGroups)
                            continue;
                        eventObjects.put(o.getCode(), o);
                    }
                    viewer.setInput(eventObjects.values().toArray());
                }
            });
        }
    }.start();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) EventObject(org.netxms.client.events.EventObject) EventGroup(org.netxms.client.events.EventGroup)

Example 5 with EventObject

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

the class RuleEvents method addEvent.

/**
 * Add new event
 */
private void addEvent() {
    EventSelectionDialog dlg = new EventSelectionDialog(getShell(), true);
    dlg.enableMultiSelection(true);
    if (dlg.open() == Window.OK) {
        for (EventObject e : dlg.getSelectedEvents()) events.put(e.getCode(), e);
    }
    viewer.setInput(events.values().toArray());
}
Also used : EventObject(org.netxms.client.events.EventObject) EventSelectionDialog(org.netxms.ui.eclipse.eventmanager.dialogs.EventSelectionDialog)

Aggregations

EventObject (org.netxms.client.events.EventObject)24 EventTemplate (org.netxms.client.events.EventTemplate)6 EventSelectionDialog (org.netxms.ui.eclipse.eventmanager.dialogs.EventSelectionDialog)5 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 EventGroup (org.netxms.client.events.EventGroup)4 SnmpTrap (org.netxms.client.snmp.SnmpTrap)4 HashSet (java.util.HashSet)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 AbstractObject (org.netxms.client.objects.AbstractObject)3 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)2 CLabel (org.eclipse.swt.custom.CLabel)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2