Author: thomas.heute(a)jboss.com
Date: 2007-10-22 09:09:16 -0400 (Mon, 22 Oct 2007)
New Revision: 8732
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/PageMetaData.java
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/WindowMetaData.java
Log:
JBPORTAL-1300: Let the user define an initial window-state and mode on a window by
specifying something lie:
<initial-window-state>maximized</initial-window-state>
<initial-mode>edit</initial-mode>
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/PageMetaData.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/PageMetaData.java 2007-10-22
10:25:33 UTC (rev 8731)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/PageMetaData.java 2007-10-22
13:09:16 UTC (rev 8732)
@@ -22,21 +22,28 @@
******************************************************************************/
package org.jboss.portal.core.model.portal.metadata;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.WindowState;
import org.jboss.portal.common.xml.XMLTools;
+import org.jboss.portal.core.model.content.spi.ContentProviderRegistry;
import org.jboss.portal.core.model.portal.PageContainer;
import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.content.spi.ContentProviderRegistry;
import org.w3c.dom.Element;
-import java.util.List;
-
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:theute@jboss.org">Thoams Heute</a>
* @version $Revision$
*/
public class PageMetaData extends PortalObjectMetaData
{
-
+ private static final Logger logger = Logger.getLogger(PageMetaData.class);
+
public PageMetaData()
{
}
@@ -75,6 +82,9 @@
e.printStackTrace();
}
}
+
+ // Log errors if any
+ checkConstraints(pageMD);
// Add the contained pages
List pageElts = XMLTools.getChildren(pageElt, "page");
@@ -95,6 +105,48 @@
//
return pageMD;
}
+
+ private static boolean checkConstraints(PageMetaData pageMD)
+ {
+ // Check that no more than 1 window has been defined as maximized
+ Collection values = pageMD.getChildren().values();
+ List maximizedWindows = new ArrayList();
+ if (values != null)
+ {
+ Iterator it = values.iterator();
+ while (it.hasNext())
+ {
+ PortalObjectMetaData poMetaData =(PortalObjectMetaData)it.next();
+ if (poMetaData instanceof WindowMetaData)
+ {
+ WindowMetaData windowMetaData = (WindowMetaData)poMetaData;
+ if
(WindowState.MAXIMIZED.toString().equals(windowMetaData.getInitialWindowState()))
+ {
+ maximizedWindows.add(windowMetaData);
+ if (maximizedWindows.size() > 1)
+ {
+ logger.debug("Set initial window state to NORMAL for window
'" + windowMetaData + "'");
+
windowMetaData.setInitialWindowState(WindowState.NORMAL.toString());
+ }
+ }
+ }
+ }
+ }
+ if (maximizedWindows.size() > 1)
+ {
+ StringBuffer windowsList = new StringBuffer();
+ Iterator it = maximizedWindows.iterator();
+ while (it.hasNext())
+ {
+ WindowMetaData windowMD = (WindowMetaData)it.next();
+ windowsList.append(windowMD.toString() + "\n");
+ }
+ logger.error("More than one window is defined as maximized for page
'" + pageMD.getName() + "'. The following windows" +
+ " have been defined as maximized:\n" + windowsList);
+ return false;
+ }
+ return true;
+ }
public String toString()
{
Modified:
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/WindowMetaData.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/WindowMetaData.java 2007-10-22
10:25:33 UTC (rev 8731)
+++
branches/JBoss_Portal_Branch_2_6/core/src/main/org/jboss/portal/core/model/portal/metadata/WindowMetaData.java 2007-10-22
13:09:16 UTC (rev 8732)
@@ -22,6 +22,9 @@
******************************************************************************/
package org.jboss.portal.core.model.portal.metadata;
+import org.jboss.logging.Logger;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.core.impl.model.portal.WindowImpl;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.Window;
@@ -37,13 +40,21 @@
*/
public class WindowMetaData extends PortalObjectMetaData
{
-
+
+ private static final Logger logger = Logger.getLogger(WindowMetaData.class);
+
/** The window region. */
protected String region;
/** The window order. */
protected int order;
+ /** The initial window state. */
+ protected String initialWindowState;
+
+ /** The initial window state. */
+ protected String initialMode;
+
/** The window content. */
protected ContentMetaData content;
@@ -89,7 +100,27 @@
{
this.contentType = contentType;
}
+
+ public String getInitialWindowState()
+ {
+ return initialWindowState;
+ }
+
+ public void setInitialWindowState(String initialWindowState)
+ {
+ this.initialWindowState = initialWindowState;
+ }
+ public String getInitialMode()
+ {
+ return initialMode;
+ }
+
+ public void setInitialMode(String initialMode)
+ {
+ this.initialMode = initialMode;
+ }
+
protected PortalObject newInstance(BuildContext buildContext, PortalObject parent)
throws Exception
{
if (!(parent instanceof Page))
@@ -103,7 +134,15 @@
//
window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION, region);
window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" +
order);
-
+ if (initialWindowState != null)
+ {
+ window.setDeclaredProperty(WindowImpl.PORTAL_INITIAL_WINDOW_STATE, ""
+ initialWindowState);
+ }
+ if (initialMode != null)
+ {
+ window.setDeclaredProperty(WindowImpl.PORTAL_INITIAL_MODE, "" +
initialMode);
+ }
+
//
return window;
}
@@ -120,6 +159,31 @@
String region = XMLTools.asString(XMLTools.getUniqueChild(windowElt,
"region", true));
windowMD.setRegion(region);
+ // Get initial window state
+ Element element = XMLTools.getUniqueChild(windowElt,
"initial-window-state", false);
+ if (element != null)
+ {
+ String initialWindowState = XMLTools.asString(element);
+ if (initialWindowState.toLowerCase().equals(WindowState.MAXIMIZED.toString())
+ ||
(initialWindowState.toLowerCase().equals(WindowState.MINIMIZED.toString()))
+ || (initialWindowState.toLowerCase().equals(WindowState.NORMAL.toString())))
+ {
+ windowMD.setInitialWindowState(initialWindowState);
+ }
+ else
+ {
+ logger.error("initial-window-state for '" + windowName +
"' must be one of 'MAXIMIZED', 'MINIMIZED' or
'NORMAL'");
+ }
+ }
+
+ // Get initial mode
+ element = XMLTools.getUniqueChild(windowElt, "initial-mode", false);
+ if (element != null)
+ {
+ String initialMode = XMLTools.asString(element);
+ windowMD.setInitialMode(initialMode);
+ }
+
//
int height = Integer.parseInt(XMLTools.asString(XMLTools.getUniqueChild(windowElt,
"height", true)));
windowMD.setOrder(height);