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