Author: woonsan
Date: Wed Dec 16 14:31:14 2009
New Revision: 891249
URL: http://svn.apache.org/viewvc?rev=891249&view=rev
Log:
JS2-1057: Adding logic to use least used column to add a portlet fragment
Modified:
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
Modified:
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js?rev=891249&r1=891248&r2=891249&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
(original)
+++
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/javascript/jetspeed/jetui/jetui-portal.js
Wed Dec 16 14:31:14 2009
@@ -126,7 +126,10 @@
* @method initializer
* @protected
*/
- initializer : function(cfg) {
+ initializer : function(cfg) {
+ this.portalContextPath = cfg.portalContextPath;
+ this.portalServletPath = cfg.portalServletPath;
+ this.portalPagePath = cfg.portalPagePath;
},
/**
@@ -437,6 +440,13 @@
});
/**
+ * The portal singleton instance
+ */
+ if (JETUI_YUI && !JETUI_YUI.portalInstance) {
+ JETUI_YUI.portalInstance = new Y.JetUI.Portal(JETUI_YUI.config);
+ }
+
+ /**
* Create a portlet window to represent a portal window.
*
* @class JetUI.Portlet
Modified:
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js?rev=891249&r1=891248&r2=891249&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
(original)
+++
portals/jetspeed-2/portal/trunk/applications/jetspeed/src/main/webapp/jetui/engine/portal.js
Wed Dec 16 14:31:14 2009
@@ -4,14 +4,7 @@
var config = JETUI_YUI.config;
Y.log("Starting up JETUI " + config.engine + " engine...");
- // initialize singleton portal instance
- if (!JETUI_YUI.portalInstance) {
- JETUI_YUI.portalInstance = new Y.JetUI.Portal();
- }
var portal = JETUI_YUI.portalInstance;
- portal.portalContextPath = config.portalContextPath;
- portal.portalServletPath = config.portalServletPath;
- portal.portalPagePath = config.portalPagePath;
////////////////////////////////////////////////////
// Create Navigator Portlet
Modified:
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
URL:
http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java?rev=891249&r1=891248&r2=891249&view=diff
==============================================================================
---
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
(original)
+++
portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/services/rest/PageLayoutService.java
Wed Dec 16 14:31:14 2009
@@ -25,6 +25,7 @@
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@@ -35,6 +36,7 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
+import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.jetspeed.JetspeedActions;
@@ -125,7 +127,10 @@
public ContentFragmentBean addContentFragment(@Context HttpServletRequest
servletRequest,
@Context UriInfo uriInfo,
@PathParam("type") String
fragmentType,
- @PathParam("name") String
fragmentName)
+ @PathParam("name") String
fragmentName,
+ @FormParam("row") String
rowParam,
+ @FormParam("col") String
colParam,
+ @FormParam("minrowscol")
String minRowsColumnParam)
{
if (StringUtils.isBlank(fragmentType) ||
StringUtils.isBlank(fragmentName))
{
@@ -135,15 +140,49 @@
RequestContext requestContext = (RequestContext)
servletRequest.getAttribute(RequestContext.REQUEST_PORTALENV);
ContentPage contentPage = getContentPage(requestContext,
JetspeedActions.EDIT);
+ int row = NumberUtils.toInt(rowParam, -1);
+ int col = NumberUtils.toInt(colParam, -1);
+ boolean minRowsColumn = BooleanUtils.toBoolean(minRowsColumnParam);
+
try
{
ContentFragment contentFragment =
pageLayoutComponent.addPortlet(contentPage, fragmentType, fragmentName);
+ String addedContentFragmentId = contentFragment.getId();
+
+ boolean needToAdjustPositions = false;
+
+ ContentFragment layoutFragment = null;
+ int columnCount = -1;
- if (contentFragment.getLayoutColumn() == -1 ||
contentFragment.getLayoutRow() == -1)
+ if (col == -1 && minRowsColumn)
{
- String addedContentFragmentId = contentFragment.getId();
- ContentFragment layoutFragment =
getParentFragment(pageLayoutComponent.getUnlockedRootFragment(contentPage),
addedContentFragmentId);
- int columnCount =
getColumnCountOfLayoutFragment(layoutFragment);
+ layoutFragment =
getParentFragment(pageLayoutComponent.getUnlockedRootFragment(contentPage),
addedContentFragmentId);
+ columnCount = getColumnCountOfLayoutFragment(layoutFragment);
+ col = getMinRowsColumnIndex(layoutFragment, columnCount);
+ }
+
+ if (row != -1 || col != -1)
+ {
+ pageLayoutComponent.updateRowColumn(contentFragment, row, col);
+ needToAdjustPositions = true;
+ }
+ else
+ {
+ needToAdjustPositions = (contentFragment.getLayoutColumn() ==
-1 || contentFragment.getLayoutRow() == -1);
+ }
+
+ if (needToAdjustPositions)
+ {
+ if (layoutFragment == null)
+ {
+ layoutFragment =
getParentFragment(pageLayoutComponent.getUnlockedRootFragment(contentPage),
addedContentFragmentId);
+ }
+
+ if (columnCount == -1)
+ {
+ columnCount =
getColumnCountOfLayoutFragment(layoutFragment);
+ }
+
adjustPositionsOfChildFragments(layoutFragment, columnCount);
}
@@ -407,6 +446,14 @@
return new DecorationBean(decoration);
}
+ /**
+ * Returns the content page of the current portal request context with
security check.
+ *
+ * @param requestContext the portal request context
+ * @param action the action to check the security against.
+ * @return
+ * @throws WebApplicationException
+ */
private ContentPage getContentPage(RequestContext requestContext, String
action) throws WebApplicationException
{
try
@@ -427,6 +474,12 @@
}
}
+ /**
+ * Returns the parent layout content fragment of the content fragment
specified by the fragmentId.
+ * @param contentFragment the seed content fragment where searching starts
from.
+ * @param fragmentId the fragment id of the content fragment, of which the
parent fragment is looked for.
+ * @return
+ */
private ContentFragment getParentFragment(ContentFragment contentFragment,
String fragmentId)
{
for (ContentFragment child : (List<ContentFragment>)
contentFragment.getFragments())
@@ -449,6 +502,11 @@
return null;
}
+ /**
+ * Returns the column count of the layout content fragment based on the
init parameters of the layout portlet.
+ * @param layoutFragment
+ * @return
+ */
private int getColumnCountOfLayoutFragment(ContentFragment layoutFragment)
{
int columnCount = 1;
@@ -483,6 +541,12 @@
return columnCount;
}
+ /**
+ * Returns child content fragment set array ordered by the column index
from the layout content fragment.
+ * @param layoutFragment
+ * @param columnCount
+ * @return
+ */
private SortedSet<ContentFragment> []
getSortedChildFragmentSetArray(ContentFragment layoutFragment, int columnCount)
{
if (columnCount <= 0)
@@ -513,6 +577,12 @@
return fragmentSetArray;
}
+ /**
+ * Adjusts the rows and cols of each content fragment contained in the
layout fragment.
+ * @param layoutFragment
+ * @param columnCount the column count of the layout fragment.
+ * @see #getColumnCountOfLayoutFragment(ContentFragment)
+ */
private void adjustPositionsOfChildFragments(ContentFragment
layoutFragment, int columnCount)
{
SortedSet<ContentFragment> [] fragmentSetArray =
getSortedChildFragmentSetArray(layoutFragment, columnCount);
@@ -533,6 +603,31 @@
}
}
+ private int getMinRowsColumnIndex(ContentFragment layoutFragment, int
columnCount)
+ {
+ SortedSet<ContentFragment> [] fragmentSetArray =
getSortedChildFragmentSetArray(layoutFragment, columnCount);
+ int col = fragmentSetArray.length - 1;
+
+ int rowCount = fragmentSetArray[col].size();
+
+ for (int i = fragmentSetArray.length - 2; i >= 0; i--)
+ {
+ if (fragmentSetArray[i].size() < rowCount)
+ {
+ col = i;
+ rowCount = fragmentSetArray[i].size();
+ }
+ }
+
+ return col;
+ }
+
+ /**
+ * ContentFragmentRowComparator
+ * <P>
+ * Comparator to compare content fragments by the row index in a column.
+ * </P>
+ */
private static class ContentFragmentRowComparator implements
Comparator<ContentFragment>
{
public int compare(ContentFragment f1, ContentFragment f2)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]