}
public String getPath() {
+ if (type != type.SOURCE) {
+ return getSubnameOrName();
+ }
+
String slash = "";
if (!name.isEmpty()) {
if (children || !subname.isEmpty()) {
return name;
}
- public String getDisplay() {
- if (display != null)
- return display;
+ public String getSubname() {
+ return subname;
+ }
+ public String getSubnameOrName() {
if (!subname.isEmpty()) {
return subname;
}
return name;
}
+ public String getDisplay() {
+ if (display != null)
+ return display;
+
+ return getSubnameOrName();
+ }
+
public void setDisplay(String display) {
this.display = display;
}
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());
@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);
}
}
@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) {
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("*");
}
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()));
}
}
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());
@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) {
}
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);
}
}