[seam-commits] Seam SVN: r8843 - in trunk: src/excel/org/jboss/seam/excel and 4 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Thu Aug 28 16:50:00 EDT 2008


Author: nickarls
Date: 2008-08-28 16:49:59 -0400 (Thu, 28 Aug 2008)
New Revision: 8843

Modified:
   trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
   trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java
   trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/ui/ExcelComponent.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIColumn.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java
   trunk/src/excel/org/jboss/seam/excel/ui/UIWorksheet.java
Log:
Support for worksheet level headers/footers and for column data footers

Modified: trunk/doc/Seam_Reference_Guide/en-US/Excel.xml
===================================================================
--- trunk/doc/Seam_Reference_Guide/en-US/Excel.xml	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/doc/Seam_Reference_Guide/en-US/Excel.xml	2008-08-28 20:49:59 UTC (rev 8843)
@@ -777,9 +777,18 @@
                      <itemizedlist>
                         <listitem>
                            <para>
-                              <literal>none</literal>
+                              <literal>header</literal>&#8212;Contents that will
+                              be placed at the top of the data block, above the 
+                              column headers (if any)
                            </para>
                         </listitem>
+                        <listitem>
+                           <para>
+                              <literal>footer</literal>&#8212;Contents that will
+                              be placed at the bottom of the data block, below the 
+                              column footers (if any)
+                           </para>
+                        </listitem>
                      </itemizedlist>
                   </entry>
                </row>
@@ -902,6 +911,20 @@
                               that will be used as header for the column.
                            </para>
                         </listitem>
+                        <listitem>
+                           <para>
+                              <literal>footer</literal>
+                              &#8212;This facet can/will contain one
+                              <literal>&lt;e:cell&gt;</literal>
+                              ,
+                              <literal>&lt;e:formula&gt;</literal>
+                              ,
+                              <literal>&lt;e:image&gt;</literal>
+                              or
+                              <literal>&lt;e:hyperLink&gt;</literal>
+                              that will be used as footer for the column.
+                           </para>
+                        </listitem>
                      </itemizedlist>
                   </entry>
                </row>

Modified: trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -79,4 +79,18 @@
     * @param command The command to execute
     */
    public abstract void executeCommand(Command command);
+
+   /**
+    * Places an item in the worksheet header
+    * 
+    * @param item The item to add
+    */
+   public abstract void addWorksheetHeader(WorksheetItem item);
+   
+   /**
+    * Places an item in the worksheet footer
+    * 
+    * @param item The item to add
+    */
+   public abstract void addWorksheetFooter(WorksheetItem item);
 }
\ No newline at end of file

Modified: trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -159,4 +159,16 @@
       log.trace("executeCommand() is not supported by CSV exporter", new Object[0]);
    }
 
+   public void addWorksheetFooter(WorksheetItem item)
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
+   public void addWorksheetHeader(WorksheetItem item)
+   {
+      // TODO Auto-generated method stub
+      
+   }
+
 }

Modified: trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -28,6 +28,8 @@
 import org.jboss.seam.excel.ui.UIColumn;
 import org.jboss.seam.excel.ui.UIWorkbook;
 import org.jboss.seam.excel.ui.UIWorksheet;
+import org.jboss.seam.log.Log;
+import org.jboss.seam.log.Logging;
 import org.jboss.seam.navigation.Pages;
 
 /**
@@ -150,6 +152,17 @@
          processOutputs(headerOutputs, "global,header");
       }
 
+      try
+      {
+         String rendered = ExcelComponent.cmp2String(FacesContext.getCurrentInstance(), column);
+         Log log = Logging.getLog(getClass());
+         log.warn("Rendered as #0", rendered);
+      }
+      catch (IOException e)
+      {
+         e.printStackTrace();
+      }
+      
       // Process data
       while (iterator.hasNext())
       {

Modified: trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -106,6 +106,12 @@
     * user-defined worksheets in the workbook.
     */
    private int currentWorksheetIndex = 0;
+   
+   /**
+    * The maximum row index we have seen. Used for determining where to place the 
+    * worksheet footer (if any)
+    */
+   private int maxRowIndex;
 
    // Template helper class for cell formats
    private JXLTemplates templates = new JXLTemplates();
@@ -127,7 +133,7 @@
          throw new ExcelWorkbookException(Interpolator.instance().interpolate("Excel only supports {0} rows", MAX_COLUMNS));
       }
    }
