示例#1
0
  /**
   * Listens to property fired by the Editor dialog.
   *
   * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)) {
      // reset text and tooltip
      String text = "";
      String description = "";
      AnnotationData annotation = null;
      if (data instanceof TagAnnotationData
          || data instanceof TermAnnotationData
          || data instanceof XMLAnnotationData) {
        annotation = (AnnotationData) data;
        text = annotation.getContentAsString();
        text = EditorUtil.truncate(text, TEXT_LENGTH, false);
      }
      if (data instanceof DoubleAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((DoubleAnnotationData) data).getDataValue();
      }
      if (data instanceof LongAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((LongAnnotationData) data).getDataValue();
      }
      if (data instanceof BooleanAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((BooleanAnnotationData) data).getValue();
      }
      description = model.getAnnotationDescription(annotation);
      if (annotation == null) return;
      label.setText(text);
      label.setToolTipText(formatToolTip(annotation, null));
      originalName = text;
      originalDescription = description;
      firePropertyChange(AnnotationUI.EDIT_TAG_PROPERTY, null, this);
    } else if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
      if (data == null) return;
      FileAnnotationData fa = (FileAnnotationData) data;
      OriginalFile f = (OriginalFile) fa.getContent();
      File folder;
      Object o = evt.getNewValue();
      if (o instanceof String) {
        String path = (String) o;
        if (!path.endsWith(File.separator)) {
          path += File.separator;
        }
        path += fa.getFileName();
        folder = new File(path);
      } else {
        File[] files = (File[]) o;
        folder = files[0];
      }
      if (folder == null) folder = UIUtilities.getDefaultFolder();
      UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();

      IconManager icons = IconManager.getInstance();

      DownloadActivityParam activity =
          new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22));
      // Check Name space
      activity.setLegend(fa.getDescription());
      un.notifyActivity(model.getSecurityContext(), activity);
    }
  }
示例#2
0
  /**
   * Formats the passed annotation.
   *
   * @param annotation The value to format.
   * @param name The full name.
   * @return See above.
   */
  private String formatToolTip(AnnotationData annotation, String name) {
    ToolTipGenerator tt = new ToolTipGenerator();
    if (model.isMultiSelection()) {
      Map<DataObject, Boolean> m = null;
      Entry<DataObject, Boolean> e;
      Iterator<Entry<DataObject, Boolean>> j;
      String text = "";
      if (annotation instanceof TagAnnotationData) {
        m = model.getTaggedObjects(annotation);
        text += "Can remove Tag from ";
      } else if (annotation instanceof FileAnnotationData) {
        m = model.getObjectsWith(annotation);
        text += "Can remove Attachment from ";
      } else if (annotation instanceof XMLAnnotationData) {
        m = model.getObjectsWith(annotation);
        text += "Can remove XML files from ";
      } else if (annotation instanceof TermAnnotationData) {
        m = model.getObjectsWith(annotation);
        text += "Can remove Term from ";
      }
      if (m == null) return "";
      j = m.entrySet().iterator();
      Collection<Boolean> l = m.values();
      int n = 0;
      Iterator<Boolean> k = l.iterator();
      while (k.hasNext()) {
        if (k.next().booleanValue()) n++;
      }
      tt.addLineNoBr(text + "" + n + " ");
      int index = 0;
      String s;
      while (j.hasNext()) {
        e = j.next();
        if (index == 0) {
          tt.addLine(model.getObjectTypeAsString(e.getKey()) + "s", true);
          index++;
        }
        tt.addLine(
            "ID " + e.getKey().getId(),
            UIUtilities.formatPartialName(model.getObjectName(e.getKey())),
            true);
        // Indicates who annotates the object if not the user
        // currently logged in.
        s = formatAnnotators(e.getKey(), annotation);
        if (s != null) tt.addLine(s);
      }
      return tt.toString();
    }

    if (name != null) {
      tt.addLine("Name", name, true);
    }

    ExperimenterData exp = null;

    if (annotation.getId() > 0) {
      exp = model.getOwner(annotation);
      tt.addLine("ID", "" + annotation.getId(), true);
    }

    String ns = annotation.getNameSpace();
    if (!CommonsLangUtils.isEmpty(ns) && !EditorUtil.isInternalNS(ns)) {
      tt.addLine("Namespace", ns, true);
    }

    String desc = annotation.getDescription();
    if (!CommonsLangUtils.isEmpty(desc)) {
      tt.addLine("Description", desc, true);
    }

    if (exp != null) {
      tt.addLine("Owner", EditorUtil.formatExperimenter(exp), true);
    }

    Timestamp created = annotation.getCreated();
    if (created != null) {
      tt.addLine("Date", UIUtilities.formatDefaultDate(created), true);
    }

    if (data instanceof FileAnnotationData) {
      FileAnnotationData fa = (FileAnnotationData) data;
      long size = ((FileAnnotationData) annotation).getFileSize();
      tt.addLine("File ID", "" + fa.getFileID(), true);
      tt.addLine("Size", UIUtilities.formatFileSize(size) + "kb", true);
      checkAnnotators(tt, annotation);
    } else if (data instanceof TagAnnotationData
        || data instanceof XMLAnnotationData
        || data instanceof TermAnnotationData
        || data instanceof LongAnnotationData
        || data instanceof DoubleAnnotationData
        || data instanceof BooleanAnnotationData) {
      checkAnnotators(tt, annotation);
    }
    return tt.toString();
  }