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 integration.forms; 24 25 import com.sun.star.uno.UnoRuntime; 26 import com.sun.star.form.XFormsSupplier; 27 import com.sun.star.container.XNameAccess; 28 import com.sun.star.container.XIndexAccess; 29 import com.sun.star.container.XChild; 30 import com.sun.star.container.XNamed; 31 import com.sun.star.drawing.XDrawPage; 32 import com.sun.star.lang.XServiceInfo; 33 34 public class FormComponent 35 { 36 private Object m_component; 37 private XNameAccess m_nameAccess; 38 private XIndexAccess m_indexAccess; 39 private XChild m_child; 40 private XNamed m_named; 41 42 /* ------------------------------------------------------------------ */ FormComponent()43 private FormComponent() 44 { 45 m_component = null; 46 m_nameAccess = null; 47 m_indexAccess = null; 48 m_child = null; 49 m_named = null; 50 } 51 52 /* ------------------------------------------------------------------ */ FormComponent( XDrawPage drawPage )53 public FormComponent( XDrawPage drawPage ) 54 { 55 XFormsSupplier supp = (XFormsSupplier)UnoRuntime.queryInterface( 56 XFormsSupplier.class, drawPage ); 57 m_component = supp.getForms(); 58 59 m_nameAccess = (XNameAccess)m_component; 60 m_indexAccess = (XIndexAccess)UnoRuntime.queryInterface( 61 XIndexAccess.class, m_component ); 62 m_child = (XChild)UnoRuntime.queryInterface( 63 XChild.class, m_component ); 64 m_named = (XNamed)UnoRuntime.queryInterface( 65 XNamed.class, m_component ); 66 } 67 68 /* ------------------------------------------------------------------ */ FormComponent( Object element )69 public FormComponent( Object element ) 70 { 71 m_component = element; 72 m_nameAccess = (XNameAccess)UnoRuntime.queryInterface( 73 XNameAccess.class, m_component ); 74 m_indexAccess = (XIndexAccess)UnoRuntime.queryInterface( 75 XIndexAccess.class, m_component ); 76 m_child = (XChild)UnoRuntime.queryInterface( 77 XChild.class, m_component ); 78 m_named = (XNamed)UnoRuntime.queryInterface( 79 XNamed.class, m_component ); 80 } 81 82 /* ------------------------------------------------------------------ */ 83 /** Quick access to a given interface of the view 84 @param aInterfaceClass 85 the class of the interface which shall be returned 86 */ query( Class aInterfaceClass )87 public Object query( Class aInterfaceClass ) 88 { 89 return UnoRuntime.queryInterface( aInterfaceClass, m_component ); 90 } 91 92 /* ------------------------------------------------------------------ */ getByName( String name )93 public FormComponent getByName( String name ) 94 { 95 try 96 { 97 if ( m_nameAccess != null ) 98 return new FormComponent( m_nameAccess.getByName( name ) ); 99 } 100 catch( com.sun.star.uno.Exception e ) 101 { 102 System.err.println( e ); 103 e.printStackTrace( System.err ); 104 } 105 return new FormComponent(); 106 } 107 108 /* ------------------------------------------------------------------ */ getElementNames()109 public String[] getElementNames() 110 { 111 if ( m_nameAccess != null ) 112 return m_nameAccess.getElementNames(); 113 return new String[]{}; 114 } 115 116 /* ------------------------------------------------------------------ */ hasByName( String name )117 public boolean hasByName( String name ) 118 { 119 if ( m_nameAccess != null ) 120 return m_nameAccess.hasByName( name ); 121 return false; 122 } 123 124 /* ------------------------------------------------------------------ */ getCount()125 public int getCount() 126 { 127 if ( m_indexAccess != null ) 128 return m_indexAccess.getCount(); 129 return 0; 130 } 131 132 /* ------------------------------------------------------------------ */ getByIndex( int index )133 public FormComponent getByIndex( int index ) 134 { 135 try 136 { 137 if ( m_indexAccess != null ) 138 return new FormComponent( m_indexAccess.getByIndex( index ) ); 139 } 140 catch( com.sun.star.uno.Exception e ) 141 { 142 System.err.println( e ); 143 e.printStackTrace( System.err ); 144 } 145 return new FormComponent(); 146 } 147 148 /* ------------------------------------------------------------------ */ getElementType( )149 public com.sun.star.uno.Type getElementType( ) 150 { 151 if ( m_indexAccess != null ) 152 return m_indexAccess.getElementType(); 153 else if ( m_nameAccess != null ) 154 return m_nameAccess.getElementType(); 155 return new com.sun.star.uno.Type( String.class ); 156 } 157 158 /* ------------------------------------------------------------------ */ hasElements()159 public boolean hasElements() 160 { 161 if ( m_indexAccess != null ) 162 return m_indexAccess.hasElements(); 163 else if ( m_nameAccess != null ) 164 return m_nameAccess.hasElements(); 165 return false; 166 } 167 168 /* ------------------------------------------------------------------ */ getParent()169 public FormComponent getParent() 170 { 171 if ( m_child != null ) 172 return new FormComponent( m_child.getParent() ); 173 return new FormComponent(); 174 } 175 176 /* ------------------------------------------------------------------ */ getName()177 public String getName() 178 { 179 if ( m_named != null ) 180 return m_named.getName(); 181 return ""; 182 } 183 184 /* ------------------------------------------------------------------ */ getImplementationName()185 public String getImplementationName() 186 { 187 XServiceInfo si = (XServiceInfo)UnoRuntime.queryInterface( 188 XServiceInfo.class, m_component ); 189 if ( si != null ) 190 return si.getImplementationName(); 191 return ""; 192 } 193 } 194