[portal-commits] JBoss Portal SVN: r9197 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: impl/model/state/navigational and 3 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Thu Nov 29 08:53:02 EST 2007


Author: julien at jboss.com
Date: 2007-11-29 08:53:02 -0500 (Thu, 29 Nov 2007)
New Revision: 9197

Added:
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java
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/state/navigational/NavigationalStateContextImpl.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
   branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java
Log:
implement navigational state change eventing

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-11-29 13:35:09 UTC (rev 9196)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/UIObjectImpl.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -27,6 +27,7 @@
 import org.jboss.portal.presentation.model.state.StateChange;
 import org.jboss.portal.presentation.model.state.StateChangeEvent;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
+import org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
 import org.jboss.portal.presentation.model.state.structural.StructuralState;
 import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
 
@@ -157,20 +158,33 @@
       switch (scopeType)
       {
          case NAVIGATIONAL:
-            context.navigationalStateContext.set(id, propertyName, propertyValue);
+         {
+            NavigationalStateModification mod = new NavigationalStateModification(propertyName, propertyValue);
+            StateChange<NavigationalStateModification> change = new StateChange<NavigationalStateModification>(id, mod);
+
+            // Have context process the change
+            context.navigationalStateContext.update(change);
+
+            // Broadcast event
+            StateChangeEvent event = new StateChangeEvent(change);
+            context.fireEvent(event);
             break;
+         }
          case STRUCTURAL:
+         {
             if (propertyValue instanceof String)
             {
                Map<String, String> changes = new HashMap<String, String>();
                changes.put(propertyName, (String)propertyValue);
 
-               // Have loader process state
+               // Create change
                StructuralStateModification mod = new StructuralStateModification.SetProperties(changes);
                StateChange<StructuralStateModification> change = new StateChange<StructuralStateModification>(id, mod);
+
+               // Have context process change
                context.structuralStateContext.update(change);
 
-               // Update state locally
+               // Update state locally to reflect correct state
                Map<String, String> updatedProperties = new HashMap<String, String>(state.getProperties());
                updateProperty(updatedProperties, propertyName, (String)propertyValue);
                state = new StructuralState(state.getType(), state.getName(), updatedProperties, state.getParentId(), state.getChildrenIds());
@@ -184,6 +198,7 @@
                throw new StateChangeVetoException("Structural property value must be string value");
             }
             break;
+         }
          default:
             throw new AssertionError();
       }

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/state/navigational/NavigationalStateContextImpl.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/state/navigational/NavigationalStateContextImpl.java	2007-11-29 13:35:09 UTC (rev 9196)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/state/navigational/NavigationalStateContextImpl.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -23,11 +23,14 @@
 package org.jboss.portal.presentation.impl.model.state.navigational;
 
 import org.jboss.portal.presentation.model.state.navigational.NavigationalStateContext;
+import org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
 import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.StateChange;
 
 import java.util.Map;
 import java.util.HashMap;
+import java.util.List;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -49,9 +52,33 @@
       this(new HashMap<Key, Object>());
    }
 
+   public void update(List<StateChange<NavigationalStateModification>> changes)
+   {
+      for (StateChange<NavigationalStateModification> change : changes)
+      {
+         update(change);
+      }
+   }
+
+   public void update(StateChange<NavigationalStateModification> change)
+   {
+      Key key = new Key(change.getTargetId(), change.getModification().getKey());
+      Object navigationalState = change.getModification().getNavigationalState();
+
+      //
+      if (navigationalState != null)
+      {
+         map.put(key, navigationalState);
+      }
+      else
+      {
+         map.remove(key);
+      }
+   }
+
    public void set(String objectId, String key, Object navigationalState) throws StateChangeVetoException, StateException, IllegalArgumentException
    {
-      map.put(new Key(objectId, key), navigationalState);
+      update(new StateChange<NavigationalStateModification>(objectId, new NavigationalStateModification(key, navigationalState)));
    }
 
    public Object get(String objectId, String key) throws IllegalArgumentException

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java	2007-11-29 13:35:09 UTC (rev 9196)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateContext.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -24,7 +24,10 @@
 
 import org.jboss.portal.presentation.model.state.StateChangeVetoException;
 import org.jboss.portal.presentation.model.state.StateException;
