/**
  * Finds the node hosting the selected <code>DataObject</code>.
  *
  * @param node The node to check.
  */
 private void findNode(TreeImageDisplay node) {
   if (node == null) return;
   if (parent == null) {
     Object uo = node.getUserObject();
     if (selected.getClass().equals(uo.getClass()) && selected.getId() == node.getUserObjectId()) {
       selectedNode = node;
     }
   } else {
     Object uo = node.getUserObject();
     TreeImageDisplay pN;
     if (parent instanceof String) {
       String key = parent.toString();
       if (uo instanceof DataObject) {
         pN = node.getParentDisplay();
         String n = pN.toString();
         if (key.equals(n) && selected.getId() == ((DataObject) uo).getId()) {
           selectedNode = node;
         }
       }
     } else {
       if (selected.getClass().equals(uo.getClass())
           && selected.getId() == node.getUserObjectId()) {
         pN = node.getParentDisplay();
         Object po = pN.getUserObject();
         if (po.getClass().equals(parent.getClass()))
           if (po instanceof DataObject && parent instanceof DataObject) {
             if (((DataObject) po).getId() == ((DataObject) parent).getId()) selectedNode = node;
           }
       }
     }
   }
 }
示例#2
0
 /**
  * Creates a new instance.
  *
  * @param refObject The collection of objects to find.
  */
 public NodesFinder(DataObject refObject) {
   type = null;
   if (refObject == null) throw new IllegalArgumentException("No object to find.");
   byName = refObject.getId() <= 0;
   refObjects = new ArrayList<DataObject>();
   refObjects.add(refObject);
   nodes = new HashSet<TreeImageDisplay>();
 }
  /**
   * Returns <code>true</code> if the passed object is the reference object, <code>false</code>
   * otherwise.
   *
   * @param uo The object to compare.
   * @param ref The object of reference.
   * @return See above.
   */
  boolean isSameObject(DataObject uo, Object ref) {
    if (uo == null || !(ref instanceof DataObject)) return false;
    Class<?> klass = ref.getClass();
    DataObject object;
    if (ref instanceof WellSampleData) {
      klass = ((WellSampleData) ref).getImage().getClass();
      object = ((WellSampleData) ref).getImage();
    } else object = (DataObject) ref;

    Class<?> hoKlass = uo.getClass();
    if (uo instanceof WellSampleData) {
      hoKlass = ((WellSampleData) uo).getImage().getClass();
      uo = ((WellSampleData) uo).getImage();
    }
    if (!hoKlass.equals(klass)) return false;
    return uo.getId() == object.getId();
  }
 /**
  * Finds the node hosting the selected <code>DataObject</code>.
  *
  * @param node The node to check.
  */
 private void findNodeFromSelection(TreeImageDisplay node) {
   if (node == null) return;
   Iterator<DataObject> i = selection.iterator();
   DataObject object;
   if (parent == null) {
     Object uo = node.getUserObject();
     while (i.hasNext()) {
       object = i.next();
       if (object.getClass().equals(uo.getClass()) && object.getId() == node.getUserObjectId()) {
         selectedNodes.add(node);
       }
     }
   } else {
     Object uo = node.getUserObject();
     TreeImageDisplay pN;
     if (parent instanceof String) {
       String key = parent.toString();
       if (uo instanceof DataObject) {
         pN = node.getParentDisplay();
         String n = pN.toString();
         while (i.hasNext()) {
           object = i.next();
           if (key.equals(n) && object.getId() == ((DataObject) uo).getId()) {
             selectedNodes.add(node);
           }
         }
       }
     } else {
       while (i.hasNext()) {
         object = i.next();
         if (object.getClass().equals(uo.getClass()) && object.getId() == node.getUserObjectId()) {
           pN = node.getParentDisplay();
           Object po = pN.getUserObject();
           if (po.getClass().equals(parent.getClass()))
             if (po instanceof DataObject && parent instanceof DataObject) {
               if (((DataObject) po).getId() == ((DataObject) parent).getId())
                 selectedNodes.add(node);
             }
         }
       }
     }
   }
 }
示例#5
0
 /**
  * Checks if the node is of the desired type.
  *
  * @param node The node to handle.
  */
 private void findNode(TreeImageDisplay node) {
   Object userObject = node.getUserObject();
   if (refObjects != null && refObjects.size() > 0) {
     if (userObject != null) {
       Iterator<DataObject> i = refObjects.iterator();
       DataObject object;
       Class<?> k = userObject.getClass();
       DataObject uo;
       String n = getNodeName(userObject);
       while (i.hasNext()) {
         object = i.next();
         if (object.getClass().equals(k)) {
           uo = (DataObject) userObject;
           if (byName) {
             if (n.equals(getNodeName(object))) {
               nodes.add(node);
               break;
             }
           } else {
             if (uo.getId() == object.getId()) {
               nodes.add(node);
               break;
             }
           }
         }
       }
     }
   } else {
     if (userObject != null && userObject.getClass().equals(type)) {
       if (userObject instanceof DataObject) {
         DataObject data = (DataObject) userObject;
         if (ids == null) {
           nodes.add(node);
         } else {
           if (ids.contains(data.getId())) nodes.add(node);
         }
       }
     }
   }
 }
 /**
  * Sets the object of reference.
  *
  * @param refObject The value to set.
  * @param ctx The security context.
  */
 void setRootObject(Object refObject, SecurityContext ctx) {
   this.refObject = refObject;
   this.ctx = ctx;
   if (ctx == null && refObject instanceof DataObject) {
     DataObject data = (DataObject) refObject;
     if (data.getId() >= 0) this.ctx = new SecurityContext(data.getGroupId());
   }
   browser.setRootObject(refObject);
   editor.setRootObject(refObject);
   data = null;
   if (!(refObject instanceof WellSampleData) && parentData != null) {
     parentData = null;
   }
   parentRefObject = null;
   viewedBy = null;
 }
 /**
  * Returns the identifier of the data object.
  *
  * @return See above.
  */
 public long getObjectId() {
   return relatedObject.getId();
 }