use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.
the class BXMLExplorerDocument method analyseObjectTree.
@SuppressWarnings("unchecked")
private TreeNode analyseObjectTree(Object container) {
// doesn't look neat
if (container instanceof TablePane) {
TreeBranch branch = new TreeBranch(nameForObject(container));
TablePane table = (TablePane) container;
for (TablePane.Row row : table.getRows()) {
TreeNode childBranch = analyseObjectTree(row);
branch.add(childBranch);
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
// We don't want to analyse the components that are added as part of the
// skin, so use similar logic to BXMLSerializer
DefaultProperty defaultProperty = container.getClass().getAnnotation(DefaultProperty.class);
if (defaultProperty != null) {
TreeBranch branch = new TreeBranch(nameForObject(container));
String defaultPropertyName = defaultProperty.value();
BeanAdapter beanAdapter = new BeanAdapter(container);
if (!beanAdapter.containsKey(defaultPropertyName)) {
throw new IllegalStateException("default property " + defaultPropertyName + " not found on " + container);
}
Object defaultPropertyValue = beanAdapter.get(defaultPropertyName);
if (defaultPropertyValue != null) {
if (defaultPropertyValue instanceof Component) {
TreeNode childBranch = analyseObjectTree(defaultPropertyValue);
branch.add(childBranch);
}
}
// so make empty branches into nodes.
if (branch.isEmpty()) {
TreeNode node = new TreeNode(branch.getText());
setComponentIconOnTreeNode(container, node);
return node;
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
if (container instanceof Sequence<?>) {
TreeBranch branch = new TreeBranch(nameForObject(container));
Iterable<Object> sequence = (Iterable<Object>) container;
for (Object child : sequence) {
TreeNode childBranch = analyseObjectTree(child);
branch.add(childBranch);
}
setComponentIconOnTreeNode(container, branch);
return branch;
}
TreeNode node = new TreeNode(nameForObject(container));
setComponentIconOnTreeNode(container, node);
return node;
}
use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.
the class Pivot718 method controlTree.
private void controlTree(BXMLSerializer bxmlSerializer) {
treeDelButton = (PushButton) bxmlSerializer.getNamespace().get("treeDelButton");
tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
@Override
public void selectedPathAdded(TreeView treeView, Path path) {
System.out.println("selectedPathAdded");
}
@Override
public void selectedPathRemoved(TreeView treeView, Path path) {
System.out.println("selectedPathRemoved");
}
@Override
public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
System.out.println("selectedPathsChanged");
}
@Override
public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
System.out.println("selectedNodeChanged");
}
});
treeDelButton.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
TreeNode selectedNode = (TreeNode) tree.getSelectedNode();
System.out.println("delete :: " + selectedNode);
if (selectedNode != null) {
TreeBranch parent = selectedNode.getParent();
if (parent != null) {
parent.remove(selectedNode);
}
}
}
});
}
use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.
the class Pivot734 method controlTree.
private void controlTree(BXMLSerializer bxmlSerializer) {
treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
@Override
public void selectedPathAdded(TreeView treeView, Path path) {
System.out.println("selectedPathAdded");
}
@Override
public void selectedPathRemoved(TreeView treeView, Path path) {
System.out.println("selectedPathRemoved");
}
@Override
public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
System.out.println("selectedPathsChanged");
}
@Override
public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
System.out.println("selectedNodeChanged");
}
});
treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Object x = tree.getSelectedNode();
System.out.println("add a 'new branch' element to the selected element :: " + x);
if (x != null && x instanceof TreeBranch) {
((TreeBranch) x).add(newBranch);
}
}
});
treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Object x = tree.getSelectedNode();
System.out.println("remove a 'new branch' element under the selected element :: " + x);
if (x != null && x instanceof TreeBranch) {
((TreeBranch) x).remove(newBranch);
}
}
});
}
use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.
the class Pivot734WithWorkaround method controlTree.
private void controlTree(BXMLSerializer bxmlSerializer) {
treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {
@Override
public void selectedPathAdded(TreeView treeView, Path path) {
System.out.println("selectedPathAdded");
}
@Override
public void selectedPathRemoved(TreeView treeView, Path path) {
System.out.println("selectedPathRemoved");
}
@Override
public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
System.out.println("selectedPathsChanged");
}
@Override
public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
System.out.println("selectedNodeChanged");
}
});
treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Object x = tree.getSelectedNode();
System.out.println("add a 'new branch' element to the selected element :: " + x);
if (x != null && x instanceof TreeBranch) {
// workaround for PIVOT-734
Path path = tree.getSelectedPath();
tree.setBranchExpanded(path, true);
// end of workaround for PIVOT-734
((TreeBranch) x).add(newBranch);
}
}
});
treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
Object x = tree.getSelectedNode();
System.out.println("remove a 'new branch' element under the selected element :: " + x);
if (x != null && x instanceof TreeBranch) {
((TreeBranch) x).remove(newBranch);
}
}
});
}
use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.
the class JSONViewer method setValue.
private void setValue(Object value) {
assert (value instanceof Map<?, ?> || value instanceof List<?>);
// Remove prompt decorator
if (promptDecorator != null) {
treeView.getDecorators().remove(promptDecorator);
promptDecorator = null;
}
TreeBranch treeData = new TreeBranch();
treeData.add(build(value));
treeView.setTreeData(treeData);
treeView.expandBranch(new Path(0));
}
Aggregations