Search in sources :

Example 16 with EventObject

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

the class EventObjectList method enableDropSupport.

/**
 * Enable drop support
 */
public void enableDropSupport() {
    final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(viewer) {

        @Override
        public boolean performDrop(Object data) {
            TreeSelection selection = (TreeSelection) data;
            List<?> movableSelection = selection.toList();
            for (int i = 0; i < movableSelection.size(); i++) {
                if (((EventObject) movableSelection.get(i)).getCode() != ((EventGroup) getCurrentTarget()).getCode())
                    ((EventGroup) getCurrentTarget()).addChild(((EventObject) movableSelection.get(i)).getCode());
            }
            modifyEventObject((EventGroup) getCurrentTarget(), false);
            return true;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
                return false;
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty())
                return false;
            if (!(target instanceof EventGroup))
                return false;
            return true;
        }
    });
}
Also used : TransferData(org.eclipse.swt.dnd.TransferData) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) TreeSelection(org.eclipse.jface.viewers.TreeSelection) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) EventObject(org.netxms.client.events.EventObject) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EventObject(org.netxms.client.events.EventObject) EventGroup(org.netxms.client.events.EventGroup)

Example 17 with EventObject

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

the class EventSelector method setEventCode.

/**
 * Set event code
 * @param eventCode
 */
public void setEventCode(long eventCode) {
    if (this.eventCode == eventCode)
        // nothing to change
        return;
    this.eventCode = eventCode;
    if (eventCode != 0) {
        EventObject object = ((NXCSession) ConsoleSharedData.getSession()).findEventObjectByCode(eventCode);
        if (object != null) {
            setText(object.getName());
            if (object instanceof EventTemplate)
                setImage(StatusDisplayInfo.getStatusImage(((EventTemplate) object).getSeverity()));
            else
                setImage(SharedIcons.IMG_CONTAINER);
            getTextControl().setToolTipText(generateToolTipText(object));
        } else {
            setText(Messages.get().EventSelector_Unknown);
            setImage(null);
            getTextControl().setToolTipText(null);
        }
    } else {
        setText(Messages.get().EventSelector_None);
        setImage(null);
        getTextControl().setToolTipText(null);
    }
    fireModifyListeners();
}
Also used : NXCSession(org.netxms.client.NXCSession) EventTemplate(org.netxms.client.events.EventTemplate) EventObject(org.netxms.client.events.EventObject)

Example 18 with EventObject

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

the class RuleEvents method createContents.

/* (non-Javadoc)
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
@Override
protected Control createContents(Composite parent) {
    session = (NXCSession) ConsoleSharedData.getSession();
    editor = (RuleEditor) getElement().getAdapter(RuleEditor.class);
    rule = editor.getRule();
    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);
    checkInverted = new Button(dialogArea, SWT.CHECK);
    checkInverted.setText(Messages.get().RuleEvents_InvertedRule);
    checkInverted.setSelection(rule.isEventsInverted());
    final String[] columnNames = { Messages.get().RuleEvents_Event };
    final int[] columnWidths = { 300 };
    viewer = new SortableTableViewer(dialogArea, columnNames, columnWidths, 0, SWT.UP, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    viewer.setContentProvider(new ArrayContentProvider());
    viewer.setLabelProvider(new EventObjectLabelProvider());
    viewer.setComparator(new ObjectLabelComparator((ILabelProvider) viewer.getLabelProvider()));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            int size = ((IStructuredSelection) viewer.getSelection()).size();
            deleteButton.setEnabled(size > 0);
        }
    });
    for (EventObject o : session.findMultipleEventObjects(rule.getEvents().toArray(new Long[0]))) events.put(o.getCode(), o);
    viewer.setInput(events.values().toArray());
    GridData gridData = new GridData();
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.heightHint = 0;
    viewer.getControl().setLayoutData(gridData);
    Composite buttons = new Composite(dialogArea, SWT.NONE);
    RowLayout buttonLayout = new RowLayout();
    buttonLayout.type = SWT.HORIZONTAL;
    buttonLayout.pack = false;
    buttonLayout.marginLeft = 0;
    buttonLayout.marginRight = 0;
    buttons.setLayout(buttonLayout);
    gridData = new GridData();
    gridData.horizontalAlignment = SWT.RIGHT;
    buttons.setLayoutData(gridData);
    addButton = new Button(buttons, SWT.PUSH);
    addButton.setText(Messages.get().RuleEvents_Add);
    addButton.addSelectionListener(new SelectionListener() {

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

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

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            deleteEvent();
        }
    });
    rd = new RowData();
    rd.width = WidgetHelper.BUTTON_WIDTH_HINT;
    deleteButton.setLayoutData(rd);
    deleteButton.setEnabled(false);
    return dialogArea;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ObjectLabelComparator(org.netxms.ui.eclipse.tools.ObjectLabelComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SortableTableViewer(org.netxms.ui.eclipse.widgets.SortableTableViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) EventObject(org.netxms.client.events.EventObject) GridLayout(org.eclipse.swt.layout.GridLayout) RowData(org.eclipse.swt.layout.RowData) Button(org.eclipse.swt.widgets.Button) EventObjectLabelProvider(org.netxms.ui.eclipse.epp.propertypages.helpers.EventObjectLabelProvider) RowLayout(org.eclipse.swt.layout.RowLayout) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 19 with EventObject

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

the class RuleEvents method deleteEvent.

/**
 * Delete event from list
 */
