Author: julien(a)jboss.com
Date: 2007-12-03 18:19:44 -0500 (Mon, 03 Dec 2007)
New Revision: 9258
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
Log:
better implementation of model update
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-03
22:37:26 UTC (rev 9257)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIContextImpl.java 2007-12-03
23:19:44 UTC (rev 9258)
@@ -32,6 +32,7 @@
import org.jboss.portal.presentation.model.UIWindow;
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.StructuralStateChangeListener;
import org.jboss.portal.presentation.model.state.structural.StructuralStateContext;
import java.util.ArrayList;
@@ -58,6 +59,18 @@
/** . */
protected final List<ModelListener> listeners;
+ protected final StructuralStateChangeListener listener = new
StructuralStateChangeListener()
+ {
+ public void update(StructuralObject object)
+ {
+ // Get the corresping object
+ UIObjectImpl tmp = objects.get(object.getId());
+
+ // Update its structural view
+ tmp.structuralObject = object;
+ }
+ };
+
private static StructuralObject getRootState(StructuralStateContext loader)
{
return loader.load(loader.getRootId());
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-03
22:37:26 UTC (rev 9257)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java 2007-12-03
23:19:44 UTC (rev 9258)
@@ -55,7 +55,7 @@
private UIObjectImpl parent;
/** This is used to assist with data needed during lazy loading, other state related
data etc... */
- private StructuralObject structuralObject;
+ StructuralObject structuralObject;
public UIObjectImpl(UIContextImpl context, StructuralObject object)
{
@@ -185,11 +185,8 @@
changes.put(propertyName, (String)propertyValue);
// Have context process change
- context.structuralStateContext.update(structuralObject, changes);
+ context.structuralStateContext.update(context.listener, structuralObject,
changes);
- // Update state locally to reflect correct state
- structuralObject =
context.structuralStateContext.load(structuralObject.getId());
-
// Broadcast event
StructuralStateModification mod = new
StructuralStateModification.Update(changes);
StateChange<StructuralStateModification> change = new
StateChange<StructuralStateModification>(getId(), mod);
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-03
22:37:26 UTC (rev 9257)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/AbstractStructuralStateContext.java 2007-12-03
23:19:44 UTC (rev 9258)
@@ -27,7 +27,6 @@
import org.jboss.portal.presentation.model.UIObject;
import java.util.Map;
-import java.util.List;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -36,22 +35,22 @@
public abstract class AbstractStructuralStateContext implements StructuralStateContext
{
- public String create(StructuralObject parent, Class<? extends UIObject> type,
String name, Map<String, String> properties) throws StateChangeVetoException,
StateException, IllegalArgumentException
+ public String create(StructuralStateChangeListener listener, StructuralObject parent,
Class<? extends UIObject> type, String name, Map<String, String> properties)
throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void destroy(StructuralObject object) throws StateChangeVetoException,
StateException, IllegalArgumentException
+ public void destroy(StructuralStateChangeListener listener, StructuralObject object)
throws StateChangeVetoException, StateException, IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void move(StructuralObject object, StructuralObject parent) throws
StateChangeVetoException, StateException, IllegalArgumentException
+ public void move(StructuralStateChangeListener listener, StructuralObject object,
StructuralObject parent) throws StateChangeVetoException, StateException,
IllegalArgumentException
{
throw new StateChangeVetoException();
}
- public void update(StructuralObject object, Map<String, String> changes) throws
StateChangeVetoException, StateException, IllegalArgumentException
+ public void update(StructuralStateChangeListener listener, StructuralObject object,
Map<String, String> changes) throws StateChangeVetoException, StateException,
IllegalArgumentException
{
throw new StateChangeVetoException();
}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateChangeListener.java 2007-12-03
23:19:44 UTC (rev 9258)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated 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.jboss.portal.presentation.model.state.structural;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface StructuralStateChangeListener
+{
+ void update(StructuralObject object);
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-03
22:37:26 UTC (rev 9257)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateContext.java 2007-12-03
23:19:44 UTC (rev 9258)
@@ -62,51 +62,53 @@
/**
* Create an object.
*
+ * @param listener the listener
* @param parent the parent
* @param type the type of the child
* @param name the name of the child
- * @param properties the initial properties of the child
- * @return the id of the newly created structural state
+ * @param properties the initial properties of the child @return the id of the newly
created structural state
+ * @return the state id
* @throws StateChangeVetoException if the creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the parent id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- String create(StructuralObject parent, Class<? extends UIObject> type, String
name, Map<String, String> properties) throws StateChangeVetoException,
StateException, IllegalArgumentException;
+ String create(StructuralStateChangeListener listener, StructuralObject parent,
Class<? extends UIObject> type, String name, Map<String, String> properties)
throws StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Destroy a specified object.
*
- * @param object the object to destroy
- * @throws StateChangeVetoException if the creation is vetoed
+ * @param listener the listener
+ * @param object the object to destroy @throws StateChangeVetoException if the
creation is vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
+ * @throws StateChangeVetoException
*/
- void destroy(StructuralObject object) throws StateChangeVetoException, StateException,
IllegalArgumentException;
+ void destroy(StructuralStateChangeListener listener, StructuralObject object) throws
StateChangeVetoException, StateException, IllegalArgumentException;
/**
* Move an object to a new parent.
*
+ * @param listener the listener
* @param object the object to move
- * @param parent the new parent
- * @throws StateChangeVetoException if the creation is vetoed
+ * @param parent the new parent @throws StateChangeVetoException if the creation is
vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void move(StructuralObject object, StructuralObject parent) throws
StateChangeVetoException, StateException, IllegalArgumentException;
+ void move(StructuralStateChangeListener listener, StructuralObject object,
StructuralObject parent) throws StateChangeVetoException, StateException,
IllegalArgumentException;
/**
* Update the state of a specified object.
*
+ * @param listener the listener
* @param object the object to udpate
- * @param changes the changes
- * @throws StateChangeVetoException if the creation is vetoed
+ * @param changes the changes @throws StateChangeVetoException if the creation is
vetoed
* @throws StateException a generic state exception
* @throws NoSuchStateException if the object id does not point a valid state
* @throws IllegalArgumentException if an argument is null or not valid
*/
- void update(StructuralObject object, Map<String, String> changes) throws
StateChangeVetoException, StateException, IllegalArgumentException;
+ void update(StructuralStateChangeListener listener, StructuralObject object,
Map<String, String> changes) throws StateChangeVetoException, StateException,
IllegalArgumentException;
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03
22:37:26 UTC (rev 9257)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/state/structural/MockModel.java 2007-12-03
23:19:44 UTC (rev 9258)
@@ -29,6 +29,7 @@
import
org.jboss.portal.presentation.model.state.structural.AbstractStructuralStateContext;
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.StructuralStateChangeListener;
import java.util.ArrayList;
import java.util.HashMap;
@@ -93,7 +94,7 @@
return root.getId();
}
- public void update(StructuralObject object, Map<String, String> changes)
throws StateChangeVetoException
+ public void update(StructuralStateChangeListener listener, StructuralObject object,
Map<String, String> changes) throws StateChangeVetoException
{
MockObject mockObject = getValidMockObject(object);
@@ -118,6 +119,12 @@
mockObject.setPropertyValue(propertyName, entry.getValue());
}
}
+
+ //
+ if (listener != null)
+ {
+ listener.update(mockObject.takeSnapshot());
+ }
}
public List<StructuralObject> loadChildren(StructuralObject object)