public final class DocumentNoteUtilities extends Object
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();
| Modifier and Type | Method and Description |
|---|---|
static DocumentNoteType |
createNewNoteType(String name,
String code,
String description,
List<DocumentNoteField> fields,
boolean visible)
Create a new
DocumentNoteType which should be used
for adding a new note type. |
static List<DocumentNoteType> |
getAllNoteTypes()
This includes all the users custom note types.
|
static DocumentNoteType |
getNoteType(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. |
static void |
setNoteType(DocumentNoteType documentNoteType)
Can be used to add a new
DocumentNoteType to the program if this
DocumentNoteType does not already exist. |
public static DocumentNoteType getNoteType(String code)
setNoteType(DocumentNoteType) to save them.code - of the DocumentNoteTypecode or null if no DocumentNoteType with this code exists.public static List<DocumentNoteType> getAllNoteTypes()
setNoteType(DocumentNoteType) to save it.public static DocumentNoteType createNewNoteType(String name, String code, String description, List<DocumentNoteField> fields, boolean visible)
DocumentNoteType which should be used
for adding a new note type. use setNoteType(DocumentNoteType) to
add the note type after setting it up.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.DocumentNoteType.IllegalArgumentException - if the note contains characters that can't be serialized to XMLpublic static void setNoteType(DocumentNoteType documentNoteType)
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.
documentNoteType - to add or updateIllegalArgumentException - if a type already exists with the given code and existingNoteType ==
documentNoteType is false.