コード例 #1
0
 /**
  * Returns the collection of attachments.
  *
  * @return See above.
  */
 List<FileAnnotationData> removeAttachedFiles() {
   List<FileAnnotationData> list = new ArrayList<FileAnnotationData>();
   if (filesDocList.size() == 0) {
     docFlag = false;
     return list;
   }
   List<FileAnnotationData> toKeep = new ArrayList<FileAnnotationData>();
   FileAnnotationData data;
   DocComponent doc;
   Object object;
   Iterator<DocComponent> i = filesDocList.iterator();
   while (i.hasNext()) {
     doc = i.next();
     object = doc.getData();
     if (doc.canUnlink()) {
       if (object instanceof FileAnnotationData) {
         data = (FileAnnotationData) object;
         if (data.getId() > 0) list.add(data);
       }
     } else {
       toKeep.add((FileAnnotationData) object);
     }
   }
   handleObjectsSelection(FileAnnotationData.class, toKeep, false);
   if (list.size() == 0) docFlag = false;
   return list;
 }
コード例 #2
0
  /**
   * Starts an asynchronous call to save the passed file back to the server.
   *
   * @param file The file to save.
   * @param asynch Pass <code>true</code> to save asynchronously, <code>false</code> otherwise.
   */
  void fireFileSaving(File file, boolean asynch) {
    boolean fileIsExp = browser.isModelExperiment();
    int fileType = (fileIsExp ? FileSaver.EXPERIMENT : FileSaver.PROTOCOL);

    saveFile(file);
    FileAnnotationData data = null;
    DataObject linkTo = parent;
    if (fileAnnotation != null) data = fileAnnotation;
    else data = new FileAnnotationData(file);
    if (data.getId() > 0) linkTo = null;
    String description = CPEsummaryExport.export(browser.getTreeModel());
    if (description != null) data.setDescription(description);

    if (asynch) {
      currentLoader = new FileSaver(component, ctx, file, data, fileType, linkTo);
      currentLoader.load();
      state = Editor.SAVING;
    } else {
      OmeroMetadataService svc = EditorAgent.getRegistry().getMetadataService();
      try {
        svc.archivedFile(ctx, fileAnnotation, file, fileType, linkTo);
      } catch (Exception e) {
        LogMessage msg = new LogMessage();
        msg.print("State: " + state);
        msg.print("Cannot save file back to server");
        msg.print(e);
        EditorAgent.getRegistry().getLogger().error(this, msg);
      }
    }
  }
コード例 #3
0
  /**
   * Attaches the passed file. Returns <code>true</code> if the file does not already exist, <code>
   * false</code> otherwise.
   *
   * @param files The files to attach.
   * @return See above
   */
  boolean attachFiles(File[] files) {
    List<FileAnnotationData> list = getCurrentAttachmentsSelection();
    DocComponent doc;
    List<File> toAdd = new ArrayList<File>();
    Object data = null;
    if (filesDocList.size() > 0) {
      Iterator<DocComponent> i = filesDocList.iterator();
      FileAnnotationData fa;
      while (i.hasNext()) {
        doc = i.next();
        data = doc.getData();
        if (data instanceof FileAnnotationData) {
          fa = (FileAnnotationData) data;
          /*
          for (int j = 0; j < files.length; j++) {
          	if (fa.getId() <= 0) {
          		if (!fa.getFilePath().equals(
          				files[j].getAbsolutePath()))
          			toAdd.add(files[j]);
          		list.add(fa);
          	} else {
          		if (fa.getFileName().equals(files[j].getName())) {
          			toReplace.add(fa);
          		} else toAdd.add(files[j]);
          	}
          }
          */
          for (int j = 0; j < files.length; j++) {
            if (fa.getId() >= 0 && fa.getFileName().equals(files[j].getName())) {
              toReplace.add(fa);
            }
          }
        }
      }
    }
    // if (data == null) {
    for (int i = 0; i < files.length; i++) {
      toAdd.add(files[i]);
    }
    // }
    if (toAdd.size() > 0) {
      data = null;
      try {
        docFlag = true;
        Iterator<File> j = toAdd.iterator();
        while (j.hasNext()) {
          list.add(new FileAnnotationData(j.next()));
        }

      } catch (Exception e) {
      }
      firePropertyChange(
          EditorControl.SAVE_PROPERTY, Boolean.valueOf(false), Boolean.valueOf(true));
    }
    layoutAttachments(list);
    return toAdd.size() > 0;
  }
コード例 #4
0
 /**
  * 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));
 }
コード例 #5
0
 /**
  * Sets the file annotation data.
  *
  * @param data The value to set.
  */
 void setFileAnnotationData(FileAnnotationData data) {
   fileAnnotation = data;
   if (data == null) {
     fileID = 0;
     fileName = null;
     nameSpace = null;
     return;
   }
   this.fileID = data.getFileID();
   this.fileName = data.getFileName();
   nameSpace = data.getNameSpace();
 }
コード例 #6
0
  /**
   * Modifies the text of the component.
   *
   * @see ActivityComponent#notifyActivityEnd()
   */
  protected void notifyActivityEnd() {
    // Download the file.
    if (result instanceof FileAnnotationData) {
      FileAnnotationData data = (FileAnnotationData) result;
      String name = "";
      if (data.isLoaded()) name = data.getFileName();
      else name = "Annotation_" + data.getId();
      download("", result, new File(parameters.getFolder(), name));
    }

    type.setText(DESCRIPTION_CREATED + " " + parameters.getFolder().getName());
  }
