summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorArtur Signell <artur.signell@itmill.com>2010-09-20 14:07:53 +0000
committerArtur Signell <artur.signell@itmill.com>2010-09-20 14:07:53 +0000
commit7059acbad69fa65fcf355991ff9bf9649996a12f (patch)
tree822694211481f7e96b6cc424afe2c72b0acc958a /src/com
parent75cb6c4f2005a479f60ac05fd9b15f22e8d61e48 (diff)
downloadvaadin-framework-7059acbad69fa65fcf355991ff9bf9649996a12f.tar.gz
vaadin-framework-7059acbad69fa65fcf355991ff9bf9649996a12f.zip
Fix for #5443 - Tree must implement SubPartAware
svn changeset:15074/svn branch:6.4
Diffstat (limited to 'src/com')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTree.java109
1 files changed, 108 insertions, 1 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
index 07afda1df9..edf04c913b 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
@@ -54,7 +54,7 @@ import com.vaadin.terminal.gwt.client.ui.dd.VerticalDropLocation;
*/
public class VTree extends SimpleFocusablePanel implements Paintable,
VHasDropHandler, FocusHandler, BlurHandler, KeyPressHandler,
- KeyDownHandler {
+ KeyDownHandler, SubPartAware {
public static final String CLASSNAME = "v-tree";
@@ -1916,4 +1916,111 @@ public class VTree extends SimpleFocusablePanel implements Paintable,
return KeyCodes.KEY_END;
}
+ private final String SUBPART_NODE_PREFIX = "n";
+ private final String EXPAND_IDENTIFIER = "expand";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.terminal.gwt.client.ui.SubPartAware#getSubPartElement(java
+ * .lang.String)
+ */
+ public Element getSubPartElement(String subPart) {
+
+ if (subPart.startsWith(SUBPART_NODE_PREFIX + "[")) {
+ boolean expandCollapse = false;
+
+ // Node
+ String[] nodes = subPart.split("/");
+ TreeNode treeNode = null;
+ try {
+ for (String node : nodes) {
+ if (node.startsWith(SUBPART_NODE_PREFIX)) {
+
+ // skip SUBPART_NODE_PREFIX"["
+ node = node.substring(SUBPART_NODE_PREFIX.length() + 1);
+ // skip "]"
+ node = node.substring(0, node.length() - 1);
+ int position = Integer.parseInt(node);
+ if (treeNode == null) {
+ treeNode = getRootNodes().get(position);
+ } else {
+ treeNode = treeNode.getChildren().get(position);
+ }
+ } else if (node.startsWith(EXPAND_IDENTIFIER)) {
+ expandCollapse = true;
+ }
+ }
+
+ if (expandCollapse) {
+ if (treeNode.ie6compatnode != null) {
+ return treeNode.ie6compatnode;
+ } else {
+ return treeNode.getElement();
+ }
+ } else {
+ return treeNode.nodeCaptionSpan;
+ }
+ } catch (Exception e) {
+ // Invalid locator string or node could not be found
+ return null;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * com.vaadin.terminal.gwt.client.ui.SubPartAware#getSubPartName(com.google
+ * .gwt.user.client.Element)
+ */
+ public String getSubPartName(Element subElement) {
+ // Supported identifiers:
+ //
+ // n[index]/n[index]/n[index]{/expand}
+ //
+ // Ends with "/expand" if the target is expand/collapse indicator,
+ // otherwise ends with the node
+
+ boolean isExpandCollapse = false;
+
+ if (!getElement().isOrHasChild(subElement)) {
+ return null;
+ }
+
+ TreeNode treeNode = Util.findWidget(subElement, TreeNode.class);
+ if (treeNode == null) {
+ // Did not click on a node, let somebody else take care of the
+ // locator string
+ return null;
+ }
+
+ if (subElement == treeNode.getElement()
+ || subElement == treeNode.ie6compatnode) {
+ // Targets expand/collapse arrow
+ isExpandCollapse = true;
+ }
+
+ ArrayList<Integer> positions = new ArrayList<Integer>();
+ while (treeNode.getParentNode() != null) {
+ positions.add(0,
+ treeNode.getParentNode().getChildren().indexOf(treeNode));
+ treeNode = treeNode.getParentNode();
+ }
+ positions.add(0, getRootNodes().indexOf(treeNode));
+
+ String locator = "";
+ for (Integer i : positions) {
+ locator += SUBPART_NODE_PREFIX + "[" + i + "]/";
+ }
+
+ locator = locator.substring(0, locator.length() - 1);
+ if (isExpandCollapse) {
+ locator += "/" + EXPAND_IDENTIFIER;
+ }
+ return locator;
+ }
}