log.println("Getting a sheet");
XSpreadsheets xSpreadsheets = (XSpreadsheets) xSheetDoc.getSheets();
XSpreadsheet oSheet = null;
XSpreadsheet oSheet2 = null;
XIndexAccess oIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class, xSpreadsheets);
try {
oSheet = (XSpreadsheet) AnyConverter.toObject(
new Type(XSpreadsheet.class),
oIndexAccess.getByIndex(0));
oSheet2 = (XSpreadsheet) AnyConverter.toObject(
new Type(XSpreadsheet.class),
oIndexAccess.getByIndex(1));
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
throw new StatusException("Couldn't get a spreadsheet", e);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
throw new StatusException("Couldn't get a spreadsheet", e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace();
throw new StatusException("Couldn't get a spreadsheet", e);
}
try {
log.println("Filling a table");
for (int i = 1; i < mMaxFieldIndex; i++) {
oSheet.getCellByPosition(i, 0).setFormula("Col" + i);
oSheet.getCellByPosition(0, i).setFormula("Row" + i);
oSheet2.getCellByPosition(i, 0).setFormula("Col" + i);
oSheet2.getCellByPosition(0, i).setFormula("Row" + i);
}
for (int i = 1; i < mMaxFieldIndex; i++)
for (int j = 1; j < mMaxFieldIndex; j++) {
oSheet.getCellByPosition(i, j).setValue(i * (j + 1));
oSheet2.getCellByPosition(i, j).setValue(i * (j + 2));
}
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
throw new StatusException("Couldn't fill some cells", e);
}
// change a value of a cell and check the change in the data pilot
// (for the XDataPilotTable.refresh() test)
Object oChangeCell = null;
Object oCheckCell = null;
Integer aChangeValue = null;
try {
// cell of data
oChangeCell = oSheet.getCellByPosition(1, 5);
int x = sCellAdress.Column;
int y = sCellAdress.Row + 3;
// cell of the data pilot output
oCheckCell = oSheet.getCellByPosition(x, y);
aChangeValue = new Integer(27);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
throw new StatusException("Couldn't get cells for changeing.", e);
}
// create the test objects
log.println("Getting test objects");
XDataPilotTablesSupplier DPTS = (XDataPilotTablesSupplier) UnoRuntime.queryInterface(
XDataPilotTablesSupplier.class,
oSheet);
XDataPilotTables DPT = DPTS.getDataPilotTables();
XDataPilotDescriptor DPDsc = DPT.createDataPilotDescriptor();
DPDsc.setSourceRange(sCellRangeAdress);
XPropertySet fieldPropSet = null;
try {
Object oDataPilotField = DPDsc.getDataPilotFields().getByIndex(0);
fieldPropSet = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, oDataPilotField);
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
throw new StatusException("Couldn't create a test environment", e);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
throw new StatusException("Couldn't create a test environment", e);
}
try {
fieldPropSet.setPropertyValue("Function",
com.sun.star.sheet.GeneralFunction.SUM);
fieldPropSet.setPropertyValue("Orientation",
com.sun.star.sheet.DataPilotFieldOrientation.DATA);
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
throw new StatusException("Couldn't create a test environment", e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace();
throw new StatusException("Couldn't create a test environment", e);
} catch (com.sun.star.beans.PropertyVetoException e) {
e.printStackTrace();
throw new StatusException("Couldn't create a test environment", e);
} catch (com.sun.star.beans.UnknownPropertyException e) {
e.printStackTrace();
throw new StatusException("Couldn't create a test environment", e);
}
log.println("Insert the DataPilotTable");
if (DPT.hasByName("DataPilotTable")) {
DPT.removeByName("DataPilotTable");
}
XIndexAccess IA = DPDsc.getDataPilotFields();
getSRange(IA);
DPT.insertNewByName("DataPilotTable", sCellAdress, DPDsc);
try {
oObj = (XInterface) AnyConverter.toObject(
new Type(XInterface.class), IA.getByIndex(0));
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace();
throw new StatusException("Couldn't get data pilot field", e);
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
e.printStackTrace();
throw new StatusException("Couldn't get data pilot field", e);
} catch (com.sun.star.lang.IllegalArgumentException e) {
e.printStackTrace();
throw new StatusException("Couldn't get data pilot field", e);
}
log.println("Creating object - " +
((oObj == null) ? "FAILED" : "OK"));
XDataPilotField xDataPilotField = (XDataPilotField) UnoRuntime.queryInterface(
XDataPilotField.class, oObj);
XIndexAccess xIA = xDataPilotField.getItems();
try {
oObj = (XInterface) UnoRuntime.queryInterface(XInterface.class,
xIA.getByIndex(0));
} catch (com.sun.star.lang.IndexOutOfBoundsException e) {
log.println("Couldn't get DataPilotItemObj");
e.printStackTrace(log);
} catch (com.sun.star.lang.WrappedTargetException e) {
log.println("Couldn't get DataPilotItemObj");