Search in sources :

Example 31 with AbstractNode

use of org.netxms.client.objects.AbstractNode 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)

Example 32 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class MapContentProvider method inputChanged.

/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    synchronized (cachedDciValues) {
        cachedDciValues.clear();
    }
    if (newInput instanceof NetworkMapPage) {
        page = (NetworkMapPage) newInput;
        synchronized (cachedDciValues) {
            for (NetworkMapElement e : page.getElements()) {
                if (e instanceof NetworkMapObject) {
                    long id = ((NetworkMapObject) e).getObjectId();
                    AbstractObject object = session.findObjectById(id);
                    if ((object != null) && (object instanceof AbstractNode)) {
                        cachedDciValues.put(id, null);
                    }
                }
            }
        }
    } else {
        page = null;
    }
}
Also used : NetworkMapPage(org.netxms.client.maps.NetworkMapPage) AbstractNode(org.netxms.client.objects.AbstractNode) NetworkMapElement(org.netxms.client.maps.elements.NetworkMapElement) AbstractObject(org.netxms.client.objects.AbstractObject) NetworkMapObject(org.netxms.client.maps.elements.NetworkMapObject)

Example 33 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class ShowSwitchForwardingDatabase method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if (obj instanceof AbstractNode) {
            action.setEnabled(true);
            objectId = ((AbstractObject) obj).getObjectId();
        } else {
            action.setEnabled(false);
            objectId = 0;
        }
    } else {
        action.setEnabled(false);
        objectId = 0;
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 34 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class ShowWirelessStations method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if ((obj instanceof AbstractNode) && ((AbstractNode) obj).isWirelessController()) {
            action.setEnabled(true);
            objectId = ((AbstractObject) obj).getObjectId();
        } else {
            action.setEnabled(false);
            objectId = 0;
        }
    } else {
        action.setEnabled(false);
        objectId = 0;
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 35 with AbstractNode

use of org.netxms.client.objects.AbstractNode in project netxms by netxms.

the class ShowRoutingTable method selectionChanged.

/* (non-Javadoc)
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
	 */
@Override
public void selectionChanged(IAction action, ISelection selection) {
    if ((selection instanceof IStructuredSelection) && (((IStructuredSelection) selection).size() == 1)) {
        Object obj = ((IStructuredSelection) selection).getFirstElement();
        if (obj instanceof AbstractNode) {
            action.setEnabled(true);
            objectId = ((AbstractObject) obj).getObjectId();
        } else {
            action.setEnabled(false);
            objectId = 0;
        }
    } else {
        action.setEnabled(false);
        objectId = 0;
    }
}
Also used : AbstractNode(org.netxms.client.objects.AbstractNode) AbstractObject(org.netxms.client.objects.AbstractObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

AbstractNode (org.netxms.client.objects.AbstractNode)47 AbstractObject (org.netxms.client.objects.AbstractObject)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)14 NXCSession (org.netxms.client.NXCSession)13 ArrayList (java.util.ArrayList)12 Cluster (org.netxms.client.objects.Cluster)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Composite (org.eclipse.swt.widgets.Composite)6 PartInitException (org.eclipse.ui.PartInitException)6 MobileDevice (org.netxms.client.objects.MobileDevice)6 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)6 NXCException (org.netxms.client.NXCException)5 Interface (org.netxms.client.objects.Interface)5 Sensor (org.netxms.client.objects.Sensor)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 DataCollectionItem (org.netxms.client.datacollection.DataCollectionItem)4 Subnet (org.netxms.client.objects.Subnet)4 ISelection (org.eclipse.jface.viewers.ISelection)3