Interface DocumentSource


public interface DocumentSource
Provides documents from a document source such as a document management system or a file system.
  • Method Details

    • getID

      String getID()
      Returns:
      A unique ID for the document source.
    • getTitle

      String getTitle()
      Returns:
      A readable title for the document source that can be used for example to display the source to an end-user.
    • getIcon

      URL getIcon()
      Returns a URL to an icon for this document source. If the icon is not 24x24 pixels, it may be rescaled.
      Returns:
      a url to an icon.
    • getColor

      default Color getColor()
      Returns a distinctive color that may be used to differentiate between this source and other source, for example when showing document types in the browser.
      Returns:
      A color.
    • getFilterTypes

      List<DocumentFilterType> getFilterTypes()
      Returns:
      Available filters that can be used to search for documents provided by this source.
    • getMetaDataGroups

      List<MetaDataGroup> getMetaDataGroups(Document doc)
      Returns groups for the meta data. The groups are used to layout editors of documents.
      Parameters:
      doc - The document to get the groups for.
      Returns:
      A list of meta data groups used to layout editors of documents.
      See Also:
    • getMetaDataTypes

      List<MetaDataType<? extends MetaData<?>>> getMetaDataTypes()
      Returns:
      Available meta-data types for documents from this source.
    • getMetaDataType

      default MetaDataType<? extends MetaData<?>> getMetaDataType(String id)
      Returns the meta data type with the given id, or null, if no such meta data type can be found.
      Parameters:
      id - The id of the meta data type to find.
      Returns:
      the meta data type with the given id or null.
    • getDocumentIDs

      List<String> getDocumentIDs(Collection<DocumentFilter> filters, MetaDataType orderBy, boolean ascendingOrder)
      Returns all document ids that matches a set of filters.
      Parameters:
      filters - The document filters to apply.
      orderBy - The meta-data type to order the result by
      ascendingOrder - true for ascending sort order, false for descending
      Returns:
      id:s for documents matching the filters.
    • getDocumentIDs

      default List<String> getDocumentIDs(Collection<String> searchSpace, Collection<DocumentFilter> filters, MetaDataType orderBy, boolean ascendingOrder)
    • getDocuments

      List<Document> getDocuments(List<String> ids, Collection<? extends MetaDataType<?>> columns)
      Fetches documents with given id:s.
      Parameters:
      ids - The id:s of documents to fetch.
      columns - The requested metadata for the returned documents.
      Returns:
      Documents matching the id:s, in the same order as the supplied id:s.
    • isSettingsEditable

      default boolean isSettingsEditable()
      Returns:
      true if the source has settings that should be editable in the user interface.
    • getEditorComponent

      JComponent getEditorComponent(Consumer<String> callback, String current)
      Returns a JComponent that will be shown in a dialog or panel. The component is self contained (must supply its own ok/cancel-buttons if applicable) and is supposed to generate a String containing settings. Once it is created, the successCallback should be invoked at which point the returned component is removed from its component hierarchy and the settings string will be persisted. This source is expected to start using the new settings immediately after a call to the callback and will have update(String) called as a convenience to help enforce this.
      Parameters:
      callback - A callback to invoke once the user is done editing the settings. The string sent to the consumer will be persisted.
      current - The current settings for this source or an empty string if this source has never changed its settings.
      Returns:
      An editor capable of editing the current settings (or the empty string if no settings have been made in the repository yet).
    • initialize

      void initialize(String settingsOrEmpty)
      This method is the first to be called once this source is registered. It will either be called with a previous settings string or an empty string if this source has never been started in the currently running repository.
      Parameters:
      settingsOrEmpty - The settings to use.
    • update

      void update(String settings)
      Convenience-method used to help implementors separate the component returned from getEditorComponent(Consumer, String) and this source. Typically, the component can have a reference to this source and inform the source when the settings change, but to make it clear when the source is expected to start using its new settings this method will always be called as a convenience after the callback parameter sent to getEditorComponent(Consumer, String) is invoked.
      Parameters:
      settings - The last settings seen by a callback sent to getEditorComponent(Consumer, String).
    • getCreator

      default Optional<DocumentSource.Creator> getCreator()
      Returns empty if this source cannot create new documents. Otherwise a creator is returned. The creator is used to create a new instance of an unsaved document. A user then gets to edit any metadata that is editable in the document. When the user is done, save is invoked on the creator with the edited document.
      Returns:
      Empty to indicate that creation is not available, otherwise a creator.
    • getRemover

      default Optional<DocumentSource.Remover> getRemover(Collection<Document> documents)
      Returns empty if this source cannot remove one or more of the given documents. Otherwise a remover is returned. The remover is called if a user decides to remove all documents in the given collection.
      The remover is only called with a collection containing the elements given to this method.
      Parameters:
      documents - The documents to possibly remove in a future call to the remover.
      Returns:
      Empty to indicate that removal of the one or more of the documents is impossible, otherwise a remover.
    • getSaver

      default Optional<DocumentSource.Saver> getSaver()
      Returns empty if this source cannot edit one or more of the given documents. Otherwise a saver is returned. The saver is called if a user decides to edit one or more of the editable metadata on the documents in the collection.
      The saver will only be called with documents transformed from the documents in the given collection. Since documents are immutable, it will however not be the same instances.
      Returns:
      Empty to indicate that editing of one or more of the documents is impossible, otherwise a saver.
    • getPatternFilter

      default Optional<DocumentFilter> getPatternFilter(String pattern, MTLanguage language, boolean exactMatch, boolean ignoreCase)
      Returns an optional pattern matching filter. If available the search field in the browser can be used to apply this filter. Sources are free to choose how to filter based on the pattern. The recommended behaviour is to filter on title only since it can be confusing to the end user if results are shown where the matching data isn't shown in any of the result columns.
      Parameters:
      pattern - The pattern to match against.
      language - The current repository language.
      exactMatch - True to match the pattern exactly, false otherwise.
      ignoreCase - True if a case insensitive match is requested, false for case sensitivity.
      Returns:
      A filter matching the pattern.
    • addDocumentSourceListener

      default void addDocumentSourceListener(DocumentSourceListener l)
      Adds a listener for changes in the source.
      Parameters:
      l - The listener to add.
    • removeDocumentSourceListener

      default void removeDocumentSourceListener(DocumentSourceListener l)
      Adds a listener for changes in the source.
      Parameters:
      l - the listener to remove.
    • isReachable

      default boolean isReachable(Document doc)
      Returns true if the given document can still be reached, false otherwise. A false return typically indicates that the document has been removed from the document source. This method is used to generate warnings, for example, when publishing. The user will be informed that any symbol or model that the given document is connected to contains a broken link.
      Parameters:
      doc - The document to test.
      Returns:
      True if the given document can still be reached, false otherwise.