/** * Returns the collection of tags. * * @return See above. */ List<TagAnnotationData> removeTags() { List<TagAnnotationData> list = new ArrayList<TagAnnotationData>(); if (tagsDocList.size() == 0) { tagFlag = false; return list; } List<TagAnnotationData> toKeep = new ArrayList<TagAnnotationData>(); TagAnnotationData data; DocComponent doc; Object object; Iterator<DocComponent> i = tagsDocList.iterator(); while (i.hasNext()) { doc = i.next(); object = doc.getData(); if (doc.canUnlink()) { if (object instanceof TagAnnotationData) { data = (TagAnnotationData) object; if (data.getId() > 0) list.add(data); } } else { toKeep.add((TagAnnotationData) object); } } handleObjectsSelection(TagAnnotationData.class, toKeep, false); if (list.size() == 0) tagFlag = false; return list; }
/** * Handles the selection of objects via the selection wizard. * * @param type The type of objects to handle. * @param objects The objects to handle. * @param fire Pass <code>true</code> to notify, <code>false</code> otherwise. */ void handleObjectsSelection(Class type, Collection objects, boolean fire) { if (objects == null) return; if (TagAnnotationData.class.equals(type)) { layoutTags(objects); List<Long> ids = new ArrayList<Long>(); Iterator i = objects.iterator(); TagAnnotationData tag; tagFlag = false; Collection tags = model.getTags(); if (tags == null || tags.size() != objects.size()) { tagFlag = true; } else { while (i.hasNext()) { tag = (TagAnnotationData) i.next(); if (tag != null && !model.isAnnotationUsedByUser(tag)) { ids.add(tag.getId()); } } i = tags.iterator(); while (i.hasNext()) { tag = (TagAnnotationData) i.next(); if (tag != null && !ids.contains(tag.getId())) { tagFlag = true; break; } } } } else if (FileAnnotationData.class.equals(type)) { layoutAttachments(objects); List<Long> ids = new ArrayList<Long>(); Iterator i = objects.iterator(); FileAnnotationData data; docFlag = false; Collection attachments = model.getAttachments(); if (attachments == null || attachments.size() != objects.size()) { docFlag = true; } else { while (i.hasNext()) { data = (FileAnnotationData) i.next(); if (data != null) ids.add(data.getId()); } i = attachments.iterator(); while (i.hasNext()) { data = (FileAnnotationData) i.next(); if (data != null && !ids.contains(data.getId())) { docFlag = true; break; } } } } buildGUI(); if (fire) firePropertyChange( EditorControl.SAVE_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true)); }
/** * Removes a tag from the view. * * @param tag The tag to remove. */ void removeTag(TagAnnotationData tag) { if (tag == null) return; List<TagAnnotationData> tags = getCurrentTagsSelection(); Iterator<TagAnnotationData> i = tags.iterator(); TagAnnotationData data; List<TagAnnotationData> toKeep = new ArrayList<TagAnnotationData>(); while (i.hasNext()) { data = i.next(); if (data.getId() != tag.getId()) toKeep.add(data); } handleObjectsSelection(TagAnnotationData.class, toKeep, true); }
/** * Returns the tags currently selected. * * @return See above. */ List<TagAnnotationData> getCurrentTagsSelection() { List<TagAnnotationData> selection = new ArrayList<TagAnnotationData>(); if (tagsDocList.size() == 0) return selection; DocComponent doc; Object object; TagAnnotationData tag; Iterator<DocComponent> i = tagsDocList.iterator(); while (i.hasNext()) { doc = i.next(); object = doc.getData(); if (object instanceof TagAnnotationData) { tag = (TagAnnotationData) object; if (tag.getId() > 0) selection.add(tag); } } return selection; }
/** * Creates a {@link CreateCmd} command to execute the action. * * @see java.awt.event.ActionListener#actionPerformed(ActionEvent) */ public void actionPerformed(ActionEvent e) { if (nodeType == -1) return; boolean withParent = false; Browser browser = model.getSelectedBrowser(); if (browser != null) { int n = browser.getSelectedDisplays().length; if (n == 1) { TreeImageDisplay node = browser.getLastSelectedDisplay(); Object uo = node.getUserObject(); switch (nodeType) { case DATASET: if (uo instanceof ProjectData) withParent = model.isUserOwner(uo); break; case EXPERIMENTER: if (uo instanceof ExperimenterData) withParent = false; // true; break; case TAG: if (uo instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) uo; String ns = tag.getNameSpace(); if (ns != null && TagAnnotationData.INSIGHT_TAGSET_NS.equals(ns)) ; withParent = model.isUserOwner(tag); } /* if (fromTopMenu) withParent = false; else { if (uo instanceof TagAnnotationData) { TagAnnotationData tag = (TagAnnotationData) uo; String ns = tag.getNameSpace(); if (ns != null && TagAnnotationData.INSIGHT_TAGSET_NS.equals( ns)); withParent = model.isUserOwner(tag); } } */ } } } CreateCmd cmd = new CreateCmd(model, nodeType); cmd.setWithParent(withParent); cmd.execute(); }
/** * Returns the collection of annotation to remove. * * @see AnnotationUI#getAnnotationToRemove() */ protected List<Object> getAnnotationToRemove() { List<Object> l = new ArrayList<Object>(); if (selectedValue != initialValue && selectedValue == 0) { RatingAnnotationData rating = model.getUserRatingAnnotation(); if (rating != null) l.add(rating); } List<Long> idsToKeep; DocComponent doc; long id; Object object; Iterator<DocComponent> i; Collection original; Iterator j; if (tagFlag && !model.isMultiSelection()) { idsToKeep = new ArrayList<Long>(); TagAnnotationData tag; i = tagsDocList.iterator(); while (i.hasNext()) { doc = i.next(); object = doc.getData(); if (object instanceof TagAnnotationData) { tag = (TagAnnotationData) object; id = tag.getId(); if (id > 0) idsToKeep.add(id); } } original = model.getTags(); j = original.iterator(); while (j.hasNext()) { tag = (TagAnnotationData) j.next(); id = tag.getId(); if (!idsToKeep.contains(id)) // && model.isAnnotationToDelete(tag)) l.add(tag); } } if (docFlag) { idsToKeep = new ArrayList<Long>(); i = filesDocList.iterator(); FileAnnotationData fa; while (i.hasNext()) { doc = i.next(); object = doc.getData(); if (object instanceof FileAnnotationData) { fa = (FileAnnotationData) object; id = fa.getId(); if (id > 0) idsToKeep.add(id); } } original = model.getAttachments(); j = original.iterator(); while (j.hasNext()) { fa = (FileAnnotationData) j.next(); id = fa.getId(); if (!idsToKeep.contains(id)) // && model.isAnnotationToDelete(fa)) l.add(fa); } } if (model.hasBeenPublished()) { if (!publishedBox.isSelected()) { BooleanAnnotationData b = model.getPublishedAnnotation(); if (b.getValue().booleanValue()) l.add(b); } } return l; }