Author: nbelaevski
Date: 2010-10-29 11:57:44 -0400 (Fri, 29 Oct 2010)
New Revision: 19783
Added:
sandbox/trunk/ui/tree-actual/ui/src/
sandbox/trunk/ui/tree-actual/ui/src/main/
sandbox/trunk/ui/tree-actual/ui/src/main/java/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDataVisitor.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/convert/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
sandbox/trunk/ui/tree-actual/ui/src/main/resources/
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/last.gif
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/leaf_icon.gif
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/line.gif
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/minus.gif
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/node_icon.gif
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/plus.gif
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss
sandbox/trunk/ui/tree-actual/ui/src/main/templates/
sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml
sandbox/trunk/ui/tree-actual/ui/src/main/templates/treeNode.template.xml
Log:
https://jira.jboss.org/browse/RF-9315
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,125 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import java.util.Iterator;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.ajax4jsf.model.DataComponentState;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.richfaces.cdk.annotations.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.convert.SequenceRowKeyConverter;
+import org.richfaces.model.TreeDataModelImpl;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(
+ type = AbstractTree.COMPONENT_TYPE,
+ family = AbstractTree.COMPONENT_FAMILY,
+ tag = @Tag(name = "tree"),
+ renderer = @JsfRenderer(type = "org.richfaces.TreeRenderer")
+)
+public abstract class AbstractTree extends UIDataAdaptor {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.Tree";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.Tree";
+
+ private static final Predicate<UIComponent> RENDERED_UITREE_NODE = new
Predicate<UIComponent>() {
+ public boolean apply(UIComponent input) {
+ return (input instanceof AbstractTreeNode) && input.isRendered();
+ };
+ };
+
+ private static final Converter ROW_KEY_CONVERTER = new SequenceRowKeyConverter();
+
+ public AbstractTree() {
+ setRendererType("org.richfaces.TreeRenderer");
+ }
+
+ public abstract Object getValue();
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+
+ @Attribute(defaultValue = "SwitchType.DEFAULT")
+ public abstract SwitchType getToggleMode();
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UIDataAdaptor#createExtendedDataModel()
+ */
+ @Override
+ protected ExtendedDataModel<?> createExtendedDataModel() {
+ TreeDataModelImpl model = new TreeDataModelImpl();
+ model.setWrappedData(getValue());
+ return model;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.component.UIDataAdaptor#createComponentState()
+ */
+ @Override
+ protected DataComponentState createComponentState() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Converter getRowKeyConverter() {
+ Converter converter = super.getRowKeyConverter();
+ if (converter == null) {
+ converter = ROW_KEY_CONVERTER;
+ }
+ return converter;
+ }
+
+ public Iterator<Object> getChildrenIterator(FacesContext faces, Object rowKey)
{
+ return ((TreeDataModelImpl) getExtendedDataModel()).getChildrenIterator(faces,
rowKey);
+ }
+
+ public AbstractTreeNode getTreeNodeComponent() {
+ if (getChildCount() == 0) {
+ return null;
+ }
+
+ Iterator<UIComponent> iterator = Iterators.filter(getChildren().iterator(),
RENDERED_UITREE_NODE);
+ if (iterator.hasNext()) {
+ return (AbstractTreeNode) iterator.next();
+ }
+
+ return null;
+ }
+
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/AbstractTreeNode.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.component.UIComponentBase;
+
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.JsfRenderer;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(
+ type = AbstractTreeNode.COMPONENT_TYPE,
+ family = AbstractTreeNode.COMPONENT_FAMILY,
+ tag = @Tag(name = "treeNode"),
+ renderer = @JsfRenderer(type = "org.richfaces.TreeNodeRenderer")
+)
+public abstract class AbstractTreeNode extends UIComponentBase {
+
+ public static final String COMPONENT_TYPE = "org.richfaces.TreeNode";
+
+ public static final String COMPONENT_FAMILY = "org.richfaces.TreeNode";
+
+ public AbstractTreeNode() {
+ setRendererType("org.richfaces.TreeNodeRenderer");
+ }
+
+ @Override
+ public String getFamily() {
+ return COMPONENT_FAMILY;
+ }
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDataVisitor.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDataVisitor.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/component/TreeDataVisitor.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.component;
+
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.model.DataVisitor;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeDataVisitor extends DataVisitor {
+
+ public void processLevelDown(FacesContext context);
+
+ public void processLevelUp(FacesContext context);
+
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/convert/SequenceRowKeyConverter.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.convert;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+import org.richfaces.model.SequenceRowKey;
+
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.base.Splitter;
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceRowKeyConverter implements Converter {
+
+ private static final Joiner DOT_JOINER = Joiner.on('.');
+
+ private static final Splitter DOT_SPLITTER = Splitter.on('.');
+
+ private static final Function<String, Integer> INTEGER_PARSER = new
Function<String, Integer>() {
+ public Integer apply(String from) {
+ return Integer.parseInt(from);
+ };
+ };
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value)
{
+ if (Strings.isNullOrEmpty(value)) {
+ return null;
+ }
+
+ Iterable<String> split = DOT_SPLITTER.split(value);
+
+ //TODO - handle another types
+ return new
SequenceRowKey<Integer>(Iterables.toArray(Iterables.transform(split,
INTEGER_PARSER), Integer.class));
+ }
+
+ public String getAsString(FacesContext context, UIComponent component, Object value)
{
+ if (value == null) {
+ return "";
+ }
+
+ SequenceRowKey<?> sequenceRowKey = (SequenceRowKey<?>) value;
+ Object[] simpleKeys=sequenceRowKey.getSimpleKeys();
+
+ return DOT_JOINER.join(simpleKeys);
+ }
+
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
===================================================================
--- sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKey.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKey.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+import com.google.common.collect.ObjectArrays;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceRowKey<T> implements Serializable {
+
+ private static final long serialVersionUID = 5605581090240141910L;
+
+ private T[] simpleKeys;
+
+ public SequenceRowKey(T... keys) {
+ super();
+ this.simpleKeys = keys;
+ }
+
+ public T[] getSimpleKeys() {
+ return simpleKeys;
+ }
+
+ public SequenceRowKey<T> append(T segment) {
+ return new SequenceRowKey<T>(ObjectArrays.concat(simpleKeys, segment));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(simpleKeys);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ SequenceRowKey<?> other = (SequenceRowKey<?>) obj;
+ if (!Arrays.equals(simpleKeys, other.simpleKeys)) {
+ return false;
+ }
+ return true;
+ }
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/SequenceRowKeyIterator.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import java.util.Iterator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class SequenceRowKeyIterator<T> implements Iterator<Object> {
+
+ private int counter = 0;
+
+ private SequenceRowKey<Integer> baseKey;
+
+ private Iterator<T> itr;
+
+ private T element;
+
+ private SequenceRowKey<Integer> elementKey;
+
+ public SequenceRowKeyIterator(SequenceRowKey<Integer> baseKey,
Iterator<T> itr) {
+ super();
+ this.baseKey = baseKey;
+ this.itr = itr;
+ }
+
+ public boolean hasNext() {
+ return itr.hasNext();
+ }
+
+ public Object next() {
+ element = itr.next();
+ elementKey = baseKey.append(counter++);
+
+ return elementKey;
+ }
+
+ public T getElement() {
+ return element;
+ }
+
+ public SequenceRowKey<Integer> getElementKey() {
+ return elementKey;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/model/TreeDataModelImpl.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,178 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.model;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.swing.tree.TreeNode;
+
+import org.ajax4jsf.model.DataVisitor;
+import org.ajax4jsf.model.ExtendedDataModel;
+import org.ajax4jsf.model.Range;
+
+import com.google.common.collect.Iterators;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class TreeDataModelImpl extends ExtendedDataModel<TreeNode> {
+
+ private static final SequenceRowKey<Integer> EMPTY_SEQUENCE_ROW_KEY = new
SequenceRowKey<Integer>();
+
+ private SwingTreeNodeImpl rootNode;
+
+ private TreeNode selectedNode;
+
+ private SequenceRowKey<Integer> selectedRowKey;
+
+ private TreeNode walkNode;
+
+ private SequenceRowKey<Integer> walkRowKey;
+
+ private void setWalkContextData(TreeNode node, SequenceRowKey<Integer> key) {
+ this.walkNode = node;
+ this.walkRowKey = key;
+ }
+
+ private Iterator<TreeNode> findChildren(SequenceRowKey<Integer>
compositeKey) {
+ TreeNode treeNode = findNode(compositeKey);
+
+ if (treeNode == null) {
+ return Iterators.emptyIterator();
+ }
+
+ return Iterators.forEnumeration((Enumeration<TreeNode>)
treeNode.children());
+ }
+
+ private TreeNode findNode(SequenceRowKey<Integer> compositeKey) {
+ if (compositeKey == null) {
+ return null;
+ }
+
+ TreeNode result = rootNode;
+
+ for (Integer simpleKey : compositeKey.getSimpleKeys()) {
+ int idx = simpleKey.intValue();
+
+ if (idx < result.getChildCount()) {
+ result = result.getChildAt(idx);
+ } else {
+ result = null;
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public void setRowKey(Object key) {
+ this.selectedRowKey = (SequenceRowKey<Integer>) key;
+
+ if (walkRowKey != null && walkRowKey.equals(key)) {
+ this.selectedNode = walkNode;
+ } else {
+ this.selectedNode = findNode(selectedRowKey);
+ }
+ }
+
+ @Override
+ public Object getRowKey() {
+ return selectedRowKey;
+ }
+
+ @Override
+ public boolean isRowAvailable() {
+ return selectedNode != null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowCount()
+ */
+ @Override
+ public int getRowCount() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public TreeNode getRowData() {
+ return selectedNode;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#getRowIndex()
+ */
+ @Override
+ public int getRowIndex() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.faces.model.DataModel#setRowIndex(int)
+ */
+ @Override
+ public void setRowIndex(int rowIndex) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Object getWrappedData() {
+ return rootNode.getChildrenList();
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ this.rootNode = new SwingTreeNodeImpl((List<TreeNode>) data);
+ }
+
+ private SequenceRowKey<Integer> castKeyAndWrapNull(Object rowKey) {
+ if (rowKey == null) {
+ return EMPTY_SEQUENCE_ROW_KEY;
+ }
+
+ return (SequenceRowKey<Integer>) rowKey;
+ }
+
+ public Iterator<Object> getChildrenIterator(FacesContext faces, Object rowKey)
{
+ SequenceRowKey<Integer> sequenceKey = castKeyAndWrapNull(rowKey);
+ Iterator<TreeNode> itr = findChildren(sequenceKey);
+
+ return new SequenceRowKeyIterator<TreeNode>(sequenceKey, itr);
+ }
+
+ /* (non-Javadoc)
+ * @see org.ajax4jsf.model.ExtendedDataModel#walk(javax.faces.context.FacesContext,
org.ajax4jsf.model.DataVisitor, org.ajax4jsf.model.Range, java.lang.Object)
+ */
+ @Override
+ public void walk(FacesContext context, DataVisitor visitor, Range range, Object
argument) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/java/org/richfaces/renderkit/TreeRendererBase.java 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,218 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.renderkit;
+
+import static org.richfaces.renderkit.util.AjaxRendererUtils.AJAX_FUNCTION_NAME;
+import static org.richfaces.renderkit.util.AjaxRendererUtils.buildAjaxFunction;
+import static org.richfaces.renderkit.util.AjaxRendererUtils.buildEventOptions;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSReference;
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.SwitchType;
+import org.richfaces.component.util.HtmlUtil;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.UnmodifiableIterator;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public abstract class TreeRendererBase extends RendererBase {
+
+ private static final Logger LOGGER = RichfacesLogger.RENDERKIT.getLogger();
+
+ private static final String NODE_ID = "nodeId";
+
+ private static final String NEW_STATE = "newState";
+
+ private static final String TOGGLE_ID_PARAM =
"org.richfaces.Tree.TOGGLE_ID";
+
+ private static final String NEW_STATE_PARAM =
"org.richfaces.Tree.NEW_STATE";
+
+ private static final class QueuedData {
+
+ private Object rowKey;
+
+ private boolean lastNode;
+
+ private boolean encoded;
+
+ public QueuedData(Object rowKey, boolean lastNode) {
+ this.rowKey = rowKey;
+ this.lastNode = lastNode;
+ }
+
+ public void setEncoded(boolean encoded) {
+ this.encoded = encoded;
+ }
+
+ public boolean isEncoded() {
+ return encoded;
+ }
+
+ public Object getRowKey() {
+ return rowKey;
+ }
+
+ public boolean isLastNode() {
+ return lastNode;
+ }
+ }
+
+ private class TreeEncoder {
+
+ private static final String TREE_NODE_HANDLE_CLASS_ATTRIBUTE =
"__treeNodeHandleClass";
+
+ private static final String TREE_NODE_ICON_CLASS_ATTRIBUTE =
"__treeNodeIconClass";
+
+ private FacesContext context;
+
+ private ResponseWriter responseWriter;
+
+ private AbstractTree tree;
+
+ private LinkedList<QueuedData> queuedData = new
LinkedList<QueuedData>();
+
+ public TreeEncoder(FacesContext context, AbstractTree tree) {
+ super();
+ this.context = context;
+ this.responseWriter = context.getResponseWriter();
+ this.tree = tree;
+ }
+
+ protected void encodeTree(Iterator<Object> childrenIterator) throws
IOException {
+ Predicate<Object> renderedTreeNodeKeyPredicate = new
Predicate<Object>() {
+ public boolean apply(Object input) {
+ tree.setRowKey(input);
+
+ if (!tree.isRowAvailable()) {
+ return false;
+ }
+
+ return tree.getTreeNodeComponent() != null;
+ }
+ };
+
+ UnmodifiableIterator<Object> filteredIterator =
Iterators.filter(childrenIterator, renderedTreeNodeKeyPredicate);
+ while (filteredIterator.hasNext()) {
+ Object rowKey = filteredIterator.next();
+
+ encodeTreeNode(rowKey, !filteredIterator.hasNext());
+ }
+ }
+
+ protected void encodeTreeNode(Object rowKey, boolean isLastNode) throws
IOException {
+ if (!queuedData.isEmpty()) {
+ QueuedData data = queuedData.getLast();
+ if (!data.isEncoded()) {
+ tree.setRowKey(context, data.getRowKey());
+
+ writeTreeNodeStartElement(data.isLastNode(), false);
+
+ data.setEncoded(true);
+ }
+ }
+
+ queuedData.add(new QueuedData(rowKey, isLastNode));
+
+ tree.setRowKey(context, rowKey);
+
+ encodeTree(tree.getChildrenIterator(context, rowKey));
+
+ QueuedData data = queuedData.removeLast();
+ if (!data.isEncoded()) {
+ writeTreeNodeStartElement(data.isLastNode(), true);
+ }
+
+ writeTreeNodeEndElement();
+ }
+
+ protected void writeTreeNodeStartElement(boolean isLast, boolean isLeaf) throws
IOException {
+ context.getAttributes().put(TREE_NODE_HANDLE_CLASS_ATTRIBUTE, isLeaf ?
"tree_handle_leaf" : "tree_handle_expanded");
+ context.getAttributes().put(TREE_NODE_ICON_CLASS_ATTRIBUTE, isLeaf ?
"tree_icon_leaf" : "tree_icon_node");
+
+ responseWriter.startElement(HtmlConstants.DIV_ELEM, tree);
+ responseWriter.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE,
+ HtmlUtil.concatClasses("tree_node", isLast ?
"tree_node_last" : null),
+ null);
+ responseWriter.writeAttribute(HtmlConstants.ID_ATTRIBUTE,
tree.getClientId(context), null);
+
+ tree.getTreeNodeComponent().encodeAll(context);
+ }
+
+ protected void writeTreeNodeEndElement() throws IOException {
+ responseWriter.endElement(HtmlConstants.DIV_ELEM);
+ }
+
+ public void encode() throws IOException {
+ Object initialRowKey = tree.getRowKey();
+ try {
+ encodeTree(tree.getChildrenIterator(context, null));
+ } finally {
+ try {
+ tree.setRowKey(context, initialRowKey);
+ } catch (Exception e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ public void encodeTree(FacesContext context, UIComponent component) throws
IOException {
+ AbstractTree tree = (AbstractTree) component;
+
+ new TreeEncoder(context, tree).encode();
+ }
+
+ protected String getAjaxToggler(FacesContext context, UIComponent component) {
+ AbstractTree tree = (AbstractTree) component;
+
+ if (!SwitchType.ajax.equals(tree.getToggleMode())) {
+ return null;
+ }
+
+ JSFunction ajaxFunction = buildAjaxFunction(context, component,
AJAX_FUNCTION_NAME);
+ AjaxEventOptions eventOptions = buildEventOptions(context, component);
+
+ eventOptions.setParameter(TOGGLE_ID_PARAM, new JSReference(NODE_ID));
+ eventOptions.setParameter(NEW_STATE_PARAM, new JSReference(NEW_STATE));
+
+ if (!eventOptions.isEmpty()) {
+ ajaxFunction.addParameter(eventOptions);
+ }
+
+ return ajaxFunction.toScript();
+ }
+}
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/last.gif
===================================================================
(Binary files differ)
Property changes on:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/last.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/leaf_icon.gif
===================================================================
(Binary files differ)
Property changes on:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/leaf_icon.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/line.gif
===================================================================
(Binary files differ)
Property changes on:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/line.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/minus.gif
===================================================================
(Binary files differ)
Property changes on:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/minus.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/node_icon.gif
===================================================================
(Binary files differ)
Property changes on:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/node_icon.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/plus.gif
===================================================================
(Binary files differ)
Property changes on:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/plus.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss
===================================================================
---
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss
(rev 0)
+++
sandbox/trunk/ui/tree-actual/ui/src/main/resources/META-INF/resources/org.richfaces/tree.ecss 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,71 @@
+.tree_item {
+ background: "url(#{resource['org.richfaces.images:last.gif']}) no-repeat
center left";
+ cursor: default;
+ font-size: '#{richSkin.generalSizeFont}';
+ font-family: '#{richSkin.generalFamilyFont}';
+ color: '#{richSkin.generalTextColor}';
+ padding: 1px 0px 1px 0px;
+ overflow: hidden;
+ width: 100%;
+ white-space: nowrap;
+}
+
+.tree_item_label {
+ padding: 0px 4px 0px 2px;
+ vertical-align: middle;
+ cursor: pointer;
+ display: inline-block;
+}
+
+.tree_selarea {
+ display: inline-block;
+}
+
+.tree_selected {
+ background: '#{richSkin.additionalBackgroundColor}';
+}
+
+.tree_node {
+ background: "url(#{resource['org.richfaces.images:line.gif']})
repeat-y";
+}
+
+.tree_node_last {
+ background: none;
+}
+
+.tree_node .tree_node {
+ margin-left: 16px;
+}
+
+.tree_icon, .tree_handle {
+ vertical-align: middle;
+ margin: 0px;
+ cursor: pointer;
+ width: 16px;
+ height: 16px;
+ display: inline-block;
+}
+
+.tree_handle_leaf {
+ cursor: default;
+}
+
+.tree_handle_collapsed {
+ background: "url(#{resource['org.richfaces.images:plus.gif']}) no-repeat
center";
+}
+
+.tree_handle_expanded {
+ background: "url(#{resource['org.richfaces.images:minus.gif']}) no-repeat
center";
+}
+
+.tree_icon_node {
+ background: "url(#{resource['org.richfaces.images:node_icon.gif']})
no-repeat center";
+}
+
+.tree_icon_leaf {
+ background: "url(#{resource['org.richfaces.images:leaf_icon.gif']})
no-repeat center";
+}
+
+.tree_node.tree_collapse .tree_node {
+ display: none;
+}
Added: sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml
===================================================================
--- sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml
(rev 0)
+++ sandbox/trunk/ui/tree-actual/ui/src/main/templates/tree.template.xml 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el"
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
+
xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core"
xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>
+
<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>
+ <cdk:component-family>org.richfaces.Tree</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
+
+ <cdk:resource-dependency name="base-component.reslib"
library="org.richfaces" />
+ <cdk:resource-dependency name="tree.js"
library="org.richfaces" />
+ <cdk:resource-dependency name="tree.ecss"
library="org.richfaces" />
+
+ <cdk:import package="org.richfaces.component"
names="SwitchType" />
+ </cc:interface>
+
+ <cc:implementation>
+ <div id="#{clientId}" class="#{concatClasses('rf-tree',
component.attributes['styleClass'])}"
+ cdk:passThroughWithExclusions="">
+ <cdk:body>
+ <cdk:call expression="encodeTree(facesContext, component)"
/>
+ </cdk:body>
+
+ <script type="text/javascript">
+ <cdk:scriptObject name="options">
+ <cdk:scriptOption attributes="toggleMode selectionMode"
defaultValue="SwitchType.DEFAULT" />
+ <cdk:scriptOption name="ajaxToggler"
value="#{getAjaxToggler(facesContext, component)}" />
+ </cdk:scriptObject>
+
+ new RichFaces.ui.Tree(#{toScriptArgs(clientId, options)});
+ </script>
+ </div>
+ </cc:implementation>
+
+</cdk:root>
Added: sandbox/trunk/ui/tree-actual/ui/src/main/templates/treeNode.template.xml
===================================================================
--- sandbox/trunk/ui/tree-actual/ui/src/main/templates/treeNode.template.xml
(rev 0)
+++ sandbox/trunk/ui/tree-actual/ui/src/main/templates/treeNode.template.xml 2010-10-29
15:57:44 UTC (rev 19783)
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://jboss.org/schema/richfaces/cdk/xhtml-el"
+
xmlns:cdk="http://jboss.org/schema/richfaces/cdk/core"
xmlns:c="http://jboss.org/schema/richfaces/cdk/jstl/core"
+
xmlns:cc="http://jboss.org/schema/richfaces/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.renderkit.html.TreeNodeRenderer
+ </cdk:class>
+ <cdk:superclass>javax.faces.render.Renderer</cdk:superclass>
+ <cdk:component-family>org.richfaces.TreeNode
+ </cdk:component-family>
+ <cdk:renderer-type>org.richfaces.TreeNodeRenderer
+ </cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ <div class="tree_item">
+ <div class="tree_handle
#{facesContext.attributes['__treeNodeHandleClass']}"></div>
+ <div class="tree_selarea">
+ <div class="tree_icon
#{facesContext.attributes['__treeNodeIconClass']}"></div>
+ <span class="tree_item_label">
+ <cdk:body />
+ </span>
+ </div>
+ </div>
+ </cc:implementation>
+
+</cdk:root>