You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by sm...@apache.org on 2006/10/06 06:08:54 UTC
svn commit: r453487 - in
/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl:
Constants.java MovePortletAction.java PortletPlacementContextImpl.java
Author: smilek
Date: Thu Oct 5 21:08:54 2006
New Revision: 453487
URL: http://svn.apache.org/viewvc?view=rev&rev=453487
Log:
changed ajax-api move action to support moving portlets between different layout fragments
Modified:
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java?view=diff&rev=453487&r1=453486&r2=453487
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/Constants.java Thu Oct 5 21:08:54 2006
@@ -29,6 +29,7 @@
public static final String REASON = "reason";
public static final String PORTLETID = "id";
public static final String PORTLETENTITY = "entity";
+ public static final String LAYOUTID = "layoutid";
public static final String WINDOW_STATE = "state";
public static final String PORTLET_MODE = "mode";
public static final String OLD_WINDOW_STATE = "oldState";
Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java?view=diff&rev=453487&r1=453486&r2=453487
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/MovePortletAction.java Thu Oct 5 21:08:54 2006
@@ -15,7 +15,9 @@
*/
package org.apache.jetspeed.layout.impl;
+import java.util.List;
import java.util.Map;
+import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -118,11 +120,55 @@
resultMap.put(ACTION, sMoveType);
// Get the necessary parameters off of the request
String portletId = requestContext.getRequestParameter(PORTLETID);
+ String layoutId = requestContext.getRequestParameter(LAYOUTID);
if (portletId == null)
{
throw new Exception("portlet id not provided");
- }
- resultMap.put(PORTLETID, portletId);
+ }
+ resultMap.put(PORTLETID, portletId);
+
+ Fragment currentLayoutFragment = null;
+ Fragment moveToLayoutFragment = null;
+ // when layoutId is null we use old behavior, ignoring everything to do with multiple layout fragments
+ if ( layoutId != null && iMoveType != CARTESIAN )
+ {
+ Page page = requestContext.getPage();
+ currentLayoutFragment = page.getFragmentById( layoutId );
+ if ( currentLayoutFragment == null )
+ {
+ throw new Exception("layout id not found: " + layoutId );
+ }
+ else
+ {
+ // determine if layoutId parameter refers to the current or the move target layout fragment
+ moveToLayoutFragment = currentLayoutFragment;
+ Iterator layoutChildIter = moveToLayoutFragment.getFragments().iterator();
+ while ( layoutChildIter.hasNext() )
+ {
+ Fragment childFrag = (Fragment)layoutChildIter.next();
+ if ( childFrag != null )
+ {
+ if ( portletId.equals( childFrag.getId() ) )
+ {
+ moveToLayoutFragment = null;
+ break;
+ }
+ }
+ }
+ if ( moveToLayoutFragment != null )
+ {
+ // figure out the current layout fragment - must know to be able to find the portlet
+ // fragment by row/col when a new page is created
+ currentLayoutFragment = getParentFragmentById( portletId, requestContext );
+ }
+ }
+ if ( currentLayoutFragment == null )
+ {
+ // report error
+ throw new Exception("parent layout id not found for portlet id:" + portletId );
+ }
+ }
+
if (false == checkAccess(requestContext, JetspeedActions.EDIT))
{
Page page = requestContext.getPage();
@@ -131,10 +177,27 @@
{
success = false;
resultMap.put(REASON, "Fragment not found");
- return success;
+ return success;
}
+
+ // remember current row/column of porlet fragment
int column = fragment.getLayoutColumn();
- int row = fragment.getLayoutRow();
+ int row = fragment.getLayoutRow();
+
+ // rememeber current row/column of parent layout fragment and move-to layout fragment
+ int layoutColumn = -1, layoutRow = -1;
+ int moveToLayoutColumn = -1, moveToLayoutRow = -1;
+ if ( currentLayoutFragment != null )
+ {
+ layoutColumn = currentLayoutFragment.getLayoutColumn();
+ layoutRow = currentLayoutFragment.getLayoutRow();
+ if ( moveToLayoutFragment != null )
+ {
+ moveToLayoutColumn = moveToLayoutFragment.getLayoutColumn();
+ moveToLayoutRow = moveToLayoutFragment.getLayoutRow();
+ }
+ }
+
if (!createNewPageOnEdit(requestContext))
{
success = false;
@@ -142,108 +205,67 @@
return success;
}
status = "refresh";
+
// translate old portlet id to new portlet id
Fragment newFragment = getFragmentIdFromLocation(row, column, requestContext.getPage());
if (newFragment == null)
{
success = false;
- resultMap.put(REASON, "Failed to find new fragment");
+ resultMap.put( REASON, "Failed to find new fragment for portlet id: " + portletId );
return success;
- }
+ }
portletId = newFragment.getId();
- }
- PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext);
- Fragment fragment = placement.getFragmentById(portletId);
- Coordinate returnCoordinate = null;
- float oldX = 0f, oldY = 0f, oldZ = 0f, oldWidth = 0f, oldHeight = 0f;
- float x = -1f, y = -1f, z = -1f, width = -1f, height = -1f;
-
- // Only required for moveabs
- if (iMoveType == ABS)
- {
- String a_sCol = requestContext.getRequestParameter(COL);
- String a_sRow = requestContext.getRequestParameter(ROW);
-
- // Convert the col and row into integers
- int a_iCol = Integer.parseInt(a_sCol);
- int a_iRow = Integer.parseInt(a_sRow);
-
- Coordinate a_oCoordinate = new CoordinateImpl(0, 0, a_iCol,
- a_iRow);
- returnCoordinate = placement.moveAbsolute(fragment, a_oCoordinate);
- }
- else if (iMoveType == LEFT)
- {
- returnCoordinate = placement.moveLeft(fragment);
- }
- else if (iMoveType == RIGHT)
- {
- returnCoordinate = placement.moveRight(fragment);
- }
- else if (iMoveType == UP)
- {
- returnCoordinate = placement.moveUp(fragment);
- }
- else if (iMoveType == DOWN)
- {
- returnCoordinate = placement.moveDown(fragment);
- }
- else if (iMoveType == CARTESIAN)
- {
- String sx = requestContext.getRequestParameter(X);
- String sy = requestContext.getRequestParameter(Y);
- String sz = requestContext.getRequestParameter(Z);
- String sWidth = requestContext.getRequestParameter(WIDTH);
- String sHeight = requestContext.getRequestParameter(HEIGHT);
- if (sx != null)
- {
- oldX = fragment.getLayoutX();
- x = Float.parseFloat(sx);
- fragment.setLayoutX(x);
- }
- if (sy != null)
- {
- oldY = fragment.getLayoutY();
- y = Float.parseFloat(sy);
- fragment.setLayoutY(y);
- }
- if (sz != null)
- {
- oldZ = fragment.getLayoutZ();
- z = Float.parseFloat(sz);
- fragment.setLayoutZ(z);
- }
- if (sWidth != null)
- {
- oldWidth = fragment.getLayoutWidth();
- width = Float.parseFloat(sWidth);
- fragment.setLayoutWidth(width);
- }
- if (sHeight != null)
- {
- oldHeight = fragment.getLayoutHeight();
- height = Float.parseFloat(sHeight);
- fragment.setLayoutHeight(height);
- }
+
+ if ( currentLayoutFragment != null )
+ {
+ newFragment = getFragmentIdFromLocation(layoutRow, layoutColumn, requestContext.getPage());
+ if (newFragment == null)
+ {
+ success = false;
+ resultMap.put( REASON, "Failed to find new parent layout fragment id: " + currentLayoutFragment.getId() + " for portlet id: " + portletId );
+ return success;
+ }
+ currentLayoutFragment = newFragment;
+ if ( moveToLayoutFragment != null )
+ {
+ newFragment = getFragmentIdFromLocation(moveToLayoutRow, moveToLayoutColumn, requestContext.getPage());
+ if (newFragment == null)
+ {
+ success = false;
+ resultMap.put( REASON, "Failed to find new move-to layout fragment id: " + moveToLayoutFragment.getId() + " for portlet id: " + portletId );
+ return success;
+ }
+ moveToLayoutFragment = newFragment;
+ }
+ }
}
- // synchronize back to the page layout root fragment
- Page page = placement.syncPageFragments();
-
- if (pageManager != null)
- pageManager.updatePage(page);
- resultMap.put(STATUS, status);
- resultMap.put(PORTLETID, portletId);
- if (iMoveType == CARTESIAN)
- {
- putCartesianResult(resultMap, x, oldX, X, OLD_X);
- putCartesianResult(resultMap, y, oldY, Y, OLD_Y);
- putCartesianResult(resultMap, z, oldZ, Z, OLD_Z);
- putCartesianResult(resultMap, width, oldWidth, WIDTH, OLD_WIDTH);
- putCartesianResult(resultMap, height, oldHeight, HEIGHT, OLD_HEIGHT);
- }
- else
+ if ( moveToLayoutFragment != null )
{
+ // remove fragment
+ PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext, currentLayoutFragment, 1);
+ Fragment fragment = placement.getFragmentById(portletId);
+ if (fragment == null)
+ {
+ success = false;
+ resultMap.put(REASON, "Failed to find fragment to move to another layout for portlet id: " + portletId );
+ return success;
+ }
+ placement.remove(fragment);
+ Page page = placement.syncPageFragments();
+ page.removeFragmentById(fragment.getId());
+ if (pageManager != null)
+ pageManager.updatePage(page);
+
+ // add fragment
+ placement = new PortletPlacementContextImpl(requestContext, moveToLayoutFragment, 1);
+ Coordinate returnCoordinate = placement.add(fragment, getCoordinateFromParams(requestContext));
+ page = placement.syncPageFragments();
+
+ moveToLayoutFragment.getFragments().add(fragment);
+ if (pageManager != null)
+ pageManager.updatePage(page);
+
// Need to determine what the old col and row were
resultMap.put(OLDCOL, String.valueOf(returnCoordinate
.getOldCol()));
@@ -253,8 +275,121 @@
resultMap.put(NEWCOL, String.valueOf(returnCoordinate
.getNewCol()));
resultMap.put(NEWROW, String.valueOf(returnCoordinate
- .getNewRow()));
+ .getNewRow()));
+ }
+ else
+ {
+ PortletPlacementContext placement = null;
+ if ( currentLayoutFragment != null )
+ placement = new PortletPlacementContextImpl(requestContext, currentLayoutFragment, 1);
+ else
+ {
+ placement = new PortletPlacementContextImpl(requestContext);
+ }
+ Fragment fragment = placement.getFragmentById(portletId);
+ if (fragment == null)
+ {
+ success = false;
+ resultMap.put(REASON, "Failed to find fragment for portlet id: " + portletId );
+ return success;
+ }
+ Coordinate returnCoordinate = null;
+ float oldX = 0f, oldY = 0f, oldZ = 0f, oldWidth = 0f, oldHeight = 0f;
+ float x = -1f, y = -1f, z = -1f, width = -1f, height = -1f;
+
+ // Only required for moveabs
+ if (iMoveType == ABS)
+ {
+ Coordinate a_oCoordinate = getCoordinateFromParams(requestContext);
+ returnCoordinate = placement.moveAbsolute(fragment, a_oCoordinate);
+ }
+ else if (iMoveType == LEFT)
+ {
+ returnCoordinate = placement.moveLeft(fragment);
+ }
+ else if (iMoveType == RIGHT)
+ {
+ returnCoordinate = placement.moveRight(fragment);
+ }
+ else if (iMoveType == UP)
+ {
+ returnCoordinate = placement.moveUp(fragment);
+ }
+ else if (iMoveType == DOWN)
+ {
+ returnCoordinate = placement.moveDown(fragment);
+ }
+ else if (iMoveType == CARTESIAN)
+ {
+ String sx = requestContext.getRequestParameter(X);
+ String sy = requestContext.getRequestParameter(Y);
+ String sz = requestContext.getRequestParameter(Z);
+ String sWidth = requestContext.getRequestParameter(WIDTH);
+ String sHeight = requestContext.getRequestParameter(HEIGHT);
+ if (sx != null)
+ {
+ oldX = fragment.getLayoutX();
+ x = Float.parseFloat(sx);
+ fragment.setLayoutX(x);
+ }
+ if (sy != null)
+ {
+ oldY = fragment.getLayoutY();
+ y = Float.parseFloat(sy);
+ fragment.setLayoutY(y);
+ }
+ if (sz != null)
+ {
+ oldZ = fragment.getLayoutZ();
+ z = Float.parseFloat(sz);
+ fragment.setLayoutZ(z);
+ }
+ if (sWidth != null)
+ {
+ oldWidth = fragment.getLayoutWidth();
+ width = Float.parseFloat(sWidth);
+ fragment.setLayoutWidth(width);
+ }
+ if (sHeight != null)
+ {
+ oldHeight = fragment.getLayoutHeight();
+ height = Float.parseFloat(sHeight);
+ fragment.setLayoutHeight(height);
+ }
+
+ }
+ // synchronize back to the page layout root fragment
+ Page page = placement.syncPageFragments();
+
+ if (pageManager != null)
+ {
+ pageManager.updatePage(page);
+ }
+
+ if (iMoveType == CARTESIAN)
+ {
+ putCartesianResult(resultMap, x, oldX, X, OLD_X);
+ putCartesianResult(resultMap, y, oldY, Y, OLD_Y);
+ putCartesianResult(resultMap, z, oldZ, Z, OLD_Z);
+ putCartesianResult(resultMap, width, oldWidth, WIDTH, OLD_WIDTH);
+ putCartesianResult(resultMap, height, oldHeight, HEIGHT, OLD_HEIGHT);
+ }
+ else
+ {
+ // Need to determine what the old col and row were
+ resultMap.put(OLDCOL, String.valueOf(returnCoordinate
+ .getOldCol()));
+ resultMap.put(OLDROW, String.valueOf(returnCoordinate
+ .getOldRow()));
+ // Need to determine what the new col and row were
+ resultMap.put(NEWCOL, String.valueOf(returnCoordinate
+ .getNewCol()));
+ resultMap.put(NEWROW, String.valueOf(returnCoordinate
+ .getNewRow()));
+ }
}
+ resultMap.put(STATUS, status);
+ resultMap.put(PORTLETID, portletId);
}
catch (Exception e)
{
@@ -267,6 +402,20 @@
return success;
}
+
+ protected Coordinate getCoordinateFromParams(RequestContext requestContext)
+ {
+ String a_sCol = requestContext.getRequestParameter(COL);
+ String a_sRow = requestContext.getRequestParameter(ROW);
+
+ // Convert the col and row into integers
+ int a_iCol = Integer.parseInt(a_sCol);
+ int a_iRow = Integer.parseInt(a_sRow);
+
+ Coordinate a_oCoordinate = new CoordinateImpl(0, 0, a_iCol,
+ a_iRow);
+ return a_oCoordinate;
+ }
protected void putCartesianResult(Map resultMap, float value, float oldValue, String name, String oldName)
{
@@ -275,5 +424,46 @@
resultMap.put(oldName, new Float(oldValue));
resultMap.put(name, new Float(value));
}
- }
+ }
+ public Fragment getParentFragmentById( String id, RequestContext requestContext )
+ {
+ if ( id == null )
+ {
+ return null;
+ }
+ Fragment root = requestContext.getPage().getRootFragment();
+ return searchForParentFragmentById( id, root );
+ }
+
+ protected Fragment searchForParentFragmentById( String id, Fragment parent )
+ {
+ // find fragment by id, tracking fragment parent
+ Fragment matchedParent = null;
+ if( parent != null )
+ {
+ // process the children
+ List children = parent.getFragments();
+ for( int i = 0, cSize = children.size() ; i < cSize ; i++)
+ {
+ Fragment childFrag = (Fragment)children.get( i );
+ if ( childFrag != null )
+ {
+ if ( id.equals( childFrag.getId() ) )
+ {
+ matchedParent = parent;
+ break;
+ }
+ else
+ {
+ matchedParent = searchForParentFragmentById( id, childFrag );
+ if ( matchedParent != null )
+ {
+ break;
+ }
+ }
+ }
+ }
+ }
+ return matchedParent;
+ }
}
Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java?view=diff&rev=453487&r1=453486&r2=453487
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java Thu Oct 5 21:08:54 2006
@@ -60,6 +60,8 @@
{
private static final String COLUMN = "column";
private static final String ROW = "row";
+
+ private static final int NO_DEPTH_LIMIT = -1;
/** Logger */
private Log log = LogFactory.getLog(PortletPlacementContextImpl.class);
@@ -90,24 +92,34 @@
protected int numberOfColumns = -1;
protected Page page;
- protected Fragment root;
+ protected Fragment containerFragment;
public PortletPlacementContextImpl(RequestContext requestContext)
throws PortletPlacementException
{
- init(requestContext);
+ init(requestContext, null, NO_DEPTH_LIMIT);
}
+
+ public PortletPlacementContextImpl(RequestContext requestContext, Fragment container, int maxdepth)
+ throws PortletPlacementException
+ {
+ init(requestContext, container, maxdepth);
+ }
// Initialize the data structures by getting the fragments
// from the page manager
- protected void init(RequestContext requestContext)
+ protected void init(RequestContext requestContext, Fragment container, int maxdepth)
throws PortletPlacementException
{
this.page = requestContext.getPage();
- this.root = page.getRootFragment();
+ if ( container == null )
+ {
+ container = page.getRootFragment();
+ }
+ this.containerFragment = container;
// Recursively process each fragment
- processFragment(root);
+ processFragment(container, maxdepth);
// The final step is to populate the array with the fragments
populateArray();
@@ -119,7 +131,7 @@
* Evaluate each portlet fragment and populate the internal data
* structures
*/
- protected void processFragment(Fragment fragment)
+ protected void processFragment(Fragment fragment, int remainingDepth)
throws PortletPlacementException
{
int rowCount = 0;
@@ -142,16 +154,19 @@
rowCount++;
}
- // Process the children
- List children = fragment.getFragments();
- for(int ix = 0; ix < children.size(); ix++)
+ if ( remainingDepth == NO_DEPTH_LIMIT || remainingDepth > 0 )
{
- Fragment childFrag = (Fragment)children.get(ix);
-
- if(childFrag != null)
+ // Process the children
+ List children = fragment.getFragments();
+ for(int ix = 0; ix < children.size(); ix++)
{
- processFragment(childFrag);
- }
+ Fragment childFrag = (Fragment)children.get(ix);
+
+ if(childFrag != null)
+ {
+ processFragment(childFrag, ((remainingDepth == NO_DEPTH_LIMIT) ? NO_DEPTH_LIMIT : remainingDepth-1) );
+ }
+ }
}
}
}
@@ -175,7 +190,7 @@
//root.getFragments().add(fragment);
}
}
- return root;
+ return containerFragment;
}
/**
@@ -328,6 +343,32 @@
return column;
}
+ public int addColumns( int col )
+ throws PortletPlacementException
+ {
+ if ( col > this.numberOfColumns )
+ {
+ if ( col < 100 ) // arbitrary limit of columns
+ {
+ // expand
+ int prevNumberOfColumns = this.numberOfColumns;
+ this.numberOfColumns = col + 1;
+
+ Vector [] temp = new Vector[this.numberOfColumns];
+ for (int ix = 0; ix < prevNumberOfColumns; ix++)
+ temp[ix] = this.columnsList[ix];
+ for (int ix = prevNumberOfColumns; ix < temp.length; ix++)
+ temp[ix] = new Vector();
+ this.columnsList = temp;
+ }
+ else
+ {
+ throw new PortletPlacementException( "cannot add column - " + col + " is above the limit of columns that this api supports" );
+ }
+ }
+ return col;
+ }
+
public Coordinate add(Fragment fragment, Coordinate coordinate) throws PortletPlacementException
{
int col = coordinate.getNewCol();
@@ -340,15 +381,8 @@
col = 0;
}
if (col > this.numberOfColumns)
- {
- // expand
- this.numberOfColumns++;
- col = this.numberOfColumns - 1;
- Vector [] temp = new Vector[this.numberOfColumns];
- for (int ix = 0; ix < this.numberOfColumns - 1; ix++)
- temp[ix] = this.columnsList[ix];
- temp[col] = new Vector();
- this.columnsList = temp;
+ {
+ col = addColumns( col );
}
Vector column = this.columnsList[col];
@@ -504,6 +538,11 @@
// The next two lines must occur after the remove above. This is
// because the new and old columns might be the same and the remove
// will change the number of rows
+ if (newCol > this.numberOfColumns)
+ {
+ newCol = addColumns( newCol );
+ }
+
List newRowList = this.columnsList[newCol];
int numRowsNewColumn = newRowList.size();
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org