1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.document;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
26cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
27cdf0e10cSrcweir import com.sun.star.container.XIndexContainer;
28cdf0e10cSrcweir import com.sun.star.document.XViewDataSupplier;
29cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
30cdf0e10cSrcweir import lib.MultiMethodTest;
31cdf0e10cSrcweir import lib.Status;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /**
34cdf0e10cSrcweir  * Check the XViewDataSupplier interface.
35cdf0e10cSrcweir  * Test idea: take the property values from the index access, change one
36cdf0e10cSrcweir  * property value, put this into the index access and write it back.
37cdf0e10cSrcweir  * Get the property value again and check that the change made it.
38cdf0e10cSrcweir  */
39cdf0e10cSrcweir public class _XViewDataSupplier extends MultiMethodTest {
40cdf0e10cSrcweir     public XViewDataSupplier oObj = null;
41cdf0e10cSrcweir     XIndexAccess xAccess = null;
42cdf0e10cSrcweir     PropertyValue[] newProps = null;
43cdf0e10cSrcweir     PropertyValue[] oldProps = null;
44cdf0e10cSrcweir     String myview = "myview1";
45cdf0e10cSrcweir 
_getViewData()46cdf0e10cSrcweir     public void _getViewData() {
47cdf0e10cSrcweir         xAccess = oObj.getViewData();
48cdf0e10cSrcweir //        util.dbg.printInterfaces(xAccess);
49cdf0e10cSrcweir         if (xAccess != null) {
50cdf0e10cSrcweir             setViewID(xAccess, myview);
51cdf0e10cSrcweir         }
52cdf0e10cSrcweir         tRes.tested("getViewData()", true);
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir 
_setViewData()55cdf0e10cSrcweir     public void _setViewData() {
56cdf0e10cSrcweir         if (xAccess == null) {
57cdf0e10cSrcweir             log.println("No view data to change available");
58cdf0e10cSrcweir             tRes.tested("setViewData()", Status.skipped(true));
59cdf0e10cSrcweir         }
60cdf0e10cSrcweir         else {
61cdf0e10cSrcweir             // 2do: provide an own implementation of the XIndexAccess to set.
62cdf0e10cSrcweir             // this will work without "setViewData()", it just checks that a
63cdf0e10cSrcweir             // setViewData can be done.
64cdf0e10cSrcweir             oObj.setViewData(xAccess);
65cdf0e10cSrcweir             XIndexAccess xAccess2 = oObj.getViewData();
66cdf0e10cSrcweir             String newView = getViewID(xAccess2);
67cdf0e10cSrcweir             tRes.tested("setViewData()", newView.equals(myview));
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
setViewID(XIndexAccess xAccess, String value)71cdf0e10cSrcweir     private void setViewID(XIndexAccess xAccess, String value) {
72cdf0e10cSrcweir         XIndexContainer xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xAccess);
73cdf0e10cSrcweir         int count = xAccess.getCount();
74cdf0e10cSrcweir         try {
75cdf0e10cSrcweir             if (count > 0) {
76cdf0e10cSrcweir                 oldProps = (PropertyValue[])xAccess.getByIndex(0);
77cdf0e10cSrcweir                 newProps = new PropertyValue[oldProps.length];
78cdf0e10cSrcweir                 for (int j=0; j<oldProps.length; j++) {
79cdf0e10cSrcweir //                    log.println("Name: " + oldProps[j].Name);
80cdf0e10cSrcweir //                    log.println("Value: " + oldProps[j].Value.toString());
81cdf0e10cSrcweir                     newProps[j] = new PropertyValue();
82cdf0e10cSrcweir                     newProps[j].Name = oldProps[j].Name;
83cdf0e10cSrcweir                     newProps[j].Handle = oldProps[j].Handle;
84cdf0e10cSrcweir                     newProps[j].State = oldProps[j].State;
85cdf0e10cSrcweir                     if (oldProps[j].Name.equals("ViewId")) {
86cdf0e10cSrcweir                         newProps[j].Value = value;
87cdf0e10cSrcweir                     }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir                 }
90cdf0e10cSrcweir                 xIndexContainer.insertByIndex(0, newProps);
91cdf0e10cSrcweir             }
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir         catch(Exception e) {
94cdf0e10cSrcweir             e.printStackTrace((java.io.PrintWriter)log);
95cdf0e10cSrcweir         }
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
getViewID(XIndexAccess xAccess)98cdf0e10cSrcweir     private String getViewID(XIndexAccess xAccess) {
99cdf0e10cSrcweir         String retValue = null;
100cdf0e10cSrcweir         int count = xAccess.getCount();
101cdf0e10cSrcweir         try {
102cdf0e10cSrcweir             if (count > 0) {
103cdf0e10cSrcweir                 oldProps = (PropertyValue[])xAccess.getByIndex(0);
104cdf0e10cSrcweir                 for (int j=0; j<oldProps.length; j++) {
105cdf0e10cSrcweir //                    log.println("Name: " + oldProps[j].Name);
106cdf0e10cSrcweir //                    log.println("Value: " + oldProps[j].Value.toString());
107cdf0e10cSrcweir                     if (oldProps[j].Name.equals("ViewId")) {
108cdf0e10cSrcweir                         retValue = (String)newProps[j].Value;
109cdf0e10cSrcweir                     }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir                 }
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir         catch(Exception e) {
115cdf0e10cSrcweir             e.printStackTrace((java.io.PrintWriter)log);
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir         return retValue;
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir }
120