deduplicate code
authorNiki Roo <niki@nikiroo.be>
Sat, 25 Apr 2020 23:23:36 +0000 (01:23 +0200)
committerNiki Roo <niki@nikiroo.be>
Sat, 25 Apr 2020 23:23:36 +0000 (01:23 +0200)
src/be/nikiroo/fanfix_swing/gui/BreadCrumbsPanel.java
src/be/nikiroo/fanfix_swing/gui/BrowserPanel.java
src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java [deleted file]
src/be/nikiroo/fanfix_swing/gui/browser/BasicTab.java
src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java [deleted file]
src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java [deleted file]
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 cae9e0d3299fe10d7f8776275b356f25881c684a..4502e8d01d185c86d70b665e8a53aa0b35a45802 100644 (file)
@@ -23,15 +23,15 @@ public class BreadCrumbsPanel extends BreadCrumbsBar<DataNodeBook> {
                        protected DataNode<DataNodeBook> extractData() throws IOException {
                                List<? extends DataNode<DataNodeBook>> children = null;
 
-                               children = new DataTreeSources().loadData().getChildren();
+                               children = new DataTreeSources(false).loadData().getChildren();
                                DataNode<DataNodeBook> sources = new DataNode<DataNodeBook>(
                                                children, new DataNodeBook(Type.SOURCE, "Sources", true,
                                                                !children.isEmpty()));
-                               children = new DataTreeAuthors().loadData().getChildren();
+                               children = new DataTreeAuthors(false).loadData().getChildren();
                                DataNode<DataNodeBook> authors = new DataNode<DataNodeBook>(
                                                children, new DataNodeBook(Type.AUTHOR, "Authors", true,
                                                                !children.isEmpty()));
-                               children = new DataTreeTag().loadData().getChildren();
+                               children = new DataTreeTag(false).loadData().getChildren();
                                DataNode<DataNodeBook> tags = new DataNode<DataNodeBook>(
                                                children, new DataNodeBook(Type.TAG, "Tags", true,
                                                                !children.isEmpty()));
index d526e20bff9499e814a5584e7384568be12cd082..c84e946e606d3be5de56147ff44d35db22622ac0 100644 (file)
@@ -16,10 +16,10 @@ import javax.swing.event.ChangeListener;
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.library.BasicLibrary;
 import be.nikiroo.fanfix_swing.gui.book.BookInfo;
-import be.nikiroo.fanfix_swing.gui.browser.AuthorTab;
 import be.nikiroo.fanfix_swing.gui.browser.BasicTab;
-import be.nikiroo.fanfix_swing.gui.browser.SourceTab;
-import be.nikiroo.fanfix_swing.gui.browser.TagsTab;
+import be.nikiroo.fanfix_swing.gui.utils.DataTreeAuthors;
+import be.nikiroo.fanfix_swing.gui.utils.DataTreeSources;
+import be.nikiroo.fanfix_swing.gui.utils.DataTreeTag;
 import be.nikiroo.fanfix_swing.gui.utils.UiHelper;
 import be.nikiroo.utils.ui.ListenerPanel;
 
@@ -62,9 +62,9 @@ public class BrowserPanel extends ListenerPanel {
        static public final String TAB_CHANGE = "tab_change";
 
        private JTabbedPane tabs;
-       private SourceTab sourceTab;
-       private AuthorTab authorTab;
-       private TagsTab tagsTab;
+       private BasicTab sourceTab;
+       private BasicTab authorTab;
+       private BasicTab tagsTab;
 
        private boolean keepSelection;
 
@@ -78,9 +78,12 @@ public class BrowserPanel extends ListenerPanel {
                tabs = new JTabbedPane();
 
                int index = 0;
-               tabs.add(sourceTab = new SourceTab(index++, SOURCE_SELECTION));
-               tabs.add(authorTab = new AuthorTab(index++, AUTHOR_SELECTION));
-               tabs.add(tagsTab = new TagsTab(index++, TAGS_SELECTION));
+               tabs.add(sourceTab = new BasicTab(new DataTreeSources(false), index++,
+                               SOURCE_SELECTION));
+               tabs.add(authorTab = new BasicTab(new DataTreeAuthors(true), index++,
+                               AUTHOR_SELECTION));
+               tabs.add(tagsTab = new BasicTab(new DataTreeTag(true), index++,
+                               TAGS_SELECTION));
 
                configureTab(tabs, sourceTab, "Sources", "Tooltip for Sources");
                configureTab(tabs, authorTab, "Authors", "Tooltip for Authors");
@@ -120,7 +123,6 @@ public class BrowserPanel extends ListenerPanel {
                });
        }
 
-       @SuppressWarnings("rawtypes")
        private void unselect() {
                for (int i = 0; i < tabs.getTabCount(); i++) {
                        if (i == tabs.getSelectedIndex())
@@ -131,8 +133,7 @@ public class BrowserPanel extends ListenerPanel {
                }
        }
 
-       private void configureTab(JTabbedPane tabs,
-                       @SuppressWarnings("rawtypes") BasicTab tab, String name,
+       private void configureTab(JTabbedPane tabs, BasicTab tab, String name,
                        String tooltip) {
                tab.setBaseTitle(name);
                tabs.setTitleAt(tab.getIndex(), tab.getTitle());
@@ -140,8 +141,7 @@ public class BrowserPanel extends ListenerPanel {
                listenTabs(tabs, tab);
        }
 
-       private void listenTabs(final JTabbedPane tabs,
-                       @SuppressWarnings("rawtypes") final BasicTab tab) {
+       private void listenTabs(final JTabbedPane tabs, final BasicTab tab) {
                tab.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/AuthorTab.java
deleted file mode 100644 (file)
index b986e4d..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-package be.nikiroo.fanfix_swing.gui.browser;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.tree.DefaultMutableTreeNode;
-
-import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.bundles.StringIdGui;
-
-public class AuthorTab extends BasicTab<List<String>> {
-       public AuthorTab(int index, String listenerCommand) {
-               super(index, listenerCommand);
-       }
-
-       @Override
-       protected List<String> createEmptyData() {
-               return new ArrayList<String>();
-       }
-
-       @Override
-       protected void fillData(List<String> data) {
-               data.clear();
-               try {
-                       List<String> authors = Instance.getInstance().getLibrary()
-                                       .getAuthors();
-                       for (String author : authors) {
-                               data.add(author);
-                       }
-
-                       sort(data);
-               } catch (Exception e) {
-                       // TODO
-                       e.printStackTrace();
-               }
-       }
-
-       @Override
-       protected String keyToElement(String key) {
-               return key;
-       }
-
-       @Override
-       protected String keyToDisplay(String key) {
-               if (key.trim().isEmpty()) {
-                       key = Instance.getInstance().getTransGui()
-                                       .getString(StringIdGui.MENU_AUTHORS_UNKNOWN);
-               }
-
-               return key;
-       }
-
-       @Override
-       protected int loadData(DefaultMutableTreeNode root, List<String> authors,
-                       String filter) {
-               for (String author : authors) {
-                       if (checkFilter(filter, author)) {
-                               DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(
-                                               author);
-                               root.add(sourceNode);
-                       }
-               }
-
-               return authors.size();
-       }
-}
index 6edb0f3f4250695c2849639212c8f56e5bbfac4b..7e70253e4c869ff9aa6b3ff287e8650e13cb5183 100644 (file)
@@ -5,10 +5,7 @@ import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
-import java.util.Map;
 
 import javax.swing.JTree;
 import javax.swing.SwingWorker;
@@ -18,42 +15,48 @@ import javax.swing.plaf.basic.BasicTreeUI;
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.tree.DefaultTreeCellRenderer;
 import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.MutableTreeNode;
 import javax.swing.tree.TreeCellRenderer;
 import javax.swing.tree.TreePath;
 
 import be.nikiroo.fanfix_swing.gui.SearchBar;
+import be.nikiroo.fanfix_swing.gui.utils.DataNodeBook;
 import be.nikiroo.fanfix_swing.images.IconGenerator;
 import be.nikiroo.fanfix_swing.images.IconGenerator.Icon;
 import be.nikiroo.fanfix_swing.images.IconGenerator.Size;
+import be.nikiroo.utils.ui.DataNode;
+import be.nikiroo.utils.ui.DataTree;
 import be.nikiroo.utils.ui.ListenerPanel;
 import be.nikiroo.utils.ui.TreeCellSpanner;
 import be.nikiroo.utils.ui.TreeSnapshot;
 import be.nikiroo.utils.ui.UIUtils;
 
-public abstract class BasicTab<T> extends ListenerPanel {
+public class BasicTab extends ListenerPanel {
        private int totalCount = 0;
        private List<String> selectedElements = new ArrayList<String>();
-       private T data;
        private String baseTitle;
        private String listenerCommand;
        private int index;
 
        private JTree tree;
        private DefaultMutableTreeNode root;
+       private DataTree<DataNodeBook> data;
        private SearchBar searchBar;
 
-       public BasicTab(int index, String listenerCommand) {
+       public BasicTab(DataTree<DataNodeBook> data, int index,
+                       String listenerCommand) {
                setLayout(new BorderLayout());
 
+               this.data = data;
+
                this.index = index;
                this.listenerCommand = listenerCommand;
 
-               data = createEmptyData();
                totalCount = 0;
 
                root = new DefaultMutableTreeNode();
-
                tree = new JTree(root);
+
                tree.setUI(new BasicTreeUI());
                TreeCellSpanner spanner = new TreeCellSpanner(tree,
                                generateCellRenderer());
@@ -68,19 +71,19 @@ public abstract class BasicTab<T> extends ListenerPanel {
                                TreePath[] paths = tree.getSelectionPaths();
                                if (paths != null) {
                                        for (TreePath path : paths) {
-                                               String key = path.getLastPathComponent().toString();
-                                               elements.add(keyToElement(key));
-                                       }
-                               }
-
-                               List<String> selectedElements = new ArrayList<String>();
-                               for (String element : elements) {
-                                       if (!selectedElements.contains(element)) {
-                                               selectedElements.add(element);
+                                               if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) {
+                                                       DefaultMutableTreeNode node = (DefaultMutableTreeNode) path
+                                                                       .getLastPathComponent();
+                                                       if (node.getUserObject() instanceof DataNodeBook) {
+                                                               DataNodeBook book = (DataNodeBook) node
+                                                                               .getUserObject();
+                                                               elements.add(book.getPath());
+                                                       }
+                                               }
                                        }
                                }
 
-                               BasicTab.this.selectedElements = selectedElements;
+                               BasicTab.this.selectedElements = elements;
 
                                fireActionPerformed(BasicTab.this.listenerCommand);
                        }
@@ -122,11 +125,10 @@ public abstract class BasicTab<T> extends ListenerPanel {
                                return oldString.equals(newString);
                        }
                };
-               SwingWorker<Map<String, List<String>>, Integer> worker = new SwingWorker<Map<String, List<String>>, Integer>() {
+               SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
                        @Override
-                       protected Map<String, List<String>> doInBackground()
-                                       throws Exception {
-                               fillData(data);
+                       protected Void doInBackground() throws Exception {
+                               data.loadData();
                                return null;
                        }
 
@@ -134,18 +136,22 @@ public abstract class BasicTab<T> extends ListenerPanel {
                        protected void done() {
                                try {
                                        get();
-                               } catch (Exception e) {
-                                       // TODO: error
-                               }
 
-                               root.removeAllChildren();
-                               totalCount = loadData(root, data, searchBar.getText());
-                               ((DefaultTreeModel) tree.getModel()).reload();
+                                       DataNode<DataNodeBook> filtered = data
+                                                       .getRoot(searchBar.getText());
+
+                                       node2node(root, filtered);
+                                       totalCount = filtered.count() - 1; // root is counted
+
+                                       ((DefaultTreeModel) tree.getModel()).reload();
 
-                               snapshot.apply();
+                                       snapshot.apply();
 
-                               if (fireActionPerformed) {
-                                       fireActionPerformed(listenerCommand);
+                                       if (fireActionPerformed) {
+                                               fireActionPerformed(listenerCommand);
+                                       }
+                               } catch (Exception e) {
+                                       // TODO: error
                                }
                        }
                };
@@ -193,58 +199,28 @@ public abstract class BasicTab<T> extends ListenerPanel {
                tree.clearSelection();
        }
 
-       protected boolean checkFilter(String filter, String value) {
-               return (filter == null || filter.isEmpty()
-                               || value.toLowerCase().contains(filter.toLowerCase()));
-       }
-
-       protected boolean checkFilter(String filter, List<String> list) {
-               for (String value : list) {
-                       if (checkFilter(filter, value))
-                               return true;
-               }
-               return false;
-       }
-
-       protected abstract T createEmptyData();
-
-       // beware: you should update it OR clean/re-add it, but previous data may
-       // still be there
-       protected abstract void fillData(T data);
-
-       protected abstract String keyToElement(String key);
-
-       protected abstract String keyToDisplay(String key);
-
-       protected abstract int loadData(DefaultMutableTreeNode root, T data,
-                       String filter);
-
-       protected void sort(List<String> values) {
-               Collections.sort(values, new Comparator<String>() {
-                       @Override
-                       public int compare(String o1, String o2) {
-                               return ("" + o1).compareToIgnoreCase("" + o2);
-                       }
-               });
-       }
-
        private TreeCellRenderer generateCellRenderer() {
                DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
                        @Override
                        public Component getTreeCellRendererComponent(JTree tree,
                                        Object value, boolean selected, boolean expanded,
                                        boolean leaf, int row, boolean hasFocus) {
+
+                               String display = value == null ? "" : value.toString();
                                if (value instanceof DefaultMutableTreeNode) {
-                                       if (((DefaultMutableTreeNode) value).getLevel() > 1) {
+                                       DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+                                       if (node.getLevel() > 1) {
                                                setLeafIcon(null);
                                                setLeafIcon(IconGenerator.get(Icon.empty, Size.x4));
                                        } else {
                                                setLeafIcon(IconGenerator.get(Icon.empty, Size.x16));
                                        }
-                               }
 
-                               String display = value == null ? "" : value.toString();
-                               display = keyToDisplay(display);
+                                       if (node.getUserObject() instanceof DataNodeBook) {
+                                               DataNodeBook book = (DataNodeBook) node.getUserObject();
+                                               display = book.getDisplay();
+                                       }
+                               }
 
                                return super.getTreeCellRendererComponent(tree, display,
                                                selected, expanded, leaf, row, hasFocus);
@@ -257,4 +233,19 @@ public abstract class BasicTab<T> extends ListenerPanel {
 
                return renderer;
        }
+
+       private MutableTreeNode node2node(DefaultMutableTreeNode root,
+                       DataNode<DataNodeBook> node) {
+               if (root == null) {
+                       root = new DefaultMutableTreeNode(node.getUserData());
+               }
+
+               root.removeAllChildren();
+
+               for (DataNode<DataNodeBook> child : node.getChildren()) {
+                       root.add(node2node(null, child));
+               }
+
+               return root;
+       }
 }
diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/SourceTab.java
deleted file mode 100644 (file)
index a86420e..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-package be.nikiroo.fanfix_swing.gui.browser;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.swing.tree.DefaultMutableTreeNode;
-
-import be.nikiroo.fanfix.Instance;
-
-public class SourceTab extends BasicTab<Map<String, List<String>>> {
-       public SourceTab(int index, String listenerCommand) {
-               super(index, listenerCommand);
-       }
-
-       @Override
-       protected Map<String, List<String>> createEmptyData() {
-               return new HashMap<String, List<String>>();
-       }
-
-       @Override
-       protected void fillData(Map<String, List<String>> data) {
-               data.clear();
-               try {
-                       Map<String, List<String>> sourcesGrouped = Instance.getInstance()
-                                       .getLibrary().getSourcesGrouped();
-                       for (String group : sourcesGrouped.keySet()) {
-                               data.put(group, sourcesGrouped.get(group));
-                       }
-               } catch (Exception e) {
-                       // TODO
-                       e.printStackTrace();
-               }
-       }
-
-       @Override
-       protected String keyToElement(String key) {
-               return key.substring(1);
-       }
-
-       @Override
-       protected String keyToDisplay(String key) {
-               if (key.trim().isEmpty()) {
-                       return "[*]"; // Root node
-               }
-
-               // Get and remove type
-               String type = key.substring(0, 1);
-               key = key.substring(1);
-
-               if (!type.equals(">")) {
-                       // Only display the final name
-                       int pos = key.toString().lastIndexOf("/");
-                       if (pos >= 0) {
-                               key = key.toString().substring(pos + 1);
-                       }
-               }
-
-               if (key.toString().isEmpty()) {
-                       key = " ";
-               }
-
-               return key;
-       }
-
-       @Override
-       protected int loadData(DefaultMutableTreeNode root,
-                       Map<String, List<String>> sourcesGrouped, String filter) {
-               int count = 0;
-               List<String> sources = new ArrayList<String>(sourcesGrouped.keySet());
-               sort(sources);
-               for (String source : sources) {
-                       if (checkFilter(filter, source)
-                                       || checkFilter(filter, sourcesGrouped.get(source))) {
-                               List<String> children = sourcesGrouped.get(source);
-                               boolean hasChildren = (children.size() > 1)
-                                               || (children.size() == 1
-                                                               && !children.get(0).trim().isEmpty());
-                               DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(
-                                               ">" + source + (hasChildren ? "/" : ""));
-                               root.add(sourceNode);
-                               sort(children);
-                               for (String subSource : children) {
-                                       if (checkFilter(filter, source)
-                                                       || checkFilter(filter, subSource)) {
-                                               count = count + 1;
-                                               if (subSource.isEmpty()
-                                                               && sourcesGrouped.get(source).size() > 1) {
-                                                       sourceNode.add(
-                                                                       new DefaultMutableTreeNode(" " + source));
-                                               } else if (!subSource.isEmpty()) {
-                                                       sourceNode.add(new DefaultMutableTreeNode(
-                                                                       " " + source + "/" + subSource));
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               return count;
-       }
-}
diff --git a/src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java b/src/be/nikiroo/fanfix_swing/gui/browser/TagsTab.java
deleted file mode 100644 (file)
index 4224fb3..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-package be.nikiroo.fanfix_swing.gui.browser;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import javax.swing.tree.DefaultMutableTreeNode;
-
-import be.nikiroo.fanfix.Instance;
-import be.nikiroo.fanfix.bundles.StringIdGui;
-import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.fanfix.library.MetaResultList;
-
-public class TagsTab extends BasicTab<List<String>> {
-       public TagsTab(int index, String listenerCommand) {
-               super(index, listenerCommand);
-       }
-
-       @Override
-       protected List<String> createEmptyData() {
-               return new ArrayList<String>();
-       }
-
-       @Override
-       protected void fillData(List<String> data) {
-               data.clear();
-               try {
-                       MetaResultList metas = Instance.getInstance().getLibrary()
-                                       .getList();
-                       // TODO: getTagList, getAuthorList... ?
-                       for (MetaData meta : metas.getMetas()) {
-                               List<String> tags = meta.getTags();
-                               if (tags != null) {
-                                       for (String tag : tags) {
-                                               if (!data.contains(tag)) {
-                                                       data.add(tag);
-                                               }
-                                       }
-                               }
-                       }
-
-                       sort(data);
-               } catch (Exception e) {
-                       // TODO
-                       e.printStackTrace();
-               }
-       }
-
-       @Override
-       protected String keyToElement(String key) {
-               return key;
-       }
-
-       @Override
-       protected String keyToDisplay(String key) {
-               if (key.trim().isEmpty()) {
-                       // TODO: new TAG_UNKNOWN needed
-                       key = Instance.getInstance().getTransGui()
-                                       .getString(StringIdGui.MENU_AUTHORS_UNKNOWN);
-               }
-
-               return key;
-       }
-
-       @Override
-       protected int loadData(DefaultMutableTreeNode root, List<String> tags,
-                       String filter) {
-               for (String tag : tags) {
-                       if (checkFilter(filter, tag)) {
-                               DefaultMutableTreeNode sourceNode = new DefaultMutableTreeNode(
-                                               tag);
-                               root.add(sourceNode);
-                       }
-               }
-
-               return tags.size();
-       }
-}
index 32c6431e47807caf517ded7f543ec1a4450b7cbe..c6ff00f43c0b33900281bd4b6eb33a374b18714c 100644 (file)
@@ -11,6 +11,10 @@ import be.nikiroo.utils.ui.DataNode;
 import be.nikiroo.utils.ui.DataTree;
 
 public class DataTreeAuthors extends DataTreeSources {
+       public DataTreeAuthors(boolean flat) {
+               super(flat);
+       }
+
        @Override
        protected boolean checkFilter(String filter, DataNodeBook userData) {
                return userData.toString().toLowerCase().contains(filter.toLowerCase());
@@ -18,9 +22,15 @@ public class DataTreeAuthors extends DataTreeSources {
 
        @Override
        protected DataNode<DataNodeBook> extractData() throws IOException {
+               if (isFlat()) {
+                       return getNodeFlat(
+                                       Instance.getInstance().getLibrary().getList().getAuthors(),
+                                       Type.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);
index 83683379d7efd50e68dbcd52b3157307dcf106be..f4651960bba7798aa023a113920257868b187569 100644 (file)
@@ -11,17 +11,33 @@ import be.nikiroo.utils.ui.DataNode;
 import be.nikiroo.utils.ui.DataTree;
 
 public class DataTreeSources extends DataTree<DataNodeBook> {
+       private boolean flat;
+
+       public DataTreeSources(boolean flat) {
+               this.flat = flat;
+       }
+
+       protected boolean isFlat() {
+               return flat;
+       }
+
        @Override
        protected boolean checkFilter(String filter, DataNodeBook userData) {
-               // TODO
-               return userData.toString().toLowerCase().contains(filter.toLowerCase());
+               return userData.getName().toLowerCase().contains(filter.toLowerCase())
+                               || userData.getSubname().toLowerCase()
+                                               .contains(filter.toLowerCase());
        }
 
        @Override
        protected DataNode<DataNodeBook> extractData() throws IOException {
+               if (isFlat()) {
+                       return getNodeFlat(
+                                       Instance.getInstance().getLibrary().getList().getSources(),
+                                       Type.SOURCE);
+               }
+
                Map<String, List<String>> sourcesGrouped = Instance.getInstance()
                                .getLibrary().getSourcesGrouped();
-
                return getNodeGrouped(sourcesGrouped, Type.SOURCE);
        }
 
@@ -29,11 +45,9 @@ public class DataTreeSources extends DataTree<DataNodeBook> {
                        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) {
+               for (String data : flatData) {
                        nodes.add(new DataNode<DataNodeBook>(null,
-                                       new DataNodeBook(type, author)));
+                                       new DataNodeBook(type, data)));
                }
 
                return new DataNode<DataNodeBook>(nodes,
index 6e240ad090077ed34f78bd884bbe4eece2f77098..318e5fea054dc2a8173749cdb8d3a51ec8a1380e 100644 (file)
@@ -11,6 +11,10 @@ import be.nikiroo.fanfix_swing.gui.book.BookInfo.Type;
 import be.nikiroo.utils.ui.DataNode;
 
 public class DataTreeTag extends DataTreeSources {
+       public DataTreeTag(boolean flat) {
+               super(flat);
+       }
+
        @Override
        protected boolean checkFilter(String filter, DataNodeBook userData) {
                return userData.toString().toLowerCase().contains(filter.toLowerCase());
@@ -18,21 +22,8 @@ public class DataTreeTag extends DataTreeSources {
 
        @Override
        protected DataNode<DataNodeBook> extractData() throws IOException {
-               List<String> tagList = new ArrayList<String>();
-               MetaResultList metas = Instance.getInstance().getLibrary().getList();
-               // TODO: getTagList, getAuthorList... ? including grouped?
-               for (MetaData meta : metas.getMetas()) {
-                       List<String> tags = meta.getTags();
-                       if (tags != null) {
-                               for (String tag : tags) {
-                                       if (!tagList.contains(tag)) {
-                                               tagList.add(tag);
-                                       }
-                               }
-                       }
-               }
-               sort(tagList);
-
-               return getNodeFlat(tagList, Type.TAG);
+               return getNodeFlat(
+                               Instance.getInstance().getLibrary().getList().getTags(),
+                               Type.TAG);
        }
 }