Author: julien(a)jboss.com
Date: 2007-03-15 07:06:18 -0400 (Thu, 15 Mar 2007)
New Revision: 6676
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/common/editPageLayout.xhtml
Log:
finished to implement the layout capabilities for the dashboard editor
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java 2007-03-15
05:19:32 UTC (rev 6675)
+++
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/common/PageManagerBean.java 2007-03-15
11:06:18 UTC (rev 6676)
@@ -26,6 +26,7 @@
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.admin.ui.actions.WindowComparator;
@@ -34,6 +35,8 @@
import org.jboss.portal.theme.PortalLayout;
import org.jboss.portal.theme.LayoutService;
import org.jboss.portal.faces.component.portlet.PortletActionEvent;
+import org.jboss.portal.faces.el.dynamic.DynamicBean;
+import org.jboss.portal.faces.el.PropertyValue;
import org.jboss.portal.portlet.PortletInvoker;
import javax.faces.model.SelectItem;
@@ -59,6 +62,15 @@
public class PageManagerBean
{
+ /** . */
+ private static final int MOVE_UP = 'u';
+
+ /** . */
+ private static final int MOVE_DOWN = 'd';
+
+ /** . */
+ private static final int MOVE_LEFT = 'l';
+
public PageManagerBean(LayoutService layoutService, PortletInvoker portletInvoker)
{
this.layoutService = layoutService;
@@ -78,6 +90,9 @@
/** . */
public ContentType selectedContentType;
+ /** . */
+ public DynamicMap assignedWindows = new DynamicMap();
+
public List getContentTypeItems()
{
LinkedList types = new LinkedList();
@@ -116,6 +131,80 @@
return "" + (int)(100 * Math.random());
}
+ public void assignWindows(ActionEvent event)
+ {
+ String id = event.getComponent().getId();
+ char direction = id.charAt(0);
+ String regionName = id.substring(2);
+
+ // Contains the names selected window in the UI
+ List selectedWindows = (List)assignedWindows.values.get(regionName);
+
+ // Get the windows belonging to the selected region sorted by order
+ List windows = new ArrayList();
+ for (Iterator i =
page.getChildren(PortalObject.WINDOW_MASK).iterator();i.hasNext();)
+ {
+ Window window = (Window)i.next();
+ if (regionName.equals(window.getProperty(ThemeConstants.PORTAL_PROP_REGION)))
+ {
+ windows.add(window);
+ }
+ }
+ Collections.sort(windows, new WindowComparator());
+
+ //
+ if (direction == MOVE_UP || direction == MOVE_DOWN)
+ {
+ //
+ int index = direction == MOVE_UP ? 1 : windows.size() - 2;
+ int length = windows.size() - 1;
+ int step = direction == MOVE_UP ? 1 : -1;
+
+ // Perform swaps
+ while (length-- > 0)
+ {
+ Window window = (Window)windows.get(index);
+ if (selectedWindows.contains(window.getName()))
+ {
+ Collections.swap(windows, index - step, index);
+ }
+ index += step;
+ }
+ }
+ else if (direction == MOVE_LEFT)
+ {
+ for (Iterator i = windows.iterator();i.hasNext();)
+ {
+ Window window = (Window)i.next();
+ if (selectedWindows.contains(window.getName()))
+ {
+ i.remove();
+ try
+ {
+ page.destroyChild(window.getName());
+ }
+ catch (NoSuchPortalObjectException ignore)
+ {
+ ignore.printStackTrace();
+ }
+ }
+ }
+ }
+
+ // Update the order states
+ for (int i = 0;i < windows.size();i++)
+ {
+ Window window = (Window)windows.get(i);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" + i);
+ }
+
+ //
+ assignedWindows.values.clear();
+ }
+
+ /**
+ * Portlet event
+ */
public void assignWindow(ActionEvent event)
{
if (event instanceof PortletActionEvent)
@@ -321,4 +410,33 @@
}
return windows;
}
+
+ public static class DynamicMap implements DynamicBean
+ {
+
+ /** . */
+ private Map values = new HashMap();
+
+ public Class getType(Object propertyName) throws IllegalArgumentException
+ {
+ return List.class;
+ }
+
+ public PropertyValue getValue(Object propertyName) throws IllegalArgumentException
+ {
+ List list = (List)values.get(propertyName);
+ if (list == null)
+ {
+ list = new ArrayList();
+ values.put(propertyName, list);
+ }
+ return new PropertyValue(list);
+ }
+
+ public boolean setValue(Object propertyName, Object value) throws
IllegalArgumentException
+ {
+ values.put(propertyName, value);
+ return true;
+ }
+ }
}
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/common/editPageLayout.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/common/editPageLayout.xhtml 2007-03-15
05:19:32 UTC (rev 6675)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/common/editPageLayout.xhtml 2007-03-15
11:06:18 UTC (rev 6676)
@@ -33,24 +33,24 @@
<td>
<div>
<h:commandButton value="Up"
id="u_#{regionName}"
-
actionListener="#{assignWindowsAction.execute}"
+
actionListener="#{pageManager.assignWindows}"
styleClass="portlet-form-button"/>
</div>
<div>
<h:commandButton value="Down"
id="d_#{regionName}"
-
actionListener="#{assignWindowsAction.execute}"
+
actionListener="#{pageManager.assignWindows}"
styleClass="portlet-form-button"/>
</div>
<div style="margin-top: 1em">
<h:commandButton
value="Delete" id="l_#{regionName}"
- actionListener="#{assignWindowsAction.execute}"
+ actionListener="#{pageManager.assignWindows}"
styleClass="portlet-form-button"/>
</div>
</td>
<td>
<h:selectManyListbox
-
value="#{assignWindowsAction.assignedWindows[regionName]}"
+ value="#{pageManager.assignedWindows[regionName]}"
size="7" styleClass="windowList
portlet-form-field">
<f:selectItems
value="#{pageManager.windowItemsMap[regionName]}"/>
@@ -70,13 +70,13 @@
<td>
<div style="margin-top: 1em">
<h:commandButton value="Delete"
- id="l_unknown"
actionListener="#{assignWindowsAction.execute}"
+ id="l_unknown"
actionListener="#{pageManager.assignWindows}"
styleClass="portlet-form-button"/>
</div>
</td>
<td>
<h:selectManyListbox
-
value="#{assignWindowsAction.assignedWindows['unknown']}"
+ value="#{pageManager.assignedWindows['unknown']}"
size="7" styleClass="windowList
portlet-form-field">
<f:selectItems
value="#{pageManager.windowItemsMap['unknown']}"/>