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