changeset 1514:9abf341f758f

Delete-by app dialogue split keys to two groups instead of mixing them * netx/net/sourceforge/jnlp/cache/CacheUtil.java: clearCache(String) changed to (String,bool,bool) to allow by-key access. (listCacheIds) - same. (getCacheIds) - same plus used those two booleasn to select what keys to include in filtering * netx/net/sourceforge/jnlp/controlpanel/CacheAppViewer.java: the deleteByApp dialog enhanced by TabView. Each tab holds one family of keys. * netx/net/sourceforge/jnlp/runtime/Boot.java: adapted to new signature of (CacheUtil.listCacheIds)
author Jiri Vanek <jvanek@redhat.com>
date Mon, 25 Feb 2019 13:54:27 +0100
parents d95157a2c838
children 0bec8e87f180
files ChangeLog netx/net/sourceforge/jnlp/cache/CacheUtil.java netx/net/sourceforge/jnlp/controlpanel/CacheAppViewer.java netx/net/sourceforge/jnlp/runtime/Boot.java
diffstat 4 files changed, 119 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Feb 25 13:51:00 2019 +0100
+++ b/ChangeLog	Mon Feb 25 13:54:27 2019 +0100
@@ -1,3 +1,12 @@
+2019-02-06  Jiri Vanek <jvanek@redhat.com>
+
+	Delete-by app dialogue split keys to two groups instead of mixing them
+	* netx/net/sourceforge/jnlp/cache/CacheUtil.java: clearCache(String) changed to (String,bool,bool) to allow by-key access.
+	(listCacheIds) - same. (getCacheIds) - same plus used those two booleasn to select what keys to include in filtering
+	* netx/net/sourceforge/jnlp/controlpanel/CacheAppViewer.java: the deleteByApp dialog enhanced by TabView. Each tab holds
+	one family of keys.
+	* netx/net/sourceforge/jnlp/runtime/Boot.java: adapted to new signature of (CacheUtil.listCacheIds)
+
 2019-01-15  Jiri Vanek <jvanek@redhat.com>
 
 	Relaxed vendor and title to be no longer mandatory - based on oracle javaws behavior
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java	Mon Feb 25 13:51:00 2019 +0100
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java	Mon Feb 25 13:54:27 2019 +0100
@@ -179,14 +179,14 @@
         return true;
     }
 
