use of org.netxms.client.objects.ZoneMember in project netxms by netxms.
the class AlarmComparator method compare.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
TableColumn sortColumn = ((TableViewer) viewer).getTable().getSortColumn();
if (sortColumn == null)
return 0;
int rc;
switch(// $NON-NLS-1$
(Integer) sortColumn.getData("ID")) {
case AlarmList.COLUMN_SEVERITY:
rc = ((Alarm) e1).getCurrentSeverity().compareTo(((Alarm) e2).getCurrentSeverity());
break;
case AlarmList.COLUMN_STATE:
rc = Integer.signum(((Alarm) e1).getState() - ((Alarm) e2).getState());
break;
case AlarmList.COLUMN_SOURCE:
AbstractObject obj1 = ConsoleSharedData.getSession().findObjectById(((Alarm) e1).getSourceObjectId());
AbstractObject obj2 = ConsoleSharedData.getSession().findObjectById(((Alarm) e2).getSourceObjectId());
String name1 = (obj1 != null) ? obj1.getObjectName() : Messages.get().AlarmComparator_Unknown;
String name2 = (obj2 != null) ? obj2.getObjectName() : Messages.get().AlarmComparator_Unknown;
rc = name1.compareToIgnoreCase(name2);
break;
case AlarmList.COLUMN_MESSAGE:
rc = ((Alarm) e1).getMessage().compareToIgnoreCase(((Alarm) e2).getMessage());
break;
case AlarmList.COLUMN_COUNT:
rc = Integer.signum(((Alarm) e1).getRepeatCount() - ((Alarm) e2).getRepeatCount());
break;
case AlarmList.COLUMN_CREATED:
rc = ((Alarm) e1).getCreationTime().compareTo(((Alarm) e2).getCreationTime());
break;
case AlarmList.COLUMN_LASTCHANGE:
rc = ((Alarm) e1).getLastChangeTime().compareTo(((Alarm) e2).getLastChangeTime());
break;
case AlarmList.COLUMN_ZONE:
NXCSession session = ConsoleSharedData.getSession();
if (session.isZoningEnabled()) {
ZoneMember o1 = session.findObjectById(((Alarm) e1).getSourceObjectId(), ZoneMember.class);
ZoneMember o2 = session.findObjectById(((Alarm) e2).getSourceObjectId(), ZoneMember.class);
String n1 = (o1 != null) ? o1.getZoneName() : "";
String n2 = (o2 != null) ? o2.getZoneName() : "";
rc = n1.compareToIgnoreCase(n2);
} else {
rc = 0;
}
break;
default:
rc = 0;
break;
}
int dir = ((TableViewer) viewer).getTable().getSortDirection();
return (dir == SWT.UP) ? rc : -rc;
}
use of org.netxms.client.objects.ZoneMember in project netxms by netxms.
the class AlarmListLabelProvider method getColumnText.
/* (non-Javadoc)
* @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
*/
@Override
public String getColumnText(Object element, int columnIndex) {
switch((Integer) viewer.getTable().getColumn(columnIndex).getData("ID")) {
case AlarmList.COLUMN_SEVERITY:
return StatusDisplayInfo.getStatusText(((Alarm) element).getCurrentSeverity());
case AlarmList.COLUMN_STATE:
int time = ((Alarm) element).getAckTime();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String timeString = time > 0 ? " (" + RegionalSettings.getDateTimeFormat().format(System.currentTimeMillis() + (time * 1000)) + ")" : "";
return stateText[((Alarm) element).getState()] + timeString;
case AlarmList.COLUMN_SOURCE:
AbstractObject object = session.findObjectById(((Alarm) element).getSourceObjectId());
// $NON-NLS-1$ //$NON-NLS-2$
return (object != null) ? object.getObjectName() : ("[" + Long.toString(((Alarm) element).getSourceObjectId()) + "]");
case AlarmList.COLUMN_ZONE:
if (session.isZoningEnabled()) {
ZoneMember zm = session.findObjectById(((Alarm) element).getSourceObjectId(), ZoneMember.class);
return (zm != null) ? zm.getZoneName() : "";
}
return "";
case AlarmList.COLUMN_MESSAGE:
return ((Alarm) element).getMessage();
case AlarmList.COLUMN_COUNT:
return Integer.toString(((Alarm) element).getRepeatCount());
case AlarmList.COLUMN_COMMENTS:
return (((Alarm) element).getCommentsCount() > 0) ? Integer.toString(((Alarm) element).getCommentsCount()) : null;
case AlarmList.COLUMN_ACK_BY:
if (((Alarm) element).getState() == Alarm.STATE_OUTSTANDING)
return null;
long userId = (((Alarm) element).getState() == Alarm.STATE_ACKNOWLEDGED) ? ((Alarm) element).getAckByUser() : ((Alarm) element).getResolvedByUser();
AbstractUserObject user = session.findUserDBObjectById(userId);
// $NON-NLS-1$ //$NON-NLS-2$
return (user != null) ? user.getName() : ("[" + Long.toString(((Alarm) element).getAckByUser()) + "]");
case AlarmList.COLUMN_CREATED:
return RegionalSettings.getDateTimeFormat().format(((Alarm) element).getCreationTime());
case AlarmList.COLUMN_LASTCHANGE:
return RegionalSettings.getDateTimeFormat().format(((Alarm) element).getLastChangeTime());
case AlarmList.COLUMN_HELPDESK_REF:
switch(((Alarm) element).getHelpdeskState()) {
case Alarm.HELPDESK_STATE_OPEN:
return ((Alarm) element).getHelpdeskReference();
case Alarm.HELPDESK_STATE_CLOSED:
return ((Alarm) element).getHelpdeskReference() + Messages.get().AlarmListLabelProvider_Closed;
}
return null;
}
return null;
}
use of org.netxms.client.objects.ZoneMember in project netxms by netxms.
the class ObjectFinder method doSearch.
/**
* Do object search
*
* @param searchString search string
* @param classFilter
* @param zoneFilter
* @param addrEnd
* @param addrStart
*/
private void doSearch(final String searchString, final int mode, final List<Integer> classFilter, final List<Long> zoneFilter, final InetAddress addrStart, final InetAddress addrEnd) {
final NXCSession session = ConsoleSharedData.getSession();
new ConsoleJob("Find objects", this, Activator.PLUGIN_ID, null) {
@Override
protected void runInternal(IProgressMonitor monitor) throws Exception {
final Pattern regexp = (mode == SEARCH_MODE_REGEXP) ? Pattern.compile(searchString, Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.UNICODE_CASE) : null;
final List<AbstractObject> objects = session.filterObjects(new ObjectFilter() {
@Override
public boolean filter(AbstractObject object) {
if (session.isZoningEnabled() && session.getAllZones().size() != zoneFilter.size()) {
if (object instanceof ZoneMember) {
ZoneMember node = (ZoneMember) object;
if (!zoneFilter.contains(node.getZoneId()))
return false;
}
if (object instanceof Sensor) {
AbstractNode proxy = session.findObjectById(((Sensor) object).getProxyId(), AbstractNode.class);
if (proxy != null && zoneFilter.contains(proxy.getZoneId()))
return false;
} else if (object instanceof Interface) {
AbstractNode parent = ((Interface) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof NetworkService) {
AbstractNode parent = ((NetworkService) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof VPNConnector) {
AbstractNode parent = ((VPNConnector) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof AccessPoint) {
AbstractNode parent = ((AccessPoint) object).getParentNode();
if (parent != null && !zoneFilter.contains(parent.getZoneId()))
return false;
} else if (object instanceof GenericObject && !zoneFilter.isEmpty()) {
AbstractObject[] children = ((GenericObject) object).getChildsAsArray();
boolean match = false;
for (AbstractObject o : children) {
if (o instanceof ZoneMember && zoneFilter.contains(((ZoneMember) o).getZoneId()))
match = true;
}
if (!match)
return false;
}
}
if (!classFilter.contains(object.getObjectClass()))
return false;
if ((addrStart != null) && (addrEnd != null)) {
if (!checkAddrRange(addrStart, addrEnd, object))
return false;
}
if (searchString.isEmpty())
return true;
for (String s : object.getStrings()) {
switch(mode) {
case SEARCH_MODE_NORMAL:
if (s.toLowerCase().contains(searchString))
return true;
break;
case SEARCH_MODE_PATTERN:
if (Glob.match(searchString, s.toLowerCase()))
return true;
break;
case SEARCH_MODE_REGEXP:
if (regexp.matcher(s).find())
return true;
break;
}
}
return false;
}
});
runInUIThread(new Runnable() {
@Override
public void run() {
results.setInput(objects);
}
});
}
@Override
protected String getErrorMessage() {
return "Object search failure";
}
}.start();
}
Aggregations