com.databasesandlife.util.gwt.dropdownhierarchy.client.ExampleDropDownHierarchy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
The newest version!
package com.databasesandlife.util.gwt.dropdownhierarchy.client;
import com.databasesandlife.util.gwt.dropdownhierarchy.client.DropDownHierarchy.LeafNode;
import com.databasesandlife.util.gwt.dropdownhierarchy.client.DropDownHierarchy.Node;
import com.databasesandlife.util.gwt.dropdownhierarchy.client.DropDownHierarchy.NonLeafNode;
/**
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
public class ExampleDropDownHierarchy {
static abstract class ExampleNode implements Node {
String displayName;
ExampleNonLeafNode parent;
ExampleNode(String n) { displayName = n; }
void setParent(ExampleNonLeafNode p) { parent = p; }
public ExampleNonLeafNode getParent() { return parent; }
public String getDisplayName() { return displayName; }
}
static class ExampleLeafNode extends ExampleNode implements LeafNode {
String id;
public ExampleLeafNode(String n, String i) { super(n); id=i; }
public String getId() { return id; }
}
static class ExampleNonLeafNode extends ExampleNode implements NonLeafNode {
ExampleNode[] children;
ExampleNonLeafNode(String n, ExampleNode[] c) { super(n); children=c; }
public ExampleNode[] getChildren() { return children; }
}
public static DropDownHierarchy createExample() {
// root
// --> A (leaf)
// --> B
// --> C (leaf)
// --> D (leaf)
var c = new ExampleLeafNode("Node CC", "c");
var d = new ExampleLeafNode("Node D", "d");
var b = new ExampleNonLeafNode("Node B", new ExampleNode[] { c, d });
var a = new ExampleLeafNode("Node A", "a");
var root = new ExampleNonLeafNode("Node A", new ExampleNode[] { a, b });
d.setParent(b);
c.setParent(b);
b.setParent(root);
a.setParent(root);
try { return new DropDownHierarchy(root, "d"); }
catch (DropDownHierarchy.NodeNotFoundException e) { throw new RuntimeException(e); } // can never happen
}
}