X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=ui%2FDataTree.java;h=6b3657da7f0f2dbc3a73506ea26aa70b8581b4fc;hb=HEAD;hp=108476eadfc2a4384bc1724a2a0c64ddcbe7fe3f;hpb=2da37d38f809da144338309b478f3b2e3287e4f8;p=nikiroo-utils.git diff --git a/ui/DataTree.java b/ui/DataTree.java deleted file mode 100644 index 108476e..0000000 --- a/ui/DataTree.java +++ /dev/null @@ -1,68 +0,0 @@ -package be.nikiroo.utils.ui; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.MutableTreeNode; - -public abstract class DataTree { - private DataNode data; - - public DataNode loadData() throws IOException { - return this.data = extractData(); - } - - public DataNode getRoot() { - return getRoot(null); - } - - public DataNode getRoot(String filter) { - return filterNode(data, filter); - } - - protected abstract DataNode extractData() throws IOException; - - // filter cannot be null nor empty - protected abstract boolean checkFilter(String filter, E userData); - - protected boolean checkFilter(DataNode node, String filter) { - if (filter == null || filter.isEmpty()) { - return true; - } - - if (checkFilter(filter, node.getUserData())) - return true; - - for (DataNode child : node.getChildren()) { - if (checkFilter(child, filter)) - return true; - } - - return false; - } - - protected void sort(List values) { - Collections.sort(values, new Comparator() { - @Override - public int compare(String o1, String o2) { - return ("" + o1).compareToIgnoreCase("" + o2); - } - }); - } - - // note: we always send TAHT node, but filter children - private DataNode filterNode(DataNode source, String filter) { - List> children = new ArrayList>(); - for (DataNode child : source.getChildren()) { - if (checkFilter(child, filter)) { - children.add(filterNode(child, filter)); - } - } - - return new DataNode(children, source.getUserData()); - } -}