// creation of testobject here
// first we write what we are intend to do to log file
log.println("creating a test environment");
XNameContainer forms = FormTools.getForms(WriterTools.getDrawPage(
xTextDoc));
try {
String[] formNames = forms.getElementNames();
for (int i = 0; i < formNames.length; i++) {
log.println("Removing form '" + formNames[i] + "' ...");
forms.removeByName(formNames[i]);
}
} catch (com.sun.star.lang.WrappedTargetException e) {
e.printStackTrace(log);
} catch (com.sun.star.container.NoSuchElementException e) {
e.printStackTrace(log);
}
String[] formNames = forms.getElementNames();
FormTools.insertForm(xTextDoc, forms, "MyForm");
formNames = forms.getElementNames();
XLoadable formLoader = null;
try {
formLoader = FormTools.bindForm(xTextDoc, "MyForm", dbSourceName,
tableName);
} catch (com.sun.star.uno.Exception e) {
log.println("Cann't bind the form to source '" + dbSourceName +
"', table '" + tableName + "' :");
e.printStackTrace(log);
throw new StatusException("Cann't bind a form", e);
}
// DEBUG
log.println("Forms before adding controls : ");
formNames = forms.getElementNames();
for (int i = 0; i < formNames.length; i++) {
log.println(" '" + formNames[i] + "'");
}
XControlShape shape1 = null;
XControlShape shape2 = null;
try {
log.println("Elements in the 'MyForm' :");
XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class,
forms.getByName("MyForm"));
for (int i = 0; i < formElements1.getCount(); i++) {
XNamed elemName = (XNamed) UnoRuntime.queryInterface(
XNamed.class,
formElements1.getByIndex(i));
log.println(" '" + elemName.getName() + "'");
}
// END DEBUG
//put something on the drawpage
log.println("inserting some ControlShapes");
oShapes = DrawTools.getShapes(WriterTools.getDrawPage(xTextDoc));
shape1 = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
1000, "CommandButton");
shape2 = FormTools.createControlShape(xTextDoc, 5000, 3500, 7500,
5000, "TextField");
XControlShape shape3 = FormTools.createControlShape(xTextDoc, 2000,
1500, 1000,
1000,
"CheckBox");
oShapes.add((XShape) shape1);
oShapes.add((XShape) shape2);
oShapes.add(shape3);
} catch (Exception e) {
e.printStackTrace(log);
}
log.println("Forms after adding controls : ");
formNames = forms.getElementNames();
for (int i = 0; i < formNames.length; i++) {
log.println(" '" + formNames[i] + "'");
}
try {
log.println("Elements in the 'MyForm' :");
XIndexAccess formElements1 = (XIndexAccess) UnoRuntime.queryInterface(
XIndexAccess.class,
forms.getByName("MyForm"));
for (int i = 0; i < formElements1.getCount(); i++) {
XNamed elemName = (XNamed) UnoRuntime.queryInterface(
XNamed.class,
formElements1.getByIndex(i));