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