1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSheetOutline.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.sheet
.XCellRangesQuery
;
33 import com
.sun
.star
.sheet
.XSheetCellRanges
;
34 import lib
.MultiMethodTest
;
36 import com
.sun
.star
.sheet
.XSheetOutline
;
37 import com
.sun
.star
.table
.CellRangeAddress
;
38 import com
.sun
.star
.table
.TableOrientation
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
41 import lib
.StatusException
;
46 public class _XSheetOutline
extends MultiMethodTest
{
47 public XSheetOutline oObj
= null;
48 CellRangeAddress address
= null;
49 CellRangeAddress subaddress
= null;
51 public void before() {
52 address
= (CellRangeAddress
)tEnv
.getObjRelation("CellRangeAddress");
53 subaddress
= (CellRangeAddress
)tEnv
.getObjRelation("CellRangeSubAddress");
55 throw new StatusException(Status
.failed("Object relation CellRangeAddress not found"));
56 if (subaddress
== null)
57 throw new StatusException(Status
.failed("Object relation CellRangeSubAddress not found"));
60 public void _autoOutline() {
61 executeMethod("ungroup()");
62 boolean result
= false;
63 oObj
.autoOutline(address
);
64 // initially the range is grouped and shown
65 result
= isCellShown(subaddress
);
66 oObj
.hideDetail(address
);
67 // here only a part of the address is hidden: subaddress must be that part
68 result
&= !isCellShown(subaddress
);
69 tRes
.tested("autoOutline()", result
);
72 public void _clearOutline() {
73 executeMethod("autoOutline()");
74 boolean result
= false;
76 result
= isCellShown(subaddress
);
77 oObj
.hideDetail(address
);
78 result
&= isCellShown(subaddress
);
79 tRes
.tested("clearOutline()", result
);
82 public void _group() {
83 oObj
.group(address
, TableOrientation
.COLUMNS
);
84 oObj
.group(address
, TableOrientation
.ROWS
);
85 tRes
.tested("group()", true);
88 public void _ungroup() {
89 executeMethod("showDetail()");
90 oObj
.ungroup(address
, TableOrientation
.COLUMNS
);
91 oObj
.ungroup(address
, TableOrientation
.ROWS
);
92 oObj
.hideDetail(address
);
93 tRes
.tested("ungroup()", isCellShown(address
));
96 public void _hideDetail() {
97 requiredMethod("group()");
98 oObj
.hideDetail(address
);
99 tRes
.tested("hideDetail()", !isCellShown(address
));
102 public void _showDetail() {
103 executeMethod("showLevel()");
104 oObj
.showDetail(address
);
105 tRes
.tested("showDetail()", isCellShown(address
));
108 public void _showLevel() {
109 executeMethod("hideDetail()");
110 boolean result
= false;
111 oObj
.showLevel((short)2, TableOrientation
.COLUMNS
);
112 oObj
.showLevel((short)2, TableOrientation
.ROWS
);
113 result
= isCellShown(address
);
114 oObj
.showLevel((short)0, TableOrientation
.COLUMNS
);
115 oObj
.showLevel((short)0, TableOrientation
.ROWS
);
117 result
&= !isCellShown(address
);
118 tRes
.tested("showLevel()", result
);
121 private boolean isCellShown(CellRangeAddress range
) {
122 boolean isNotShown
= true;
123 XCellRangesQuery xCellRangesQuery
= (XCellRangesQuery
)UnoRuntime
.queryInterface(XCellRangesQuery
.class, oObj
);
124 if (xCellRangesQuery
!= null) {
125 XSheetCellRanges xRanges
= xCellRangesQuery
.queryVisibleCells();
126 CellRangeAddress
[] visibleRanges
= xRanges
.getRangeAddresses();
127 for (int i
=0; i
<visibleRanges
.length
; i
++) {
128 isNotShown
&= dotIsOutsideRange(range
.StartRow
, range
.StartColumn
, visibleRanges
[i
]);
129 isNotShown
&= dotIsOutsideRange(range
.StartRow
, range
.EndColumn
, visibleRanges
[i
]);
130 isNotShown
&= dotIsOutsideRange(range
.EndRow
, range
.StartColumn
, visibleRanges
[i
]);
131 isNotShown
&= dotIsOutsideRange(range
.EndRow
, range
.EndColumn
, visibleRanges
[i
]);
132 log
.println(isNotShown?
"\tisOutSide":"\tisInside");
138 private boolean dotIsOutsideRange(int dotRow
, int dotColumn
, CellRangeAddress range
) {
139 log
.println("Checking dot(" + dotRow
+ "," + dotColumn
+ ") against row["
140 + range
.StartRow
+ ":" + range
.EndRow
+ "] column["
141 + range
.StartColumn
+ ":" + range
.EndColumn
+ "]");
142 boolean isInside
= true;
143 if (dotRow
>= range
.StartRow
&& dotRow
<= range
.EndRow
)
144 if (dotColumn
>= range
.StartColumn
&& dotColumn
<= range
.EndColumn
)