Author: julien(a)jboss.com
Date: 2008-03-26 20:21:45 -0400 (Wed, 26 Mar 2008)
New Revision: 10385
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java
Log:
improved stuff
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java 2008-03-26
23:41:59 UTC (rev 10384)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model2/Refresh.java 2008-03-27
00:21:45 UTC (rev 10385)
@@ -75,7 +75,7 @@
refresh(rootId);
}
- private boolean refresh(String objectId)
+ private Status refresh(String objectId)
{
UIObjectImpl object = (UIObjectImpl)context.getObject(objectId);
@@ -89,18 +89,18 @@
StructuralObject structuralObject = structuralStateContext.load(objectId);
// It is not present, load it
- return load(structuralObject);
+ return load(structuralObject) ? Status.LOADED : Status.NOT_LOADED;
}
}
- private boolean refresh(StructuralObject structuralObject)
+ private Status refresh(StructuralObject structuralObject)
{
UIObjectImpl object = (UIObjectImpl)context.getObject(structuralObject.getId());
if (object == null)
{
- return load(structuralObject);
+ return load(structuralObject) ? Status.LOADED : Status.NOT_LOADED;
}
else
{
@@ -111,8 +111,15 @@
}
}
- private boolean refresh(UIObjectImpl object)
+ private enum Status
{
+ LOADED,
+ NOT_LOADED,
+ WANT_EVICT
+ }
+
+ private Status refresh(UIObjectImpl object)
+ {
ObjectTraversalType traversalType = scope.enterObject(object);
//
@@ -120,10 +127,7 @@
{
if (traversalType == ObjectTraversalType.SKIP)
{
- evict(object);
-
- //
- return false;
+ return Status.WANT_EVICT;
}
else if (traversalType == ObjectTraversalType.SINGLE)
{
@@ -149,7 +153,7 @@
}
//
- return true;
+ return Status.LOADED;
}
else
{
@@ -175,41 +179,55 @@
// Is it the same object with a new state or is it a new child with the
same name ?
if (childEntry.getKey().equals(childId))
{
- boolean loaded = refresh(childEntry.getValue());
+ Status status = refresh(childEntry.getValue());
- //
- if (hadChildren)
+ switch (status)
{
- UIObjectImpl.ChildRef childRef = object.childrenRefs.get(childId);
-
- //
- if (loaded)
- {
- if (!childRef.loaded)
+ case LOADED:
+ if (hadChildren)
{
- childRef.loaded = true;
- context.addChild(objectId, childId);
+ UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
+ if (!childRef.loaded)
+ {
+ childRef.loaded = true;
+ context.addChild(objectId, childId);
+ }
}
- }
- else
- {
- if (childRef.loaded)
+ else
{
- childRef.loaded = false;
- context.removeChild(objectId, childId);
+ object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, true));
+ context.addChild(objectId, structuralChild.getId());
}
- }
+ break;
+ case NOT_LOADED:
+ if (hadChildren)
+ {
+ UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
+ if (childRef.loaded)
+ {
+ childRef.loaded = false;
+ context.removeChild(objectId, childId);
+ }
+ }
+ else
+ {
+ object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, false));
+ }
+ break;
+ case WANT_EVICT:
+ if (hadChildren)
+ {
+ UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
+ if (childRef.loaded)
+ {
+ context.removeChild(objectId, childId);
+ childRef.loaded = false;
+ UIObjectImpl child =
(UIObjectImpl)context.getObject(childId);
+ evict(child);
+ }
+ }
+ break;
}
- else
- {
- object.childrenRefs.put(childId, new UIObjectImpl.ChildRef(childId,
loaded));
-
- //
- if (loaded)
- {
- context.addChild(objectId, structuralChild.getId());
- }
- }
}
else
{
@@ -247,45 +265,59 @@
//
for (String childId : refresh.getValidChildren())
{
- boolean loaded = refresh(childId);
+ Status status = refresh(childId);
- //
- if (hadChildren)
+ switch (status)
{
- UIObjectImpl.ChildRef childRef = object.childrenRefs.get(childId);
-
- //
- if (childRef.loaded)
- {
- if (!loaded)
+ case LOADED:
+ if (hadChildren)
{
- childRef.loaded = false;
- context.removeChild(objectId, childId);
+ UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
+ if (!childRef.loaded)
+ {
+ childRef.loaded = true;
+ context.addChild(objectId, childId);
+ }
}
- }
- else
- {
- if (loaded)
+ else
{
- childRef.loaded = true;
+ object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, true));
context.addChild(objectId, childId);
}
- }
+ break;
+ case NOT_LOADED:
+ if (hadChildren)
+ {
+ UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
+ if (childRef.loaded)
+ {
+ childRef.loaded = false;
+ context.removeChild(objectId, childId);
+ }
+ }
+ else
+ {
+ object.childrenRefs.put(childId, new
UIObjectImpl.ChildRef(childId, false));
+ }
+ break;
+ case WANT_EVICT:
+ if (hadChildren)
+ {
+ UIObjectImpl.ChildRef childRef =
object.childrenRefs.get(childId);
+ if (childRef.loaded)
+ {
+ context.removeChild(objectId, childId);
+ childRef.loaded = false;
+ UIObjectImpl child =
(UIObjectImpl)context.getObject(childId);
+ evict(child);
+ }
+ }
+ break;
}
- else
- {
- object.childrenRefs.put(childId, new UIObjectImpl.ChildRef(childId,
loaded));
-
- //
- if (loaded)
- {
- context.addChild(objectId, childId);
- }
- }
}
//
- return true;
+ return Status.LOADED;
}
}
finally
@@ -305,11 +337,10 @@
UIObjectImpl child = (UIObjectImpl)context.getObject(childRef.id);
//
- evict(child);
+ context.removeChild(object.structuralObject.getId(),
child.structuralObject.getId());
//
- context.removeChild(object.structuralObject.getId(),
child.structuralObject.getId());
- context.removeObject(child.structuralObject.getId());
+ evict(child);
}
}
@@ -318,7 +349,7 @@
}
//
- // context.removeObject(object.structuralObject.getId());
+ context.removeObject(object.structuralObject.getId());
}
private boolean load(StructuralObject structuralObject)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java 2008-03-26
23:41:59 UTC (rev 10384)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model2/UIObjectTree.java 2008-03-27
00:21:45 UTC (rev 10385)
@@ -45,12 +45,12 @@
public void assertConsistency(String rootId)
{
-// UIObjectNode root = nodes.get(rootId);
-// Assert.assertNotNull(root);
-// ArrayList<String> allIds = new ArrayList<String>();
-// collect(root, allIds);
-// Assert.assertEquals(new HashSet<String>(allIds).size(), allIds.size());
-// Assert.assertEquals(new HashSet<String>(allIds), nodes.keySet());
+ UIObjectNode root = nodes.get(rootId);
+ Assert.assertNotNull(root);
+ ArrayList<String> allIds = new ArrayList<String>();
+ collect(root, allIds);
+ Assert.assertEquals(new HashSet<String>(allIds).size(), allIds.size());
+ Assert.assertEquals(new HashSet<String>(allIds), nodes.keySet());
}
private void collect(UIObjectNode node, ArrayList<String> ids)