fix unknown author/tag as blank
authorNiki Roo <niki@nikiroo.be>
Mon, 27 Apr 2020 19:36:23 +0000 (21:36 +0200)
committerNiki Roo <niki@nikiroo.be>
Mon, 27 Apr 2020 19:36:23 +0000 (21:36 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java
src/be/nikiroo/fanfix_swing/gui/utils/DataTreeBooks.java

index ac10a1a7427cd3edc74b384ea63a0d4bdb0b2712..8f18237a192ca38ac9bd8fdaae80d2c34b396d31 100644 (file)
@@ -88,7 +88,7 @@ public class BooksPanel extends ListenerPanel {
                        lastLoad[2] = authors;
                        lastLoad[3] = tags;
                }
-
+               
                new SwingWorker<List<BookInfo>, Void>() {
                        @Override
                        protected List<BookInfo> doInBackground() throws Exception {
index 3c4df7d83d4407ca19b304bcb067c4b443a99177..26c42b34ce9bf5aabbeb035dd56010cb44c7bd05 100644 (file)
@@ -46,18 +46,19 @@ public class DataNodeBook {
        }
 
        public String getPath() {
-               if (type != type.SOURCE) {
-                       return getSubnameOrName();
-               }
-
-               String slash = "";
-               if (!name.isEmpty()) {
-                       if (children || !subname.isEmpty()) {
-                               slash = "/";
+               if (type == Type.SOURCE) {
+                       // Sources are more complex
+                       String slash = "";
+                       if (!name.isEmpty()) {
+                               if (children || !subname.isEmpty()) {
+                                       slash = "/";
+                               }
                        }
+
+                       return name + slash + subname;
                }
 
-               return name + slash + subname;
+               return getSubnameOrName();
        }
 
        public String getName() {
index ad0c5c396d0f87a170acaf6cc36177ce56243d8c..adebf0d0ca54384f1acdc33ef83f8e2cf094ced2 100644 (file)
@@ -7,9 +7,7 @@ import java.util.List;
 import java.util.Map;
 
 import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix.library.MetaResultList;
-import be.nikiroo.fanfix_swing.gui.book.BookInfo;
 import be.nikiroo.fanfix_swing.gui.book.BookInfo.Type;
 import be.nikiroo.utils.ui.DataNode;
 import be.nikiroo.utils.ui.DataTree;
@@ -195,8 +193,11 @@ public class DataTreeBooks {
                List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
 
                for (String data : flatData) {
-                       nodes.add(new DataNode<DataNodeBook>(null,
-                                       new DataNodeBook(type, data)));
+                       DataNodeBook dnb = new DataNodeBook(type, data);
+                       if (data == null || data.isEmpty()) {
+                               dnb.setDisplay("[unknown]");
+                       }
+                       nodes.add(new DataNode<DataNodeBook>(null, dnb));
                }
 
                return new DataNode<DataNodeBook>(nodes,
@@ -204,35 +205,49 @@ public class DataTreeBooks {
        }
 
        private DataNode<DataNodeBook> getNodeGrouped(DataTreeSort tree,
-                       Map<String, List<String>> sourcesGrouped, Type type) {
+                       Map<String, List<String>> valuesGrouped, Type type) {
                List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
 
-               List<String> sources = new ArrayList<String>(sourcesGrouped.keySet());
-               tree.sort(sources);
-               for (String source : sources) {
-                       List<String> children = sourcesGrouped.get(source);
-                       boolean hasChildren = (children.size() > 1) || (children.size() == 1
-                                       && !children.get(0).trim().isEmpty());
+               List<String> values = new ArrayList<String>(valuesGrouped.keySet());
+               tree.sort(values);
+               for (String value : values) {
+                       List<String> children = valuesGrouped.get(value);
+
+                       boolean emptyLoneChild = children.size() == 1
+                                       && children.get(0).trim().isEmpty();
+                       boolean hasChildren = !children.isEmpty();
+
+                       // Empty, lone children are special for SOURCES
+                       if (type == Type.SOURCE && emptyLoneChild) {
+                               hasChildren = false;
+                       }
 
                        List<DataNode<DataNodeBook>> subnodes = new ArrayList<DataNode<DataNodeBook>>();
                        if (hasChildren) {
                                tree.sort(children);
-                               for (String subSource : children) {
-                                       boolean baseSubSource = subSource.isEmpty()
+                               for (String subValue : children) {
+                                       boolean baseSubValue = subValue.isEmpty()
                                                        && children.size() > 1;
-                                       DataNodeBook book = new DataNodeBook(type, source,
-                                                       subSource, false);
-                                       if (baseSubSource)
-                                               book.setDisplay("*");
+                                       DataNodeBook book = new DataNodeBook(type,
+                                                       emptyLoneChild ? "" : value, subValue, false);
+                                       if (baseSubValue)
+                                               book.setDisplay("[*]");
+                                       if (emptyLoneChild)
+                                               book.setDisplay("[unknown]");
                                        subnodes.add(new DataNode<DataNodeBook>(null, book));
                                }
                        }
 
-                       nodes.add(new DataNode<DataNodeBook>(subnodes,
-                                       new DataNodeBook(type, source, "", hasChildren)));
+                       DataNodeBook dnb = new DataNodeBook(type, value, "", hasChildren);
+                       if (type == Type.AUTHOR && "*".equals(value)) {
+                               System.out.println("we found " + value + ": "
+                                               + subnodes.get(0).getUserData().getName() + "/"
+                                               + subnodes.get(0).getUserData().getSubname());
+                       }
+                       nodes.add(new DataNode<DataNodeBook>(subnodes, dnb));
                }
 
-               return new DataNode<DataNodeBook>(nodes,
-                               new DataNodeBook(type, !nodes.isEmpty()));
+               DataNodeBook dnb = new DataNodeBook(type, !nodes.isEmpty());
+               return new DataNode<DataNodeBook>(nodes, dnb);
        }
 }