Author: sergeyhalipov
Date: 2007-06-25 08:44:28 -0400 (Mon, 25 Jun 2007)
New Revision: 1292
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
Log:
Some improvements for state advising code.
Modified:
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-06-25
12:24:52 UTC (rev 1291)
+++
trunk/richfaces/tree/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2007-06-25
12:44:28 UTC (rev 1292)
@@ -67,6 +67,8 @@
private final UITree tree;
private final TreeDataModelEventNavigator navigator;
+
+ private TreeStateAdvisor methodBindingAdvisor = null;
private DataVisitorWithLastElement(ResponseWriter writer,
StringHolder holder, Flag flag, UITree tree,
@@ -124,53 +126,55 @@
public void processAdvisors(FacesContext context, TreeRowKey rowKey) throws IOException
{
TreeState componentState = (TreeState) tree.getComponentState();
TreeStateAdvisor stateAdvisor = (TreeStateAdvisor)tree.getStateAdvisor();
- if (null != stateAdvisor) {
- Boolean adviseOpened = stateAdvisor.adviseNodeOpened(tree);
- if (null != adviseOpened) {
- if (adviseOpened.booleanValue()) {
- if (!componentState.isExpanded(rowKey)) {
- componentState.expandNode(rowKey);
+
+ if (null == stateAdvisor) {
+ if (null == methodBindingAdvisor) {
+ methodBindingAdvisor = new TreeStateAdvisor() {
+ public Boolean adviseNodeOpened(UITree tree) {
+ MethodBinding adviseNodeOpened = tree.getAdviseNodeOpened();
+ if (null != adviseNodeOpened) {
+ return (Boolean) adviseNodeOpened.invoke(FacesContext.getCurrentInstance(), new
Object[] {tree});
+ }
+ return null;
}
- }
- else {
- if (componentState.isExpanded(rowKey)) {
- componentState.collapseNode(rowKey);
+
+ public Boolean adviseNodeSelected(UITree tree) {
+ MethodBinding adviseNodeSelected = tree.getAdviseNodeSelected();
+ if (null != adviseNodeSelected) {
+ return (Boolean) adviseNodeSelected.invoke(FacesContext.getCurrentInstance(), new
Object [] {tree});
+ }
+ return null;
}
+ };
+ }
+ stateAdvisor = methodBindingAdvisor;
+ }
+
+ Boolean adviseOpened = stateAdvisor.adviseNodeOpened(tree);
+ if (null != adviseOpened) {
+ if (adviseOpened.booleanValue()) {
+ if (!componentState.isExpanded(rowKey)) {
+ componentState.expandNode(rowKey);
}
}
- Boolean adviseSelected = stateAdvisor.adviseNodeSelected(tree);
- if (null != adviseSelected) {
- if (adviseSelected.booleanValue()) {
- if (!componentState.isSelected(rowKey)) {
- componentState.setSelected(rowKey);
- }
+ else {
+ if (componentState.isExpanded(rowKey)) {
+ componentState.collapseNode(rowKey);
}
- else {
- if (componentState.isSelected(rowKey)) {
- componentState.setSelected(null);
- }
- }
}
}
- else {
- tree.setStateAdvisor(new TreeStateAdvisor() {
- public Boolean adviseNodeOpened(UITree tree) {
- MethodBinding adviseNodeOpened = tree.getAdviseNodeOpened();
- if (null != adviseNodeOpened) {
- return (Boolean) adviseNodeOpened.invoke(FacesContext.getCurrentInstance(), new
Object[] {tree});
- }
- return null;
+ Boolean adviseSelected = stateAdvisor.adviseNodeSelected(tree);
+ if (null != adviseSelected) {
+ if (adviseSelected.booleanValue()) {
+ if (!componentState.isSelected(rowKey)) {
+ componentState.setSelected(rowKey);
}
-
- public Boolean adviseNodeSelected(UITree tree) {
- MethodBinding adviseNodeSelected = tree.getAdviseNodeSelected();
- if (null != adviseNodeSelected) {
- return (Boolean) adviseNodeSelected.invoke(FacesContext.getCurrentInstance(), new
Object [] {tree});
- }
- return null;
+ }
+ else {
+ if (componentState.isSelected(rowKey)) {
+ componentState.setSelected(null);
}
- });
- processAdvisors(context, rowKey);
+ }
}
}
}
Show replies by date