sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: Add a "Close" menu item in the main "File" menu. It previously existed only in the contextual menu, which was non-obvious.
Date Mon, 17 Aug 2020 18:18:51 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 101eef534788f5b62053ed67c5137acb01f732f1
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Aug 17 12:16:54 2020 +0200

    Add a "Close" menu item in the main "File" menu.
    It previously existed only in the contextual menu, which was non-obvious.
---
 .../main/java/org/apache/sis/gui/DataViewer.java   | 17 +++++++++++--
 .../apache/sis/gui/dataset/ResourceExplorer.java   | 28 +++++++++++++++++++---
 .../org/apache/sis/gui/dataset/ResourceTree.java   | 15 +++++-------
 3 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
index e0e2288..c8024d0 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/DataViewer.java
@@ -45,6 +45,7 @@ import org.apache.sis.internal.storage.Capability;
 import org.apache.sis.internal.storage.StoreMetadata;
 import org.apache.sis.storage.DataStoreProvider;
 import org.apache.sis.storage.DataStores;
+import org.apache.sis.storage.DataStore;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.util.resources.Vocabulary;
 
@@ -135,13 +136,18 @@ public class DataViewer extends Application {
         final MenuBar menus = new MenuBar();
         final Menu file = new Menu(vocabulary.getString(Vocabulary.Keys.File));
         {   // For keeping variables locale.
-            final MenuItem open;
+            final MenuItem open, close;
             file.getItems().addAll(
-                    open = localized.menu(Resources.Keys.Open, (e) -> showOpenFileDialog()),
+                    open  = localized.menu(Resources.Keys.Open,  (e) -> showOpenFileDialog()),
+                    close = localized.menu(Resources.Keys.Close, (e) -> closeSelectedFile()),
                     new SeparatorMenuItem(),
                     localized.menu(Resources.Keys.Exit, (e) -> Platform.exit()));
 
             open.setAccelerator(KeyCombination.keyCombination("Shortcut+O"));
+            close.setDisable(true);
+            content.selectedResourceProperty().addListener((e,o,n) -> {
+                close.setDisable(!(n instanceof DataStore));
+            });
         }
         final Menu help = new Menu(localized.getString(Resources.Keys.Help));
         {   // For keeping variables locale.
@@ -261,6 +267,13 @@ public class DataViewer extends Application {
     }
 
     /**
+     * Closes the currently selected file.
+     */
+    private void closeSelectedFile() {
+        content.removeAndClose(content.getSelectedResource());
+    }
+
+    /**
      * Invoked when the application should stop. No SIS application can be used after
      * this method has been invoked (i.e. the application can not be restarted).
      *
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
index 4622259..bf7b835 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceExplorer.java
@@ -283,6 +283,19 @@ public class ResourceExplorer extends WindowManager {
     }
 
     /**
+     * Removes the given resource from the tree and eventually closes it.
+     * If the given resource is not in this tree explorer or can not be removed,
+     * then this method does nothing.
+     *
+     * @param  resource  the resource to remove, or {@code null}.
+     *
+     * @see ResourceTree#removeAndClose(Resource)
+     */
+    public void removeAndClose(final Resource resource) {
+        resources.removeAndClose(resource);
+    }
+
+    /**
      * Invoked in JavaFX thread when a new item is selected in the resource tree.
      * Normally, only one resource is selected since we use a single selection model.
      * We nevertheless loop over the items as a paranoiac check and take the first non-null
resource.
@@ -383,7 +396,7 @@ public class ResourceExplorer extends WindowManager {
         if (selected) {
             if (!isDataTabSet) {
                 isDataTabSet = true;                    // Must be set before to invoke `updateDataTab(…)`.
-                updateDataTab(selectedResource.get());
+                updateDataTab(getSelectedResource());
             }
             if (coverage != null) {                     // May still be null if selected
resource is not a coverage.
                 type = visual ? CoverageExplorer.View.IMAGE : CoverageExplorer.View.TABLE;
@@ -420,7 +433,7 @@ public class ResourceExplorer extends WindowManager {
      */
     @Override
     final SelectedData getSelectedData() {
-        final Resource resource = selectedResource.get();
+        final Resource resource = getSelectedResource();
         if (resource == null) {
             return null;
         }
@@ -454,11 +467,20 @@ public class ResourceExplorer extends WindowManager {
     }
 
     /**
+     * Returns the currently selected resource.
+     *
+     * @return the currently selected resource, or {@code null} if none.
+     */
+    public final Resource getSelectedResource() {
+        return selectedResource.get();
+    }
+
+    /**
      * Returns the property for currently selected resource.
      *
      * @return property for currently selected resource.
      */
-    public ReadOnlyProperty<Resource> selectedResourceProperty() {
+    public final ReadOnlyProperty<Resource> selectedResourceProperty() {
         return selectedResource.getReadOnlyProperty();
     }
 }
diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
index 7faba4f..70d1133 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/dataset/ResourceTree.java
@@ -135,7 +135,7 @@ public class ResourceTree extends TreeView<Resource> {
     /**
      * Adds a resource to this tree. If this tree is empty, then invoking this method
      * has the same effect than invoking {@link #setResource(Resource)}. Otherwise this
-     * method add the new resource below previously added resources if not already present.
+     * method adds the new resource below previously added resources if not already present.
      *
      * <p>This method updates the {@link #setRoot root} and {@link #setShowRoot showRoot}
      * properties of {@link TreeView}.</p>
@@ -257,6 +257,8 @@ public class ResourceTree extends TreeView<Resource> {
      * tree view or is not a root resource, then this method does nothing.
      *
      * @param  resource  the resource to remove, or {@code null}.
+     *
+     * @see ResourceExplorer#removeAndClose(Resource)
      */
     public void removeAndClose(final Resource resource) {
         if (findOrRemove(resource, true)) {
@@ -491,19 +493,14 @@ public class ResourceTree extends TreeView<Resource> {
                     menu = getContextMenu();
                     if (menu == null) {
                         menu = new ContextMenu();
-                        menu.getItems().add(tree.localized().menu(Resources.Keys.Close, (e)
-> close()));
+                        menu.getItems().add(tree.localized().menu(Resources.Keys.Close, (e)
-> {
+                            ((ResourceTree) getTreeView()).removeAndClose(getItem());
+                        }));
                     }
                 }
                 setContextMenu(menu);
             }
         }
-
-        /**
-         * Invoked when user selected the "close" action in the contextual menu.
-         */
-        private void close() {
-            ((ResourceTree) getTreeView()).removeAndClose(getItem());
-        }
     }
 
     /**


Mime
View raw message