Search in sources :

Example 11 with AbstractObject

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

the class NXCSession method getTopLevelObjects.

/**
 * Get list of top-level objects matching given class filter. Class filter
 * may be null to ignore object class.
 *
 * @param classFilter To filter the classes
 * @return List of all top matching level objects (either without parents or with
 *         inaccessible parents)
 */
public AbstractObject[] getTopLevelObjects(Set<Integer> classFilter) {
    HashSet<AbstractObject> list = new HashSet<AbstractObject>();
    synchronized (objectList) {
        for (AbstractObject object : objectList.values()) {
            if ((classFilter != null) && !classFilter.contains(object.getObjectClass()))
                continue;
            if (!object.hasParents()) {
                list.add(object);
            } else {
                boolean hasParents = false;
                Iterator<Long> it = object.getParents();
                while (it.hasNext()) {
                    Long parent = it.next();
                    if (classFilter != null) {
                        AbstractObject p = objectList.get(parent);
                        if ((p != null) && classFilter.contains(p.getObjectClass())) {
                            hasParents = true;
                            break;
                        }
                    } else {
                        if (objectList.containsKey(parent)) {
                            hasParents = true;
                            break;
                        }
                    }
                }
                if (!hasParents)
                    list.add(object);
            }
        }
    }
    return list.toArray(new AbstractObject[list.size()]);
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashSet(java.util.HashSet)

Example 12 with AbstractObject

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

the class NXCSession method removeOrphanedObjects.

/**
 * Remove orphaned objects (with last parent left)
 *
 * @param parent
 */
private void removeOrphanedObjects(AbstractObject parent) {
    Iterator<Long> it = parent.getChildren();
    while (it.hasNext()) {
        AbstractObject object = objectList.get(it.next());
        if ((object != null) && (object.getParentCount() == 1)) {
            objectList.remove(object.getObjectId());
            objectListGUID.remove(object.getGuid());
            if (object instanceof Zone)
                zoneList.remove(((Zone) object).getUIN());
            removeOrphanedObjects(object);
        }
    }
}
Also used : Zone(org.netxms.client.objects.Zone) AbstractObject(org.netxms.client.objects.AbstractObject) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 13 with AbstractObject

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

the class NXCSession method handover.

/**
 * Handover object cache to new session. After call to this method,
 * object cache of this session invalidated and should not be used.
 *
 * @param target target session object
 */
public void handover(NXCSession target) {
    target.objectList = objectList;
    target.objectListGUID = objectListGUID;
    target.zoneList = zoneList;
    for (AbstractObject o : objectList.values()) {
        o.setSession(target);
    }
    objectList = null;
    objectListGUID = null;
    zoneList = null;
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject)

Example 14 with AbstractObject

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

the class ObjectTest method testObjectIsParent.

public void testObjectIsParent() throws Exception {
    final NXCSession session = connect();
    session.syncObjects();
    AbstractObject object = session.findObjectById(2);
    assertFalse(object.isChildOf(1));
    object = session.findObjectById(TestConstants.NODE_ID);
    assertTrue(object.isChildOf(1));
    session.disconnect();
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject)

Example 15 with AbstractObject

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

the class ObjectTest method testObjectTree.

public void testObjectTree() throws Exception {
    final NXCSession session = connect();
    session.syncObjects();
    AbstractObject object = session.findObjectById(1, EntireNetwork.class);
    assertNotNull(object);
    assertEquals(1, object.getObjectId());
    printObject(object, 0);
    session.disconnect();
}
Also used : AbstractObject(org.netxms.client.objects.AbstractObject)

Aggregations

AbstractObject (org.netxms.client.objects.AbstractObject)216 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)55 NXCSession (org.netxms.client.NXCSession)51 AbstractNode (org.netxms.client.objects.AbstractNode)31 PartInitException (org.eclipse.ui.PartInitException)27 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)26 ConsoleJob (org.netxms.ui.eclipse.jobs.ConsoleJob)25 Cluster (org.netxms.client.objects.Cluster)22 ObjectSelectionDialog (org.netxms.ui.eclipse.objectbrowser.dialogs.ObjectSelectionDialog)22 ArrayList (java.util.ArrayList)20 Node (org.netxms.client.objects.Node)20 GridData (org.eclipse.swt.layout.GridData)18 Composite (org.eclipse.swt.widgets.Composite)18 NetworkMapObject (org.netxms.client.maps.elements.NetworkMapObject)18 GridLayout (org.eclipse.swt.layout.GridLayout)15 Container (org.netxms.client.objects.Container)15 Interface (org.netxms.client.objects.Interface)12 Template (org.netxms.client.objects.Template)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Point (org.eclipse.swt.graphics.Point)11