protected TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
String sTreeControlName = "UnoTreeControl-Test";
mxMSF = (XMultiServiceFactory) Param.getMSF();
XInterface oObj = null;
XMutableTreeNode xNode = null;
try {
mXTreeDataModel = (XMutableTreeDataModel )
UnoRuntime.queryInterface(XMutableTreeDataModel.class,
mxMSF.createInstance("com.sun.star.awt.tree.MutableTreeDataModel"));
xNode = mXTreeDataModel.createNode("UnoTreeControl", false);
xNode.setDataValue( "UnoTreeControl");
xNode.setExpandedGraphicURL( "private:graphicrepository/sd/res/triangle_down.png");
xNode.setCollapsedGraphicURL( "private:graphicrepository/sd/res/triangle_right.png");
fillNode(xNode);
mXTreeDataModel.setRoot(xNode);
XControlModel xDialogModel = (XControlModel)
UnoRuntime.queryInterface(XControlModel.class,
mxMSF.createInstance("com.sun.star.awt.UnoControlDialogModel"));
XPropertySet xDialogPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xDialogModel);
xDialogPropertySet.setPropertyValue( "PositionX", new Integer(50) );
xDialogPropertySet.setPropertyValue( "PositionY", new Integer(50) );
xDialogPropertySet.setPropertyValue( "Width", new Integer(256) );
xDialogPropertySet.setPropertyValue( "Height", new Integer(256) );
xDialogPropertySet.setPropertyValue( "Title", "Tree Control Test");
XMultiServiceFactory xDialogMSF = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class, xDialogModel);
XControlModel xTreeControlModel = (XControlModel)
UnoRuntime.queryInterface(XControlModel.class,
xDialogMSF.createInstance("com.sun.star.awt.tree.TreeControlModel"));
XPropertySet XTreeControlModelSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTreeControlModel);
XTreeControlModelSet.setPropertyValue( "SelectionType",com.sun.star.view.SelectionType.NONE);
XTreeControlModelSet.setPropertyValue( "PositionX", new Integer(3 ));
XTreeControlModelSet.setPropertyValue( "PositionY", new Integer(3 ));
XTreeControlModelSet.setPropertyValue( "Width", new Integer(253));
XTreeControlModelSet.setPropertyValue( "Height", new Integer(253) );
XTreeControlModelSet.setPropertyValue( "DataModel", mXTreeDataModel );
XTreeControlModelSet.setPropertyValue( "ShowsRootHandles",new Boolean (false));
XTreeControlModelSet.setPropertyValue( "ShowsHandles", new Boolean (false));
XTreeControlModelSet.setPropertyValue( "RootDisplayed", new Boolean (true));
XTreeControlModelSet.setPropertyValue( "Editable", new Boolean (true ));
XNameContainer xDialogModelContainer = (XNameContainer)
UnoRuntime.queryInterface(XNameContainer.class, xDialogModel);
xDialogModelContainer.insertByName( sTreeControlName, xTreeControlModel);
XControl xDialogControl = (XControl)
UnoRuntime.queryInterface(XControl.class,
mxMSF.createInstance("com.sun.star.awt.UnoControlDialog"));
xDialogControl.setModel( xDialogModel );
XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class,
mxMSF.createInstance("com.sun.star.awt.Toolkit" ));
xDialogControl.createPeer( xToolkit, null );
// get the peers of the sub controls from the dialog peer container
XControlContainer xDialogContainer = (XControlContainer)
UnoRuntime.queryInterface(XControlContainer.class ,xDialogControl);
XTreeControl xTreeControl = (XTreeControl)
UnoRuntime.queryInterface(XTreeControl.class, xDialogContainer.getControl( sTreeControlName ));
xTreeControl.expandNode(xNode);
oObj = xTreeControl;
XDialog xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, xDialogControl);
execurteDialog aDialog = new execurteDialog(xDialog);
aDialog.start();
// xDialog.execute();
} catch (com.sun.star.uno.Exception ex) {
ex.printStackTrace();
}
TestEnvironment tEnv = new TestEnvironment(oObj);
tEnv.addObjRelation("XTreeControl_Node", xNode);
//com.sun.star.view.XSelectionSupplier
try {
System.out.println("count of children: " + xNode.getChildCount());
tEnv.addObjRelation("Selections", new Object[]{xNode.getChildAt(0), xNode});
} catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
log.println("ERROR: could not add object relation 'Selections' because 'xNode.getChildAt(1) failed: " +
ex.toString());
}
tEnv.addObjRelation("Comparer",
new Comparator() {
public int compare(Object o1, Object o2) {
XMutableTreeNode xNode1 = (XMutableTreeNode) UnoRuntime.queryInterface(
XMutableTreeNode.class, o1);
XTreeNode xNode2a = null;
try {
xNode2a = (XTreeNode) AnyConverter.toObject(new Type(XTreeNode.class), o2);
} catch (com.sun.star.lang.IllegalArgumentException ex) {
ex.printStackTrace();
}
XMutableTreeNode xNode2 = (XMutableTreeNode) UnoRuntime.queryInterface(
XMutableTreeNode.class, xNode2a);
if (((String) xNode1.getDataValue()).equals((String)xNode2.getDataValue())) {
return 0;
}
return -1;
}