1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 import com
.sun
.star
.beans
.PropertyValue
;
30 import com
.sun
.star
.container
.XIndexAccess
;
31 import com
.sun
.star
.container
.XIndexContainer
;
32 import com
.sun
.star
.document
.XViewDataSupplier
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import lib
.MultiMethodTest
;
38 * Check the XViewDataSupplier interface.
39 * Test idea: take the property values from the index access, change one
40 * property value, put this into the index access and write it back.
41 * Get the property value again and check that the change made it.
43 public class _XViewDataSupplier
extends MultiMethodTest
{
44 public XViewDataSupplier oObj
= null;
45 XIndexAccess xAccess
= null;
46 PropertyValue
[] newProps
= null;
47 PropertyValue
[] oldProps
= null;
48 String myview
= "myview1";
50 public void _getViewData() {
51 xAccess
= oObj
.getViewData();
52 // util.dbg.printInterfaces(xAccess);
53 if (xAccess
!= null) {
54 setViewID(xAccess
, myview
);
56 tRes
.tested("getViewData()", true);
59 public void _setViewData() {
60 if (xAccess
== null) {
61 log
.println("No view data to change available");
62 tRes
.tested("setViewData()", Status
.skipped(true));
65 // 2do: provide an own implementation of the XIndexAccess to set.
66 // this will work without "setViewData()", it just checks that a
67 // setViewData can be done.
68 oObj
.setViewData(xAccess
);
69 XIndexAccess xAccess2
= oObj
.getViewData();
70 String newView
= getViewID(xAccess2
);
71 tRes
.tested("setViewData()", newView
.equals(myview
));
75 private void setViewID(XIndexAccess xAccess
, String value
) {
76 XIndexContainer xIndexContainer
= (XIndexContainer
)UnoRuntime
.queryInterface(XIndexContainer
.class, xAccess
);
77 int count
= xAccess
.getCount();
80 oldProps
= (PropertyValue
[])xAccess
.getByIndex(0);
81 newProps
= new PropertyValue
[oldProps
.length
];
82 for (int j
=0; j
<oldProps
.length
; j
++) {
83 // log.println("Name: " + oldProps[j].Name);
84 // log.println("Value: " + oldProps[j].Value.toString());
85 newProps
[j
] = new PropertyValue();
86 newProps
[j
].Name
= oldProps
[j
].Name
;
87 newProps
[j
].Handle
= oldProps
[j
].Handle
;
88 newProps
[j
].State
= oldProps
[j
].State
;
89 if (oldProps
[j
].Name
.equals("ViewId")) {
90 newProps
[j
].Value
= value
;
94 xIndexContainer
.insertByIndex(0, newProps
);
98 e
.printStackTrace((java
.io
.PrintWriter
)log
);
102 private String
getViewID(XIndexAccess xAccess
) {
103 String retValue
= null;
104 int count
= xAccess
.getCount();
107 oldProps
= (PropertyValue
[])xAccess
.getByIndex(0);
108 for (int j
=0; j
<oldProps
.length
; j
++) {
109 // log.println("Name: " + oldProps[j].Name);
110 // log.println("Value: " + oldProps[j].Value.toString());
111 if (oldProps
[j
].Name
.equals("ViewId")) {
112 retValue
= (String
)newProps
[j
].Value
;
119 e
.printStackTrace((java
.io
.PrintWriter
)log
);