Search in sources :

Example 1 with EventTemplate

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

the class EventProcessingPolicyEditor method createPartControl.

/*
    * (non-Javadoc)
    * 
    * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
    */
@Override
public void createPartControl(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    IDialogSettings settings = Activator.getDefault().getDialogSettings();
    // $NON-NLS-1$
    filterEnabled = settings.getBoolean("EventProcessingPolicyEditor.filterEnabled");
    // Initiate loading of required plugins if they was not loaded yet
    try {
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(new ServerAction(0), "org.eclipse.ui.model.IWorkbenchAdapter");
        // $NON-NLS-1$
        Platform.getAdapterManager().loadAdapter(session.getTopLevelObjects()[0], "org.eclipse.ui.model.IWorkbenchAdapter");
    } catch (Exception e) {
    }
    // $NON-NLS-1$
    imageStop = Activator.getImageDescriptor("icons/stop.png").createImage();
    // $NON-NLS-1$
    imageAlarm = Activator.getImageDescriptor("icons/alarm.png").createImage();
    // $NON-NLS-1$
    imageSituation = Activator.getImageDescriptor("icons/situation.gif").createImage();
    // $NON-NLS-1$
    imageExecute = Activator.getImageDescriptor("icons/execute.png").createImage();
    // $NON-NLS-1$
    imageTerminate = Activator.getImageDescriptor("icons/terminate.png").createImage();
    imageCollapse = SharedIcons.COLLAPSE.createImage();
    imageExpand = SharedIcons.EXPAND.createImage();
    imageEdit = SharedIcons.EDIT.createImage();
    parent.setLayout(new FormLayout());
    // Create filter area
    filterControl = new FilterText(parent, SWT.NONE);
    filterControl.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            onFilterModify();
        }
    });
    filterControl.setCloseAction(new Action() {

        @Override
        public void run() {
            enableFilter(false);
        }
    });
    scroller = new ScrolledComposite(parent, SWT.V_SCROLL);
    dataArea = new Composite(scroller, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    dataArea.setLayout(layout);
    dataArea.setBackground(BACKGROUND_COLOR);
    scroller.setContent(dataArea);
    scroller.setExpandVertical(true);
    scroller.setExpandHorizontal(true);
    scroller.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            Rectangle r = scroller.getClientArea();
            scroller.setMinSize(dataArea.computeSize(r.width, SWT.DEFAULT));
        }
    });
    // Setup layout
    FormData fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(filterControl);
    fd.right = new FormAttachment(100, 0);
    fd.bottom = new FormAttachment(100, 0);
    scroller.setLayoutData(fd);
    fd = new FormData();
    fd.left = new FormAttachment(0, 0);
    fd.top = new FormAttachment(0, 0);
    fd.right = new FormAttachment(100, 0);
    filterControl.setLayoutData(fd);
    normalFont = JFaceResources.getDefaultFont();
    boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
    sessionListener = new SessionListener() {

        @Override
        public void notificationHandler(SessionNotification n) {
            processSessionNotification(n);
        }
    };
    session.addListener(sessionListener);
    selection = new TreeSet<RuleEditor>(new Comparator<RuleEditor>() {

        @Override
        public int compare(RuleEditor arg0, RuleEditor arg1) {
            return arg0.getRuleNumber() - arg1.getRuleNumber();
        }
    });
    createActions();
    contributeToActionBars();
    openEventProcessingPolicy();
    activateContext();
    // Set initial focus to filter input line
    if (filterEnabled)
        filterControl.setFocus();
    else
        // Will hide filter area correctly
        enableFilter(false);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) ServerAction(org.netxms.client.ServerAction) Action(org.eclipse.jface.action.Action) ModifyListener(org.eclipse.swt.events.ModifyListener) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) EventTemplate(org.netxms.client.events.EventTemplate) Rectangle(org.eclipse.swt.graphics.Rectangle) Comparator(java.util.Comparator) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FilterText(org.netxms.ui.eclipse.widgets.FilterText) SessionListener(org.netxms.client.SessionListener) RuleEditor(org.netxms.ui.eclipse.epp.widgets.RuleEditor) ControlEvent(org.eclipse.swt.events.ControlEvent) ServerAction(org.netxms.client.ServerAction) SessionNotification(org.netxms.client.SessionNotification) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 2 with EventTemplate

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

