/**
  * 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();
 }
  /**
   * 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;
  }
 /**
  * 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();
 }
  /**
   * 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());
  }
 /**
  * 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;
 }
 /**
  * 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);
   }
 }