-    public static boolean clearCache(final String application) {
+    public static boolean clearCache(final String application, boolean jnlpPath, boolean domain) {
         // clear one app
         if (!checkToClearCache()) {
             return false;
         }
 
         OutputController.getLogger().log(OutputController.Level.WARNING_ALL, Translator.R("BXSingleCacheCleared", application));
-        List<CacheId> ids = getCacheIds(".*");
+        List<CacheId> ids = getCacheIds(".*", jnlpPath, domain);
         int found = 0;
         int files = 0;
         for (CacheId id : ids) {
@@ -289,8 +289,8 @@
 
     }
     
-     public static void listCacheIds(String filter) {
-         List<CacheId> items = getCacheIds(filter);
+     public static void listCacheIds(String filter, boolean jnlpPath, boolean domain) {
+         List<CacheId> items = getCacheIds(filter, jnlpPath, domain);
          if (JNLPRuntime.isDebug()) {
              for (CacheId id : items) {
                  OutputController.getLogger().log(OutputController.Level.MESSAGE_ALL, id.getId()+" ("+id.getType()+") ["+id.files.size()+"]");
@@ -315,11 +315,12 @@
      
      /**
       * This method load all known IDs of applications and  will gather all members, which share the id
+     * @param filter - regex to filter keys
       * @return 
       */
-      public static List<CacheId> getCacheIds(final String filter) {
+      public static List<CacheId> getCacheIds(final String filter, final boolean jnlpPath, final boolean domain) {
         CacheLRUWrapper.getInstance().lock();
-        final List<CacheId> r = new ArrayList<CacheId>();
+        final List<CacheId> r = new ArrayList<>();
         try {
             Files.walk(Paths.get(CacheLRUWrapper.getInstance().getCacheDir().getFile().getCanonicalPath())).filter(new Predicate<Path>() {
                 @Override
@@ -331,23 +332,27 @@
                 public void accept(Path path) {
                     if (path.getFileName().toString().endsWith(CacheDirectory.INFO_SUFFIX)) {
                         PropertiesFile pf = new PropertiesFile(new File(path.toString()));
-                        // if jnlp-path in .info equals path of app to delete mark to delete
-                        String jnlpPath = pf.getProperty(CacheEntry.KEY_JNLP_PATH);
-                        if (jnlpPath != null && jnlpPath.matches(filter)) {
-                            CacheId jnlpPathId = new CacheJnlpId(jnlpPath);
-                            if (!r.contains(jnlpPathId)) {
-                                r.add(jnlpPathId);
-                                jnlpPathId.populate();
+                        if (jnlpPath) {
+                            // if jnlp-path in .info equals path of app to delete mark to delete
+                            String jnlpPath = pf.getProperty(CacheEntry.KEY_JNLP_PATH);
+                            if (jnlpPath != null && jnlpPath.matches(filter)) {
+                                CacheId jnlpPathId = new CacheJnlpId(jnlpPath);
+                                if (!r.contains(jnlpPathId)) {
+                                    r.add(jnlpPathId);
+                                    jnlpPathId.populate();
 
+                                }
                             }
                         }
-                        String domain = getDomain(path);
-                        if (domain != null && domain.matches(filter)) {
-                            CacheId doaminId = new CacheDomainId(domain);
-                            if (!r.contains(doaminId)) {
-                                r.add(doaminId);
-                                doaminId.populate();
+                        if (domain) {
+                            String domain = getDomain(path);
+                            if (domain != null && domain.matches(filter)) {
+                                CacheId doaminId = new CacheDomainId(domain);
+                                if (!r.contains(doaminId)) {
+                                    r.add(doaminId);
+                                    doaminId.populate();
 
+                                }
                             }
                         }
                     }
--- a/netx/net/sourceforge/jnlp/controlpanel/CacheAppViewer.java	Mon Feb 25 13:51:00 2019 +0100
+++ b/netx/net/sourceforge/jnlp/controlpanel/CacheAppViewer.java	Mon Feb 25 13:54:27 2019 +0100
@@ -31,9 +31,12 @@
 import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
 import javax.swing.JTextArea;
 import javax.swing.ListModel;
 import javax.swing.ListSelectionModel;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 import javax.swing.event.ListDataListener;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
@@ -80,9 +83,22 @@
         parentPane.setLayout(new BorderLayout());
         mainPane.setLayout(new GridLayout(2, 1));
         parentPane.add(mainPane);
-        final JList<CacheUtil.CacheId> apps = new JList<>();
-        apps.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        final JTextArea info = new JTextArea();
+        info.setEditable(false);
+        final JTabbedPane idTabs = new JTabbedPane();
+        final JPanel jnlpPaths = new JPanel(new BorderLayout());
+        jnlpPaths.setName("jnlp-path");
+        final JPanel domains = new JPanel(new BorderLayout());
+        domains.setName("domain");
+        idTabs.add(jnlpPaths);
+        idTabs.add(domains);
         final JButton delete = new JButton(Translator.R("TIFPDeleteFiles"));
+        DummyCacheIdListModel jnlpPathsIds = new DummyCacheIdListModel(CacheUtil.getCacheIds(".*", true, false));
+        DummyCacheIdListModel domainIds = new DummyCacheIdListModel(CacheUtil.getCacheIds(".*", false, true));
+        final JList<CacheUtil.CacheId> appsByJnlpPath = new JList<>();
+        final JList<CacheUtil.CacheId> appsByDomain = new JList<>();
+        appsByJnlpPath.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        appsByDomain.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
         delete.setEnabled(false);
         delete.addActionListener(new ActionListener() {
             @Override
@@ -91,7 +107,12 @@
                 SwingUtils.invokeLater(new Runnable() {
                     @Override
                     public void run() {
-                        CacheUtil.clearCache(apps.getSelectedValue().getId());
+                        if (idTabs.getSelectedComponent()==jnlpPaths){
+                            CacheUtil.clearCache(appsByJnlpPath.getSelectedValue().getId(), true, false);
+                        }
+                        if (idTabs.getSelectedComponent()==domains){
+                            CacheUtil.clearCache(appsByDomain.getSelectedValue().getId(), false, true);
+                        }
                         CacheAppViewer.this.getContentPane().removeAll();
                         CacheAppViewer.this.pack();
                         create();
@@ -100,33 +121,42 @@
                 });
             }
         });
-        final List<CacheUtil.CacheId> content = CacheUtil.getCacheIds(".*");
-        ListModel<CacheUtil.CacheId> m = new ListModel<CacheUtil.CacheId>() {
-            @Override
-            public int getSize() {
-                return content.size();
-            }
-
-            @Override
-            public CacheUtil.CacheId getElementAt(int index) {
-                return content.get(index);
-            }
-
+        appsByJnlpPath.setModel(jnlpPathsIds);
+        appsByDomain.setModel(domainIds);
+        appsByJnlpPath.addListSelectionListener(new DummyListSelectionListenerWithModel(info, appsByJnlpPath, delete));
+        appsByDomain.addListSelectionListener(new DummyListSelectionListenerWithModel(info, appsByDomain, delete));
+        jnlpPaths.add(mainPane.add(new JScrollPane(appsByJnlpPath)));
+        domains.add(mainPane.add(new JScrollPane(appsByDomain)));
+        mainPane.add(idTabs);
+        idTabs.addChangeListener(new ChangeListener() {
             @Override
-            public void addListDataListener(ListDataListener l) {
-
+            public void stateChanged(ChangeEvent e) {
+                appsByDomain.clearSelection();
+                appsByJnlpPath.clearSelection();
             }
+        });
+        mainPane.add(new JScrollPane(info));
+        parentPane.add(delete, BorderLayout.SOUTH);
+        pack();
 
-            @Override
-            public void removeListDataListener(ListDataListener l) {
+    }
 
-            }
+    public void centerDialog() {
+        ScreenFinder.centerWindowsToCurrentScreen(this);
+    }
+    
+    private static class DummyListSelectionListenerWithModel implements ListSelectionListener {
 
-        };
-        apps.setModel(m);
-        final JTextArea info = new JTextArea();
-        info.setEditable(false);
-        apps.addListSelectionListener(new ListSelectionListener() {
+        private final JTextArea info;
+        private final JList<CacheUtil.CacheId> apps;
+        private final JButton delete;
+
+        public DummyListSelectionListenerWithModel(JTextArea info, JList<CacheUtil.CacheId> apps, JButton delete) {
+            this.info = info;
+            this.apps = apps;
+            this.delete = delete;
+        }
+        
             @Override
             public void valueChanged(ListSelectionEvent e) {
                 info.setText("");
@@ -149,15 +179,34 @@
                     delete.setText(Translator.R("TIFPDeleteFiles"));
                 }
             }
-        });
-        mainPane.add(new JScrollPane(apps));
-        mainPane.add(new JScrollPane(info));
-        parentPane.add(delete, BorderLayout.SOUTH);
-        pack();
+        }
+    
+    private static class DummyCacheIdListModel implements ListModel<CacheUtil.CacheId> {
+        
+        List<CacheUtil.CacheId> content;
+        public DummyCacheIdListModel(List<CacheUtil.CacheId> content){
+            this.content = content;
+        }
+            @Override
+            public int getSize() {
+                return content.size();
+            }
 
-    }
+            @Override
+            public CacheUtil.CacheId getElementAt(int index) {
+                return content.get(index);
+            }
+
+            @Override
+            public void addListDataListener(ListDataListener l) {
 
-    public void centerDialog() {
-        ScreenFinder.centerWindowsToCurrentScreen(this);
-    }
+            }
+
+            @Override
+            public void removeListDataListener(ListDataListener l) {
+
+            }
+
+        };
 }
+
--- a/netx/net/sourceforge/jnlp/runtime/Boot.java	Mon Feb 25 13:51:00 2019 +0100
+++ b/netx/net/sourceforge/jnlp/runtime/Boot.java	Mon Feb 25 13:54:27 2019 +0100
@@ -352,10 +352,10 @@
             List<String> optionArgs = optionParser.getMainArgs();
             if (optionArgs.size() > 0) {
                 //clear one app 
-                CacheUtil.listCacheIds(optionArgs.get(0));
+                CacheUtil.listCacheIds(optionArgs.get(0), true, true);
             } else {
                 // clear all cache
-                CacheUtil.listCacheIds(".*");
+                CacheUtil.listCacheIds(".*", true, true);
             }
             return null;
         }
@@ -370,7 +370,7 @@
             List<String> optionArgs = optionParser.getMainArgs();
             if (optionArgs.size() > 0) {
                 //clear one app 
-                CacheUtil.clearCache(optionArgs.get(0));
+                CacheUtil.clearCache(optionArgs.get(0), true, true);
             } else {
                 // clear all cache
                 CacheUtil.clearCache();