Author: julien(a)jboss.com
Date: 2007-02-27 11:31:00 -0500 (Tue, 27 Feb 2007)
New Revision: 6426
Added:
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/AssignWindowsAction.java
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/WindowComparator.java
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/PortalObjectManagerBean.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsp/management/editPageLayout.xhtml
Log:
layout manager redone using the dashboard editor technique
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/PortalObjectManagerBean.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/PortalObjectManagerBean.java 2007-02-27
16:24:11 UTC (rev 6425)
+++
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/PortalObjectManagerBean.java 2007-02-27
16:31:00 UTC (rev 6426)
@@ -842,6 +842,19 @@
}
}
+ public Map getWindowMap()
+ {
+ try
+ {
+ return getWindows((Page)getSelectedObject());
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return Collections.EMPTY_MAP;
+ }
+ }
+
/** Returns a <Region,<Window>SortedSet>Map. */
private Map getWindows(Page page) throws Exception
{
@@ -877,18 +890,49 @@
}
/** Return the <Region>List on the selected object which must be a page. */
- public List getCols() throws Exception
+ public List getCols()
{
- Map windows = getWindows((Page)getSelectedObject());
+ try
+ {
+ Map windows = getWindows((Page)getSelectedObject());
- //
- List regions = new ArrayList(windows.keySet());
- Collections.sort(regions);
+ //
+ List regions = new ArrayList(windows.keySet());
+ Collections.sort(regions);
- //
- return regions;
+ //
+ return regions;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ //
+ return Collections.EMPTY_LIST;
+ }
}
+ public Map getWindowItemsMap() throws Exception
+ {
+ Map windowMap = getWindows((Page)getSelectedObject());
+ for (Iterator i = windowMap.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ SortedSet windows = (SortedSet)entry.getValue();
+ ArrayList windowItems = new ArrayList(windows.size());
+ for (Iterator j = windows.iterator();j.hasNext();)
+ {
+ Window window = (Window)j.next();
+ SelectItem windowItem = new SelectItem();
+ windowItem.setValue(window.getName());
+ windowItem.setLabel(window.getName());
+ windowItems.add(windowItem);
+ }
+ entry.setValue(windowItems);
+ }
+ return windowMap;
+ }
+
public List getRegionItems() throws Exception
{
List list = getCols();
Added:
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/AssignWindowsAction.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/AssignWindowsAction.java
(rev 0)
+++
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/AssignWindowsAction.java 2007-02-27
16:31:00 UTC (rev 6426)
@@ -0,0 +1,282 @@
+/******************************************************************************
+ * 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.core.portlet.management.actions;
+
+import org.jboss.portal.faces.el.dynamic.DynamicBean;
+import org.jboss.portal.faces.el.PropertyValue;
+import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.portlet.management.PortalObjectManagerBean;
+import org.jboss.portal.theme.ThemeConstants;
+
+import javax.faces.event.ActionEvent;
+import javax.faces.context.FacesContext;
+import javax.faces.application.FacesMessage;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class AssignWindowsAction
+{
+
+ /** . */
+ private static final int MOVE_UP = 'u';
+
+ /** . */
+ private static final int MOVE_DOWN = 'd';
+
+ /** . */
+ private static final int MOVE_LEFT = 'l';
+
+ /** . */
+ private static final int MOVE_RIGHT = 'r';
+
+ /** . */
+ private DynamicMap assignedWindows = new DynamicMap();
+
+ /** . */
+ private String windowName;
+
+ /** . */
+ private PortalObjectManagerBean pomgr;
+
+ /** . */
+ private ContentType contentType;
+
+ /** . */
+ private String contentURI;
+
+ public DynamicMap getAssignedWindows()
+ {
+ return assignedWindows;
+ }
+
+ public PortalObjectManagerBean getPortalObjectManager()
+ {
+ return pomgr;
+ }
+
+ public void setPortalObjectManager(PortalObjectManagerBean portalObjectManager)
+ {
+ this.pomgr = portalObjectManager;
+ }
+
+ public String getWindowName()
+ {
+ return windowName;
+ }
+
+ public void setWindowName(String windowName)
+ {
+ this.windowName = windowName;
+ }
+
+ public void execute(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);
+
+ //
+ Page page = (Page)pomgr.getSelectedObject();
+
+ // 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();
+ }
+ }
+ }
+ }
+ else if (direction == MOVE_RIGHT)
+ {
+ //
+ if (validateAddWindow())
+ {
+ try
+ {
+ ContentType contentType = pomgr.getSelectedContentType();
+ String contentURI = pomgr.getSelectedContentURI();
+
+ //
+ Window window = page.createWindow(windowName, contentType, contentURI);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION,
regionName);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, ""
+ Integer.MAX_VALUE);
+ windows.add(window);
+ }
+ catch (DuplicatePortalObjectException unexpected)
+ {
+ unexpected.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);
+ }
+ }
+
+ /**
+ * Checks for duplicate window names on the page. Blank window names are not allowed
and are
+ * controlled by the required attribute in the presentation page.
+ */
+ public boolean validateAddWindow()
+ {
+ if (windowName == null)
+ {
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No
window name!", null);
+ FacesContext.getCurrentInstance().addMessage("windowName", message);
+ return false;
+ }
+
+ // Trim name
+ windowName = windowName.trim();
+
+ // Check for empty string
+ if (windowName.length() == 0)
+ {
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Window name cannot be blank!", null);
+ FacesContext.getCurrentInstance().addMessage("windowName", message);
+ return false;
+ }
+
+ // Check for duplicate window name
+ Page page = (Page)pomgr.getSelectedObject();
+ if (page.getWindow(windowName) != null)
+ {
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Duplicate window name found on this page!", null);
+ FacesContext.getCurrentInstance().addMessage("windowName", message);
+ return false;
+ }
+
+ //
+ contentType = pomgr.getSelectedContentType();
+ if (contentType == null)
+ {
+ FacesMessage message = new FacesMessage("No content type provided!",
null);
+ FacesContext.getCurrentInstance().addMessage("instanceId", message);
+ return false;
+ }
+
+ //
+ contentURI = pomgr.getSelectedContentURI();
+ if (contentURI == null)
+ {
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No
portlet selected!", null);
+ FacesContext.getCurrentInstance().addMessage("instanceId", message);
+ return false;
+ }
+
+ //
+ return true;
+ }
+
+ 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;
+ }
+ }
+}
Added:
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/WindowComparator.java
===================================================================
---
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/WindowComparator.java
(rev 0)
+++
trunk/core-admin/src/main/org/jboss/portal/core/portlet/management/actions/WindowComparator.java 2007-02-27
16:31:00 UTC (rev 6426)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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.core.portlet.management.actions;
+
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.theme.ThemeConstants;
+
+import java.util.Comparator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowComparator implements Comparator
+{
+
+ public int compare(Object o1, Object o2)
+ {
+ Window w1 = (Window)o1;
+ Window w2 = (Window)o2;
+ int sign = getOrder(w1) - getOrder(w2);
+ if (sign == 0)
+ {
+ sign = 1;
+ // sign = w1.getId().compareTo(w2.getId());
+ }
+
+ return sign;
+ }
+
+ private static int getOrder(Window w)
+ {
+ try
+ {
+ return
Integer.parseInt(w.getDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER));
+ }
+ catch (NumberFormatException e)
+ {
+ return Integer.MAX_VALUE;
+ }
+ }
+}
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml 2007-02-27
16:24:11 UTC (rev 6425)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/faces-config.xml 2007-02-27
16:31:00 UTC (rev 6426)
@@ -99,6 +99,15 @@
</managed-property>
</managed-bean>
<managed-bean>
+ <managed-bean-name>assignWindowsAction</managed-bean-name>
+
<managed-bean-class>org.jboss.portal.core.portlet.management.actions.AssignWindowsAction</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>portalObjectManager</property-name>
+ <value>#{sessionScope.portalobjectmgr}</value>
+ </managed-property>
+ </managed-bean>
+ <managed-bean>
<managed-bean-name>themePropertyAction</managed-bean-name>
<managed-bean-class>org.jboss.portal.core.portlet.management.actions.ThemePropertyAction</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
Modified:
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsp/management/editPageLayout.xhtml
===================================================================
---
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsp/management/editPageLayout.xhtml 2007-02-27
16:24:11 UTC (rev 6425)
+++
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsp/management/editPageLayout.xhtml 2007-02-27
16:31:00 UTC (rev 6426)
@@ -4,7 +4,8 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
- xmlns:ct="http://www.julien.com">
+ xmlns:ct="http://www.julien.com"
+
xmlns:c="http://java.sun.com/jstl/core">
<ui:composition template="/WEB-INF/jsp/management/objectTemplate.xhtml">
@@ -16,74 +17,78 @@
<hr />
- <h:form id="page_form_2">
- <t:dataTable
- id="data"
- var="row"
- value="#{portalobjectmgr.rows}"
- border="1">
- <t:columns value="#{portalobjectmgr.cols}"
var="col">
- <f:facet name="header">
- <h:outputText value="#{col}"/>
- </f:facet>
- <h:commandLink rendered="#{row[col] != null}"
action="#{portalobjectmgr.moveUp}">
- <f:param name="id" value="#{row[col].id}"/>
- <h:graphicImage value="/images/management/up.png"
style="vertical-align:middle;border-width:0"/>
- </h:commandLink>
- <h:commandLink rendered="#{row[col] != null}"
action="#{portalobjectmgr.moveDown}">
- <f:param name="id" value="#{row[col].id}"/>
- <h:graphicImage value="/images/management/down.png"
style="vertical-align:middle;border-width:0"/>
- </h:commandLink>
- <h:commandLink rendered="#{row[col] != null}"
action="#{portalobjectmgr.moveLeft}">
- <f:param name="id" value="#{row[col].id}"/>
- <h:graphicImage value="/images/management/left.png"
style="vertical-align:middle;border-width:0"/>
- </h:commandLink>
- <h:commandLink rendered="#{row[col] != null}"
action="#{portalobjectmgr.moveRight}">
- <f:param name="id" value="#{row[col].id}"/>
- <h:graphicImage value="/images/management/right.png"
style="vertical-align:middle;border-width:0"/>
- </h:commandLink>
- <h:commandLink rendered="#{row[col] != null}"
action="#{portalobjectmgr.selectObject}">
- <f:param name="id" value="#{row[col].id}"/>
- <h:outputText value="#{row[col].name}"/>
- </h:commandLink>
- </t:columns>
- </t:dataTable>
-
- </h:form>
-
- <!-- -->
-
- <hr />
-
- <h:form id="page_form_3">
- <h:message for="windowName" style="color: red"/>
- <br />
- <br />
- <h:selectOneMenu
- value="#{portalobjectmgr.selectedContentType}">
- <f:selectItems value="#{registry.availableTypes}"/>
- </h:selectOneMenu>
- <h:commandButton
- value="Change content type"
styleClass="portlet-form-button"/>
- <ct:content
- contentType="#{portalobjectmgr.selectedContentType}"
- contentURI="#{portalobjectmgr.selectedContentURI}"/>
-
- <br/>
-
+ <h:form>
<h:panelGroup>
- <h:outputLabel for="windowName">
- <h:outputText value="New Window Name: "
style="font-weight:bold;"/>
- </h:outputLabel>
- <h:inputText id="windowName"
value="#{addWindowAction.windowName}"
- validator="#{addWindowAction.validateWindowName}"
- required="true"/>
- <h:selectOneMenu value="#{addWindowAction.regionName}">
- <f:selectItems
value="#{portalobjectmgr.regionItems}"></f:selectItems>
- </h:selectOneMenu>
- <h:commandButton value="Add window"
action="#{addWindowAction.execute}"
styleClass="portlet-form-button"/>
+ <table>
+ <tr>
+ <td>
+ <table>
+ <tr>
+ <td>
+ <h:selectOneMenu
+ id="instanceId"
+
value="#{portalobjectmgr.selectedContentType}">
+ <f:selectItems
value="#{registry.availableTypes}"/>
+ </h:selectOneMenu>
+ <h:message for="instanceId"/>
+ <h:commandButton value="Change content type"
styleClass="portlet-form-button"/>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <ct:content
+
contentType="#{portalobjectmgr.selectedContentType}"
+
contentURI="#{portalobjectmgr.selectedContentURI}"/>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <h:outputLabel for="windowName">
+ <h:outputText value="Window Name: "
style="font-weight:bold;"/>
+ </h:outputLabel>
+ <h:inputText id="windowName"
value="#{assignWindowsAction.windowName}"/>
+ <h:message for="windowName"/>
+ </td>
+ </tr>
+ </table>
+ </td>
+ <td>
+ <c:forEach items="#{portalobjectmgr.cols}"
var="regionName">
+ <table>
+ <tr>
+ <td colspan="3">#{regionName}
Column</td>
+ </tr>
+ <tr>
+ <td>
+ <div>
+ <h:commandButton value="<-"
id="l_#{regionName}" actionListener="#{assignWindowsAction.execute}"
styleClass="portlet-form-button"/>
+ </div>
+ <div>
+ <h:commandButton value="->"
id="r_#{regionName}" actionListener="#{assignWindowsAction.execute}"
styleClass="portlet-form-button"/>
+ </div>
+ </td>
+ <td>
+ <h:selectManyListbox
+
value="#{assignWindowsAction.assignedWindows[regionName]}"
+ size="7">
+ <f:selectItems
value="#{portalobjectmgr.windowItemsMap[regionName]}"/>
+ </h:selectManyListbox>
+ </td>
+ <td>
+ <div>
+ <h:commandButton value="Up"
id="u_#{regionName}" actionListener="#{assignWindowsAction.execute}"
styleClass="portlet-form-button"/>
+ </div>
+ <div>
+ <h:commandButton value="Down"
id="d_#{regionName}" actionListener="#{assignWindowsAction.execute}"
styleClass="portlet-form-button"/>
+ </div>
+ </td>
+ </tr>
+ </table>
+ </c:forEach>
+ </td>
+ </tr>
+ </table>
</h:panelGroup>
-
</h:form>
</ui:define>