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 
24 import com.sun.star.uno.*;
25 import com.sun.star.container.*;
26 import com.sun.star.lang.*;
27 
28 /**************************************************************************/
29 /** an abstract interface for components doing an action on a form component
30 */
31 interface IFormComponentAction
32 {
handle( Object aFormComponent )33 	public abstract void handle( Object aFormComponent ) throws java.lang.Exception;
34 };
35 
36 /**************************************************************************/
37 /** a helper class for travelling a form component tree
38 */
39 class ComponentTreeTraversal implements IFormComponentAction
40 {
41 	/* ------------------------------------------------------------------ */
42 	/** Indicator method to decide whether to step down the tree.
43 
44 		<p>The default implementation checks if the container given is a grid
45 		control model or a <service scope="com.sun.star.form">FormComponents</service>
46 		instance.</p>
47 	*/
shouldStepInto( XIndexContainer xContainer )48 	protected boolean shouldStepInto( XIndexContainer xContainer ) throws com.sun.star.uno.Exception
49 	{
50 		// step down the tree, if possible
51 		XServiceInfo xSI = UNO.queryServiceInfo( xContainer );
52 		if	(	null != xSI
53 			&&	(	xSI.supportsService( "com.sun.star.form.FormComponents" )
54 				||	xSI.supportsService( "com.sun.star.form.component.GridControl" )
55 				)
56 			)
57 		{
58 			return true;
59 		}
60 		else
61 		{
62 			return false;
63 		}
64 	}
65 	/* ------------------------------------------------------------------ */
handle( Object aFormComponent )66 	public void handle( Object aFormComponent ) throws com.sun.star.uno.Exception
67 	{
68 		XIndexContainer xCont = UNO.queryIndexContainer( aFormComponent );
69 		if	(	( null != xCont )
70 			&&	shouldStepInto( xCont )
71 			)
72 		{
73 			for ( int i=0; i<xCont.getCount(); ++i )
74 			{
75 				handle( xCont.getByIndex( i ) );
76 			}
77 		}
78 	}
79 }
80 
81