From: Niki Roo Date: Mon, 27 Apr 2020 19:36:23 +0000 (+0200) Subject: fix unknown author/tag as blank X-Git-Tag: fanfix-swing-1.0.0~9 X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=c0a5f31cda05e12e5b809f71fa85879821a2e659;p=fanfix-swing.git fix unknown author/tag as blank --- diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index ac10a1a7..8f18237a 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -88,7 +88,7 @@ public class BooksPanel extends ListenerPanel { lastLoad[2] = authors; lastLoad[3] = tags; } - + new SwingWorker, Void>() { @Override protected List doInBackground() throws Exception { diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java b/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java index 3c4df7d8..26c42b34 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java @@ -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() { diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeBooks.java b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeBooks.java index ad0c5c39..adebf0d0 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeBooks.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeBooks.java @@ -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> nodes = new ArrayList>(); for (String data : flatData) { - nodes.add(new DataNode(null, - new DataNodeBook(type, data))); + DataNodeBook dnb = new DataNodeBook(type, data); + if (data == null || data.isEmpty()) { + dnb.setDisplay("[unknown]"); + } + nodes.add(new DataNode(null, dnb)); } return new DataNode(nodes, @@ -204,35 +205,49 @@ public class DataTreeBooks { } private DataNode getNodeGrouped(DataTreeSort tree, - Map> sourcesGrouped, Type type) { + Map> valuesGrouped, Type type) { List> nodes = new ArrayList>(); - List sources = new ArrayList(sourcesGrouped.keySet()); - tree.sort(sources); - for (String source : sources) { - List children = sourcesGrouped.get(source); - boolean hasChildren = (children.size() > 1) || (children.size() == 1 - && !children.get(0).trim().isEmpty()); + List values = new ArrayList(valuesGrouped.keySet()); + tree.sort(values); + for (String value : values) { + List 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> subnodes = new ArrayList>(); 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(null, book)); } } - nodes.add(new DataNode(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(subnodes, dnb)); } - return new DataNode(nodes, - new DataNodeBook(type, !nodes.isEmpty())); + DataNodeBook dnb = new DataNodeBook(type, !nodes.isEmpty()); + return new DataNode(nodes, dnb); } }