+import org.jboss.portal.presentation.model.state.StateChange;
 
+import java.util.List;
+
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  * @version $Revision: 630 $
@@ -34,4 +37,8 @@
    Object get(String objectId, String key) throws IllegalArgumentException;
 
    void set(String objectId, String key, Object navigationalState) throws StateChangeVetoException, StateException, IllegalArgumentException;
+
+   void update(List<StateChange<NavigationalStateModification>> modifications);
+
+   void update(StateChange<NavigationalStateModification> modification);
 }

Added: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java	                        (rev 0)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/navigational/NavigationalStateModification.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * 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.navigational;
+
+import org.jboss.portal.presentation.model.state.StateModification;
+
+/**
+ * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public final class NavigationalStateModification extends StateModification
+{
+
+   /** . */
+   private final String key;
+
+   /** . */
+   private final Object navigationalState;
+
+   public NavigationalStateModification(String key, Object navigationalState)
+   {
+      if (key == null)
+      {
+         throw new IllegalArgumentException();
+      }
+
+      //
+      this.key = key;
+      this.navigationalState = navigationalState;
+   }
+
+   public String getKey()
+   {
+      return key;
+   }
+
+   public Object getNavigationalState()
+   {
+      return navigationalState;
+   }
+}

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java	2007-11-29 13:35:09 UTC (rev 9196)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/model/state/structural/StructuralStateModification.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -33,9 +33,13 @@
 public abstract class StructuralStateModification extends StateModification
 {
 
-   public static class SetProperties extends StructuralStateModification
+   protected StructuralStateModification()
    {
+   }
 
+   public final static class SetProperties extends StructuralStateModification
+   {
+
       /** . */
       private final Map<String, String> changes;
 

Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java
===================================================================
--- branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java	2007-11-29 13:35:09 UTC (rev 9196)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/EventAssert.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -25,13 +25,13 @@
 import junit.framework.Assert;
 import org.jboss.portal.presentation.model.ModelEvent;
 import org.jboss.portal.presentation.model.ModelListener;
+import org.jboss.portal.presentation.model.state.StateChange;
+import org.jboss.portal.presentation.model.state.StateChangeEvent;
+import org.jboss.portal.presentation.model.state.navigational.NavigationalStateModification;
 import org.jboss.portal.presentation.model.state.structural.StructuralStateModification;
-import org.jboss.portal.presentation.model.state.StateChangeEvent;
-import org.jboss.portal.presentation.model.state.StateChange;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Collections;
 
 /**
  * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
@@ -69,6 +69,16 @@
       Assert.assertEquals(sp.getChanges(), mod.getChanges());
    }
 
+   public void next(String targetId, NavigationalStateModification ns)
+   {
+      StateChangeEvent ste = next(StateChangeEvent.class);
+      StateChange change = ste.getChange();
+      Assert.assertEquals(targetId, change.getTargetId());
+      NavigationalStateModification mod = (NavigationalStateModification)change.getModification();
+      Assert.assertEquals(ns.getKey(), mod.getKey());
+      Assert.assertEquals(ns.getNavigationalState(), mod.getNavigationalState());
+   }
+
    public void assertEmpty()
    {
       Assert.assertEquals(events.size(), index);

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-11-29 13:35:09 UTC (rev 9196)
+++ branches/presentation/presentation/src/main/org/jboss/portal/presentation/test/model/ModelTestCase.java	2007-11-29 13:53:02 UTC (rev 9197)
@@ -440,6 +440,8 @@
    {
       MockObject mockFoo = model.getRoot().addChild("foo", MockObject.Type.PORTAL);
       UIContext context = createContext();
+      EventAssert eventAssert = new EventAssert();
+      context.addModelListener(eventAssert);
 
       // Check initial state
       UIPortal foo = (UIPortal)context.getObject(mockFoo.getId());




More information about the portal-commits mailing list