Class DocumentNoteUtilities


  • public final class DocumentNoteUtilities
    extends java.lang.Object
    This gives access to the NoteTypes defined in the program. These are the "Note Types" that can be seen in the "Notes" interface of the program. The user can modify them through the user interface.

    If you programatically depend on a particular DocumentNoteType you should always deal with the codes of fields as the names can change. Also it is recommended that any note type fields that you depend on are dontAllowModification = true so the user can not delete or modify that field.

    DocumentNoteTypes can not be deleted from the program once they are added. This is because documents may already have instances of a note type. Use DocumentNoteType.setVisible(boolean) and then setNoteType(DocumentNoteType) to have the NoteType not visible in the interface. This is equivalent to a note type being deleted in the user interface.

    Here is an example of creating a note type and adding it to a document. This could be used to add extra information to a document at the end of an operation.

        java.util.List noteFields = new ArrayList();
        String fieldCode = "Field1";
        noteFields.add(DocumentNoteField.createTextNoteField("Field no.1", "The first field", fieldCode, Collections.emptyList(), false));
        String noteTypeCode = "DocumentNoteUtilities-TestNote";
        DocumentNoteType noteType = DocumentNoteUtilities.getNoteType(noteTypeCode);
        if (noteType == null) { //create and add the note type if it hasn't already been added
            noteType = DocumentNoteUtilities.createNewNoteType("Test Note", noteTypeCode, "A test note", noteFields, true);
            DocumentNoteUtilities.setNoteType(noteType);
        }
        DocumentNote note = noteType.createDocumentNote();
        note.setFieldValue(fieldCode, "A value!");
        AnnotatedPluginDocument.DocumentNotes documentNotes = annotatedDocument.getDocumentNotes(true);
        documentNotes.setNote(note);
        documentNotes.saveNotes();
     
    • Method Detail

      • getNoteType

        public static DocumentNoteType getNoteType​(java.lang.String code)
        WARNING: These are not defensive copies of the note types so do not modify them unless you are definitely going to call setNoteType(DocumentNoteType) to save them.
        Parameters:
        code - of the DocumentNoteType
        Returns:
        DocumentNoteType with code code or null if no DocumentNoteType with this code exists.
      • getAllNoteTypes

        public static java.util.List<DocumentNoteType> getAllNoteTypes()
        This includes all the users custom note types.

        WARNING: This is not a defensive copies of the note type so do not modify the note type unless you are definitely going to call setNoteType(DocumentNoteType) to save it.

        Returns:
        a list of all available note types
      • createNewNoteType

        public static DocumentNoteType createNewNoteType​(java.lang.String name,
                                                         java.lang.String code,
                                                         java.lang.String description,
                                                         java.util.List<DocumentNoteField> fields,
                                                         boolean visible)
        Create a new DocumentNoteType which should be used for adding a new note type. use setNoteType(DocumentNoteType) to add the note type after setting it up.
        Parameters:
        name - of the new DocumentNoteType. Must not be null.
        code - a unique identifier for this note type. Must not contain '.' or be null. Using fully qualified class name with '.' stripped is a good way to ensure uniqueness.
        description - of the new DocumentNoteType. Must not be null.
        fields - for the DocumentNoteType to contain. Must not be null or empty.
        visible - true to have the DocumentNoteType visible in the user interface, false if not.
        Returns:
        The new DocumentNoteType.
        Throws:
        java.lang.IllegalArgumentException - if the note contains characters that can't be serialized to XML
      • setNoteType

        public static void setNoteType​(DocumentNoteType documentNoteType)
        Can be used to add a new DocumentNoteType to the program if this DocumentNoteType does not already exist. Can also be used to modify an existing DocumentNoteType by getting the original from getNoteType(String), modifying it and calling this to save the changes.

        Be careful when using this because you can modify the users custom note types which is not recommended unless the users is absolutely aware of this happening and of the possible consequences.
        Parameters:
        documentNoteType - to add or update
        Throws:
        java.lang.IllegalArgumentException - if a type already exists with the given code and existingNoteType == documentNoteType is false.
      • copyNotes

        public static void copyNotes​(AnnotatedPluginDocument sourceDocument,
                                     AnnotatedPluginDocument destinationDocument)
        Copies all document notes from one document to another
        Parameters:
        sourceDocument - the document to copy notes from
        destinationDocument - the document to copy notes to
        Since:
        API 4.901 (Geneious 9.0.1)
      • addNotesTo

        public static void addNotesTo​(AnnotatedPluginDocument document,
                                      java.util.List<DocumentNote> notesToAdd)
        Adds a list of document notes to a document
        Parameters:
        document - the document to add notes to
        notesToAdd - the notes to be added to the document
        Since:
        API 4.901 (Geneious 9.0.1)