1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
26cdf0e10cSrcweir import com.sun.star.uno.Any;
27cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
28cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
29cdf0e10cSrcweir import com.sun.star.uno.TypeClass;
30cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
31cdf0e10cSrcweir import com.sun.star.uno.Type;
32cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
33cdf0e10cSrcweir import com.sun.star.beans.XIntrospectionAccess;
34cdf0e10cSrcweir import com.sun.star.beans.Property;
35cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
36cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
37cdf0e10cSrcweir import com.sun.star.reflection.XIdlMethod;
38cdf0e10cSrcweir import javax.swing.tree.ExpandVetoException;
39cdf0e10cSrcweir import org.openoffice.XInstanceInspector;
40cdf0e10cSrcweir import javax.swing.tree.TreePath;
41cdf0e10cSrcweir import javax.swing.event.TreeWillExpandListener;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     public class InspectorPane extends WeakBase implements XInstanceInspector{  //, XServiceInfo
44cdf0e10cSrcweir         private XIdlMethod[] xIdlMethods;
45cdf0e10cSrcweir         private Property[] aProperties;
46cdf0e10cSrcweir         private boolean bIncludeContent = false;
47cdf0e10cSrcweir         private XComponentContext m_xComponentContext;
48cdf0e10cSrcweir         private XDialogProvider m_xDialogProvider;
49cdf0e10cSrcweir         private Introspector m_oIntrospector = null;
50cdf0e10cSrcweir         private SourceCodeGenerator m_oSourceCodeGenerator;
51cdf0e10cSrcweir         private XTreeControlProvider m_xTreeControlProvider;
52cdf0e10cSrcweir         private String sTitle = "";
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
55cdf0e10cSrcweir         /** The constructor of the inner class has a XMultiServiceFactory parameter.
56cdf0e10cSrcweir          * @param xMultiServiceFactory XMultiServiceFactory
57cdf0e10cSrcweir          */
58cdf0e10cSrcweir         public InspectorPane(XComponentContext _xComponentContext, XDialogProvider _xDialogProvider, XTreeControlProvider _xTreeControlProvider, int _nLanguage) {
59cdf0e10cSrcweir             m_xComponentContext = _xComponentContext;
60cdf0e10cSrcweir             m_xTreeControlProvider = _xTreeControlProvider;
61cdf0e10cSrcweir             m_xDialogProvider = _xDialogProvider;
62cdf0e10cSrcweir             m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
63cdf0e10cSrcweir             m_oSourceCodeGenerator = new SourceCodeGenerator(_nLanguage);
64cdf0e10cSrcweir             _xTreeControlProvider.addInspectorPane(this);
65cdf0e10cSrcweir         }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         private void setMaximumOfProgressBar(Object _oUnoObject){
69cdf0e10cSrcweir             int nMaxValue = 0;
70cdf0e10cSrcweir             xIdlMethods = m_oIntrospector.getMethods(_oUnoObject);
71cdf0e10cSrcweir             aProperties = m_oIntrospector.getProperties(_oUnoObject);
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         /** Inspect the given object for methods, properties, interfaces, and
76cdf0e10cSrcweir          * services.
77cdf0e10cSrcweir          * @param a The object to inspect
78cdf0e10cSrcweir          * @throws RuntimeException If
79cdf0e10cSrcweir          */
80cdf0e10cSrcweir         public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
81cdf0e10cSrcweir         try {
82cdf0e10cSrcweir             Object oContainer = m_xTreeControlProvider.inspect(_oUserDefinedObject, _sTitle);
83cdf0e10cSrcweir             m_xDialogProvider.addInspectorPage(getTitle(), oContainer);
84cdf0e10cSrcweir         }
85cdf0e10cSrcweir         catch( Exception exception ) {
86cdf0e10cSrcweir             exception.printStackTrace(System.out);
87cdf0e10cSrcweir         }}
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         public void setTitle(String _sTitle){
91cdf0e10cSrcweir             if (_sTitle != null){
92cdf0e10cSrcweir                 if (_sTitle.length() > 0){
93cdf0e10cSrcweir                     sTitle = _sTitle;
94cdf0e10cSrcweir                 }
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         public String getTitle(){
100cdf0e10cSrcweir             return sTitle;
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         private Type[] getTypes(Object _oUnoObject){
106cdf0e10cSrcweir             Type[] aTypes = null;
107cdf0e10cSrcweir             if (m_oIntrospector.isArray(_oUnoObject)){
108cdf0e10cSrcweir                 aTypes = (Type[])_oUnoObject;
109cdf0e10cSrcweir             }
110cdf0e10cSrcweir             else{
111cdf0e10cSrcweir                 aTypes = m_oIntrospector.getInterfaces(_oUnoObject);
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir             return aTypes;
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         private Object invoke(XUnoMethodNode _oUnoMethodNode){
118cdf0e10cSrcweir         try{
119cdf0e10cSrcweir             String sParamValueDescription = "";
120cdf0e10cSrcweir             Object oUnoReturnObject = _oUnoMethodNode.invoke();
121cdf0e10cSrcweir             boolean bHasParameters = _oUnoMethodNode.hasParameters();
122cdf0e10cSrcweir             boolean bIsPrimitive = _oUnoMethodNode.isPrimitive();
123cdf0e10cSrcweir                 if (bHasParameters){
124cdf0e10cSrcweir                     sParamValueDescription = " (" + m_oSourceCodeGenerator.getMethodParameterValueDescription(_oUnoMethodNode, _oUnoMethodNode.getLastParameterObjects(), true) + ")";
125cdf0e10cSrcweir                 }
126cdf0e10cSrcweir             if (oUnoReturnObject != null ){
127cdf0e10cSrcweir                 String sNodeDescription = "";
128cdf0e10cSrcweir                 XUnoNode oUnoNode = null;
129cdf0e10cSrcweir                 if (_oUnoMethodNode.getXIdlMethod().getReturnType().getTypeClass().getValue() == TypeClass.VOID_value){
130cdf0e10cSrcweir                     sNodeDescription += _oUnoMethodNode.getXIdlMethod().getReturnType().getName() + " " + _oUnoMethodNode.getXIdlMethod().getName() + sParamValueDescription;
131cdf0e10cSrcweir                     _oUnoMethodNode.setLabel(sNodeDescription);
132cdf0e10cSrcweir                     m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
133cdf0e10cSrcweir                 }
134cdf0e10cSrcweir                 else if (bHasParameters || !bIsPrimitive){
135cdf0e10cSrcweir                     if (bIsPrimitive){
136cdf0e10cSrcweir                         sNodeDescription += m_oSourceCodeGenerator.getStringValueOfObject(oUnoReturnObject, _oUnoMethodNode.getTypeClass());
137cdf0e10cSrcweir                     }
138cdf0e10cSrcweir                     else{
139cdf0e10cSrcweir                         Any aReturnObject = Any.complete(oUnoReturnObject);
140cdf0e10cSrcweir                         String sShortClassName = m_oIntrospector.getShortClassName(aReturnObject.getType().getTypeName());
141cdf0e10cSrcweir                         sNodeDescription += m_oSourceCodeGenerator.getVariableNameforUnoObject(sShortClassName);
142cdf0e10cSrcweir                     }
143cdf0e10cSrcweir                     if (m_oIntrospector.isArray(oUnoReturnObject)){
144cdf0e10cSrcweir                         if (m_oIntrospector.isUnoTypeObject(oUnoReturnObject)){
145cdf0e10cSrcweir                             oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoMethodNode.getUnoObject());
146cdf0e10cSrcweir                         }
147cdf0e10cSrcweir                         else if(m_oIntrospector.isUnoPropertyTypeObject(oUnoReturnObject)){
148cdf0e10cSrcweir                             oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYINFODESCRIPTION, oUnoReturnObject);
149cdf0e10cSrcweir                         }
150cdf0e10cSrcweir                         else if(m_oIntrospector.isUnoPropertyValueTypeObject(oUnoReturnObject)){
151cdf0e10cSrcweir                             oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION, oUnoReturnObject);
152cdf0e10cSrcweir                         }
153cdf0e10cSrcweir                     }
154cdf0e10cSrcweir                     if (oUnoNode == null){
155cdf0e10cSrcweir                         if (bHasParameters){
156cdf0e10cSrcweir                             sNodeDescription += sParamValueDescription;
157cdf0e10cSrcweir                         }
158cdf0e10cSrcweir                         oUnoNode = addUnoNode(null, oUnoReturnObject, sNodeDescription);
159cdf0e10cSrcweir                         if (bHasParameters){
160cdf0e10cSrcweir                             oUnoNode.setParameterObjects(_oUnoMethodNode.getLastParameterObjects());
161cdf0e10cSrcweir                         }
162cdf0e10cSrcweir                     }
163cdf0e10cSrcweir                     if (oUnoNode != null){
164cdf0e10cSrcweir                         oUnoNode.setFoldable(!bIsPrimitive);
165cdf0e10cSrcweir                         _oUnoMethodNode.setFoldable(false);
166cdf0e10cSrcweir                         _oUnoMethodNode.addChildNode(oUnoNode);
167cdf0e10cSrcweir                         m_xTreeControlProvider.nodeInserted(_oUnoMethodNode, oUnoNode, _oUnoMethodNode.getChildCount()-1);
168cdf0e10cSrcweir                     }
169cdf0e10cSrcweir                 }
170cdf0e10cSrcweir                 else{
171cdf0e10cSrcweir                     if (bIsPrimitive){
172cdf0e10cSrcweir                         sNodeDescription  = _oUnoMethodNode.getStandardMethodDescription() + "=" + UnoMethodNode.getDisplayValueOfPrimitiveType(oUnoReturnObject);
173cdf0e10cSrcweir                         _oUnoMethodNode.setLabel(sNodeDescription);
174cdf0e10cSrcweir                         m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
175cdf0e10cSrcweir                     }
176cdf0e10cSrcweir                 }
177cdf0e10cSrcweir             }
178cdf0e10cSrcweir             // ReturnObject of method node == null..
179cdf0e10cSrcweir             else{
180cdf0e10cSrcweir                 if (!bHasParameters){
181cdf0e10cSrcweir                     _oUnoMethodNode.setLabel(_oUnoMethodNode.getLabel() + " = null");
182cdf0e10cSrcweir                 }
183cdf0e10cSrcweir                 else{
184cdf0e10cSrcweir                     _oUnoMethodNode.setLabel(_oUnoMethodNode.getXIdlMethod().getName() + sParamValueDescription + " = null");
185cdf0e10cSrcweir                 }
186cdf0e10cSrcweir                 m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir             return oUnoReturnObject;
189cdf0e10cSrcweir         }catch(Exception exception ) {
190cdf0e10cSrcweir             return null;
191cdf0e10cSrcweir         }}
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         public void invokeSelectedMethodNode(){
195cdf0e10cSrcweir             XTreePathProvider xTreePathProvider = m_xTreeControlProvider.getSelectedPath();
196cdf0e10cSrcweir             XUnoNode oUnoNode = xTreePathProvider.getLastPathComponent();
197cdf0e10cSrcweir             if (oUnoNode instanceof XUnoMethodNode){
198cdf0e10cSrcweir                 invoke((XUnoMethodNode) oUnoNode);
199cdf0e10cSrcweir                 m_xTreeControlProvider.expandPath(xTreePathProvider);
200cdf0e10cSrcweir             }
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 
204cdf0e10cSrcweir         public void addSourceCodeOfSelectedNode(){
205cdf0e10cSrcweir             XTreePathProvider oTreePathProvider = m_xTreeControlProvider.getSelectedPath();
206cdf0e10cSrcweir             XUnoNode oUnoNode = oTreePathProvider.getLastPathComponent();
207cdf0e10cSrcweir             if (oUnoNode instanceof XUnoMethodNode){
208cdf0e10cSrcweir                 XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
209cdf0e10cSrcweir                 if (!oUnoMethodNode.isInvoked() && oUnoMethodNode.isInvokable()){
210cdf0e10cSrcweir                     invoke(oUnoMethodNode);
211cdf0e10cSrcweir                 }
212cdf0e10cSrcweir             }
213cdf0e10cSrcweir             String sSourceCode = m_oSourceCodeGenerator.addSourceCodeOfUnoObject(oTreePathProvider, true, true, true);
214cdf0e10cSrcweir             m_xTreeControlProvider.setSourceCode(sSourceCode);
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         public void convertCompleteSourceCode(int _nLanguage){
219cdf0e10cSrcweir             String sSourceCode = m_oSourceCodeGenerator.convertAllUnoObjects(_nLanguage);
220cdf0e10cSrcweir             m_xTreeControlProvider.setSourceCode(sSourceCode);
221cdf0e10cSrcweir         }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir         protected XUnoNode getSelectedNode(){
224cdf0e10cSrcweir             return m_xTreeControlProvider.getSelectedNode();
225cdf0e10cSrcweir         }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         //  add the object to the hashtable for a possible access in the tree
229cdf0e10cSrcweir         private  XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject){
230cdf0e10cSrcweir             return m_xTreeControlProvider.addUnoFacetteNode( _oParentNode, _sNodeDescription, _oUnoObject);
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         private XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod){
235cdf0e10cSrcweir             return m_xTreeControlProvider.addMethodNode(_objectElement, _xIdlMethod);
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 
240cdf0e10cSrcweir         public void addMethodsToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, XIdlMethod[] _xIdlMethods){
241cdf0e10cSrcweir             if (this.m_oIntrospector.isValid(_xIdlMethods)){
242cdf0e10cSrcweir                 for ( int n = 0; n < _xIdlMethods.length; n++ ) {
243cdf0e10cSrcweir                     XIdlMethod xIdlMethod = _xIdlMethods[n];
244cdf0e10cSrcweir                     if (!xIdlMethod.getDeclaringClass().getName().equals("com.sun.star.uno.XInterface")){
245cdf0e10cSrcweir                         XUnoMethodNode oChildNode = addMethodNode(_oUnoParentObject, xIdlMethod);
246cdf0e10cSrcweir                         if (oChildNode != null){
247cdf0e10cSrcweir                             _oGrandParentNode.addChildNode(oChildNode);
248cdf0e10cSrcweir                         }
249cdf0e10cSrcweir                     }
250cdf0e10cSrcweir                 }
251cdf0e10cSrcweir             }
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         private void addFacetteNodesToTreeNode(XUnoNode _oParentNode, Object _oUnoObject){
256cdf0e10cSrcweir             if (m_oIntrospector.hasMethods(_oUnoObject)){
257cdf0e10cSrcweir                 XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SMETHODDESCRIPTION, _oUnoObject);
258cdf0e10cSrcweir             }
259cdf0e10cSrcweir             if (m_oIntrospector.hasProperties(_oUnoObject)){
260cdf0e10cSrcweir                 XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SPROPERTYDESCRIPTION, _oUnoObject);
261cdf0e10cSrcweir             }
262cdf0e10cSrcweir             if (m_oIntrospector.hasInterfaces(_oUnoObject)){
263cdf0e10cSrcweir                 XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoObject);
264cdf0e10cSrcweir             }
265cdf0e10cSrcweir             if (m_oIntrospector.isContainer(_oUnoObject)){
266cdf0e10cSrcweir                 XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SCONTAINERDESCRIPTION, _oUnoObject);
267cdf0e10cSrcweir             }
268cdf0e10cSrcweir             if (m_oIntrospector.hasSupportedServices(_oUnoObject)){
269cdf0e10cSrcweir                 XUnoFacetteNode oUnoFacetteNode = addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SSERVICEDESCRIPTION, _oUnoObject);
270cdf0e10cSrcweir             }
271cdf0e10cSrcweir         }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 
274cdf0e10cSrcweir         private void addInterfacesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, Type[] _aTypes) {
275cdf0e10cSrcweir         try {
276cdf0e10cSrcweir             if (_oUnoParentObject != null){
277cdf0e10cSrcweir                 for ( int m = 0; m < _aTypes.length; m++ ) {
278cdf0e10cSrcweir                     addUnoNode(_oGrandParentNode, _oUnoParentObject, _aTypes[m]);
279cdf0e10cSrcweir                 }
280cdf0e10cSrcweir             }
281cdf0e10cSrcweir         }
282cdf0e10cSrcweir         catch( Exception exception ) {
283cdf0e10cSrcweir             exception.printStackTrace(System.out);
284cdf0e10cSrcweir         }}
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         //  add all services for the given object to the tree under the node parent
288cdf0e10cSrcweir         private void addServicesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoObject) {
289cdf0e10cSrcweir         try{
290cdf0e10cSrcweir             XServiceInfo xServiceInfo = ( XServiceInfo ) UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject );
291cdf0e10cSrcweir             if ( xServiceInfo != null ){
292cdf0e10cSrcweir                 String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
293cdf0e10cSrcweir                 for ( int m = 0; m < sSupportedServiceNames.length; m++ ) {
294cdf0e10cSrcweir                     String sServiceName = sSupportedServiceNames[m];
295cdf0e10cSrcweir                     if (sServiceName.length() > 0){
296cdf0e10cSrcweir                         XUnoNode oUnoNode = addUnoNode(_oGrandParentNode, _oUnoObject, sSupportedServiceNames[m]);
297cdf0e10cSrcweir                         oUnoNode.setNodeType(XUnoNode.nSERVICE);
298cdf0e10cSrcweir                     }
299cdf0e10cSrcweir                 }
300cdf0e10cSrcweir             }
301cdf0e10cSrcweir         }
302cdf0e10cSrcweir         catch(Exception exception) {
303cdf0e10cSrcweir             exception.printStackTrace(System.out);
304cdf0e10cSrcweir         }}
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
307cdf0e10cSrcweir         private void addPropertiesAndInterfacesOfService(XUnoNode _oUnoServiceNode){
308cdf0e10cSrcweir             String sServiceName  = _oUnoServiceNode.getClassName();
309cdf0e10cSrcweir             Object oUnoObject = _oUnoServiceNode.getUnoObject();
310cdf0e10cSrcweir             addInterfacesToTreeNode(_oUnoServiceNode, oUnoObject, m_oIntrospector.getInterfaces(oUnoObject, sServiceName));
311cdf0e10cSrcweir             addPropertiesToTreeNode(_oUnoServiceNode, oUnoObject, m_oIntrospector.getProperties(oUnoObject, sServiceName));
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     private void addPropertiesToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject,  Property[] _aProperties) {
316cdf0e10cSrcweir     try {
317cdf0e10cSrcweir         if (_aProperties.length > 0){
318cdf0e10cSrcweir             for ( int n = 0; n < _aProperties.length; n++ ){
319cdf0e10cSrcweir                 Property aProperty = _aProperties[n];
320cdf0e10cSrcweir                 XIntrospectionAccess xIntrospectionAccess = m_oIntrospector.getXIntrospectionAccess(_oUnoParentObject);
321cdf0e10cSrcweir                 XPropertySet xPropertySet = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, xIntrospectionAccess.queryAdapter(new Type( XPropertySet.class)));
322cdf0e10cSrcweir                 if (xPropertySet != null) {
323cdf0e10cSrcweir                     if (xPropertySet.getPropertySetInfo().hasPropertyByName(aProperty.Name)){
324cdf0e10cSrcweir                         Object objectElement = xPropertySet.getPropertyValue(aProperty.Name);
325cdf0e10cSrcweir                         if (objectElement != null) {
326cdf0e10cSrcweir                             XUnoNode oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoParentObject, aProperty, objectElement);
327cdf0e10cSrcweir                             if (oChildNode != null){
328cdf0e10cSrcweir                                 _oParentNode.addChildNode(oChildNode);
329cdf0e10cSrcweir                             }
330cdf0e10cSrcweir                         }
331cdf0e10cSrcweir                     }
332cdf0e10cSrcweir                 }
333cdf0e10cSrcweir             }
334cdf0e10cSrcweir         }
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir     catch(Exception exception) {
337cdf0e10cSrcweir         exception.printStackTrace(System.out);
338cdf0e10cSrcweir     }}
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     public void addContainerElementsToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject){
342cdf0e10cSrcweir         Object[] oUnoContainerElements = m_oIntrospector.getUnoObjectsOfContainer(_oUnoParentObject);
343cdf0e10cSrcweir         if (m_oIntrospector.isValid(oUnoContainerElements)){
344cdf0e10cSrcweir             if (oUnoContainerElements.length > 0){
345cdf0e10cSrcweir                 for (int i=0; i< oUnoContainerElements.length; i++){
346cdf0e10cSrcweir                     XUnoNode oChildNode = addUnoNode(_oParentNode, oUnoContainerElements[i], UnoNode.getNodeDescription(oUnoContainerElements[i]));
347cdf0e10cSrcweir                     m_xTreeControlProvider.nodeInserted(_oParentNode, oChildNode, _oParentNode.getChildCount()-1);
348cdf0e10cSrcweir                 }
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 
354cdf0e10cSrcweir     private XUnoNode addUnoNode(XUnoNode _oParentNode, Object _oUnoObject, String _sLabel ){
355cdf0e10cSrcweir         XUnoNode oUnoNode = this.m_xTreeControlProvider.addUnoNode(_oUnoObject);
356cdf0e10cSrcweir         oUnoNode.setLabel(_sLabel);
357cdf0e10cSrcweir         if (_oParentNode != null){
358cdf0e10cSrcweir             _oParentNode.addChildNode(oUnoNode);
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir         setNodeFoldable(oUnoNode, _oUnoObject);
361cdf0e10cSrcweir         return oUnoNode;
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 
365cdf0e10cSrcweir     private void setNodeFoldable(XUnoNode _oUnoNode, Object _oUnoObject){
366cdf0e10cSrcweir         if (_oUnoObject != null){
367cdf0e10cSrcweir             if (!m_oIntrospector.isObjectPrimitive(_oUnoObject)){
368cdf0e10cSrcweir                 _oUnoNode.setFoldable(true);
369cdf0e10cSrcweir             }
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     private XUnoNode addUnoNode(XUnoNode _oParentNode, Object _oUnoObject, Type _aType){
375cdf0e10cSrcweir         XUnoNode oUnoNode = this.m_xTreeControlProvider.addUnoNode(_oUnoObject, _aType);
376cdf0e10cSrcweir         if (_oParentNode != null){
377cdf0e10cSrcweir             _oParentNode.addChildNode(oUnoNode);
378cdf0e10cSrcweir         }
379cdf0e10cSrcweir         setNodeFoldable(oUnoNode, _oUnoObject);
380cdf0e10cSrcweir         return oUnoNode;
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     private void addPropertySetInfoNodesToTreeNode(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){
385cdf0e10cSrcweir         if (_oUnoObject.getClass().isArray()){
386cdf0e10cSrcweir             Object[] object = ( Object[] ) _oUnoObject;
387cdf0e10cSrcweir             for ( int i = 0; i < object.length; i++ ) {
388cdf0e10cSrcweir                 Property aProperty = (Property) object[i];
389cdf0e10cSrcweir                 XUnoPropertyNode oUnoPropertyNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aProperty);
390cdf0e10cSrcweir                 oUnoPropertyNode.setLabel(XUnoFacetteNode.SPROPERTYINFODESCRIPTION + " (" + aProperty.Name + ")");
391cdf0e10cSrcweir                 oUnoPropertyNode.setFoldable(true);
392cdf0e10cSrcweir                 _oUnoFacetteNode.addChildNode(oUnoPropertyNode);
393cdf0e10cSrcweir             }
394cdf0e10cSrcweir         }
395cdf0e10cSrcweir     }
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     private void addPrimitiveValuesToTreeNode(XUnoNode _oUnoNode, Object _oUnoObject){
398cdf0e10cSrcweir         if (_oUnoObject.getClass().isArray()){
399cdf0e10cSrcweir             if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
400cdf0e10cSrcweir                 Object[] object = ( Object[] ) _oUnoObject;
401cdf0e10cSrcweir                 for ( int i = 0; i < object.length; i++ ) {
402cdf0e10cSrcweir                     if (m_oIntrospector.isObjectPrimitive(object[i])){
403cdf0e10cSrcweir                         XUnoNode oChildNode = addUnoNode(_oUnoNode, null, UnoNode.getNodeDescription(object[i]));
404cdf0e10cSrcweir                     }
405cdf0e10cSrcweir                 }
406cdf0e10cSrcweir             }
407cdf0e10cSrcweir             else{
408cdf0e10cSrcweir                 String[] sDisplayValues = UnoNode.getDisplayValuesofPrimitiveArray(_oUnoObject);
409cdf0e10cSrcweir                 for ( int i = 0; i < sDisplayValues.length; i++ ) {
410cdf0e10cSrcweir                     XUnoNode oUnoNode = addUnoNode(_oUnoNode, null, sDisplayValues[i]);
411cdf0e10cSrcweir                 }
412cdf0e10cSrcweir             }
413cdf0e10cSrcweir         }
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     private void addPropertySetInfoSubNodes(XUnoPropertyNode _oUnoPropertyNode){
418cdf0e10cSrcweir         Property aProperty = _oUnoPropertyNode.getProperty();
419cdf0e10cSrcweir         _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithName(aProperty));
420cdf0e10cSrcweir         _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithType(aProperty));
421cdf0e10cSrcweir         _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithHandle(aProperty));
422cdf0e10cSrcweir         _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithAttributesDescription(aProperty));
423cdf0e10cSrcweir     }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     private void addPropertyValueSubNodes(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){
427cdf0e10cSrcweir         if (m_oIntrospector.isUnoPropertyValueTypeObject(_oUnoObject)){
428cdf0e10cSrcweir             Object[] object = ( Object[] ) _oUnoObject;
429cdf0e10cSrcweir             for ( int i = 0; i < object.length; i++ ) {
430cdf0e10cSrcweir                 String sObjectClassName = object[i].getClass().getName();
431cdf0e10cSrcweir                 if (sObjectClassName.equals("com.sun.star.beans.PropertyValue")){
432cdf0e10cSrcweir                     XUnoNode oChildNode = null;
433cdf0e10cSrcweir                     PropertyValue aPropertyValue = (PropertyValue) object[i];
434cdf0e10cSrcweir                     if (! m_oIntrospector.isObjectPrimitive(aPropertyValue.Value)){
435cdf0e10cSrcweir                         oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aPropertyValue, _oUnoObject);
436cdf0e10cSrcweir                     }
437cdf0e10cSrcweir                     else{
438cdf0e10cSrcweir                         oChildNode = addUnoNode(null, aPropertyValue.Value, UnoPropertyNode.getStandardPropertyValueDescription(aPropertyValue));
439cdf0e10cSrcweir                     }
440cdf0e10cSrcweir                     if (oChildNode != null){
441cdf0e10cSrcweir                         _oUnoFacetteNode.addChildNode(oChildNode);
442cdf0e10cSrcweir                     }
443cdf0e10cSrcweir                 }
444cdf0e10cSrcweir             }
445cdf0e10cSrcweir         }
446cdf0e10cSrcweir     }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     public boolean expandNode(XUnoNode _oUnoNode, XTreePathProvider _xTreePathProvider){
450cdf0e10cSrcweir         if ( _oUnoNode != null ) {
451cdf0e10cSrcweir             _oUnoNode.setFoldable(false);
452cdf0e10cSrcweir             if (m_xTreeControlProvider.isMethodNode(_oUnoNode)){
453cdf0e10cSrcweir                 XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) _oUnoNode;
454cdf0e10cSrcweir                 if (!oUnoMethodNode.isInvoked()){
455cdf0e10cSrcweir                     Object oUnoReturnObject = invoke((XUnoMethodNode) _oUnoNode);
456cdf0e10cSrcweir                     if (oUnoReturnObject == null){
457cdf0e10cSrcweir                         _oUnoNode.setFoldable(true);
458cdf0e10cSrcweir                         return false;
459cdf0e10cSrcweir                     }
460cdf0e10cSrcweir                 }
461cdf0e10cSrcweir             }
462cdf0e10cSrcweir             else if (m_xTreeControlProvider.isPropertyNode(_oUnoNode)){
463cdf0e10cSrcweir                 XUnoPropertyNode oUnoPropertyNode = (XUnoPropertyNode) _oUnoNode;
464cdf0e10cSrcweir                 Object oUnoObject = oUnoPropertyNode.getUnoReturnObject();
465cdf0e10cSrcweir                 if (oUnoPropertyNode.getPropertyNodeType() == XUnoPropertyNode.nPROPERTYSETINFOTYPE){
466cdf0e10cSrcweir                     addPropertySetInfoSubNodes(oUnoPropertyNode);
467cdf0e10cSrcweir                 }
468cdf0e10cSrcweir                 else{
469cdf0e10cSrcweir                     //TOOD this code is redundant!!!
470cdf0e10cSrcweir                     if ( oUnoObject.getClass().isArray()){
471cdf0e10cSrcweir                         // TOODO probably we should provid a possibility to insert also non-primitive nodes
472cdf0e10cSrcweir                         addPrimitiveValuesToTreeNode(oUnoPropertyNode, oUnoObject);
473cdf0e10cSrcweir                     }
474cdf0e10cSrcweir                     else{
475cdf0e10cSrcweir                         addFacetteNodesToTreeNode(oUnoPropertyNode, oUnoObject);
476cdf0e10cSrcweir                     }
477cdf0e10cSrcweir                 }
478cdf0e10cSrcweir             }
479cdf0e10cSrcweir             else if (m_xTreeControlProvider.isFacetteNode(_oUnoNode)){
480cdf0e10cSrcweir                 XUnoFacetteNode oUnoFacetteNode = (XUnoFacetteNode) _oUnoNode;
481cdf0e10cSrcweir                 Object oUnoObject = _oUnoNode.getUnoObject();
482cdf0e10cSrcweir                 if (oUnoFacetteNode.isMethodNode()){
483cdf0e10cSrcweir                     addMethodsToTreeNode(oUnoFacetteNode, oUnoObject, m_oIntrospector.getMethods(oUnoObject));
484cdf0e10cSrcweir                 }
485cdf0e10cSrcweir                 if (oUnoFacetteNode.isPropertyNode()){
486cdf0e10cSrcweir                     String sNodeDescription = oUnoFacetteNode.getLabel();
487cdf0e10cSrcweir                     // TODO: it's very dangerous to distinguishe the different UnoFacetteNodes only by the nodedescription
488cdf0e10cSrcweir                     if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
489cdf0e10cSrcweir                         addPropertySetInfoNodesToTreeNode(oUnoFacetteNode, oUnoObject);
490cdf0e10cSrcweir                     }
491cdf0e10cSrcweir                     else if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
492cdf0e10cSrcweir                         addPropertyValueSubNodes(oUnoFacetteNode, oUnoObject);
493cdf0e10cSrcweir                     }
494cdf0e10cSrcweir                     else{
495cdf0e10cSrcweir                         addPropertiesToTreeNode(oUnoFacetteNode, oUnoObject, m_oIntrospector.getProperties(oUnoObject));
496cdf0e10cSrcweir                     }
497cdf0e10cSrcweir                 }
498cdf0e10cSrcweir                 if (oUnoFacetteNode.isServiceNode()){
499cdf0e10cSrcweir                     addServicesToTreeNode(oUnoFacetteNode, oUnoObject);
500cdf0e10cSrcweir                 }
501cdf0e10cSrcweir                 if (oUnoFacetteNode.isInterfaceNode()){
502cdf0e10cSrcweir                     addInterfacesToTreeNode(oUnoFacetteNode, oUnoObject, getTypes(oUnoObject));
503cdf0e10cSrcweir                 }
504cdf0e10cSrcweir                 if (oUnoFacetteNode.isContainerNode()){
505cdf0e10cSrcweir                     addContainerElementsToTreeNode(oUnoFacetteNode, oUnoObject);
506cdf0e10cSrcweir                 }
507cdf0e10cSrcweir             }
508cdf0e10cSrcweir             else if (_oUnoNode.getNodeType() == XUnoNode.nSERVICE){
509cdf0e10cSrcweir                 addPropertiesAndInterfacesOfService(_oUnoNode);
510cdf0e10cSrcweir             }
511cdf0e10cSrcweir             else if (_oUnoNode.getNodeType() == XUnoNode.nINTERFACE){
512cdf0e10cSrcweir                 Type aType = _oUnoNode.getUnoType();
513cdf0e10cSrcweir                 if (aType != null){
514cdf0e10cSrcweir                     addMethodsToTreeNode(_oUnoNode, _oUnoNode.getUnoObject(), m_oIntrospector.getMethodsOfInterface(aType));
515cdf0e10cSrcweir                 }
516cdf0e10cSrcweir             }
517cdf0e10cSrcweir             else if (_oUnoNode.getNodeType() == XUnoNode.nOTHERS){
518cdf0e10cSrcweir                 Object oUnoObject = _oUnoNode.getUnoObject();
519cdf0e10cSrcweir                 if ( oUnoObject.getClass().isArray()){
520cdf0e10cSrcweir                     // TOODO probably we should provid a possibility to insert also non-primitive nodes
521cdf0e10cSrcweir                      addPrimitiveValuesToTreeNode(_oUnoNode, oUnoObject);
522cdf0e10cSrcweir                 }
523cdf0e10cSrcweir                 else{
524cdf0e10cSrcweir                     addFacetteNodesToTreeNode(_oUnoNode, oUnoObject);
525cdf0e10cSrcweir                 }
526cdf0e10cSrcweir             }
527cdf0e10cSrcweir         }
528cdf0e10cSrcweir         return true;
529cdf0e10cSrcweir     }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 
533cdf0e10cSrcweir         public void applyFilter(XUnoFacetteNode _oUnoFacetteNode, String _sFilter){
534cdf0e10cSrcweir             for (int i = 0; i < _oUnoFacetteNode.getChildCount(); i++){
535cdf0e10cSrcweir                 XUnoNode oUnoNode = _oUnoFacetteNode.getChild(i);
536cdf0e10cSrcweir                 boolean bIsVisible = oUnoNode.isFilterApplicable(_sFilter);
537cdf0e10cSrcweir                 m_xTreeControlProvider.setNodeVisible(oUnoNode, bIsVisible);
538cdf0e10cSrcweir             }
539cdf0e10cSrcweir             _oUnoFacetteNode.setFilter(_sFilter);
540cdf0e10cSrcweir         }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 
543cdf0e10cSrcweir         /** In opposition to 'getUnoObjectOfTreeNode' this method inspects the passed node if it represents a Uno object
544cdf0e10cSrcweir          *  If not it returns null
545cdf0e10cSrcweir          *
546cdf0e10cSrcweir          */
547cdf0e10cSrcweir         private Object getUnoObjectOfExplicitTreeNode(XTreePathProvider _xTreePathProvider){
548cdf0e10cSrcweir             XUnoNode oUnoNode = _xTreePathProvider.getLastPathComponent();
549cdf0e10cSrcweir             if (oUnoNode != null){
550cdf0e10cSrcweir                 return oUnoNode.getUnoObject();
551cdf0e10cSrcweir             }
552cdf0e10cSrcweir             return null;
553cdf0e10cSrcweir         }
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 
556cdf0e10cSrcweir         public String getFilter(XUnoNode _oUnoNode){
557cdf0e10cSrcweir             String sFilter = "";
558cdf0e10cSrcweir             if (_oUnoNode != null){
559cdf0e10cSrcweir                 XUnoNode oUnoNode = _oUnoNode;
560cdf0e10cSrcweir                 boolean bleaveLoop = false;
561cdf0e10cSrcweir                 do{
562cdf0e10cSrcweir                     if (m_xTreeControlProvider.isFacetteNode(oUnoNode)){
563cdf0e10cSrcweir                         sFilter = ((XUnoFacetteNode) oUnoNode).getFilter();
564cdf0e10cSrcweir                         bleaveLoop = true;
565cdf0e10cSrcweir                     }
566cdf0e10cSrcweir                     else{
567cdf0e10cSrcweir                         if (oUnoNode.getParentNode() != null){
568cdf0e10cSrcweir                             oUnoNode = oUnoNode.getParentNode();
569cdf0e10cSrcweir                         }
570cdf0e10cSrcweir                         else{
571cdf0e10cSrcweir                             bleaveLoop = true;
572cdf0e10cSrcweir                         }
573cdf0e10cSrcweir                     }
574cdf0e10cSrcweir                 } while(!bleaveLoop);
575cdf0e10cSrcweir             }
576cdf0e10cSrcweir             return sFilter;
577cdf0e10cSrcweir         }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 
580cdf0e10cSrcweir         /** In opposition to 'getUnoObjectOfexplictTreeNode' this method inspects the passed node if it represents a Uno object
581cdf0e10cSrcweir          *  if not it keeps checking all ancestors until it finds a Uno representation
582cdf0e10cSrcweir          */
583cdf0e10cSrcweir         private Object getUnoObjectOfTreeNode(XTreePathProvider _xTreePathProvider){
584cdf0e10cSrcweir             XTreePathProvider xTreePathProvider = _xTreePathProvider;
585cdf0e10cSrcweir             HideableMutableTreeNode oNode = null;
586cdf0e10cSrcweir             Object oUnoObject = null;
587cdf0e10cSrcweir             while (xTreePathProvider != null){
588cdf0e10cSrcweir                 oUnoObject = getUnoObjectOfExplicitTreeNode(xTreePathProvider);
589cdf0e10cSrcweir                 if (oUnoObject != null){
590cdf0e10cSrcweir                     if (oUnoObject instanceof String){
591cdf0e10cSrcweir                     }
592cdf0e10cSrcweir                     else{
593cdf0e10cSrcweir                         if (!m_oIntrospector.isUnoTypeObject(oUnoObject)){
594cdf0e10cSrcweir                             return oUnoObject;
595cdf0e10cSrcweir                         }
596cdf0e10cSrcweir                     }
597cdf0e10cSrcweir                 }
598cdf0e10cSrcweir                 xTreePathProvider = xTreePathProvider.getParentPath();
599cdf0e10cSrcweir             }
600cdf0e10cSrcweir             return null;
601cdf0e10cSrcweir         }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir 
604cdf0e10cSrcweir         public void showPopUpMenu(Object _invoker, int x, int y) throws ClassCastException{
605cdf0e10cSrcweir             XUnoNode oUnoNode = getSelectedNode();
606cdf0e10cSrcweir             boolean bdoEnableInvoke = oUnoNode instanceof XUnoMethodNode;
607cdf0e10cSrcweir //            boolean bdoEnableSourceCodeGeneration = true;
608cdf0e10cSrcweir             if (bdoEnableInvoke){
609cdf0e10cSrcweir                 XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
610cdf0e10cSrcweir                 bdoEnableInvoke = oUnoMethodNode.isInvokable();
611cdf0e10cSrcweir //                bdoEnableSourceCodeGeneration = bdoEnableInvoke;
612cdf0e10cSrcweir             }
613cdf0e10cSrcweir             m_xDialogProvider.enablePopupMenuItem(XDialogProvider.SINVOKE, bdoEnableInvoke);
614cdf0e10cSrcweir //            m_xDialogProvider.enablePopupMenuItem(XDialogProvider.SADDTOSOURCECODE, bdoEnableSourceCodeGeneration);
615cdf0e10cSrcweir             m_xDialogProvider.showPopUpMenu(_invoker, x, y);
616cdf0e10cSrcweir         }
617cdf0e10cSrcweir }
618cdf0e10cSrcweir