portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r354675 - in /portals/jetspeed-2/trunk/components/portal/src: java/org/apache/jetspeed/layout/impl/ test/org/apache/jetspeed/layout/
Date Wed, 07 Dec 2005 02:49:25 GMT
Author: taylor
Date: Tue Dec  6 18:49:21 2005
New Revision: 354675

URL: http://svn.apache.org/viewcvs?rev=354675&view=rev
Log:
http://issues.apache.org/jira/browse/JS2-387

This completes the first phase of the Layout AJAX Api
we will revisit this post 2.0 release

Modified:
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
    portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
    portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java?rev=354675&r1=354674&r2=354675&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/AddPortletAction.java
Tue Dec  6 18:49:21 2005
@@ -115,17 +115,23 @@
             Fragment fragment = pageManager.newFragment();
             fragment.setType(Fragment.PORTLET);
             fragment.setName(portletId);
-            // TODO: this does not handle nested layouts            
-            Fragment root = requestContext.getPage().getRootFragment();
-            root.getFragments().add(fragment);
+            fragment.setLayoutColumn(iCol);
+            fragment.setLayoutRow(iRow);
             
             Coordinate coordinate = placement.add(fragment, new CoordinateImpl(iCol, iRow,
iCol, iRow));
             Page page = placement.syncPageFragments();                                  
             
             
-            if (pageManager != null)
-                pageManager.updatePage(page);
+            // TODO: this does not handle nested layouts            
+            Fragment root = requestContext.getPage().getRootFragment();
+            root.getFragments().add(fragment);            
+            pageManager.updatePage(page);
 
             resultMap.put(STATUS, "success");
