true
when the elements shall get enabled,
- * false
when they shall get disabled.
- */
- private void disOrEnableDialog(boolean enable) {
-
- if (enable) {
- tree.addMouseListener(treeMouseListener);
- } else {
- tree.removeMouseListener(treeMouseListener);
- }
- disOrEnableAllElements(FindUnlinkedFilesDialog.this, enable);
- }
-
- /**
- * Recursively disables or enables all swing and awt components in this
- * dialog, starting with but not including the container
- * startContainer
.
- *
- * @param startContainer
- * The GUI Element to start with.
- * @param enable
- * true
, if all elements will get enabled,
- * false
if all elements will get disabled.
- */
- private void disOrEnableAllElements(Container startContainer, boolean enable) {
- Component[] children = startContainer.getComponents();
- for (Component child : children) {
- if (child instanceof Container) {
- disOrEnableAllElements((Container) child, enable);
- }
- child.setEnabled(enable);
- }
- }
-
- /**
- * Expands or collapses the specified tree according to the
- * expand
-parameter.
- */
- private void expandTree(JTree currentTree, TreePath parent, boolean expand) {
- TreeNode node = (TreeNode) parent.getLastPathComponent();
- if (node.getChildCount() >= 0) {
- for (Enumerationnode
, which have been marked as selected. Selected
nodes correspond to those entries in the tree,
- * whose checkbox is checked
.
- *
- * SIDE EFFECT: The checked nodes are removed from the tree.
- *
- * @param node
- * The root node representing a tree structure.
- * @return A list of files of all checked leaf nodes.
- */
- private Listnull
, if no
- * filling wants to be specified.
- * @param anchor
- * A constant describing the anchor of the element in its parent
- * container (see {@link GridBagConstraints}). Can be
- * null
, if no specification is needed.
- * @param gridX
- * The relative grid-X coordinate.
- * @param gridY
- * The relative grid-Y coordinate.
- * @param width
- * The relative width of the component.
- * @param height
- * The relative height of the component.
- * @param weightX
- * A value for the horizontal weight.
- * @param weightY
- * A value for the vertical weight.
- * @param insets
- * Insets of the component. Can be null
.
- */
- private static void addComponent(GridBagLayout layout, Container container, Component component, Integer fill,
- Integer anchor, Insets insets, int gridX, int gridY, int width, int height, double weightX, double weightY,
- int ipadX, int ipadY) {
- container.setLayout(layout);
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.gridx = gridX;
- constraints.gridy = gridY;
- constraints.gridwidth = width;
- constraints.gridheight = height;
- constraints.weightx = weightX;
- constraints.weighty = weightY;
- constraints.ipadx = ipadX;
- constraints.ipady = ipadY;
- if (fill != null) {
- constraints.fill = fill;
- }
- if (insets != null) {
- constraints.insets = insets;
- }
- if (anchor != null) {
- constraints.anchor = anchor;
- }
- layout.setConstraints(component, constraints);
- container.add(component);
- }
-
- /**
- * Creates the tree view, that holds the data structure. expand
-parameter.
+ */
+ private void expandTree(TreeItem> item, boolean expand) {
+ if (item != null && !item.isLeaf()) {
+ item.setExpanded(expand);
+ for (TreeItem> child : item.getChildren()) {
+ expandTree(child, expand);
+ }
+ }
+ }
+
+ /**
+ * Starts the search of unlinked files according chosen directory and the file type selection. The search will
+ * process in a separate thread and a progress indicator will be displayed.
+ */
+ private void startSearch() {
+ Path directory = getSearchDirectory();
+ FileFilter selectedFileFilter = comboBoxFileTypeSelection.getValue();
+
+ findUnlinkedFilesTask = new UnlinkedFilesCrawler(directory, selectedFileFilter, databaseContext)
+ .onRunning(() -> {
+ panelSearchProgress.setVisible(true);
+ buttonScan.setDisable(true);
+ tree.setRoot(null);
+ })
+ .onFinished(() -> {
+ panelSearchProgress.setVisible(false);
+ buttonScan.setDisable(false);
+ })
+ .onSuccess(root -> {
+ tree.setRoot(root);
+ root.setSelected(true);
+ root.setExpanded(true);
+
+ buttonApply.setDisable(false);
+ buttonExport.setDisable(false);
+ buttonScan.setDefaultButton(false);
+ });
+ findUnlinkedFilesTask.executeWith(Globals.TASK_EXECUTOR);
+ }
+
+ private Path getSearchDirectory() {
+ Path directory = Paths.get(textfieldDirectoryPath.getText());
+ if (Files.notExists(directory)) {
+ directory = Paths.get(System.getProperty("user.dir"));
+ textfieldDirectoryPath.setText(directory.toAbsolutePath().toString());
+ }
+ if (!Files.isDirectory(directory)) {
+ directory = directory.getParent();
+ textfieldDirectoryPath.setText(directory.toAbsolutePath().toString());
+ }
+ return directory;
+ }
+
+ /**
+ * This will start the import of all file of all selected nodes in the file tree view.
+ */
+ private void startImport() {
+ CheckBoxTreeItem