the class TableThresholds 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);
    dci = editor.getObjectAsTable();
    thresholds = new ArrayList<TableThreshold>();
    for (TableThreshold t : dci.getThresholds()) thresholds.add(new TableThreshold(t));
    // Initiate loading of event manager plugin if it was not loaded before
    // $NON-NLS-1$
    Platform.getAdapterManager().loadAdapter(new EventTemplate(0), "org.eclipse.ui.model.IWorkbenchAdapter");
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    dialogArea.setLayout(layout);
    Composite thresholdListArea = new Composite(dialogArea, SWT.NONE);
    GridData gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    thresholdListArea.setLayoutData(gd);
    layout = new GridLayout();
    layout.verticalSpacing = WidgetHelper.INNER_SPACING;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    thresholdListArea.setLayout(layout);
    new Label(thresholdListArea, SWT.NONE).setText(Messages.get().TableThresholds_Thresholds);
    thresholdList = new TableViewer(thresholdListArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    gd = new GridData();
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalSpan = 2;
    thresholdList.getControl().setLayoutData(gd);
    setupThresholdList();
    thresholdList.setInput(thresholds.toArray());
    Composite leftButtons = new Composite(thresholdListArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.LEFT;
    leftButtons.setLayoutData(gd);
    RowLayout buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    leftButtons.setLayout(buttonsLayout);
    upButton = new Button(leftButtons, SWT.PUSH);
    upButton.setText(Messages.get().TableThresholds_Up);
    RowData rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    upButton.setLayoutData(rd);
    upButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveSelectionUp();
        }
    });
    downButton = new Button(leftButtons, SWT.PUSH);
    downButton.setText(Messages.get().TableThresholds_Down);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    downButton.setLayoutData(rd);
    downButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveSelectionDown();
        }
    });
    Composite buttons = new Composite(thresholdListArea, SWT.NONE);
    gd = new GridData();
    gd.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gd);
    buttonsLayout = new RowLayout(SWT.HORIZONTAL);
    buttonsLayout.marginBottom = 0;
    buttonsLayout.marginLeft = 0;
    buttonsLayout.marginRight = 0;
    buttonsLayout.marginTop = 0;
    buttonsLayout.spacing = WidgetHelper.OUTER_SPACING;
    buttonsLayout.fill = true;
    buttonsLayout.pack = false;
    buttons.setLayout(buttonsLayout);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().TableThresholds_Add);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    addButton.setLayoutData(rd);
    addButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            addThreshold();
        }
    });
    duplicateButton = new Button(buttons, SWT.PUSH);
    duplicateButton.setText("Duplicate");
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    duplicateButton.setLayoutData(rd);
    duplicateButton.setEnabled(false);
    duplicateButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            duplicateThreshold();
        }
    });
    modifyButton = new Button(buttons, SWT.PUSH);
    modifyButton.setText(Messages.get().TableThresholds_Edit);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    modifyButton.setLayoutData(rd);
    modifyButton.setEnabled(false);
    modifyButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            editThreshold();
        }
    });
    deleteButton = new Button(buttons, SWT.PUSH);
    deleteButton.setText(Messages.get().TableThresholds_Delete);
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.setEnabled(false);
    deleteButton.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteThresholds();
        }
    });
    /**
     * Selection change listener for thresholds list **
     */
    thresholdList.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            deleteButton.setEnabled(selection.size() > 0);
            duplicateButton.setEnabled(selection.size() > 0);
            if (selection.size() == 1) {
                modifyButton.setEnabled(true);
                upButton.setEnabled(thresholds.indexOf(selection.getFirstElement()) > 0);
                downButton.setEnabled(thresholds.indexOf(selection.getFirstElement()) < thresholds.size() - 1);
            } else {
                modifyButton.setEnabled(false);
                upButton.setEnabled(false);
                downButton.setEnabled(false);
            }
        }
    });
    thresholdList.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            editThreshold();
        }
    });
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) EventTemplate(org.netxms.client.events.EventTemplate) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableThreshold(org.netxms.client.datacollection.TableThreshold) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with EventTemplate

use of org.netxms.client.events.EventTemplate 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 EventTemplate

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

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

the class EventObjectList method createNewEventTemplate.

/**
 * Create new event template
 */
protected void createNewEventTemplate() {
    final EventTemplate etmpl = new EventTemplate(0);
    EditEventTemplateDialog dlg = new EditEventTemplateDialog(getShell().getShell(), etmpl, false);
    if (dlg.open() == Window.OK)
        modifyEventObject(etmpl, true);
}
Also used : EventTemplate(org.netxms.client.events.EventTemplate) EditEventTemplateDialog(org.netxms.ui.eclipse.eventmanager.dialogs.EditEventTemplateDialog)

Aggregations

EventTemplate (org.netxms.client.events.EventTemplate)11 GridLayout (org.eclipse.swt.layout.GridLayout)4 Composite (org.eclipse.swt.widgets.Composite)4 EventObject (org.netxms.client.events.EventObject)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 GridData (org.eclipse.swt.layout.GridData)3 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 RowData (org.eclipse.swt.layout.RowData)2 RowLayout (org.eclipse.swt.layout.RowLayout)2 Button (org.eclipse.swt.widgets.Button)2 Label (org.eclipse.swt.widgets.Label)2 Threshold (org.netxms.client.datacollection.Threshold)2 EditEventTemplateDialog (org.netxms.ui.eclipse.eventmanager.dialogs.EditEventTemplateDialog)2 EventSelectionDialog (org.netxms.ui.eclipse.eventmanager.dialogs.EventSelectionDialog)2