+            resultMap.put(NEWCOL, String.valueOf(coordinate
+                    .getNewCol()));
+            resultMap.put(NEWROW, String.valueOf(coordinate
+                    .getNewRow()));
+            
         } 
         catch (Exception e)
         {

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/PortletPlacementContextImpl.java?rev=354675&r1=354674&r2=354675&view=diff
==============================================================================
--- 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
Tue Dec  6 18:49:21 2005
@@ -121,6 +121,7 @@
 	protected void processFragment(Fragment fragment) 
     throws PortletPlacementException 
     {
+        int rowCount = 0;
 		// Process this fragment, then its children
 		if(fragment != null) 
         {
@@ -131,16 +132,13 @@
 				int col = getFragmentCol(fragment);
 				int row = getFragmentRow(fragment);
 		        
-		        if(col > -1 && row > -1) 
+		        if(row < 0) 
                 {
-		        	// Add this fragment to the data structures
-		        	addFragmentInternal(fragment, col, row);
-		        } 
-                else 
-                {
-		        	// log a message
-		        	log.error("fragment found without a row or column property, skipping");
-		        }
+                    row = rowCount;
+                }
+	        	// Add this fragment to the data structures
+	        	addFragmentInternal(fragment, col, row);
+                rowCount++;
 			}
 			
 			// Process the children
@@ -195,6 +193,8 @@
             while (frags.hasNext())
             {
                 Fragment f = (Fragment)frags.next();
+                if (f == null)
+                    continue;
                 f.setLayoutColumn(col);
                 f.setLayoutRow(row);
                 row++;
@@ -215,7 +215,10 @@
 	// directly from the fragment via fragment.getFragmentRow()
 	protected int getFragmentCol(Fragment fragment) 
     {
-        return fragment.getLayoutColumn();
+        int col = fragment.getLayoutColumn();
+        if (col < 0)
+            col = 0;
+        return col;
 	}
 	
 	// Adds the fragment to the internal data structures
@@ -231,7 +234,7 @@
 		// Establish the maximum column number
 		if(col > this.numberOfColumns) 
         {
-			this.numberOfColumns = col;
+			this.numberOfColumns = col + 1;
 		}
 	}
 	
@@ -243,7 +246,8 @@
     {
 		if(this.numberOfColumns == -1) 
         {
-			throw new PortletPlacementException("no columns found");
+			//throw new PortletPlacementException("no columns found");
+            this.numberOfColumns = 1; // create a new column
 		}
 		
 		// Allocate the memory for the array of ArrayLists
@@ -325,7 +329,50 @@
 	
 	public Coordinate add(Fragment fragment, Coordinate coordinate) throws PortletPlacementException

     {
-        return addInternal(fragment, coordinate);
+        int col = coordinate.getNewCol();
+        int row = coordinate.getNewRow();
+        
+        if (this.numberOfColumns == -1)
+        {
+            this.numberOfColumns = 1;
+            this.columnsList = new Vector[this.numberOfColumns];
+            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;
+        }
+        
+        Vector column = this.columnsList[col];
+        if (column != null)
+        {
+            for (int ix = 0; ix < column.size(); ix++)
+            {                
+                Fragment frag = (Fragment)column.get(ix);
+                if (frag == null)
+                    continue;
+                Coordinate c = (Coordinate)this.fragmentCoordinateMap.get(frag);
+                if (c == null)
+                    continue;
+                if (c.getNewCol() == row)
+                {
+                    row++;
+                }
+                
+            }
+            column.add(fragment);
+            Coordinate newCoord = new CoordinateImpl(col, row, col, row);
+            this.fragmentCoordinateMap.put(fragment, newCoord);
+            return newCoord;
+        }
+        return coordinate;
 	}
 	
 	// Adds an existing fragment to the coordinate position

Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java?rev=354675&r1=354674&r2=354675&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/RemovePortletAction.java
Tue Dec  6 18:49:21 2005
@@ -76,7 +76,9 @@
             String portletId = requestContext.getRequestParameter(PORTLETID);
             if (portletId == null) 
             { 
-                throw new Exception("portlet id not provided"); 
+                success = false;
+                resultMap.put(REASON, "Portlet ID not provided");
+                return success;
             }
 
             resultMap.put(PORTLETID, portletId);
@@ -91,16 +93,21 @@
             // Use the Portlet Placement Manager to accomplish the removal
             PortletPlacementContext placement = new PortletPlacementContextImpl(requestContext);
             Fragment fragment = placement.getFragmentById(portletId);
-            Coordinate coordinate = placement.remove(fragment);
-
-            Page page = placement.syncPageFragments();
-            if (pageManager != null)
-                pageManager.updatePage(page);
+            if (fragment == null)
+            {
+                success = false;
+                resultMap.put(REASON, "Fragment not found");
+                return success;                
+            }
+            //Coordinate coordinate = placement.remove(fragment);
+            Page page = requestContext.getPage();
+            page.removeFragmentById(fragment.getId());            
+            pageManager.updatePage(page);
             
             // Build the results for the response
             resultMap.put(STATUS, "success");
-            resultMap.put(OLDCOL, String.valueOf(coordinate.getOldCol()));
-            resultMap.put(OLDROW, String.valueOf(coordinate.getOldRow()));
+            resultMap.put(OLDCOL, String.valueOf(fragment.getLayoutColumn()));
+            resultMap.put(OLDROW, String.valueOf(fragment.getLayoutRow()));
         } 
         catch (Exception e)
         {

Modified: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java?rev=354675&r1=354674&r2=354675&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
(original)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestLayout.java
Tue Dec  6 18:49:21 2005
@@ -87,7 +87,7 @@
         cm.stop();
     }
 
-    public void xtestNullRequestContext()
+    public void testNullRequestContext()
     {
         // Get the layout that has a null request context        
         try
@@ -100,7 +100,7 @@
         }
     }
 
-    public void xtestNullParameters()
+    public void testNullParameters()
     {
         try
         {
@@ -168,7 +168,7 @@
         //moveSuccess("moveabs", "2", "0", "1", "0", "2", "0", "1");
     }
     
-    public void xtestMoveSuccess()
+    public void testMoveSuccess()
     {
         moveSuccess("moveabs", "1", "0", "0", "0", "0", "0", "0"); // Doesn't
                                                                     // really
@@ -264,7 +264,7 @@
                                                                     // move
     }
 
-    public void xtestMoveFailure()
+    public void testMoveFailure()
     {
         moveFailure("moveabs", "bogus", "0", "0", "0", "0"); // non integer
                                                                 // portlet id



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message