private void deleteEvent() {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    Iterator<?> it = selection.iterator();
    if (it.hasNext()) {
        while (it.hasNext()) {
            EventObject e = (EventObject) it.next();
            events.remove(e.getCode());
        }
        viewer.setInput(events.values().toArray());
    }
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) EventObject(org.netxms.client.events.EventObject)

Example 20 with EventObject

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

the class LogLabelProvider method getColumnText.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
	 */
@Override
public String getColumnText(Object element, int columnIndex) {
    final String value = ((TableRow) element).get(columnIndex).getValue();
    switch(columns[columnIndex].getType()) {
        case LogColumn.LC_TIMESTAMP:
            try {
                long timestamp = Long.parseLong(value);
                Date date = new Date(timestamp * 1000);
                return RegionalSettings.getDateTimeFormat().format(date);
            } catch (NumberFormatException e) {
                return Messages.get().LogLabelProvider_Error;
            }
        case LogColumn.LC_OBJECT_ID:
            try {
                long id = Long.parseLong(value);
                if (id == 0)
                    // $NON-NLS-1$
                    return "";
                AbstractObject object = session.findObjectById(id);
                // $NON-NLS-1$ //$NON-NLS-2$
                return (object != null) ? object.getObjectName() : ("[" + id + "]");
            } catch (NumberFormatException e) {
                return Messages.get().LogLabelProvider_Error;
            }
        case LogColumn.LC_SEVERITY:
            try {
                int severity = Integer.parseInt(value);
                return StatusDisplayInfo.getStatusText(severity);
            } catch (NumberFormatException e) {
                return Messages.get().LogLabelProvider_Error;
            }
        case LogColumn.LC_USER_ID:
            try {
                long id = Long.parseLong(value);
                AbstractUserObject user = session.findUserDBObjectById(id);
                return (user != null) ? wbLabelProvider.getText(user) : null;
            } catch (NumberFormatException e) {
                return null;
            }
        case LogColumn.LC_EVENT_CODE:
            try {
                long code = Long.parseLong(value);
                EventObject evo = session.findEventObjectByCode(code);
                // $NON-NLS-1$ //$NON-NLS-2$
                return (evo != null) ? evo.getName() : ("[" + code + "]");
            } catch (NumberFormatException e) {
                return null;
            }
        case LogColumn.LC_ALARM_STATE:
            try {
                int state = Integer.parseInt(value);
                return ALARM_STATE_TEXTS[state & Alarm.STATE_MASK];
            } catch (Exception e) {
                return Messages.get().LogLabelProvider_Error;
            }
        case LogColumn.LC_ALARM_HD_STATE:
            try {
                int state = Integer.parseInt(value);
                return ALARM_HD_STATE_TEXTS[state];
            } catch (Exception e) {
                return Messages.get().LogLabelProvider_Error;
            }
        case LogColumn.LC_ZONE_UIN:
            try {
                long uin = Long.parseLong(value);
                Zone zone = session.findZone(uin);
                return (zone != null) ? zone.getObjectName() : "[" + uin + "]";
            } catch (NumberFormatException e) {
                return null;
            }
        default:
            return value;
    }
}
Also used : Zone(org.netxms.client.objects.Zone) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractUserObject(org.netxms.client.users.AbstractUserObject) Date(java.util.Date) EventObject(org.netxms.client.events.EventObject)

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