1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package ifc.sheet; 24 25 import lib.MultiMethodTest; 26 import lib.Status; 27 import lib.StatusException; 28 29 import com.sun.star.beans.XPropertySet; 30 import com.sun.star.sheet.TableFilterField; 31 import com.sun.star.sheet.XSheetFilterDescriptor; 32 import com.sun.star.sheet.XSheetFilterable; 33 import com.sun.star.sheet.XSpreadsheet; 34 import com.sun.star.table.XColumnRowRange; 35 import com.sun.star.table.XTableRows; 36 import com.sun.star.uno.UnoRuntime; 37 38 39 public class _XSheetFilterable extends MultiMethodTest { 40 public XSheetFilterable oObj; 41 protected XSpreadsheet oSheet; 42 protected XSheetFilterDescriptor desc; 43 before()44 protected void before() { 45 oSheet = (XSpreadsheet) tEnv.getObjRelation("SHEET"); 46 47 if (oSheet == null) { 48 log.println("Object relation oSheet is missing"); 49 log.println("Trying to query the needed Interface"); 50 oSheet = (XSpreadsheet) UnoRuntime.queryInterface( 51 XSpreadsheet.class, tEnv.getTestObject()); 52 53 if (oSheet == null) { 54 throw new StatusException(Status.failed( 55 "Object relation oSheet is missing")); 56 } 57 } 58 } 59 _createFilterDescriptor()60 public void _createFilterDescriptor() { 61 desc = oObj.createFilterDescriptor(true); 62 63 TableFilterField[] tff = new TableFilterField[2]; 64 tff[0] = new TableFilterField(); 65 tff[0].IsNumeric = true; 66 tff[0].Field = 0; 67 tff[0].NumericValue = 2; 68 tff[0].Operator = com.sun.star.sheet.FilterOperator.GREATER_EQUAL; 69 tff[1] = new TableFilterField(); 70 tff[1].IsNumeric = false; 71 tff[1].Field = 1; 72 tff[1].StringValue = "C"; 73 tff[1].Operator = com.sun.star.sheet.FilterOperator.LESS; 74 desc.setFilterFields(tff); 75 tRes.tested("createFilterDescriptor()", true); 76 } 77 _filter()78 public void _filter() { 79 boolean res = true; 80 81 try { 82 oSheet.getCellByPosition(0, 0).setValue(1); 83 oSheet.getCellByPosition(0, 1).setValue(2); 84 oSheet.getCellByPosition(0, 2).setValue(3); 85 oSheet.getCellByPosition(1, 0).setFormula("A"); 86 oSheet.getCellByPosition(1, 1).setFormula("D"); 87 oSheet.getCellByPosition(1, 2).setFormula("B"); 88 oObj.filter(desc); 89 90 XColumnRowRange oColumnRowRange = (XColumnRowRange) UnoRuntime.queryInterface( 91 XColumnRowRange.class, 92 oSheet); 93 XTableRows oRows = (XTableRows) oColumnRowRange.getRows(); 94 XPropertySet rowProp = (XPropertySet) UnoRuntime.queryInterface( 95 XPropertySet.class, 96 oRows.getByIndex(0)); 97 boolean locRes = ((Boolean) rowProp.getPropertyValue("IsVisible")).booleanValue(); 98 99 if (locRes) { 100 log.println("Row 1 should be invisible after filter()"); 101 res &= false; 102 } else { 103 res &= true; 104 } 105 106 rowProp = (XPropertySet) UnoRuntime.queryInterface( 107 XPropertySet.class, oRows.getByIndex(1)); 108 locRes = ((Boolean) rowProp.getPropertyValue("IsVisible")).booleanValue(); 109 110 if (locRes) { 111 log.println("Row 2 should be invisible after filter()"); 112 res &= false; 113 } else { 114 res &= true; 115 } 116 } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 117 log.println("couldn't fill cells " + e.getLocalizedMessage()); 118 res = false; 119 } catch (com.sun.star.lang.WrappedTargetException e) { 120 log.println("problems geting Property 'isVisible' " + 121 e.getLocalizedMessage()); 122 res = false; 123 } catch (com.sun.star.beans.UnknownPropertyException e) { 124 log.println("problems geting Property 'isVisible' " + 125 e.getLocalizedMessage()); 126 res = false; 127 } 128 129 tRes.tested("filter()", res); 130 } 131 }