You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/08/30 08:28:08 UTC
svn commit: r571050 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/component/
core/src/main/java/org/apache/myfaces/tobago/model/
theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/ta...
Author: bommel
Date: Wed Aug 29 23:28:08 2007
New Revision: 571050
URL: http://svn.apache.org/viewvc?rev=571050&view=rev
Log:
(TOBAGO-471) Tree should remember scrollposition
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITreeOld.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/TreeState.java
myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java
myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITreeOld.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITreeOld.java?rev=571050&r1=571049&r2=571050&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITreeOld.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UITreeOld.java Wed Aug 29 23:28:08 2007
@@ -57,10 +57,12 @@
public static final String MESSAGE_NOT_LEAF = "tobago.tree.MESSAGE_NOT_LEAF";
public static final String SEP = "-";
-
+ // TODO should moved to renderer
+ public static final String TREE_DIV = SEP + "div";
public static final String TREE_STATE = SEP + "treeState";
public static final String SELECT_STATE = SEP + "selectState";
public static final String MARKER = SEP + "marker";
+ public static final String SCROLL_POSITION = SEP + "scrollPosition";
public static final String FACET_TREE_NODE_COMMAND = "treeNodeCommand";
public static final String PARAMETER_TREE_NODE_ID = "treeNodeId";
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/TreeState.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/TreeState.java?rev=571050&r1=571049&r2=571050&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/TreeState.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/model/TreeState.java Wed Aug 29 23:28:08 2007
@@ -18,6 +18,9 @@
*/
import javax.swing.tree.DefaultMutableTreeNode;
+
+import org.apache.commons.lang.StringUtils;
+
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
@@ -37,6 +40,7 @@
private DefaultMutableTreeNode marker;
private DefaultMutableTreeNode lastMarker;
private String lastCommand;
+ private Integer[] scrollPosition;
public TreeState() {
selection = new HashSet<DefaultMutableTreeNode>();
@@ -148,5 +152,30 @@
public void setSelection(Set<DefaultMutableTreeNode> selection) {
this.selection = selection;
}
+
+ public Integer[] getScrollPosition() {
+ return scrollPosition;
+ }
+
+ public void setScrollPosition(Integer[] scrollPosition) {
+ this.scrollPosition = scrollPosition;
+ }
+
+ public static Integer[] parseScrollPosition(String value) {
+ Integer[] position = null;
+ if (!StringUtils.isBlank(value)) {
+ int sep = value.indexOf(";");
+ if (sep == -1) {
+ throw new NumberFormatException(value);
+ }
+ int left = Integer.parseInt(value.substring(0, sep));
+ int top = Integer.parseInt(value.substring(sep + 1));
+ position = new Integer[2];
+ position[0] = left;
+ position[1] = top;
+ }
+ return position;
+ }
+
}
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java?rev=571050&r1=571049&r2=571050&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/TreeOldRenderer.java Wed Aug 29 23:28:08 2007
@@ -40,6 +40,7 @@
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
+import java.util.Map;
import java.util.StringTokenizer;
@Deprecated
@@ -75,9 +76,10 @@
if (ComponentUtil.isOutputOnly(component)) {
return;
}
-
UITreeOld tree = (UITreeOld) component;
+ String treeId = tree.getClientId(facesContext);
TreeState state = tree.getState();
+ final Map requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
if (state != null) {
if ("TreeOld".equals(tree.getRendererType())) {
@@ -89,6 +91,14 @@
if (ComponentUtil.getBooleanAttribute(tree, TobagoConstants.ATTR_MUTABLE)) {
state.setMarker(null);
}
+ // scroll position
+ String value = (String) requestParameterMap.get(treeId + UITreeOld.SCROLL_POSITION);
+ if (value != null) {
+ Integer[] scrollPosition = TreeState.parseScrollPosition(value);
+ if (scrollPosition != null) {
+ state.setScrollPosition(scrollPosition);
+ }
+ }
}
tree.setValid(true);
}
@@ -111,9 +121,12 @@
String clientId = tree.getClientId(facesContext);
UITreeOldNode root = tree.getRoot();
+ TreeState state = tree.getState();
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlConstants.DIV, tree);
+ writer.writeNameAttribute(clientId + UITreeOld.TREE_DIV);
+ writer.writeIdAttribute(clientId + UITreeOld.TREE_DIV);
writer.writeClassAttribute();
writer.writeStyleAttribute();
@@ -140,6 +153,19 @@
writer.endElement(HtmlConstants.INPUT);
}
+ writer.startElement(HtmlConstants.INPUT, tree);
+ writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
+ writer.writeNameAttribute(clientId + UITreeOld.SCROLL_POSITION);
+ writer.writeIdAttribute(clientId + UITreeOld.SCROLL_POSITION);
+ Integer[] scrollPosition = state.getScrollPosition();
+ if (scrollPosition != null) {
+ String scroll = scrollPosition[0] + ";" + scrollPosition[1];
+ writer.writeAttribute(HtmlAttributes.VALUE, scroll, false);
+ } else {
+ writer.writeAttribute(HtmlAttributes.VALUE, "", false);
+ }
+ writer.endElement(HtmlConstants.INPUT);
+
if (ComponentUtil.getBooleanAttribute(tree, TobagoConstants.ATTR_MUTABLE)) {
@@ -235,7 +261,16 @@
sb.append(".toString(0, true);\n ");
sb.append(rootNode);
- sb.append(".initSelection();\n");
+ sb.append(".initSelection();\n ");
+
+ sb.append(rootNode);
+ sb.append(".setScrollPosition();\n");
+
+ sb.append(" Tobago.addBindEventListener(Tobago.element('");
+ sb.append(clientId);
+ sb.append("-div'), 'scroll', ");
+ sb.append(rootNode);
+ sb.append(", 'doScroll');\n");
sb.append("}");
// return sb.toString();
Modified: myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js?rev=571050&r1=571049&r2=571050&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/script/tree.js Wed Aug 29 23:28:08 2007
@@ -356,6 +356,32 @@
}
}
+TreeOldNode.prototype.setScrollPosition = function() {
+ var treeDiv = Tobago.element(this.treeHiddenId + '-div');
+ if (treeDiv) {
+ var scrollHidden = Tobago.element(this.treeHiddenId + '-scrollPosition');
+ if (scrollHidden) {
+ var sep = scrollHidden.value.indexOf(";");
+ if (sep != -1) {
+ var scrollLeft = scrollHidden.value.substr(0, sep);
+ var scrollTop = scrollHidden.value.substr(sep + 1);
+ treeDiv.scrollLeft = scrollLeft;
+ treeDiv.scrollTop = scrollTop;
+ }
+ }
+ }
+}
+
+TreeOldNode.prototype.doScroll = function(event) {
+ var treeDiv = Tobago.element(this.treeHiddenId + '-div');
+ if (treeDiv) {
+ var scrollHidden = Tobago.element(this.treeHiddenId + '-scrollPosition');
+ if (scrollHidden) {
+ scrollHidden.value = treeDiv.scrollLeft + ";" + treeDiv.scrollTop;
+ }
+ }
+}
+
TreeOldNode.prototype.toString = function (depth, last) {
if (!depth) depth = 0;