xref: /AOO41X/main/odk/examples/java/Inspector/Inspector.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  *  The Contents of this file are made available subject to the terms of
4*cdf0e10cSrcweir  *  the BSD license.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *  All rights reserved.
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  *  Redistribution and use in source and binary forms, with or without
10*cdf0e10cSrcweir  *  modification, are permitted provided that the following conditions
11*cdf0e10cSrcweir  *  are met:
12*cdf0e10cSrcweir  *  1. Redistributions of source code must retain the above copyright
13*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer.
14*cdf0e10cSrcweir  *  2. Redistributions in binary form must reproduce the above copyright
15*cdf0e10cSrcweir  *     notice, this list of conditions and the following disclaimer in the
16*cdf0e10cSrcweir  *     documentation and/or other materials provided with the distribution.
17*cdf0e10cSrcweir  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18*cdf0e10cSrcweir  *     contributors may be used to endorse or promote products derived
19*cdf0e10cSrcweir  *     from this software without specific prior written permission.
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*cdf0e10cSrcweir  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*cdf0e10cSrcweir  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*cdf0e10cSrcweir  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25*cdf0e10cSrcweir  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*cdf0e10cSrcweir  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*cdf0e10cSrcweir  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28*cdf0e10cSrcweir  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29*cdf0e10cSrcweir  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30*cdf0e10cSrcweir  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31*cdf0e10cSrcweir  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32*cdf0e10cSrcweir  *
33*cdf0e10cSrcweir  *************************************************************************/
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir import com.sun.star.awt.Rectangle;
36*cdf0e10cSrcweir import com.sun.star.awt.XMessageBox;
37*cdf0e10cSrcweir import com.sun.star.awt.XMessageBoxFactory;
38*cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
39*cdf0e10cSrcweir import com.sun.star.beans.NamedValue;
40*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
41*cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
42*cdf0e10cSrcweir import com.sun.star.frame.XModel;
43*cdf0e10cSrcweir import com.sun.star.lang.XComponent;
44*cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
45*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
46*cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo;
47*cdf0e10cSrcweir import com.sun.star.lang.XSingleComponentFactory;
48*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.Factory;
49*cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
50*cdf0e10cSrcweir import com.sun.star.registry.XRegistryKey;
51*cdf0e10cSrcweir import com.sun.star.ui.dialogs.XExecutableDialog;
52*cdf0e10cSrcweir import com.sun.star.ui.dialogs.XFolderPicker;
53*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
54*cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
55*cdf0e10cSrcweir import com.sun.star.util.CloseVetoException;
56*cdf0e10cSrcweir import com.sun.star.util.XChangesBatch;
57*cdf0e10cSrcweir import com.sun.star.util.XCloseable;
58*cdf0e10cSrcweir import java.util.HashMap;
59*cdf0e10cSrcweir import java.util.Iterator;
60*cdf0e10cSrcweir import java.util.Set;
61*cdf0e10cSrcweir import java.util.Vector;
62*cdf0e10cSrcweir import org.openoffice.XInstanceInspector;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir /** The purpose of this class is to provide a factory for creating the service
66*cdf0e10cSrcweir  * (<CODE>__getServiceFactory</CODE>) and writes the information into the given
67*cdf0e10cSrcweir  * registry key (<CODE>__writeRegistryServiceInfo</CODE>).
68*cdf0e10cSrcweir  */
69*cdf0e10cSrcweir public class Inspector{
70*cdf0e10cSrcweir      public static final String sIDLDOCUMENTSUBFOLDER = "docs/common/ref/";
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir     /** This class implements the method of the interface XInstanceInspector.
74*cdf0e10cSrcweir      * Also the class implements the interfaces XServiceInfo, and XTypeProvider.
75*cdf0e10cSrcweir      */
76*cdf0e10cSrcweir     static public class _Inspector extends WeakBase implements XInstanceInspector, XServiceInfo{
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir         static private final String __serviceName = "org.openoffice.InstanceInspector";
79*cdf0e10cSrcweir         private HashMap aApplicationHashMap = new HashMap();
80*cdf0e10cSrcweir         private String sTitle = "Object Inspector";
81*cdf0e10cSrcweir         private Vector aHiddenDocuments = new Vector();
82*cdf0e10cSrcweir //        private String[] sApplicationDocUrls = new String[]{"private:factory/swriter", "private:factory/scalc", "private:factory/simpress", "private:factory/sdraw", "private:factory/sbase"};
83*cdf0e10cSrcweir //        private String[] sApplicationDocNames = new String[]{"Text Document", "Spreadsheet", "Presentation", "Drawing", "Database"};
84*cdf0e10cSrcweir         private XComponentContext m_xComponentContext;
85*cdf0e10cSrcweir         private HashMap aInspectorPanes = new HashMap();
86*cdf0e10cSrcweir         private XDialogProvider m_oSwingDialogProvider;
87*cdf0e10cSrcweir         private TDocSupplier oTDocSupplier;
88*cdf0e10cSrcweir         private Introspector m_oIntrospector = null;
89*cdf0e10cSrcweir         // TODO: improve these strings:
90*cdf0e10cSrcweir         private static final String sWRONGINSTALLATIONPATH = "Your selected path does not refer to an SDK-Installation!";
91*cdf0e10cSrcweir         /** Creates a new instance of Dialog */
92*cdf0e10cSrcweir         public _Inspector(XComponentContext _xComponentContext) {
93*cdf0e10cSrcweir             m_xComponentContext = _xComponentContext;
94*cdf0e10cSrcweir             m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
95*cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/swriter", "Text Document");
96*cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/scalc", "Spreadsheet");
97*cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/simpress", "Presentation");
98*cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/sdraw", "Drawing");
99*cdf0e10cSrcweir             aApplicationHashMap.put("private:factory/smath", "Formula");
100*cdf0e10cSrcweir             m_oSwingDialogProvider = new SwingDialogProvider(this, sTitle);
101*cdf0e10cSrcweir //            aApplicationHashMap.put("private:factory/sbase", "Database");
102*cdf0e10cSrcweir         }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         public XComponentContext getXComponentContext(){
106*cdf0e10cSrcweir             return m_xComponentContext;
107*cdf0e10cSrcweir         }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         public HashMap getInspectorPages(){
111*cdf0e10cSrcweir             return aInspectorPanes;
112*cdf0e10cSrcweir         }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir         protected String getSDKPath(){
116*cdf0e10cSrcweir         String sRetPath = "";
117*cdf0e10cSrcweir         try{
118*cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
119*cdf0e10cSrcweir             XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
120*cdf0e10cSrcweir             sRetPath = (String) xPropertySet.getPropertyValue("SDKPath");
121*cdf0e10cSrcweir         }catch( Exception exception ) {
122*cdf0e10cSrcweir             exception.printStackTrace(System.out);
123*cdf0e10cSrcweir         }
124*cdf0e10cSrcweir         return sRetPath;
125*cdf0e10cSrcweir         }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         public String getIDLPath(){
129*cdf0e10cSrcweir             String sRetPath = getSDKPath();
130*cdf0e10cSrcweir             if (m_oIntrospector.isValidSDKInstallationPath(sRetPath)){
131*cdf0e10cSrcweir                 sRetPath = m_oIntrospector.addToPath(sRetPath, sIDLDOCUMENTSUBFOLDER);
132*cdf0e10cSrcweir             }
133*cdf0e10cSrcweir             else{
134*cdf0e10cSrcweir                 sRetPath = "";
135*cdf0e10cSrcweir             }
136*cdf0e10cSrcweir             return sRetPath;
137*cdf0e10cSrcweir         }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         public void openIdlFileforSelectedNode(){
141*cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
142*cdf0e10cSrcweir             if (oInspectorPane != null){
143*cdf0e10cSrcweir                 XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
144*cdf0e10cSrcweir                 if (oUnoNode != null){
145*cdf0e10cSrcweir                     String sPath = getIDLPath();
146*cdf0e10cSrcweir                     oUnoNode.openIdlDescription(sPath);
147*cdf0e10cSrcweir                 }
148*cdf0e10cSrcweir             }
149*cdf0e10cSrcweir         }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         public void assignSDKPath() {
153*cdf0e10cSrcweir         try {
154*cdf0e10cSrcweir             String sInstallationFolder = "";
155*cdf0e10cSrcweir             Object oFolderPicker = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FolderPicker", m_xComponentContext);
156*cdf0e10cSrcweir             XFolderPicker xFolderPicker = (XFolderPicker) UnoRuntime.queryInterface(XFolderPicker.class, oFolderPicker);
157*cdf0e10cSrcweir             XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker);
158*cdf0e10cSrcweir             XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, oFolderPicker);
159*cdf0e10cSrcweir             String sPath = getSDKPath();
160*cdf0e10cSrcweir             if (!sPath.equals("")){
161*cdf0e10cSrcweir                 xFolderPicker.setDisplayDirectory(sPath);
162*cdf0e10cSrcweir             }
163*cdf0e10cSrcweir             xFolderPicker.setTitle("Add the Path to your SDK installation");
164*cdf0e10cSrcweir             short nResult = xExecutable.execute();
165*cdf0e10cSrcweir             if (nResult == com.sun.star.ui.dialogs.ExecutableDialogResults.OK){
166*cdf0e10cSrcweir                 sInstallationFolder = xFolderPicker.getDirectory();
167*cdf0e10cSrcweir                 if (m_oIntrospector.isValidSDKInstallationPath(sInstallationFolder)){
168*cdf0e10cSrcweir                     XNameAccess xNameAccess = getConfigurationAccess(true);
169*cdf0e10cSrcweir                     XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
170*cdf0e10cSrcweir                     xPropertySet.setPropertyValue("SDKPath", sInstallationFolder);
171*cdf0e10cSrcweir                     XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
172*cdf0e10cSrcweir                     xBatch.commitChanges();
173*cdf0e10cSrcweir                 }
174*cdf0e10cSrcweir                 else{
175*cdf0e10cSrcweir                     XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFolderPicker);
176*cdf0e10cSrcweir                     Object oWindow = xPropertySet.getPropertyValue("Window");
177*cdf0e10cSrcweir                     XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, oWindow);
178*cdf0e10cSrcweir                     showErrorMessageBox(xWindowPeer, sTitle, sWRONGINSTALLATIONPATH);
179*cdf0e10cSrcweir                     assignSDKPath();
180*cdf0e10cSrcweir                 }
181*cdf0e10cSrcweir             }
182*cdf0e10cSrcweir             xComponent.dispose();
183*cdf0e10cSrcweir         }catch( Exception exception ) {
184*cdf0e10cSrcweir             exception.printStackTrace(System.out);
185*cdf0e10cSrcweir         }}
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir         public void showErrorMessageBox(XWindowPeer _xWindowPeer, String _sTitle, String _sMessage){
189*cdf0e10cSrcweir         try {
190*cdf0e10cSrcweir             Object oToolkit = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xComponentContext);
191*cdf0e10cSrcweir             XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit);
192*cdf0e10cSrcweir             Rectangle aRectangle = new Rectangle();
193*cdf0e10cSrcweir             XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xWindowPeer, aRectangle, "errorbox", com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage);
194*cdf0e10cSrcweir             XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox);
195*cdf0e10cSrcweir             if (xMessageBox != null){
196*cdf0e10cSrcweir                 short nResult = xMessageBox.execute();
197*cdf0e10cSrcweir                 xComponent.dispose();
198*cdf0e10cSrcweir             }
199*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception ex) {
200*cdf0e10cSrcweir             ex.printStackTrace(System.out);
201*cdf0e10cSrcweir         }}
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir         public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
205*cdf0e10cSrcweir         try {
206*cdf0e10cSrcweir             int nPageIndex = m_oSwingDialogProvider.getInspectorPageCount();
207*cdf0e10cSrcweir             SwingTreeControlProvider oSwingTreeControlProvider = new SwingTreeControlProvider(m_oSwingDialogProvider);
208*cdf0e10cSrcweir             InspectorPane oInspectorPane = new InspectorPane(getXComponentContext(), m_oSwingDialogProvider, oSwingTreeControlProvider, getSourceCodeLanguage());
209*cdf0e10cSrcweir             oInspectorPane.inspect(_oUserDefinedObject, _sTitle);
210*cdf0e10cSrcweir             getInspectorPages().put(_sTitle, oInspectorPane);
211*cdf0e10cSrcweir             m_oSwingDialogProvider.show(nPageIndex);
212*cdf0e10cSrcweir         }catch( Exception exception ) {
213*cdf0e10cSrcweir             exception.printStackTrace(System.out);
214*cdf0e10cSrcweir         }}
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir         public void inspectOpenEmptyDocument(String _sApplicationDocUrl){
218*cdf0e10cSrcweir             XComponent xComponent = getTDocSupplier().openEmptyDocument(_sApplicationDocUrl);
219*cdf0e10cSrcweir             String sRootTitle = (String) aApplicationHashMap.get(_sApplicationDocUrl);
220*cdf0e10cSrcweir             inspect(xComponent, sRootTitle);
221*cdf0e10cSrcweir             aHiddenDocuments.add(xComponent);
222*cdf0e10cSrcweir         }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         public void inspectOpenDocument(String _sTDocUrl){
226*cdf0e10cSrcweir             String sTreeNodeName = getTDocSupplier().getTitleByTDocUrl(_sTDocUrl);
227*cdf0e10cSrcweir             XModel xTDocModel = getTDocSupplier().getXModelByTDocUrl(_sTDocUrl);
228*cdf0e10cSrcweir             inspect(xTDocModel, sTreeNodeName);
229*cdf0e10cSrcweir         }
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir         public void inspectSelectedNode(){
233*cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
234*cdf0e10cSrcweir             if (oInspectorPane != null){
235*cdf0e10cSrcweir                 XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
236*cdf0e10cSrcweir                 Object oUnoObject = oUnoNode.getUnoObject();
237*cdf0e10cSrcweir                 if (oUnoObject != null){
238*cdf0e10cSrcweir                     String sNodeDescription = UnoNode.getNodeDescription(oUnoObject);
239*cdf0e10cSrcweir                     inspect(oUnoObject, sNodeDescription);
240*cdf0e10cSrcweir                 }
241*cdf0e10cSrcweir             }
242*cdf0e10cSrcweir         }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir         public void addSourceCodeOfSelectedNode(){
246*cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
247*cdf0e10cSrcweir             if (oInspectorPane != null){
248*cdf0e10cSrcweir                 oInspectorPane.addSourceCodeOfSelectedNode();
249*cdf0e10cSrcweir             }
250*cdf0e10cSrcweir         }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir         public void invokeSelectedMethod(){
254*cdf0e10cSrcweir             InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
255*cdf0e10cSrcweir             if (oInspectorPane != null){
256*cdf0e10cSrcweir                 oInspectorPane.invokeSelectedMethodNode();
257*cdf0e10cSrcweir             }
258*cdf0e10cSrcweir         }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir         public void setSourceCodeLanguage(final int _nLanguage){
262*cdf0e10cSrcweir         try{
263*cdf0e10cSrcweir             String sLanguage = "Java";
264*cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
265*cdf0e10cSrcweir             XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
266*cdf0e10cSrcweir             switch (_nLanguage){
267*cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nJAVA:
268*cdf0e10cSrcweir                     sLanguage = "Java";
269*cdf0e10cSrcweir                     break;
270*cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nCPLUSPLUS:
271*cdf0e10cSrcweir                     sLanguage = "CPlusPlus";
272*cdf0e10cSrcweir                     break;
273*cdf0e10cSrcweir                 case XLanguageSourceCodeGenerator.nBASIC:
274*cdf0e10cSrcweir                     sLanguage = "Basic";
275*cdf0e10cSrcweir                     break;
276*cdf0e10cSrcweir                 default:
277*cdf0e10cSrcweir                     System.out.println("Warning: Sourcecode language is not defined!");
278*cdf0e10cSrcweir             }
279*cdf0e10cSrcweir             xPropertySet.setPropertyValue("Language", sLanguage);
280*cdf0e10cSrcweir             XChangesBatch xBatch = (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
281*cdf0e10cSrcweir             xBatch.commitChanges();
282*cdf0e10cSrcweir             for (int i = 0; i < m_oSwingDialogProvider.getInspectorPageCount(); i++){
283*cdf0e10cSrcweir                 m_oSwingDialogProvider.getInspectorPage(i).convertCompleteSourceCode(_nLanguage);
284*cdf0e10cSrcweir             }
285*cdf0e10cSrcweir         }catch( Exception exception ) {
286*cdf0e10cSrcweir             exception.printStackTrace(System.out);
287*cdf0e10cSrcweir         }}
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir         private TDocSupplier getTDocSupplier(){
291*cdf0e10cSrcweir             if (oTDocSupplier == null){
292*cdf0e10cSrcweir                 oTDocSupplier = new TDocSupplier(m_xComponentContext);
293*cdf0e10cSrcweir             }
294*cdf0e10cSrcweir             return oTDocSupplier;
295*cdf0e10cSrcweir         }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         public String[] getTDocUrls(){
298*cdf0e10cSrcweir             return getTDocSupplier().getTDocUrls();
299*cdf0e10cSrcweir         }
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir         public String[] getTDocTitles(String[] _sTDocUrls){
303*cdf0e10cSrcweir             return getTDocSupplier().getTDocTitles(_sTDocUrls);
304*cdf0e10cSrcweir         }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir         public String[][] getApplicationUrls(){
308*cdf0e10cSrcweir             Set aSet = aApplicationHashMap.keySet();
309*cdf0e10cSrcweir             String[][] sReturnList = new String[aSet.size()][];
310*cdf0e10cSrcweir             int n= 0;
311*cdf0e10cSrcweir             for ( Iterator i = aSet.iterator(); i.hasNext(); ){
312*cdf0e10cSrcweir                 String[] sSingleApplication = new String[2];
313*cdf0e10cSrcweir                 sSingleApplication[0] = (String) i.next();
314*cdf0e10cSrcweir                 // assign the title in the second index
315*cdf0e10cSrcweir                 sSingleApplication[1] = (String) aApplicationHashMap.get(sSingleApplication[0]);
316*cdf0e10cSrcweir                 sReturnList[n++] = sSingleApplication;
317*cdf0e10cSrcweir             }
318*cdf0e10cSrcweir             return sReturnList;
319*cdf0e10cSrcweir         }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir         public void disposeHiddenDocuments(){
323*cdf0e10cSrcweir             int nHiddenCount = aHiddenDocuments.size();
324*cdf0e10cSrcweir             if (nHiddenCount > 0){
325*cdf0e10cSrcweir                 for (int i = nHiddenCount - 1; i >= 0; i--){
326*cdf0e10cSrcweir                     XComponent xComponent = (XComponent) aHiddenDocuments.get(i);
327*cdf0e10cSrcweir                     if (xComponent != null){
328*cdf0e10cSrcweir                         try {
329*cdf0e10cSrcweir                             XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xComponent);
330*cdf0e10cSrcweir                             xCloseable.close(true);
331*cdf0e10cSrcweir                             aHiddenDocuments.remove(i);
332*cdf0e10cSrcweir                         } catch (CloseVetoException ex) {
333*cdf0e10cSrcweir                             ex.printStackTrace();
334*cdf0e10cSrcweir                         }
335*cdf0e10cSrcweir                     }
336*cdf0e10cSrcweir                 }
337*cdf0e10cSrcweir             }
338*cdf0e10cSrcweir         }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir         public static String[] getServiceNames() {
342*cdf0e10cSrcweir             String[] sSupportedServiceNames = { __serviceName };
343*cdf0e10cSrcweir             return sSupportedServiceNames;
344*cdf0e10cSrcweir         }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir         // Implement the interface XServiceInfo
347*cdf0e10cSrcweir         /** Get all supported service names.
348*cdf0e10cSrcweir          * @return Supported service names.
349*cdf0e10cSrcweir          */
350*cdf0e10cSrcweir         public String[] getSupportedServiceNames() {
351*cdf0e10cSrcweir             return getServiceNames();
352*cdf0e10cSrcweir         }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         // Implement the interface XServiceInfo
355*cdf0e10cSrcweir         /** Test, if the given service will be supported.
356*cdf0e10cSrcweir          * @param sService Service name.
357*cdf0e10cSrcweir          * @return Return true, if the service will be supported.
358*cdf0e10cSrcweir          */
359*cdf0e10cSrcweir         public boolean supportsService( String sServiceName ) {
360*cdf0e10cSrcweir             return sServiceName.equals( __serviceName );
361*cdf0e10cSrcweir         }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir         // Implement the interface XServiceInfo
364*cdf0e10cSrcweir         /** Get the implementation name of the component.
365*cdf0e10cSrcweir          * @return Implementation name of the component.
366*cdf0e10cSrcweir          */
367*cdf0e10cSrcweir         public String getImplementationName() {
368*cdf0e10cSrcweir             return _Inspector.class.getName();
369*cdf0e10cSrcweir         }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir         private int getSourceCodeLanguage(){
373*cdf0e10cSrcweir         int nLanguage = XLanguageSourceCodeGenerator.nJAVA;
374*cdf0e10cSrcweir         try{
375*cdf0e10cSrcweir             XNameAccess xNameAccess  = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", false);
376*cdf0e10cSrcweir             String sLanguage = (String) xNameAccess.getByName("Language");
377*cdf0e10cSrcweir             if (sLanguage.toUpperCase().equals("JAVA")){
378*cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nJAVA;
379*cdf0e10cSrcweir             }
380*cdf0e10cSrcweir             else if (sLanguage.toUpperCase().equals("BASIC")){
381*cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nBASIC;
382*cdf0e10cSrcweir             }
383*cdf0e10cSrcweir             else if (sLanguage.toUpperCase().equals("CPLUSPLUS")){
384*cdf0e10cSrcweir                 nLanguage = XLanguageSourceCodeGenerator.nCPLUSPLUS;
385*cdf0e10cSrcweir             }
386*cdf0e10cSrcweir             else{
387*cdf0e10cSrcweir                 System.out.println("Warning: Sourcecode language " + sLanguage + " is not defined!");
388*cdf0e10cSrcweir             }
389*cdf0e10cSrcweir             m_oSwingDialogProvider.selectSourceCodeLanguage(nLanguage);
390*cdf0e10cSrcweir         }catch( Exception exception ) {
391*cdf0e10cSrcweir             exception.printStackTrace(System.out);
392*cdf0e10cSrcweir         }
393*cdf0e10cSrcweir             return nLanguage;
394*cdf0e10cSrcweir         }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir         public XNameAccess getConfigurationAccess(boolean _bUpdate){
398*cdf0e10cSrcweir             return getConfigurationAccess("org.openoffice.inspector.ObjectInspector", _bUpdate);
399*cdf0e10cSrcweir         }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir         public XNameAccess getConfigurationAccess(String _sNodePath, boolean update) {
403*cdf0e10cSrcweir         XNameAccess xNameAccess = null;
404*cdf0e10cSrcweir         try {
405*cdf0e10cSrcweir             String sAccess = "";
406*cdf0e10cSrcweir             if (update) {
407*cdf0e10cSrcweir                 sAccess = "com.sun.star.configuration.ConfigurationUpdateAccess";
408*cdf0e10cSrcweir             }
409*cdf0e10cSrcweir             else{
410*cdf0e10cSrcweir                 sAccess = "com.sun.star.configuration.ConfigurationAccess";
411*cdf0e10cSrcweir             }
412*cdf0e10cSrcweir             XMultiComponentFactory xMCF = m_xComponentContext.getServiceManager();
413*cdf0e10cSrcweir             Object oDefaultProvider = xMCF.createInstanceWithContext("com.sun.star.configuration.DefaultProvider", this.getXComponentContext());
414*cdf0e10cSrcweir             XMultiServiceFactory xMSFCfg = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDefaultProvider);
415*cdf0e10cSrcweir             Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, new Object[]{new NamedValue("nodepath", _sNodePath)});
416*cdf0e10cSrcweir             xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oAccess);
417*cdf0e10cSrcweir         } catch (com.sun.star.uno.Exception e) {
418*cdf0e10cSrcweir         }
419*cdf0e10cSrcweir         return xNameAccess;
420*cdf0e10cSrcweir         }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir // end of inner class
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir     /**
429*cdf0e10cSrcweir      * Gives a factory for creating the service.
430*cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
431*cdf0e10cSrcweir      * <p>
432*cdf0e10cSrcweir      * @return  returns a <code>XSingleComponentFactory</code> for creating
433*cdf0e10cSrcweir      *          the component
434*cdf0e10cSrcweir      * @param   sImplName the name of the implementation for which a
435*cdf0e10cSrcweir      *          service is desired
436*cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
437*cdf0e10cSrcweir      */
438*cdf0e10cSrcweir     public static XSingleComponentFactory __getComponentFactory( String sImplName )
439*cdf0e10cSrcweir     {
440*cdf0e10cSrcweir         XSingleComponentFactory xFactory = null;
441*cdf0e10cSrcweir         if ( sImplName.equals( _Inspector.class.getName() ) )
442*cdf0e10cSrcweir             xFactory = Factory.createComponentFactory(_Inspector.class, _Inspector.getServiceNames());
443*cdf0e10cSrcweir         if ( xFactory == null )
444*cdf0e10cSrcweir             xFactory = InspectorAddon.__getComponentFactory(sImplName);
445*cdf0e10cSrcweir         return xFactory;
446*cdf0e10cSrcweir     }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir     /**
449*cdf0e10cSrcweir      * Writes the service information into the given registry key.
450*cdf0e10cSrcweir      * This method is called by the <code>JavaLoader</code>
451*cdf0e10cSrcweir      * <p>
452*cdf0e10cSrcweir      * @return  returns true if the operation succeeded
453*cdf0e10cSrcweir      * @param   regKey the registryKey
454*cdf0e10cSrcweir      * @see     com.sun.star.comp.loader.JavaLoader
455*cdf0e10cSrcweir      */
456*cdf0e10cSrcweir     public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
457*cdf0e10cSrcweir         return (Factory.writeRegistryServiceInfo(_Inspector.class.getName(), _Inspector.getServiceNames(), regKey)
458*cdf0e10cSrcweir                 && InspectorAddon.__writeRegistryServiceInfo(regKey));
459*cdf0e10cSrcweir     }
460*cdf0e10cSrcweir }
461*cdf0e10cSrcweir 
462