grouped authors in breadcrumbs
authorNiki Roo <niki@nikiroo.be>
Sat, 25 Apr 2020 19:56:47 +0000 (21:56 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 25 Apr 2020 19:56:47 +0000 (21:56 +0200)
src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java
src/be/nikiroo/fanfix_swing/gui/utils/DataTreeAuthors.java
src/be/nikiroo/fanfix_swing/gui/utils/DataTreeSources.java
src/be/nikiroo/fanfix_swing/gui/utils/DataTreeTag.java

index 1e26d1533f14d3921b765a8fb66239635adfd7ff..3c4df7d83d4407ca19b304bcb067c4b443a99177 100644 (file)
@@ -46,6 +46,10 @@ public class DataNodeBook {
        }
 
        public String getPath() {
+               if (type != type.SOURCE) {
+                       return getSubnameOrName();
+               }
+
                String slash = "";
                if (!name.isEmpty()) {
                        if (children || !subname.isEmpty()) {
@@ -60,10 +64,11 @@ public class DataNodeBook {
                return name;
        }
 
-       public String getDisplay() {
-               if (display != null)
-                       return display;
+       public String getSubname() {
+               return subname;
+       }
 
+       public String getSubnameOrName() {
                if (!subname.isEmpty()) {
                        return subname;
                }
@@ -71,6 +76,13 @@ public class DataNodeBook {
                return name;
        }
 
+       public String getDisplay() {
+               if (display != null)
+                       return display;
+
+               return getSubnameOrName();
+       }
+
        public void setDisplay(String display) {
                this.display = display;
        }
index a46a49c562b2103a26fb0fcb68a5c75437b37b1e..32c6431e47807caf517ded7f543ec1a4450b7cbe 100644 (file)
@@ -10,7 +10,7 @@ import be.nikiroo.fanfix_swing.gui.book.BookInfo.Type;
 import be.nikiroo.utils.ui.DataNode;
 import be.nikiroo.utils.ui.DataTree;
 
-public class DataTreeAuthors extends DataTree<DataNodeBook> {
+public class DataTreeAuthors extends DataTreeSources {
        @Override
        protected boolean checkFilter(String filter, DataNodeBook userData) {
                return userData.toString().toLowerCase().contains(filter.toLowerCase());
@@ -18,16 +18,14 @@ public class DataTreeAuthors extends DataTree<DataNodeBook> {
 
        @Override
        protected DataNode<DataNodeBook> extractData() throws IOException {
-               List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
-
-               // TODO: getResult() -> getTagList, getAuthorList... ?
-               List<String> authors = Instance.getInstance().getLibrary().getAuthors();
-               for (String author : authors) {
-                       nodes.add(new DataNode<DataNodeBook>(null,
-                                       new DataNodeBook(Type.AUTHOR, author)));
+               Map<String, List<String>> authorsGrouped = Instance.getInstance()
+                               .getLibrary().getAuthorsGrouped();
+               
+               if (authorsGrouped.size() == 1) {
+                       List<String> authors = authorsGrouped.values().iterator().next();
+                       return getNodeFlat(authors, Type.AUTHOR);
                }
 
-               return new DataNode<DataNodeBook>(nodes,
-                               new DataNodeBook(Type.AUTHOR, !nodes.isEmpty()));
+               return getNodeGrouped(authorsGrouped, Type.AUTHOR);
        }
 }
index 188765ab61727338b12022d086413175bc9c2f78..83683379d7efd50e68dbcd52b3157307dcf106be 100644 (file)
@@ -19,11 +19,32 @@ public class DataTreeSources extends DataTree<DataNodeBook> {
 
        @Override
        protected DataNode<DataNodeBook> extractData() throws IOException {
-               List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
-
                Map<String, List<String>> sourcesGrouped = Instance.getInstance()
                                .getLibrary().getSourcesGrouped();
 
+               return getNodeGrouped(sourcesGrouped, Type.SOURCE);
+       }
+
+       protected DataNode<DataNodeBook> getNodeFlat(List<String> flatData,
+                       Type type) throws IOException {
+               List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
+
+               // TODO: getResult() -> getTagList, getAuthorList... ?
+               List<String> authors = Instance.getInstance().getLibrary().getAuthors();
+               for (String author : authors) {
+                       nodes.add(new DataNode<DataNodeBook>(null,
+                                       new DataNodeBook(type, author)));
+               }
+
+               return new DataNode<DataNodeBook>(nodes,
+                               new DataNodeBook(type, !nodes.isEmpty()));
+       }
+
+       protected DataNode<DataNodeBook> getNodeGrouped(
+                       Map<String, List<String>> sourcesGrouped, Type type)
+                       throws IOException {
+               List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
+
                List<String> sources = new ArrayList<String>(sourcesGrouped.keySet());
                sort(sources);
                for (String source : sources) {
@@ -37,7 +58,7 @@ public class DataTreeSources extends DataTree<DataNodeBook> {
                                for (String subSource : children) {
                                        boolean baseSubSource = subSource.isEmpty()
                                                        && children.size() > 1;
-                                       DataNodeBook book = new DataNodeBook(Type.SOURCE, source,
+                                       DataNodeBook book = new DataNodeBook(type, source,
                                                        subSource, false);
                                        if (baseSubSource)
                                                book.setDisplay("*");
@@ -46,10 +67,10 @@ public class DataTreeSources extends DataTree<DataNodeBook> {
                        }
 
                        nodes.add(new DataNode<DataNodeBook>(subnodes,
-                                       new DataNodeBook(Type.SOURCE, source, "", hasChildren)));
+                                       new DataNodeBook(type, source, "", hasChildren)));
                }
 
                return new DataNode<DataNodeBook>(nodes,
-                               new DataNodeBook(Type.SOURCE, !nodes.isEmpty()));
+                               new DataNodeBook(type, !nodes.isEmpty()));
        }
 }
index 445d2bf3943c2f7e8e585fe356d28927d3367c73..6e240ad090077ed34f78bd884bbe4eece2f77098 100644 (file)
@@ -3,16 +3,14 @@ package be.nikiroo.fanfix_swing.gui.utils;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.library.MetaResultList;
 import be.nikiroo.fanfix_swing.gui.book.BookInfo.Type;
 import be.nikiroo.utils.ui.DataNode;
-import be.nikiroo.utils.ui.DataTree;
 
-public class DataTreeTag extends DataTree<DataNodeBook> {
+public class DataTreeTag extends DataTreeSources {
        @Override
        protected boolean checkFilter(String filter, DataNodeBook userData) {
                return userData.toString().toLowerCase().contains(filter.toLowerCase());
@@ -20,11 +18,9 @@ public class DataTreeTag extends DataTree<DataNodeBook> {
 
        @Override
        protected DataNode<DataNodeBook> extractData() throws IOException {
-               List<DataNode<DataNodeBook>> nodes = new ArrayList<DataNode<DataNodeBook>>();
-
                List<String> tagList = new ArrayList<String>();
                MetaResultList metas = Instance.getInstance().getLibrary().getList();
-               // TODO: getTagList, getAuthorList... ?
+               // TODO: getTagList, getAuthorList... ? including grouped?
                for (MetaData meta : metas.getMetas()) {
                        List<String> tags = meta.getTags();
                        if (tags != null) {
@@ -37,12 +33,6 @@ public class DataTreeTag extends DataTree<DataNodeBook> {
                }
                sort(tagList);
 
-               for (String tag : tagList) {
-                       nodes.add(new DataNode<DataNodeBook>(null,
-                                       new DataNodeBook(Type.TAG, tag)));
-               }
-
-               return new DataNode<DataNodeBook>(nodes,
-                               new DataNodeBook(Type.TAG, !nodes.isEmpty()));
+               return getNodeFlat(tagList, Type.TAG);
        }
 }