Search in sources :

Example 1 with ZoneMember

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;
}
Also used : NXCSession(org.netxms.client.NXCSession) Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) ZoneMember(org.netxms.client.objects.ZoneMember) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 2 with ZoneMember

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;
}
Also used : Alarm(org.netxms.client.events.Alarm) AbstractObject(org.netxms.client.objects.AbstractObject) AbstractUserObject(org.netxms.client.users.AbstractUserObject) ZoneMember(org.netxms.client.objects.ZoneMember)

Example 3 with ZoneMember

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();
}
Also used : Pattern(java.util.regex.Pattern) NXCSession(org.netxms.client.NXCSession) AbstractNode(org.netxms.client.objects.AbstractNode) AccessPoint(org.netxms.client.objects.AccessPoint) VPNConnector(org.netxms.client.objects.VPNConnector) ObjectFilter(org.netxms.client.ObjectFilter) PartInitException(org.eclipse.ui.PartInitException) UnknownHostException(java.net.UnknownHostException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractObject(org.netxms.client.objects.AbstractObject) GenericObject(org.netxms.client.objects.GenericObject) NetworkService(org.netxms.client.objects.NetworkService) List(java.util.List) ArrayList(java.util.ArrayList) ZoneMember(org.netxms.client.objects.ZoneMember) ConsoleJob(org.netxms.ui.eclipse.jobs.ConsoleJob) Interface(org.netxms.client.objects.Interface) Sensor(org.netxms.client.objects.Sensor)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)3 ZoneMember (org.netxms.client.objects.ZoneMember)3 NXCSession (org.netxms.client.NXCSession)2 Alarm (org.netxms.client.events.Alarm)2 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 PartInitException (org.eclipse.ui.PartInitException)1 ObjectFilter (org.netxms.client.ObjectFilter)1 AbstractNode (org.netxms.client.objects.AbstractNode)1 AccessPoint (org.netxms.client.objects.AccessPoint)1 GenericObject (org.netxms.client.objects.GenericObject)1 Interface (org.netxms.client.objects.Interface)1 NetworkService (org.netxms.client.objects.NetworkService)1 Sensor (org.netxms.client.objects.Sensor)1 VPNConnector (org.netxms.client.objects.VPNConnector)1 AbstractUserObject (org.netxms.client.users.AbstractUserObject)1