From 2a74e543733e8a5ccd5bbd5cff6110f4270a9e1d Mon Sep 17 00:00:00 2001 From: jmillman Date: Tue, 8 Dec 2015 16:09:00 -0500 Subject: [PATCH] cleanup and bind disabled state of controls to selectionAnchorIndex also put sorting of fx collection on fx thread --- .../datamodel/grouping/GroupManager.java | 11 +++--- .../autopsy/imagegallery/gui/GuiUtils.java | 16 ++++---- .../autopsy/imagegallery/gui/Toolbar.java | 38 ++++++++++--------- .../gui/drawableviews/GroupPane.java | 14 +++++-- .../gui/drawableviews/SlideShowView.java | 4 +- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java index 0a804118f8..dda6641097 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/datamodel/grouping/GroupManager.java @@ -34,7 +34,6 @@ import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; -import org.sleuthkit.autopsy.coreutils.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; import javafx.application.Platform; @@ -58,11 +57,12 @@ import org.apache.commons.lang3.concurrent.BasicThreadFactory; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.sleuthkit.autopsy.casemodule.Case; -import org.sleuthkit.autopsy.coreutils.LoggedTask; -import org.sleuthkit.autopsy.coreutils.ThreadConfined; -import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.casemodule.events.ContentTagAddedEvent; import org.sleuthkit.autopsy.casemodule.events.ContentTagDeletedEvent; +import org.sleuthkit.autopsy.coreutils.LoggedTask; +import org.sleuthkit.autopsy.coreutils.Logger; +import org.sleuthkit.autopsy.coreutils.ThreadConfined; +import org.sleuthkit.autopsy.coreutils.ThreadConfined.ThreadType; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.CategoryManager; @@ -697,7 +697,8 @@ public class GroupManager { groupProgress.progress("regrouping files by " + groupBy.attrName.toString() + " : " + val, p); popuplateIfAnalyzed(new GroupKey(groupBy, val), this); } - FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder)); + Platform.runLater(() -> FXCollections.sort(analyzedGroups, sortBy.getGrpComparator(sortOrder))); + updateProgress(1, 1); return null; } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java index b05a541574..2ff6f24d90 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/GuiUtils.java @@ -18,10 +18,9 @@ */ package org.sleuthkit.autopsy.imagegallery.gui; +import javafx.scene.control.ButtonBase; import javafx.scene.control.MenuItem; -import javafx.scene.control.SplitMenuButton; import org.controlsfx.control.action.Action; -import org.controlsfx.control.action.ActionUtils; /** * Static utility methods for working with GUI components @@ -32,21 +31,24 @@ public class GuiUtils { } /** + * create a MenuItem that performs the given action and also set the Action + * as the action for the given Button. Usefull to have a SplitMenuButton + * remember the last chosen menu item as its action. * - * @param splitMenuButton + * @param button * @param action * * @return */ - public static MenuItem createAutoAssigningSplitMenuItem(SplitMenuButton splitMenuButton, Action action) { + public static MenuItem createAutoAssigningMenuItem(ButtonBase button, Action action) { MenuItem menuItem = new MenuItem(action.getText(), action.getGraphic()); menuItem.setOnAction(actionEvent -> { action.handle(actionEvent); - ActionUtils.configureButton(action, splitMenuButton); + button.setText(action.getText()); + button.setGraphic(action.getGraphic()); + button.setOnAction(action); }); - return menuItem; } - } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java index abf9ab5442..91ca4a142c 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/Toolbar.java @@ -42,13 +42,13 @@ import javafx.scene.layout.HBox; import javax.swing.SortOrder; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.imagegallery.FXMLConstructor; -import org.sleuthkit.autopsy.imagegallery.FileIDSelectionModel; import org.sleuthkit.autopsy.imagegallery.ImageGalleryController; import org.sleuthkit.autopsy.imagegallery.actions.CategorizeGroupAction; import org.sleuthkit.autopsy.imagegallery.actions.TagGroupAction; import org.sleuthkit.autopsy.imagegallery.datamodel.Category; import org.sleuthkit.autopsy.imagegallery.datamodel.DrawableAttribute; import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupSortBy; +import org.sleuthkit.autopsy.imagegallery.datamodel.grouping.GroupViewState; import org.sleuthkit.datamodel.TskCoreException; /** @@ -103,7 +103,7 @@ public class Toolbar extends ToolBar { ImageGalleryController.getDefault().getGroupManager().regroup(groupByBox.getSelectionModel().getSelectedItem(), sortByBox.getSelectionModel().getSelectedItem(), getSortOrder(), false); }; - private final ImageGalleryController IGController; + private final ImageGalleryController controller; synchronized public SortOrder getSortOrder() { return orderProperty.get(); @@ -133,21 +133,14 @@ public class Toolbar extends ToolBar { assert sortControlGroup != null : "fx:id=\"sortControlGroup\" was not injected: check your FXML file 'Toolbar.fxml'."; assert tagGroupMenuButton != null : "fx:id=\"tagSelectedMenubutton\" was not injected: check your FXML file 'Toolbar.fxml'."; - FileIDSelectionModel.getInstance().getSelected().addListener((Observable o) -> { - Runnable r = () -> { - tagGroupMenuButton.setDisable(FileIDSelectionModel.getInstance().getSelected().isEmpty()); - catGroupMenuButton.setDisable(FileIDSelectionModel.getInstance().getSelected().isEmpty()); - }; - if (Platform.isFxApplicationThread()) { - r.run(); - } else { - Platform.runLater(r); - } + controller.viewState().addListener((observable, oldViewState, newViewState) -> { + Platform.runLater(() -> syncGroupControlsEnabledState(newViewState)); }); + syncGroupControlsEnabledState(controller.viewState().get()); tagGroupMenuButton.setOnAction(actionEvent -> { try { - new TagGroupAction(IGController.getTagsManager().getFollowUpTagName(), IGController).handle(actionEvent); + new TagGroupAction(controller.getTagsManager().getFollowUpTagName(), controller).handle(actionEvent); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "Could create follow up tag menu item", ex); } @@ -156,19 +149,19 @@ public class Toolbar extends ToolBar { tagGroupMenuButton.setGraphic(new ImageView(DrawableAttribute.TAGS.getIcon())); tagGroupMenuButton.showingProperty().addListener(showing -> { if (tagGroupMenuButton.isShowing()) { - List selTagMenues = Lists.transform(IGController.getTagsManager().getNonCategoryTagNames(), - tn -> GuiUtils.createAutoAssigningSplitMenuItem(tagGroupMenuButton, new TagGroupAction(tn, IGController))); + List selTagMenues = Lists.transform(controller.getTagsManager().getNonCategoryTagNames(), + tn -> GuiUtils.createAutoAssigningMenuItem(tagGroupMenuButton, new TagGroupAction(tn, controller))); tagGroupMenuButton.getItems().setAll(selTagMenues); } }); - catGroupMenuButton.setOnAction(new CategorizeGroupAction(Category.FIVE, IGController)); + catGroupMenuButton.setOnAction(new CategorizeGroupAction(Category.FIVE, controller)); catGroupMenuButton.setText(Category.FIVE.getDisplayName()); catGroupMenuButton.setGraphic(new ImageView(DrawableAttribute.CATEGORY.getIcon())); catGroupMenuButton.showingProperty().addListener(showing -> { if (catGroupMenuButton.isShowing()) { List categoryMenues = Lists.transform(Arrays.asList(Category.values()), - cat -> GuiUtils.createAutoAssigningSplitMenuItem(catGroupMenuButton, new CategorizeGroupAction(cat, IGController))); + cat -> GuiUtils.createAutoAssigningMenuItem(catGroupMenuButton, new CategorizeGroupAction(cat, controller))); catGroupMenuButton.getItems().setAll(categoryMenues); } }); @@ -200,6 +193,15 @@ public class Toolbar extends ToolBar { } + private void syncGroupControlsEnabledState(GroupViewState newViewState) { + boolean noGroupSelected = newViewState == null + ? true + : newViewState.getGroup() == null; + + tagGroupMenuButton.setDisable(noGroupSelected); + catGroupMenuButton.setDisable(noGroupSelected); + } + public void reset() { Platform.runLater(() -> { groupByBox.getSelectionModel().select(DrawableAttribute.PATH); @@ -210,7 +212,7 @@ public class Toolbar extends ToolBar { } private Toolbar(ImageGalleryController controller) { - this.IGController = controller; + this.controller = controller; FXMLConstructor.construct(this, "Toolbar.fxml"); } diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java index b0f819b272..a1eb1f8ccb 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/GroupPane.java @@ -38,6 +38,7 @@ import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Platform; import javafx.beans.InvalidationListener; +import javafx.beans.Observable; import javafx.beans.property.ReadOnlyObjectProperty; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.property.SimpleObjectProperty; @@ -325,6 +326,13 @@ public class GroupPane extends BorderPane { HBox.setHgrow(spacer, Priority.ALWAYS); spacer.setMinWidth(Region.USE_PREF_SIZE); + FileIDSelectionModel.getInstance().getSelected().addListener((Observable o) -> { + Platform.runLater(() -> { + catSelectedSplitMenu.setDisable(FileIDSelectionModel.getInstance().getSelected().isEmpty()); + tagSelectedSplitMenu.setDisable(FileIDSelectionModel.getInstance().getSelected().isEmpty()); + }); + }); + try { tagSelectedSplitMenu.setText(controller.getTagsManager().getFollowUpTagName().getDisplayName()); } catch (TskCoreException tskCoreException) { @@ -342,18 +350,18 @@ public class GroupPane extends BorderPane { tagSelectedSplitMenu.showingProperty().addListener(showing -> { if (tagSelectedSplitMenu.isShowing()) { List selTagMenues = Lists.transform(controller.getTagsManager().getNonCategoryTagNames(), - tagName -> GuiUtils.createAutoAssigningSplitMenuItem(tagSelectedSplitMenu, new TagSelectedFilesAction(tagName, controller))); + tagName -> GuiUtils.createAutoAssigningMenuItem(tagSelectedSplitMenu, new TagSelectedFilesAction(tagName, controller))); tagSelectedSplitMenu.getItems().setAll(selTagMenues); } }); List grpCategoryMenues = Lists.transform(Arrays.asList(Category.values()), - cat -> GuiUtils.createAutoAssigningSplitMenuItem(catSelectedSplitMenu, new CategorizeSelectedFilesAction(cat, controller))); + cat -> GuiUtils.createAutoAssigningMenuItem(catSelectedSplitMenu, new CategorizeSelectedFilesAction(cat, controller))); catSelectedSplitMenu.setText(Category.FIVE.getDisplayName()); catSelectedSplitMenu.setGraphic(new ImageView(DrawableAttribute.CATEGORY.getIcon())); catSelectedSplitMenu.getItems().setAll(grpCategoryMenues); - catSelectedSplitMenu.setOnAction(GuiUtils.createAutoAssigningSplitMenuItem(catSelectedSplitMenu, new CategorizeSelectedFilesAction(Category.FIVE, controller)).getOnAction()); + catSelectedSplitMenu.setOnAction(GuiUtils.createAutoAssigningMenuItem(catSelectedSplitMenu, new CategorizeSelectedFilesAction(Category.FIVE, controller)).getOnAction()); Runnable syncMode = () -> { switch (groupViewMode.get()) { diff --git a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java index f1f621158f..6b811ea0fc 100644 --- a/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java +++ b/ImageGallery/src/org/sleuthkit/autopsy/imagegallery/gui/drawableviews/SlideShowView.java @@ -142,7 +142,7 @@ public class SlideShowView extends DrawableTileBase { try { TagName followUpTagName = getController().getTagsManager().getFollowUpTagName(); - tagSplitButton.setOnAction(GuiUtils.createAutoAssigningSplitMenuItem(tagSplitButton, new TagSelectedFilesAction(followUpTagName, getController())).getOnAction()); + tagSplitButton.setOnAction(GuiUtils.createAutoAssigningMenuItem(tagSplitButton, new TagSelectedFilesAction(followUpTagName, getController())).getOnAction()); } catch (TskCoreException ex) { LOGGER.log(Level.SEVERE, "failed to create tag menu item", ex); } @@ -151,7 +151,7 @@ public class SlideShowView extends DrawableTileBase { tagSplitButton.showingProperty().addListener(showing -> { if (tagSplitButton.isShowing()) { List selTagMenues = Lists.transform(getController().getTagsManager().getNonCategoryTagNames(), - tagName -> GuiUtils.createAutoAssigningSplitMenuItem(tagSplitButton, new TagSelectedFilesAction(tagName, getController()))); + tagName -> GuiUtils.createAutoAssigningMenuItem(tagSplitButton, new TagSelectedFilesAction(tagName, getController()))); tagSplitButton.getItems().setAll(selTagMenues); } });