Author: julien(a)jboss.com
Date: 2008-06-29 11:10:18 -0400 (Sun, 29 Jun 2008)
New Revision: 11196
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutAdapter.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/ModelLayoutAdapter.java
Modified:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DefaultLayout.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DesktopLayout.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/Layout.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutFactory.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/RegionLayout.java
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/SimpleLayout.java
Log:
update layout framework to use generics and avoid dependency on the client side model
Modified:
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java
===================================================================
---
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/classic/src/main/java/org/jboss/portal/presentation/classic/ClassicPresentationClient.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -45,6 +45,7 @@
import org.jboss.portal.presentation.layout.Layout;
import org.jboss.portal.presentation.layout.SimpleLayout;
import org.jboss.portal.presentation.layout.Orientation;
+import org.jboss.portal.presentation.layout.ModelLayoutAdapter;
import org.jboss.portal.presentation.model.content.ContentFragment;
import org.jboss.portal.presentation.model.ui.UIContext;
import org.jboss.portal.presentation.model.ui.UIPage;
@@ -327,18 +328,17 @@
private void renderPane(UINode node, PrintWriter writer)
{
- LayoutFactory layoutFactory = new LayoutFactory();
+ LayoutFactory<UINode> layoutFactory = new LayoutFactory<UINode>(new
ModelLayoutAdapter());
//
- Layout layout = layoutFactory.getLayout(node);
+ Layout<UINode> layout = layoutFactory.getLayout(node);
//
if (layout instanceof SimpleLayout)
{
//
- SimpleLayout simpleLayout = (SimpleLayout)layout;
+ SimpleLayout<UINode> simpleLayout = (SimpleLayout<UINode>)layout;
-
//
Orientation orientation = simpleLayout.getOrientation();
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DefaultLayout.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DefaultLayout.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DefaultLayout.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -22,10 +22,18 @@
******************************************************************************/
package org.jboss.portal.presentation.layout;
+import org.jboss.portal.common.NotYetImplemented;
+
+import java.util.Collection;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class DefaultLayout implements Layout
+public class DefaultLayout<I> implements Layout<I>
{
+ public Collection<? extends I> getItems()
+ {
+ throw new NotYetImplemented();
+ }
}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DesktopLayout.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DesktopLayout.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/DesktopLayout.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -22,12 +22,20 @@
******************************************************************************/
package org.jboss.portal.presentation.layout;
+import org.jboss.portal.common.NotYetImplemented;
+
+import java.util.Collection;
+
/**
* Desktop layout.
*
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class DesktopLayout implements Layout
+public class DesktopLayout<I> implements Layout<I>
{
+ public Collection<? extends I> getItems()
+ {
+ throw new NotYetImplemented();
+ }
}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/Layout.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/Layout.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/Layout.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -22,10 +22,13 @@
******************************************************************************/
package org.jboss.portal.presentation.layout;
+import java.util.Collection;
+
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public interface Layout
+public interface Layout<I>
{
+ Collection<? extends I> getItems();
}
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutAdapter.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutAdapter.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutAdapter.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.layout;
+
+import java.util.Collection;
+
+/**
+ * Adapts any model to the layout model. The parametrization of the class allows
+ * the client code of the layout framework to avoid unnecessary casting.
+ *
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public interface LayoutAdapter<I>
+{
+
+ /**
+ * Returns the id of the specified item
+ *
+ * @param item the item
+ * @return the item id
+ */
+ String getId(I item);
+
+ /**
+ * Returns a property of the specified item.
+ *
+ * @param item the item
+ * @param propertyName the property name
+ * @param propertyType the property class
+ * @return the property value
+ */
+ <T> T getProperty(I item, String propertyName, Class<T> propertyType);
+
+ /**
+ * Returns the children of the specifed item.
+ *
+ * @param item the item
+ * @return the children
+ */
+ Collection<? extends I> getChildren(I item);
+
+}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutFactory.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutFactory.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/LayoutFactory.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -22,11 +22,6 @@
******************************************************************************/
package org.jboss.portal.presentation.layout;
-import org.jboss.portal.presentation.model.ui.UIPane;
-import org.jboss.portal.presentation.model.ui.UIObject;
-import org.jboss.portal.presentation.model.UINode;
-import org.jboss.portal.presentation.state.StateType;
-
import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.common.util.SetMap;
@@ -35,23 +30,30 @@
import java.util.Comparator;
/**
+ * A factory for getting layout from a specified item.
+ *
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class LayoutFactory
+public class LayoutFactory<I>
{
- public Layout getLayout(UINode node)
+ /** . */
+ private LayoutAdapter<I> adapter;
+
+ public LayoutFactory(LayoutAdapter<I> adapter)
{
- UIPane pane = (UIPane)node.getObject();
+ this.adapter = adapter;
+ }
- //
- String layoutId = pane.getProperty(StateType.STRUCTURAL, Constants.LAYOUT_ID,
String.class);
+ public Layout<I> getLayout(I item)
+ {
+ String layoutId = adapter.getProperty(item, Constants.LAYOUT_ID, String.class);
//
if (Constants.SIMPLE_LAYOUT.equals(layoutId))
{
- String orientationValue = pane.getProperty(StateType.STRUCTURAL,
Constants.SIMPLE_LAYOUT_ORIENTATION, String.class);
+ String orientationValue = adapter.getProperty(item,
Constants.SIMPLE_LAYOUT_ORIENTATION, String.class);
//
Orientation orientation = Orientation.HORIZONTAL;
@@ -63,56 +65,41 @@
}
//
- Collection<? extends UINode> chidrenNodes = node.getChildren();
-
- //
- if (chidrenNodes == null)
+ TreeMap<Integer, I> items = new TreeMap<Integer, I>();
+ for (I child : adapter.getChildren(item))
{
- throw new IllegalStateException("No children found for the simple layout
" + pane.getId());
- }
+ Integer index = adapter.getProperty(child, Constants.SIMPLE_LAYOUT_INDEX,
Integer.class);
- //
- TreeMap<Integer, UINode> layoutNodes = new TreeMap<Integer,
UINode>();
- for (UINode childNode : chidrenNodes)
- {
- UIObject child = childNode.getObject();
-
//
- Integer index = child.getProperty(StateType.STRUCTURAL,
Constants.SIMPLE_LAYOUT_INDEX, Integer.class);
-
- //
if (index != null)
{
- layoutNodes.put(index, childNode);
+ items.put(index, child);
}
}
//
- return new SimpleLayout(orientation, layoutNodes.values());
+ return new SimpleLayout<I>(orientation, items.values());
}
else if (Constants.REGION_LAYOUT.equals(layoutId))
{
- Collection<? extends UINode> chidrenNodes = node.getChildren();
+ Collection<? extends I> children = adapter.getChildren(item);
//
- SetMap<String, UINode> map = new SetMap<String,
UINode>(comparator);
- for (UINode childNode : chidrenNodes)
+ SetMap<String, I> map = new SetMap<String, I>(comparator);
+ for (I child : children)
{
- UIObject child = childNode.getObject();
+ String regionName = adapter.getProperty(child, Constants.REGION_LAYOUT_NAME,
String.class);
+ Integer regionIndex = adapter.getProperty(child,
Constants.REGION_LAYOUT_INDEX, Integer.class);
//
- String regionName = child.getProperty(StateType.STRUCTURAL,
Constants.REGION_LAYOUT_NAME, String.class);
- Integer regionIndex = child.getProperty(StateType.STRUCTURAL,
Constants.REGION_LAYOUT_INDEX, Integer.class);
-
- //
if (regionName != null && regionIndex != null)
{
- map.put(regionName, childNode);
+ map.put(regionName, child);
}
}
//
- return new RegionLayout(map);
+ return new RegionLayout<I>(map);
}
else
{
@@ -121,14 +108,12 @@
}
/** . */
- private static final Comparator<UINode> comparator = new
Comparator<UINode>()
+ private final Comparator<I> comparator = new Comparator<I>()
{
- public int compare(UINode node1, UINode node2)
+ public int compare(I i1, I i2)
{
- UIObject object1 = node1.getObject();
- UIObject object2 = node2.getObject();
- Integer index1 = object1.getProperty(StateType.STRUCTURAL,
Constants.REGION_LAYOUT_INDEX, Integer.class);
- Integer index2 = object2.getProperty(StateType.STRUCTURAL,
Constants.REGION_LAYOUT_INDEX, Integer.class);
+ Integer index1 = adapter.getProperty(i1, Constants.REGION_LAYOUT_INDEX,
Integer.class);
+ Integer index2 = adapter.getProperty(i2, Constants.REGION_LAYOUT_INDEX,
Integer.class);
return index1.compareTo(index2);
}
};
Added:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/ModelLayoutAdapter.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/ModelLayoutAdapter.java
(rev 0)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/ModelLayoutAdapter.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.layout;
+
+import org.jboss.portal.presentation.model.UINode;
+import org.jboss.portal.presentation.model.ui.UIObject;
+import org.jboss.portal.presentation.state.StateType;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class ModelLayoutAdapter implements LayoutAdapter<UINode>
+{
+
+ public String getId(UINode item)
+ {
+ return item.getObject().getId();
+ }
+
+ public <T> T getProperty(UINode item, String propertyName, Class<T>
propertyType)
+ {
+ UIObject object = item.getObject();
+
+ //
+ return object.getProperty(StateType.STRUCTURAL, propertyName, propertyType);
+ }
+
+ public Collection<? extends UINode> getChildren(UINode item)
+ {
+ return item.getChildren();
+ }
+}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/RegionLayout.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/RegionLayout.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/RegionLayout.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -22,9 +22,8 @@
******************************************************************************/
package org.jboss.portal.presentation.layout;
-import org.jboss.portal.presentation.model.UINode;
-
import org.jboss.portal.common.util.CollectionMap;
+import org.jboss.portal.common.NotYetImplemented;
import java.util.Set;
import java.util.Collection;
@@ -33,13 +32,13 @@
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class RegionLayout implements Layout
+public class RegionLayout<I> implements Layout<I>
{
/** . */
- private final CollectionMap<String, UINode> map;
+ private final CollectionMap<String, I> map;
- RegionLayout(CollectionMap<String, UINode> map)
+ RegionLayout(CollectionMap<String, I> map)
{
this.map = map;
}
@@ -49,8 +48,13 @@
return map.keySet();
}
- public Collection<? extends UINode> getNodes(String regionName)
+ public Collection<? extends I> getItems(String regionName)
{
return map.get(regionName);
}
+
+ public Collection<? extends I> getItems()
+ {
+ throw new NotYetImplemented();
+ }
}
Modified:
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/SimpleLayout.java
===================================================================
---
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/SimpleLayout.java 2008-06-29
14:34:53 UTC (rev 11195)
+++
modules/presentation/trunk/presentation/src/main/java/org/jboss/portal/presentation/layout/SimpleLayout.java 2008-06-29
15:10:18 UTC (rev 11196)
@@ -22,24 +22,22 @@
******************************************************************************/
package org.jboss.portal.presentation.layout;
-import org.jboss.portal.presentation.model.UINode;
-
import java.util.Collection;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
* @version $Revision: 630 $
*/
-public class SimpleLayout implements Layout
+public class SimpleLayout<I> implements Layout<I>
{
/** . */
private final Orientation orientation;
/** . */
- private final Collection<? extends UINode> nodes;
+ private final Collection<? extends I> nodes;
- SimpleLayout(Orientation orientation, Collection<? extends UINode> nodes)
+ SimpleLayout(Orientation orientation, Collection<? extends I> nodes)
{
this.orientation = orientation;
this.nodes = nodes;
@@ -50,7 +48,7 @@
return orientation;
}
- public Collection<? extends UINode> getNodes()
+ public Collection<? extends I> getItems()
{
return nodes;
}