Class BundleFileLibrary
java.lang.Object
com.amalgamasimulation.desktop.appelements.utils.BundleFileLibrary
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 namedignored.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.xlsxis hidden, because the path containsold.resources/scenarios/gold.xlsxis hidden too, becausegoldcontainsold.resources/scenarios/new/b.xlsxis 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 Summary
ConstructorsConstructorDescriptionBundleFileLibrary(org.osgi.framework.Bundle bundle, String folder, String rootName, Set<String> fileExtensions) Builds the tree of files in a folder of the bundle. -
Method Summary
Modifier and TypeMethodDescriptionchooseFile(org.eclipse.swt.widgets.Shell shell) Opens the library dialog and waits for the user to choose a file.booleanisEmpty()Tells whether the library has no files.
-
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 filesfolder- the path to the folder from the root of the bundle, for exampleresources/scenarios/; the trailing slash may be omittedrootName- the label of the tree root in the dialogfileExtensions- 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 byignored.txt.- Returns:
- true if the tree has no files
-
chooseFile
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)
-