Author: nbelaevski
Date: 2010-11-29 15:44:15 -0500 (Mon, 29 Nov 2010)
New Revision: 20215
Added:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveEntry.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveFile.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Class.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Directory.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Entry.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/File.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Package.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Project.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Root.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SimpleRecursiveNode.java
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SourceDirectory.java
trunk/examples/iteration-demo/src/main/resources/org/richfaces/demo/model/
trunk/examples/iteration-demo/src/main/resources/org/richfaces/demo/model/tree/
trunk/examples/iteration-demo/src/main/resources/org/richfaces/demo/model/tree/tree-model-data.xml
trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
Modified:
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java
trunk/core/api/src/main/java/org/richfaces/log/RichfacesLogger.java
trunk/examples/iteration-demo/src/main/webapp/index.xhtml
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
Log:
RF-9680
Modified: trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java
===================================================================
---
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java 2010-11-29
20:36:39 UTC (rev 20214)
+++
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -31,6 +31,21 @@
*/
public final class ComponentPredicates {
+ private static final class WithIdPredicate implements Predicate<UIComponent> {
+
+ private final String id;
+
+ public WithIdPredicate(String id) {
+ super();
+ this.id = id;
+ }
+
+ public boolean apply(UIComponent input) {
+ return id.equals(input.getId());
+ }
+
+ }
+
private static final Predicate<UIComponent> IS_RENDERED = new
Predicate<UIComponent>() {
public boolean apply(UIComponent input) {
return input.isRendered();
@@ -42,4 +57,12 @@
public static Predicate<UIComponent> isRendered() {
return IS_RENDERED;
}
+
+ public static Predicate<UIComponent> withId(String id) {
+ if (id == null) {
+ throw new NullPointerException("id");
+ }
+
+ return new WithIdPredicate(id);
+ }
}
Modified: trunk/core/api/src/main/java/org/richfaces/log/RichfacesLogger.java
===================================================================
--- trunk/core/api/src/main/java/org/richfaces/log/RichfacesLogger.java 2010-11-29
20:36:39 UTC (rev 20214)
+++ trunk/core/api/src/main/java/org/richfaces/log/RichfacesLogger.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -8,9 +8,9 @@
*
*/
public enum RichfacesLogger {
- RESOURCE("Resource"), RENDERKIT("Renderkit"),
CONFIG("Config"), CONNECTION("Connection"),
- APPLICATION("Application"),
- CACHE("Cache"), CONTEXT("Context"),
COMPONENTS("Components"), WEBAPP("Webapp"), UTIL("Util");
+ RESOURCE("Resource"), RENDERKIT("Renderkit"),
CONFIG("Config"), CONNECTION("Connection"),
+ APPLICATION("Application"), CACHE("Cache"),
CONTEXT("Context"), COMPONENTS("Components"),
+ WEBAPP("Webapp"), UTIL("Util"), MODEL("Model");
private static final String LOGGER_NAME_PREFIX = "org.richfaces.log.";
private String loggerName;
Added:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/TreeModelBean.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,36 @@
+/**
+ *
+ */
+package org.richfaces.demo.model.tree;
+
+import javax.faces.bean.ApplicationScoped;
+import javax.faces.bean.ManagedBean;
+import javax.xml.bind.JAXB;
+
+import org.richfaces.demo.model.tree.adaptors.Root;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 25.07.2007
+ *
+ */
+@ManagedBean
+@ApplicationScoped
+public class TreeModelBean {
+
+ private Root root;
+
+ private void initializeRoot() {
+ root =
JAXB.unmarshal(TreeModelBean.class.getResource("tree-model-data.xml"),
Root.class);
+ }
+
+ public Root getRoot() {
+ if (root == null) {
+ initializeRoot();
+ }
+
+ return root;
+ }
+
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveEntry.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveEntry.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveEntry.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 04.08.2007
+ *
+ */
+public class ArchiveEntry extends Entry {
+
+ @XmlElement(name = "archiveEntry")
+ private List<ArchiveEntry> archiveEntries;
+
+ @XmlElement(name = "archiveEntryFile")
+ private List<ArchiveEntry> archiveEntryFiles;
+
+ public List<ArchiveEntry> getArchiveEntries() {
+ return archiveEntries;
+ }
+
+ public List<ArchiveEntry> getArchiveEntryFiles() {
+ return archiveEntryFiles;
+ }
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveFile.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveFile.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/ArchiveFile.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 04.08.2007
+ *
+ */
+public class ArchiveFile extends File {
+
+ @XmlElement(name = "archiveEntry")
+ private List<ArchiveEntry> archiveEntries = Lists.newArrayList();
+
+ public List<ArchiveEntry> getArchiveEntries() {
+ return archiveEntries;
+ }
+
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Class.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Class.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Class.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+
+/**
+ * @author Nick Belaevski
+ */
+public class Class extends Entry {
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Directory.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Directory.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Directory.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 24.07.2007
+ *
+ */
+public class Directory extends Entry {
+
+ @XmlElement(name = "directory")
+ private List<Directory> directories;
+
+ @XmlElement(name = "file")
+ private List<File> files;
+
+ @XmlElement(name = "archive")
+ private List<ArchiveFile> archiveFiles;
+
+ public List<Directory> getDirectories() {
+ return directories;
+ }
+
+ public List<File> getFiles() {
+ return files;
+ }
+
+ public List<ArchiveFile> getArchiveFiles() {
+ return archiveFiles;
+ }
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Entry.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Entry.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Entry.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 29.07.2007
+ *
+ */
+(a)XmlAccessorType(XmlAccessType.FIELD)
+public abstract class Entry {
+
+ @XmlAttribute
+ private String name;
+
+ public String toString() {
+ return this.getClass().getSimpleName() + "[" + name + "]";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void click() {
+ }
+
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/File.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/File.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/File.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,32 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 25.07.2007
+ *
+ */
+public class File extends Entry {
+
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Package.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Package.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Package.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * @author Nick Belaevski mailto:nbelaevski@exadel.com created 25.07.2007
+ *
+ */
+public class Package extends Entry {
+
+ @XmlElement(name = "class")
+ private List<Class> classes;
+
+ public List<Class> getClasses() {
+ return classes;
+ }
+
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Project.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Project.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Project.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 24.07.2007
+ *
+ */
+public class Project extends Entry {
+
+ @XmlElement(name = "sourceDirectory")
+ private List<SourceDirectory> sourceDirectories;
+
+ @XmlElement(name = "directory")
+ private List<Directory> commonDirectories;
+
+ public List<SourceDirectory> getSourceDirectories() {
+ return sourceDirectories;
+ }
+
+ public List<Directory> getCommonDirectories() {
+ return commonDirectories;
+ }
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Root.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Root.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/Root.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,43 @@
+/*
+ * 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "root")
+public class Root {
+
+ @XmlElement(name = "project")
+ private List<Project> projects;
+
+ public List<Project> getProjects() {
+ return projects;
+ }
+
+}
Added:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SimpleRecursiveNode.java
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SimpleRecursiveNode.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SimpleRecursiveNode.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.2
+ */
+
+public class SimpleRecursiveNode {
+
+ private SimpleRecursiveNode parent;
+
+ private List<SimpleRecursiveNode> children = Lists.newArrayList();
+
+ private String text;
+
+ public SimpleRecursiveNode(SimpleRecursiveNode parent, String text) {
+ super();
+ this.parent = parent;
+ if (parent != null) {
+ parent.addChild(this);
+ }
+ this.text = text;
+ }
+
+ public void addChild(SimpleRecursiveNode node) {
+ children.add(node);
+ }
+
+ public void removeChild(SimpleRecursiveNode node) {
+ children.remove(node);
+ }
+
+ public void remove() {
+ if (parent != null) {
+ parent.removeChild(this);
+ }
+ }
+
+ public SimpleRecursiveNode getParent() {
+ return parent;
+ }
+
+ public List<SimpleRecursiveNode> getChildren() {
+ return children;
+ }
+
+ public String getText() {
+ return text;
+ }
+}
Copied:
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SourceDirectory.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SourceDirectory.java
(rev 0)
+++
trunk/examples/iteration-demo/src/main/java/org/richfaces/demo/model/tree/adaptors/SourceDirectory.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, 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.demo.model.tree.adaptors;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * @author Nick Belaevski
+ * mailto:nbelaevski@exadel.com
+ * created 24.07.2007
+ *
+ */
+public class SourceDirectory extends Entry {
+
+ @XmlElement(name = "package")
+ private List<Package> packages;
+
+ public List<Package> getPackages() {
+ return packages;
+ }
+
+}
Added:
trunk/examples/iteration-demo/src/main/resources/org/richfaces/demo/model/tree/tree-model-data.xml
===================================================================
---
trunk/examples/iteration-demo/src/main/resources/org/richfaces/demo/model/tree/tree-model-data.xml
(rev 0)
+++
trunk/examples/iteration-demo/src/main/resources/org/richfaces/demo/model/tree/tree-model-data.xml 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+ <!-- project name="ajax4jsf">
+ <sourceDirectory name="src/main/java">
+ <package name="org.ajax4jsf">
+ <class name="FastFilter.java" />
+ <class name="Filter.java" />
+ </package>
+ <package name="org.ajax4jsf.component">
+ <class name="UIDataAdaptor.java" />
+ <class name="AjaxActionComponent.java" />
+ </package>
+ <package name="org.ajax4jsf.renderkit">
+ <class name="AjaxChildrenRenderer.java" />
+ <class name="AjaxComponentRendererBase.java" />
+ </package>
+ </sourceDirectory>
+ <sourceDirectory name="src/main/resources">
+ <package name="org.ajax4jsf">
+ </package>
+ <package name="org.ajax4jsf.javascript">
+ </package>
+ </sourceDirectory>
+ </project -->
+
+ <project name="richfaces">
+ <!-- sourceDirectory name="src/main/java">
+ <package name="org.richfaces">
+ </package>
+ <package name="org.richfaces.component">
+ </package>
+ <package name="org.richfaces.model">
+ </package>
+ </sourceDirectory>
+ <sourceDirectory name="src/main/resources">
+ <package name="org.richfaces">
+ </package>
+ <package name="org.richfaces.renderkit">
+ </package>
+ </sourceDirectory>
+ <sourceDirectory name="target/generated/java">
+ <package name="org.richfaces">
+ </package>
+ <package name="org.richfaces.component">
+ </package>
+ <package name="org.richfaces.renderkit">
+ </package>
+ </sourceDirectory>
+ <directory name="design">
+ <directory name="funcspec">
+ <file name="FunctionalSpecification-1.0.doc" />
+ <file name="Requirements-1.0.doc" />
+ </directory>
+ </directory -->
+ <directory name="src">
+ <directory name="main">
+ <directory name="config">
+ <directory name="org">
+ <directory name="richfaces">
+ <directory name="component">
+ <file name="tree.config.xml" />
+ <file name="treeNode.config.xml" />
+ </directory>
+ </directory>
+ </directory>
+ </directory>
+ <directory name="templates"></directory>
+ </directory>
+ <directory name="test"></directory>
+ </directory>
+ <directory name="target">
+ <directory name="generated-component">
+ </directory>
+ <directory name="surefire-reports">
+ <file name="org.richfaces.JSFComponentTest.txt" />
+ <file name="TEST-ComponentTest.xml" />
+ </directory>
+ <file name="richfaces-3.1.0-snapshot" />
+ <file name="richfaces-3.1.0-javadoc" />
+ <archive name="richfaces-3.1.0-sources">
+ <archiveEntry name="org">
+ <archiveEntry name="richfaces">
+ <archiveEntry name="component">
+ <archiveEntryFile name="UITree" />
+ <archiveEntryFile name="UITreeNode" />
+ <archiveEntryFile name="UICalendar" />
+ <archiveEntryFile name="UIRangedNumberInput" />
+ </archiveEntry>
+ </archiveEntry>
+ </archiveEntry>
+ </archive>
+ </directory>
+ </project>
+</root>
\ No newline at end of file
Modified: trunk/examples/iteration-demo/src/main/webapp/index.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/index.xhtml 2010-11-29 20:36:39 UTC (rev
20214)
+++ trunk/examples/iteration-demo/src/main/webapp/index.xhtml 2010-11-29 20:44:15 UTC (rev
20215)
@@ -14,6 +14,7 @@
<li><h:link outcome="filteringAndSorting">filtering and sorting
feature</h:link></li>
<li><h:link outcome="list">rich:list</h:link></li>
<li><h:link outcome="tree">rich:tree</h:link></li>
+ <li><h:link outcome="treeModel">rich:treeModelAdaptor and
rich:treeModelRecursiveAdaptor</h:link></li>
</ul>
Added: trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml
===================================================================
--- trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml
(rev 0)
+++ trunk/examples/iteration-demo/src/main/webapp/treeModel.xhtml 2010-11-29 20:44:15 UTC
(rev 20215)
@@ -0,0 +1,37 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:it="http://richfaces.org/iteration"
+
xmlns:a4j="http://richfaces.org/a4j">
+<f:view contentType="text/html" />
+
+<h:head>
+ <title>Richfaces Tree Models</title>
+</h:head>
+
+<h:body>
+ <h:messages id="messages" />
+
+ <h:form id="form">
+ <it:tree id="tree" var="node" toggleType="ajax">
+ <it:treeModelAdaptor nodes="#{treeModelBean.root.projects}">
+ <it:treeModelAdaptor nodes="#{node.sourceDirectories}">
+ <it:treeModelAdaptor nodes="#{node.packages}">
+ <it:treeModelAdaptor nodes="#{node.classes}" />
+ </it:treeModelAdaptor>
+ </it:treeModelAdaptor>
+
+ <it:treeModelRecursiveAdaptor roots="#{node.commonDirectories}"
nodes="#{node.directories}">
+ <it:treeModelRecursiveAdaptor roots="#{node.archiveFiles}"
nodes="#{node.archiveEntries}">
+ <it:treeModelAdaptor rendered="#{node.class.simpleName eq
'ArchiveEntry'}"
+ nodes="#{node.archiveEntryFiles}" />
+ </it:treeModelRecursiveAdaptor>
+ <it:treeModelAdaptor nodes="#{node.files}" />
+ </it:treeModelRecursiveAdaptor>
+ </it:treeModelAdaptor>
+ </it:tree>
+ </h:form>
+</h:body>
+</html>
Modified: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-29
20:36:39 UTC (rev 20214)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTree.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -68,6 +68,7 @@
import org.richfaces.event.TreeToggleEvent;
import org.richfaces.event.TreeToggleListener;
import org.richfaces.event.TreeToggleSource;
+import org.richfaces.model.DeclarativeTreeDataModelImpl;
import org.richfaces.model.SwingTreeNodeDataModelImpl;
import org.richfaces.model.TreeDataModel;
import org.richfaces.model.TreeDataModelTuple;
@@ -467,8 +468,16 @@
@Override
protected ExtendedDataModel<?> createExtendedDataModel() {
- SwingTreeNodeDataModelImpl dataModel = new SwingTreeNodeDataModelImpl();
- dataModel.setWrappedData(getValue());
+ ExtendedDataModel<?> dataModel;
+
+ Object value = getValue();
+ if (value == null) {
+ dataModel = new DeclarativeTreeDataModelImpl(this, getVar(),
getVariablesMap(getFacesContext()));
+ } else {
+ dataModel = new SwingTreeNodeDataModelImpl();
+ dataModel.setWrappedData(getValue());
+ }
+
return dataModel;
}
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelAdaptor.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,39 @@
+/*
+ * 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.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(type = AbstractTreeModelAdaptor.COMPONENT_TYPE,
+ tag = @Tag(name = "treeModelAdaptor"))
+public abstract class AbstractTreeModelAdaptor extends UIComponentBase implements
TreeModelAdaptor {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.TreeModelAdaptor";
+
+}
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/AbstractTreeModelRecursiveAdaptor.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,43 @@
+/*
+ * 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.Attribute;
+import org.richfaces.cdk.annotations.JsfComponent;
+import org.richfaces.cdk.annotations.Tag;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@JsfComponent(type = AbstractTreeModelRecursiveAdaptor.COMPONENT_TYPE,
+ tag = @Tag(name = "treeModelRecursiveAdaptor"))
+public abstract class AbstractTreeModelRecursiveAdaptor extends UIComponentBase
implements TreeModelRecursiveAdaptor {
+
+ public static final String COMPONENT_TYPE =
"org.richfaces.TreeModelRecursiveAdaptor";
+
+ @Attribute(defaultValue = "first")
+ public abstract String getRecursionOrder();
+
+}
Copied: trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelAdaptor.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeModelAdaptor {
+
+ public Object getNodes();
+
+}
Copied:
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java
(from rev 20214,
trunk/core/api/src/main/java/org/richfaces/component/ComponentPredicates.java)
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/component/TreeModelRecursiveAdaptor.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public interface TreeModelRecursiveAdaptor extends TreeModelAdaptor {
+
+ public Object getRoots();
+
+ public String getRecursionOrder();
+
+}
Added: trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java
===================================================================
--- trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeModelKey.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DeclarativeModelKey implements Serializable {
+
+ private static final long serialVersionUID = 7065813074553570168L;
+
+ private String modelId;
+
+ private Object modelKey;
+
+ public DeclarativeModelKey(String modelId, Object modelKey) {
+ super();
+ this.modelId = modelId;
+ this.modelKey = modelKey;
+ }
+
+ public String getModelId() {
+ return modelId;
+ }
+
+ public Object getModelKey() {
+ return modelKey;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((modelId == null) ? 0 : modelId.hashCode());
+ result = prime * result + ((modelKey == null) ? 0 : modelKey.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ DeclarativeModelKey other = (DeclarativeModelKey) obj;
+ if (modelId == null) {
+ if (other.modelId != null) {
+ return false;
+ }
+ } else if (!modelId.equals(other.modelId)) {
+ return false;
+ }
+ if (modelKey == null) {
+ if (other.modelKey != null) {
+ return false;
+ }
+ } else if (!modelKey.equals(other.modelKey)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return getModelId() + '.' + getModelKey();
+ }
+}
Added:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java
(rev 0)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/DeclarativeTreeDataModelImpl.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -0,0 +1,265 @@
+/*
+ * 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.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.AbstractTree;
+import org.richfaces.component.ComponentPredicates;
+import org.richfaces.component.TreeModelAdaptor;
+import org.richfaces.component.TreeModelRecursiveAdaptor;
+import org.richfaces.log.Logger;
+import org.richfaces.log.RichfacesLogger;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.ForwardingIterator;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
+import com.google.common.collect.Lists;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class DeclarativeTreeDataModelImpl extends
TreeSequenceKeyModel<DeclarativeModelKey, Object> {
+
+ private static final Logger LOGGER = RichfacesLogger.MODEL.getLogger();
+
+ private final class DeclarativeModelIterator implements
Iterator<TreeDataModelTuple> {
+
+ private UIComponent component;
+
+ private SequenceRowKey<DeclarativeModelKey> baseKey;
+
+ private int counter = 0;
+
+ private Iterator<?> nodesIterator;
+
+ public DeclarativeModelIterator(UIComponent component,
SequenceRowKey<DeclarativeModelKey> baseKey, Iterator<?> nodesIterator) {
+ super();
+ this.component = component;
+ this.baseKey = baseKey;
+ this.nodesIterator = nodesIterator;
+ }
+
+ public TreeDataModelTuple next() {
+ Object nextNode = nodesIterator.next();
+ DeclarativeModelKey key = new DeclarativeModelKey(component.getId(),
counter++);
+
+ SequenceRowKey<DeclarativeModelKey> newKey = baseKey.append(key);
+ setCurrentState(newKey, nextNode, component);
+
+ return new TreeDataModelTuple(newKey, nextNode);
+ }
+
+ public boolean hasNext() {
+ return nodesIterator.hasNext();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ private final class DeclarativeModelCompositeIterator extends
ForwardingIterator<TreeDataModelTuple> {
+
+ private UIComponent component;
+
+ private SequenceRowKey<DeclarativeModelKey> key;
+
+ private Iterator<TreeDataModelTuple> iterator;
+
+ public DeclarativeModelCompositeIterator(UIComponent component,
SequenceRowKey<DeclarativeModelKey> key) {
+ super();
+ this.component = component;
+ this.key = key;
+ }
+
+ @Override
+ protected Iterator<TreeDataModelTuple> delegate() {
+ if (iterator == null) {
+ List<Iterator<TreeDataModelTuple>> list =
Lists.newArrayList();
+
+ if (component instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor parentRecursiveAdaptor =
(TreeModelRecursiveAdaptor) component;
+
+ Collection<?> nodes = (Collection<?>)
parentRecursiveAdaptor.getNodes();
+
+ if (nodes != null) {
+ list.add(new DeclarativeModelIterator(component, key,
nodes.iterator()));
+ }
+ }
+
+ if (component.getChildCount() > 0) {
+ for (UIComponent child : Iterables.filter(component.getChildren(),
ComponentPredicates.isRendered())) {
+ Collection<?> nodes = null;
+
+ if (child instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor treeModelRecursiveAdaptor =
(TreeModelRecursiveAdaptor) child;
+
+ nodes = (Collection<?>)
treeModelRecursiveAdaptor.getRoots();
+ } else if (child instanceof TreeModelAdaptor) {
+ TreeModelAdaptor treeModelAdaptor = (TreeModelAdaptor)
child;
+
+ nodes = (Collection<?>) treeModelAdaptor.getNodes();
+ }
+
+ if (nodes != null) {
+ list.add(new DeclarativeModelIterator(child, key,
nodes.iterator()));
+ }
+ }
+ }
+
+ iterator = Iterators.concat(list.iterator());
+ }
+
+ return iterator;
+ }
+
+ }
+
+ private String var;
+
+ private Map<String, Object> contextMap;
+
+ private UIComponent tree;
+
+ private UIComponent currentComponent;
+
+ public DeclarativeTreeDataModelImpl(AbstractTree tree, String var, Map<String,
Object> contextMap) {
+ super();
+ this.tree = tree;
+ this.currentComponent = tree;
+ this.var = var;
+ this.contextMap = contextMap;
+ }
+
+ protected UIComponent getCurrentComponent() {
+ return currentComponent;
+ }
+
+ protected void setCurrentState(SequenceRowKey<DeclarativeModelKey> key, Object
data, UIComponent currentComponent) {
+ setRowKeyAndData(key, data);
+ this.currentComponent = currentComponent;
+ }
+
+ public boolean isLeaf() {
+ if (currentComponent instanceof TreeModelRecursiveAdaptor) {
+ return false;
+ }
+
+ if (currentComponent.getChildCount() == 0) {
+ return true;
+ }
+
+ return Iterables.contains(currentComponent.getChildren(),
Predicates.instanceOf(TreeModelAdaptor.class));
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#children()
+ */
+ public Iterator<TreeDataModelTuple> children() {
+ return new DeclarativeModelCompositeIterator(currentComponent, safeGetRowKey());
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.model.TreeDataModel#getParentRowKey(java.lang.Object)
+ */
+ public Object getParentRowKey(Object rowKey) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getWrappedData() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void setWrappedData(Object data) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected void walkKey(SequenceRowKey<DeclarativeModelKey> key) {
+ Object initialContextValue = null;
+
+ if (var != null) {
+ initialContextValue = contextMap.remove(var);
+ }
+
+ try {
+ this.currentComponent = tree;
+
+ super.walkKey(key);
+ } finally {
+ if (var != null) {
+ try {
+ contextMap.put(var, initialContextValue);
+ } catch (Exception e) {
+ LOGGER.error(e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void walkNext(DeclarativeModelKey segment) {
+ String modelId = segment.getModelId();
+
+ UIComponent modelComponent;
+
+ if (currentComponent instanceof TreeModelRecursiveAdaptor &&
modelId.equals(currentComponent.getId())) {
+ modelComponent = currentComponent;
+ } else {
+ modelComponent = Iterables.find(currentComponent.getChildren(),
ComponentPredicates.withId(modelId));
+ }
+
+ Object nodes = null;
+
+ if (modelComponent instanceof TreeModelRecursiveAdaptor) {
+ TreeModelRecursiveAdaptor recursiveAdaptor = (TreeModelRecursiveAdaptor)
modelComponent;
+
+ if (currentComponent.equals(modelComponent)) {
+ nodes = recursiveAdaptor.getNodes();
+ } else {
+ nodes = recursiveAdaptor.getRoots();
+ }
+ } else {
+ nodes = ((TreeModelAdaptor) modelComponent).getNodes();
+ }
+
+ Object data = Iterables.get((Iterable<?>) nodes, (Integer)
segment.getModelKey());
+ setCurrentState(safeGetRowKey().append(segment), data, modelComponent);
+
+ if (var != null) {
+ contextMap.put(var, data);
+ }
+ }
+
+}
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-11-29
20:36:39 UTC (rev 20214)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/SwingTreeNodeDataModelImpl.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -166,14 +166,8 @@
return rootNode.getWrappedData();
}
- @Override
protected TreeNode findChild(TreeNode parent, Integer simpleKey) {
- int idx = simpleKey.intValue();
- if (idx >= 0 && idx < parent.getChildCount()) {
- return parent.getChildAt(idx);
- }
-
- return null;
+ return parent.getChildAt(simpleKey.intValue());
}
public Iterator<TreeDataModelTuple> children() {
@@ -188,4 +182,13 @@
return !getData().getAllowsChildren();
}
}
+
+ @Override
+ protected void walkNext(Integer segment) {
+ TreeNode child = findChild(getData(), segment);
+ //TODO what if node is missing?
+ //TODO - optimize - remove partial keys creation
+ setRowKeyAndData(safeGetRowKey().append(segment), child);
+ }
+
}
\ No newline at end of file
Modified:
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java
===================================================================
---
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-11-29
20:36:39 UTC (rev 20214)
+++
trunk/ui/iteration/ui/src/main/java/org/richfaces/model/TreeSequenceKeyModel.java 2010-11-29
20:44:15 UTC (rev 20215)
@@ -34,6 +34,8 @@
*/
public abstract class TreeSequenceKeyModel<K, V> extends ExtendedDataModel<V>
implements TreeDataModel<V> {
+ private final SequenceRowKey<K> emptyKey = new SequenceRowKey<K>();
+
private V rootNode;
private V data;
@@ -44,20 +46,33 @@
return rowKey;
}
+ protected SequenceRowKey<K> safeGetRowKey() {
+ SequenceRowKey<K> key = getRowKey();
+
+ if (key == null) {
+ key = emptyKey;
+ }
+
+ return key;
+ }
+
public void setRowKey(Object rowKey) {
if (this.rowKey == null || !this.rowKey.equals(rowKey)) {
- this.rowKey = (SequenceRowKey<K>) rowKey;
- this.data = findData(this.rowKey);
+ walkKey((SequenceRowKey<K>) rowKey);
}
}
+ protected void resetRowKeyAndData() {
+ setRowKeyAndData(null, rootNode);
+ }
+
protected void setRowKeyAndData(SequenceRowKey<K> key, V data) {
this.rowKey = key;
this.data = data;
}
public boolean isDataAvailable() {
- return data != null;
+ return getRowKey() == null || data != null;
}
public V getData() {
@@ -67,26 +82,18 @@
return data;
}
+
+ protected void walkKey(SequenceRowKey<K> key) {
+ resetRowKeyAndData();
- protected V findData(SequenceRowKey<K> key) {
- if (key == null) {
- return rootNode;
- }
-
- V result = rootNode;
-
- for (K simpleKey : key.getSimpleKeys()) {
- result = findChild(result, simpleKey);
-
- if (result == null) {
- break;
+ if (key != null) {
+ for (K simpleKey: key.getSimpleKeys()) {
+ walkNext(simpleKey);
}
}
-
- return result;
}
-
- protected abstract V findChild(V parent, K simpleKey);
+
+ protected abstract void walkNext(K segment);
protected V getRootNode() {
return rootNode;