use of org.apache.pivot.wtk.TreeViewNodeStateListener in project pivot by apache.
the class EventLoggerSkin method install.
@Override
public void install(Component component) {
super.install(component);
EventLogger eventLogger = (EventLogger) component;
eventLogger.getEventLoggerListeners().add(this);
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
content = (Component) bxmlSerializer.readObject(EventLoggerSkin.class, "event_logger_skin.bxml", true);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
eventLogger.add(content);
declaredEventsTreeView = (TreeView) bxmlSerializer.getNamespace().get("declaredEventsTreeView");
firedEventsTableView = (TableView) bxmlSerializer.getNamespace().get("firedEventsTableView");
// Propagate check state upwards or downwards as necessary
declaredEventsTreeView.getTreeViewNodeStateListeners().add(new TreeViewNodeStateListener() {
@Override
public void nodeCheckStateChanged(TreeView treeView, Path path, TreeView.NodeCheckState previousCheckState) {
TreeView.NodeCheckState checkState = treeView.getNodeCheckState(path);
if (!updating) {
// Set the updating flag for the life of this event loop
updating = true;
ApplicationContext.queueCallback(new Runnable() {
@Override
public void run() {
updating = false;
}
});
EventLogger eventLoggerLocal = (EventLogger) getComponent();
boolean checked = (checkState == TreeView.NodeCheckState.CHECKED);
List<?> treeData = treeView.getTreeData();
TreeNode treeNode = (TreeNode) Sequence.Tree.get(treeData, path);
if (treeNode instanceof List<?>) {
if (previousCheckState == TreeView.NodeCheckState.CHECKED || checkState == TreeView.NodeCheckState.CHECKED) {
// Propagate downward
List<?> treeBranch = (List<?>) treeNode;
Path childPath = new Path(path);
int lastIndex = childPath.getLength();
childPath.add(0);
for (int i = 0, n = treeBranch.getLength(); i < n; i++) {
childPath.update(lastIndex, i);
treeView.setNodeChecked(childPath, checked);
EventNode eventNode = (EventNode) treeBranch.get(i);
Method event = eventNode.getEvent();
if (checked) {
eventLoggerLocal.getIncludeEvents().add(event);
} else {
eventLoggerLocal.getIncludeEvents().remove(event);
}
}
}
} else {
Path parentPath = new Path(path, path.getLength() - 1);
EventNode eventNode = (EventNode) treeNode;
Method event = eventNode.getEvent();
if (checked) {
List<?> treeBranch = (List<?>) Sequence.Tree.get(treeData, parentPath);
Path childPath = new Path(path);
int lastIndex = parentPath.getLength();
int i = 0, n = treeBranch.getLength();
while (i < n) {
childPath.update(lastIndex, i);
if (!treeView.isNodeChecked(childPath)) {
break;
}
i++;
}
if (i == n) {
// Propagate upward
treeView.setNodeChecked(parentPath, checked);
}
eventLoggerLocal.getIncludeEvents().add(event);
} else {
// Propagate upward
treeView.setNodeChecked(parentPath, checked);
eventLoggerLocal.getIncludeEvents().remove(event);
}
}
}
}
});
sourceChanged(eventLogger, null);
}
Aggregations