/************************************************************************* * * $RCSfile: SbaXGridControl.java,v $ * * $Revision: 1.7 $ * * last change:$Date: 2005-03-29 11:58:39 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses * * - GNU Lesser General Public License Version 2.1 * - Sun Industry Standards Source License Version 1.1 * * Sun Microsystems Inc., October, 2000 * * GNU Lesser General Public License Version 2.1 * ============================================= * Copyright 2000 by Sun Microsystems, Inc. * 901 San Antonio Road, Palo Alto, CA 94303, USA * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * * Sun Industry Standards Source License Version 1.1 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.1 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://www.openoffice.org/license.html. * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2000 by Sun Microsystems, Inc. * * All Rights Reserved. * * Contributor(s): _______________________________________ * * ************************************************************************/ package mod._dbaccess; import java.io.PrintWriter; import java.util.Comparator; import lib.StatusException; import lib.TestCase; import lib.TestEnvironment; import lib.TestParameters; import util.AccessibilityTools; import util.FormTools; import util.SOfficeFactory; import util.WriterTools; import util.utils; import com.sun.star.accessibility.AccessibleRole; import com.sun.star.accessibility.XAccessible; import com.sun.star.accessibility.XAccessibleAction; import com.sun.star.awt.Point; import com.sun.star.awt.Size; import com.sun.star.awt.XControlModel; import com.sun.star.awt.XDevice; import com.sun.star.awt.XExtendedToolkit; import com.sun.star.awt.XGraphics; import com.sun.star.awt.XToolkit; import com.sun.star.awt.XWindow; import com.sun.star.awt.XWindowPeer; import com.sun.star.beans.XPropertySet; import com.sun.star.container.XNameContainer; import com.sun.star.drawing.XControlShape; import com.sun.star.drawing.XShape; import com.sun.star.form.XBoundComponent; import com.sun.star.form.XGridColumnFactory; import com.sun.star.form.XLoadable; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.sdbc.XResultSetUpdate; import com.sun.star.text.XTextDocument; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.util.URL; import com.sun.star.util.XCloseable; import com.sun.star.view.XControlAccess; /** * Test for object which represents the control of the Grid model.
* Object implements the following interfaces : *
com::sun::star::util::XModifyBroadcastercom::sun::star::form::XGridFieldDataSuppliercom::sun::star::view::XSelectionSuppliercom::sun::star::form::XGridcom::sun::star::awt::XControlcom::sun::star::util::XModeSelectorcom::sun::star::container::XElementAccesscom::sun::star::awt::XWindowcom::sun::star::form::XUpdateBroadcastercom::sun::star::frame::XDispatchcom::sun::star::container::XEnumerationAccesscom::sun::star::form::XBoundComponentcom::sun::star::frame::XDispatchProviderInterceptioncom::sun::star::container::XIndexAccesscom::sun::star::lang::XComponentcom::sun::star::awt::XViewcom::sun::star::container::XContainercom.sun.star.form.component.GridControl instance
* is added to the ControlShape. Then this model's
* control is retrieved.
*
* Object relations created :
*
* -
'GRAPHICS' for
* {@link ifc.awt_XView} test : XGraphics
* object different that belong to the object tested.
* -
'CONTEXT' for
* {@link ifc.awt._XControl}
* -
'WINPEER' for
* {@link ifc.awt._XCOntrol}
* -
'TOOLKIT' for
* {@link ifc.awt._XCOntrol}
* -
'MODEL' for
* {@link ifc.awt._XCOntrol}
* -
'XWindow.AnotherWindow' for
* {@link ifc.awt._XWindow} for switching focus.
* -
'XDispatch.URL' for
* {@link ifc.frame._XDispatch} the url which moves
* DB cursor to the next row (".uno:FormSlots/moveToNext").
* -
'XContainer.Container' for
* {@link ifc.container._XContainer} as the component created
* doesn't support XContainer itself, but
* it is supported by its model. So this model is passed.
* -
'INSTANCE' for
* {@link ifc.container._XContainer} the instance to be
* inserted into collection. Is a column instance.
*
*/
protected TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
XInterface oObj = null;
XWindowPeer the_win = null;
XToolkit the_kit = null;
XDevice aDevice = null;
XGraphics aGraphic = null;
XPropertySet aControl = null;
XPropertySet aControl2 = null;
XPropertySet aControl3 = null;
XPropertySet aControl4 = null;
XGridColumnFactory columns = null;
//Insert a ControlShape and get the ControlModel
XControlShape aShape = createGrid(xTextDoc, 3000, 4500, 15000, 10000);
XControlModel the_Model = aShape.getControl();
WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
XLoadable formLoader = FormTools.bindForm(xTextDoc);
//Try to query XControlAccess
XControlAccess the_access = (XControlAccess) UnoRuntime.queryInterface(
XControlAccess.class,
xTextDoc.getCurrentController());
try {
columns = (XGridColumnFactory) UnoRuntime.queryInterface(
XGridColumnFactory.class, the_Model);
aControl = columns.createColumn("TextField");
aControl.setPropertyValue("DataField", "Identifier");
aControl.setPropertyValue("Label", "Identifier");
aControl2 = columns.createColumn("TextField");
aControl2.setPropertyValue("DataField", "Publisher");
aControl2.setPropertyValue("Label", "Publisher");
aControl3 = columns.createColumn("TextField");
aControl3.setPropertyValue("DataField", "Author");
aControl3.setPropertyValue("Label", "Author");
aControl4 = columns.createColumn("TextField");
aControl4.setPropertyValue("DataField", "Title");
aControl4.setPropertyValue("Label", "Title");
} catch (com.sun.star.lang.IllegalArgumentException e) {
// Some exception occures.FAILED
log.println("!!! Couldn't create instance : " + e);
throw new StatusException("Can't create column instances.", e);
} catch (com.sun.star.lang.WrappedTargetException e) {
// Some exception occures.FAILED
log.println("!!! Couldn't create instance : " + e);
throw new StatusException("Can't create column instances.", e);
} catch (com.sun.star.beans.PropertyVetoException e) {
// Some exception occures.FAILED
log.println("!!! Couldn't create instance : " + e);
throw new StatusException("Can't create column instances.", e);
} catch (com.sun.star.beans.UnknownPropertyException e) {
// Some exception occures.FAILED
log.println("!!! Couldn't create instance : " + e);
throw new StatusException("Can't create column instances.", e);
}
XNameContainer aContainer = (XNameContainer) UnoRuntime.queryInterface(
XNameContainer.class, the_Model);
try {
aContainer.insertByName("First", aControl);
aContainer.insertByName("Second", aControl2);
} catch (com.sun.star.uno.Exception e) {
log.println("!!! Could't insert column Instance");
e.printStackTrace(log);
throw new StatusException("Can't insert columns", e);
}
//now get the OGridControl
try {
oObj = the_access.getControl(the_Model);
the_win = the_access.getControl(the_Model).getPeer();
the_kit = the_win.getToolkit();
aDevice = the_kit.createScreenCompatibleDevice(200, 200);
aGraphic = aDevice.createGraphics();
} catch (com.sun.star.uno.Exception e) {
log.println("Couldn't get GridControl");
e.printStackTrace(log);
throw new StatusException("Couldn't get GridControl", e);
}
// creating another window
aShape = FormTools.createControlShape(xTextDoc, 3000, 4500, 15000,
10000, "TextField");
WriterTools.getDrawPage(xTextDoc).add((XShape) aShape);
the_Model = aShape.getControl();
//Try to query XControlAccess
the_access = (XControlAccess) UnoRuntime.queryInterface(
XControlAccess.class,
xTextDoc.getCurrentController());
//now get the TextControl
XWindow win = null;
Object cntrl = null;
try {
cntrl = the_access.getControl(the_Model);
win = (XWindow) UnoRuntime.queryInterface(XWindow.class, cntrl);
} catch (com.sun.star.uno.Exception e) {
log.println("Couldn't get Control");
e.printStackTrace(log);
throw new StatusException("Couldn't get Control", e);
}
log.println("creating a new environment for object");
TestEnvironment tEnv = new TestEnvironment(oObj);
//Relations for XSelectionSupplier
tEnv.addObjRelation("Selections",
new Object[] {
new Object[] { new Integer(0) }, new Object[] { new Integer(1) }
});
tEnv.addObjRelation("Comparer",
new Comparator() {
public int compare(Object o1, Object o2) {
return ((Integer) o1).compareTo((Integer)o2);
}
public boolean equals(Object obj) {
return compare(this, obj) == 0;
}
});
//Realtion for XContainer
tEnv.addObjRelation("XContainer.Container", aContainer);
tEnv.addObjRelation("INSTANCE", aControl3);
tEnv.addObjRelation("INSTANCE2", aControl4);
//Adding ObjRelation for XView
tEnv.addObjRelation("GRAPHICS", aGraphic);
//Adding ObjRelation for XControl
tEnv.addObjRelation("CONTEXT", xTextDoc);
tEnv.addObjRelation("WINPEER", the_win);
tEnv.addObjRelation("TOOLKIT", the_kit);
tEnv.addObjRelation("MODEL", the_Model);
// Adding relation for XWindow
tEnv.addObjRelation("XWindow.AnotherWindow", win);
// Adding relation for XDispatch
URL url = new URL();
url.Complete = ".uno:FormSlots/moveToNext";
//url.Complete = ".uno:GridSlots/RowHeight";
//url.Complete = ".uno:GridSlots/RowHeight" ;
tEnv.addObjRelation("XDispatch.URL", url);
log.println("ImplName: " + utils.getImplName(oObj));
FormTools.switchDesignOf((XMultiServiceFactory)Param.getMSF(), xTextDoc);
// adding relation for XUpdateBroadcaster
final XInterface ctrl = oObj;
final XLoadable formLoaderF = formLoader;
final XPropertySet ps = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, aControl2);
tEnv.addObjRelation("XUpdateBroadcaster.Checker",
new ifc.form._XUpdateBroadcaster.UpdateChecker() {
private String lastText = "";
public void update() throws com.sun.star.uno.Exception {
if (!formLoaderF.isLoaded()) {
formLoaderF.load();
}
lastText = "_" + ps.getPropertyValue("Text");
ps.setPropertyValue("Text", lastText);
}
public void commit() throws com.sun.star.sdbc.SQLException {
XBoundComponent bound = (XBoundComponent) UnoRuntime.queryInterface(
XBoundComponent.class, ctrl);
XResultSetUpdate update = (XResultSetUpdate) UnoRuntime.queryInterface(
XResultSetUpdate.class,
formLoaderF);
bound.commit();
update.updateRow();
}
public boolean wasCommited() throws com.sun.star.uno.Exception {
String getS = (String) ps.getPropertyValue("Text");
return lastText.equals(getS);
}
});
return tEnv;
} // finish method getTestEnvironment
public static XControlShape createGrid(XComponent oDoc, int height,
int width, int x, int y) {
Size size = new Size();
Point position = new Point();
XControlShape oCShape = null;
XControlModel aControl = null;
//get MSF
XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
XMultiServiceFactory.class,
oDoc);
try {
Object oInt = oDocMSF.createInstance(
"com.sun.star.drawing.ControlShape");
Object aCon = oDocMSF.createInstance(
"com.sun.star.form.component.GridControl");
XPropertySet model_props = (XPropertySet) UnoRuntime.queryInterface(
XPropertySet.class, aCon);
model_props.setPropertyValue("DefaultControl",
"com.sun.star.form.control.InteractionGridControl");
aControl = (XControlModel) UnoRuntime.queryInterface(
XControlModel.class, aCon);
oCShape = (XControlShape) UnoRuntime.queryInterface(
XControlShape.class, oInt);
size.Height = height;
size.Width = width;
position.X = x;
position.Y = y;
oCShape.setSize(size);
oCShape.setPosition(position);
} catch (com.sun.star.uno.Exception e) {
// Some exception occures.FAILED
System.out.println("Couldn't create Grid" + e);
throw new StatusException("Couldn't create Grid", e);
}
oCShape.setControl(aControl);
return oCShape;
} // finish createGrid
}