[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset ...
Christian Bauer
christian at hibernate.org
Mon Sep 24 04:23:19 EDT 2007
User: cbauer
Date: 07/09/24 04:23:19
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset
NestedSetResultTransformer.java
NestedSetNodeWrapper.java
Added: examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset
NestedSetNodeWrapperEntityConverter.java
Log:
New help system and improved wiki text editor
Revision Changes Path
1.4 +5 -6 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/NestedSetResultTransformer.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NestedSetResultTransformer.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/NestedSetResultTransformer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- NestedSetResultTransformer.java 15 Sep 2007 17:06:17 -0000 1.3
+++ NestedSetResultTransformer.java 24 Sep 2007 08:23:19 -0000 1.4
@@ -177,7 +177,7 @@
if (flattenToLevel > 0) {
List<NestedSetNodeWrapper<N>> flatChildren = new ArrayList<NestedSetNodeWrapper<N>>();
for(NestedSetNodeWrapper<N> child: rootWrapper.getWrappedChildrenSorted()) {
- flattenTree(flatChildren, 1l, child);
+ flattenTree(flatChildren, child);
}
rootWrapper.setWrappedChildren(flatChildren);
}
@@ -185,19 +185,18 @@
}
// Recursively flatten tree
- public void flattenTree(List<NestedSetNodeWrapper<N>> flatChildren, long i, NestedSetNodeWrapper<N> wrapper) {
+ public void flattenTree(List<NestedSetNodeWrapper<N>> flatChildren, NestedSetNodeWrapper<N> wrapper) {
NestedSetNodeWrapper<N> newWrapper =
- createNestedSetNodeWrapper(wrapper.getWrappedNode(), comparator, i, wrapper.getAdditionalProjections());
+ createNestedSetNodeWrapper(wrapper.getWrappedNode(), comparator, wrapper.getLevel(), wrapper.getAdditionalProjections());
flatChildren.add( newWrapper );
if (wrapper.getWrappedChildren().size() > 0 && wrapper.getLevel() < flattenToLevel) {
- i++;
for (NestedSetNodeWrapper<N> child : wrapper.getWrappedChildrenSorted()) {
- flattenTree(newWrapper.getWrappedChildren(), i, child);
+ flattenTree(newWrapper.getWrappedChildren(), child);
}
} else if (wrapper.getWrappedChildren().size() > 0) {
for (NestedSetNodeWrapper<N> child : wrapper.getWrappedChildrenSorted()) {
- flattenTree(flatChildren, i, child);
+ flattenTree(flatChildren, child);
}
}
}
1.4 +31 -0 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/NestedSetNodeWrapper.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NestedSetNodeWrapper.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/NestedSetNodeWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- NestedSetNodeWrapper.java 15 Sep 2007 17:06:17 -0000 1.3
+++ NestedSetNodeWrapper.java 24 Sep 2007 08:23:19 -0000 1.4
@@ -51,6 +51,17 @@
Map<String, Object> additionalProjections = new HashMap<String, Object>();
public boolean childrenLoaded = false;
+ public NestedSetNodeWrapper(N wrappedNode) {
+ this(
+ wrappedNode,
+ new Comparator() {
+ public int compare(Object o, Object o1) {
+ return 0;
+ }
+ }
+ );
+ }
+
public NestedSetNodeWrapper(N wrappedNode, Comparator<NestedSetNodeWrapper<N>> comparator) {
this(wrappedNode, comparator, 0l);
}
@@ -60,6 +71,9 @@
}
public NestedSetNodeWrapper(N wrappedNode, Comparator<NestedSetNodeWrapper<N>> comparator, Long level, Map<String,Object> additionalProjections) {
+ if (wrappedNode == null) {
+ throw new IllegalArgumentException("Can't wrap null node");
+ }
this.wrappedNode = wrappedNode;
this.comparator = comparator;
this.level = level;
@@ -114,6 +128,23 @@
return sortedSet;
}
+ // This is needed because JSF converters for selectitems need to return an equal() instance to
+ // the selected item of the selectitems collection. This sucks.
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ NestedSetNodeWrapper that = (NestedSetNodeWrapper) o;
+
+ if (!wrappedNode.getId().equals(that.wrappedNode.getId())) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ return wrappedNode.getId().hashCode();
+ }
+
public String toString() {
return "Wrapper on level " + getLevel() + " for: " + getWrappedNode();
}
1.1 date: 2007/09/24 08:23:19; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/nestedset/NestedSetNodeWrapperEntityConverter.java
Index: NestedSetNodeWrapperEntityConverter.java
===================================================================
package org.jboss.seam.wiki.core.nestedset;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.ui.converter.EntityConverter;
import javax.faces.context.FacesContext;
import javax.faces.component.UIComponent;
import javax.faces.convert.ConverterException;
/**
* Unwraps a wrapped Nested Set node and stores its identifier in the page context.
* <p>
* Because some clown in the JSF EG decided that a converter needs to return an instance
* from <tt>getAsObject()</tt> that is <tt>equal()</tt> to one of the instances in the
* <tt>SelectItem</tt>s list, we now need to override <tt>equals()</tt> in
* <tt>NestedSetNodeWrapper</tt> to trick it. No, this check does not add security, it just
* makes JSF less flexible.
*
* @author Christian Bauer
*/
@Name("nestedSetNodeWrapperEntityConverter")
public class NestedSetNodeWrapperEntityConverter extends EntityConverter {
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o) throws ConverterException {
String result;
if (o instanceof NestedSetNodeWrapper) {
result = super.getAsString(facesContext, uiComponent, ((NestedSetNodeWrapper)o).getWrappedNode());
return result;
} else {
throw new IllegalArgumentException("Can not convert: " + o);
}
}
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) throws ConverterException {
Object o = super.getAsObject(facesContext, uiComponent, s);
return new NestedSetNodeWrapper( (NestedSetNode)o );
}
}
More information about the jboss-cvs-commits
mailing list