-
+   
    /**
     * Moves the internal column pointer to the next column, called by the tag to
     * indicate that a new column has been started. If the pointer exceeds the
@@ -147,6 +153,9 @@
       {
          throw new ExcelWorkbookException(Interpolator.instance().interpolate("Excel doesn't support more than {0} columns", MAX_COLUMNS));
       }
+      if (currentRowIndex > maxRowIndex) {
+         maxRowIndex = currentRowIndex;
+      }
       currentRowIndex = startRowIndex;
    }
 
@@ -224,6 +233,7 @@
       currentColumnIndex = startColumnIndex;
       startRowIndex = uiWorksheet.getStartRow() == null ? 0 : uiWorksheet.getStartRow();
       currentRowIndex = startRowIndex;
+      maxRowIndex = currentRowIndex;
    }
 
    /**
@@ -667,4 +677,27 @@
       }
    }
 
+   /**
+    * Places an item in the worksheet footer
+    * 
+    * @param item The item to add
+    */
+   public void addWorksheetFooter(WorksheetItem item)
+   {
+      currentColumnIndex = startColumnIndex;
+      currentRowIndex = maxRowIndex;
+      addItem(item);
+   }
+
+   /**
+    * Places an item in the worksheet header
+    * 
+    * @param item The item to add
+    */
+   public void addWorksheetHeader(WorksheetItem item)
+   {
+      addItem(item);
+      startRowIndex++;
+   }
+
 }

Modified: trunk/src/excel/org/jboss/seam/excel/ui/ExcelComponent.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/ExcelComponent.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/ui/ExcelComponent.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -29,7 +29,6 @@
  */
 public abstract class ExcelComponent extends UIComponentBase
 {
-   public final static String HEADER_FACET = "header";
    private static final String DEFAULT_CONTENT_TYPE = "text/html";
    private static final String DEFAULT_CHARACTER_ENCODING = "utf-8";
 

Modified: trunk/src/excel/org/jboss/seam/excel/ui/UIColumn.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIColumn.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIColumn.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -16,6 +16,9 @@
 {
    public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIColumn";
 
+   private static final String HEADER_FACET_NAME = "header";
+   private static final String FOOTER_FACET_NAME = "footer";
+
    private Boolean autoSize;
    private Boolean hidden;
    private Integer width;
@@ -74,9 +77,7 @@
    @Override
    public void encodeBegin(FacesContext facesContext) throws IOException
    {
-      /**
-       * Get workbook and worksheet
-       */
+      // Get workbook and worksheet
       ExcelWorkbook excelWorkbook = getWorkbook(getParent());
 
       if (excelWorkbook == null)
@@ -84,9 +85,7 @@
          throw new ExcelWorkbookException("Could not find excel workbook");
       }
 
-      /**
-       * Column width etc.
-       */
+      // Column width etc.
       excelWorkbook.applyColumnSettings(this);
 
       UIWorksheet sheet = (UIWorksheet) getParentByClass(getParent(), UIWorksheet.class);
@@ -95,30 +94,21 @@
          throw new ExcelWorkbookException("Could not find worksheet");
       }
 
-      /**
-       * Add header items (if any)
-       */
-      // TODO: multicells
-      UICell headerCell = (UICell) getFacet(HEADER_FACET);
-      if (headerCell != null)
+      // Add header items (if any)
+      WorksheetItem headerItem = (WorksheetItem) getFacet(HEADER_FACET_NAME);
+      if (headerItem != null)
       {
-         excelWorkbook.addItem(headerCell);
+         excelWorkbook.addItem(headerItem);
       }
 
-      /**
-       * Execute commands (if any)
-       */
+      // Execute commands (if any)
       List<Command> commands = getCommands(getChildren());
       for (Command command : commands)
       {
          excelWorkbook.executeCommand(command);
       }
 
-      /**
-       * Get UiCell template this column's data cells and iterate over sheet
-       * data
-       * 
-       */
+       // Get UiCell template this column's data cells and iterate over sheet data
       for (WorksheetItem item : getItems(getChildren()))
       {
          Object oldValue = null;
@@ -153,9 +143,15 @@
          }
       }
 
-      /**
-       * Move column pointer to next column
-       */
+      // Add footer items (if any)
+      WorksheetItem footerItem = (WorksheetItem) getFacet(FOOTER_FACET_NAME);
+      if (footerItem != null)
+      {
+         excelWorkbook.addItem(footerItem);
+      }
+      
+      
+      // Move column pointer to next column
       excelWorkbook.nextColumn();
 
    }

Modified: trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -55,8 +55,6 @@
    private Boolean useTemporaryFileDuringWrite;
    private Boolean workbookProtected;
 
