/** * Sets the action enabled depending on the selected type. * * @see TreeViewerAction#onDisplayChange(TreeImageDisplay) */ protected void onDisplayChange(TreeImageDisplay selectedDisplay) { if (selectedDisplay == null) { setEnabled(false); return; } Browser browser = model.getSelectedBrowser(); if (browser == null) { setEnabled(false); return; } Object ho = selectedDisplay.getUserObject(); if (ho instanceof DatasetData || ho instanceof ProjectData || ho instanceof ImageData || ho instanceof ScreenData || ho instanceof PlateData) { if (model.canAnnotate(ho)) { List selected = browser.getSelectedDataObjects(); if (selected == null) setEnabled(false); else { List<Long> ids = new ArrayList<Long>(); Iterator i = selected.iterator(); DataObject data; while (i.hasNext()) { data = (DataObject) i.next(); if (!ids.contains(data.getGroupId())) ids.add(data.getGroupId()); } setEnabled(ids.size() == 1); } } else setEnabled(false); } else setEnabled(false); }
/** * 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; } } } } }
/** * 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; }
/** * 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(); }
/** * Sets the action enabled depending on the currently selected display * * @see DataBrowserAction#onDisplayChange(ImageDisplay) */ protected void onDisplayChange(ImageDisplay node) { if (node == null) { setEnabled(false); return; } Object ho = node.getHierarchyObject(); if (ho instanceof ImageData || ho instanceof DatasetData || ho instanceof ProjectData || ho instanceof ScreenData || ho instanceof PlateData) { if (model.canAnnotate(ho)) { Collection l = model.getBrowser().getSelectedDataObjects(); List<Long> ids = new ArrayList<Long>(); Iterator i = l.iterator(); DataObject data; while (i.hasNext()) { data = (DataObject) i.next(); if (!ids.contains(data.getGroupId())) ids.add(data.getGroupId()); } setEnabled(ids.size() == 1); } else setEnabled(false); } else setEnabled(false); }
/** * 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); } } } } }
/** * 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); } } } } } }
/** * Creates a new context if <code>null</code>. * * @param ho The node to handle. * @return See above. */ private SecurityContext retrieveContext(DataObject ho) { if (ctx != null) return ctx; return new SecurityContext(ho.getGroupId()); }
/** * Returns the identifier of the data object. * * @return See above. */ public long getObjectId() { return relatedObject.getId(); }