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;
}
});
}
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();
}
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;
}
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());
}
}
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;
}
}
Aggregations