Author: julien(a)jboss.com
Date: 2007-12-18 17:47:00 -0500 (Tue, 18 Dec 2007)
New Revision: 9366
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
Log:
- finish move implementation + basic test of the feature
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18
22:04:33 UTC (rev 9365)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/AbstractUIObject.java 2007-12-18
22:47:00 UTC (rev 9366)
@@ -382,6 +382,29 @@
context.container.update(destruction);
}
+ public void move(UIObject destination) throws IllegalArgumentException,
StateException
+ {
+ if (destination == null)
+ {
+ throw new IllegalArgumentException("No null object accepted");
+ }
+ if (destination instanceof AbstractUIObject)
+ {
+ //
+ AbstractUIObject tmp = (AbstractUIObject)destination;
+
+ // Perform the move operation
+ StructuralObject.Move move =
context.container.structuralStateContext.move(context.structuralObject,
tmp.context.structuralObject);
+
+ //
+ context.container.update(move);
+ }
+ else
+ {
+ throw new IllegalArgumentException("Object not of right type");
+ }
+ }
+
protected abstract <T extends UIObject> boolean isAllowedAsChild(Class<T>
type);
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18
22:04:33 UTC (rev 9365)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-18
22:47:00 UTC (rev 9366)
@@ -94,12 +94,18 @@
if (change instanceof StructuralObject.Update)
{
StructuralObject.Update update = (StructuralObject.Update)change;
+
+ //
update(update.getObject());
}
else if (change instanceof StructuralObject.Creation)
{
StructuralObject.Creation creation = (StructuralObject.Creation)change;
+
+ //
update(creation.getParent());
+
+ //
update(creation.getChild());
}
else if (change instanceof StructuralObject.Destruction)
@@ -121,6 +127,19 @@
}
}
}
+ else if (change instanceof StructuralObject.Move)
+ {
+ StructuralObject.Move move = (StructuralObject.Move)change;
+
+ //
+ update(move.getParent());
+
+ //
+ update(move.getSource());
+
+ //
+ update(move.getDestination());
+ }
else
{
throw new AssertionError();
@@ -235,6 +254,13 @@
// Private
**********************************************************************************************************
+ /**
+ * Update the state of an object if it is present. It will also reset the parent and
children
+ * relationships in order to force a implicit refresh.
+ *
+ * @param structuralObject the structural object to update
+ * @return the object API implementation
+ */
private AbstractUIObject update(StructuralObject structuralObject)
{
AbstractUIObject object = universe.get(structuralObject.getId());
@@ -250,8 +276,6 @@
else
{
object.context.structuralObject = structuralObject;
-
- //
object.parent.reset();
object.children.reset();
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18
22:04:33 UTC (rev 9365)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/UIObject.java 2007-12-18
22:47:00 UTC (rev 9366)
@@ -161,4 +161,7 @@
*/
void destroyChild(String name) throws IllegalArgumentException, StateException;
+
+ void move(UIObject destination) throws IllegalArgumentException, StateException;
+
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-18
22:04:33 UTC (rev 9365)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-18
22:47:00 UTC (rev 9366)
@@ -66,13 +66,23 @@
{
/** . */
+ private final StructuralObject parent;
+
+ /** . */
private final StructuralObject source;
/** . */
private final StructuralObject destination;
- public Move(StructuralObject source, StructuralObject destination)
+ public Move(
+ StructuralObject parent,
+ StructuralObject source,
+ StructuralObject destination)
{
+ if (parent == null)
+ {
+ throw new IllegalArgumentException();
+ }
if (source == null)
{
throw new IllegalArgumentException();
@@ -83,10 +93,16 @@
}
//
+ this.parent = parent;
this.source = source;
this.destination = destination;
}
+ public StructuralObject getParent()
+ {
+ return parent;
+ }
+
public StructuralObject getSource()
{
return source;
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18
22:04:33 UTC (rev 9365)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java 2007-12-18
22:47:00 UTC (rev 9366)
@@ -39,10 +39,12 @@
import org.jboss.portal.presentation.test.model.state.structural.MockObject;
import org.jboss.portal.presentation.test.model.state.structural.MockException;
import org.jboss.portal.presentation.test.model.state.structural.MockModelImpl;
+import org.jboss.portal.common.util.Tools;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.HashSet;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -537,4 +539,36 @@
assertEquals(null, context.getObject(daaId));
}
+ public void testMove() throws Exception
+ {
+ MockObject mockRoot = model.getRoot();
+
+ MockObject mockFoo = mockRoot.addChild("foo", MockObject.Type.PORTAL);
+ MockObject mockBar = mockRoot.addChild("bar", MockObject.Type.PORTAL);
+
+ MockObject mockFooJuu = mockFoo.addChild("juu", MockObject.Type.PAGE);
+ MockObject mockFooDaa = mockFoo.addChild("daa", MockObject.Type.PAGE);
+
+ MockObject mockBarDaa = mockBar.addChild("daa", MockObject.Type.PAGE);
+
+ //
+ UIContext context = createContext();
+
+ //
+ UIObject foo = context.getChild("foo");
+ List<? extends UIObject> fooChildren = foo.getChildren();
+ UIObject fooJuu = foo.getChild("juu");
+ UIObject fooDaa = foo.getChild("daa");
+ UIObject bar = context.getChild("bar");
+ UIObject barDaa = bar.getChild("daa");
+ List<? extends UIObject> barChildren = bar.getChildren();
+
+ //
+ fooJuu.move(bar);
+
+ //
+ assertEquals(bar, fooJuu.getParent());
+ assertEquals(Collections.singleton(fooDaa), new
HashSet<UIObject>(fooChildren));
+ assertEquals(Tools.toSet(barDaa, fooJuu), new
HashSet<UIObject>(barChildren));
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18
22:04:33 UTC (rev 9365)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-18
22:47:00 UTC (rev 9366)
@@ -227,6 +227,7 @@
{
MockObject mockSource = getValidMockObject(source);
MockObject mockDestination = getValidMockObject(destination);
+ MockObject mockParent = mockSource.getParent();
//
try
@@ -234,7 +235,7 @@
mockSource.move(mockDestination);
//
- return new StructuralObject.Move(mockSource.takeSnapshot(),
mockSource.takeSnapshot());
+ return new StructuralObject.Move(mockParent.takeSnapshot(),
mockSource.takeSnapshot(), mockSource.takeSnapshot());
}
catch (MockException e)
{