From: Niki Roo Date: Sat, 25 Apr 2020 19:56:47 +0000 (+0200) Subject: grouped authors in breadcrumbs X-Git-Tag: fanfix-swing-1.0.0~28 X-Git-Url: http://git.nikiroo.be/?a=commitdiff_plain;h=2a6662e75884e39c46ba133843d74676b986170c;p=fanfix-swing.git grouped authors in breadcrumbs --- diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java b/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java index 1e26d153..3c4df7d8 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/DataNodeBook.java @@ -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; } diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeAuthors.java b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeAuthors.java index a46a49c5..32c6431e 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeAuthors.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeAuthors.java @@ -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 { +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 { @Override protected DataNode extractData() throws IOException { - List> nodes = new ArrayList>(); - - // TODO: getResult() -> getTagList, getAuthorList... ? - List authors = Instance.getInstance().getLibrary().getAuthors(); - for (String author : authors) { - nodes.add(new DataNode(null, - new DataNodeBook(Type.AUTHOR, author))); + Map> authorsGrouped = Instance.getInstance() + .getLibrary().getAuthorsGrouped(); + + if (authorsGrouped.size() == 1) { + List authors = authorsGrouped.values().iterator().next(); + return getNodeFlat(authors, Type.AUTHOR); } - return new DataNode(nodes, - new DataNodeBook(Type.AUTHOR, !nodes.isEmpty())); + return getNodeGrouped(authorsGrouped, Type.AUTHOR); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeSources.java b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeSources.java index 188765ab..83683379 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeSources.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeSources.java @@ -19,11 +19,32 @@ public class DataTreeSources extends DataTree { @Override protected DataNode extractData() throws IOException { - List> nodes = new ArrayList>(); - Map> sourcesGrouped = Instance.getInstance() .getLibrary().getSourcesGrouped(); + return getNodeGrouped(sourcesGrouped, Type.SOURCE); + } + + protected DataNode getNodeFlat(List flatData, + Type type) throws IOException { + List> nodes = new ArrayList>(); + + // TODO: getResult() -> getTagList, getAuthorList... ? + List authors = Instance.getInstance().getLibrary().getAuthors(); + for (String author : authors) { + nodes.add(new DataNode(null, + new DataNodeBook(type, author))); + } + + return new DataNode(nodes, + new DataNodeBook(type, !nodes.isEmpty())); + } + + protected DataNode getNodeGrouped( + Map> sourcesGrouped, Type type) + throws IOException { + List> nodes = new ArrayList>(); + List sources = new ArrayList(sourcesGrouped.keySet()); sort(sources); for (String source : sources) { @@ -37,7 +58,7 @@ public class DataTreeSources extends DataTree { 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 { } nodes.add(new DataNode(subnodes, - new DataNodeBook(Type.SOURCE, source, "", hasChildren))); + new DataNodeBook(type, source, "", hasChildren))); } return new DataNode(nodes, - new DataNodeBook(Type.SOURCE, !nodes.isEmpty())); + new DataNodeBook(type, !nodes.isEmpty())); } } diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeTag.java b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeTag.java index 445d2bf3..6e240ad0 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeTag.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/DataTreeTag.java @@ -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 { +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 { @Override protected DataNode extractData() throws IOException { - List> nodes = new ArrayList>(); - List tagList = new ArrayList(); MetaResultList metas = Instance.getInstance().getLibrary().getList(); - // TODO: getTagList, getAuthorList... ? + // TODO: getTagList, getAuthorList... ? including grouped? for (MetaData meta : metas.getMetas()) { List tags = meta.getTags(); if (tags != null) { @@ -37,12 +33,6 @@ public class DataTreeTag extends DataTree { } sort(tagList); - for (String tag : tagList) { - nodes.add(new DataNode(null, - new DataNodeBook(Type.TAG, tag))); - } - - return new DataNode(nodes, - new DataNodeBook(Type.TAG, !nodes.isEmpty())); + return getNodeFlat(tagList, Type.TAG); } }