コード例 #7
0
 /**
  * Returns the instrument transfer function linked to the edited object.
  *
  * @return See above
  */
 FileAnnotationData getIRF() {
   if (!(refObject instanceof ImageData)) return null;
   if (data == null) return null;
   Collection<FileAnnotationData> l = getStructuredData().getAttachments();
   if (l == null || l.size() == 0) return null;
   Iterator<FileAnnotationData> i = l.iterator();
   FileAnnotationData fa;
   while (i.hasNext()) {
     fa = i.next();
     if (fa.getFileName().contains("irf")) return fa;
   }
   return null;
 }
コード例 #8
0
ファイル: FileLoader.java プロジェクト: hinerm/openmicroscopy
 /**
  * Creates a new instance.
  *
  * @param viewer The viewer this data loader is for. Mustn't be <code>null</code>.
  * @param data The annotation hosting the file to load.
  * @param uiView The object to handle.
  */
 public FileLoader(Editor viewer, FileAnnotationData data, Object uiView) {
   super(viewer);
   if (data == null) throw new IllegalArgumentException("No data set.");
   this.data = data;
   this.uiView = uiView;
   file = new File(MetadataViewerAgent.getTmpDir() + File.separator + data.getFileName());
   file.deleteOnExit();
 }
コード例 #9
0
 /**
  * Returns the list of attachments currently selected by the user.
  *
  * @return See above.
  */
 List<FileAnnotationData> getCurrentAttachmentsSelection() {
   List<FileAnnotationData> list = new ArrayList<FileAnnotationData>();
   if (filesDocList.size() == 0) return list;
   DocComponent doc;
   Object object;
   FileAnnotationData data;
   Iterator<DocComponent> i = filesDocList.iterator();
   while (i.hasNext()) {
     doc = i.next();
     object = doc.getData();
     if (object instanceof FileAnnotationData) {
       data = (FileAnnotationData) object;
       if (data.getId() > 0) list.add(data);
     }
   }
   return list;
 }
コード例 #10
0
 /**
  * Returns the collection of the attachments linked to the <code>DataObject</code>.
  *
  * @return See above.
  */
 private List<FileAnnotationData> getTabularData() {
   StructuredDataResults data = getStructuredData();
   List<FileAnnotationData> l = new ArrayList<FileAnnotationData>();
   if (data == null) return l;
   Collection<FileAnnotationData> attachments = data.getAttachments();
   if (attachments == null) return l;
   Iterator<FileAnnotationData> i = attachments.iterator();
   FileAnnotationData f;
   String ns;
   while (i.hasNext()) {
     f = i.next();
     ns = f.getNameSpace();
     if (FileAnnotationData.BULK_ANNOTATIONS_NS.equals(ns)) {
       l.add(f);
     }
   }
   return l;
 }
コード例 #11
0
  /**
   * Starts the asynchronous loading of the file to edit. and sets the state to {@link
   * Editor#LOADING}.
   */
  void fireFileLoading() {
    long size = 0;
    if (fileAnnotation != null) size = fileAnnotation.getFileSize();

    // fileID can be annotationID if fileName is null
    // E.g. if EditorModel(long annotationID) was the constructor.
    currentLoader = new FileLoader(component, ctx, fileName, fileID, size);
    currentLoader.load();
    state = Editor.LOADING;
  }
コード例 #12
0
 /**
  * Removes the passed file from the display.
  *
  * @param file The file to remove.
  */
 void removeAttachedFile(Object file) {
   if (file == null) return;
   FileAnnotationData fData = (FileAnnotationData) file;
   List<FileAnnotationData> attachments = getCurrentAttachmentsSelection();
   Iterator<FileAnnotationData> i = attachments.iterator();
   FileAnnotationData data;
   List<FileAnnotationData> toKeep = new ArrayList<FileAnnotationData>();
   while (i.hasNext()) {
     data = i.next();
     if (data.getId() != fData.getId()) toKeep.add(data);
   }
   if (filesDocList.size() > 0) {
     Iterator<DocComponent> j = filesDocList.iterator();
     DocComponent doc;
     Object fa;
     while (j.hasNext()) {
       doc = j.next();
       fa = doc.getData();
       if (fa instanceof FileAnnotationData) {
         data = (FileAnnotationData) fa;
         if (data.getId() <= 0 && !data.equals(file)) {
           toKeep.add(data);
         }
       }
     }
   }
   handleObjectsSelection(FileAnnotationData.class, toKeep, true);
 }
コード例 #13
0
ファイル: FileLoader.java プロジェクト: hinerm/openmicroscopy
 /**
  * Downloads the file.
  *
  * @see EditorLoader#cancel()
  */
 public void load() {
   if (data != null) {
     OriginalFile f = ((FileAnnotation) data.asAnnotation()).getFile();
     if (f.isLoaded()) {
       handle = mhView.loadFile(file, f.getId().getValue(), f.getSize().getValue(), this);
     }
   } else {
     Entry entry;
     Iterator i = files.entrySet().iterator();
     FileAnnotationData fa;
     filesMap = new HashMap<FileAnnotationData, File>(files.size());
     File f;
     // int index = 0;
     String dir = MetadataViewerAgent.getTmpDir();
     while (i.hasNext()) {
       entry = (Entry) i.next();
       fa = (FileAnnotationData) entry.getKey();
       f = new File(dir + File.separator + fa.getFileID() + "_" + fa.getFileName());
       f.deleteOnExit();
       filesMap.put(fa, f);
     }
     handle = mhView.loadFiles(filesMap, this);
   }
 }
コード例 #14
0
 /**
  * Gets a reference to the Original File if this file has been saved to the server. Otherwise
  * returns 0.
  *
  * @return See above
  */
 long getAnnotationId() {
   if (fileAnnotation == null) return annotationID;
   return fileAnnotation.getId();
 }
コード例 #15
0
  /**
   * 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;
  }