Author: julien(a)jboss.com
Date: 2007-12-29 17:51:43 -0500 (Sat, 29 Dec 2007)
New Revision: 9404
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.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/event/state/StateChange.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.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/state/structural/MockModelImpl.java
Log:
improve a bit existing eventing stuff (need to add test)
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-29
15:14:44 UTC (rev 9403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2007-12-29
22:51:43 UTC (rev 9404)
@@ -212,10 +212,12 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- StructuralObject.Update update;
try
{
- update =
context.container.structuralStateContext.update(context.structuralObject, changes);
+ StructuralObject.Update update =
context.container.structuralStateContext.update(context.structuralObject, changes);
+
+ //
+ context.container.update(update);
}
catch (StateException e)
{
@@ -224,15 +226,6 @@
//
throw e;
}
-
- //
- context.container.update(update);
-
- // Broadcast event
- StructuralStateModification mod = new
StructuralStateModification.Update(changes);
- StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(id, mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
}
else
{
@@ -322,12 +315,6 @@
//
StructuralObject child = creation.getChild();
- // Eventing
- StructuralStateModification mod = new StructuralStateModification.Creation(type,
name, EMPTY_STATE);
- StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(child.getId(), mod);
- StateChangeEvent event = new StateChangeEvent(change);
- context.container.fireEvent(event);
-
//
return type.cast(context.getObject(child.getId()));
}
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-29
15:14:44 UTC (rev 9403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/UIObjectContainer.java 2007-12-29
22:51:43 UTC (rev 9404)
@@ -26,9 +26,13 @@
import org.jboss.portal.presentation.model.ModelListener;
import org.jboss.portal.presentation.model.UIObject;
import org.jboss.portal.presentation.model.UIContext;
+import
org.jboss.portal.presentation.model.event.state.structural.StructuralStateModification;
+import org.jboss.portal.presentation.model.event.state.StateChange;
+import org.jboss.portal.presentation.model.event.state.StateChangeEvent;
import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
import org.jboss.portal.presentation.model.state.structural.StructuralObject;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
+import org.jboss.portal.presentation.model.state.structural.StructuralState;
import org.jboss.portal.presentation.model.state.NoSuchStateException;
import org.jboss.portal.presentation.model.state.StateException;
import org.jboss.portal.presentation.impl.model.container.spi.UIContainerObject;
@@ -50,6 +54,9 @@
{
/** . */
+ private final static StructuralStateModification.Destruction DESTRUCTION = new
StructuralStateModification.Destruction();
+
+ /** . */
private final Map<String, UIContainerObject> universe = new HashMap<String,
UIContainerObject>();
/** . */
@@ -136,6 +143,12 @@
//
ObjectContext context = (ObjectContext)object.getContext();
context.structuralObject = update.getObject();
+
+ // Eventing
+ StructuralStateModification mod = new
StructuralStateModification.Update(update.getChanges());
+ StateChange<StructuralStateModification> stateChange = new
StateChange<StructuralStateModification>(update.getObject().getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
else if (change instanceof StructuralObject.Creation)
{
@@ -167,6 +180,14 @@
//
parentContext.associationContext.children.addLoadedRelated(child);
}
+
+ // Eventing
+ StructuralObject childSO = creation.getChild();
+ StructuralState state = childSO.getState();
+ StructuralStateModification mod = new
StructuralStateModification.Creation(state.getType(), state.getName(),
state.getProperties());
+ StateChange<StructuralStateModification> stateChange = new
StateChange<StructuralStateModification>(childSO.getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
else if (change instanceof StructuralObject.Destruction)
{
@@ -204,6 +225,11 @@
{
ObjectContext destroyedContext = (ObjectContext)destroyed.getContext();
destroyedContext.status = UIObject.Status.INVALID;
+
+ // Eventing
+ StateChange<StructuralStateModification> stateChange = new
StateChange<StructuralStateModification>(id, DESTRUCTION);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
}
}
@@ -277,6 +303,12 @@
}
}
}
+
+ // Eventing
+ StructuralStateModification.Move mod = new
StructuralStateModification.Move(move.getParent().getId(),
move.getDestination().getId());
+ StateChange<StructuralStateModification> stateChange = new
StateChange<StructuralStateModification>(move.getSource().getId(), mod);
+ StateChangeEvent event = new StateChangeEvent(stateChange);
+ fireEvent(event);
}
else
{
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java 2007-12-29
15:14:44 UTC (rev 9403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/StateChange.java 2007-12-29
22:51:43 UTC (rev 9404)
@@ -22,8 +22,6 @@
******************************************************************************/
package org.jboss.portal.presentation.model.event.state;
-import org.jboss.portal.presentation.model.event.state.StateModification;
-
/**
* A change in the state of the model. The change is the association of a target id and a
modification.
* The target id refers to an object in the structural state context and the modification
is a modification
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java 2007-12-29
15:14:44 UTC (rev 9403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/event/state/structural/StructuralStateModification.java 2007-12-29
22:51:43 UTC (rev 9404)
@@ -86,13 +86,22 @@
{
/** . */
+ private final String parentId;
+
+ /** . */
private final String destinationId;
- public Move(String parentId)
+ public Move(String parentId, String destinationId)
{
- this.destinationId = parentId;
+ this.parentId = parentId;
+ this.destinationId = destinationId;
}
+ public String getParentId()
+ {
+ return parentId;
+ }
+
public String getDestinationId()
{
return destinationId;
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-29
15:14:44 UTC (rev 9403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralObject.java 2007-12-29
22:51:43 UTC (rev 9404)
@@ -150,21 +150,34 @@
/** . */
private final StructuralObject object;
- public Update(StructuralObject object)
+ /** . */
+ private final Map<String, String> changes;
+
+ public Update(StructuralObject object, Map<String, String> changes)
{
if (object == null)
{
throw new IllegalArgumentException();
}
+ if (changes == null)
+ {
+ throw new IllegalArgumentException();
+ }
//
this.object = object;
+ this.changes = changes;
}
public StructuralObject getObject()
{
return object;
}
+
+ public Map<String, String> getChanges()
+ {
+ return changes;
+ }
}
public static class Move extends Change
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-29
15:14:44 UTC (rev 9403)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModelImpl.java 2007-12-29
22:51:43 UTC (rev 9404)
@@ -43,6 +43,7 @@
import java.util.HashSet;
import java.util.Set;
import java.util.Collection;
+import java.util.Collections;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -227,6 +228,9 @@
{
MockObject mockObject = getValidMockObject(object);
+ // Create an non mutable clone (for the event)
+ changes = Collections.unmodifiableMap(new HashMap<String,
String>(changes));
+
//
for (Map.Entry<String, String> entry : changes.entrySet())
{
@@ -257,7 +261,7 @@
}
//
- return new StructuralObject.Update(mockObject.takeSnapshot());
+ return new StructuralObject.Update(mockObject.takeSnapshot(), changes);
}
public StructuralObject.Creation create(StructuralObject parent, Class<? extends
UIObject> classType, String name, Map<String, String> properties) throws
StateException, IllegalArgumentException