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 package integration.extensions; 25 26 import com.sun.star.uno.XComponentContext; 27 import com.sun.star.uno.UnoRuntime; 28 import com.sun.star.lang.XMultiServiceFactory; 29 30 import com.sun.star.frame.*; 31 import com.sun.star.inspection.*; 32 import com.sun.star.beans.*; 33 34 import integration.extensions.Frame; 35 36 public class ObjectInspector extends complexlib.ComplexTestCase 37 { 38 private XComponentContext m_context; 39 private XMultiServiceFactory m_orb; 40 private Frame m_desktop; 41 42 final private String m_inspectorFrameName = new String( "ObjectInspector" ); 43 44 /** Creates a new instance of ValueBinding */ ObjectInspector()45 public ObjectInspector() 46 { 47 } 48 49 /* ------------------------------------------------------------------ */ getTestMethodNames()50 public String[] getTestMethodNames() 51 { 52 return new String[] { 53 "interactiveObjectInspector" 54 }; 55 } 56 57 /* ------------------------------------------------------------------ */ getTestObjectName()58 public String getTestObjectName() 59 { 60 return "Test Skeleton"; 61 } 62 63 /* ------------------------------------------------------------------ */ before()64 public void before() throws com.sun.star.uno.Exception, java.lang.Exception 65 { 66 m_orb = (XMultiServiceFactory)param.getMSF(); 67 m_context = (XComponentContext)UnoRuntime.queryInterface( XComponentContext.class, 68 ((XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, m_orb )).getPropertyValue( "DefaultContext" ) ); 69 m_desktop = new Frame( m_orb.createInstance( "com.sun.star.frame.Desktop" ) ); 70 } 71 72 /* ------------------------------------------------------------------ */ after()73 public void after() throws com.sun.star.uno.Exception, java.lang.Exception 74 { 75 closeExistentInspector(); 76 } 77 78 /* ------------------------------------------------------------------ */ interactiveObjectInspector()79 public void interactiveObjectInspector() throws com.sun.star.uno.Exception, java.lang.Exception 80 { 81 closeExistentInspector(); 82 83 // the to-be-inspected object 84 XFrame inspectee = m_desktop.getActiveFrame(); 85 86 // the inspector 87 XObjectInspector inspector = createObjectInspector(); 88 89 // do inspect 90 inspector.inspect( new Object[] { inspectee } ); 91 92 ConsoleWait keyWaiter = new ConsoleWait( inspector ); 93 keyWaiter.waitForUserInput(); 94 } 95 96 /* ------------------------------------------------------------------ */ createObjectInspector()97 private XObjectInspector createObjectInspector() throws com.sun.star.uno.Exception 98 { 99 com.sun.star.awt.XWindow floatingWindow = createFloatingWindow(); 100 101 Frame inspectorFrame = new Frame( m_orb.createInstance( "com.sun.star.frame.Frame" ) ); 102 inspectorFrame.setName( m_inspectorFrameName ); 103 inspectorFrame.initialize( floatingWindow ); 104 m_desktop.getFrames().append( inspectorFrame.getXFrame() ); 105 106 // handler factories: 107 Object[] handlerFactories = new Object[] { 108 "com.sun.star.inspection.GenericPropertyHandler", 109 new ComponentFactory( ServicesHandler.class ), 110 new ComponentFactory( MethodHandler.class ) 111 }; 112 // a model 113 XObjectInspectorModel model = ObjectInspectorModel.createWithHandlerFactoriesAndHelpSection( 114 m_context, handlerFactories, 4, 4 ); 115 116 // create the ObjectInspector 117 XObjectInspector inspector = com.sun.star.inspection.ObjectInspector.createWithModel( 118 m_context, model ); 119 120 // add an observer which will emit help texts 121 new HelpTextProvider( inspector.getInspectorUI() ); 122 123 // plug it into the frame 124 inspector.attachFrame( inspectorFrame.getXFrame() ); 125 126 // make the window visible 127 floatingWindow.setVisible( true ); 128 129 // outta here 130 return inspector; 131 } 132 133 /* ------------------------------------------------------------------ */ closeExistentInspector()134 private void closeExistentInspector() 135 { 136 Frame existentInspectorFrame = new Frame( m_desktop.findFrame( m_inspectorFrameName, 255 ) ); 137 if ( existentInspectorFrame != null ) 138 { 139 try 140 { 141 existentInspectorFrame.close( true ); 142 } 143 catch( com.sun.star.util.CloseVetoException e ) 144 { 145 failed( "could not close the existent inspector frame" ); 146 } 147 } 148 } 149 150 /* ------------------------------------------------------------------ */ createFloatingWindow()151 private com.sun.star.awt.XWindow createFloatingWindow() throws com.sun.star.uno.Exception 152 { 153 com.sun.star.awt.XToolkit toolkit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface( 154 com.sun.star.awt.XToolkit.class, m_orb.createInstance( "com.sun.star.awt.Toolkit" ) ); 155 156 com.sun.star.awt.WindowDescriptor windowDescriptor = new com.sun.star.awt.WindowDescriptor(); 157 windowDescriptor.Type = com.sun.star.awt.WindowClass.TOP; 158 windowDescriptor.WindowServiceName = "modelessdialog"; // "floatingwindow" would need a parent 159 windowDescriptor.ParentIndex = -1; 160 //windowDescriptor.Parent = null; 161 162 windowDescriptor.Bounds = new com.sun.star.awt.Rectangle( 500, 100, 400, 600 ); 163 windowDescriptor.WindowAttributes = com.sun.star.awt.WindowAttribute.BORDER 164 + com.sun.star.awt.WindowAttribute.MOVEABLE 165 + com.sun.star.awt.WindowAttribute.SIZEABLE 166 + com.sun.star.awt.WindowAttribute.CLOSEABLE 167 + com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN; 168 169 return (com.sun.star.awt.XWindow)UnoRuntime.queryInterface( com.sun.star.awt.XWindow.class, 170 toolkit.createWindow( windowDescriptor ) ); 171 } 172 } 173