-   private long timing;
-
    public CreationType getCreationType()
    {
       if (hasSettings())
@@ -289,20 +287,13 @@
    @Override
    public void encodeBegin(javax.faces.context.FacesContext facesContext) throws IOException
    {
-      timing = new Date().getTime();
-      /**
-       * Get workbook implementation
-       */
+      // Get workbook implementation
       excelWorkbook = ExcelFactory.instance().getExcelWorkbook(type);
 
-      /**
-       * Create a new workbook
-       */
+      // Create a new workbook
       excelWorkbook.createWorkbook(this);
 
-      /**
-       * Find global templates and push them to workbook
-       */
+      // Find global templates and push them to workbook
       for (Template template : getTemplates(getChildren()))
       {
          excelWorkbook.addTemplate(template);
@@ -314,23 +305,14 @@
    public void encodeEnd(FacesContext context) throws IOException
    {
 
-      /**
-       * Get the bytes from workbook that should be passed on to the user
-       */
-      byte[] bytes = new byte[0];
-      bytes = excelWorkbook.getBytes();
-      if (log.isDebugEnabled())
-      {
-         log.debug("Prosessed for {0}ms", new Date().getTime() - timing);
-      }
+      // Get the bytes from workbook that should be passed on to the user
+      byte[] bytes = excelWorkbook.getBytes();
 
       DocumentType type = excelWorkbook.getDocumentType();
 
       /**
-       * 
        * Code below is the same as for PDF generation. With a seam core document
        * store (or equivalent), this might need modifications
-       * 
        */
       String viewId = Pages.getViewId(context);
       String baseName = baseNameForViewId(viewId);

Modified: trunk/src/excel/org/jboss/seam/excel/ui/UIWorksheet.java
===================================================================
--- trunk/src/excel/org/jboss/seam/excel/ui/UIWorksheet.java	2008-08-28 13:56:25 UTC (rev 8842)
+++ trunk/src/excel/org/jboss/seam/excel/ui/UIWorksheet.java	2008-08-28 20:49:59 UTC (rev 8843)
@@ -6,6 +6,7 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.faces.component.UIComponent;
 import javax.faces.model.DataModel;
 
 import org.jboss.seam.excel.Command;
@@ -18,6 +19,9 @@
 {
    public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIWorksheet";
 
+   private static final String HEADER_FACET_NAME = "header";
+   private static final String FOOTER_FACET_NAME = "footer";
+
    private String name;
    private String var;
    private Object value;
@@ -94,9 +98,7 @@
    @Override
    public void encodeBegin(javax.faces.context.FacesContext facesContext) throws java.io.IOException
    {
-      /**
-       * Get workbook
-       */
+      // Get workbook
       ExcelWorkbook excelWorkbook = getWorkbook(getParent());
 
       if (excelWorkbook == null)
@@ -104,31 +106,44 @@
          throw new ExcelWorkbookException("Could not find excel workbook");
       }
 
-      /**
-       * Create new worksheet (or select an existing one) and apply settings (if
-       * any)
-       */
+      // Create new worksheet (or select an existing one) and apply settings (if any)
       excelWorkbook.createOrSelectWorksheet(this);
 
-      /**
-       * Add worksheet level items
-       */
+      WorksheetItem headerItem = (WorksheetItem) getFacet(HEADER_FACET_NAME);
+      if (headerItem != null) {
+         excelWorkbook.addWorksheetHeader(headerItem);
+      }
+      
+      // Add worksheet level items
       List<WorksheetItem> items = getItems(getChildren());
       for (WorksheetItem item : items)
       {
          excelWorkbook.addItem(item);
       }
 
-      /**
-       * Execute worksheet level commands
-       */
+      // Execute worksheet level commands
       List<Command> commands = getCommands(getChildren());
       for (Command command : commands)
       {
          excelWorkbook.executeCommand(command);
       }
    }
+   
+   @Override
+   public void encodeEnd(javax.faces.context.FacesContext facesContext) throws java.io.IOException
+   {
+      ExcelWorkbook excelWorkbook = getWorkbook(getParent());
+      if (excelWorkbook == null)
+      {
+         throw new ExcelWorkbookException("Could not find excel workbook");
+      }
 
+      WorksheetItem footerItem = (WorksheetItem) getFacet(FOOTER_FACET_NAME);
+      if (footerItem != null) {
+         excelWorkbook.addWorksheetFooter(footerItem);
+      }
+   }
+   
    @SuppressWarnings("unchecked")
    public static Iterator unwrapIterator(Object value)
    {




More information about the seam-commits mailing list