Class BundleFileLibrary

java.lang.Object
com.amalgamasimulation.desktop.appelements.utils.BundleFileLibrary

public class BundleFileLibrary extends Object
A library of files stored inside a bundle. It shows them as a tree in a dialog and returns the file system path of the chosen file.

The constructor builds the tree. It contains the files with the given extensions from the given folder of the bundle and all its subfolders, and the subfolders that have at least one such file at any depth. Empty folders are removed. Inside a folder the entries are sorted alphabetically, ignoring case, with folders and files mixed. The root of the tree is the folder itself, shown as rootName.

The ignored.txt file

To hide some files and folders, put a file named ignored.txt into the given folder. Each line of the file is a piece of text to look for in the path of a file or folder, counted from the root of the bundle. If the path contains the text anywhere, the file or folder is left out of the tree. Everything inside a hidden folder is hidden too.

Example: the folder is resources/scenarios/, and ignored.txt has one line, old.

  • resources/scenarios/old/a.xlsx is hidden, because the path contains old.
  • resources/scenarios/gold.xlsx is hidden too, because gold contains old.
  • resources/scenarios/new/b.xlsx is shown.

Spaces at the ends of a line are ignored. Empty lines and lines that start with # are skipped, so # can mark comments. Case matters. Only the ignored.txt of the given folder is read; such files in subfolders have no effect.

Author:
Ionov Ivan
  • Constructor Details

    • BundleFileLibrary

      public BundleFileLibrary(org.osgi.framework.Bundle bundle, String folder, String rootName, Set<String> fileExtensions)
      Builds the tree of files in a folder of the bundle.
      Parameters:
      bundle - the bundle that holds the files
      folder - the path to the folder from the root of the bundle, for example resources/scenarios/; the trailing slash may be omitted
      rootName - the label of the tree root in the dialog
      fileExtensions - the endings of the file names to include, for example .xlsx; case is ignored
  • Method Details

    • isEmpty

      public boolean isEmpty()
      Tells whether the library has no files. This happens when the bundle has no such folder, the folder has no files with the given extensions, or all of them are hidden by ignored.txt.
      Returns:
      true if the tree has no files
    • chooseFile

      public String chooseFile(org.eclipse.swt.widgets.Shell shell)
      Opens the library dialog and waits for the user to choose a file.
      Parameters:
      shell - the parent shell of the dialog
      Returns:
      the file system path of the chosen file, or null if the dialog is closed without a choice or the file cannot be obtained (the error is printed to the console)