[seam-commits] Seam SVN: r13469 - in sandbox/modules/spreadsheet/src: main/java/org/jboss/seam/spreadsheet/jxl/command and 14 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Jul 22 02:59:56 EDT 2010
Author: nickarls
Date: 2010-07-22 02:59:54 -0400 (Thu, 22 Jul 2010)
New Revision: 13469
Added:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java
Removed:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java
Modified:
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java
sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java
sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
Log:
moving stuff
merge cells command
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,19 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
- at Qualifier
- at Retention(RUNTIME)
- at Target( { METHOD, FIELD, PARAMETER, TYPE })
-public @interface BeforeAdded
-{
-}
\ No newline at end of file
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,19 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
- at Qualifier
- at Retention(RUNTIME)
- at Target( { METHOD, FIELD, PARAMETER, TYPE })
-public @interface BeforeCreated
-{
-}
\ No newline at end of file
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,19 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.ElementType.PARAMETER;
-import static java.lang.annotation.ElementType.TYPE;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.inject.Qualifier;
-
- at Qualifier
- at Retention(RUNTIME)
- at Target( { METHOD, FIELD, PARAMETER, TYPE })
-public @interface BeforeExecuted
-{
-}
\ No newline at end of file
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,145 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.List;
-
-import javax.enterprise.event.Event;
-import javax.inject.Inject;
-
-import jxl.write.WritableSheet;
-import jxl.write.WritableWorkbook;
-import jxl.write.WriteException;
-import jxl.write.biff.RowsExceededException;
-
-import org.jboss.seam.spreadsheet.SpreadsheetException;
-import org.jboss.seam.spreadsheet.SpreadsheetWriter;
-import org.jboss.seam.spreadsheet.jxl.command.CommandFactory;
-import org.jboss.seam.spreadsheet.jxl.command.JxlCommand;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.Workbook;
-import org.jboss.seam.spreadsheet.model.Worksheet;
-import org.jboss.seam.spreadsheet.model.command.Command;
-
-public class JXLSpreadsheetWriter implements SpreadsheetWriter
-{
- CellFactory cellFactory;
- CellFormatResolver cellFormatResolver;
- WritableWorkbook jxlWorkbook;
-
- @Inject
- @BeforeAdded
- Event<Cell> cellAdded;
-
- @Inject
- @BeforeCreated
- Event<Worksheet> worksheetCreated;
-
- @Inject
- @BeforeExecuted
- Event<Command> commandExecuted;
-
- @Override
- public byte[] writeWorkbook(Workbook workbook) throws SpreadsheetException
- {
- if (workbook.getWorksheets().isEmpty())
- {
- throw new SpreadsheetException("You must have at least one worksheet");
- }
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- cellFactory = new CellFactory();
- cellFormatResolver = new CellFormatResolver(workbook.getCellFormatRules());
- try
- {
- jxlWorkbook = jxl.Workbook.createWorkbook(outStream);
- processWorkbook(jxlWorkbook, workbook);
- jxlWorkbook.write();
- jxlWorkbook.close();
- }
- catch (IOException e)
- {
- throw new SpreadsheetException("Could not create workbook", e);
- }
- catch (WriteException e)
- {
- throw new SpreadsheetException("Could not write workbook", e);
- }
- return outStream.toByteArray();
- }
-
- private void processWorkbook(WritableWorkbook jxlWorkbook, Workbook workbook)
- {
- for (Worksheet worksheet : workbook.getWorksheets())
- {
- processWorksheet(worksheet, workbook, jxlWorkbook);
- }
- }
-
- private void processWorksheet(Worksheet worksheet, Workbook workbook, WritableWorkbook jxlWorkbook)
- {
- cellFormatResolver.setWorksheetRules(worksheet.getCellFormatRules());
- worksheetCreated.fire(worksheet);
- WritableSheet jxlWorksheet = jxlWorkbook.createSheet(worksheet.getName(), jxlWorkbook.getNumberOfSheets());
- for (Cell cell : worksheet.getCells())
- {
- processCell(jxlWorksheet, cell);
- }
- processCommands(workbook.getCommands(), jxlWorksheet);
- processCommands(worksheet.getCommands(), jxlWorksheet);
- }
-
- private void processCommands(List<Command> commands, WritableSheet jxlWorksheet)
- {
- for (Command command : commands)
- {
- JxlCommand jxlCommand = CommandFactory.getJxlCommand(command, jxlWorksheet);
- commandExecuted.fire(command);
- jxlCommand.execute();
- }
- }
-
- private void processCell(WritableSheet jxlWorksheet, Cell cell)
- {
- try
- {
- cellAdded.fire(cell);
- jxlWorksheet.addCell(cellFactory.createCell(cell, cellFormatResolver));
- if (cell.getCellSpan() != null)
- {
- mergeCells(jxlWorksheet, cell);
- }
- }
- catch (RowsExceededException e)
- {
- throw new SpreadsheetException("Too many rows", e);
- }
- catch (WriteException e)
- {
- throw new SpreadsheetException("Could not write cell", e);
- }
- }
-
- private void mergeCells(WritableSheet jxlWorksheet, Cell cell) throws RowsExceededException, WriteException
- {
- int columnStart = cell.getCoordinate().getColumn();
- int rowStart = cell.getCoordinate().getRow();
- int columnEnd = columnStart + cell.getCellSpan().getColumnSpan();
- int rowEnd = rowStart + cell.getCellSpan().getRowSpan();
- jxlWorksheet.mergeCells(columnStart, rowStart, columnEnd, rowEnd);
- }
-
- @Override
- public byte[] writeWorkbook(Workbook workbook, byte[] template) throws SpreadsheetException
- {
- return null;
- }
-
- @Override
- public Object getRawWorkbook()
- {
- return jxlWorkbook;
- }
-
-}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/AbstractJxlCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,13 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import jxl.write.WritableSheet;
+
+public abstract class AbstractJxlCommand implements JxlCommand
+{
+ protected WritableSheet jxlWorksheet;
+
+ public AbstractJxlCommand(WritableSheet jxlWorksheet)
+ {
+ this.jxlWorksheet = jxlWorksheet;
+ }
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/CommandFactory.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,6 +4,7 @@
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
import org.jboss.seam.spreadsheet.model.command.Command;
+import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
import org.jboss.seam.spreadsheet.model.command.RowHeightCommand;
public class CommandFactory
@@ -17,6 +18,8 @@
return new JxlColumnWidthCommand((ColumnWidthCommand) command, jxlWorksheet);
case ROW_HEIGHT:
return new JxlRowHeightCommand((RowHeightCommand) command, jxlWorksheet);
+ case MERGE_CELLS:
+ return new JxlMergeCellsCommand((MergeCellsCommand) command, jxlWorksheet);
}
return null;
}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlColumnWidthCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -5,15 +5,14 @@
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
-public class JxlColumnWidthCommand implements JxlCommand
+public class JxlColumnWidthCommand extends AbstractJxlCommand
{
private ColumnWidthCommand columnWidthCommand;
- private WritableSheet jxlWorksheet;
public JxlColumnWidthCommand(ColumnWidthCommand columnWidthCommand, WritableSheet jxlWorksheet)
{
+ super(jxlWorksheet);
this.columnWidthCommand = columnWidthCommand;
- this.jxlWorksheet = jxlWorksheet;
}
@Override
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlMergeCellsCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,41 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import jxl.write.WritableSheet;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.jboss.seam.spreadsheet.SpreadsheetException;
+import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
+
+public class JxlMergeCellsCommand extends AbstractJxlCommand
+{
+ private MergeCellsCommand command;
+
+ public JxlMergeCellsCommand(MergeCellsCommand command, WritableSheet jxlWorksheet)
+ {
+ super(jxlWorksheet);
+ this.command = command;
+ }
+
+ @Override
+ public void execute()
+ {
+ int startColumn = command.getCoordinate().getColumn();
+ int startRow = command.getCoordinate().getRow();
+ int endColumn = startColumn + command.getCellSpan().getColumnSpan();
+ int endRow = startRow + command.getCellSpan().getRowSpan();
+ try
+ {
+ jxlWorksheet.mergeCells(startColumn, startRow, endColumn, endRow);
+ }
+ catch (RowsExceededException e)
+ {
+ throw new SpreadsheetException(String.format("Too many rows when merging cell at %s", command.getCoordinate()), e);
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException(String.format("Could not merge cells at %s", command.getCoordinate()), e);
+ }
+ }
+
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/command/JxlRowHeightCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,15 +4,14 @@
import org.jboss.seam.spreadsheet.model.command.RowHeightCommand;
-public class JxlRowHeightCommand implements JxlCommand
+public class JxlRowHeightCommand extends AbstractJxlCommand
{
private RowHeightCommand rowHeightCommand;
- private WritableSheet jxlWorksheet;
public JxlRowHeightCommand(RowHeightCommand rowHeightCommand, WritableSheet jxlWorksheet)
{
+ super(jxlWorksheet);
this.rowHeightCommand = rowHeightCommand;
- this.jxlWorksheet = jxlWorksheet;
}
@Override
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/formatting/CellFormatResolver.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -7,7 +7,7 @@
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
public class CellFormatResolver
{
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java (from rev 13459, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriter.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/JXLSpreadsheetWriter.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,128 @@
+package org.jboss.seam.spreadsheet.jxl.writer;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+import jxl.write.WriteException;
+import jxl.write.biff.RowsExceededException;
+
+import org.jboss.seam.spreadsheet.SpreadsheetException;
+import org.jboss.seam.spreadsheet.SpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.command.CommandFactory;
+import org.jboss.seam.spreadsheet.jxl.command.JxlCommand;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Workbook;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.command.Command;
+import org.jboss.seam.spreadsheet.model.command.MergeCellsCommand;
+
+public class JXLSpreadsheetWriter implements SpreadsheetWriter
+{
+ private CellFactory cellFactory;
+ private CellFormatResolver cellFormatResolver;
+ private WritableWorkbook jxlWorkbook;
+
+ @Inject
+ private Events events;
+
+ @Override
+ public byte[] writeWorkbook(Workbook workbook) throws SpreadsheetException
+ {
+ if (workbook.getWorksheets().isEmpty())
+ {
+ throw new SpreadsheetException("You must have at least one worksheet");
+ }
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ cellFactory = new CellFactory();
+ cellFormatResolver = new CellFormatResolver(workbook.getCellFormatRules());
+ try
+ {
+ jxlWorkbook = jxl.Workbook.createWorkbook(outStream);
+ processWorkbook(workbook);
+ jxlWorkbook.write();
+ jxlWorkbook.close();
+ }
+ catch (IOException e)
+ {
+ throw new SpreadsheetException("Could not create workbook", e);
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException("Could not write workbook", e);
+ }
+ return outStream.toByteArray();
+ }
+
+ private void processWorkbook(Workbook workbook)
+ {
+ for (Worksheet worksheet : workbook.getWorksheets())
+ {
+ processWorksheet(worksheet, workbook.getCommands());
+ }
+ }
+
+ private void processWorksheet(Worksheet worksheet, List<Command> workbookCommands)
+ {
+ cellFormatResolver.setWorksheetRules(worksheet.getCellFormatRules());
+ events.worksheetCreated(worksheet);
+ WritableSheet jxlWorksheet = jxlWorkbook.createSheet(worksheet.getName(), jxlWorkbook.getNumberOfSheets());
+ for (Cell cell : worksheet.getCells())
+ {
+ processCell(worksheet, jxlWorksheet, cell);
+ }
+ processCommands(workbookCommands, jxlWorksheet);
+ processCommands(worksheet.getCommands(), jxlWorksheet);
+ }
+
+ private void processCommands(List<Command> commands, WritableSheet jxlWorksheet)
+ {
+ for (Command command : commands)
+ {
+ JxlCommand jxlCommand = CommandFactory.getJxlCommand(command, jxlWorksheet);
+ events.commandExecuted(command);
+ jxlCommand.execute();
+ }
+ }
+
+ private void processCell(Worksheet worksheet, WritableSheet jxlWorksheet, Cell cell)
+ {
+ try
+ {
+ events.cellAdded(cell);
+ jxlWorksheet.addCell(cellFactory.createCell(cell, cellFormatResolver));
+ if (cell.getCellSpan() != null)
+ {
+ worksheet.getCommands().add(new MergeCellsCommand(cell.getCoordinate(), cell.getCellSpan()));
+ }
+ }
+ catch (RowsExceededException e)
+ {
+ throw new SpreadsheetException("Too many rows", e);
+ }
+ catch (WriteException e)
+ {
+ throw new SpreadsheetException("Could not write cell", e);
+ }
+ }
+
+ @Override
+ public byte[] writeWorkbook(Workbook workbook, byte[] template) throws SpreadsheetException
+ {
+ return null;
+ }
+
+ @Override
+ public Object getRawWorkbook()
+ {
+ return jxlWorkbook;
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeAdded.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeAdded.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { METHOD, FIELD, PARAMETER, TYPE })
+public @interface BeforeAdded
+{
+}
\ No newline at end of file
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeCreated.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeCreated.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { METHOD, FIELD, PARAMETER, TYPE })
+public @interface BeforeCreated
+{
+}
\ No newline at end of file
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/BeforeExecuted.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/BeforeExecuted.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RUNTIME)
+ at Target( { METHOD, FIELD, PARAMETER, TYPE })
+public @interface BeforeExecuted
+{
+}
\ No newline at end of file
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/jxl/writer/event/Events.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,38 @@
+package org.jboss.seam.spreadsheet.jxl.writer.event;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.command.Command;
+
+public class Events
+{
+ @Inject
+ @BeforeAdded
+ private Event<Cell> cellAdded;
+
+ @Inject
+ @BeforeCreated
+ private Event<Worksheet> worksheetCreated;
+
+ @Inject
+ @BeforeExecuted
+ private Event<Command> commandExecuted;
+
+ public void cellAdded(Cell cell)
+ {
+ cellAdded.fire(cell);
+ }
+
+ public void worksheetCreated(Worksheet worksheet)
+ {
+ worksheetCreated.fire(worksheet);
+ }
+
+ public void commandExecuted(Command command)
+ {
+ commandExecuted.fire(command);
+ }
+}
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Workbook.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,7 +4,7 @@
import java.util.List;
import org.jboss.seam.spreadsheet.model.command.Command;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
public class Workbook
{
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/Worksheet.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,7 +4,7 @@
import java.util.List;
import org.jboss.seam.spreadsheet.model.command.Command;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
public class Worksheet
{
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilder.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -11,8 +11,8 @@
import org.jboss.seam.spreadsheet.model.Worksheet;
import org.jboss.seam.spreadsheet.model.command.Command;
import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
-import org.jboss.seam.spreadsheet.model.formatting.RangeCellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.RangeCellFormatRule;
import org.jboss.seam.spreadsheet.util.ReflectionUtil;
public class WorkbookBuilder
@@ -21,7 +21,7 @@
Worksheet worksheet;
IteratingCoordinate cursor;
-
+
public void clear()
{
workbook = new Workbook();
@@ -141,7 +141,7 @@
Coordinate topLeft = Coordinate.of(startCoordinate.getColumn(), startCoordinate.getRow());
Coordinate bottomRight = Coordinate.of(startCoordinate.getColumn() + blockWidth - 1, startCoordinate.getRow());
Range range = Range.of(topLeft, bottomRight);
- addWorksheetCellFormatRule(RangeCellFormatRule.of(cellFormat, range));
+ addWorksheetCellFormatRule(RangeCellFormatRule.of(range, cellFormat));
}
private void addDataCellFormatRule(Coordinate startCoordinate, int blockWidth, CellFormat cellFormat)
@@ -149,7 +149,7 @@
Coordinate topLeft = Coordinate.of(startCoordinate.getColumn(), startCoordinate.getRow());
Coordinate bottomRight = Coordinate.of(startCoordinate.getColumn() + blockWidth - 1, cursor.getRow() - 1);
Range range = Range.of(topLeft, bottomRight);
- addWorksheetCellFormatRule(RangeCellFormatRule.of(cellFormat, range));
+ addWorksheetCellFormatRule(RangeCellFormatRule.of(range, cellFormat));
}
public IteratingCoordinate getCursor()
Modified: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/Command.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -4,7 +4,7 @@
{
public enum CommandId
{
- COLUMN_WIDTH, ROW_HEIGHT
+ COLUMN_WIDTH, ROW_HEIGHT, MERGE_CELLS
};
public abstract CommandId getCommandId();
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/command/MergeCellsCommand.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,33 @@
+package org.jboss.seam.spreadsheet.model.command;
+
+import org.jboss.seam.spreadsheet.model.CellSpan;
+import org.jboss.seam.spreadsheet.model.Coordinate;
+
+public class MergeCellsCommand implements Command
+{
+ private Coordinate coordinate;
+ private CellSpan cellSpan;
+
+ public MergeCellsCommand(Coordinate coordinate, CellSpan cellSpan)
+ {
+ this.coordinate = coordinate;
+ this.cellSpan = cellSpan;
+ }
+
+ @Override
+ public CommandId getCommandId()
+ {
+ return CommandId.MERGE_CELLS;
+ }
+
+ public Coordinate getCoordinate()
+ {
+ return coordinate;
+ }
+
+ public CellSpan getCellSpan()
+ {
+ return cellSpan;
+ }
+
+}
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,9 +0,0 @@
-package org.jboss.seam.spreadsheet.model.formatting;
-
-import org.jboss.seam.spreadsheet.model.Cell;
-
-public interface CellFormatRule
-{
- public abstract boolean appliesTo(Cell cell);
- public abstract CellFormat getCellFormat();
-}
Deleted: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,35 +0,0 @@
-package org.jboss.seam.spreadsheet.model.formatting;
-
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.Coordinate;
-import org.jboss.seam.spreadsheet.model.Range;
-
-public class RangeCellFormatRule implements CellFormatRule
-{
- private CellFormat cellFormat;
- private Range range;
-
- protected RangeCellFormatRule(CellFormat cellFormat, Range range)
- {
- this.cellFormat = cellFormat;
- this.range = range;
- }
-
- public static RangeCellFormatRule of(CellFormat cellFormat, Range range)
- {
- return new RangeCellFormatRule(cellFormat, range);
- }
-
- @Override
- public boolean appliesTo(Cell cell)
- {
- return cell.getCoordinate().within(range);
- }
-
- @Override
- public CellFormat getCellFormat()
- {
- return cellFormat;
- }
-
-}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/AbstractCellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,19 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public abstract class AbstractCellFormatRule implements CellFormatRule
+{
+ protected CellFormat cellFormat;
+
+ public AbstractCellFormatRule(CellFormat cellFormat)
+ {
+ this.cellFormat = cellFormat;
+ }
+
+ @Override
+ public CellFormat getCellFormat()
+ {
+ return cellFormat;
+ }
+}
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/CellFormatRule.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/CellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,10 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public interface CellFormatRule
+{
+ public abstract boolean appliesTo(Cell cell);
+ public abstract CellFormat getCellFormat();
+}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/EvenRowRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,20 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class EvenRowRule extends AbstractCellFormatRule
+{
+
+ protected EvenRowRule(CellFormat cellFormat)
+ {
+ super(cellFormat);
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return cell.getCoordinate().getRow() % 2 != 0;
+ }
+
+}
Added: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/OddRowRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,20 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class OddRowRule extends AbstractCellFormatRule
+{
+
+ protected OddRowRule(CellFormat cellFormat)
+ {
+ super(cellFormat);
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return cell.getCoordinate().getRow() % 2 == 0;
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java (from rev 13456, sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/RangeCellFormatRule.java)
===================================================================
--- sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java (rev 0)
+++ sandbox/modules/spreadsheet/src/main/java/org/jboss/seam/spreadsheet/model/formatting/rule/RangeCellFormatRule.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,28 @@
+package org.jboss.seam.spreadsheet.model.formatting.rule;
+
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.Range;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+
+public class RangeCellFormatRule extends AbstractCellFormatRule
+{
+ private Range range;
+
+ protected RangeCellFormatRule(Range range, CellFormat cellFormat)
+ {
+ super(cellFormat);
+ this.range = range;
+ }
+
+ public static RangeCellFormatRule of(Range range, CellFormat cellFormat)
+ {
+ return new RangeCellFormatRule(range, cellFormat);
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return cell.getCoordinate().within(range);
+ }
+
+}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,39 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import junit.framework.Assert;
-import jxl.write.WritableCell;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Test;
-
-public class CellFactoryTest extends SpreadsheetTest
-{
-
- @Test
- public void cellFormatsCachedForEqualCellFormatsTest()
- {
- CellFactory cellFactory = new CellFactory();
- CellFormatResolver cellFormatResolver = new CellFormatResolver();
- WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
- WritableCell jxlCell2 = cellFactory.createCell(getTestCell(), cellFormatResolver);
- Assert.assertTrue(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
- }
-
- @Test
- public void cellFormatsNotCachedForNonEqualCellFormatsTest()
- {
- CellFactory cellFactory = new CellFactory();
- CellFormatResolver cellFormatResolver = new CellFormatResolver();
- WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
- Cell cell2 = getTestCell();
- cell2.getCellFormat().setFont(getSampleFont());
- cell2.getCellFormat().getFont().setColour(Colour.GREEN);
- WritableCell jxlCell2 = cellFactory.createCell(cell2, cellFormatResolver);
- Assert.assertFalse(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
- }
-
-}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,241 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.formatting.Background;
-import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
-import org.jboss.seam.spreadsheet.model.formatting.Border;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Before;
-import org.junit.Test;
-
-public class CellFormatFactoryTest extends SpreadsheetTest
-{
- private CellFactory cellFactory;
- private CellFormatResolver cellFormatResolver;
- private Cell cell;
-
- @Before
- public void init()
- {
- cellFactory = new CellFactory();
- cellFormatResolver = new CellFormatResolver();
- cell = getTestCell();
- }
-
- private jxl.write.WritableCell getJxlCell()
- {
- return cellFactory.createCell(cell, cellFormatResolver);
- }
-
- @Test
- public void fontTest()
- {
- cell.getCellFormat().setFont(getSampleFont());
- jxl.format.Font jxlFont = getJxlCell().getCellFormat().getFont();
- Assert.assertEquals("Times New Roman", jxlFont.getName());
- Assert.assertEquals(700, jxlFont.getBoldWeight());
- Assert.assertEquals(jxl.format.Colour.RED, jxlFont.getColour());
- Assert.assertTrue(jxlFont.isItalic());
- Assert.assertEquals(100, jxlFont.getPointSize());
- Assert.assertTrue(jxlFont.isStruckout());
- Assert.assertEquals(jxl.format.ScriptStyle.SUBSCRIPT, jxlFont.getScriptStyle());
- Assert.assertEquals(jxl.format.UnderlineStyle.DOUBLE, jxlFont.getUnderlineStyle());
- }
-
- @Test
- public void alignmentTest()
- {
- cell.getCellFormat().setAlignment(Alignment.RIGHT);
- Assert.assertEquals(jxl.format.Alignment.RIGHT, getJxlCell().getCellFormat().getAlignment());
- }
-
- @Test
- public void backgroundColourTest()
- {
- cell.getCellFormat().setBackground(new Background());
- cell.getCellFormat().getBackground().setColour(Colour.BLUE);
- Assert.assertEquals(jxl.format.Colour.BLUE, getJxlCell().getCellFormat().getBackgroundColour());
- }
-
- @Test
- public void borderColourTest()
- {
- List<Border> borders = new ArrayList<Border>();
- Border border = new Border(BorderType.TOP);
- border.setColour(Colour.PINK);
- borders.add(border);
- cell.getCellFormat().setBorders(borders);
- Assert.assertEquals(jxl.format.Colour.PINK, getJxlCell().getCellFormat().getBorderColour(jxl.format.Border.TOP));
- }
-
- @Test
- public void rightMergedAllBorderTest() {
- List<Border> borders = new ArrayList<Border>();
- Border borderL = new Border(BorderType.LEFT);
- borderL.setColour(Colour.RED);
- borders.add(borderL);
-
- Border borderA = new Border(BorderType.ALL);
- borderA.setLineStyle(BorderLineStyle.DOUBLE);
- borderA.setColour(Colour.PINK);
- borders.add(borderA);
-
- cell.getCellFormat().setBorders(borders);
-
- jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
- }
-
- @Test
- public void leftMergedAllBorderTest() {
- List<Border> borders = new ArrayList<Border>();
-
- Border borderA = new Border(BorderType.ALL);
- borderA.setLineStyle(BorderLineStyle.DOUBLE);
- borderA.setColour(Colour.PINK);
- borders.add(borderA);
-
- Border borderL = new Border(BorderType.LEFT);
- borderL.setColour(Colour.RED);
- borderL.setLineStyle(BorderLineStyle.DOTTED);
- borders.add(borderL);
-
-
- cell.getCellFormat().setBorders(borders);
-
- jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
- Assert.assertEquals(jxl.format.BorderLineStyle.DOTTED, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
- Assert.assertEquals(jxl.format.Colour.RED, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
- Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
- }
-
-
- @Test
- public void borderLineStyleTest()
- {
- List<Border> borders = new ArrayList<Border>();
- Border border = new Border(BorderType.TOP);
- border.setLineStyle(BorderLineStyle.DOUBLE);
- borders.add(border);
- cell.getCellFormat().setBorders(borders);
- Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, getJxlCell().getCellFormat().getBorderLine(jxl.format.Border.TOP));
- }
-
- @Test
- public void indentationTest()
- {
- cell.getCellFormat().setIndentation(10);
- Assert.assertEquals(10, getJxlCell().getCellFormat().getIndentation());
- }
-
- @Test
- public void orientationTest()
- {
- cell.getCellFormat().setOrientation(Orientation.MINUS_45);
- Assert.assertEquals(jxl.format.Orientation.MINUS_45, getJxlCell().getCellFormat().getOrientation());
- }
-
- @Test
- public void patternTest()
- {
- cell.getCellFormat().setBackground(new Background());
- cell.getCellFormat().getBackground().setPattern(Pattern.GRAY_50);
- Assert.assertEquals(jxl.format.Pattern.GRAY_50, getJxlCell().getCellFormat().getPattern());
- }
-
- @Test
- public void verticalAlignmentTest()
- {
- cell.getCellFormat().setVerticalAlignment(VerticalAlignment.TOP);
- Assert.assertEquals(jxl.format.VerticalAlignment.TOP, getJxlCell().getCellFormat().getVerticalAlignment());
- }
-
- @Test
- public void wrapTest()
- {
- cell.getCellFormat().setWrap(true);
- Assert.assertTrue(getJxlCell().getCellFormat().getWrap());
- }
-
- @Test
- public void lockedTest()
- {
- cell.getCellFormat().setLocked(true);
- Assert.assertTrue(getJxlCell().getCellFormat().isLocked());
- }
-
- @Test
- public void shrinkToFitTest()
- {
- cell.getCellFormat().setShrinkToFit(true);
- Assert.assertTrue(getJxlCell().getCellFormat().isShrinkToFit());
- }
-
- @Test
- public void testCustomDateMask() throws IOException
- {
- cell.setValue(new Date());
- cell.getCellFormat().setMask("dd.MM.yyyy");
-// Assert.assertEquals("MM.yyyy", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testNamedDateMask() throws IOException
- {
- cell.setValue(new Date());
- cell.getCellFormat().setMask("FORMAT9");
-// Assert.assertEquals("M/d/yy H:mm", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testCustomNumberMask()
- {
- cell.setValue(1.1111111f);
- cell.getCellFormat().setMask("#.##");
-// Assert.assertEquals("#.##", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testNamedNumberMask()
- {
- cell.setValue(1.1111111f);
- cell.getCellFormat().setMask("CURRENCY_EURO_PREFIX");
-// Assert.assertEquals("CURRENCY_EURO_PREFIX", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
- @Test
- public void testNamedNumberMask2()
- {
- cell.setValue(1.1111111f);
- cell.getCellFormat().setMask("EXPONENTIAL");
-// Assert.assertEquals("EXPONENTIAL", getJxlCell().getCellFormat().getFormat().getFormatString());
- }
-
-}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,98 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.Assert;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
-import org.jboss.seam.spreadsheet.model.Cell;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.Font;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Test;
-
-public class CellFormatResolverTest extends SpreadsheetTest
-{
-
- private class SimpleRule implements CellFormatRule
- {
-
- private CellFormat cellFormat;
-
- public SimpleRule(CellFormat cellFormat)
- {
- this.cellFormat = cellFormat;
- }
-
- @Override
- public boolean appliesTo(Cell cell)
- {
- return true;
- }
-
- @Override
- public CellFormat getCellFormat()
- {
- return cellFormat;
- }
-
- }
-
- @Test
- public void resolveTest() {
-
- CellFormat cellFormat = new CellFormat();
- Font cellFont = new Font();
- cellFont.setBold(true);
- cellFormat.setFont(cellFont);
- Cell cell = new Cell();
- cell.setCellFormat(cellFormat);
-
- CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
- cellFormatResolver.setWorksheetRules(getWorksheetRules());
- CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
- Assert.assertEquals(Colour.RED, effectiveCellFormat.getFont().getColour());
- Assert.assertEquals((Integer)40, effectiveCellFormat.getFont().getPointSize());
- Assert.assertEquals(Boolean.TRUE, effectiveCellFormat.getFont().getBold());
- }
-
- @Test
- public void resolveAbsoluteTest() {
-
- CellFormat cellFormat = new CellFormat();
- cellFormat.setType(CellFormat.Type.ABSOLUTE);
- cellFormat.setFont(new Font());
- Cell cell = new Cell();
- cell.setCellFormat(cellFormat);
-
- CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
- cellFormatResolver.setWorksheetRules(getWorksheetRules());
- CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
- Assert.assertEquals(null, effectiveCellFormat.getFont().getColour());
- Assert.assertEquals(null, effectiveCellFormat.getFont().getPointSize());
- Assert.assertEquals(null, effectiveCellFormat.getFont().getBold());
- }
-
- private List<CellFormatRule> getWorkbookRules() {
- List<CellFormatRule> workbookRules = new ArrayList<CellFormatRule>();
- CellFormat workbookCellFormat = new CellFormat();
- Font workbookFont = new Font();
- workbookFont.setColour(Colour.RED);
- workbookCellFormat.setFont(workbookFont);
- workbookRules.add(new SimpleRule(workbookCellFormat));
- return workbookRules;
- }
-
- private List<CellFormatRule> getWorksheetRules() {
- List<CellFormatRule> worksheetRules = new ArrayList<CellFormatRule>();
- CellFormat worksheetCellFormat = new CellFormat();
- Font worksheetFont = new Font();
- worksheetFont.setPointSize(40);
- worksheetCellFormat.setFont(worksheetFont);
- worksheetRules.add(new SimpleRule(worksheetCellFormat));
- return worksheetRules;
- }
-}
Deleted: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,147 +0,0 @@
-package org.jboss.seam.spreadsheet.jxl;
-
-import java.util.Map;
-
-import jxl.biff.DisplayFormat;
-import jxl.write.DateFormat;
-import jxl.write.DateFormats;
-import jxl.write.NumberFormat;
-import jxl.write.NumberFormats;
-
-import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
-import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
-import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
-import org.jboss.seam.spreadsheet.model.formatting.Colour;
-import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
-import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
-import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-public class ConstantFactoryTest extends SpreadsheetTest
-{
- ConstantFactory constantFactory;
-
- @Before
- public void init()
- {
- constantFactory = new ConstantFactory();
- }
-
- @Test
- public void coloursTest()
- {
- for (Colour colour : Colour.values())
- {
- Assert.assertNotNull(constantFactory.getColour(colour));
- }
- }
-
- @Test
- public void underlineStyleTest()
- {
- for (UnderlineStyle underlineStyle : UnderlineStyle.values())
- {
- Assert.assertNotNull(constantFactory.getUnderlineStyle(underlineStyle));
- }
- }
-
- @Test
- public void scriptStyleTest()
- {
- for (ScriptStyle scriptStyle : ScriptStyle.values())
- {
- Assert.assertNotNull(constantFactory.getScriptStyle(scriptStyle));
- }
- }
-
- @Test
- public void borderLineTest()
- {
- for (BorderLineStyle borderLineStyle : BorderLineStyle.values())
- {
- Assert.assertNotNull(constantFactory.getBorderLineStyle(borderLineStyle));
- }
- }
-
- @Test
- public void borderTypeTest()
- {
- for (BorderType borderType : BorderType.values())
- {
- Assert.assertNotNull(constantFactory.getBorder(borderType));
- }
- }
-
- @Test
- public void patternTest()
- {
- for (Pattern pattern : Pattern.values())
- {
- Assert.assertNotNull(constantFactory.getPattern(pattern));
- }
- }
-
- @Test
- public void verticalAlignmentTest()
- {
- for (VerticalAlignment verticalAlignment : VerticalAlignment.values())
- {
- Assert.assertNotNull(constantFactory.getVerticalAlignment(verticalAlignment));
- }
- }
-
- @Test
- public void orientationTest()
- {
- for (Orientation orientation : Orientation.values())
- {
- Assert.assertNotNull(constantFactory.getOrientation(orientation));
- }
- }
-
- @Test
- public void alignmentTest()
- {
- for (Alignment alignment : Alignment.values())
- {
- Assert.assertNotNull(constantFactory.getAlignment(alignment));
- }
- }
-
- @Test
- public void numberFormatTest()
- {
- Map<String, DisplayFormat> numberFormats = constantFactory.loadConstants(DisplayFormat.class, NumberFormats.class);
- for (String key : numberFormats.keySet())
- {
- Assert.assertNotNull(constantFactory.getNumberFormat(key));
- }
- }
-
- @Test
- public void numberFormatShorthandTest()
- {
- Map<String, String> numberFormatShorthands = constantFactory.loadConstants(String.class, NumberFormat.class);
- for (String key : numberFormatShorthands.keySet())
- {
-// Assert.assertNotNull(constantFactory.getNumberFormatShorthand(key));
- }
- }
-
- @Test
- public void dateFormatTest()
- {
- Map<String, DisplayFormat> dateFormats = constantFactory.loadConstants(DisplayFormat.class, DateFormats.class);
- for (String key : dateFormats.keySet())
- {
- Assert.assertNotNull(constantFactory.getDateFormat(key));
- }
- }
-
-}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/EventObserver.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -3,6 +3,9 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
+import org.jboss.seam.spreadsheet.jxl.writer.event.BeforeAdded;
+import org.jboss.seam.spreadsheet.jxl.writer.event.BeforeCreated;
+import org.jboss.seam.spreadsheet.jxl.writer.event.BeforeExecuted;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Worksheet;
import org.jboss.seam.spreadsheet.model.command.Command;
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/JXLSpreadsheetWriterTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -10,6 +10,8 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Workbook;
@@ -30,7 +32,7 @@
@Deployment
public static JavaArchive getArchive()
{
- return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, EventObserver.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class, EventObserver.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
}
@Inject EventObserver eventObserver;
Added: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/command/CellMergeCommandTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,43 @@
+package org.jboss.seam.spreadsheet.jxl.command;
+
+import junit.framework.Assert;
+
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.CellSpan;
+import org.jboss.seam.spreadsheet.model.Coordinate;
+import org.jboss.seam.spreadsheet.model.Workbook;
+import org.jboss.seam.spreadsheet.model.Worksheet;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class CellMergeCommandTest extends SpreadsheetTest
+{
+
+ @Deployment
+ public static JavaArchive getArchive()
+ {
+ return ShrinkWrap.create("foo.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ }
+
+ @Test
+ public void mergeTest()
+ {
+ Cell cell = Cell.of("foo", Coordinate.ORIGO);
+ cell.setCellSpan(CellSpan.of(10, 10));
+ Worksheet ws = Worksheet.named("foo");
+ ws.getCells().add(cell);
+ Workbook wb = new Workbook();
+ wb.getWorksheets().add(ws);
+ // Assert
+ }
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java (from rev 13461, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFactoryTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,39 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import junit.framework.Assert;
+import jxl.write.WritableCell;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Test;
+
+public class CellFactoryTest extends SpreadsheetTest
+{
+
+ @Test
+ public void cellFormatsCachedForEqualCellFormatsTest()
+ {
+ CellFactory cellFactory = new CellFactory();
+ CellFormatResolver cellFormatResolver = new CellFormatResolver();
+ WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
+ WritableCell jxlCell2 = cellFactory.createCell(getTestCell(), cellFormatResolver);
+ Assert.assertTrue(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
+ }
+
+ @Test
+ public void cellFormatsNotCachedForNonEqualCellFormatsTest()
+ {
+ CellFactory cellFactory = new CellFactory();
+ CellFormatResolver cellFormatResolver = new CellFormatResolver();
+ WritableCell jxlCell = cellFactory.createCell(getTestCell(), cellFormatResolver);
+ Cell cell2 = getTestCell();
+ cell2.getCellFormat().setFont(getSampleFont());
+ cell2.getCellFormat().getFont().setColour(Colour.GREEN);
+ WritableCell jxlCell2 = cellFactory.createCell(cell2, cellFormatResolver);
+ Assert.assertFalse(jxlCell.getCellFormat() == jxlCell2.getCellFormat());
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java (from rev 13459, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatFactoryTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,241 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFactory;
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.Background;
+import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
+import org.jboss.seam.spreadsheet.model.formatting.Border;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CellFormatFactoryTest extends SpreadsheetTest
+{
+ private CellFactory cellFactory;
+ private CellFormatResolver cellFormatResolver;
+ private Cell cell;
+
+ @Before
+ public void init()
+ {
+ cellFactory = new CellFactory();
+ cellFormatResolver = new CellFormatResolver();
+ cell = getTestCell();
+ }
+
+ private jxl.write.WritableCell getJxlCell()
+ {
+ return cellFactory.createCell(cell, cellFormatResolver);
+ }
+
+ @Test
+ public void fontTest()
+ {
+ cell.getCellFormat().setFont(getSampleFont());
+ jxl.format.Font jxlFont = getJxlCell().getCellFormat().getFont();
+ Assert.assertEquals("Times New Roman", jxlFont.getName());
+ Assert.assertEquals(700, jxlFont.getBoldWeight());
+ Assert.assertEquals(jxl.format.Colour.RED, jxlFont.getColour());
+ Assert.assertTrue(jxlFont.isItalic());
+ Assert.assertEquals(100, jxlFont.getPointSize());
+ Assert.assertTrue(jxlFont.isStruckout());
+ Assert.assertEquals(jxl.format.ScriptStyle.SUBSCRIPT, jxlFont.getScriptStyle());
+ Assert.assertEquals(jxl.format.UnderlineStyle.DOUBLE, jxlFont.getUnderlineStyle());
+ }
+
+ @Test
+ public void alignmentTest()
+ {
+ cell.getCellFormat().setAlignment(Alignment.RIGHT);
+ Assert.assertEquals(jxl.format.Alignment.RIGHT, getJxlCell().getCellFormat().getAlignment());
+ }
+
+ @Test
+ public void backgroundColourTest()
+ {
+ cell.getCellFormat().setBackground(new Background());
+ cell.getCellFormat().getBackground().setColour(Colour.BLUE);
+ Assert.assertEquals(jxl.format.Colour.BLUE, getJxlCell().getCellFormat().getBackgroundColour());
+ }
+
+ @Test
+ public void borderColourTest()
+ {
+ List<Border> borders = new ArrayList<Border>();
+ Border border = new Border(BorderType.TOP);
+ border.setColour(Colour.PINK);
+ borders.add(border);
+ cell.getCellFormat().setBorders(borders);
+ Assert.assertEquals(jxl.format.Colour.PINK, getJxlCell().getCellFormat().getBorderColour(jxl.format.Border.TOP));
+ }
+
+ @Test
+ public void rightMergedAllBorderTest() {
+ List<Border> borders = new ArrayList<Border>();
+ Border borderL = new Border(BorderType.LEFT);
+ borderL.setColour(Colour.RED);
+ borders.add(borderL);
+
+ Border borderA = new Border(BorderType.ALL);
+ borderA.setLineStyle(BorderLineStyle.DOUBLE);
+ borderA.setColour(Colour.PINK);
+ borders.add(borderA);
+
+ cell.getCellFormat().setBorders(borders);
+
+ jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
+ }
+
+ @Test
+ public void leftMergedAllBorderTest() {
+ List<Border> borders = new ArrayList<Border>();
+
+ Border borderA = new Border(BorderType.ALL);
+ borderA.setLineStyle(BorderLineStyle.DOUBLE);
+ borderA.setColour(Colour.PINK);
+ borders.add(borderA);
+
+ Border borderL = new Border(BorderType.LEFT);
+ borderL.setColour(Colour.RED);
+ borderL.setLineStyle(BorderLineStyle.DOTTED);
+ borders.add(borderL);
+
+
+ cell.getCellFormat().setBorders(borders);
+
+ jxl.format.CellFormat jxlCellFormat = getJxlCell().getCellFormat();
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOTTED, jxlCellFormat.getBorderLine(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, jxlCellFormat.getBorderLine(jxl.format.Border.TOP));
+ Assert.assertEquals(jxl.format.Colour.RED, jxlCellFormat.getBorderColour(jxl.format.Border.LEFT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.RIGHT));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.BOTTOM));
+ Assert.assertEquals(jxl.format.Colour.PINK, jxlCellFormat.getBorderColour(jxl.format.Border.TOP));
+ }
+
+
+ @Test
+ public void borderLineStyleTest()
+ {
+ List<Border> borders = new ArrayList<Border>();
+ Border border = new Border(BorderType.TOP);
+ border.setLineStyle(BorderLineStyle.DOUBLE);
+ borders.add(border);
+ cell.getCellFormat().setBorders(borders);
+ Assert.assertEquals(jxl.format.BorderLineStyle.DOUBLE, getJxlCell().getCellFormat().getBorderLine(jxl.format.Border.TOP));
+ }
+
+ @Test
+ public void indentationTest()
+ {
+ cell.getCellFormat().setIndentation(10);
+ Assert.assertEquals(10, getJxlCell().getCellFormat().getIndentation());
+ }
+
+ @Test
+ public void orientationTest()
+ {
+ cell.getCellFormat().setOrientation(Orientation.MINUS_45);
+ Assert.assertEquals(jxl.format.Orientation.MINUS_45, getJxlCell().getCellFormat().getOrientation());
+ }
+
+ @Test
+ public void patternTest()
+ {
+ cell.getCellFormat().setBackground(new Background());
+ cell.getCellFormat().getBackground().setPattern(Pattern.GRAY_50);
+ Assert.assertEquals(jxl.format.Pattern.GRAY_50, getJxlCell().getCellFormat().getPattern());
+ }
+
+ @Test
+ public void verticalAlignmentTest()
+ {
+ cell.getCellFormat().setVerticalAlignment(VerticalAlignment.TOP);
+ Assert.assertEquals(jxl.format.VerticalAlignment.TOP, getJxlCell().getCellFormat().getVerticalAlignment());
+ }
+
+ @Test
+ public void wrapTest()
+ {
+ cell.getCellFormat().setWrap(true);
+ Assert.assertTrue(getJxlCell().getCellFormat().getWrap());
+ }
+
+ @Test
+ public void lockedTest()
+ {
+ cell.getCellFormat().setLocked(true);
+ Assert.assertTrue(getJxlCell().getCellFormat().isLocked());
+ }
+
+ @Test
+ public void shrinkToFitTest()
+ {
+ cell.getCellFormat().setShrinkToFit(true);
+ Assert.assertTrue(getJxlCell().getCellFormat().isShrinkToFit());
+ }
+
+ @Test
+ public void testCustomDateMask() throws IOException
+ {
+ cell.setValue(new Date());
+ cell.getCellFormat().setMask("dd.MM.yyyy");
+// Assert.assertEquals("MM.yyyy", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testNamedDateMask() throws IOException
+ {
+ cell.setValue(new Date());
+ cell.getCellFormat().setMask("FORMAT9");
+// Assert.assertEquals("M/d/yy H:mm", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testCustomNumberMask()
+ {
+ cell.setValue(1.1111111f);
+ cell.getCellFormat().setMask("#.##");
+// Assert.assertEquals("#.##", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testNamedNumberMask()
+ {
+ cell.setValue(1.1111111f);
+ cell.getCellFormat().setMask("CURRENCY_EURO_PREFIX");
+// Assert.assertEquals("CURRENCY_EURO_PREFIX", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+ @Test
+ public void testNamedNumberMask2()
+ {
+ cell.setValue(1.1111111f);
+ cell.getCellFormat().setMask("EXPONENTIAL");
+// Assert.assertEquals("EXPONENTIAL", getJxlCell().getCellFormat().getFormat().getFormatString());
+ }
+
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java (from rev 13456, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/CellFormatResolverTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/CellFormatResolverTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,98 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.CellFormatResolver;
+import org.jboss.seam.spreadsheet.model.Cell;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.Font;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.junit.Test;
+
+public class CellFormatResolverTest extends SpreadsheetTest
+{
+
+ private class SimpleRule implements CellFormatRule
+ {
+
+ private CellFormat cellFormat;
+
+ public SimpleRule(CellFormat cellFormat)
+ {
+ this.cellFormat = cellFormat;
+ }
+
+ @Override
+ public boolean appliesTo(Cell cell)
+ {
+ return true;
+ }
+
+ @Override
+ public CellFormat getCellFormat()
+ {
+ return cellFormat;
+ }
+
+ }
+
+ @Test
+ public void resolveTest() {
+
+ CellFormat cellFormat = new CellFormat();
+ Font cellFont = new Font();
+ cellFont.setBold(true);
+ cellFormat.setFont(cellFont);
+ Cell cell = new Cell();
+ cell.setCellFormat(cellFormat);
+
+ CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
+ cellFormatResolver.setWorksheetRules(getWorksheetRules());
+ CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
+ Assert.assertEquals(Colour.RED, effectiveCellFormat.getFont().getColour());
+ Assert.assertEquals((Integer)40, effectiveCellFormat.getFont().getPointSize());
+ Assert.assertEquals(Boolean.TRUE, effectiveCellFormat.getFont().getBold());
+ }
+
+ @Test
+ public void resolveAbsoluteTest() {
+
+ CellFormat cellFormat = new CellFormat();
+ cellFormat.setType(CellFormat.Type.ABSOLUTE);
+ cellFormat.setFont(new Font());
+ Cell cell = new Cell();
+ cell.setCellFormat(cellFormat);
+
+ CellFormatResolver cellFormatResolver = new CellFormatResolver(getWorkbookRules());
+ cellFormatResolver.setWorksheetRules(getWorksheetRules());
+ CellFormat effectiveCellFormat = cellFormatResolver.getEffectiveCellFormatting(cell);
+ Assert.assertEquals(null, effectiveCellFormat.getFont().getColour());
+ Assert.assertEquals(null, effectiveCellFormat.getFont().getPointSize());
+ Assert.assertEquals(null, effectiveCellFormat.getFont().getBold());
+ }
+
+ private List<CellFormatRule> getWorkbookRules() {
+ List<CellFormatRule> workbookRules = new ArrayList<CellFormatRule>();
+ CellFormat workbookCellFormat = new CellFormat();
+ Font workbookFont = new Font();
+ workbookFont.setColour(Colour.RED);
+ workbookCellFormat.setFont(workbookFont);
+ workbookRules.add(new SimpleRule(workbookCellFormat));
+ return workbookRules;
+ }
+
+ private List<CellFormatRule> getWorksheetRules() {
+ List<CellFormatRule> worksheetRules = new ArrayList<CellFormatRule>();
+ CellFormat worksheetCellFormat = new CellFormat();
+ Font worksheetFont = new Font();
+ worksheetFont.setPointSize(40);
+ worksheetCellFormat.setFont(worksheetFont);
+ worksheetRules.add(new SimpleRule(worksheetCellFormat));
+ return worksheetRules;
+ }
+}
Copied: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java (from rev 13463, sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/ConstantFactoryTest.java)
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java (rev 0)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/jxl/format/ConstantFactoryTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -0,0 +1,147 @@
+package org.jboss.seam.spreadsheet.jxl.format;
+
+import java.util.Map;
+
+import jxl.biff.DisplayFormat;
+import jxl.write.DateFormat;
+import jxl.write.DateFormats;
+import jxl.write.NumberFormat;
+import jxl.write.NumberFormats;
+
+import org.jboss.seam.spreadsheet.jxl.formatting.ConstantFactory;
+import org.jboss.seam.spreadsheet.model.formatting.Background.Pattern;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderLineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Border.BorderType;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Alignment;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.Orientation;
+import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
+import org.jboss.seam.spreadsheet.model.formatting.Colour;
+import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
+import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConstantFactoryTest extends SpreadsheetTest
+{
+ ConstantFactory constantFactory;
+
+ @Before
+ public void init()
+ {
+ constantFactory = new ConstantFactory();
+ }
+
+ @Test
+ public void coloursTest()
+ {
+ for (Colour colour : Colour.values())
+ {
+ Assert.assertNotNull(constantFactory.getColour(colour));
+ }
+ }
+
+ @Test
+ public void underlineStyleTest()
+ {
+ for (UnderlineStyle underlineStyle : UnderlineStyle.values())
+ {
+ Assert.assertNotNull(constantFactory.getUnderlineStyle(underlineStyle));
+ }
+ }
+
+ @Test
+ public void scriptStyleTest()
+ {
+ for (ScriptStyle scriptStyle : ScriptStyle.values())
+ {
+ Assert.assertNotNull(constantFactory.getScriptStyle(scriptStyle));
+ }
+ }
+
+ @Test
+ public void borderLineTest()
+ {
+ for (BorderLineStyle borderLineStyle : BorderLineStyle.values())
+ {
+ Assert.assertNotNull(constantFactory.getBorderLineStyle(borderLineStyle));
+ }
+ }
+
+ @Test
+ public void borderTypeTest()
+ {
+ for (BorderType borderType : BorderType.values())
+ {
+ Assert.assertNotNull(constantFactory.getBorder(borderType));
+ }
+ }
+
+ @Test
+ public void patternTest()
+ {
+ for (Pattern pattern : Pattern.values())
+ {
+ Assert.assertNotNull(constantFactory.getPattern(pattern));
+ }
+ }
+
+ @Test
+ public void verticalAlignmentTest()
+ {
+ for (VerticalAlignment verticalAlignment : VerticalAlignment.values())
+ {
+ Assert.assertNotNull(constantFactory.getVerticalAlignment(verticalAlignment));
+ }
+ }
+
+ @Test
+ public void orientationTest()
+ {
+ for (Orientation orientation : Orientation.values())
+ {
+ Assert.assertNotNull(constantFactory.getOrientation(orientation));
+ }
+ }
+
+ @Test
+ public void alignmentTest()
+ {
+ for (Alignment alignment : Alignment.values())
+ {
+ Assert.assertNotNull(constantFactory.getAlignment(alignment));
+ }
+ }
+
+ @Test
+ public void numberFormatTest()
+ {
+ Map<String, DisplayFormat> numberFormats = constantFactory.loadConstants(DisplayFormat.class, NumberFormats.class);
+ for (String key : numberFormats.keySet())
+ {
+ Assert.assertNotNull(constantFactory.getNumberFormat(key));
+ }
+ }
+
+ @Test
+ public void numberFormatShorthandTest()
+ {
+ Map<String, String> numberFormatShorthands = constantFactory.loadConstants(String.class, NumberFormat.class);
+ for (String key : numberFormatShorthands.keySet())
+ {
+// Assert.assertNotNull(constantFactory.getNumberFormatShorthand(key));
+ }
+ }
+
+ @Test
+ public void dateFormatTest()
+ {
+ Map<String, DisplayFormat> dateFormats = constantFactory.loadConstants(DisplayFormat.class, DateFormats.class);
+ for (String key : dateFormats.keySet())
+ {
+ Assert.assertNotNull(constantFactory.getDateFormat(key));
+ }
+ }
+
+}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/WorkbookTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -5,7 +5,8 @@
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.seam.spreadsheet.SpreadsheetException;
-import org.jboss.seam.spreadsheet.jxl.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.event.Events;
import org.jboss.seam.spreadsheet.model.formatting.SpreadsheetTest;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.ShrinkWrap;
@@ -20,7 +21,7 @@
@Deployment
public static JavaArchive getArchive()
{
- return ShrinkWrap.create("test.jar", JavaArchive.class).addClass(JXLSpreadsheetWriter.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
+ return ShrinkWrap.create("test.jar", JavaArchive.class).addClasses(JXLSpreadsheetWriter.class, Events.class).addManifestResource(new ByteArrayAsset("<beans/>".getBytes()), ArchivePaths.create("beans.xml"));
}
@Test
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/builder/WorkbookBuilderTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -8,7 +8,7 @@
import junit.framework.Assert;
import org.jboss.seam.spreadsheet.SpreadsheetWriter;
-import org.jboss.seam.spreadsheet.jxl.JXLSpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Range;
@@ -16,10 +16,10 @@
import org.jboss.seam.spreadsheet.model.Worksheet;
import org.jboss.seam.spreadsheet.model.command.ColumnWidthCommand;
import org.jboss.seam.spreadsheet.model.formatting.CellFormat;
-import org.jboss.seam.spreadsheet.model.formatting.CellFormatRule;
import org.jboss.seam.spreadsheet.model.formatting.Colour;
import org.jboss.seam.spreadsheet.model.formatting.Font;
-import org.jboss.seam.spreadsheet.model.formatting.RangeCellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.RangeCellFormatRule;
import org.jboss.seam.spreadsheet.util.Person;
import org.junit.Test;
@@ -123,7 +123,7 @@
public void addWorkbookCellFormatRuleTest()
{
WorkbookBuilder wbb = new WorkbookBuilder();
- wbb.addWorkbookCellFormatRule(RangeCellFormatRule.of(new CellFormat(), Range.of(1, 1, 10, 10)));
+ wbb.addWorkbookCellFormatRule(RangeCellFormatRule.of(Range.of(1, 1, 10, 10), new CellFormat()));
Workbook wb = wbb.getWorkbook();
Assert.assertFalse(wb.getCellFormatRules().isEmpty());
}
@@ -132,7 +132,7 @@
public void addWorksheetCellFormatRuleTest()
{
WorkbookBuilder wbb = new WorkbookBuilder();
- wbb.addWorksheetCellFormatRule(RangeCellFormatRule.of(new CellFormat(), Range.of(1, 1, 10, 10)));
+ wbb.addWorksheetCellFormatRule(RangeCellFormatRule.of(Range.of(1, 1, 10, 10), new CellFormat()));
Workbook wb = wbb.getWorkbook();
Assert.assertFalse(wb.getWorksheets().iterator().next().getCellFormatRules().isEmpty());
}
Modified: sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java
===================================================================
--- sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java 2010-07-22 06:28:55 UTC (rev 13468)
+++ sandbox/modules/spreadsheet/src/test/java/org/jboss/seam/spreadsheet/model/formatting/SpreadsheetTest.java 2010-07-22 06:59:54 UTC (rev 13469)
@@ -1,6 +1,8 @@
package org.jboss.seam.spreadsheet.model.formatting;
import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -9,7 +11,9 @@
import jxl.read.biff.BiffException;
+import org.jboss.seam.spreadsheet.SpreadsheetException;
import org.jboss.seam.spreadsheet.SpreadsheetWriter;
+import org.jboss.seam.spreadsheet.jxl.writer.JXLSpreadsheetWriter;
import org.jboss.seam.spreadsheet.model.Cell;
import org.jboss.seam.spreadsheet.model.Coordinate;
import org.jboss.seam.spreadsheet.model.Range;
@@ -22,16 +26,28 @@
import org.jboss.seam.spreadsheet.model.formatting.CellFormat.VerticalAlignment;
import org.jboss.seam.spreadsheet.model.formatting.Font.ScriptStyle;
import org.jboss.seam.spreadsheet.model.formatting.Font.UnderlineStyle;
+import org.jboss.seam.spreadsheet.model.formatting.rule.CellFormatRule;
+import org.jboss.seam.spreadsheet.model.formatting.rule.RangeCellFormatRule;
public abstract class SpreadsheetTest
{
- @Inject SpreadsheetWriter sw;
+ @Inject
+ SpreadsheetWriter sw;
+ private SpreadsheetWriter getSpreadsheetWriter()
+ {
+ if (sw == null)
+ {
+ sw = new JXLSpreadsheetWriter();
+ }
+ return sw;
+ }
+
protected jxl.Workbook getWorkbook(Workbook workbook)
{
try
{
- byte[] data = sw.writeWorkbook(workbook);
+ byte[] data = getSpreadsheetWriter().writeWorkbook(workbook);
return jxl.Workbook.getWorkbook(new ByteArrayInputStream(data));
}
catch (BiffException e)
@@ -112,6 +128,21 @@
protected CellFormatRule getSampleCellFormatRule()
{
- return new RangeCellFormatRule(new CellFormat(), Range.of(10, 10, 20, 20));
+ return RangeCellFormatRule.of(Range.of(10, 10, 20, 20), new CellFormat());
}
+
+ protected void workbookToFile(Workbook workbook, String fileName)
+ {
+ try
+ {
+ FileOutputStream out = new FileOutputStream(fileName);
+ out.write(sw.writeWorkbook(workbook));
+ out.flush();
+ out.close();
+ }
+ catch (Exception e)
+ {
+ throw new SpreadsheetException(String.format("Could not write to file %s", fileName), e);
+ }
+ }
}
More information about the seam-commits
mailing list