summaryrefslogtreecommitdiffstats
path: root/odk/examples/java/Inspector
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--odk/examples/java/Inspector/Addons.xcu40
-rw-r--r--odk/examples/java/Inspector/HideableMutableTreeNode.java106
-rw-r--r--odk/examples/java/Inspector/HideableTreeModel.java258
-rw-r--r--odk/examples/java/Inspector/Inspector.java459
-rw-r--r--odk/examples/java/Inspector/InspectorAddon.java224
-rw-r--r--odk/examples/java/Inspector/InspectorPane.java577
-rw-r--r--odk/examples/java/Inspector/InstanceInspectorTest.odtbin0 -> 12272 bytes
-rw-r--r--odk/examples/java/Inspector/Introspector.java643
-rw-r--r--odk/examples/java/Inspector/Makefile186
-rw-r--r--odk/examples/java/Inspector/MethodParametersDialog.java351
-rw-r--r--odk/examples/java/Inspector/ObjectInspector.xcs34
-rw-r--r--odk/examples/java/Inspector/ObjectInspector.xcu31
-rw-r--r--odk/examples/java/Inspector/ProtocolHandler.xcu28
-rw-r--r--odk/examples/java/Inspector/ProtocolHandlerAddon.java273
-rw-r--r--odk/examples/java/Inspector/SourceCodeGenerator.java1635
-rw-r--r--odk/examples/java/Inspector/SwingDialogProvider.java444
-rw-r--r--odk/examples/java/Inspector/SwingTreeControlProvider.java423
-rw-r--r--odk/examples/java/Inspector/SwingTreePathProvider.java60
-rw-r--r--odk/examples/java/Inspector/SwingUnoFacetteNode.java84
-rw-r--r--odk/examples/java/Inspector/SwingUnoMethodNode.java144
-rw-r--r--odk/examples/java/Inspector/SwingUnoNode.java160
-rw-r--r--odk/examples/java/Inspector/SwingUnoPropertyNode.java102
-rw-r--r--odk/examples/java/Inspector/TDocSupplier.java166
-rw-r--r--odk/examples/java/Inspector/TestInspector.java88
-rw-r--r--odk/examples/java/Inspector/UnoMethodNode.java228
-rw-r--r--odk/examples/java/Inspector/UnoNode.java351
-rw-r--r--odk/examples/java/Inspector/UnoPropertyNode.java218
-rw-r--r--odk/examples/java/Inspector/UnoTreeRenderer.java122
-rw-r--r--odk/examples/java/Inspector/XDialogProvider.java68
-rw-r--r--odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java108
-rw-r--r--odk/examples/java/Inspector/XTreeControlProvider.java96
-rw-r--r--odk/examples/java/Inspector/XTreePathProvider.java33
-rw-r--r--odk/examples/java/Inspector/XUnoFacetteNode.java66
-rw-r--r--odk/examples/java/Inspector/XUnoMethodNode.java70
-rw-r--r--odk/examples/java/Inspector/XUnoNode.java87
-rw-r--r--odk/examples/java/Inspector/XUnoPropertyNode.java54
-rw-r--r--odk/examples/java/Inspector/description.xml15
-rw-r--r--odk/examples/java/Inspector/images/containers_16.pngbin0 -> 233 bytes
-rw-r--r--odk/examples/java/Inspector/images/content_16.pngbin0 -> 370 bytes
-rw-r--r--odk/examples/java/Inspector/images/interfaces_16.pngbin0 -> 433 bytes
-rw-r--r--odk/examples/java/Inspector/images/methods_16.pngbin0 -> 380 bytes
-rw-r--r--odk/examples/java/Inspector/images/properties_16.pngbin0 -> 242 bytes
-rw-r--r--odk/examples/java/Inspector/images/services_16.pngbin0 -> 258 bytes
-rw-r--r--odk/examples/java/Inspector/manifest.mf3
-rw-r--r--odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl55
-rw-r--r--odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl59
46 files changed, 8149 insertions, 0 deletions
diff --git a/odk/examples/java/Inspector/Addons.xcu b/odk/examples/java/Inspector/Addons.xcu
new file mode 100644
index 000000000..2ea6abdef
--- /dev/null
+++ b/odk/examples/java/Inspector/Addons.xcu
@@ -0,0 +1,40 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office">
+ <node oor:name="AddonUI">
+ <node oor:name="OfficeToolBar">
+ <node oor:name="org.openoffice.Office.addon.Inspector" oor:op="replace">
+ <node oor:name="toolBar_Inspector" oor:op="replace">
+ <prop oor:name="URL" oor:type="xs:string">
+ <value>org.openoffice.Office.addon.Inspector:inspect</value>
+ </prop>
+ <prop oor:name="Title" oor:type="xs:string">
+ <value xml:lang="en-US">Object Inspector</value>
+ </prop>
+ <prop oor:name="Target" oor:type="xs:string">
+ <value>_self</value>
+ </prop>
+ <prop oor:name="Context" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/odk/examples/java/Inspector/HideableMutableTreeNode.java b/odk/examples/java/Inspector/HideableMutableTreeNode.java
new file mode 100644
index 000000000..c601d075e
--- /dev/null
+++ b/odk/examples/java/Inspector/HideableMutableTreeNode.java
@@ -0,0 +1,106 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import javax.swing.tree.*;
+
+/**
+ * <code>HideableMutableTreeNode</code> is a <code>DefaultMutableTreeNode</code>
+ * implementation that works with <code>HideableTreeModel</code>.
+ */
+public class HideableMutableTreeNode extends DefaultMutableTreeNode {
+ /**
+ * The node is visible flag.
+ */
+ private boolean bIsvisible = true;
+ private static final String SDUMMY = "Dummy";
+
+
+ /**
+ * Creates a tree node that has no parent and no children, but which
+ * allows children.
+ */
+ public HideableMutableTreeNode() {
+ super();
+ }
+
+ /**
+ * Creates a tree node with no parent, no children, but which allows
+ * children, and initializes it with the specified user object.
+ *
+ * @param _userObject - an Object provided by the user that
+ * constitutes the node's data
+ */
+ public HideableMutableTreeNode(Object _userObject) {
+ super(_userObject);
+ }
+
+ /**
+ * Creates a tree node with no parent, no children, initialized with the
+ * specified user object, and that allows children only if specified.
+ *
+ * @param _userObject - an Object provided by the user that describes the node's data
+ * @param _ballowsChildren - if true, the node is allowed to have childnodes -- otherwise, it is always a leaf node
+ */
+ public HideableMutableTreeNode(Object _userObject, boolean _ballowsChildren) {
+ super(_userObject, _ballowsChildren);
+ }
+
+ /**
+ * Checks if the node is visible.
+ *
+ * @return true if the node is visible, else false
+ */
+ public boolean isVisible() {
+ return this.bIsvisible;
+ }
+
+ /**
+ * Sets if the node is visible.
+ *
+ * @param _bIsVisible true if the node is visible, else false
+ */
+ public void setVisible(boolean _bIsVisible) {
+ this.bIsvisible = _bIsVisible;
+ }
+
+
+ public void addDummyNode(){
+ removeDummyNode();
+ DefaultMutableTreeNode oDefaultMutableTreeNode = new DefaultMutableTreeNode(SDUMMY);
+ add(oDefaultMutableTreeNode);
+
+ }
+
+
+ public boolean removeDummyNode(){
+ boolean breturn = false;
+ if (getChildCount() == 1){
+ DefaultMutableTreeNode oDefaultMutableTreeNode = (DefaultMutableTreeNode) getChildAt(0);
+ if (oDefaultMutableTreeNode != null){
+ if (oDefaultMutableTreeNode.getUserObject().equals(SDUMMY)){
+ remove(0);
+ breturn = true;
+ }
+ }
+ }
+ return breturn;
+ }
+
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/HideableTreeModel.java b/odk/examples/java/Inspector/HideableTreeModel.java
new file mode 100644
index 000000000..b70d63046
--- /dev/null
+++ b/odk/examples/java/Inspector/HideableTreeModel.java
@@ -0,0 +1,258 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import java.util.ArrayList;
+import javax.swing.event.TreeModelEvent;
+import javax.swing.event.TreeModelListener;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+
+
+public class HideableTreeModel implements TreeModel {
+
+ private ArrayList<TreeModelListener> modelListeners = new ArrayList<TreeModelListener>();
+ private Object root = null;
+
+
+ public HideableTreeModel(TreeNode _root) {
+ super();
+ setRoot(_root);
+ }
+
+
+ public Object getRoot() {
+ return this.root;
+ }
+
+
+ private void setRoot(Object r) {
+ this.root = r;
+ }
+
+
+ private Object[] getPathToRoot(Object node) {
+ return getPathToRoot(node, 0);
+ }
+
+
+ private Object[] getPathToRoot(Object node, int i) {
+ Object anode[];
+ if(node == null) {
+ if(i == 0) {
+ return null;
+ }
+ anode = new Object[i];
+ } else {
+ i++;
+ if(node == getRoot()) {
+ anode = new Object[i];
+ } else {
+ anode = getPathToRoot(getParent(node), i);
+ }
+ anode[anode.length - i] = node;
+ }
+ return anode;
+ }
+
+
+ public void addTreeModelListener(TreeModelListener l) {
+ modelListeners.add(l);
+ }
+
+
+ public void removeTreeModelListener(TreeModelListener l) {
+ modelListeners.remove(l);
+ }
+
+
+
+
+
+ public void valueForPathChanged(TreePath path, Object newValue) {
+ nodeChanged(path.getLastPathComponent());
+ }
+
+
+
+
+ public void nodeInserted(Object node, Object child, int index) {
+ if(index < 0) {
+ index = getIndexOfChild(node, child);
+ }
+ if(node != null && child != null && index >= 0) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ int[] ai = { index };
+ Object[] ac = { child };
+ fireTreeNodesInserted(new TreeModelEvent(this, tp, ai, ac));
+ }
+ }
+
+
+ private void nodeRemoved(Object node, Object child, int index) {
+ if(node != null && child != null && index >= 0) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ int[] ai = { index };
+ Object[] ac = { child };
+ fireTreeNodesRemoved(new TreeModelEvent(this, tp, ai, ac));
+ }
+ }
+
+
+ public void nodeChanged(Object node) {
+ if(node != null) {
+ TreePath tp = new TreePath(getPathToRoot(node));
+ fireTreeNodesChanged(new TreeModelEvent(this, tp, null, null));
+ }
+ }
+
+
+ private void fireTreeNodesChanged(TreeModelEvent event) {
+ for(TreeModelListener l : modelListeners) {
+ l.treeNodesChanged(event);
+ }
+ }
+
+
+ private void fireTreeNodesInserted(TreeModelEvent event) {
+ for(TreeModelListener l : modelListeners) {
+ l.treeNodesInserted(event);
+ }
+ }
+
+
+ private void fireTreeNodesRemoved(TreeModelEvent event) {
+ for(TreeModelListener l : modelListeners) {
+ l.treeNodesRemoved(event);
+ }
+ }
+
+ public boolean isLeaf(Object _oNode) {
+ if(_oNode instanceof TreeNode) {
+ return ((TreeNode) _oNode).isLeaf();
+ }
+ return true;
+ }
+
+
+
+ private Object getParent(Object node) {
+ if(node != getRoot() && (node instanceof TreeNode)) {
+ return ((TreeNode)node).getParent();
+ }
+ return null;
+ }
+
+
+ private boolean isNodeVisible(Object node) {
+ if(node != getRoot()) {
+ if(node instanceof HideableMutableTreeNode) {
+ return ((HideableMutableTreeNode)node).isVisible();
+ }
+ }
+ return true;
+ }
+
+
+ public boolean setNodeVisible(Object node, boolean v) {
+ // can't hide root
+ if(node != getRoot()) {
+ if(node instanceof HideableMutableTreeNode) {
+ HideableMutableTreeNode n = (HideableMutableTreeNode)node;
+ if(v != n.isVisible()) {
+ TreeNode parent = n.getParent();
+ if(v) {
+ // need to get index after showing...
+ n.setVisible(v);
+ int index = getIndexOfChild(parent, n);
+ nodeInserted(parent, n, index);
+ } else {
+ // need to get index before hiding...
+ int index = getIndexOfChild(parent, n);
+ n.setVisible(v);
+ nodeRemoved(parent, n, index);
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+
+
+
+
+
+ public Object getChild(Object parent, int index) {
+ if(parent instanceof TreeNode) {
+ TreeNode p = (TreeNode) parent;
+ for(int i = 0, j = -1; i < p.getChildCount(); i++) {
+ TreeNode pc = p.getChildAt(i);
+ if(isNodeVisible(pc)) {
+ j++;
+ }
+ if(j == index) {
+ return pc;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ public int getChildCount(Object parent) {
+ int count = 0;
+ if(parent instanceof TreeNode) {
+ TreeNode p = (TreeNode) parent;
+ for(int i = 0; i < p.getChildCount(); i++) {
+ TreeNode pc = p.getChildAt(i);
+ if(isNodeVisible(pc)) {
+ count++;
+ }
+ }
+ }
+ return count;
+ }
+
+
+ public int getIndexOfChild(Object parent, Object child) {
+ int index = -1;
+ if(parent instanceof TreeNode && child instanceof TreeNode) {
+ TreeNode p = (TreeNode)parent;
+ TreeNode c = (TreeNode)child;
+ if(isNodeVisible(c)) {
+ index = 0;
+ for(int i = 0; i < p.getChildCount(); i++) {
+ TreeNode pc = p.getChildAt(i);
+ if(pc.equals(c)) {
+ return index;
+ }
+ if(isNodeVisible(pc)) {
+ index++;
+ }
+ }
+ }
+ }
+ return index;
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/Inspector.java b/odk/examples/java/Inspector/Inspector.java
new file mode 100644
index 000000000..18d8d909a
--- /dev/null
+++ b/odk/examples/java/Inspector/Inspector.java
@@ -0,0 +1,459 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.openoffice.XInstanceInspector;
+
+import com.sun.star.awt.XMessageBox;
+import com.sun.star.awt.XMessageBoxFactory;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.beans.NamedValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.configuration.theDefaultProvider;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.Factory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.ui.dialogs.XExecutableDialog;
+import com.sun.star.ui.dialogs.XFolderPicker2;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.CloseVetoException;
+import com.sun.star.util.XChangesBatch;
+import com.sun.star.util.XCloseable;
+
+
+/** The purpose of this class is to provide a factory for creating the service
+ * (<CODE>__getServiceFactory</CODE>) and writes the information into the given
+ * registry key (<CODE>__writeRegistryServiceInfo</CODE>).
+ */
+public class Inspector{
+ public static final String sIDLDOCUMENTSUBFOLDER = "docs/idl/ref/";
+
+
+ /** This class implements the method of the interface XInstanceInspector.
+ * Also the class implements the interfaces XServiceInfo, and XTypeProvider.
+ */
+ public static class _Inspector extends WeakBase implements XInstanceInspector, XServiceInfo{
+
+ private static final String __serviceName = "org.openoffice.InstanceInspector";
+ private HashMap<String, String> aApplicationHashMap = new HashMap<String, String>();
+ private String sTitle = "Object Inspector";
+ private ArrayList<XComponent> aHiddenDocuments = new ArrayList<XComponent>();
+ private XComponentContext m_xComponentContext;
+ private HashMap<String, InspectorPane> aInspectorPanes = new HashMap<String, InspectorPane>();
+ private XDialogProvider m_oSwingDialogProvider;
+ private TDocSupplier oTDocSupplier;
+ private Introspector m_oIntrospector = null;
+ // TODO: improve these strings:
+ private static final String sWRONGINSTALLATIONPATH = "Your selected path does not refer to an SDK-Installation!";
+ /** Creates a new instance of Dialog */
+ public _Inspector(XComponentContext _xComponentContext) {
+ m_xComponentContext = _xComponentContext;
+ m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
+ aApplicationHashMap.put("private:factory/swriter", "Text Document");
+ aApplicationHashMap.put("private:factory/scalc", "Spreadsheet");
+ aApplicationHashMap.put("private:factory/simpress", "Presentation");
+ aApplicationHashMap.put("private:factory/sdraw", "Drawing");
+ aApplicationHashMap.put("private:factory/smath", "Formula");
+ m_oSwingDialogProvider = new SwingDialogProvider(this, sTitle);
+ }
+
+
+ public XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ public HashMap<String, InspectorPane> getInspectorPages(){
+ return aInspectorPanes;
+ }
+
+
+ private String getSDKPath(){
+ String sRetPath = "";
+ try{
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
+ XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ sRetPath = (String) xPropertySet.getPropertyValue("SDKPath");
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }
+ return sRetPath;
+ }
+
+
+ public String getIDLPath(){
+ String sRetPath = getSDKPath();
+ if (m_oIntrospector.isValidSDKInstallationPath(sRetPath)){
+ sRetPath = Introspector.addToPath(sRetPath, sIDLDOCUMENTSUBFOLDER);
+ }
+ else{
+ sRetPath = "";
+ }
+ return sRetPath;
+ }
+
+
+ public void openIdlFileforSelectedNode(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
+ if (oUnoNode != null){
+ String sPath = getIDLPath();
+ oUnoNode.openIdlDescription(sPath);
+ }
+ }
+ }
+
+
+ public void assignSDKPath() {
+ try {
+ String sInstallationFolder = "";
+ Object oFolderPicker = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ui.dialogs.FolderPicker", m_xComponentContext);
+ XFolderPicker2 xFolderPicker = UnoRuntime.queryInterface(XFolderPicker2.class, oFolderPicker);
+ XExecutableDialog xExecutable = UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker);
+ XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, oFolderPicker);
+ String sPath = getSDKPath();
+ if (!sPath.equals("")){
+ xFolderPicker.setDisplayDirectory(sPath);
+ }
+ xFolderPicker.setTitle("Add the Path to your SDK installation");
+ short nResult = xExecutable.execute();
+ if (nResult == com.sun.star.ui.dialogs.ExecutableDialogResults.OK){
+ sInstallationFolder = xFolderPicker.getDirectory();
+ if (m_oIntrospector.isValidSDKInstallationPath(sInstallationFolder)){
+ XNameAccess xNameAccess = getConfigurationAccess(true);
+ XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ xPropertySet.setPropertyValue("SDKPath", sInstallationFolder);
+ XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
+ xBatch.commitChanges();
+ }
+ else{
+ XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xFolderPicker);
+ Object oWindow = xPropertySet.getPropertyValue("Window");
+ XWindowPeer xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, oWindow);
+ showErrorMessageBox(xWindowPeer, sTitle, sWRONGINSTALLATIONPATH);
+ assignSDKPath();
+ }
+ }
+ xComponent.dispose();
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ private void showErrorMessageBox(XWindowPeer _xWindowPeer, String _sTitle, String _sMessage){
+ try {
+ Object oToolkit = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xComponentContext);
+ XMessageBoxFactory xMessageBoxFactory = UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit);
+ XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xWindowPeer, com.sun.star.awt.MessageBoxType.ERRORBOX, com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage);
+ XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xMessageBox);
+ if (xMessageBox != null){
+ xMessageBox.execute();
+ xComponent.dispose();
+ }
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.err);
+ }}
+
+
+ public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
+ try {
+ int nPageIndex = m_oSwingDialogProvider.getInspectorPageCount();
+ SwingTreeControlProvider oSwingTreeControlProvider = new SwingTreeControlProvider(m_oSwingDialogProvider);
+ InspectorPane oInspectorPane = new InspectorPane(getXComponentContext(), m_oSwingDialogProvider, oSwingTreeControlProvider, getSourceCodeLanguage());
+ oInspectorPane.inspect(_oUserDefinedObject, _sTitle);
+ getInspectorPages().put(_sTitle, oInspectorPane);
+ m_oSwingDialogProvider.show(nPageIndex);
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ public void inspectOpenEmptyDocument(String _sApplicationDocUrl){
+ XComponent xComponent = getTDocSupplier().openEmptyDocument(_sApplicationDocUrl);
+ String sRootTitle = aApplicationHashMap.get(_sApplicationDocUrl);
+ inspect(xComponent, sRootTitle);
+ aHiddenDocuments.add(xComponent);
+ }
+
+
+ public void inspectOpenDocument(String _sTDocUrl){
+ String sTreeNodeName = getTDocSupplier().getTitleByTDocUrl(_sTDocUrl);
+ XModel xTDocModel = getTDocSupplier().getXModelByTDocUrl(_sTDocUrl);
+ inspect(xTDocModel, sTreeNodeName);
+ }
+
+
+ public void inspectSelectedNode(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ XUnoNode oUnoNode = oInspectorPane.getSelectedNode();
+ Object oUnoObject = oUnoNode.getUnoObject();
+ if (oUnoObject != null){
+ String sNodeDescription = UnoNode.getNodeDescription(oUnoObject);
+ inspect(oUnoObject, sNodeDescription);
+ }
+ }
+ }
+
+
+ public void addSourceCodeOfSelectedNode(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ oInspectorPane.addSourceCodeOfSelectedNode();
+ }
+ }
+
+
+ public void invokeSelectedMethod(){
+ InspectorPane oInspectorPane = m_oSwingDialogProvider.getSelectedInspectorPage();
+ if (oInspectorPane != null){
+ oInspectorPane.invokeSelectedMethodNode();
+ }
+ }
+
+
+ public void setSourceCodeLanguage(final int _nLanguage){
+ try{
+ String sLanguage = "Java";
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", true);
+ XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xNameAccess);
+ switch (_nLanguage){
+ case XLanguageSourceCodeGenerator.nJAVA:
+ sLanguage = "Java";
+ break;
+ case XLanguageSourceCodeGenerator.nCPLUSPLUS:
+ sLanguage = "CPlusPlus";
+ break;
+ case XLanguageSourceCodeGenerator.nBASIC:
+ sLanguage = "Basic";
+ break;
+ default:
+ System.out.println("Warning: Sourcecode language is not defined!");
+ }
+ xPropertySet.setPropertyValue("Language", sLanguage);
+ XChangesBatch xBatch = UnoRuntime.queryInterface(XChangesBatch.class, xNameAccess);
+ xBatch.commitChanges();
+ for (int i = 0; i < m_oSwingDialogProvider.getInspectorPageCount(); i++){
+ m_oSwingDialogProvider.getInspectorPage(i).convertCompleteSourceCode(_nLanguage);
+ }
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ private TDocSupplier getTDocSupplier(){
+ if (oTDocSupplier == null){
+ oTDocSupplier = new TDocSupplier(m_xComponentContext);
+ }
+ return oTDocSupplier;
+ }
+
+ public String[] getTDocUrls(){
+ return getTDocSupplier().getTDocUrls();
+ }
+
+
+ public String[] getTDocTitles(String[] _sTDocUrls){
+ return getTDocSupplier().getTDocTitles(_sTDocUrls);
+ }
+
+
+ public String[][] getApplicationUrls(){
+ Set<String> aSet = aApplicationHashMap.keySet();
+ String[][] sReturnList = new String[aSet.size()][];
+ int n= 0;
+ for ( Iterator<String> i = aSet.iterator(); i.hasNext(); ){
+ String[] sSingleApplication = new String[2];
+ sSingleApplication[0] = i.next();
+ // assign the title in the second index
+ sSingleApplication[1] = aApplicationHashMap.get(sSingleApplication[0]);
+ sReturnList[n++] = sSingleApplication;
+ }
+ return sReturnList;
+ }
+
+
+ public void disposeHiddenDocuments(){
+ int nHiddenCount = aHiddenDocuments.size();
+ if (nHiddenCount > 0){
+ for (int i = nHiddenCount - 1; i >= 0; i--){
+ XComponent xComponent = aHiddenDocuments.get(i);
+ if (xComponent != null){
+ try {
+ XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xComponent);
+ xCloseable.close(true);
+ aHiddenDocuments.remove(i);
+ } catch (CloseVetoException ex) {
+ ex.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+
+ private static String[] getServiceNames() {
+ String[] sSupportedServiceNames = { __serviceName };
+ return sSupportedServiceNames;
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get all supported service names.
+ * @return Supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ // Implement the interface XServiceInfo
+ /** Test, if the given service will be supported.
+ * @return Return true, if the service will be supported.
+ */
+ public boolean supportsService( String sServiceName ) {
+ return sServiceName.equals( __serviceName );
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get the implementation name of the component.
+ * @return Implementation name of the component.
+ */
+ public String getImplementationName() {
+ return _Inspector.class.getName();
+ }
+
+
+ private int getSourceCodeLanguage(){
+ int nLanguage = XLanguageSourceCodeGenerator.nJAVA;
+ try{
+ XNameAccess xNameAccess = getConfigurationAccess("org.openoffice.inspector.ObjectInspector", false);
+ String sLanguage = (String) xNameAccess.getByName("Language");
+ if (sLanguage.toUpperCase().equals("JAVA")){
+ nLanguage = XLanguageSourceCodeGenerator.nJAVA;
+ }
+ else if (sLanguage.toUpperCase().equals("BASIC")){
+ nLanguage = XLanguageSourceCodeGenerator.nBASIC;
+ }
+ else if (sLanguage.toUpperCase().equals("CPLUSPLUS")){
+ nLanguage = XLanguageSourceCodeGenerator.nCPLUSPLUS;
+ }
+ else{
+ System.out.println("Warning: Sourcecode language " + sLanguage + " is not defined!");
+ }
+ m_oSwingDialogProvider.selectSourceCodeLanguage(nLanguage);
+ }catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }
+ return nLanguage;
+ }
+
+
+ private XNameAccess getConfigurationAccess(boolean _bUpdate){
+ return getConfigurationAccess("org.openoffice.inspector.ObjectInspector", _bUpdate);
+ }
+
+
+ private XNameAccess getConfigurationAccess(String _sNodePath, boolean update) {
+ XNameAccess xNameAccess = null;
+ try {
+ String sAccess = "";
+ if (update) {
+ sAccess = "com.sun.star.configuration.ConfigurationUpdateAccess";
+ }
+ else{
+ sAccess = "com.sun.star.configuration.ConfigurationAccess";
+ }
+ XMultiComponentFactory xMCF = m_xComponentContext.getServiceManager();
+ XMultiServiceFactory xMSFCfg = theDefaultProvider.get(this.getXComponentContext());
+ Object oAccess = xMSFCfg.createInstanceWithArguments(sAccess, new Object[]{new NamedValue("nodepath", _sNodePath)});
+ xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oAccess);
+ } catch (com.sun.star.uno.Exception e) {
+ }
+ return xNameAccess;
+ }
+
+
+ }
+
+// end of inner class
+
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory( String sImplName )
+ {
+ XSingleComponentFactory xFactory = null;
+ if ( sImplName.equals( _Inspector.class.getName() ) )
+ xFactory = Factory.createComponentFactory(_Inspector.class, _Inspector.getServiceNames());
+ if ( xFactory == null )
+ xFactory = InspectorAddon.__getComponentFactory(sImplName);
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return (Factory.writeRegistryServiceInfo(_Inspector.class.getName(), _Inspector.getServiceNames(), regKey)
+ && InspectorAddon.__writeRegistryServiceInfo(regKey));
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/InspectorAddon.java b/odk/examples/java/Inspector/InspectorAddon.java
new file mode 100644
index 000000000..b001d17b5
--- /dev/null
+++ b/odk/examples/java/Inspector/InspectorAddon.java
@@ -0,0 +1,224 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.frame.DispatchDescriptor;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XStatusListener;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lib.uno.helper.Factory;
+
+
+public class InspectorAddon {
+ /** This class implements the component. At least the interfaces XServiceInfo,
+ * XTypeProvider, and XInitialization should be provided by the service.
+ */
+ public static class InspectorAddonImpl extends WeakBase implements XDispatchProvider, XInitialization, XServiceInfo {
+ private org.openoffice.XInstanceInspector xInstInspector = null;
+// Dispatcher oDispatcher = null;
+ private XFrame m_xFrame = null;
+
+ private static final String[] m_serviceNames = {
+ "org.openoffice.InstanceInspectorAddon",
+ "com.sun.star.frame.ProtocolHandler" };
+
+ private XComponentContext m_xContext = null;
+
+ /** Creates a new instance of InspectorAddon */
+ public InspectorAddonImpl(XComponentContext _xContext) {
+ m_xContext = _xContext;
+ }
+
+ public XDispatch queryDispatch( /*IN*/com.sun.star.util.URL aURL, /*IN*/String sTargetFrameName, /*IN*/int iSearchFlags ) {
+ XDispatch xRet = null;
+ if ( aURL.Protocol.equals("org.openoffice.Office.addon.Inspector:") ) {
+ if ( aURL.Path.equals( "inspect" ) ){
+ // Todo: Check if the frame is already administered (use hashtable)
+ xRet = new Dispatcher(m_xFrame);
+ }
+ }
+ return xRet;
+ }
+
+
+ public XDispatch[] queryDispatches( /*IN*/DispatchDescriptor[] seqDescripts ) {
+ int nCount = seqDescripts.length;
+ XDispatch[] lDispatcher = new XDispatch[nCount];
+ for( int i=0; i<nCount; ++i )
+ lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
+ return lDispatcher;
+ }
+
+
+ public void initialize( Object[] object ) throws com.sun.star.uno.Exception {
+ if ( object.length > 0 ){
+ m_xFrame = UnoRuntime.queryInterface(XFrame.class, object[ 0 ] );
+ }
+ }
+
+ private class Dispatcher implements XDispatch{
+ private XFrame m_xFrame = null;
+ private XModel xModel = null;
+
+ private Dispatcher(XFrame _xFrame){
+ m_xFrame = _xFrame;
+ if (m_xFrame != null){
+ XController xController = m_xFrame.getController();
+ if (xController != null){
+ xModel = xController.getModel();
+ }
+ }
+ }
+
+ // XDispatch
+ public void dispatch( /*IN*/com.sun.star.util.URL _aURL, /*IN*/com.sun.star.beans.PropertyValue[] aArguments ) {
+ try{
+ if ( _aURL.Protocol.equals("org.openoffice.Office.addon.Inspector:") ){
+ if ( _aURL.Path.equals("inspect")){
+ Object oUnoInspectObject = xModel;
+ com.sun.star.lang.XMultiComponentFactory xMCF = m_xContext.getServiceManager();
+ if (xInstInspector == null){
+ Object obj= xMCF.createInstanceWithContext("org.openoffice.InstanceInspector", m_xContext);
+ xInstInspector = UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj);
+ }
+ if ((m_xFrame == null) || (xModel == null)){
+ Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext);
+ m_xFrame = UnoRuntime.queryInterface(XFrame.class, oDesktop);
+ oUnoInspectObject = m_xFrame;
+ }
+ XPropertySet xFramePropertySet = UnoRuntime.queryInterface(XPropertySet.class, m_xFrame);
+ String sTitle = (String) xFramePropertySet.getPropertyValue("Title");
+ String[] sTitleList = sTitle.split(" - ");
+ if (sTitleList.length > 0){
+ sTitle = sTitleList[0];
+ }
+ xInstInspector.inspect(oUnoInspectObject, sTitle);
+ }
+ }
+ } catch( Exception e ) {
+ System.err.println( e + e.getMessage());
+ e.printStackTrace(System.err);
+ }}
+
+ public void addStatusListener( /*IN*/XStatusListener xControl, /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+ public void removeStatusListener( /*IN*/XStatusListener xControl, /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+
+ }
+
+
+ private static String[] getServiceNames() {
+ return m_serviceNames;
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get all supported service names.
+ * @return Supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ // Implement the interface XServiceInfo
+ /** Test, if the given service will be supported.
+ * @return Return true, if the service will be supported.
+ */
+ public boolean supportsService( String sServiceName ) {
+ int len = m_serviceNames.length;
+
+ for( int i=0; i < len; i++) {
+ if ( sServiceName.equals( m_serviceNames[i] ) )
+ return true;
+ }
+
+ return false;
+ }
+
+ // Implement the interface XServiceInfo
+ /** Get the implementation name of the component.
+ * @return Implementation name of the component.
+ */
+ public String getImplementationName() {
+ return InspectorAddonImpl.class.getName();
+ }
+
+ }
+
+
+ /**
+ * Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns a <code>XSingleComponentFactory</code> for creating
+ * the component
+ * @param sImplName the name of the implementation for which a
+ * service is desired
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static XSingleComponentFactory __getComponentFactory( String sImplName )
+ {
+ XSingleComponentFactory xFactory = null;
+ if ( sImplName.equals( InspectorAddonImpl.class.getName() ) )
+ xFactory = Factory.createComponentFactory(InspectorAddonImpl.class, InspectorAddonImpl.getServiceNames());
+ return xFactory;
+ }
+
+ /**
+ * Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return returns true if the operation succeeded
+ * @param regKey the registryKey
+ * @see com.sun.star.comp.loader.JavaLoader
+ */
+ public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
+ return Factory.writeRegistryServiceInfo(InspectorAddonImpl.class.getName(), InspectorAddonImpl.getServiceNames(), regKey);
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/InspectorPane.java b/odk/examples/java/Inspector/InspectorPane.java
new file mode 100644
index 000000000..6483958b7
--- /dev/null
+++ b/odk/examples/java/Inspector/InspectorPane.java
@@ -0,0 +1,577 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+import org.openoffice.XInstanceInspector;
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XIntrospectionAccess;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+ public class InspectorPane extends WeakBase implements XInstanceInspector{ //, XServiceInfo
+ private XComponentContext m_xComponentContext;
+ private XDialogProvider m_xDialogProvider;
+ private Introspector m_oIntrospector = null;
+ private SourceCodeGenerator m_oSourceCodeGenerator;
+ private XTreeControlProvider m_xTreeControlProvider;
+ private String sTitle = "";
+
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ */
+ public InspectorPane(XComponentContext _xComponentContext, XDialogProvider _xDialogProvider, XTreeControlProvider _xTreeControlProvider, int _nLanguage) {
+ m_xComponentContext = _xComponentContext;
+ m_xTreeControlProvider = _xTreeControlProvider;
+ m_xDialogProvider = _xDialogProvider;
+ m_oIntrospector = Introspector.getIntrospector(m_xComponentContext);
+ m_oSourceCodeGenerator = new SourceCodeGenerator(_nLanguage);
+ _xTreeControlProvider.addInspectorPane(this);
+ }
+
+ /** Inspect the given object for methods, properties, interfaces, and
+ * services.
+ * @param _oUserDefinedObject The object to inspect
+ * @throws RuntimeException If
+ */
+ public void inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
+ try {
+ Object oContainer = m_xTreeControlProvider.inspect(_oUserDefinedObject, _sTitle);
+ m_xDialogProvider.addInspectorPage(getTitle(), oContainer);
+ }
+ catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ public void setTitle(String _sTitle){
+ if (_sTitle != null){
+ if (_sTitle.length() > 0){
+ sTitle = _sTitle;
+ }
+ }
+ }
+
+
+ public String getTitle(){
+ return sTitle;
+ }
+
+
+
+ private Type[] getTypes(Object _oUnoObject){
+ Type[] aTypes = null;
+ if (AnyConverter.isArray(_oUnoObject)){
+ aTypes = (Type[])_oUnoObject;
+ }
+ else{
+ aTypes = m_oIntrospector.getInterfaces(_oUnoObject);
+ }
+ return aTypes;
+ }
+
+
+ private Object invoke(XUnoMethodNode _oUnoMethodNode){
+ try{
+ String sParamValueDescription = "";
+ Object oUnoReturnObject = _oUnoMethodNode.invoke();
+ boolean bHasParameters = _oUnoMethodNode.hasParameters();
+ boolean bIsPrimitive = _oUnoMethodNode.isPrimitive();
+ if (bHasParameters){
+ sParamValueDescription = " (" + m_oSourceCodeGenerator.getMethodParameterValueDescription(_oUnoMethodNode, _oUnoMethodNode.getLastParameterObjects(), true) + ")";
+ }
+ if (oUnoReturnObject != null ){
+ String sNodeDescription = "";
+ XUnoNode oUnoNode = null;
+ if (_oUnoMethodNode.getXIdlMethod().getReturnType().getTypeClass().getValue() == TypeClass.VOID_value){
+ sNodeDescription += _oUnoMethodNode.getXIdlMethod().getReturnType().getName() + " " + _oUnoMethodNode.getXIdlMethod().getName() + sParamValueDescription;
+ _oUnoMethodNode.setLabel(sNodeDescription);
+ m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
+ }
+ else if (bHasParameters || !bIsPrimitive){
+ if (bIsPrimitive){
+ sNodeDescription += m_oSourceCodeGenerator.getStringValueOfObject(oUnoReturnObject, _oUnoMethodNode.getTypeClass());
+ }
+ else{
+ Any aReturnObject = Any.complete(oUnoReturnObject);
+ String sShortClassName = Introspector.getShortClassName(aReturnObject.getType().getTypeName());
+ sNodeDescription += m_oSourceCodeGenerator.getVariableNameforUnoObject(sShortClassName);
+ }
+ if (Introspector.isArray(oUnoReturnObject)){
+ if (Introspector.isUnoTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoMethodNode.getUnoObject());
+ }
+ else if(Introspector.isUnoPropertyTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYINFODESCRIPTION, oUnoReturnObject);
+ }
+ else if(Introspector.isUnoPropertyValueTypeObject(oUnoReturnObject)){
+ oUnoNode = addUnoFacetteNode(_oUnoMethodNode, XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION, oUnoReturnObject);
+ }
+ }
+ if (oUnoNode == null){
+ if (bHasParameters){
+ sNodeDescription += sParamValueDescription;
+ }
+ oUnoNode = addUnoNode(null, oUnoReturnObject, sNodeDescription);
+ if (bHasParameters){
+ oUnoNode.setParameterObjects(_oUnoMethodNode.getLastParameterObjects());
+ }
+ }
+ if (oUnoNode != null){
+ oUnoNode.setFoldable(!bIsPrimitive);
+ _oUnoMethodNode.setFoldable(false);
+ _oUnoMethodNode.addChildNode(oUnoNode);
+ m_xTreeControlProvider.nodeInserted(_oUnoMethodNode, oUnoNode, _oUnoMethodNode.getChildCount()-1);
+ }
+ }
+ else{
+ if (bIsPrimitive){
+ sNodeDescription = _oUnoMethodNode.getStandardMethodDescription() + "=" + UnoMethodNode.getDisplayValueOfPrimitiveType(oUnoReturnObject);
+ _oUnoMethodNode.setLabel(sNodeDescription);
+ m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
+ }
+ }
+ }
+ // ReturnObject of method node == null...
+ else{
+ if (!bHasParameters){
+ _oUnoMethodNode.setLabel(_oUnoMethodNode.getLabel() + " = null");
+ }
+ else{
+ _oUnoMethodNode.setLabel(_oUnoMethodNode.getXIdlMethod().getName() + sParamValueDescription + " = null");
+ }
+ m_xTreeControlProvider.nodeChanged(_oUnoMethodNode);
+ }
+ return oUnoReturnObject;
+ }catch(Exception exception ) {
+ return null;
+ }}
+
+
+ public void invokeSelectedMethodNode(){
+ XTreePathProvider xTreePathProvider = m_xTreeControlProvider.getSelectedPath();
+ XUnoNode oUnoNode = xTreePathProvider.getLastPathComponent();
+ if (oUnoNode instanceof XUnoMethodNode){
+ invoke((XUnoMethodNode) oUnoNode);
+ m_xTreeControlProvider.expandPath(xTreePathProvider);
+ }
+ }
+
+
+ public void addSourceCodeOfSelectedNode(){
+ XTreePathProvider oTreePathProvider = m_xTreeControlProvider.getSelectedPath();
+ XUnoNode oUnoNode = oTreePathProvider.getLastPathComponent();
+ if (oUnoNode instanceof XUnoMethodNode){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ if (!oUnoMethodNode.isInvoked() && oUnoMethodNode.isInvokable()){
+ invoke(oUnoMethodNode);
+ }
+ }
+ String sSourceCode = m_oSourceCodeGenerator.addSourceCodeOfUnoObject(oTreePathProvider, true, true);
+ m_xTreeControlProvider.setSourceCode(sSourceCode);
+ }
+
+
+ public void convertCompleteSourceCode(int _nLanguage){
+ String sSourceCode = m_oSourceCodeGenerator.convertAllUnoObjects(_nLanguage);
+ m_xTreeControlProvider.setSourceCode(sSourceCode);
+ }
+
+ protected XUnoNode getSelectedNode(){
+ return m_xTreeControlProvider.getSelectedNode();
+ }
+
+
+ // add the object to the hashtable for a possible access in the tree
+ private XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject){
+ return m_xTreeControlProvider.addUnoFacetteNode( _oParentNode, _sNodeDescription, _oUnoObject);
+ }
+
+
+ private XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod){
+ return m_xTreeControlProvider.addMethodNode(_objectElement, _xIdlMethod);
+ }
+
+
+
+ private void addMethodsToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, XIdlMethod[] _xIdlMethods){
+ if (Introspector.isValid(_xIdlMethods)){
+ for ( int n = 0; n < _xIdlMethods.length; n++ ) {
+ XIdlMethod xIdlMethod = _xIdlMethods[n];
+ if (!xIdlMethod.getDeclaringClass().getName().equals("com.sun.star.uno.XInterface")){
+ XUnoMethodNode oChildNode = addMethodNode(_oUnoParentObject, xIdlMethod);
+ if (oChildNode != null){
+ _oGrandParentNode.addChildNode(oChildNode);
+ }
+ }
+ }
+ }
+ }
+
+
+ private void addFacetteNodesToTreeNode(XUnoNode _oParentNode, Object _oUnoObject){
+ if (m_oIntrospector.hasMethods(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SMETHODDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasProperties(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SPROPERTYDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasInterfaces(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SINTERFACEDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.isContainer(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SCONTAINERDESCRIPTION, _oUnoObject);
+ }
+ if (m_oIntrospector.hasSupportedServices(_oUnoObject)){
+ addUnoFacetteNode(_oParentNode, XUnoFacetteNode.SSERVICEDESCRIPTION, _oUnoObject);
+ }
+ }
+
+
+ private void addInterfacesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoParentObject, Type[] _aTypes) {
+ try {
+ if (_oUnoParentObject != null){
+ for ( int m = 0; m < _aTypes.length; m++ ) {
+ addUnoNode(_oGrandParentNode, _oUnoParentObject, _aTypes[m]);
+ }
+ }
+ }
+ catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ // add all services for the given object to the tree under the node parent
+ private void addServicesToTreeNode(XUnoNode _oGrandParentNode, Object _oUnoObject) {
+ try{
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject );
+ if ( xServiceInfo != null ){
+ String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
+ for ( int m = 0; m < sSupportedServiceNames.length; m++ ) {
+ String sServiceName = sSupportedServiceNames[m];
+ if (sServiceName.length() > 0){
+ XUnoNode oUnoNode = addUnoNode(_oGrandParentNode, _oUnoObject, sSupportedServiceNames[m]);
+ oUnoNode.setNodeType(XUnoNode.nSERVICE);
+ }
+ }
+ }
+ }
+ catch(Exception exception) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ private void addPropertiesAndInterfacesOfService(XUnoNode _oUnoServiceNode){
+ String sServiceName = _oUnoServiceNode.getClassName();
+ Object oUnoObject = _oUnoServiceNode.getUnoObject();
+ addInterfacesToTreeNode(_oUnoServiceNode, oUnoObject, m_oIntrospector.getInterfaces(oUnoObject, sServiceName));
+ addPropertiesToTreeNode(_oUnoServiceNode, oUnoObject, m_oIntrospector.getProperties(oUnoObject, sServiceName));
+ }
+
+
+ private void addPropertiesToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject, Property[] _aProperties) {
+ try {
+ if (_aProperties.length > 0){
+ for ( int n = 0; n < _aProperties.length; n++ ){
+ Property aProperty = _aProperties[n];
+ XIntrospectionAccess xIntrospectionAccess = m_oIntrospector.getXIntrospectionAccess(_oUnoParentObject);
+ XPropertySet xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, xIntrospectionAccess.queryAdapter(new Type( XPropertySet.class)));
+ if (xPropertySet != null) {
+ if (xPropertySet.getPropertySetInfo().hasPropertyByName(aProperty.Name)){
+ Object objectElement = xPropertySet.getPropertyValue(aProperty.Name);
+ if (objectElement != null) {
+ XUnoNode oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoParentObject, aProperty, objectElement);
+ if (oChildNode != null){
+ _oParentNode.addChildNode(oChildNode);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ catch(Exception exception) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ private void addContainerElementsToTreeNode(XUnoNode _oParentNode, Object _oUnoParentObject){
+ Object[] oUnoContainerElements = m_oIntrospector.getUnoObjectsOfContainer(_oUnoParentObject);
+ if (Introspector.isValid(oUnoContainerElements)){
+ if (oUnoContainerElements.length > 0){
+ for (int i=0; i< oUnoContainerElements.length; i++){
+ XUnoNode oChildNode = addUnoNode(_oParentNode, oUnoContainerElements[i], UnoNode.getNodeDescription(oUnoContainerElements[i]));
+ m_xTreeControlProvider.nodeInserted(_oParentNode, oChildNode, _oParentNode.getChildCount()-1);
+ }
+ }
+ }
+ }
+
+
+ private XUnoNode addUnoNode(XUnoNode _oParentNode, Object _oUnoObject, String _sLabel ){
+ XUnoNode oUnoNode = this.m_xTreeControlProvider.addUnoNode(_oUnoObject);
+ oUnoNode.setLabel(_sLabel);
+ if (_oParentNode != null){
+ _oParentNode.addChildNode(oUnoNode);
+ }
+ setNodeFoldable(oUnoNode, _oUnoObject);
+ return oUnoNode;
+ }
+
+
+ private void setNodeFoldable(XUnoNode _oUnoNode, Object _oUnoObject){
+ if (_oUnoObject != null){
+ if (!Introspector.isObjectPrimitive(_oUnoObject)){
+ _oUnoNode.setFoldable(true);
+ }
+ }
+ }
+
+
+ private XUnoNode addUnoNode(XUnoNode _oParentNode, Object _oUnoObject, Type _aType){
+ XUnoNode oUnoNode = this.m_xTreeControlProvider.addUnoNode(_oUnoObject, _aType);
+ if (_oParentNode != null){
+ _oParentNode.addChildNode(oUnoNode);
+ }
+ setNodeFoldable(oUnoNode, _oUnoObject);
+ return oUnoNode;
+ }
+
+
+ private void addPropertySetInfoNodesToTreeNode(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){
+ if (_oUnoObject.getClass().isArray()){
+ Object[] object = ( Object[] ) _oUnoObject;
+ for ( int i = 0; i < object.length; i++ ) {
+ Property aProperty = (Property) object[i];
+ XUnoPropertyNode oUnoPropertyNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aProperty);
+ oUnoPropertyNode.setLabel(XUnoFacetteNode.SPROPERTYINFODESCRIPTION + " (" + aProperty.Name + ")");
+ oUnoPropertyNode.setFoldable(true);
+ _oUnoFacetteNode.addChildNode(oUnoPropertyNode);
+ }
+ }
+ }
+
+ private void addPrimitiveValuesToTreeNode(XUnoNode _oUnoNode, Object _oUnoObject){
+ if (_oUnoObject.getClass().isArray()){
+ if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
+ Object[] object = ( Object[] ) _oUnoObject;
+ for ( int i = 0; i < object.length; i++ ) {
+ if (Introspector.isObjectPrimitive(object[i])){
+ addUnoNode(_oUnoNode, null, UnoNode.getNodeDescription(object[i]));
+ }
+ }
+ }
+ else{
+ String[] sDisplayValues = UnoNode.getDisplayValuesofPrimitiveArray(_oUnoObject);
+ for ( int i = 0; i < sDisplayValues.length; i++ ) {
+ addUnoNode(_oUnoNode, null, sDisplayValues[i]);
+ }
+ }
+ }
+ }
+
+
+ private void addPropertySetInfoSubNodes(XUnoPropertyNode _oUnoPropertyNode){
+ Property aProperty = _oUnoPropertyNode.getProperty();
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithName(aProperty));
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithType(aProperty));
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithHandle(aProperty));
+ _oUnoPropertyNode.addChildNode(m_xTreeControlProvider.addUnoPropertyNodeWithAttributesDescription(aProperty));
+ }
+
+
+ private void addPropertyValueSubNodes(XUnoFacetteNode _oUnoFacetteNode, Object _oUnoObject){
+ if (Introspector.isUnoPropertyValueTypeObject(_oUnoObject)){
+ Object[] object = ( Object[] ) _oUnoObject;
+ for ( int i = 0; i < object.length; i++ ) {
+ String sObjectClassName = object[i].getClass().getName();
+ if (sObjectClassName.equals("com.sun.star.beans.PropertyValue")){
+ XUnoNode oChildNode = null;
+ PropertyValue aPropertyValue = (PropertyValue) object[i];
+ if (! Introspector.isObjectPrimitive(aPropertyValue.Value)){
+ oChildNode = m_xTreeControlProvider.addUnoPropertyNode(_oUnoObject, aPropertyValue, _oUnoObject);
+ }
+ else{
+ oChildNode = addUnoNode(null, aPropertyValue.Value, UnoPropertyNode.getStandardPropertyValueDescription(aPropertyValue));
+ }
+ if (oChildNode != null){
+ _oUnoFacetteNode.addChildNode(oChildNode);
+ }
+ }
+ }
+ }
+ }
+
+
+ public boolean expandNode(XUnoNode _oUnoNode){
+ if ( _oUnoNode != null ) {
+ _oUnoNode.setFoldable(false);
+ if (m_xTreeControlProvider.isMethodNode(_oUnoNode)){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) _oUnoNode;
+ if (!oUnoMethodNode.isInvoked()){
+ Object oUnoReturnObject = invoke((XUnoMethodNode) _oUnoNode);
+ if (oUnoReturnObject == null){
+ _oUnoNode.setFoldable(true);
+ return false;
+ }
+ }
+ }
+ else if (m_xTreeControlProvider.isPropertyNode(_oUnoNode)){
+ XUnoPropertyNode oUnoPropertyNode = (XUnoPropertyNode) _oUnoNode;
+ Object oUnoObject = oUnoPropertyNode.getUnoReturnObject();
+ if (oUnoPropertyNode.getPropertyNodeType() == XUnoPropertyNode.nPROPERTYSETINFOTYPE){
+ addPropertySetInfoSubNodes(oUnoPropertyNode);
+ }
+ else{
+ //TODO: this code is redundant!!!
+ if ( oUnoObject.getClass().isArray()){
+ // TODO: probably we should provide a possibility to insert also non-primitive nodes
+ addPrimitiveValuesToTreeNode(oUnoPropertyNode, oUnoObject);
+ }
+ else{
+ addFacetteNodesToTreeNode(oUnoPropertyNode, oUnoObject);
+ }
+ }
+ }
+ else if (m_xTreeControlProvider.isFacetteNode(_oUnoNode)){
+ XUnoFacetteNode oUnoFacetteNode = (XUnoFacetteNode) _oUnoNode;
+ Object oUnoObject = _oUnoNode.getUnoObject();
+ if (oUnoFacetteNode.isMethodNode()){
+ addMethodsToTreeNode(oUnoFacetteNode, oUnoObject, m_oIntrospector.getMethods(oUnoObject));
+ }
+ if (oUnoFacetteNode.isPropertyNode()){
+ String sNodeDescription = oUnoFacetteNode.getLabel();
+ // TODO: it's very dangerous to distinguish the different UnoFacetteNodes only by the node description
+ if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
+ addPropertySetInfoNodesToTreeNode(oUnoFacetteNode, oUnoObject);
+ }
+ else if (sNodeDescription.startsWith(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
+ addPropertyValueSubNodes(oUnoFacetteNode, oUnoObject);
+ }
+ else{
+ addPropertiesToTreeNode(oUnoFacetteNode, oUnoObject, m_oIntrospector.getProperties(oUnoObject));
+ }
+ }
+ if (oUnoFacetteNode.isServiceNode()){
+ addServicesToTreeNode(oUnoFacetteNode, oUnoObject);
+ }
+ if (oUnoFacetteNode.isInterfaceNode()){
+ addInterfacesToTreeNode(oUnoFacetteNode, oUnoObject, getTypes(oUnoObject));
+ }
+ if (oUnoFacetteNode.isContainerNode()){
+ addContainerElementsToTreeNode(oUnoFacetteNode, oUnoObject);
+ }
+ }
+ else if (_oUnoNode.getNodeType() == XUnoNode.nSERVICE){
+ addPropertiesAndInterfacesOfService(_oUnoNode);
+ }
+ else if (_oUnoNode.getNodeType() == XUnoNode.nINTERFACE){
+ Type aType = _oUnoNode.getUnoType();
+ if (aType != null){
+ addMethodsToTreeNode(_oUnoNode, _oUnoNode.getUnoObject(), m_oIntrospector.getMethodsOfInterface(aType));
+ }
+ }
+ else if (_oUnoNode.getNodeType() == XUnoNode.nOTHERS){
+ Object oUnoObject = _oUnoNode.getUnoObject();
+ if ( oUnoObject.getClass().isArray()){
+ // TODO: probably we should provide a possibility to insert also non-primitive nodes
+ addPrimitiveValuesToTreeNode(_oUnoNode, oUnoObject);
+ }
+ else{
+ addFacetteNodesToTreeNode(_oUnoNode, oUnoObject);
+ }
+ }
+ }
+ return true;
+ }
+
+
+
+ public void applyFilter(XUnoFacetteNode _oUnoFacetteNode, String _sFilter){
+ for (int i = 0; i < _oUnoFacetteNode.getChildCount(); i++){
+ XUnoNode oUnoNode = _oUnoFacetteNode.getChild(i);
+ boolean bIsVisible = oUnoNode.isFilterApplicable(_sFilter);
+ m_xTreeControlProvider.setNodeVisible(oUnoNode, bIsVisible);
+ }
+ _oUnoFacetteNode.setFilter(_sFilter);
+ }
+
+
+ public String getFilter(XUnoNode _oUnoNode){
+ String sFilter = "";
+ if (_oUnoNode != null){
+ XUnoNode oUnoNode = _oUnoNode;
+ boolean bleaveLoop = false;
+ do{
+ if (m_xTreeControlProvider.isFacetteNode(oUnoNode)){
+ sFilter = ((XUnoFacetteNode) oUnoNode).getFilter();
+ bleaveLoop = true;
+ }
+ else{
+ if (oUnoNode.getParentNode() != null){
+ oUnoNode = oUnoNode.getParentNode();
+ }
+ else{
+ bleaveLoop = true;
+ }
+ }
+ } while(!bleaveLoop);
+ }
+ return sFilter;
+ }
+
+
+ public void showPopUpMenu(Object _invoker, int x, int y) throws ClassCastException{
+ XUnoNode oUnoNode = getSelectedNode();
+ boolean bdoEnableInvoke = oUnoNode instanceof XUnoMethodNode;
+ if (bdoEnableInvoke){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ bdoEnableInvoke = oUnoMethodNode.isInvokable();
+ }
+ m_xDialogProvider.enablePopupMenuItem(XDialogProvider.SINVOKE, bdoEnableInvoke);
+ m_xDialogProvider.showPopUpMenu(_invoker, x, y);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/InstanceInspectorTest.odt b/odk/examples/java/Inspector/InstanceInspectorTest.odt
new file mode 100644
index 000000000..74cde4e68
--- /dev/null
+++ b/odk/examples/java/Inspector/InstanceInspectorTest.odt
Binary files differ
diff --git a/odk/examples/java/Inspector/Introspector.java b/odk/examples/java/Inspector/Introspector.java
new file mode 100644
index 000000000..b8d3be3c0
--- /dev/null
+++ b/odk/examples/java/Inspector/Introspector.java
@@ -0,0 +1,643 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.sun.star.beans.IllegalTypeException;
+import com.sun.star.beans.MethodConcept;
+import com.sun.star.beans.Property;
+import com.sun.star.beans.XIntrospection;
+import com.sun.star.beans.XIntrospectionAccess;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XEnumerationAccess;
+import com.sun.star.container.XHierarchicalNameAccess;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.lang.XTypeProvider;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.reflection.TypeDescriptionSearchDepth;
+import com.sun.star.reflection.XConstantTypeDescription;
+import com.sun.star.reflection.XConstantsTypeDescription;
+import com.sun.star.reflection.XIdlClass;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.reflection.XIdlReflection;
+import com.sun.star.reflection.XIndirectTypeDescription;
+import com.sun.star.reflection.XInterfaceTypeDescription;
+import com.sun.star.reflection.XPropertyTypeDescription;
+import com.sun.star.reflection.XServiceTypeDescription;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.reflection.XTypeDescriptionEnumeration;
+import com.sun.star.reflection.XTypeDescriptionEnumerationAccess;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+
+public class Introspector extends WeakBase{
+
+ private XIntrospection m_xIntrospection;
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+ private XTypeDescriptionEnumerationAccess m_xTDEnumerationAccess;
+ private XIdlReflection mxIdlReflection;
+ private static Introspector m_oIntrospector = null;
+ private XSimpleFileAccess xSimpleFileAccess = null;
+
+
+
+ public static Introspector getIntrospector(){
+ if (m_oIntrospector == null){
+ throw new NullPointerException();
+ }
+ else{
+ return m_oIntrospector;
+ }
+ }
+
+ public static Introspector getIntrospector(XComponentContext _xComponentContext){
+ if (m_oIntrospector == null){
+ m_oIntrospector = new Introspector(_xComponentContext);
+ }
+ return m_oIntrospector;
+ }
+
+
+ /** Creates a new instance of Introspection */
+ private Introspector(XComponentContext _xComponentContext) {
+ try{
+ m_xComponentContext = _xComponentContext;
+ m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
+ Object o = m_xMultiComponentFactory.createInstanceWithContext("com.sun.star.beans.Introspection", m_xComponentContext);
+ m_xIntrospection = UnoRuntime.queryInterface(XIntrospection.class, o );
+ Object oCoreReflection = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.reflection.CoreReflection", getXComponentContext());
+ mxIdlReflection = UnoRuntime.queryInterface(XIdlReflection.class, oCoreReflection);
+ initTypeDescriptionManager();
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }}
+
+
+ protected XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ private XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+
+ protected XIntrospectionAccess getXIntrospectionAccess(Object _oUnoComponent){
+ return m_xIntrospection.inspect(_oUnoComponent);
+ }
+
+
+ public boolean isContainer(Object _oUnoObject){
+ boolean bIsContainer = false;
+ try {
+ XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoObject);
+ if (xIntrospectionAccessObject != null){
+ XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
+ if (xEnumerationAccess != null){
+ XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
+ bIsContainer = xEnumeration.hasMoreElements();
+ }
+ if (!bIsContainer){
+ XIndexAccess xIndexAccess = UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
+ if (xIndexAccess != null){
+ bIsContainer = (xIndexAccess.getCount() > 0);
+ }
+ }
+ }
+ } catch (IllegalTypeException ex) {
+ ex.printStackTrace(System.err);
+ }
+ return bIsContainer;
+ }
+
+
+ // add all containers for the given object to the tree under the node
+ // parent
+ public Object[] getUnoObjectsOfContainer(Object _oUnoParentObject) {
+ Object[] oRetComponents = null;
+ try {
+ ArrayList<Object> oRetComponentsVector = new ArrayList<Object>();
+ XIntrospectionAccess xIntrospectionAccessObject = getXIntrospectionAccess(_oUnoParentObject);
+ if ( xIntrospectionAccessObject != null ) {
+ XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface(XEnumerationAccess.class, xIntrospectionAccessObject.queryAdapter( new Type( XEnumerationAccess.class ) ) );
+ if ( xEnumerationAccess != null ) {
+ XEnumeration xEnumeration = xEnumerationAccess.createEnumeration();
+ while ( xEnumeration.hasMoreElements() ) {
+ oRetComponentsVector.add(xEnumeration.nextElement());
+ }
+ }
+ XIndexAccess xIndexAccess = UnoRuntime.queryInterface( XIndexAccess.class, xIntrospectionAccessObject.queryAdapter(new Type( XIndexAccess.class )));
+ if ( xIndexAccess != null ) {
+ XIdlMethod mMethod = xIntrospectionAccessObject.getMethod("getByIndex", com.sun.star.beans.MethodConcept.INDEXCONTAINER);
+ for ( int i = 0; i < xIndexAccess.getCount(); i++ ) {
+ Object[][] aParamInfo = new Object[1][1];
+ aParamInfo[0] = new Integer[] { Integer.valueOf(i) };
+ oRetComponentsVector.add(mMethod.invoke(_oUnoParentObject, aParamInfo));
+ }
+ }
+ }
+ if (oRetComponentsVector != null){
+ oRetComponents = new Object[oRetComponentsVector.size()];
+ oRetComponentsVector.toArray(oRetComponents);
+ }
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ }
+ return oRetComponents;
+ }
+
+
+ protected XIdlMethod[] getMethodsOfInterface(Type _aType){
+ try{
+ XIdlClass xIdlClass = mxIdlReflection.forName(_aType.getTypeName());
+ return xIdlClass.getMethods();
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ return null;
+ }}
+
+
+
+
+
+ public boolean hasMethods(Object _oUnoObject){
+ boolean bHasMethods = (getMethods(_oUnoObject).length > 0);
+ return bHasMethods;
+ }
+
+
+ // add all methods for the given object to the tree under the node parent
+ public XIdlMethod[] getMethods(Object _oUnoParentObject) {
+ try {
+ XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
+ if (xIntrospectionAccess != null){
+ XIdlMethod[] xIdlMethods = xIntrospectionAccess.getMethods(MethodConcept.ALL - MethodConcept.DANGEROUS);
+ return xIdlMethods;
+ }
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ }
+ return null;
+ }
+
+
+ public boolean hasProperties(Object _oUnoObject){
+ boolean bHasProperties = (getProperties(_oUnoObject).length > 0);
+ return bHasProperties;
+ }
+
+
+ protected Property[] getProperties( Object _oUnoParentObject){
+ try {
+ XIntrospectionAccess xIntrospectionAccess = getXIntrospectionAccess(_oUnoParentObject);
+ if (xIntrospectionAccess != null){
+ Property[] aProperties = xIntrospectionAccess.getProperties(com.sun.star.beans.PropertyConcept.ATTRIBUTES + com.sun.star.beans.PropertyConcept.PROPERTYSET);
+ return aProperties;
+ }
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ }
+ return null;
+ }
+
+
+ protected Property[] getProperties(Object _oUnoObject, String _sServiceName){
+ Property[] aProperties = getProperties(_oUnoObject);
+ List<Property> aListOfProperties = java.util.Arrays.asList(aProperties);
+ ArrayList<Property> aPropertiesVector = new ArrayList<Property>(aListOfProperties);
+ if (aProperties != null){
+ XPropertyTypeDescription[] xPropertyTypeDescriptions = getPropertyDescriptionsOfService(_sServiceName);
+ for (int i = aProperties.length - 1; i >= 0; i--){
+ if (!hasByName(xPropertyTypeDescriptions, _sServiceName + "." + aProperties[i].Name)){
+ aPropertiesVector.remove(i);
+ }
+ }
+ }
+ Property[] aRetProperties = new Property[aPropertiesVector.size()];
+ aPropertiesVector.toArray(aRetProperties);
+ return aRetProperties;
+ }
+
+
+ protected Type[] getInterfaces(Object _oUnoObject, String _sServiceName){
+ Type[] aTypes = getInterfaces(_oUnoObject);
+ List<Type> aListOfTypes = java.util.Arrays.asList(aTypes);
+ ArrayList<Type> aTypesVector = new ArrayList<Type>(aListOfTypes);
+ if (aTypes != null){
+ XInterfaceTypeDescription[] xInterfaceTypeDescriptions = getInterfaceDescriptionsOfService(_sServiceName);
+ for (int i = aTypes.length - 1; i >= 0; i--){
+ if (!hasByName(xInterfaceTypeDescriptions, aTypes[i].getTypeName())){
+ aTypesVector.remove(i);
+ }
+ }
+ }
+ Type[] aRetTypes = new Type[aTypesVector.size()];
+ aTypesVector.toArray(aRetTypes);
+ return aRetTypes;
+ }
+
+
+ public boolean hasInterfaces(Object _oUnoObject){
+ return (getInterfaces(_oUnoObject).length > 0);
+ }
+
+
+ protected Type[] getInterfaces(Object _oUnoParentObject){
+ Type[] aTypes = new Type[]{};
+ XTypeProvider xTypeProvider = UnoRuntime.queryInterface( XTypeProvider.class, _oUnoParentObject);
+ if ( xTypeProvider != null ) {
+ aTypes = xTypeProvider.getTypes();
+ }
+ return aTypes;
+ }
+
+
+
+ public static boolean isObjectSequence(Object _oUnoObject){
+ Type aType = AnyConverter.getType(_oUnoObject);
+ return aType.getTypeClass().getValue() == TypeClass.SEQUENCE_value;
+ }
+
+
+ public static boolean isObjectPrimitive(Object _oUnoObject){
+ boolean breturn = false;
+ if (_oUnoObject != null){
+ Type aType = AnyConverter.getType(_oUnoObject);
+ breturn = isObjectPrimitive(_oUnoObject.getClass(), aType.getTypeClass());
+ }
+ return breturn;
+ }
+
+
+ public static boolean isPrimitive(TypeClass _typeClass){
+ return (( _typeClass == TypeClass.BOOLEAN )
+ || ( _typeClass == TypeClass.BYTE )
+ || ( _typeClass == TypeClass.CHAR )
+ || ( _typeClass == TypeClass.DOUBLE )
+ || ( _typeClass == TypeClass.ENUM )
+ || ( _typeClass == TypeClass.FLOAT )
+ || ( _typeClass == TypeClass.HYPER )
+ || ( _typeClass == TypeClass.LONG )
+ || ( _typeClass == TypeClass.SHORT )
+ || ( _typeClass == TypeClass.STRING )
+ || ( _typeClass == TypeClass.UNSIGNED_HYPER )
+ || ( _typeClass == TypeClass.UNSIGNED_LONG )
+ || ( _typeClass == TypeClass.UNSIGNED_SHORT ));
+ }
+
+ public static boolean isObjectPrimitive(Class<? extends Object> _oUnoClass, TypeClass _typeClass){
+ return !( ( !_oUnoClass.isPrimitive() ) && ( _typeClass != TypeClass.ARRAY )
+ && ( _typeClass != TypeClass.BOOLEAN )
+ && ( _typeClass != TypeClass.BYTE )
+ && ( _typeClass != TypeClass.CHAR )
+ && ( _typeClass != TypeClass.DOUBLE )
+ && ( _typeClass != TypeClass.ENUM )
+ && ( _typeClass != TypeClass.FLOAT )
+ && ( _typeClass != TypeClass.HYPER )
+ && ( _typeClass != TypeClass.LONG )
+ && ( _typeClass != TypeClass.SHORT )
+ && ( _typeClass != TypeClass.STRING )
+ && ( _typeClass != TypeClass.UNSIGNED_HYPER )
+ && ( _typeClass != TypeClass.UNSIGNED_LONG )
+ && ( _typeClass != TypeClass.UNSIGNED_SHORT ));
+ }
+
+
+ private void initTypeDescriptionManager() {
+ try {
+ Object oTypeDescriptionManager = getXComponentContext().getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager");
+ m_xTDEnumerationAccess = UnoRuntime.queryInterface(XTypeDescriptionEnumerationAccess.class, oTypeDescriptionManager);
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }}
+
+
+ private XTypeDescriptionEnumerationAccess getXTypeDescriptionEnumerationAccess(){
+ return m_xTDEnumerationAccess;
+ }
+
+
+ protected XConstantTypeDescription[] getFieldsOfConstantGroup(String _sTypeClass){
+ XConstantTypeDescription[] xConstantTypeDescriptions = null;
+ try {
+ TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[1];
+ eTypeClasses[0] = com.sun.star.uno.TypeClass.CONSTANTS;
+ XTypeDescriptionEnumeration xTDEnumeration = m_xTDEnumerationAccess.createTypeDescriptionEnumeration(getModuleName(_sTypeClass), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
+ while (xTDEnumeration.hasMoreElements()) {
+ XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
+ if (xTD.getName().equals(_sTypeClass)){
+ XConstantsTypeDescription xConstantsTypeDescription = UnoRuntime.queryInterface(XConstantsTypeDescription.class, xTD);
+ xConstantTypeDescriptions = xConstantsTypeDescription.getConstants();
+ }
+ String sName = xTD.getName();
+ }
+ return xConstantTypeDescriptions;
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return null;
+ }
+
+ private XServiceTypeDescription getServiceTypeDescription(String _sServiceName, TypeClass _eTypeClass){
+ try{
+ if (_sServiceName.length() > 0){
+ TypeClass[] eTypeClasses = new com.sun.star.uno.TypeClass[2];
+ eTypeClasses[0] = com.sun.star.uno.TypeClass.SERVICE;
+ eTypeClasses[1] = _eTypeClass;
+ XTypeDescriptionEnumeration xTDEnumeration = getXTypeDescriptionEnumerationAccess().createTypeDescriptionEnumeration(Introspector.getModuleName(_sServiceName), eTypeClasses, TypeDescriptionSearchDepth.INFINITE);
+ while (xTDEnumeration.hasMoreElements()) {
+ XTypeDescription xTD = xTDEnumeration.nextTypeDescription();
+ if (xTD.getName().equals(_sServiceName)){
+ XServiceTypeDescription xServiceTypeDescription = UnoRuntime.queryInterface(XServiceTypeDescription.class, xTD);
+ return xServiceTypeDescription;
+ }
+ }
+ }
+ return null;
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ public XPropertyTypeDescription[] getPropertyDescriptionsOfService(String _sServiceName){
+ try {
+ XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.PROPERTY);
+ if (xServiceTypeDescription != null){
+ XPropertyTypeDescription[] xPropertyTypeDescriptions = xServiceTypeDescription.getProperties();
+ return xPropertyTypeDescriptions;
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return new XPropertyTypeDescription[]{};
+ }
+
+
+ public XTypeDescription getReferencedType(String _sTypeName){
+ XTypeDescription xTypeDescription = null;
+ try{
+ XHierarchicalNameAccess xHierarchicalNameAccess = UnoRuntime.queryInterface(XHierarchicalNameAccess.class, m_xTDEnumerationAccess);
+ if (xHierarchicalNameAccess != null){
+ if (xHierarchicalNameAccess.hasByHierarchicalName(_sTypeName)){
+ XIndirectTypeDescription xIndirectTypeDescription = UnoRuntime.queryInterface(XIndirectTypeDescription.class, xHierarchicalNameAccess.getByHierarchicalName(_sTypeName));
+ if (xIndirectTypeDescription != null){
+ xTypeDescription = xIndirectTypeDescription.getReferencedType();
+ }
+ }
+ }
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ }
+ return xTypeDescription;
+ }
+
+
+ private XInterfaceTypeDescription[] getInterfaceDescriptionsOfService(String _sServiceName){
+ try {
+ XServiceTypeDescription xServiceTypeDescription = getServiceTypeDescription(_sServiceName, com.sun.star.uno.TypeClass.INTERFACE);
+ if (xServiceTypeDescription != null){
+ XInterfaceTypeDescription[] xInterfaceTypeDescriptions = xServiceTypeDescription.getMandatoryInterfaces();
+ return xInterfaceTypeDescriptions;
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return new XInterfaceTypeDescription[]{};
+ }
+
+
+ private static boolean hasByName(XTypeDescription[] _xTypeDescriptions, String _sTypeName){
+ for (int i = 0; i < _xTypeDescriptions.length; i++){
+ if (_xTypeDescriptions[i].getName().equals(_sTypeName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public static String getModuleName(String _sTypeClass){
+ int nlastindex = _sTypeClass.lastIndexOf(".");
+ if (nlastindex > -1){
+ return _sTypeClass.substring(0, nlastindex);
+ }
+ else{
+ return "";
+ }
+ }
+
+
+ public static String getShortClassName(String _sClassName){
+ String sShortClassName = _sClassName;
+ int nindex = _sClassName.lastIndexOf(".");
+ if ((nindex < _sClassName.length()) && nindex > -1){
+ sShortClassName = _sClassName.substring(nindex + 1);
+ }
+ return sShortClassName;
+ }
+
+
+
+ public static boolean isUnoTypeObject(Object _oUnoObject){
+ return isOfUnoType(_oUnoObject, "com.sun.star.uno.Type");
+ }
+
+
+ public static boolean isUnoPropertyTypeObject(Object _oUnoObject){
+ return isOfUnoType(_oUnoObject, "com.sun.star.beans.Property");
+ }
+
+
+ public static boolean isUnoPropertyValueTypeObject(Object _oUnoObject){
+ return isOfUnoType(_oUnoObject, "com.sun.star.beans.PropertyValue");
+ }
+
+
+ private static boolean isOfUnoType(Object _oUnoObject, String _sTypeName){
+ boolean bIsUnoObject = false;
+ if (_oUnoObject != null){
+ if (_oUnoObject.getClass().isArray()){
+ if (!_oUnoObject.getClass().getComponentType().isPrimitive()){
+ Object[] oUnoArray = (Object[]) _oUnoObject;
+ if (oUnoArray.length > 0){
+ bIsUnoObject = ( oUnoArray[0].getClass().getName().equals(_sTypeName));
+ }
+ }
+ }
+ }
+ else{
+ bIsUnoObject = (_oUnoObject.getClass().getName().equals(_sTypeName));
+ }
+ return bIsUnoObject;
+ }
+
+
+ public String getConstantDisplayString(int _nValue, XConstantTypeDescription[] _xConstantTypeDescription, String _sDisplayString){
+ String sPrefix = "";
+ int[] nbits = new int[_xConstantTypeDescription.length];
+ for (int i = 0; i < _xConstantTypeDescription.length; i++){
+ short nConstantValue = ((Short) _xConstantTypeDescription[i].getConstantValue()).shortValue();
+ nbits[i] = _nValue & nConstantValue;
+ if (nbits[i] > 0){
+ _sDisplayString += sPrefix + _xConstantTypeDescription[i].getName();
+ sPrefix = " + ";
+ }
+ }
+ return _sDisplayString;
+ }
+
+
+ public static boolean isValid(Object[] _oObject){
+ if (_oObject != null){
+ if (_oObject.length > 0){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+
+
+
+ public static boolean isArray(Object _oObject){
+ return _oObject.getClass().isArray();
+ }
+
+
+ public boolean hasSupportedServices(Object _oUnoObject){
+ boolean bHasSupportedServices = false;
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject);
+ if ( xServiceInfo != null ){
+ String[] sSupportedServiceNames = xServiceInfo.getSupportedServiceNames();
+ bHasSupportedServices = sSupportedServiceNames.length > 0;
+ }
+ return bHasSupportedServices;
+ }
+
+
+ public Object getValueOfText(TypeClass aTypeClass, String sText){
+ Object oReturn = null;
+ switch (aTypeClass.getValue()){
+ case TypeClass.CHAR_value:
+ break;
+ case TypeClass.DOUBLE_value:
+ oReturn = Double.valueOf(sText);
+ break;
+ case TypeClass.ENUM_value:
+ break;
+ case TypeClass.FLOAT_value:
+ oReturn = Float.valueOf(sText);
+ break;
+ case TypeClass.HYPER_value:
+ oReturn = Long.valueOf(sText);
+ break;
+ case TypeClass.LONG_value:
+ oReturn = Integer.valueOf(sText);
+ break;
+ case TypeClass.SHORT_value:
+ oReturn = Byte.valueOf(sText);
+ break;
+ case TypeClass.STRING_value:
+ oReturn = sText;
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ oReturn = Long.valueOf(sText);
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ oReturn = Integer.valueOf(sText);
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ oReturn = Byte.valueOf(sText);
+ break;
+ default:
+ }
+ return oReturn;
+ }
+
+
+ public XSimpleFileAccess getXSimpleFileAccess(){
+ try {
+ if (xSimpleFileAccess == null){
+ Object oSimpleFileAccess = m_xComponentContext.getServiceManager().createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_xComponentContext);
+ xSimpleFileAccess = com.sun.star.uno.UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
+ }
+ return xSimpleFileAccess;
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ public boolean isValidSDKInstallationPath(String _sSDKInstallationPath){
+ boolean bIsValid = false;
+ try {
+ String sIDLFolder = Introspector.addToPath(_sSDKInstallationPath, Inspector.sIDLDOCUMENTSUBFOLDER);
+ String sIndexFile = Introspector.addToPath(_sSDKInstallationPath, "index.html");
+ if (getXSimpleFileAccess() != null){
+ bIsValid = (getXSimpleFileAccess().exists(sIDLFolder) && getXSimpleFileAccess().exists(sIndexFile));
+ }
+ } catch (com.sun.star.uno.Exception ex) {
+ ex.printStackTrace(System.err);
+ }
+ return bIsValid;
+ }
+
+
+ public static String addToPath(String _sPath, String _sSubPath){
+ if (!_sPath.endsWith("/")){
+ _sPath += "/";
+ }
+ return _sPath + _sSubPath;
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/Makefile b/odk/examples/java/Inspector/Makefile
new file mode 100644
index 000000000..b7c611be0
--- /dev/null
+++ b/odk/examples/java/Inspector/Makefile
@@ -0,0 +1,186 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the Java InstanceInspector component example of the SDK.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+
+# Define non-platform/compiler specific settings
+
+# we use the sample directory name for separating this example
+# from others in the output directory
+SAMPLE_NAME=InstanceInspector
+SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME)
+SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
+
+# some special macro names for separating the component jar stuff
+COMP_NAME=Inspector
+COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
+COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME)
+COMP_RDB_NAME=$(COMP_NAME).uno.rdb
+COMP_RDB=$(COMP_GEN_OUT)/$(COMP_RDB_NAME)
+COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
+COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
+COMP_JAR_NAME=$(COMP_NAME).uno.jar
+COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
+COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).uno.Manifest
+COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
+COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
+
+IDLFILES = InstanceInspector.idl \
+ XInstanceInspector.idl
+
+PACKAGE = org/openoffice
+
+COMP_JAVAFILES = XDialogProvider.java XTreeControlProvider.java XTreePathProvider.java MethodParametersDialog.java HideableMutableTreeNode.java HideableTreeModel.java Introspector.java XUnoNode.java SwingUnoNode.java UnoNode.java XUnoMethodNode.java SwingUnoMethodNode.java UnoMethodNode.java XUnoPropertyNode.java SwingUnoPropertyNode.java UnoPropertyNode.java XUnoFacetteNode.java SwingUnoFacetteNode.java TDocSupplier.java UnoTreeRenderer.java InspectorAddon.java XLanguageSourceCodeGenerator.java SourceCodeGenerator.java InspectorPane.java SwingDialogProvider.java SwingTreeControlProvider.java SwingTreePathProvider.java Inspector.java
+COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
+
+GEN_CLASSFILES = $(patsubst %.idl,$(SAMPLE_CLASS_OUT)/$(PACKAGE)/%.class,$(IDLFILES))
+GEN_TYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
+
+# the generated types are necessary for the component jar
+GEN_CLASSFILENAMES = $(subst $(SAMPLE_CLASS_OUT)/,,$(GEN_CLASSFILES))
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\
+ $(PATH_SEPARATOR)$(COMP_CLASS_OUT))
+
+COMP_IMAGE_FILES= images/containers_16.png \
+ images/content_16.png \
+ images/interfaces_16.png \
+ images/methods_16.png \
+ images/properties_16.png \
+ images/services_16.png
+
+# Targets
+.PHONY: ALL
+ALL : JavaInspectorExample
+
+include $(SETTINGS)/stdtarget.mk
+
+# rule for component manifest file
+$(COMP_GEN_OUT)/%.Manifest :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo RegistrationClassName: $(basename $(basename $(@F)))> $@
+
+# rule for creating the component rdb file
+$(COMP_GEN_OUT)/%.rdb : $(patsubst %,$(PACKAGE)/%,$(IDLFILES))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(UNOIDLWRITE) $(URE_TYPES) $(OFFICE_TYPES) . $@
+
+# rule for creating IDL dependent class files
+$(GEN_CLASSFILES) : $(COMP_RDB)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(JAVAMAKER) -nD $(GEN_TYPELIST) -O$(SAMPLE_CLASS_OUT) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
+
+# component as well as application are dependent from the generated types
+# rule for component class files
+$(COMP_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -sourcepath . -d $(COMP_CLASS_OUT) $<
+
+# rule for component jar file
+$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES) $(COMP_IMAGE_FILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) .
+ +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES)
+ +$(SDK_JAR) uvf $@ $(COMP_IMAGE_FILES)
+
+# rule for component package manifest
+$(COMP_GEN_OUT)/%/manifest.xml :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
+ @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
+ @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)Addons.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)ProtocolHandler.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-schema$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)ObjectInspector.xcs$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)ObjectInspector.xcu$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
+ @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=Java$(QM)" >> $@
+ @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.jar$(QM)"/$(CSEP) >> $@
+ @echo $(OSEP)/manifest:manifest$(CSEP) >> $@
+
+# rule for component package file
+$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) Addons.xcu ProtocolHandler.xcu ObjectInspector.xcu ObjectInspector.xcs description.xml $(COMP_UNOPKG_MANIFEST)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) ../../../bin/$(@F) $(COMP_RDB_NAME)
+
+ cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_JAR_NAME)
+ $(SDK_ZIP) -u $@ Addons.xcu ProtocolHandler.xcu ObjectInspector.xcu ObjectInspector.xcs description.xml
+ cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
+
+$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
+ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(DEPLOYTOOL) $(COMP_PACKAGE_URL)
+ @echo flagged > $(subst /,$(PS),$@)
+else
+ @echo --------------------------------------------------------------------------------
+ @echo If you want to install your component automatically, please set the environment
+ @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
+ @echo possible if no office instance is running.
+ @echo --------------------------------------------------------------------------------
+endif
+
+JavaInspectorExample : $(COMP_REGISTERFLAG)
+ @echo --------------------------------------------------------------------------------
+ @echo The InstanceInspector component was installed if SDK_AUTO_DEPLOYMENT = YES.
+ @echo You can use this component inside your office installation, see the example
+ @echo document.
+ @echo -
+ @echo $(MAKE) InstanceInspectorTest.odt.load
+ @echo --------------------------------------------------------------------------------
+
+InstanceInspectorTest.odt.load : $(COMP_REGISTERFLAG)
+ "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
diff --git a/odk/examples/java/Inspector/MethodParametersDialog.java b/odk/examples/java/Inspector/MethodParametersDialog.java
new file mode 100644
index 000000000..216ef87f3
--- /dev/null
+++ b/odk/examples/java/Inspector/MethodParametersDialog.java
@@ -0,0 +1,351 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import com.sun.star.reflection.ParamInfo;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+public class MethodParametersDialog extends JDialog{
+ private javax.swing.JPanel jPnlParamContainer;
+ private ParameterPanel[] m_aParameterPanels;
+ private ParamInfo[] m_aParamInfo;
+ private XIdlMethod m_xIdlMethod;
+ private ActionListener oActionListener;
+ private JButton jHelpButton = new JButton("Help");
+ private JButton jOKButton = new JButton("Ok");
+ private JButton jInvokeButton = new JButton("Invoke");
+ private Object m_oUnoObject = null;
+ private Object m_oUnoReturnObject = null;
+ private JLabel jLblResult;
+ private JPanel jResultPanel = null;
+ private boolean bisdisposed = false;
+ private XUnoMethodNode m_xUnoMethodNode;
+
+
+ public MethodParametersDialog(XUnoMethodNode _xUnoMethodNode){
+ m_xUnoMethodNode = _xUnoMethodNode;
+ m_xIdlMethod = _xUnoMethodNode.getXIdlMethod();
+ m_aParamInfo = m_xIdlMethod.getParameterInfos();
+ m_oUnoObject = m_xUnoMethodNode.getUnoObject();
+ }
+
+
+ public ArrayList<Object> getMethodObjects() {
+ super.setModal(true);
+ addBorderPanel(getContentPane(), BorderLayout.NORTH);
+ addBorderPanel(getContentPane(), BorderLayout.WEST);
+ addBorderPanel(getContentPane(), BorderLayout.EAST);
+ jPnlParamContainer = new JPanel();
+ jPnlParamContainer.setLayout(new javax.swing.BoxLayout(jPnlParamContainer, javax.swing.BoxLayout.Y_AXIS));
+ JPanel jHeaderPanel = new JPanel(new BorderLayout());
+ JLabel jLblHeader = new JLabel();
+ jLblHeader.setText("Please insert the values for the given Parameters of the method '" + m_xIdlMethod.getName() + "'");
+ jHeaderPanel.add(jLblHeader,BorderLayout.WEST);
+ jPnlParamContainer.add(jHeaderPanel);
+
+ m_aParameterPanels = new ParameterPanel[m_aParamInfo.length];
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ m_aParameterPanels[i] = new ParameterPanel(m_aParamInfo[i]);
+ jPnlParamContainer.add(m_aParameterPanels[i]);
+ }
+ jPnlParamContainer.add(new ButtonPanel(), java.awt.BorderLayout.SOUTH);
+ getContentPane().add(jPnlParamContainer, java.awt.BorderLayout.CENTER);
+ pack();
+ setLocation(350, 350);
+ setTitle("Object Inspector - Parameter Values of '" + m_xIdlMethod.getName() + "'");
+ super.setFocusable(true);
+ super.setFocusableWindowState(true);
+ super.requestFocus();
+ m_aParameterPanels[0].getInputComponent().requestFocusInWindow();
+ setVisible(true);
+ if (!bisdisposed){
+ ArrayList<Object> aMethodObjects = new ArrayList<Object>();
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ aMethodObjects.add(m_aParameterPanels[i].getValue());
+ }
+ aMethodObjects.add(m_oUnoReturnObject);
+ return aMethodObjects;
+ }
+ else{
+ return null;
+ }
+ }
+
+
+ private void insertResultPanel(Exception _oInvocationException){
+ boolean bAddPanel = false;
+ if (jResultPanel == null){
+ jResultPanel = new JPanel(new BorderLayout());
+ bAddPanel = true;
+ }
+ else{
+ jResultPanel.removeAll();
+ }
+ jLblResult = new JLabel();
+ jLblResult.setMaximumSize(new java.awt.Dimension(getSize().width - 20, 57));
+ if (_oInvocationException != null){
+ jLblResult.setText("<html>Invoking the method cause an exception: <br>" + _oInvocationException.toString() + "</html>");
+ }
+ else{
+ jLblResult.setText("<html>The invocation of the method did not produce any error</html>");
+ }
+ jResultPanel.add(jLblResult,BorderLayout.WEST);
+ if (bAddPanel){
+ int nPos = jPnlParamContainer.getComponentCount() - 1;
+ jPnlParamContainer.add(jResultPanel, nPos);
+ }
+ super.pack();
+ super.validate();
+ }
+
+
+ private Object[] getParameterValues(){
+ Object[] oParameterValues = new Object[m_aParameterPanels.length];
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ oParameterValues[i] = m_aParameterPanels[i].getValue();
+ }
+ return oParameterValues;
+ }
+
+
+ private boolean isCompleted(){
+ boolean bIsCompleted = true;
+ for (int i = 0; i < m_aParameterPanels.length; i++){
+ bIsCompleted = m_aParameterPanels[i].isCompleted();
+ if (!bIsCompleted){
+ break;
+ }
+ }
+ return bIsCompleted;
+ }
+
+
+ private void addBorderPanel(java.awt.Container _jContainer, String _sLayout){
+ JPanel jPnlBorder = new JPanel();
+ jPnlBorder.setPreferredSize(new java.awt.Dimension(10, 10));
+ _jContainer.add(jPnlBorder, _sLayout);
+ }
+
+ private void addGapPanel(java.awt.Container _jContainer){
+ JPanel jPnlBorder = new JPanel();
+ jPnlBorder.setPreferredSize(new java.awt.Dimension(10, 10));
+ jPnlBorder.setMaximumSize(new java.awt.Dimension(10, 10));
+ _jContainer.add(jPnlBorder);
+ }
+
+
+ private class ParameterPanel extends JPanel{
+ private JComponent m_jComponent;
+ private TypeClass m_aTypeClass = null;
+
+ public ParameterPanel(ParamInfo _aParamInfo){
+ JTextField jTextField = new JTextField();
+ JComboBox jComboBox = new JComboBox();
+ m_aTypeClass = _aParamInfo.aType.getTypeClass();
+ setLayout(new java.awt.BorderLayout());
+ addBorderPanel(this, BorderLayout.NORTH);
+ addBorderPanel(this, BorderLayout.SOUTH);
+ JPanel jPnlCenter1 = new javax.swing.JPanel();
+ jPnlCenter1.setLayout(new javax.swing.BoxLayout(jPnlCenter1, javax.swing.BoxLayout.X_AXIS));
+ JLabel jLabel1 = new JLabel();
+ jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
+ String sParamText = _aParamInfo.aName + " (" + _aParamInfo.aType.getName() +")";
+ jLabel1.setText(sParamText);
+ jPnlCenter1.add(jLabel1);
+ addGapPanel(jPnlCenter1);
+ switch (m_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ jComboBox.setBackground(new java.awt.Color(255, 255, 255));
+ jComboBox.setPreferredSize(new java.awt.Dimension(50, 19));
+ jComboBox.addItem("True");
+ jComboBox.addItem("False");
+ jComboBox.addKeyListener(new UpdateUIAdapter());
+ jPnlCenter1.add(jComboBox);
+ m_jComponent = jComboBox;
+ break;
+ case TypeClass.BYTE_value:
+ case TypeClass.CHAR_value:
+ case TypeClass.DOUBLE_value:
+ case TypeClass.ENUM_value:
+ case TypeClass.FLOAT_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.LONG_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.STRING_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ jTextField.setPreferredSize(new java.awt.Dimension(50, 19));
+ jTextField.addKeyListener(new UpdateUIAdapter());
+ jPnlCenter1.add(jTextField);
+ m_jComponent = jTextField;
+ break;
+ default:
+ System.out.println("Type " + m_aTypeClass.getValue() + " not yet defined in 'ParameterPanel()'");
+ }
+ add(jPnlCenter1, java.awt.BorderLayout.CENTER);
+ JPanel jPnlEast = new JPanel();
+ add(jPnlEast, BorderLayout.EAST);
+ }
+
+ private JComponent getInputComponent(){
+ return m_jComponent;
+ }
+
+ public Object getValue(){
+ Object oReturn = null;
+ if (m_jComponent instanceof JTextField){
+ String sText = ((JTextField) m_jComponent).getText();
+ oReturn = Introspector.getIntrospector().getValueOfText(m_aTypeClass, sText);
+ }
+ else{
+ JComboBox jComboBox = ((JComboBox) m_jComponent);
+ oReturn = Boolean.valueOf(jComboBox.getSelectedIndex() == 0);
+ }
+ return oReturn;
+ }
+
+
+ public boolean isCompleted(){
+ if (m_jComponent instanceof JTextField){
+ return !((JTextField) m_jComponent).getText().equals("");
+ }
+ else{
+ return true;
+ }
+ }
+ }
+
+
+ private class UpdateUIAdapter extends KeyAdapter{
+ @Override
+ public void keyReleased(KeyEvent e){
+ boolean bIsCompleted = isCompleted();
+ jOKButton.setEnabled(bIsCompleted);
+ jInvokeButton.setEnabled(bIsCompleted);
+ if (jLblResult != null){
+ jLblResult.setEnabled(false);
+ jLblResult.invalidate();
+ }
+ }
+ }
+
+
+
+ private class ButtonPanel extends JPanel{
+ public ButtonPanel(){
+ super();
+ setLayout(new BorderLayout());
+ addBorderPanel(this, BorderLayout.NORTH);
+ addBorderPanel(this, BorderLayout.SOUTH);
+ JPanel jPnlBottomCenter = new JPanel();
+ jPnlBottomCenter.setLayout(new javax.swing.BoxLayout(jPnlBottomCenter, javax.swing.BoxLayout.X_AXIS));
+ jHelpButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ oActionListener.actionPerformed(e);
+ }
+ });
+ jHelpButton.setEnabled(oActionListener != null);
+ jPnlBottomCenter.add(jHelpButton);
+ addGapPanel(jPnlBottomCenter);
+ jOKButton.setEnabled(false);
+ jOKButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ invokeParameterMethod();
+ dispose();
+ }
+ });
+ jOKButton.setEnabled(isCompleted());
+ jInvokeButton.setEnabled(isCompleted());
+ jInvokeButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ invokeParameterMethod();
+ }
+ });
+
+ jPnlBottomCenter.add(jOKButton);
+ addGapPanel(jPnlBottomCenter);
+ jPnlBottomCenter.add(jInvokeButton);
+ addGapPanel(jPnlBottomCenter);
+ JButton jCancelButton = new JButton("Cancel");
+ jCancelButton.setFocusCycleRoot(true);
+ jCancelButton.setFocusPainted(true);
+ jCancelButton.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ bisdisposed = true;
+ dispose();
+ }
+ });
+
+ jPnlBottomCenter.add(jCancelButton);
+ add(jPnlBottomCenter);
+ }
+ }
+
+
+ public void addActionListener(ActionListener _oActionListener){
+ oActionListener = _oActionListener;
+ jHelpButton.setEnabled(oActionListener != null);
+ }
+
+
+ private void invokeParameterMethod(){
+ try{
+ Object[] oParameters = getParameterValues();
+ m_oUnoReturnObject = m_xUnoMethodNode.invoke(m_oUnoObject, oParameters);
+ insertResultPanel(null);
+ } catch (Exception ex) {
+ insertResultPanel(ex);
+ m_oUnoReturnObject = null;
+ }}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/ObjectInspector.xcs b/odk/examples/java/Inspector/ObjectInspector.xcs
new file mode 100644
index 000000000..552e72ef8
--- /dev/null
+++ b/odk/examples/java/Inspector/ObjectInspector.xcs
@@ -0,0 +1,34 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<oor:component-schema
+ xmlns:oor="http://openoffice.org/2001/registry"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ oor:name="ObjectInspector"
+ oor:package="org.openoffice.inspector"
+ xml:lang="en-US">
+ <info>
+ <desc>Configuration parameters for the Object Inspector.</desc>
+ </info>
+ <component>
+ <prop oor:name="Language" oor:type="xs:string"/>
+ <prop oor:name="SDKPath" oor:type="xs:string"/>
+ </component>
+
+</oor:component-schema>
diff --git a/odk/examples/java/Inspector/ObjectInspector.xcu b/odk/examples/java/Inspector/ObjectInspector.xcu
new file mode 100644
index 000000000..d6fb08a0f
--- /dev/null
+++ b/odk/examples/java/Inspector/ObjectInspector.xcu
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<oor:component-data
+ xmlns:oor="http://openoffice.org/2001/registry"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ oor:name="ObjectInspector" oor:package="org.openoffice.inspector">
+ <prop oor:name="Language" oor:type="xs:string">
+ <value>Java</value>
+ </prop>
+ <prop oor:name="SDKPath" oor:type="xs:string">
+ <value></value>
+ </prop>
+
+</oor:component-data>
+
diff --git a/odk/examples/java/Inspector/ProtocolHandler.xcu b/odk/examples/java/Inspector/ProtocolHandler.xcu
new file mode 100644
index 000000000..30f3b6b44
--- /dev/null
+++ b/odk/examples/java/Inspector/ProtocolHandler.xcu
@@ -0,0 +1,28 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <node oor:name="HandlerSet">
+ <node oor:name="InspectorAddon$InspectorAddonImpl" oor:op="replace">
+ <prop oor:name="Protocols" oor:type="oor:string-list">
+ <value>org.openoffice.Office.addon.Inspector:*</value>
+ </prop>
+ </node>
+ </node>
+</oor:component-data>
+
diff --git a/odk/examples/java/Inspector/ProtocolHandlerAddon.java b/odk/examples/java/Inspector/ProtocolHandlerAddon.java
new file mode 100644
index 000000000..51158c392
--- /dev/null
+++ b/odk/examples/java/Inspector/ProtocolHandlerAddon.java
@@ -0,0 +1,273 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.lib.uno.helper.Factory;
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.lib.uno.helper.WeakBase;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.registry.XRegistryKey;
+import com.sun.star.lang.XInitialization;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.frame.XStatusListener;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.DispatchDescriptor;
+import com.sun.star.awt.XToolkit;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.awt.XMessageBox;
+import com.sun.star.awt.WindowAttribute;
+import com.sun.star.awt.WindowClass;
+import com.sun.star.awt.WindowDescriptor;
+import com.sun.star.awt.Rectangle;
+
+public class ProtocolHandlerAddon {
+ /** This class implements the component. At least the interfaces XServiceInfo,
+ * XTypeProvider, and XInitialization should be provided by the service.
+ */
+ public static class ProtocolHandlerAddonImpl extends WeakBase implements
+ XDispatchProvider,
+ XDispatch,
+ XInitialization,
+ XServiceInfo {
+
+ /** The service name, that must be used to get an instance of this service.
+ */
+ private static final String[] m_serviceNames = { "com.sun.star.frame.ProtocolHandler" };
+
+ /** The component context, that gives access to the service manager and all registered services.
+ */
+ private XComponentContext m_xCmpCtx;
+
+ /** The toolkit, that we can create UNO dialogs.
+ */
+ private XToolkit m_xToolkit;
+
+ /** The frame where the addon depends on.
+ */
+ private XFrame m_xFrame;
+
+
+ /** The constructor of the inner class has a XMultiServiceFactory parameter.
+ * @param xComponentContext A special service factory
+ * could be introduced while initializing.
+ */
+ public ProtocolHandlerAddonImpl( XComponentContext xComponentContext ) {
+ m_xCmpCtx = xComponentContext;
+ }
+
+ /** This method is a member of the interface for initializing an object
+ * directly after its creation.
+ * @param object This array of arbitrary objects will be passed to the
+ * component after its creation.
+ * @throws com.sun.star.uno.Exception Every exception will not be handled, but will be
+ * passed to the caller.
+ */
+ public void initialize( Object[] object )
+ throws com.sun.star.uno.Exception {
+
+ if ( object.length > 0 )
+ {
+ m_xFrame = UnoRuntime.queryInterface(
+ XFrame.class, object[ 0 ] );
+ }
+
+ // Create the toolkit to have access to it later
+ m_xToolkit = UnoRuntime.queryInterface(
+ XToolkit.class,
+ m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit",
+ m_xCmpCtx));
+ }
+
+ /** This method returns an array of all supported service names.
+ * @return Array of supported service names.
+ */
+ public String[] getSupportedServiceNames() {
+ return getServiceNames();
+ }
+
+ private static String[] getServiceNames() {
+ return m_serviceNames;
+ }
+
+ /** This method returns true, if the given service will be
+ * supported by the component.
+ * @param sService Service name.
+ * @return True, if the given service name will be supported.
+ */
+ public boolean supportsService( String sService ) {
+ int len = m_serviceNames.length;
+
+ for( int i=0; i < len; i++) {
+ if ( sService.equals( m_serviceNames[i] ) )
+ return true;
+ }
+
+ return false;
+ }
+
+ /** Return the class name of the component.
+ * @return Class name of the component.
+ */
+ public String getImplementationName() {
+ return ProtocolHandlerAddonImpl.class.getName();
+ }
+
+ // XDispatchProvider
+ public XDispatch queryDispatch( /*IN*/com.sun.star.util.URL aURL,
+ /*IN*/String sTargetFrameName,
+ /*IN*/int iSearchFlags ) {
+ XDispatch xRet = null;
+ if ( aURL.Protocol.equals("org.openoffice.Office.addon.example:") ) {
+ if ( aURL.Path.equals( "Function1" ) )
+ xRet = this;
+ if ( aURL.Path.equals( "Function2" ) )
+ xRet = this;
+ if ( aURL.Path.equals( "Help" ) )
+ xRet = this;
+ }
+ return xRet;
+ }
+
+ public XDispatch[] queryDispatches( /*IN*/DispatchDescriptor[] seqDescripts ) {
+ int nCount = seqDescripts.length;
+ XDispatch[] lDispatcher = new XDispatch[nCount];
+
+ for( int i=0; i<nCount; ++i )
+ lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL,
+ seqDescripts[i].FrameName,
+ seqDescripts[i].SearchFlags );
+
+ return lDispatcher;
+ }
+
+ // XDispatch
+ public void dispatch( /*IN*/com.sun.star.util.URL aURL,
+ /*IN*/com.sun.star.beans.PropertyValue[] aArguments ) {
+
+ if ( aURL.Protocol.equals("org.openoffice.Office.addon.example:") )
+ {
+ if ( aURL.Path.equals( "Function1" ) )
+ {
+ showMessageBox("SDK DevGuide Add-On example", "Function 1 activated");
+ }
+ if ( aURL.Path.equals( "Function2" ) )
+ {
+ showMessageBox("SDK DevGuide Add-On example", "Function 2 activated");
+ }
+ if ( aURL.Path.equals( "Help" ) )
+ {
+ showMessageBox("About SDK DevGuide Add-On example", "This is the SDK Add-On example");
+ }
+ }
+ }
+
+ public void addStatusListener( /*IN*/XStatusListener xControl,
+ /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+ public void removeStatusListener( /*IN*/XStatusListener xControl,
+ /*IN*/com.sun.star.util.URL aURL ) {
+ }
+
+ private void showMessageBox(String sTitle, String sMessage) {
+ if ( null != m_xFrame && null != m_xToolkit ) {
+
+ // describe window properties.
+ WindowDescriptor aDescriptor = new WindowDescriptor();
+ aDescriptor.Type = WindowClass.MODALTOP;
+ aDescriptor.WindowServiceName = "infobox";
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = UnoRuntime.queryInterface(
+ XWindowPeer.class, m_xFrame.getContainerWindow());
+ aDescriptor.Bounds = new Rectangle(0,0,300,200);
+ aDescriptor.WindowAttributes = WindowAttribute.BORDER |
+ WindowAttribute.MOVEABLE |
+ WindowAttribute.CLOSEABLE;
+
+ XWindowPeer xPeer = m_xToolkit.createWindow( aDescriptor );
+ if ( null != xPeer ) {
+ XMessageBox xMsgBox = UnoRuntime.queryInterface(
+ XMessageBox.class, xPeer);
+ if ( null != xMsgBox )
+ {
+ xMsgBox.setCaptionText( sTitle );
+ xMsgBox.setMessageText( sMessage );
+ xMsgBox.execute();
+ }
+ }
+ }
+ }
+ }
+
+
+ /** Gives a factory for creating the service.
+ * This method is called by the <code>JavaLoader</code>
+ * <p>
+ * @return Returns a <code>XSingleServiceFactory</code> for creating the
+ * component.
+ * @see com.sun.star.comp.loader.JavaLoader
+ * @param sImplementationName The implementation name of the component.
+ */
+ public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) {
+ XSingleComponentFactory xFactory = null;
+
+ if ( sImplementationName.equals( ProtocolHandlerAddonImpl.class.getName() ) )
+ xFactory = Factory.createComponentFactory(ProtocolHandlerAddonImpl.class,
+ ProtocolHandlerAddonImpl.getServiceNames());
+
+ return xFactory;
+ }
+
+ /** Writes the service information into the given registry key.
+ * This method is called by the <code>JavaLoader</code>.
+ * @return returns true if the operation succeeded
+ * @see com.sun.star.comp.loader.JavaLoader
+ * @see com.sun.star.lib.uno.helper.Factory
+ * @param xRegistryKey Makes structural information (except regarding tree
+ * structures) of a single
+ * registry key accessible.
+ */
+ public static boolean __writeRegistryServiceInfo(
+ XRegistryKey xRegistryKey ) {
+ return Factory.writeRegistryServiceInfo(
+ ProtocolHandlerAddonImpl.class.getName(),
+ ProtocolHandlerAddonImpl.getServiceNames(),
+ xRegistryKey );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SourceCodeGenerator.java b/odk/examples/java/Inspector/SourceCodeGenerator.java
new file mode 100644
index 000000000..9ff6ad793
--- /dev/null
+++ b/odk/examples/java/Inspector/SourceCodeGenerator.java
@@ -0,0 +1,1635 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import com.sun.star.reflection.ParamInfo;
+import com.sun.star.reflection.XIdlClass;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.reflection.XTypeDescription;
+import com.sun.star.uno.Any;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.TypeClass;
+
+
+
+public class SourceCodeGenerator {
+ private ArrayList<String> sExceptions = new ArrayList<String>();
+ private ArrayList<String> sHeaderStatements = new HeaderStatements();
+ private XLanguageSourceCodeGenerator m_xLanguageSourceCodeGenerator;
+ private String sStatementCode = "";
+ private String sMainMethodSignature = "";
+
+ private HashMap<String, UnoObjectDefinition> aVariables = new HashMap<String, UnoObjectDefinition>();
+ private final String SSUFFIXSEPARATOR = "_";
+ private final String SVARIABLENAME = "VariableName";
+ private Introspector m_oIntrospector;
+ private ArrayList<XTreePathProvider> aTreepathProviders = new ArrayList<XTreePathProvider>();
+ private boolean baddExceptionHandling = false;
+ private boolean bXPropertySetExceptionsAreAdded = false;
+ private XUnoNode oInitialUnoNode = null;
+ private final String sINITIALVARIABLENAME = "_oUnoEntryObject";
+
+
+ /** Creates a new instance of SourceCodeGenerator */
+ public SourceCodeGenerator(int _nLanguage) {
+ this.setLanguage(_nLanguage);
+ m_oIntrospector = Introspector.getIntrospector();
+ }
+
+
+ public String addSourceCodeOfUnoObject(XTreePathProvider _xTreepathProvider, boolean _brememberPath, boolean _baddHeader){
+ String sVariableName = "";
+ if (_xTreepathProvider != null) {
+ for (int i = 0; i < _xTreepathProvider.getPathCount(); i++){
+ XUnoNode oUnoNode = _xTreepathProvider.getPathComponent(i);
+ if (i == 0){
+ sVariableName = sINITIALVARIABLENAME;
+ oInitialUnoNode = oUnoNode;
+ }
+ else{
+ if (oUnoNode instanceof XUnoMethodNode){
+ XUnoMethodNode oUnoMethodNode = (XUnoMethodNode) oUnoNode;
+ if (oUnoMethodNode.isInvoked()){
+ UnoObjectDefinition oUnoReturnObjectDefinition = getUnoObjectDefinition(_xTreepathProvider, oUnoMethodNode, i);
+ if (!isVariableDeclared(oUnoReturnObjectDefinition, this.generateVariableNameFromMethod(oUnoMethodNode.getXIdlMethod()))){
+ sStatementCode += "\n" + getMethodStatementSourceCode(oUnoMethodNode, sVariableName, oUnoReturnObjectDefinition);
+ }
+ sVariableName = oUnoReturnObjectDefinition.getVariableName();
+ }
+ }
+ else if (oUnoNode instanceof XUnoPropertyNode){
+ XUnoPropertyNode oUnoPropertyNode = (XUnoPropertyNode) oUnoNode;
+ Any oReturnObject = com.sun.star.uno.Any.complete(oUnoPropertyNode.getUnoReturnObject());
+ UnoObjectDefinition oUnoReturnObjectDefinition = new UnoObjectDefinition(oReturnObject);
+ if (!isVariableDeclared(oUnoReturnObjectDefinition, oUnoPropertyNode.getProperty().Name)){
+ sStatementCode += "\n" + getPropertyStatementSourceCode(oUnoPropertyNode, sVariableName, oUnoReturnObjectDefinition);
+ }
+ sVariableName = oUnoReturnObjectDefinition.getVariableName();
+ }
+ }
+ }
+ }
+ String sCompleteCode = combineCompleteSourceCode(_baddHeader);
+ if (_brememberPath){
+ aTreepathProviders.add(_xTreepathProvider);
+ }
+ return sCompleteCode;
+ }
+
+
+ private void setLanguage(int _nLanguage){
+ XLanguageSourceCodeGenerator xLanguageSourceCodeGenerator = null;
+ switch(_nLanguage){
+ case XLanguageSourceCodeGenerator.nJAVA:
+ xLanguageSourceCodeGenerator = new JavaCodeGenerator();
+ break;
+ case XLanguageSourceCodeGenerator.nCPLUSPLUS:
+ xLanguageSourceCodeGenerator = new CPlusPlusCodeGenerator();
+ break;
+ case XLanguageSourceCodeGenerator.nBASIC:
+ xLanguageSourceCodeGenerator = new BasicCodeGenerator();
+ break;
+ default:
+ System.out.println("Unknown Sourcecode Language. Check Menus!");
+ }
+ if (xLanguageSourceCodeGenerator != null){
+ m_xLanguageSourceCodeGenerator = xLanguageSourceCodeGenerator;
+ }
+ }
+
+ private void resetSourceCodeGeneration(int _nLanguage){
+ aVariables.clear();
+ this.sHeaderStatements.clear();
+ setLanguage(_nLanguage);
+ sStatementCode = "";
+ }
+
+ private String generateVariableNameFromMethod(String _sMethodName, String _sPrefix, boolean _bConsiderAll){
+ String sReturn = "";
+ if (_sMethodName.startsWith(_sPrefix)){
+ int nPrefixLength = _sPrefix.length();
+ if (_sMethodName.length() > nPrefixLength){
+ String sChar = _sMethodName.substring(nPrefixLength, nPrefixLength + 1);
+ String sUpperChar = sChar.toUpperCase();
+ if (sUpperChar.equals(sChar)){
+ if (_bConsiderAll){
+ sReturn = _sMethodName;
+ }
+ else{
+ sReturn = _sMethodName.substring(nPrefixLength, _sMethodName.length());
+ }
+ }
+ }
+ }
+ return sReturn;
+ }
+
+
+ private String generateVariableNameFromMethod(XIdlMethod _xIdlMethod){
+ // todo: refactor this!!!
+ String sMethodName = _xIdlMethod.getName();
+ String sReturn = "";
+ sReturn = generateVariableNameFromMethod(sMethodName, "getBy", false);
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "get", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "attach", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "assign", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "attach", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "create", false);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "is", true);
+ }
+ if (sReturn.equals("")){
+ sReturn = generateVariableNameFromMethod(sMethodName, "has", true);
+ }
+ if (sReturn.equals("")){
+ sReturn = sMethodName;
+ }
+ return sReturn;
+ }
+
+
+ public String convertAllUnoObjects(int _nLanguage){
+ String sSourceCode = "";
+ resetSourceCodeGeneration(_nLanguage);
+ int ncount = aTreepathProviders.size();
+ for (int i=0; i< ncount; i++){
+ sSourceCode = addSourceCodeOfUnoObject(aTreepathProviders.get(i), false, (i == (ncount-1)));
+ }
+ return sSourceCode;
+ }
+
+ private UnoObjectDefinition getUnoObjectDefinition(XTreePathProvider _xTreePathProvider, XUnoMethodNode _oUnoMethodNode, int _nindex){
+ XUnoNode oUnoNode = null;
+ Object oUnoReturnObject = null;
+ Object[] oParamObjects = null;
+ XIdlClass xIdlClass = _oUnoMethodNode.getXIdlMethod().getReturnType();
+ String sTypeName = xIdlClass.getName();
+ TypeClass aTypeClass = xIdlClass.getTypeClass();
+ if (aTypeClass.getValue() != TypeClass.VOID_value){
+ if (_xTreePathProvider.getPathCount() > _nindex + 1){
+ oUnoNode = _xTreePathProvider.getPathComponent(_nindex + 1);
+ oUnoReturnObject = oUnoNode.getUnoObject();
+ }
+ }
+ if (oUnoReturnObject == null){
+ oUnoReturnObject = _oUnoMethodNode.getLastUnoReturnObject();
+ }
+ UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(oUnoReturnObject, sTypeName, aTypeClass);
+ if (_oUnoMethodNode.hasParameters()){
+ if (oUnoNode != null){
+ oParamObjects = oUnoNode.getParameterObjects();
+ }
+ else{
+ oParamObjects = _oUnoMethodNode.getLastParameterObjects();
+ }
+ }
+ if (oParamObjects != null){
+ oUnoObjectDefinition.addParameterObjects(oParamObjects);
+ }
+ return oUnoObjectDefinition;
+ }
+
+
+ private String combineCompleteSourceCode(boolean _bAddHeader){
+ String sCompleteCode = "";
+ if (_bAddHeader){
+ sMainMethodSignature = m_xLanguageSourceCodeGenerator.getMainMethodSignatureSourceCode(oInitialUnoNode, sINITIALVARIABLENAME);
+ m_xLanguageSourceCodeGenerator.assignqueryInterfaceHeaderSourceCode();
+ sCompleteCode += getHeaderSourceCode();
+ }
+ sCompleteCode += sMainMethodSignature;
+ sCompleteCode += sStatementCode;
+ if (_bAddHeader){
+ sCompleteCode += m_xLanguageSourceCodeGenerator.getMethodTerminationSourceCode();
+ sCompleteCode += "\n" + m_xLanguageSourceCodeGenerator.getCommentSign() + "...";
+ }
+ return sCompleteCode;
+ }
+
+
+ private String getPropertyStatementSourceCode(XUnoPropertyNode _oUnoPropertyNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition){
+ String sReturnObjectVariableDefinition = "";
+ String sStatement = "";
+ String sPropertyName = _oUnoPropertyNode.getProperty().Name;
+ UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(_oUnoPropertyNode.getUnoObject(), "com.sun.star.beans.XPropertySet");
+ if (!m_xLanguageSourceCodeGenerator.needsqueryInterface() || (oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.STRUCT_value)){
+ oUnoObjectDefinition.setVariableName(_sVariableName);
+ if (oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.STRUCT_value){
+ sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, false);
+ sStatement += m_xLanguageSourceCodeGenerator.getStructSourceCode(sReturnObjectVariableDefinition, oUnoObjectDefinition.getVariableName(), sPropertyName);
+ return sStatement;
+ }
+ }
+ sStatement += addQueryInterfaceSourceCode(oUnoObjectDefinition, _sVariableName, "com.sun.star.beans.XPropertySet");
+ if (_oUnoReturnObjectDefinition.getTypeClass().getValue() != TypeClass.VOID_value){
+ sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, true);
+ }
+ sStatement += m_xLanguageSourceCodeGenerator.getPropertyValueGetterSourceCode(sPropertyName, sReturnObjectVariableDefinition, oUnoObjectDefinition.getVariableName(), _oUnoReturnObjectDefinition.getTypeClass(), _oUnoReturnObjectDefinition.getTypeName());
+ addXPropertySetRelatedExceptions();
+ return sStatement;
+ }
+
+
+ private String getMethodStatementSourceCode(XUnoMethodNode _oUnoMethodNode, String _sVariableName, UnoObjectDefinition _oUnoReturnObjectDefinition){
+ String sReturnObjectVariableDefinition = "";
+ String sStatement = "";
+ XIdlMethod xIdlMethod = _oUnoMethodNode.getXIdlMethod();
+ TypeClass aReturnTypeClass = xIdlMethod.getReturnType().getTypeClass();
+ UnoObjectDefinition oUnoObjectDefinition = new UnoObjectDefinition(_oUnoMethodNode.getUnoObject(), _oUnoMethodNode.getClassName());
+ String sVariableStemName = this.generateVariableNameFromMethod(xIdlMethod);
+ sStatement += addQueryInterfaceSourceCode(oUnoObjectDefinition, _sVariableName, oUnoObjectDefinition.getTypeName());
+ if (_oUnoReturnObjectDefinition.getTypeClass().getValue() != TypeClass.VOID_value){
+ sReturnObjectVariableDefinition = getVariableInitialization(_oUnoReturnObjectDefinition, false) + " = ";
+ }
+ Object[] oParamObjects = _oUnoReturnObjectDefinition.getParameterObjects();
+ String sParameterCode = getMethodParameterValueDescription(_oUnoMethodNode, oParamObjects, false);
+ String sSeparator = m_xLanguageSourceCodeGenerator.getMethodSeparator();
+ sStatement += "\t" + sReturnObjectVariableDefinition + oUnoObjectDefinition.getVariableName() + sSeparator + xIdlMethod.getName() + "(" + sParameterCode + ")";
+ sStatement += m_xLanguageSourceCodeGenerator.getStatementTerminationCharacter();
+ addExceptions(xIdlMethod);
+ return sStatement;
+ }
+
+
+ private String addQueryInterfaceSourceCode(UnoObjectDefinition _oUnoObjectDefinition, String _sVariableName, String _sTypeName){
+ String sLocStatement = "";
+ if (m_xLanguageSourceCodeGenerator.needsqueryInterface()){
+ if (!isVariableDeclared(_oUnoObjectDefinition, "")){
+ String sObjectVariableDefinition = getVariableDeclaration(_oUnoObjectDefinition, false, "");
+ sLocStatement += m_xLanguageSourceCodeGenerator.getqueryInterfaceSourceCode(_sTypeName, sObjectVariableDefinition, _sVariableName);
+ }
+ }
+ else{
+ _oUnoObjectDefinition.setVariableName(_sVariableName);
+ }
+ return sLocStatement;
+ }
+
+
+ private void addXPropertySetRelatedExceptions(){
+ if (!bXPropertySetExceptionsAreAdded){
+ sExceptions.add("com.sun.star.beans.UnknownPropertyException");
+ sExceptions.add("com.sun.star.lang.WrappedTargetException");
+ sExceptions.add("com.sun.star.lang.IllegalArgumentException");
+ bXPropertySetExceptionsAreAdded = true;
+ baddExceptionHandling = true;
+ }
+ }
+
+
+ private void addExceptions(XIdlMethod _xIdlMethod){
+ XIdlClass[] xIdlClasses = _xIdlMethod.getExceptionTypes();
+ for (int i = 0; i > xIdlClasses.length; i++){
+ sExceptions.add(xIdlClasses[0].getName());
+ baddExceptionHandling = true;
+ }
+ }
+
+ private String getHeaderSourceCode(){
+ for(UnoObjectDefinition oUnoObjectDefinition : aVariables.values()){
+ String sCurHeaderStatement = m_xLanguageSourceCodeGenerator.getHeaderSourceCode(oUnoObjectDefinition.getUnoObject(), oUnoObjectDefinition.getTypeName(), oUnoObjectDefinition.getTypeClass());
+ sHeaderStatements.add(sCurHeaderStatement);
+ }
+ String sHeaderSourcecode = "";
+ String[] sHeaderStatementArray = new String[sHeaderStatements.size()];
+ sHeaderStatements.toArray(sHeaderStatementArray);
+ java.util.Arrays.sort(sHeaderStatementArray);
+ for (int i = 0; i < sHeaderStatementArray.length; i++){
+ sHeaderSourcecode += sHeaderStatementArray[i];
+ }
+ sHeaderSourcecode += m_xLanguageSourceCodeGenerator.getFinalHeaderStatements();
+ return sHeaderSourcecode +"\n" + m_xLanguageSourceCodeGenerator.getCommentSign() + "...\n";
+ }
+
+
+ private class HeaderStatements extends ArrayList<String> {
+
+ public boolean contains(String _oElement){
+ String sCompName = _oElement;
+ for (int i = 0; i < this.size(); i++){
+ String sElement = this.get(i);
+ if (sElement.equals(sCompName)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ @Override
+ public boolean add(String _oElement){
+ if (!contains(_oElement)){
+ super.add(_oElement);
+ return true;
+ }
+ return false;
+ }
+ }
+
+
+ private boolean isVariableDeclared(UnoObjectDefinition _oUnoObjectDefinition, String _sDefaultStemName){
+ boolean bisDeclared = false;
+ if (!_sDefaultStemName.equals("")){
+ _oUnoObjectDefinition.setCentralVariableStemName(_sDefaultStemName);
+ }
+ String sVariableStemName = _oUnoObjectDefinition.getVariableStemName();
+ bisDeclared = aVariables.containsKey(sVariableStemName);
+ if (bisDeclared){
+ Object oUnoObject = _oUnoObjectDefinition.getUnoObject();
+ if (Introspector.isObjectPrimitive(oUnoObject)){
+ bisDeclared = false;
+ }
+ else if (Introspector.isObjectSequence(oUnoObject)){
+ bisDeclared = false;
+ }
+ else{
+ String sCompVariableName = sVariableStemName;
+ String sUnoObjectIdentity = oUnoObject.toString();
+ boolean bleaveloop = false;
+ int a = 2;
+ while (!bleaveloop){
+ if (aVariables.containsKey(sCompVariableName)){
+ Object oUnoCompObject = aVariables.get(sCompVariableName).getUnoObject();
+ String sUnoCompObjectIdentity = oUnoCompObject.toString();
+ bleaveloop = sUnoCompObjectIdentity.equals(sUnoObjectIdentity);
+ bisDeclared = bleaveloop;
+ if (!bleaveloop){
+ sCompVariableName = sVariableStemName + SSUFFIXSEPARATOR + a++;
+ }
+ }
+ else{
+ bleaveloop = true;
+ bisDeclared = false;
+ }
+ }
+ }
+ }
+ return bisDeclared;
+ }
+
+
+ private String addUniqueVariableName(String _sStemVariableName, UnoObjectDefinition _oUnoObjectDefinition){
+ boolean bElementexists = true;
+ int a = 2;
+ String sCompName = _sStemVariableName;
+ while (bElementexists){
+ if (! aVariables.containsKey(sCompName)){
+ aVariables.put(sCompName, _oUnoObjectDefinition);
+ break;
+ }
+ sCompName = _sStemVariableName + SSUFFIXSEPARATOR + a++;
+ }
+ return sCompName;
+ }
+
+
+
+ private String getTypeString(String _sTypeName, TypeClass _aTypeClass, boolean _bAsHeaderSourceCode){
+ String sTypeString = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getbooleanTypeDescription();
+ break;
+ case TypeClass.BYTE_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getbyteTypeDescription();
+ break;
+ case TypeClass.CHAR_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getcharTypeDescription();
+ break;
+ case TypeClass.DOUBLE_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getdoubleTypeDescription();
+ break;
+ case TypeClass.FLOAT_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getfloatTypeDescription();
+ break;
+ case TypeClass.HYPER_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.gethyperTypeDescription();
+ break;
+ case TypeClass.LONG_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getlongTypeDescription();
+ break;
+ case TypeClass.SHORT_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getshortTypeDescription();
+ break;
+ case TypeClass.STRING_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getstringTypeDescription(_bAsHeaderSourceCode);
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getunsignedhyperTypeDescription();
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getunsignedlongTypeDescription();
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getdoubleTypeDescription();
+ break;
+ case TypeClass.SEQUENCE_value:
+ //TODO consider mulitdimensional Arrays
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(_sTypeName);
+ if (xTypeDescription != null){
+ sTypeString = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), _bAsHeaderSourceCode);
+ }
+ break;
+ case TypeClass.ANY_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getanyTypeDescription(_bAsHeaderSourceCode);
+ break;
+ case TypeClass.TYPE_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getObjectTypeDescription("com.sun.star.uno.Type", _bAsHeaderSourceCode);
+ break;
+ case TypeClass.ENUM_value:
+ case TypeClass.STRUCT_value:
+ case TypeClass.INTERFACE_ATTRIBUTE_value:
+ case TypeClass.INTERFACE_METHOD_value:
+ case TypeClass.INTERFACE_value:
+ case TypeClass.PROPERTY_value:
+ sTypeString = m_xLanguageSourceCodeGenerator.getObjectTypeDescription(_sTypeName, _bAsHeaderSourceCode);
+ break;
+ default:
+ }
+ return sTypeString;
+ }
+
+
+ private String getVariableDeclaration(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize, String _sVariableDefaultName){
+ TypeClass aTypeClass = _oUnoObjectDefinition.getTypeClass();
+ TypeClass aLocTypeClass = aTypeClass;
+ boolean bIsArray = false;
+ if (_oUnoObjectDefinition.getUnoObject() != null){
+ bIsArray = Introspector.isObjectSequence(_oUnoObjectDefinition.getUnoObject());
+ }
+ else{
+ bIsArray = _oUnoObjectDefinition.getTypeClass().getValue() == TypeClass.SEQUENCE_value;
+ }
+ String sVariableName = _oUnoObjectDefinition.getVariableName(_sVariableDefaultName);
+ String sTypeName = _oUnoObjectDefinition.getTypeName();
+ String sTypeString = getTypeString(sTypeName, aLocTypeClass, false);
+ if (bIsArray){
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(sTypeName);
+ if (xTypeDescription != null){
+ aLocTypeClass = xTypeDescription.getTypeClass();
+ }
+ }
+ String sVariableDeclaration = m_xLanguageSourceCodeGenerator.getVariableDeclaration(sTypeString, sVariableName, bIsArray, aLocTypeClass, _bInitialize);
+ addUniqueVariableName(sVariableName, _oUnoObjectDefinition);
+ return sVariableDeclaration;
+ }
+
+
+ private String getVariableInitialization(UnoObjectDefinition _oUnoObjectDefinition, boolean _bInitialize){
+ String sObjectVariableDeclaration = "";
+ String sVariableName = _oUnoObjectDefinition.getVariableName();
+ if (isVariableDeclared(_oUnoObjectDefinition, "")){
+ sObjectVariableDeclaration = sVariableName;
+ }
+ else{
+ sObjectVariableDeclaration = getVariableDeclaration(_oUnoObjectDefinition, _bInitialize, "");
+ }
+ return sObjectVariableDeclaration;
+ }
+
+
+
+ public String getVariableNameforUnoObject(String _sShortClassName){
+ if (_sShortClassName.startsWith("X")){
+ return "x" + _sShortClassName.substring(1);
+ }
+ else{
+ return _sShortClassName;
+ }
+ }
+
+
+private class UnoObjectDefinition{
+ private Object m_oUnoObject = null;
+
+ private String sVariableStemName = "";
+ private String m_sCentralVariableStemName = "";
+ private String sVariableName = "";
+ private String m_sTypeName = "";
+ private TypeClass m_aTypeClass = null;
+ private Object[] m_oParameterObjects = null;
+
+
+ private UnoObjectDefinition(Any _oUnoObject){
+ m_sTypeName = _oUnoObject.getType().getTypeName();
+ m_aTypeClass = _oUnoObject.getType().getTypeClass();
+ m_oUnoObject = _oUnoObject;
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ private UnoObjectDefinition(Object _oUnoObject, String _sTypeName, TypeClass _aTypeClass){
+ m_oUnoObject = _oUnoObject;
+ m_sTypeName = _sTypeName;
+ m_aTypeClass = _aTypeClass;
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ private UnoObjectDefinition(Object _oUnoObject, String _sTypeName){
+ m_oUnoObject = _oUnoObject;
+ m_sTypeName = _sTypeName;
+ m_aTypeClass = AnyConverter.getType(_oUnoObject).getTypeClass();
+ m_sCentralVariableStemName = getCentralVariableStemName(m_aTypeClass);
+ }
+
+
+ private String getCentralVariableStemName(TypeClass _aTypeClass){
+ String sCentralVariableStemName = "";
+ int nTypeClass = _aTypeClass.getValue();
+ switch(nTypeClass){
+ case TypeClass.SEQUENCE_value:
+ //TODO consider mulitdimensional Arrays
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(getTypeName());
+ if (xTypeDescription != null){
+ sCentralVariableStemName = getCentralVariableStemName(xTypeDescription.getTypeClass());
+ }
+ break;
+ case TypeClass.TYPE_value:
+ sCentralVariableStemName = SVARIABLENAME;
+ break;
+ case TypeClass.STRUCT_value:
+ sCentralVariableStemName = Introspector.getShortClassName(getTypeName());
+ break;
+ case TypeClass.INTERFACE_ATTRIBUTE_value:
+ case TypeClass.INTERFACE_METHOD_value:
+ case TypeClass.INTERFACE_value:
+ case TypeClass.PROPERTY_value:
+ String sShortClassName = Introspector.getShortClassName(getTypeName());
+ sCentralVariableStemName = getVariableNameforUnoObject(sShortClassName);
+ default:
+ sCentralVariableStemName = SVARIABLENAME;
+ }
+ return sCentralVariableStemName;
+ }
+
+ /** may return null
+ */
+ public Object getUnoObject(){
+ return m_oUnoObject;
+ }
+
+
+ public TypeClass getTypeClass(){
+ return m_aTypeClass;
+ }
+
+
+ public String getTypeName(){
+ return m_sTypeName;
+ }
+
+
+ public void setCentralVariableStemName(String _sCentralVariableStemName){
+ m_sCentralVariableStemName = _sCentralVariableStemName;
+ }
+
+
+ public String getVariableStemName(){
+ if (sVariableStemName.equals("")){
+ sVariableStemName = getVariableStemName(m_aTypeClass);
+ }
+ return sVariableStemName;
+ }
+
+
+ private void addParameterObjects(Object[] _oParameterObjects){
+ m_oParameterObjects = _oParameterObjects;
+ }
+
+
+ public Object[] getParameterObjects(){
+ return m_oParameterObjects;
+ }
+
+
+
+
+
+ private String getVariableStemName(TypeClass _aTypeClass){
+ int nTypeClass = _aTypeClass.getValue();
+ switch(nTypeClass){
+ case TypeClass.BOOLEAN_value:
+ sVariableStemName = "b" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ sVariableStemName = "f" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.BYTE_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ sVariableStemName = "n" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.CHAR_value:
+ case TypeClass.STRING_value:
+ sVariableStemName = "s" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.SEQUENCE_value:
+ //TODO consider mulitdimensional Arrays
+ XTypeDescription xTypeDescription = Introspector.getIntrospector().getReferencedType(getTypeName());
+ if (xTypeDescription != null){
+ sVariableStemName = getVariableStemName(xTypeDescription.getTypeClass());
+ }
+ break;
+ case TypeClass.TYPE_value:
+ sVariableStemName = "a" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.ANY_value:
+ sVariableStemName = "o" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.STRUCT_value:
+ case TypeClass.ENUM_value:
+ sVariableStemName = "a" + m_sCentralVariableStemName;
+ break;
+ case TypeClass.INTERFACE_ATTRIBUTE_value:
+ case TypeClass.INTERFACE_METHOD_value:
+ case TypeClass.INTERFACE_value:
+ case TypeClass.PROPERTY_value:
+ String sShortClassName = Introspector.getShortClassName(getTypeName());
+ sVariableStemName = getVariableNameforUnoObject(sShortClassName);
+ default:
+ }
+ return sVariableStemName;
+ }
+
+
+ private void setVariableName(String _sVariableName){
+ sVariableName = _sVariableName;
+ }
+
+
+ private String getVariableName(String _sCentralVariableStemName){
+ if (!_sCentralVariableStemName.equals("")){
+ this.m_sCentralVariableStemName = _sCentralVariableStemName;
+ }
+ return getVariableName();
+ }
+
+
+ private String getVariableName() throws NullPointerException{
+ if (sVariableName.equals("")){
+ int a = 2;
+ sVariableName = getVariableStemName();
+ boolean bleaveloop = false;
+ while (!bleaveloop){
+ if (aVariables.containsKey(sVariableName)){
+ String sUnoObjectIdentity = aVariables.get(sVariableName).getUnoObject().toString();
+ if (m_oUnoObject != null){
+ if ((sUnoObjectIdentity.equals(m_oUnoObject.toString()) && (!Introspector.isPrimitive(this.getTypeClass())) &&
+ (! Introspector.isObjectSequence(m_oUnoObject)))){
+ bleaveloop = true;
+ }
+ else{
+ sVariableName = getVariableStemName() + SSUFFIXSEPARATOR + a++;
+ }
+ }
+ else{
+ bleaveloop = true;
+ }
+ }
+ else{
+ bleaveloop = true;
+ }
+ }
+ }
+ return sVariableName;
+ }
+ }
+
+
+ public String getStringValueOfObject(Object _oUnoObject, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ boolean bbooleanValue = ((Boolean) _oUnoObject).booleanValue();
+ sReturn += Boolean.toString(bbooleanValue);
+ case TypeClass.CHAR_value:
+ break;
+ case TypeClass.DOUBLE_value:
+ double fdoubleValue = ((Double) _oUnoObject).doubleValue();
+ sReturn += Double.toString(fdoubleValue);
+ break;
+ case TypeClass.ENUM_value:
+ break;
+ case TypeClass.FLOAT_value:
+ float floatValue = ((Float) _oUnoObject).floatValue();
+ sReturn += Float.toString(floatValue);
+ break;
+ case TypeClass.HYPER_value:
+ long nlongValue = ((Long) _oUnoObject).longValue();
+ sReturn += Long.toString(nlongValue);
+ break;
+ case TypeClass.LONG_value:
+ int nintValue = ((Integer) _oUnoObject).intValue();
+ sReturn += Integer.toString(nintValue);
+ break;
+ case TypeClass.SHORT_value:
+ short nshortValue = ((Short) _oUnoObject).shortValue();
+ sReturn += Short.toString(nshortValue);
+ break;
+ case TypeClass.STRING_value:
+ sReturn += (String) _oUnoObject;
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ nlongValue = ((Long) _oUnoObject).longValue();
+ sReturn += Long.toString(nlongValue);
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ nintValue = ((Integer) _oUnoObject).intValue();
+ sReturn += Integer.toString(nintValue);
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ nshortValue = ((Short) _oUnoObject).shortValue();
+ sReturn += Short.toString(nshortValue);
+ break;
+ default:
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'getStringValueOfObject()'");
+ }
+ return sReturn;
+ }
+
+
+ public String getMethodParameterValueDescription(XUnoMethodNode _oUnoMethodNode, Object[] _oParamObjects, boolean _bIncludeParameterNames){
+ String sParamSourceCode = "";
+ ParamInfo[] aParamInfos = _oUnoMethodNode.getXIdlMethod().getParameterInfos();
+ if (_oParamObjects != null){
+ for (int i = 0; i < _oParamObjects.length; i++){
+ TypeClass aTypeClass = aParamInfos[i].aType.getTypeClass();
+ if (_bIncludeParameterNames){
+ sParamSourceCode += aParamInfos[i].aName + "=";
+ }
+ String sParamDescription = getStringValueOfObject(_oParamObjects[i], aTypeClass);
+ sParamDescription = this.m_xLanguageSourceCodeGenerator.castLiteral(sParamDescription, aTypeClass);
+ sParamSourceCode += sParamDescription;
+
+ if (i < _oParamObjects.length - 1){
+ sParamSourceCode += ", ";
+ }
+ }
+ }
+ return sParamSourceCode;
+ }
+
+
+ private class JavaCodeGenerator implements XLanguageSourceCodeGenerator{
+
+ private boolean bAddAnyConverter = false;
+ private boolean bIsPropertyUnoObjectDefined = false;
+
+ public JavaCodeGenerator(){
+ }
+
+
+ public String getStatementTerminationCharacter(){
+ return ";";
+ }
+
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){
+ String sClassName = _sClassName;
+ String sHeaderStatement = "";
+ if (_oUnoObject != null){
+ if (!Introspector.isObjectPrimitive(_oUnoObject)){
+ if (Introspector.isObjectSequence(_oUnoObject)){
+ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName);
+ if (xTypeDescription != null){
+ if (!Introspector.isPrimitive(xTypeDescription.getTypeClass())){
+ sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true);
+ }
+ // primitive Types are not supposed to turn up in the import section...
+ else{
+ sClassName = "";
+ }
+ }
+ }
+ else{
+ sClassName = getTypeString(_sClassName, _aTypeClass, true);
+ }
+ }
+ else if (_aTypeClass.getValue() == TypeClass.ENUM_value){
+ sClassName = _sClassName;
+ }
+ else{
+ sClassName = "";
+ }
+ if (!sClassName.equals("")){
+ sHeaderStatement = "import " + sClassName + ";\n";
+ }
+ }
+ return sHeaderStatement;
+ }
+
+
+ public String getFinalHeaderStatements(){
+ return "";
+ }
+
+
+ public void assignqueryInterfaceHeaderSourceCode(){
+ sHeaderStatements.add("import com.sun.star.uno.UnoRuntime;\n");
+ sHeaderStatements.add("import com.sun.star.uno.XInterface;\n");
+ if (bAddAnyConverter){
+ sHeaderStatements.add("import com.sun.star.uno.AnyConverter;\n");
+ }
+ }
+
+
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){
+ boolean bLocAddAnyConverter = true;
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toBoolean(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toChar(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.BYTE_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toByte(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.DOUBLE_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toDouble(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.FLOAT_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toFloat(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedLong(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.HYPER_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toLong(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.UNSIGNED_LONG_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedInt(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.LONG_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toInt(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.SHORT_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toShort(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toUnsignedShort(" + _sObjectDescription + ")";
+ break;
+ case TypeClass.STRING_value:
+ sReturn = _sReturnVariableName + " = AnyConverter.toString(" + _sObjectDescription + ")";
+ break;
+ default:
+ String sShortTypeName = Introspector.getShortClassName(_sTypeName);
+ if (bIsPropertyUnoObjectDefined){
+ sReturn = "oUnoObject = " + _sObjectDescription + ";\n\t";
+ }
+ else{
+ sReturn = "Object oUnoObject = " + _sObjectDescription + ";\n\t";
+ bIsPropertyUnoObjectDefined = true;
+ }
+ sReturn += _sReturnVariableName + " = (" + sShortTypeName + ") AnyConverter.toObject(" + sShortTypeName + ".class, oUnoObject);";
+ break;
+ }
+ if (!bAddAnyConverter){
+ bAddAnyConverter = bLocAddAnyConverter;
+ }
+ return sReturn;
+ }
+
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){
+ return "\t" + _sReturnVariableDescription + " = " + _sObjectDescription + "." + _sMember + ";";
+ }
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){
+ //TODO try to use + _oUnoNode.getClassName() instead of the hack
+ String sReturn = "public void codesnippet(XInterface " + _soReturnObjectDescription + "){";
+ if (baddExceptionHandling){
+ sReturn += "\ntry{";
+ }
+ return sReturn;
+ }
+
+ public String getMethodSeparator(){
+ return ".";
+ }
+
+ public boolean needsqueryInterface(){
+ return true;
+ }
+
+ public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){
+ String sShortClassName = Introspector.getShortClassName(_sClassName);
+ return "\t" + _sReturnVariableName + " = (" + sShortClassName + ") UnoRuntime.queryInterface(" + sShortClassName + ".class, " + _sIncomingObjectName + ");\n";
+ }
+
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){
+ String sObjectDescription = _sIncomingObjectName + ".getPropertyValue(\"" + _sPropertyName + "\")";
+ String sReturn = getConvertedSourceCodeValueOfObject(_sReturnVariableName, sObjectDescription, _aTypeClass, _sTypeName);
+ sReturn += ";";
+ sReturn = "\t" + sReturn;
+ return sReturn;
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ String sReturn = "";
+ if (_bAsHeader){
+ sReturn = _sClassName;
+ }
+ else{
+ sReturn = Introspector.getShortClassName(_sClassName);
+ }
+ return sReturn;
+ }
+
+
+ public String getMethodTerminationSourceCode(){
+ String sReturn = "";
+ int nIndex = 1;
+ String sExceptionName = "e";
+ if (baddExceptionHandling){
+ for (int i = 0; i < sExceptions.size(); i++){
+ String sCurException = sExceptions.get(i);
+ if (sReturn.indexOf(sCurException) == -1){
+ if (nIndex > 1){
+ sExceptionName = "e"+ nIndex;
+ }
+ else{
+ sReturn +="\n}";
+ }
+ sReturn += "catch (" + sCurException + " " + sExceptionName + "){\n";
+ sReturn += "\t" + sExceptionName + ".printStackTrace(System.err);\n";
+ sReturn += "\t" + getCommentSign() + "Enter your Code here...\n}";
+ nIndex++;
+ }
+ }
+ }
+ sReturn += "\n}";
+ return sReturn;
+ }
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.BYTE_value:
+ sReturn = "(byte) " + _sExpression;
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = "'" + _sExpression + "'";
+ break;
+ case TypeClass.DOUBLE_value:
+ sReturn = "(double) " + _sExpression;
+ break;
+ case TypeClass.FLOAT_value:
+ sReturn = "(float) " + _sExpression;
+ break;
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ sReturn = "(short) " + _sExpression;
+ break;
+ case TypeClass.STRING_value:
+ sReturn = "\"" + _sExpression + "\"";
+ break;
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = "(long) " + _sExpression;
+ break;
+ case TypeClass.LONG_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.ENUM_value:
+ default:
+ sReturn = _sExpression;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'");
+ }
+ return sReturn;
+ }
+
+
+ public String getbooleanTypeDescription(){
+ return "boolean";
+ }
+
+ public String getbyteTypeDescription(){
+ return "byte";
+ }
+
+ public String getshortTypeDescription(){
+ return "short";
+ }
+
+ public String getlongTypeDescription(){
+ return "int";
+ }
+
+ public String getunsignedlongTypeDescription(){
+ return "int";
+ }
+
+ public String gethyperTypeDescription(){
+ return "long";
+ }
+
+ public String getunsignedhyperTypeDescription(){
+ return "long";
+ }
+
+ public String getfloatTypeDescription(){
+ return "float";
+ }
+
+ public String getdoubleTypeDescription(){
+ return "double";
+ }
+
+ public String getcharTypeDescription(){
+ return "char";
+ }
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "String";
+ }
+ }
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "Object";
+ }
+ }
+
+
+ public String getStringValue(String _sValue){
+ return _sValue;
+ }
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean _bIsArray, TypeClass _aTypeClass, boolean _bInitialize){
+ String sReturn = "";
+ if (_bIsArray){
+ sReturn = _sTypeString + "[] " + _sVariableName;
+ }
+ else{
+ sReturn = _sTypeString + " " + _sVariableName;
+ }
+ return sReturn;
+ }
+
+
+ public String getCommentSign(){
+ return "//";
+ }
+ }
+
+
+ private class BasicCodeGenerator implements XLanguageSourceCodeGenerator{
+
+
+ public BasicCodeGenerator(){
+ }
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){
+ String sHeaderStatement = "";
+ return sHeaderStatement;
+ }
+
+ public String getFinalHeaderStatements(){
+ return "";
+ }
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){
+ //TODO try to use + _oUnoNode.getClassName() instead of the hack
+ return "Sub Main(" + _soReturnObjectDescription + " as " + getanyTypeDescription(false) + ")";
+ }
+
+ public boolean needsqueryInterface(){
+ return false;
+ }
+
+ public void assignqueryInterfaceHeaderSourceCode(){
+ }
+
+ public String getMethodSeparator(){
+ return ".";
+ }
+
+
+ public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){
+ return _sIncomingObjectName;
+ }
+
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){
+ return "\t" + _sReturnVariableName + " = " + _sIncomingObjectName + "." + _sPropertyName;
+ }
+
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){
+ return getPropertyValueGetterSourceCode(_sMember, _sReturnVariableDescription, _sObjectDescription, null, "" );
+ }
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){
+ return _sReturnVariableName + " = " + _sObjectDescription;
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ return "Object";
+ }
+
+
+ public String getMethodTerminationSourceCode(){
+ return "\nEnd Sub\n";
+ }
+
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ case TypeClass.BYTE_value:
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.CHAR_value:
+ case TypeClass.STRING_value:
+ sReturn = "\"" +_sExpression + "\"";
+ break;
+ case TypeClass.ENUM_value:
+ default:
+ sReturn = _sExpression;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'");
+ }
+ return sReturn;
+ }
+
+
+
+ public String getbooleanTypeDescription(){
+ return "Boolean";
+ }
+
+ public String getbyteTypeDescription(){
+ return "Integer";
+ }
+
+ public String getshortTypeDescription(){
+ return "Integer";
+ }
+
+ public String getlongTypeDescription(){
+ return "Integer";
+ }
+
+ public String getunsignedlongTypeDescription(){
+ return "Long";
+ }
+
+ public String gethyperTypeDescription(){
+ return "Long";
+ }
+
+ public String getunsignedhyperTypeDescription(){
+ return "Long";
+ }
+
+ public String getfloatTypeDescription(){
+ return "Double";
+ }
+
+ public String getdoubleTypeDescription(){
+ return "Double";
+ }
+
+ public String getcharTypeDescription(){
+ return "String";
+ }
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "String";
+ }
+ }
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "Object";
+ }
+ }
+
+ public String getStatementTerminationCharacter(){
+ return "";
+ }
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){
+ String sReturn = "";
+ if (bIsArray){
+ sReturn = "Dim " + _sVariableName + "() as " + _sTypeString + "\n\t" + _sVariableName;
+ }
+ else{
+ sReturn = "Dim " + _sVariableName + " as " + _sTypeString + "\n\t" + _sVariableName;
+ }
+ return sReturn;
+ }
+
+
+ public String getStringValue(String _sValue){
+ return _sValue;
+ }
+
+
+ public String getCommentSign(){
+ return "'";
+ }
+
+ }
+
+ private class CPlusPlusCodeGenerator implements XLanguageSourceCodeGenerator{
+
+ private boolean bIncludeStringHeader = false;
+ private boolean bIncludeAny = false;
+ private boolean bIncludeSequenceHeader = false;
+
+ public CPlusPlusCodeGenerator(){
+ }
+
+ private String getCSSNameSpaceString(){
+ return "css";
+ }
+
+ public String getStatementTerminationCharacter(){
+ return ";";
+ }
+
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass){
+ String sClassName = _sClassName;
+ String sHeaderStatement = "";
+ if (_oUnoObject != null){
+ if (!Introspector.isObjectPrimitive(_oUnoObject)){
+ if (Introspector.isObjectSequence(_oUnoObject)){
+ XTypeDescription xTypeDescription = m_oIntrospector.getReferencedType(sClassName);
+ if (xTypeDescription != null){
+ if (!Introspector.isPrimitive(xTypeDescription.getTypeClass())){
+ sClassName = getTypeString(xTypeDescription.getName(), xTypeDescription.getTypeClass(), true);
+ }
+ // primitive Types are not supposed to turn up in the import section...
+ else{
+ sClassName = "";
+ }
+ }
+ }
+ else{
+ sClassName = getTypeString(_sClassName, _aTypeClass, true);
+ }
+ if (!sClassName.equals("")){
+ sHeaderStatement = getHeaderOfClass(sClassName);
+ }
+ }
+ }
+ return sHeaderStatement;
+ }
+
+
+
+ public String getFinalHeaderStatements(){
+ String sReturn = "";
+ sReturn += "\nnamespace " + getCSSNameSpaceString() + " = com::sun::star;\n";
+ sReturn += "using ::rtl::OUString;\n";
+ return sReturn;
+ }
+
+
+ private String getHeaderOfClass(String _sClassName){
+ return "#include \"" + _sClassName.replace('.', '/') + ".hpp\"\n";
+ }
+
+
+
+ public void assignqueryInterfaceHeaderSourceCode(){
+ sHeaderStatements.add("#include \"sal/config.h\"\n");
+ sHeaderStatements.add("#include \"sal/types.h\"\n");
+ if (bIncludeStringHeader){
+ sHeaderStatements.add("#include \"rtl/ustring.hxx\"\n");
+ }
+ sHeaderStatements.add("#include \"com/sun/star/uno/Reference.hxx\"\n");
+ if (bIncludeSequenceHeader){
+ sHeaderStatements.add("#include \"com/sun/star/uno/Sequence.hxx\"\n");
+ }
+ sHeaderStatements.add(getHeaderOfClass("com.sun.star.uno.XInterface"));
+ if (bIncludeAny){
+ sHeaderStatements.add(getHeaderOfClass("com.sun.star.uno.Any"));
+ }
+ }
+
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription){
+ String sReturn = "";
+ sReturn = "void codesnippet(const " + getCSSNameSpaceString() + "::uno::Reference<" + getCSSNameSpaceString() + "::uno::XInterface>& " + _soReturnObjectDescription + " ){";
+ int a = 0;
+ if (!sExceptions.contains("com.sun.star.uno.RuntimeException")){
+ sExceptions.add("com.sun.star.uno.RuntimeException");
+ }
+ if (baddExceptionHandling){
+ sReturn += "\n//throw ";
+ for (int i = 0; i < sExceptions.size(); i++){
+ String sCurException = sExceptions.get(i);
+ if (sReturn.indexOf(sCurException) == -1){
+ if (a++ > 0){
+ sReturn += ", ";
+ }
+ sReturn += getObjectTypeDescription(sCurException, false);
+
+ }
+ }
+
+ }
+ sReturn += "{";
+ return sReturn;
+ }
+
+
+ public boolean needsqueryInterface(){
+ return true;
+ }
+
+
+ public String getqueryInterfaceSourceCode(String _sClassName, String _sReturnVariableName, String _sIncomingObjectName){
+ return "\t" + _sReturnVariableName + "( " + _sIncomingObjectName + ", " + getCSSNameSpaceString() + "::uno::UNO_QUERY_THROW);\n";
+ }
+
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName){
+ String sFirstLine = "\t";
+ String sReturnVariableName = _sReturnVariableName;
+ // e.g. uno::Any a = xPropSet->getPropertyValue( rtl::OUString( "DefaultContext" ) );
+ String[] sVarDefinition = _sReturnVariableName.split("=");
+ if (sVarDefinition.length > 0){
+ String sVariable = sVarDefinition[0];
+ String[] sVarDeclaration = sVariable.split(" ");
+ if (sVarDeclaration.length > 0){
+ sFirstLine += sReturnVariableName + ";\n";
+ sReturnVariableName = sVarDeclaration[sVarDeclaration.length-1];
+ }
+ }
+ String sObjectDescription = _sIncomingObjectName + "->getPropertyValue(" + getStringValue(_sPropertyName) + ")";
+ String sSecondLine = "\t" + getConvertedSourceCodeValueOfObject(sReturnVariableName, sObjectDescription, _aTypeClass, _sTypeName) + ";";
+ return sFirstLine + sSecondLine;
+ }
+
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember){
+ return "\t" + _sReturnVariableDescription + " = " + _sObjectDescription + "->" + _sMember + ";";
+ }
+
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName){
+ return _sObjectDescription + " >>= " + _sReturnVariableName;
+ }
+
+
+ public String getStringValue(String _sValue){
+ bIncludeStringHeader = true;
+ return "OUString(\"" + _sValue + "\")";
+ }
+
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader){
+ String sReturn = "";
+ if (_bAsHeader){
+ sReturn = _sClassName.replace('.', '/');
+ }
+ else{
+ String sModuleName = Introspector.getModuleName(_sClassName);
+ sModuleName = Introspector.getShortClassName(sModuleName);
+ sReturn = getCSSNameSpaceString() + "::" + sModuleName + "::" + Introspector.getShortClassName(_sClassName);
+ }
+ return sReturn;
+ }
+
+
+ public String getMethodTerminationSourceCode(){
+ return "\n}";
+ }
+
+ public String getMethodSeparator(){
+ return "->";
+ }
+
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass){
+ String sReturn = "";
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ case TypeClass.BYTE_value:
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = _sExpression;
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = "'" + _sExpression + "'";
+ break;
+ case TypeClass.STRING_value:
+ sReturn = getStringValue(_sExpression);
+ break;
+ case TypeClass.ENUM_value:
+ default:
+ sReturn = _sExpression;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'castliteral()'");
+ }
+ return sReturn;
+ }
+
+ public String getbooleanTypeDescription(){
+ return "sal_Bool";
+ }
+
+ public String getbyteTypeDescription(){
+ return "sal_Int8";
+ }
+
+ public String getshortTypeDescription(){
+ return "sal_Int16";
+ }
+
+ public String getlongTypeDescription(){
+ return "sal_Int32";
+ }
+
+ public String getunsignedlongTypeDescription(){
+ return "sal_uInt32";
+ }
+
+ public String gethyperTypeDescription(){
+ return "sal_Int64";
+ }
+
+ public String getunsignedhyperTypeDescription(){
+ return "sal_uInt64";
+ }
+
+ public String getfloatTypeDescription(){
+ return "float";
+ }
+
+ public String getdoubleTypeDescription(){
+ return "double";
+ }
+
+ public String getcharTypeDescription(){
+ return "sal_Unicode";
+ }
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode){
+ bIncludeStringHeader = true;
+ if (_bAsHeaderSourceCode){
+ return "";
+ }
+ else{
+ return "OUString";
+ }
+ }
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode){
+ if (_bAsHeaderSourceCode){
+ return "com/sun/star/uno/XInterface";
+ }
+ else{
+ return "XInterface";
+ }
+ }
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean bIsArray, TypeClass _aTypeClass, boolean _bInitialize){
+ boolean bIsPrimitive = Introspector.isPrimitive(_aTypeClass);
+
+ String sReturn = "";
+ if (bIsArray){
+ bIncludeSequenceHeader = true;
+ sReturn = getCSSNameSpaceString() + "::uno::Sequence<" + _sTypeString + "> " + _sVariableName;
+ }
+ else{
+ if (bIsPrimitive){
+ sReturn = _sTypeString + " " + _sVariableName;
+ if (_bInitialize){
+ switch (_aTypeClass.getValue()){
+ case TypeClass.BOOLEAN_value:
+ sReturn = sReturn + " = false";
+ break;
+ case TypeClass.BYTE_value:
+ case TypeClass.UNSIGNED_SHORT_value:
+ case TypeClass.SHORT_value:
+ case TypeClass.LONG_value:
+ case TypeClass.UNSIGNED_LONG_value:
+ case TypeClass.HYPER_value:
+ case TypeClass.UNSIGNED_HYPER_value:
+ sReturn = sReturn + " = 0";
+ break;
+ case TypeClass.DOUBLE_value:
+ case TypeClass.FLOAT_value:
+ sReturn = sReturn + " = 0.0";
+ break;
+ case TypeClass.CHAR_value:
+ sReturn = sReturn + "'0'";
+ break;
+ case TypeClass.STRING_value:
+ sReturn = _sTypeString + " " + _sVariableName;
+ break;
+ default:
+ sReturn = _sTypeString + " " + _sVariableName;
+ System.out.println("Type " + _aTypeClass.getValue() + " not yet defined in 'getVariableDeclaration()'");
+ }
+ }
+ }
+ else{
+ sReturn = getCSSNameSpaceString() + "::uno::Reference<" + _sTypeString + "> " +_sVariableName;
+ }
+ }
+ return sReturn;
+ }
+
+ public String getCommentSign(){
+ return "//";
+ }
+
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingDialogProvider.java b/odk/examples/java/Inspector/SwingDialogProvider.java
new file mode 100644
index 000000000..e66bedce8
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingDialogProvider.java
@@ -0,0 +1,444 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.uno.XComponentContext;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import javax.swing.ButtonGroup;
+import javax.swing.JDialog;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JTabbedPane;
+import javax.swing.KeyStroke;
+
+
+
+public class SwingDialogProvider implements XDialogProvider{
+
+ private JPopupMenu m_jPopupMenu = new JPopupMenu();
+ private XComponentContext m_xComponentContext;
+ private Inspector._Inspector m_oInspector;
+ private JDialog m_jInspectorDialog = new JDialog();
+ private JTabbedPane m_jTabbedPane1 = new JTabbedPane();
+ private Container cp;
+
+ private JMenu jMnuOptions = new JMenu("Options");
+ private JRadioButtonMenuItem jJavaMenuItem = null;
+ private JRadioButtonMenuItem jCPlusPlusMenuItem = null;
+ private JRadioButtonMenuItem jBasicMenuItem = null;
+
+ /** Creates a new instance of SwingPopupMentuProvider */
+ public SwingDialogProvider(Inspector._Inspector _oInspector, String _sTitle) {
+ m_oInspector = _oInspector;
+ m_xComponentContext = _oInspector.getXComponentContext();
+ insertMenus();
+ initializePopupMenu();
+ cp = m_jInspectorDialog.getContentPane();
+ cp.setLayout(new java.awt.BorderLayout(0, 10));
+ m_jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
+ m_jInspectorDialog.addWindowListener(new InspectorWindowAdapter());
+ m_jInspectorDialog.addComponentListener(new InspectorComponentAdapter());
+ m_jInspectorDialog.setTitle(_sTitle);
+ m_jInspectorDialog.setLocation(100, 50);
+ m_jInspectorDialog.getContentPane().add(m_jTabbedPane1);
+ }
+
+
+
+ public JDialog getDialog(){
+ return m_jInspectorDialog;
+ }
+
+
+ private void addMenuBar(JMenuBar _jMenuBar){
+ getDialog().setJMenuBar(_jMenuBar);
+ }
+
+
+ private void removeTabPaneByIndex(int _nIndex){
+ if (_nIndex > -1){
+ String sSelInspectorPanelTitle = m_jTabbedPane1.getTitleAt(_nIndex);
+ m_jTabbedPane1.remove(_nIndex);
+ m_oInspector.getInspectorPages().remove(sSelInspectorPanelTitle);
+ }
+ }
+
+
+ public void selectInspectorPageByIndex(int nTabIndex){
+ m_jTabbedPane1.setSelectedIndex(nTabIndex);
+ }
+
+
+ public int getInspectorPageCount(){
+ return m_jTabbedPane1.getTabCount();
+ }
+
+
+ public JTabbedPane getTabbedPane(){
+ return m_jTabbedPane1;
+ }
+
+
+ public InspectorPane getSelectedInspectorPage(){
+ int nIndex = m_jTabbedPane1.getSelectedIndex();
+ return getInspectorPage(nIndex);
+ }
+
+
+ public InspectorPane getInspectorPage(int _nIndex){
+ InspectorPane oInspectorPane = null;
+ if (_nIndex > -1){
+ String sInspectorPanelTitle = m_jTabbedPane1.getTitleAt(_nIndex);
+ oInspectorPane = m_oInspector.getInspectorPages().get(sInspectorPanelTitle);
+ }
+ return oInspectorPane;
+ }
+
+
+ private void removeTabPanes(){
+ int nCount = m_jTabbedPane1.getTabCount();
+ if (nCount > 0){
+ for (int i = nCount-1; i >= 0; i--){
+ removeTabPaneByIndex(i);
+ }
+ }
+ }
+
+ private void removeSelectedTabPane(){
+ int nIndex = getTabbedPane().getSelectedIndex();
+ removeTabPaneByIndex(nIndex);
+ }
+
+
+ private class InspectorComponentAdapter extends ComponentAdapter{
+ @Override
+ public void componentHidden(ComponentEvent e){
+ m_jInspectorDialog.pack();
+ m_jInspectorDialog.invalidate();
+
+ }
+
+ @Override
+ public void componentShown(ComponentEvent e){
+ m_jInspectorDialog.pack();
+ m_jInspectorDialog.invalidate();
+ }
+ }
+
+ private class InspectorWindowAdapter extends WindowAdapter{
+ @Override
+ public void windowClosed(WindowEvent e){
+ removeTabPanes();
+ m_oInspector.disposeHiddenDocuments();
+ }
+
+ @Override
+ public void windowClosing(WindowEvent e){
+ removeTabPanes();
+ m_oInspector.disposeHiddenDocuments();
+ }
+ }
+
+
+
+ private void initializePopupMenu(){
+ m_jPopupMenu.add(getInspectMenuItem("Inspect"));
+ m_jPopupMenu.add(getSourceCodeMenuItem(SADDTOSOURCECODE));
+ m_jPopupMenu.add(getInvokeMenuItem(SINVOKE));
+ m_jPopupMenu.addSeparator();
+ m_jPopupMenu.add(getHelpMenuItem("Help"));
+ }
+
+
+ private void addOpenDocumentMenu(JMenu _jMnuRoot){
+ ActionListener oActionListener = new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ String sTDocUrl = evt.getActionCommand();
+ m_oInspector.inspectOpenDocument(sTDocUrl);
+ }
+ };
+ String[] sTDocUrls = m_oInspector.getTDocUrls();
+ String[] sTDocTitles = m_oInspector.getTDocTitles(sTDocUrls);
+ for (int i = 0; i < sTDocUrls.length; i++){
+ addSingleMenuItem(_jMnuRoot, sTDocTitles[i], sTDocUrls[i], oActionListener);
+ }
+ }
+
+
+ private void addApplicationDocumentMenu(JMenu _jMnuRoot){
+ ActionListener oActionListener = new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ String sApplicationDocUrl = evt.getActionCommand();
+ m_oInspector.inspectOpenEmptyDocument(sApplicationDocUrl);
+ }
+ };
+ String[][] sApplUrls = m_oInspector.getApplicationUrls();
+ for (int i = 0; i < sApplUrls.length; i++){
+ addSingleMenuItem(_jMnuRoot, sApplUrls[i][1], sApplUrls[i][0], oActionListener);
+ }
+ }
+
+
+ private void addSingleMenuItem(JMenu _jMnuOpenDocs, String _sTitle, String _sActionCommand, ActionListener _oActionListener){
+ javax.swing.JMenuItem jMnuItemOpenDoc = new javax.swing.JMenuItem(_sTitle);
+ jMnuItemOpenDoc.setActionCommand(_sActionCommand);
+ jMnuItemOpenDoc.addActionListener(_oActionListener);
+ _jMnuOpenDocs.add(jMnuItemOpenDoc);
+ }
+
+
+ private void addHelpMenu(JMenuBar _jInspectMenuBar){
+ JMenu jMnuHelp = new JMenu("Help");
+ jMnuHelp.add(getHelpMenuItem("Idl-Help"));
+ _jInspectMenuBar.add(jMnuHelp);
+ }
+
+
+ private JMenuItem getHelpMenuItem(String _sMenuTitle){
+ JMenuItem jMnuHelpItem = new JMenuItem(_sMenuTitle);
+ jMnuHelpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
+ jMnuHelpItem.setMnemonic('H');
+ jMnuHelpItem.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.openIdlFileforSelectedNode();
+ }
+ });
+ return jMnuHelpItem;
+ }
+
+ private void addFileMenu(JMenuBar _jInspectMenuBar){
+ JMenu jMnuFile = new JMenu("File");
+ JMenuItem jMnuItemRemoveInspector = new JMenuItem("Remove");
+ jMnuItemRemoveInspector.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ removeSelectedTabPane();
+ }
+ });
+ jMnuFile.add(jMnuItemRemoveInspector);
+ JMenuItem jMnuItemExit = new JMenuItem("Exit");
+ jMnuItemExit.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ getDialog().dispose();
+ }
+ });
+ jMnuFile.add(jMnuItemExit);
+ _jInspectMenuBar.add(jMnuFile);
+ }
+
+ private JMenuItem getInspectMenuItem(String _sLabel){
+ JMenuItem jMnuSelectedObject = new JMenuItem(_sLabel);
+ jMnuSelectedObject.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.inspectSelectedNode();
+ }
+ });
+ return jMnuSelectedObject;
+ }
+
+
+ private JMenuItem getSourceCodeMenuItem(String _sLabel){
+ JMenuItem jMnuSelectedObject = new JMenuItem(_sLabel);
+ jMnuSelectedObject.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.addSourceCodeOfSelectedNode();
+ }
+ });
+ return jMnuSelectedObject;
+ }
+
+ private JMenuItem getInvokeMenuItem(String _sLabel){
+ JMenuItem jMnuSelectedObject = new JMenuItem(_sLabel);
+ jMnuSelectedObject.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.invokeSelectedMethod();
+ }
+ });
+ return jMnuSelectedObject;
+ }
+
+
+ private void addInspectMenu(JMenuBar _jInspectMenuBar){
+ JMenu jMnuInspect = new JMenu("Inspect");
+ addApplicationDocumentMenu(jMnuInspect);
+ jMnuInspect.addSeparator();
+ addGlobalServiceManagerMenu(jMnuInspect);
+ jMnuInspect.addSeparator();
+ jMnuInspect.add(getInspectMenuItem("Selected Object"));
+ jMnuInspect.addSeparator();
+ addOpenDocumentMenu(jMnuInspect);
+ _jInspectMenuBar.add(jMnuInspect);
+ }
+
+ public int getLanguage(){
+ return XLanguageSourceCodeGenerator.nJAVA;
+ }
+
+
+ public void selectSourceCodeLanguage(int _nLanguage){
+ switch (_nLanguage){
+ case XLanguageSourceCodeGenerator.nJAVA:
+ jJavaMenuItem.setSelected(true);
+ break;
+ case XLanguageSourceCodeGenerator.nCPLUSPLUS:
+ jCPlusPlusMenuItem.setSelected(true);
+ break;
+ case XLanguageSourceCodeGenerator.nBASIC:
+ jBasicMenuItem.setSelected(true);
+ break;
+ default:
+ System.out.println("Warning: Sourcecode language is not defined!");
+ }
+ }
+
+ private JRadioButtonMenuItem addLanguageMenuItem(ButtonGroup _group, String _sLanguageTitle, boolean _bSelect, char _sMnemonic, final int _nLanguage){
+ JRadioButtonMenuItem jMenuItem = new JRadioButtonMenuItem(_sLanguageTitle, _bSelect);
+ jMenuItem.setMnemonic(_sMnemonic);
+ _group.add(jMenuItem);
+ jMenuItem.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.setSourceCodeLanguage(_nLanguage);
+ }
+ });
+ return jMenuItem;
+ }
+
+
+ public String getIDLPath(){
+ return this.m_oInspector.getIDLPath();
+ }
+
+ private void addOptionsMenu(JMenuBar _jInspectMenuBar){
+ ButtonGroup oButtonGroup = new ButtonGroup();
+ jJavaMenuItem = addLanguageMenuItem(oButtonGroup, "Generate Java Sourcecode", true, 'J', XLanguageSourceCodeGenerator.nJAVA);
+ jMnuOptions.add(jJavaMenuItem);
+ jCPlusPlusMenuItem = addLanguageMenuItem(oButtonGroup, "Generate C++ Sourcecode", false, 'C', XLanguageSourceCodeGenerator.nCPLUSPLUS);
+ jMnuOptions.add(jCPlusPlusMenuItem);
+ jBasicMenuItem = addLanguageMenuItem(oButtonGroup, "Generate OpenOffice.org Basic Sourcecode", false, 'B', XLanguageSourceCodeGenerator.nBASIC);
+ jMnuOptions.add(jBasicMenuItem);
+ jMnuOptions.addSeparator();
+ JMenuItem jMenuItem = new JMenuItem("Path to SDK-Installation");
+ jMenuItem.setMnemonic('I');
+ jMenuItem.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.assignSDKPath();
+ }
+ });
+
+ jMnuOptions.add(jMenuItem);
+ _jInspectMenuBar.add(jMnuOptions);
+ }
+
+
+ private void insertMenus(){
+ JMenuBar jMenuBar1 = new javax.swing.JMenuBar();
+ addFileMenu(jMenuBar1);
+ addInspectMenu(jMenuBar1);
+ JMenu jMnuEdit = new JMenu("Edit");
+ JMenu jMnuView = new JMenu("View");
+ addOptionsMenu(jMenuBar1);
+ jMenuBar1.setFont(new java.awt.Font("Dialog", 0, 12));
+ jMenuBar1.add(jMnuEdit);
+ jMenuBar1.add(jMnuView);
+ addHelpMenu(jMenuBar1);
+ addMenuBar(jMenuBar1);
+ }
+
+ private void addGlobalServiceManagerMenu(JMenu _jMnuRoot){
+ JMenuItem jMnuGlobalServiceManager = new JMenuItem("Global Service Manager");
+ jMnuGlobalServiceManager.addActionListener(new ActionListener(){
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ m_oInspector.inspect(m_xComponentContext.getServiceManager(), "Global ServiceManager");
+ }
+ });
+ _jMnuRoot.add(jMnuGlobalServiceManager);
+ }
+
+
+
+ public void enablePopupMenuItem(String _sMenuTitle, boolean _bdoEnable){
+ Component[] oComponents = m_jPopupMenu.getComponents();
+ for (int i = 0; i < oComponents.length; i++){
+ if (oComponents[i] instanceof JMenuItem){
+ JMenuItem jMenuItem = (JMenuItem) oComponents[i];
+ if (jMenuItem.getText().equals(_sMenuTitle)){
+ jMenuItem.setEnabled(_bdoEnable);
+ }
+ }
+ }
+ }
+
+
+ public void showPopUpMenu(Object _invoker, int x, int y) throws ClassCastException{
+ if (_invoker instanceof Component){
+ m_jPopupMenu.show((Component) _invoker, x, y);
+ }
+ }
+
+
+ public void show(int _nPageIndex){
+ Dimension aDimension = m_jInspectorDialog.getSize();
+ selectInspectorPageByIndex(_nPageIndex);
+ if (_nPageIndex > 0){
+ m_jInspectorDialog.setSize(aDimension);
+ }
+ else{
+ m_jInspectorDialog.pack();
+ }
+ m_jInspectorDialog.setVisible(true);
+ }
+
+ public void paint(){
+ m_jTabbedPane1.paintImmediately(m_jTabbedPane1.getBounds());
+ }
+
+
+ public void addInspectorPage(String _sTitle, Object _oContainer) throws ClassCastException{
+ if (_oContainer instanceof Component){
+ m_jTabbedPane1.addTab(_sTitle, (Component) _oContainer);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingTreeControlProvider.java b/odk/examples/java/Inspector/SwingTreeControlProvider.java
new file mode 100644
index 000000000..c8cbb4dcb
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingTreeControlProvider.java
@@ -0,0 +1,423 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.lang.NullPointerException;
+import com.sun.star.reflection.XConstantTypeDescription;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.Type;
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.JPanel;
+import javax.swing.JScrollBar;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.JTree;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.event.TreeWillExpandListener;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.ExpandVetoException;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+
+
+
+public class SwingTreeControlProvider implements XTreeControlProvider{
+ private JTextArea jtxtGeneratedSourceCode = new JTextArea();
+ private JTextField jtxtFilter = new JTextField();
+ private javax.swing.JLabel jlblFilter = new javax.swing.JLabel("Set a filter");
+ private JTree jTree = new javax.swing.JTree();
+ private XDialogProvider m_xDialogProvider;
+ private HideableTreeModel treeModel;
+ private InspectorPane m_oInspectorPane;
+ private Object oUserDefinedObject = null;
+ private boolean bIsUserDefined = false;
+ private SwingUnoNode oRootNode;
+
+ private final int nDIALOGWIDTH = 800;
+
+
+
+ public SwingTreeControlProvider(XDialogProvider _xDialogProvider){
+ m_xDialogProvider = _xDialogProvider;
+ }
+
+
+ public void addInspectorPane(InspectorPane _oInspectorPane){
+ m_oInspectorPane = _oInspectorPane;
+ }
+
+ public InspectorPane getInspectorPane() throws NullPointerException{
+ if (m_oInspectorPane == null){
+ throw new NullPointerException("InspectorPage has not been added to TreeControl");
+ }
+ else{
+ return m_oInspectorPane;
+ }
+ }
+
+ private void ComponentSelector(Object _oRootObject, String _sRootTreeNodeName) {
+ oRootNode = new SwingUnoNode(_oRootObject);
+ oRootNode.setLabel(_sRootTreeNodeName);
+ treeModel = new HideableTreeModel(oRootNode);
+ jTree.setModel(treeModel);
+ jTree.setRootVisible(true);
+ jTree.setVisible(true);
+ oRootNode.setFoldable(true);
+ enableFilterElements(null);
+ }
+
+
+
+ private void insertTopPanel(JPanel _jPnlCenter){
+ javax.swing.JPanel jPnlTop = new javax.swing.JPanel(new BorderLayout(10, 10));
+ jPnlTop.setPreferredSize(new java.awt.Dimension(nDIALOGWIDTH, 20));
+ jlblFilter.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
+ jlblFilter.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
+ jPnlTop.add(jlblFilter, java.awt.BorderLayout.WEST);
+ jtxtFilter.setHorizontalAlignment(javax.swing.JTextField.LEFT);
+ jtxtFilter.setPreferredSize(new java.awt.Dimension(200, 10));
+ jtxtFilter.addKeyListener(new InspectorKeyFilterAdapter());
+ jPnlTop.add(jtxtFilter, java.awt.BorderLayout.CENTER);
+ _jPnlCenter.add(jPnlTop, java.awt.BorderLayout.NORTH);
+ }
+
+
+ private void insertBottomPanel(JSplitPane _jSplitPane){ //JPanel _jPnlCenter){
+ jtxtGeneratedSourceCode.setTabSize(4);
+ jtxtGeneratedSourceCode.getAccessibleContext().setAccessibleName("generated SourceCode");
+ JScrollPane jScrollPane = new JScrollPane(jtxtGeneratedSourceCode);
+ jScrollPane.setPreferredSize(new Dimension(nDIALOGWIDTH,205));
+ jtxtGeneratedSourceCode.setEditable(false);
+ _jSplitPane.setBottomComponent(jScrollPane);
+ }
+
+ private void insertBorderPanes(Container _cp){
+ JPanel jPnlEast = new JPanel(new BorderLayout());
+ JPanel jPnlNorth = new JPanel(new BorderLayout());
+ JPanel jPnlSouth = new JPanel(new BorderLayout());
+ JPanel jPnlWest = new JPanel(new BorderLayout());
+ _cp.add(jPnlNorth, java.awt.BorderLayout.NORTH);
+ jPnlWest.setPreferredSize(new java.awt.Dimension(10, 10));
+ _cp.add(jPnlWest, java.awt.BorderLayout.WEST);
+ jPnlEast.setPreferredSize(new java.awt.Dimension(10, 10));
+ _cp.add(jPnlEast, java.awt.BorderLayout.EAST);
+ jPnlSouth.setPreferredSize(new java.awt.Dimension(10, 10));
+ _cp.add(jPnlSouth, java.awt.BorderLayout.SOUTH);
+ }
+
+
+ public String enableFilterElements(XUnoNode _oUnoNode){
+ String sFilter ="";
+ boolean bIsFacetteNode = isFacetteNode(_oUnoNode);
+ this.jtxtFilter.setEnabled(bIsFacetteNode);
+ this.jlblFilter.setEnabled(bIsFacetteNode);
+ sFilter = m_oInspectorPane.getFilter(_oUnoNode);
+ jtxtFilter.setText(sFilter);
+ return sFilter;
+ }
+
+
+ private class InspectorKeyFilterAdapter extends KeyAdapter{
+ @Override
+ public void keyReleased(KeyEvent e){
+ String sFilter = jtxtFilter.getText();
+ SwingTreePathProvider oSwingTreePathProvider = new SwingTreePathProvider(jTree.getSelectionPath());
+ XUnoNode oUnoNode = oSwingTreePathProvider.getLastPathComponent();
+ if (oUnoNode instanceof XUnoFacetteNode){
+ m_oInspectorPane.applyFilter((XUnoFacetteNode) oUnoNode, sFilter);
+ }
+ }
+ }
+
+
+
+ /** Inspect the given object for methods, properties, interfaces, and
+ * services.
+ * @param _oUserDefinedObject The object to inspect
+ * @throws RuntimeException If
+ */
+ public Object inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException {
+ JPanel jPnlContainer = new javax.swing.JPanel(new BorderLayout(10, 10));
+ try {
+ javax.swing.JPanel jPnlCenter = new javax.swing.JPanel();
+ bIsUserDefined = (_oUserDefinedObject != null);
+ if (bIsUserDefined){
+ oUserDefinedObject = _oUserDefinedObject;
+ m_oInspectorPane.setTitle(_sTitle);
+ }
+ javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
+ TreeSelectionModel tsm = new DefaultTreeSelectionModel();
+ tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ jTree.setSelectionModel(tsm);
+ jTree.setVisible(false);
+ jPnlCenter.setLayout(new java.awt.BorderLayout(10, 10));
+ jPnlCenter.getAccessibleContext().setAccessibleName("inspection tab view");
+ insertTopPanel(jPnlCenter);
+ jScrollPane1.setViewportView(jTree);
+ jScrollPane1.setPreferredSize(new java.awt.Dimension(600, 600));
+ jScrollPane1.getAccessibleContext().setAccessibleName("API view scroll pane");
+
+ JScrollBar jHScrollBar = jScrollPane1.createHorizontalScrollBar();
+ jHScrollBar.getAccessibleContext().setAccessibleName("API view horizontal scroll bar");
+ jScrollPane1.setHorizontalScrollBar(jHScrollBar);
+
+ JScrollBar jVScrollBar = jScrollPane1.createVerticalScrollBar();
+ jVScrollBar.getAccessibleContext().setAccessibleName("API view vertical scroll bar");
+ jScrollPane1.setVerticalScrollBar(jVScrollBar);
+
+ JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ jSplitPane.setTopComponent(jScrollPane1);
+ jPnlCenter.add(jSplitPane, java.awt.BorderLayout.CENTER);
+ jSplitPane.setDividerLocation(500);
+ insertBottomPanel(jSplitPane);
+ UnoTreeRenderer oUnoTreeRenderer = new UnoTreeRenderer();
+ jTree.setCellRenderer(oUnoTreeRenderer);
+ jTree.addTreeSelectionListener(
+ new TreeSelectionListener() {
+ public void valueChanged(TreeSelectionEvent event) {
+ TreePath tp = event.getNewLeadSelectionPath();
+ if (tp != null){
+ XUnoNode oUnoNode = getSelectedNode();
+ String sFilter = enableFilterElements(oUnoNode);
+ }
+ }
+ }
+ );
+ // Add KeyListener for help
+ jTree.addKeyListener( new java.awt.event.KeyAdapter() {
+ @Override
+ public void keyReleased(java.awt.event.KeyEvent event) {
+ if ( event.getKeyCode() == KeyEvent.VK_F1 ) {
+ // function key F1 pressed
+ TreePath aTreePath = jTree.getSelectionPath();
+ SwingUnoNode oUnoNode = (SwingUnoNode) aTreePath.getLastPathComponent();
+ oUnoNode.openIdlDescription(m_xDialogProvider.getIDLPath());
+ }
+ }
+ });
+ jTree.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed (MouseEvent e) {
+ if (e.isPopupTrigger()){
+ m_oInspectorPane.showPopUpMenu(e.getComponent(), e.getX(), e.getY());
+ }
+ //unfortunately under Windows the method "isPopupTrigger" always returns false
+ else if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK){
+ m_oInspectorPane.showPopUpMenu(e.getComponent(), e.getX(), e.getY());
+ }
+ }
+ });
+ jPnlContainer.add(jPnlCenter, java.awt.BorderLayout.CENTER);
+ insertBorderPanes(jPnlContainer);
+ if (this.bIsUserDefined){
+ ComponentSelector(oUserDefinedObject, m_oInspectorPane.getTitle());
+ }
+ m_xDialogProvider.addInspectorPage(m_oInspectorPane.getTitle(), jPnlContainer);
+ addTreeExpandListener();
+ }
+ catch( Exception exception ) {
+ exception.printStackTrace(System.err);
+ }
+ return jPnlContainer;
+ }
+
+ public HideableTreeModel getModel(){
+ return treeModel;
+ }
+
+
+ public void addTreeExpandListener(){
+ jTree.addTreeWillExpandListener(
+ new TreeWillExpandListener() {
+ public void treeWillExpand(javax.swing.event.TreeExpansionEvent event) throws javax.swing.tree.ExpandVetoException {
+ SwingTreePathProvider oSwingTreePathProvider = new SwingTreePathProvider(event.getPath());
+ XUnoNode oUnoNode = oSwingTreePathProvider.getLastPathComponent();
+ if (!m_oInspectorPane.expandNode(oUnoNode)){
+ throw new ExpandVetoException(event);
+ }
+ }
+
+ public void treeWillCollapse( javax.swing.event.TreeExpansionEvent evt) throws javax.swing.tree.ExpandVetoException {
+ }
+ });
+ }
+
+
+ public void setSourceCode(String _sSourceCode){
+ jtxtGeneratedSourceCode.setText(_sSourceCode);
+ }
+
+
+ public XTreePathProvider getSelectedPath(){
+ return new SwingTreePathProvider(jTree.getSelectionPath());
+ }
+
+
+ public void expandPath(XTreePathProvider _xTreePathProvider) throws ClassCastException{
+ SwingTreePathProvider oSwingTreePathProvider = (SwingTreePathProvider) _xTreePathProvider;
+ jTree.expandPath(oSwingTreePathProvider.getSwingTreePath());
+ }
+
+
+ public XUnoNode getSelectedNode(){
+ XUnoNode oUnoNode = null;
+ TreePath aTreePath = jTree.getSelectionPath();
+ Object oNode = aTreePath.getLastPathComponent();
+ if (oNode instanceof XUnoNode){
+ oUnoNode = (XUnoNode) oNode;
+ }
+ return oUnoNode;
+ }
+
+
+ public void nodeInserted(XUnoNode _oParentNode, XUnoNode _oChildNode, int index) {
+ getModel().nodeInserted(_oParentNode, _oChildNode, _oParentNode.getChildCount()-1);
+ }
+
+
+ public void nodeChanged(XUnoNode _oNode) {
+ getModel().nodeChanged(_oNode);
+ }
+
+
+ public boolean setNodeVisible(Object node, boolean v) {
+ return getModel().setNodeVisible(node, v);
+ }
+
+
+ public boolean isPropertyNode(XUnoNode _oUnoNode){
+ return (_oUnoNode instanceof SwingUnoPropertyNode);
+ }
+
+
+ public boolean isMethodNode(XUnoNode _oUnoNode){
+ return (_oUnoNode instanceof SwingUnoMethodNode);
+ }
+
+
+ public boolean isFacetteNode(XUnoNode _oUnoNode){
+ return (_oUnoNode instanceof SwingUnoFacetteNode);
+ }
+
+
+ public XUnoNode addUnoNode(Object _oUnoObject){
+ return new SwingUnoNode(_oUnoObject);
+ }
+
+
+ public XUnoNode addUnoNode(Object _oUnoObject, Type _aType){
+ return new SwingUnoNode(_oUnoObject, _aType);
+ }
+
+
+ public XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject){
+ SwingUnoFacetteNode oSwingUnoFacetteNode = new SwingUnoFacetteNode(_oUnoObject);
+ oSwingUnoFacetteNode.setLabel(_sNodeDescription);
+ if (_oParentNode != null){
+ ((SwingUnoNode) _oParentNode).addChildNode(oSwingUnoFacetteNode);
+ }
+ return oSwingUnoFacetteNode;
+ }
+
+
+ public XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod){
+ SwingUnoMethodNode oSwingUnoMethodNode = new SwingUnoMethodNode(_xIdlMethod, _objectElement, m_xDialogProvider);
+ return oSwingUnoMethodNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithName(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ oUnoPropertyNode.setLabel("Name: " + _aProperty.Name);
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithHandle(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ oUnoPropertyNode.setLabel("Handle: " + _aProperty.Handle);
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithType(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ oUnoPropertyNode.setLabel("Type: " + _aProperty.Type.getTypeName());
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNodeWithAttributesDescription(Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty);
+ XConstantTypeDescription[] xPropertyAttributesTypeDescriptions = Introspector.getIntrospector().getFieldsOfConstantGroup("com.sun.star.beans.PropertyAttribute");
+ String sDisplay = Introspector.getIntrospector().getConstantDisplayString(_aProperty.Attributes, xPropertyAttributesTypeDescriptions, "Attributes: ");
+ oUnoPropertyNode.setLabel(sDisplay);
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty, _oUnoObject, null);
+ oUnoPropertyNode.setPropertyNodeType(XUnoPropertyNode.nPROPERTYSETINFOTYPE);
+ oUnoPropertyNode.setLabel(UnoPropertyNode.getStandardPropertyDescription(_aProperty, null));
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty, Object _oUnoReturnObject){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aProperty, _oUnoObject, _oUnoReturnObject);
+ oUnoPropertyNode.setLabel(UnoPropertyNode.getStandardPropertyDescription(_aProperty, _oUnoReturnObject));
+ return oUnoPropertyNode;
+ }
+
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, PropertyValue _aPropertyValue, Object _oReturnObject){
+ SwingUnoPropertyNode oUnoPropertyNode = new SwingUnoPropertyNode(_aPropertyValue, _oUnoObject, _oReturnObject);
+ oUnoPropertyNode.setLabel(UnoPropertyNode.getStandardPropertyValueDescription(_aPropertyValue));
+ return oUnoPropertyNode;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingTreePathProvider.java b/odk/examples/java/Inspector/SwingTreePathProvider.java
new file mode 100644
index 000000000..c0f6703ca
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingTreePathProvider.java
@@ -0,0 +1,60 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+import javax.swing.tree.TreePath;
+
+public class SwingTreePathProvider implements XTreePathProvider {
+ private TreePath m_aTreePath;
+
+ /** Creates a new instance of TreePathProvider */
+ public SwingTreePathProvider(TreePath _aTreePath) {
+ m_aTreePath = _aTreePath;
+ }
+
+
+ public XUnoNode getLastPathComponent(){
+ return (XUnoNode) m_aTreePath.getLastPathComponent();
+ }
+
+
+ public XUnoNode getPathComponent(int i){
+ return (XUnoNode) m_aTreePath.getPathComponent(i);
+ }
+
+ public int getPathCount(){
+ return m_aTreePath.getPathCount();
+ }
+
+
+ public XTreePathProvider getParentPath(){
+ return new SwingTreePathProvider(m_aTreePath.getParentPath());
+ }
+
+
+ public XTreePathProvider pathByAddingChild(XUnoNode _oUnoNode){
+ TreePath aTreePath = m_aTreePath.pathByAddingChild(_oUnoNode);
+ return new SwingTreePathProvider(aTreePath);
+ }
+
+ public TreePath getSwingTreePath(){
+ return m_aTreePath;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoFacetteNode.java b/odk/examples/java/Inspector/SwingUnoFacetteNode.java
new file mode 100644
index 000000000..31a80ffd9
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoFacetteNode.java
@@ -0,0 +1,84 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+
+public class SwingUnoFacetteNode extends SwingUnoNode implements XUnoFacetteNode{
+ private String m_sFilter = "";
+
+ /** Creates a new instance of UnoMethodNode */
+ public SwingUnoFacetteNode(Object _oUnoObject){
+ super(_oUnoObject);
+ setFoldable(true);
+ }
+
+
+ public String getFilter(){
+ return m_sFilter;
+ }
+
+ public void setFilter(String _sFilter){
+ m_sFilter = _sFilter;
+ }
+
+ @Override
+ public String getName(){
+ return toString();
+ }
+
+// TODO The implementation of the following methods is not really robust and should be changed!!!
+ public boolean isMethodNode(){
+ return ((String) getUserObject()).equals(SMETHODDESCRIPTION);
+ }
+
+ public boolean isPropertyNode(){
+ String sNodeDescription = (String) getUserObject();
+ return ((sNodeDescription.equals(SPROPERTYDESCRIPTION)) || (sNodeDescription.equals(SPROPERTYINFODESCRIPTION)) || (sNodeDescription.equals(SPROPERTYVALUEDESCRIPTION)));
+ }
+
+ public boolean isContainerNode(){
+ return ((String) getUserObject()).equals(SCONTAINERDESCRIPTION);
+ }
+
+ public boolean isServiceNode(){
+ return ((String) getUserObject()).equals(SSERVICEDESCRIPTION);
+ }
+
+ public boolean isInterfaceNode(){
+ return ((String) getUserObject()).equals(SINTERFACEDESCRIPTION);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoMethodNode.java b/odk/examples/java/Inspector/SwingUnoMethodNode.java
new file mode 100644
index 000000000..f06f2161c
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoMethodNode.java
@@ -0,0 +1,144 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+
+
+public class SwingUnoMethodNode extends SwingUnoNode implements ActionListener, XUnoMethodNode{
+
+ private UnoMethodNode m_oUnoMethodNode;
+ private XDialogProvider m_xDialogProvider = null;
+
+ public SwingUnoMethodNode(XIdlMethod _xIdlMethod, Object _oUnoObject, XDialogProvider _xDialogProvider) {
+ super(_oUnoObject);
+ m_oUnoMethodNode = new UnoMethodNode(_xIdlMethod, _oUnoObject, this);
+ m_xDialogProvider = _xDialogProvider;
+ setUserObject(m_oUnoMethodNode.getNodeDescription());
+ if (m_oUnoMethodNode.isFoldable()){
+ setFoldable(true);
+ }
+ }
+
+ public boolean isFoldable(){
+ return m_oUnoMethodNode.isFoldable();
+ }
+
+ @Override
+ public String getName(){
+ return m_oUnoMethodNode.getName();
+ }
+
+ @Override
+ public String getClassName(){
+ String sClassName = "";
+ sClassName = getXIdlMethod().getDeclaringClass().getName();
+ if (sClassName.equals("")){
+ sClassName = super.getClassName();
+ }
+ return sClassName;
+ }
+
+ @Override
+ public String getAnchor(){
+ return m_oUnoMethodNode.getAnchor();
+ }
+
+ public Object invoke(Object _oUnoObject, Object[] _oParameters) throws com.sun.star.uno.Exception{
+ return m_oUnoMethodNode.invoke(_oUnoObject, _oParameters);
+ }
+
+
+ public Object[] getLastParameterObjects(){
+ return m_oUnoMethodNode.getLastParameterObjects();
+ }
+
+ public Object getLastUnoReturnObject(){
+ return m_oUnoMethodNode.getLastUnoReturnObject();
+ }
+
+ public TypeClass getTypeClass() {
+ return m_oUnoMethodNode.getTypeClass();
+ }
+
+ public XIdlMethod getXIdlMethod() {
+ return m_oUnoMethodNode.getXIdlMethod();
+ }
+
+ public boolean hasParameters() {
+ return m_oUnoMethodNode.hasParameters();
+ }
+
+ public Object invoke() throws com.sun.star.uno.Exception{
+ return m_oUnoMethodNode.invoke();
+ }
+
+ public boolean isInvoked() {
+ return m_oUnoMethodNode.isInvoked();
+ }
+
+ public boolean isInvokable(){
+ return m_oUnoMethodNode.isInvokable();
+ }
+
+ public boolean isPrimitive() {
+ return m_oUnoMethodNode.isPrimitive();
+ }
+
+ public void actionPerformed(ActionEvent e){
+ openIdlDescription(m_xDialogProvider.getIDLPath());
+ }
+
+ public ArrayList<Object> getMethodObjects(){
+ MethodParametersDialog oMethodParametersDialog = new MethodParametersDialog(this);
+ oMethodParametersDialog.addActionListener(this);
+ return oMethodParametersDialog.getMethodObjects();
+ }
+
+
+ public String getParameterDescription(){
+ return m_oUnoMethodNode.getParameterDescription();
+ }
+
+
+ public String getStandardMethodDescription(){
+ return m_oUnoMethodNode.getStandardMethodDescription();
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoNode.java b/odk/examples/java/Inspector/SwingUnoNode.java
new file mode 100644
index 000000000..c1d84d85e
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoNode.java
@@ -0,0 +1,160 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.uno.Type;
+import javax.swing.tree.TreeNode;
+
+
+public class SwingUnoNode extends HideableMutableTreeNode implements XUnoNode{
+ private UnoNode m_oUnoNode;
+
+ /** Creates a new instance of SwingUnoNode */
+ public SwingUnoNode(Object _oUnoObject) {
+ super();
+ m_oUnoNode = new UnoNode(_oUnoObject);
+ }
+
+
+ public SwingUnoNode(Object _oUnoObject, Type _aType) {
+ super();
+ m_oUnoNode = new UnoNode(_oUnoObject, _aType);
+ if (_aType != null){
+ this.setLabel(_aType.getTypeName());
+ }
+ }
+
+
+ public Object getUnoObject(){
+ return m_oUnoNode.getUnoObject();
+ }
+
+ public void setVisible(String _sFilter){
+ boolean bisVisible = isFilterApplicable(_sFilter);
+ super.setVisible(bisVisible);
+ }
+
+ public boolean isFilterApplicable(String _sFilter) {
+ return m_oUnoNode.isFilterApplicable(_sFilter, getName());
+ }
+
+ public void setParameterObjects(Object[] _oParamObjects) {
+ m_oUnoNode.setParameterObjects(_oParamObjects);
+ }
+
+ public void openIdlDescription(String _SDKPath) {
+ m_oUnoNode.openIdlDescription(_SDKPath, getClassName());
+ }
+
+ public Object[] getParameterObjects() {
+ return m_oUnoNode.getParameterObjects();
+ }
+
+ public String getClassName(){
+ String sClassName = m_oUnoNode.getClassName();
+ if (sClassName.equals("")){
+ TreeNode oTreeNode = getParent();
+ if (oTreeNode != null){
+ if (oTreeNode instanceof XUnoNode){
+ SwingUnoNode oUnoNode = (SwingUnoNode) oTreeNode;
+ sClassName = oUnoNode.getClassName();
+ }
+ }
+ }
+ return sClassName;
+ }
+
+ public String getAnchor() {
+ return m_oUnoNode.getAnchor();
+ }
+
+
+ public void setFoldable(boolean _bIsFoldable){
+ if (_bIsFoldable){
+ addDummyNode();
+ }
+ else{
+ removeDummyNode();
+ }
+ }
+
+
+ public XUnoNode getParentNode(){
+ return (SwingUnoNode) super.getParent();
+ }
+
+
+ public void addChildNode(XUnoNode _xUnoNode) {
+ super.add((SwingUnoNode) _xUnoNode);
+ }
+
+ public void setLabel(String _sLabel){
+ super.setUserObject(_sLabel);
+ this.m_oUnoNode.setLabel(_sLabel);
+ }
+
+ public String getLabel(){
+ return (String) super.getUserObject();
+ }
+
+
+ @Override
+ public int getChildCount(){
+ return super.getChildCount();
+ }
+
+
+ public XUnoNode getChild(int _i){
+ return (SwingUnoNode) super.getChildAt(_i);
+ }
+
+ public int getNodeType(){
+ return m_oUnoNode.getNodeType();
+ }
+
+ public void setNodeType(int _nNodeType){
+ m_oUnoNode.setNodeType(_nNodeType);
+ }
+
+
+ public String getName(){
+ return getClassName();
+ }
+
+
+ public Type getUnoType(){
+ return m_oUnoNode.getUnoType();
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/SwingUnoPropertyNode.java b/odk/examples/java/Inspector/SwingUnoPropertyNode.java
new file mode 100644
index 000000000..0e65a0361
--- /dev/null
+++ b/odk/examples/java/Inspector/SwingUnoPropertyNode.java
@@ -0,0 +1,102 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+
+public class SwingUnoPropertyNode extends SwingUnoNode implements XUnoPropertyNode{
+
+ private UnoPropertyNode m_oUnoPropertyNode = null;
+
+
+ public SwingUnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ m_oUnoPropertyNode = new UnoPropertyNode(_aProperty, _oUnoObject, _oUnoReturnObject);
+ super.setUserObject(m_oUnoPropertyNode.getLabel());
+ setFoldable(m_oUnoPropertyNode.isFoldable());
+ }
+
+
+ public SwingUnoPropertyNode(Property _aProperty){
+ super(null);
+ m_oUnoPropertyNode = new UnoPropertyNode(_aProperty);
+ }
+
+
+ public SwingUnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ m_oUnoPropertyNode = new UnoPropertyNode(_aPropertyValue, _oUnoObject, _oUnoReturnObject);
+ }
+
+ @Override
+ public String getName(){
+ return m_oUnoPropertyNode.getName();
+ }
+
+
+ public Object getUnoReturnObject(){
+ return m_oUnoPropertyNode.getUnoReturnObject();
+ }
+
+
+ @Override
+ public String getClassName(){
+ String sClassName = m_oUnoPropertyNode.getClassName();
+ if (sClassName.equals("")){
+ sClassName = super.getClassName();
+ }
+ return sClassName;
+ }
+
+ @Override
+ public String getAnchor(){
+ return m_oUnoPropertyNode.getAnchor();
+ }
+
+ public int getPropertyNodeType(){
+ return m_oUnoPropertyNode.getPropertyNodeType();
+ }
+
+
+ public void setPropertyNodeType(int _nPropertyType){
+ m_oUnoPropertyNode.setPropertyNodeType(_nPropertyType);
+ }
+
+ public Property getProperty(){
+ return m_oUnoPropertyNode.getProperty();
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/TDocSupplier.java b/odk/examples/java/Inspector/TDocSupplier.java
new file mode 100644
index 000000000..593c8a852
--- /dev/null
+++ b/odk/examples/java/Inspector/TDocSupplier.java
@@ -0,0 +1,166 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.sdbc.XRow;
+import com.sun.star.ucb.Command;
+import com.sun.star.ucb.UniversalContentBroker;
+import com.sun.star.ucb.XCommandProcessor;
+import com.sun.star.ucb.XContent;
+import com.sun.star.ucb.XContentIdentifier;
+import com.sun.star.ucb.XSimpleFileAccess;
+import com.sun.star.ucb.XUniversalContentBroker;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import javax.swing.JOptionPane;
+
+
+public class TDocSupplier {
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+
+
+ /** Creates a new instance of TDocSupplier */
+ public TDocSupplier(XComponentContext _xComponentContext) {
+ m_xComponentContext = _xComponentContext;
+ m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
+ }
+
+
+ private XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ private XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+ public XModel getXModelByTDocUrl(String _sTDocUrl){
+ try{
+ XRow xRow = getXRowOfTDocUrl(_sTDocUrl, "DocumentModel");
+ if (xRow != null){
+ Object oModel = xRow.getObject(1, null);
+ XModel xModel = UnoRuntime.queryInterface(XModel.class, oModel);
+ return xModel;
+ }
+ }catch(Exception exception){
+ exception.printStackTrace(System.err);
+ }
+ JOptionPane.showMessageDialog(new javax.swing.JFrame(), "The selected Document could not be opened!", "Object Inspector", JOptionPane.ERROR_MESSAGE);
+ return null;
+ }
+
+
+ public String getTitleByTDocUrl(String _sTDocUrl){
+ try{
+ XRow xRow = this.getXRowOfTDocUrl(_sTDocUrl, "Title");
+ if (xRow != null){
+ return xRow.getString(1);
+ }
+ }catch(Exception exception){
+ exception.printStackTrace(System.err);
+ }
+ JOptionPane.showMessageDialog(new javax.swing.JFrame(), "The selected Document could not be opened!", "Object Inspector", JOptionPane.ERROR_MESSAGE);
+ return "";
+ }
+
+
+ private XRow getXRowOfTDocUrl(String _sTDocUrl, String _sPropertyName){
+ try{
+ XUniversalContentBroker xUCB = UniversalContentBroker.create( getXComponentContext() );
+ XContentIdentifier xId = xUCB.createContentIdentifier(_sTDocUrl);
+ XContent xContent = xUCB.queryContent(xId);
+ XCommandProcessor xCmdProcessor = UnoRuntime.queryInterface(XCommandProcessor.class, xContent);
+ Property aProperty = new Property();
+ aProperty.Name = _sPropertyName; // "DocumentModel"; //DocumentModel
+ Command aCommand = new Command();
+ aCommand.Name = "getPropertyValues";
+ aCommand.Handle = -1; // not available
+ aCommand.Argument = new Property[]{aProperty};
+ Object oAny = xCmdProcessor.execute(aCommand, 0, null);
+ XRow xRow = UnoRuntime.queryInterface(XRow.class, oAny);
+ return xRow;
+ }catch(Exception exception){
+ exception.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ protected String[] getTDocTitles(String[] _sTDocUrls){
+ String[] sTitles = new String[_sTDocUrls.length];
+ for (int i = 0; i < _sTDocUrls.length; i++){
+ sTitles[i] = getTitleByTDocUrl(_sTDocUrls[i]);
+ }
+ return sTitles;
+ }
+
+
+ protected String[] getTDocUrls(){
+ try{
+ Object oSimpleFileAccess = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", getXComponentContext());
+ XSimpleFileAccess xSimpleFileAccess = UnoRuntime.queryInterface(XSimpleFileAccess.class, oSimpleFileAccess);
+ String[] sContent = xSimpleFileAccess.getFolderContents("vnd.sun.star.tdoc:/", false);
+ return sContent;
+ } catch( Exception e ) {
+ System.err.println( e );
+ return new String[]{};
+ }}
+
+
+ public XComponent openEmptyDocument(String _sUrl){
+ try{
+ PropertyValue[] aPropertyValues = new PropertyValue[1];
+ aPropertyValues[0] = new PropertyValue();
+ aPropertyValues[0].Name = "Hidden";
+ aPropertyValues[0].Value = Boolean.TRUE;
+ Object oDesktop = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.frame.Desktop", getXComponentContext());
+ XComponentLoader xCL = UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
+ return xCL.loadComponentFromURL(_sUrl, "_default", 0, aPropertyValues);
+ }
+ catch( Exception exception ) {
+ System.err.println( exception );
+ return null;
+ }}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/TestInspector.java b/odk/examples/java/Inspector/TestInspector.java
new file mode 100644
index 000000000..208acf25b
--- /dev/null
+++ b/odk/examples/java/Inspector/TestInspector.java
@@ -0,0 +1,88 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.XSingleComponentFactory;
+import com.sun.star.uno.UnoRuntime;
+
+public class TestInspector {
+
+ public static void main(String args[]) {
+ com.sun.star.uno.XComponentContext xContext = null;
+ try {
+ // get the remote office component context
+ xContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ if( xContext != null )
+ System.out.println("Connected to a running office ...");
+ }
+ catch( Exception e) {
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ try {
+ com.sun.star.lang.XMultiComponentFactory xMCF = xContext.getServiceManager();
+ // Creating an instance of the instance inspector with arguments
+
+ XSingleComponentFactory xFactory = Inspector.__getComponentFactory(Inspector._Inspector.class.getName());
+ Object obj= null;
+ if (xFactory != null) {
+ obj = xFactory.createInstanceWithContext(xContext);
+ }
+ org.openoffice.XInstanceInspector xInstInspector = null;
+ if (obj != null) {
+ xInstInspector = UnoRuntime.queryInterface(org.openoffice.XInstanceInspector.class, obj);
+ }
+
+ /* A desktop environment contains tasks with one or more
+ frames in which components can be loaded. Desktop is the
+ environment for components which can instantiate within
+ frames. */
+ com.sun.star.frame.XComponentLoader xCmpLoader = UnoRuntime.queryInterface( com.sun.star.frame.XComponentLoader.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext));
+
+ // Load a new spreadsheet document, which will be automatically
+ // displayed and is used for inspection
+ com.sun.star.lang.XComponent xComp = xCmpLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, new com.sun.star.beans.PropertyValue[0] );
+ xInstInspector.inspect(xCmpLoader, "");
+ System.out.println("You can now inspect the new spreadsheet " + "document ...\n");
+ }
+ catch( Exception e ) {
+ System.err.println( e + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoMethodNode.java b/odk/examples/java/Inspector/UnoMethodNode.java
new file mode 100644
index 000000000..a620fc81a
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoMethodNode.java
@@ -0,0 +1,228 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.reflection.ParamInfo;
+import com.sun.star.reflection.ParamMode;
+import com.sun.star.reflection.XIdlClass;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+public class UnoMethodNode extends UnoNode{
+ private XIdlMethod m_xIdlMethod = null;
+ private Object[] m_oParamObjects = null;
+ private Object m_oUnoReturnObject = null;
+ private boolean m_bisInvoked = false;
+ private XUnoMethodNode m_xUnoMethodNode = null;
+
+
+ /** Creates a new instance of UnoMethodNode */
+ public UnoMethodNode(XIdlMethod _xIdlMethod, Object _oUnoObject, XUnoMethodNode _xUnoMethodNode) {
+ super(_oUnoObject);
+ m_xIdlMethod = _xIdlMethod;
+ m_oParamObjects = new Object[m_xIdlMethod.getParameterInfos().length];
+ m_xUnoMethodNode = _xUnoMethodNode;
+ }
+
+ protected boolean isFoldable(){
+ return ((!this.isPrimitive()) && (getTypeClass().getValue() != TypeClass.VOID_value));
+ }
+
+ protected boolean isInvokable(){
+ boolean bisFoldable = true;
+ XIdlClass[] xIdlClasses = m_xIdlMethod.getParameterTypes();
+ for (int i = 0; i < xIdlClasses.length; i++){
+ bisFoldable = Introspector.isPrimitive(xIdlClasses[i].getTypeClass());
+ if (!bisFoldable){
+ return false;
+ }
+ }
+ return bisFoldable;
+ }
+
+ public XIdlMethod getXIdlMethod(){
+ return m_xIdlMethod;
+ }
+
+
+ @Override
+ public String getAnchor(){
+ return getXIdlMethod().getName();
+ }
+
+
+ public String getName(){
+ return getXIdlMethod().getName();
+ }
+
+
+ public Object invoke(){
+ Object oUnoReturnObject = null;
+ if (!hasParameters()){
+ oUnoReturnObject = invokeParameterlessMethod();
+ m_bisInvoked = true;
+ }
+ else{
+ java.util.List<Object> oUnoMethodObjects = m_xUnoMethodNode.getMethodObjects();
+ if (oUnoMethodObjects != null){
+ for (int i = 0; i < getXIdlMethod().getParameterInfos().length; i++){
+ this.m_oParamObjects[i] = oUnoMethodObjects.get(i);
+ }
+ if (oUnoMethodObjects.size() == m_oParamObjects.length + 1){
+ oUnoReturnObject = oUnoMethodObjects.get(oUnoMethodObjects.size()-1);
+ }
+ m_bisInvoked = (oUnoReturnObject != null);
+ }
+ }
+ m_oUnoReturnObject = oUnoReturnObject;
+ return oUnoReturnObject;
+ }
+
+
+ public boolean isInvoked(){
+ return m_bisInvoked;
+ }
+
+
+ protected String getNodeDescription(){
+ String sNodeDescription = "";
+ String sParameters = getParameterDescription();
+ if (m_xIdlMethod.getParameterInfos().length > 0){
+ sNodeDescription = getStandardMethodDescription();
+ }
+ else{
+ TypeClass typeClass = getTypeClass();
+ if (typeClass != TypeClass.VOID){
+ sNodeDescription = getStandardMethodDescription();
+ }
+ else{
+ sNodeDescription = getStandardMethodDescription();
+ }
+ }
+ return sNodeDescription;
+ }
+
+
+ public String getStandardMethodDescription(){
+ String sNodeDescription = m_xIdlMethod.getReturnType().getName() + " " + m_xIdlMethod.getName() + " (" + getParameterDescription() + " )";
+ if (isPrimitive()){
+ sNodeDescription += "";
+ }
+ return sNodeDescription;
+ }
+
+
+ public boolean hasParameters(){
+ return (m_xIdlMethod.getParameterInfos().length > 0);
+ }
+
+
+ public Object[] getLastParameterObjects(){
+ return m_oParamObjects;
+ }
+
+
+ public Object getLastUnoReturnObject(){
+ return m_oUnoReturnObject;
+ }
+
+
+ public String getParameterDescription(){
+ ParamInfo[] paramInfo = m_xIdlMethod.getParameterInfos();
+ String sParameters = "";
+ if (Introspector.isValid(paramInfo)) {
+ // get all parameters with type and mode
+ for ( int i = 0; i < paramInfo.length; i++ ) {
+ XIdlClass xIdlClass = paramInfo[ i ].aType;
+ if ( i == 0 ) {
+ // the first parameter has no leading comma
+ sParameters += "[" + getParamMode(paramInfo[ i ].aMode ) + "] " + xIdlClass.getName();
+ }
+ else {
+ // all other parameters are separated with comma
+ sParameters += ", [" + getParamMode(paramInfo[ i ].aMode ) + "] " + xIdlClass.getName();
+ }
+ }
+ }
+ return sParameters;
+ }
+
+
+ // return the parameter mode (IN, OUT, INOUT)
+ private static String getParamMode(ParamMode paramMode) {
+ String toReturn = "";
+ if ( paramMode == ParamMode.IN ) {
+ toReturn = "IN";
+ }
+ if ( paramMode == ParamMode.OUT ) {
+ toReturn = "OUT";
+ }
+ if ( paramMode == ParamMode.INOUT ) {
+ toReturn = "INOUT";
+ }
+ return toReturn;
+ }
+
+ public TypeClass getTypeClass(){
+ XIdlClass xIdlClass = m_xIdlMethod.getReturnType();
+ return xIdlClass.getTypeClass();
+ }
+
+
+ private Object invokeParameterlessMethod(){
+ try {
+ Object[][] aParamInfo = new Object[1][];
+ aParamInfo[0] = new Object[] {};
+ return getXIdlMethod().invoke(getUnoObject(), aParamInfo);
+ } catch (Exception ex) {
+ ex.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ public boolean isPrimitive(){
+ return Introspector.isObjectPrimitive(m_xIdlMethod.getClass(), getTypeClass());
+ }
+
+
+ protected Object invoke(Object _oUnoObject, Object[] oParameters) throws com.sun.star.uno.Exception{
+ Object[][] aParams = new Object[1][oParameters.length];
+ for ( int i = 0; i < oParameters.length; i++ ) {
+ aParams[0][i] = oParameters[i];
+ }
+ return m_xIdlMethod.invoke(_oUnoObject, aParams);
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoNode.java b/odk/examples/java/Inspector/UnoNode.java
new file mode 100644
index 000000000..0e72d1efd
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoNode.java
@@ -0,0 +1,351 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.FrameSearchFlag;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XDispatch;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XFrame;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.TypeClass;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.util.URL;
+import com.sun.star.util.XURLTransformer;
+
+public class UnoNode{
+
+
+ Object m_oUnoObject;
+ private XMultiComponentFactory m_xMultiComponentFactory;
+ private XComponentContext m_xComponentContext;
+ private Object[] m_oParamObjects = null;
+ private int m_nNodeType = XUnoNode.nOTHERS;
+ private Type aType = null;
+ private String sLabel = "";
+
+
+
+ /** Creates a new instance of UnoNode */
+ public UnoNode(Object _oUnoObject) {
+ m_xComponentContext = Introspector.getIntrospector().getXComponentContext();
+ m_xMultiComponentFactory = m_xComponentContext.getServiceManager();
+ m_oUnoObject = _oUnoObject;
+ }
+
+ public UnoNode(Object _oUnoObject, Type _aType) {
+ this(_oUnoObject);
+ aType = _aType;
+ m_nNodeType = XUnoNode.nINTERFACE;
+ }
+
+ public Object getUnoObject(){
+ return m_oUnoObject;
+ }
+
+
+ private XComponentContext getXComponentContext(){
+ return m_xComponentContext;
+ }
+
+
+ private XMultiComponentFactory getXMultiComponentFactory(){
+ return m_xMultiComponentFactory;
+ }
+
+
+ public String getAnchor(){
+ return "";
+ }
+
+ public int getNodeType(){
+ return m_nNodeType;
+ }
+
+ public void setNodeType(int _nNodeType){
+ m_nNodeType = _nNodeType;
+ }
+
+ public String getClassName(){
+ String sClassName = "";
+ if (m_nNodeType == XUnoNode.nINTERFACE){
+ sClassName = aType.getTypeName();
+ }
+ else if(m_nNodeType == XUnoNode.nSERVICE){
+ sClassName = sLabel;
+ }
+ return sClassName;
+ }
+
+
+ public Type getUnoType(){
+ return aType;
+ }
+
+ protected void setLabel(String _sLabel){
+ sLabel = _sLabel;
+ }
+
+ public void openIdlDescription(String _sIDLUrl, String _sClassName){
+ try{
+ String sIDLUrl = _sIDLUrl;
+ String sAnchor = ""; // TODO find out how the Anchor may be set at the html file; //_sAnchor;
+ boolean bExists = Introspector.getIntrospector().getXSimpleFileAccess().exists(sIDLUrl);
+ if (sIDLUrl.equals("") || (!bExists)){
+ sIDLUrl = "https://api.libreoffice.org/" + Inspector.sIDLDOCUMENTSUBFOLDER;
+ }
+ if (!sIDLUrl.endsWith("/")){
+ sIDLUrl += "/";
+ }
+ if (_sClassName.equals("")){
+ sIDLUrl += "index";
+ sAnchor = "";
+ }
+ else{
+ sIDLUrl += _sClassName.replace(".", "_1_1");
+ }
+ sIDLUrl += ".html";
+ if (sAnchor != null){
+ if (!sAnchor.equals("")){
+ sIDLUrl += "#" + sAnchor;
+ }
+ }
+ URL openHyperlink = getDispatchURL(".uno:OpenHyperlink");
+ PropertyValue pv = new PropertyValue();
+ pv.Name = "URL";
+ pv.Value = sIDLUrl;
+ getXDispatcher(openHyperlink).dispatch(openHyperlink, new PropertyValue[] {pv});
+ } catch(Exception exception) {
+ exception.printStackTrace(System.err);
+ }}
+
+
+ private com.sun.star.util.URL getDispatchURL(String _sURL){
+ try {
+ Object oTransformer = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.util.URLTransformer", getXComponentContext());
+ XURLTransformer xTransformer = UnoRuntime.queryInterface(XURLTransformer.class, oTransformer);
+ com.sun.star.util.URL[] oURL = new com.sun.star.util.URL[1];
+ oURL[0] = new com.sun.star.util.URL();
+ oURL[0].Complete = _sURL;
+ xTransformer.parseStrict(oURL);
+ return oURL[0];
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ }
+ return null;
+ }
+
+
+ private XFrame getCurrentFrame(){
+ try{
+ Object oDesktop = getXMultiComponentFactory().createInstanceWithContext("com.sun.star.frame.Desktop", getXComponentContext());
+ XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop);
+ return xDesktop.getCurrentFrame();
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ private XDispatch getXDispatcher(com.sun.star.util.URL oURL) {
+ try {
+ com.sun.star.util.URL[] oURLArray = new com.sun.star.util.URL[1];
+ oURLArray[0] = oURL;
+ XDispatchProvider xDispatchProvider = UnoRuntime.queryInterface(XDispatchProvider.class, getCurrentFrame());
+ XDispatch xDispatch = xDispatchProvider.queryDispatch(oURLArray[0], "_top", FrameSearchFlag.ALL); // "_self"
+ return xDispatch;
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ return null;
+ }}
+
+
+ public boolean isFilterApplicable(String _sFilter, String _sName){
+ boolean bFilterDoesApply = true;
+ if (_sFilter.length() > 0){
+ if (_sName.indexOf(_sFilter) == -1){
+ bFilterDoesApply = false;
+ }
+ }
+ return bFilterDoesApply;
+ }
+
+
+ public static String getDisplayValueOfPrimitiveType(Object _objectElement){
+ String sValue ="";
+ try{
+ if (AnyConverter.isString(_objectElement)){
+ sValue = AnyConverter.toString(_objectElement);
+ }
+ else if (AnyConverter.isBoolean(_objectElement)){
+ sValue += AnyConverter.toBoolean(_objectElement);
+ }
+ else if (AnyConverter.isByte(_objectElement)){
+ sValue += AnyConverter.toByte(_objectElement);
+ }
+ else if (AnyConverter.isChar(_objectElement)){
+ sValue += AnyConverter.toChar(_objectElement);
+ }
+ else if (AnyConverter.isDouble(_objectElement)){
+ sValue += AnyConverter.toDouble(_objectElement);
+ }
+ else if (AnyConverter.isFloat(_objectElement)){
+ sValue += AnyConverter.toFloat(_objectElement);
+ }
+ else if (AnyConverter.isInt(_objectElement)){
+ sValue += AnyConverter.toInt(_objectElement);
+ }
+ else if (AnyConverter.isLong(_objectElement)){
+ sValue += AnyConverter.toLong(_objectElement);
+ }
+ else if (AnyConverter.isShort(_objectElement)){
+ sValue += AnyConverter.toShort(_objectElement);
+ }
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ }
+ return sValue;
+ }
+
+ protected static String[] getDisplayValuesofPrimitiveArray(Object _oUnoObject){
+ String[] sDisplayValues = null;
+ try{
+ Type aType = AnyConverter.getType(_oUnoObject);
+ TypeClass aTypeClass = aType.getTypeClass();
+ int nTypeValue = aTypeClass.getValue();
+ if (nTypeValue == TypeClass.SEQUENCE_value){
+ nTypeValue = (sequenceComponentType(aType)).getTypeClass().getValue();
+ }
+ switch (nTypeValue){
+ case TypeClass.BOOLEAN_value:
+ boolean[] bBooleans = (boolean[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[bBooleans.length];
+ for (int i = 0; i < bBooleans.length; i++){
+ sDisplayValues[i] = Boolean.toString(bBooleans[i]);
+ }
+ break;
+ case TypeClass.BYTE_value:
+ byte[] bBytes = (byte[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[bBytes.length];
+ for (int i = 0; i < bBytes.length; i++){
+ sDisplayValues[i] = "" + bBytes[i];
+ }
+ break;
+ case TypeClass.DOUBLE_value:
+ double[] fdoubles = (double[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[fdoubles.length];
+ for (int i = 0; i < fdoubles.length; i++){
+ sDisplayValues[i] = String.valueOf(fdoubles[i]);
+ }
+ break;
+ case TypeClass.FLOAT_value:
+ float[] ffloats = (float[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[ffloats.length];
+ for (int i = 0; i < ffloats.length; i++){
+ sDisplayValues[i] = String.valueOf(ffloats[i]);
+ }
+ break;
+ case TypeClass.LONG_value:
+ int[] nints = (int[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[nints.length];
+ for (int i = 0; i < nints.length; i++){
+ sDisplayValues[i] = String.valueOf(nints[i]);
+ }
+ break;
+ case TypeClass.HYPER_value:
+ long[] nlongs = (long[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[nlongs.length];
+ for (int i = 0; i < nlongs.length; i++){
+ sDisplayValues[i] = String.valueOf(nlongs[i]);
+ }
+ break;
+ case TypeClass.SHORT_value:
+ short[] nShorts = (short[]) AnyConverter.toArray(_oUnoObject);
+ sDisplayValues = new String[nShorts.length];
+ for (int i = 0; i < nShorts.length; i++){
+ sDisplayValues[i] = "" + nShorts[i];
+ }
+ break;
+ case TypeClass.CHAR_value:
+ break;
+ default:
+ System.out.println("Value could not be retrieved: " + aType.getTypeClass().getClass().getName());
+ }
+ return sDisplayValues;
+ }
+ catch( Exception e ) {
+ System.err.println( e );
+ return null;
+ }}
+
+
+ private static Type sequenceComponentType(Type sequenceType) {
+ String n = sequenceType.getTypeName();
+ final String PREFIX = "[]";
+ return new Type(n.substring(PREFIX.length()));
+ }
+
+
+
+
+
+ public static String getNodeDescription(Object _oUnoObject){
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _oUnoObject );
+ if ( xServiceInfo != null ) {
+ return xServiceInfo.getImplementationName();
+ }
+ if (Introspector.isObjectPrimitive(_oUnoObject)){ //super.isO{sObjectClassName.equals("String"))issClassName.equals("String"))
+ return _oUnoObject.toString();
+ }
+ else{
+ return _oUnoObject.getClass().getName();
+ }
+ }
+
+ public void setParameterObjects(Object[] _oParamObjects){
+ m_oParamObjects = _oParamObjects;
+ }
+
+ public Object[] getParameterObjects(){
+ return m_oParamObjects;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoPropertyNode.java b/odk/examples/java/Inspector/UnoPropertyNode.java
new file mode 100644
index 000000000..51b6569b2
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoPropertyNode.java
@@ -0,0 +1,218 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.reflection.XPropertyTypeDescription;
+import com.sun.star.uno.UnoRuntime;
+
+public class UnoPropertyNode extends UnoNode{
+
+ private Property aProperty;
+ private PropertyValue aPropertyValue;
+ private String m_sPropertyName;
+ private Object m_oUnoReturnObject;
+ private int m_nPropertyType = XUnoPropertyNode.nDEFAULT;
+ private String sLabel = "";
+
+
+ /** Creates a new instance of UnoMethodNode */
+ public UnoPropertyNode(Property _aProperty, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ aProperty = _aProperty;
+ m_sPropertyName = aProperty.Name;
+ m_oUnoReturnObject = _oUnoReturnObject;
+ }
+
+
+ public UnoPropertyNode(Property _aProperty){
+ super(null);
+ aProperty = _aProperty;
+ m_sPropertyName = aProperty.Name;
+ m_oUnoReturnObject = null;
+ }
+
+ public UnoPropertyNode(PropertyValue _aPropertyValue, Object _oUnoObject, Object _oUnoReturnObject) {
+ super(_oUnoObject);
+ m_oUnoReturnObject = _oUnoReturnObject;
+ aPropertyValue = _aPropertyValue;
+ m_sPropertyName = aPropertyValue.Name;
+ }
+
+
+ public int getPropertyNodeType(){
+ return m_nPropertyType;
+ }
+
+
+ public void setPropertyNodeType(int _nPropertyType){
+ m_nPropertyType = _nPropertyType;
+ }
+
+
+ public String getPropertyName(){
+ return m_sPropertyName;
+ }
+
+ public String getName(){
+ return this.m_sPropertyName;
+ }
+
+
+ @Override
+ public String getClassName(){
+ String sClassName = "";
+ if (m_oUnoObject != null){
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, m_oUnoObject);
+ if (xServiceInfo != null){
+ String[] sServiceNames = xServiceInfo.getSupportedServiceNames();
+ for (int i = 0; i < sServiceNames.length; i++){
+ if (doesServiceSupportProperty(sServiceNames[i], m_sPropertyName)){
+ sClassName = sServiceNames[i];
+ break;
+ }
+ }
+ }
+ }
+ else{
+ sClassName = "com.sun.star.beans.Property";
+ }
+ return sClassName;
+ }
+
+
+ @Override
+ public String getAnchor(){
+ return m_sPropertyName;
+ }
+
+
+
+ private boolean doesServiceSupportProperty(String _sServiceName, String _sPropertyName){
+ try {
+ XPropertyTypeDescription[] xPropertyTypeDescriptions = Introspector.getIntrospector().getPropertyDescriptionsOfService(_sServiceName);
+ for (int i = 0; i < xPropertyTypeDescriptions.length; i++){
+ if (xPropertyTypeDescriptions[i].getName().equals(_sServiceName + "." + _sPropertyName)){
+ return true;
+ }
+ }
+ } catch ( java.lang.Exception e) {
+ System.out.println(System.out);
+ }
+ return false;
+ }
+
+
+ public Object getUnoReturnObject(){
+ return m_oUnoReturnObject;
+ }
+
+
+ private boolean isPrimitive(){
+ boolean bIsPrimitive = true;
+ if (getUnoReturnObject() != null){
+ if (getProperty() != null){
+ bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass(), getProperty().Type.getTypeClass());
+ }
+ else{
+ bIsPrimitive = Introspector.isObjectPrimitive(getUnoReturnObject().getClass());
+ }
+ }
+ else{
+ bIsPrimitive = Introspector.isObjectPrimitive(aProperty.Type.getTypeClass());
+ }
+ return bIsPrimitive;
+ }
+
+
+ protected boolean isFoldable(){
+ boolean bIsFoldable = false;
+ if (! isPrimitive()){
+ String sTypeName = getUnoReturnObject().getClass().getName();
+ bIsFoldable = (!sTypeName.equals("com.sun.star.uno.Type"));
+ }
+ return bIsFoldable;
+ }
+
+
+ protected String getLabel(){
+ if (!sLabel.equals("")){
+ if (! isPrimitive()){
+ if (isFoldable()){
+ sLabel = getPropertyTypeDescription(aProperty, getUnoReturnObject());
+ }
+ else{
+ sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject());
+ }
+ }
+ else {
+ sLabel = getStandardPropertyDescription(aProperty, getUnoReturnObject());
+ }
+ }
+ return sLabel;
+ }
+
+ public Property getProperty(){
+ return aProperty;
+ }
+
+ private static String getPropertyTypeDescription(Property _aProperty, Object _oUnoObject){
+ return _aProperty.Type.getTypeName() + " " + _aProperty.Name + " = " + _oUnoObject.toString();
+ }
+
+
+ protected static String getStandardPropertyDescription(Property _aProperty, Object _objectElement){
+ if (!Introspector.isObjectPrimitive(_objectElement)){
+ return _aProperty.Name + " = (" + _aProperty.Type.getTypeName() + ") ";
+ }
+ else{
+ return _aProperty.Name + " (" + _aProperty.Type.getTypeName() + ") = " + getDisplayValueOfPrimitiveType(_objectElement);
+ }
+ }
+
+
+ protected static String getStandardPropertyValueDescription(PropertyValue _aPropertyValue){
+ if (!Introspector.isObjectPrimitive(_aPropertyValue.Value)){
+ return _aPropertyValue.Name;
+ }
+ else{
+ return _aPropertyValue.Name + " : " + UnoNode.getDisplayValueOfPrimitiveType(_aPropertyValue.Value);
+ }
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/UnoTreeRenderer.java b/odk/examples/java/Inspector/UnoTreeRenderer.java
new file mode 100644
index 000000000..81e62a6d1
--- /dev/null
+++ b/odk/examples/java/Inspector/UnoTreeRenderer.java
@@ -0,0 +1,122 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import java.awt.Component;
+import java.awt.Graphics;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JTree;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+
+
+public class UnoTreeRenderer extends DefaultTreeCellRenderer{
+ private Icon m_oMethodIcon;
+ private Icon m_oPropertyIcon;
+ private Icon m_oContainerIcon;
+ private Icon m_oContentIcon;
+ private Icon m_oServiceIcon;
+ private Icon m_oInterfaceIcon;
+ private Icon m_oPropertyValueIcon;
+ private boolean bSelected;
+ private int nWidth = 0;
+
+
+ /** Creates a new instance of UnoTreeRenderer */
+ public UnoTreeRenderer(){
+ super();
+ try {
+
+ final ClassLoader loader = ClassLoader.getSystemClassLoader();
+ m_oMethodIcon = new ImageIcon(loader.getResource("images/methods_16.png"));
+ m_oPropertyIcon = new ImageIcon("images/properties_16.png");
+ m_oPropertyValueIcon = new ImageIcon("images/properties_16.png");
+ m_oContainerIcon = new ImageIcon("images/containers_16.png");
+ m_oServiceIcon = new ImageIcon("images/services_16.png");
+ m_oInterfaceIcon = new ImageIcon("images/interfaces_16.png");
+ m_oContentIcon = new ImageIcon("images/content_16.png");
+ } catch (RuntimeException e) {
+ System.out.println("Sorry, could not locate resources, treecell icons will not be displayed.");
+ }
+ }
+
+
+ @Override
+ public synchronized Component getTreeCellRendererComponent(JTree tree,Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus){
+ try{
+ bSelected = sel;
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
+ Component rc = super.getTreeCellRendererComponent( tree, value, sel,expanded, leaf, row,hasFocus);
+ String sLabelText = (String)node.getUserObject();
+ if (sLabelText != null){
+ if (sLabelText.equals(XUnoFacetteNode.SCONTAINERDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SCONTENTDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SINTERFACEDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SMETHODDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYDESCRIPTION)){
+ } else if (sLabelText.startsWith(XUnoFacetteNode.SPROPERTYINFODESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SPROPERTYVALUEDESCRIPTION)){
+ } else if (sLabelText.equals(XUnoFacetteNode.SSERVICEDESCRIPTION)){
+ } else{
+ setText(sLabelText);
+ rc.validate();
+ }
+ setSize(getPreferredSize());
+ rc.validate();
+ doLayout();
+ }
+ } catch (RuntimeException e) {
+ System.out.println("Sorry, icon for treecell could not be displayed.");
+ }
+ return this;
+ }
+
+
+
+ @Override
+ public void paintComponent(Graphics g) {
+ int x;
+ if(getIcon() == null) {
+ x = 0;
+ } else {
+ x = getIcon().getIconWidth() + getIconTextGap();
+ }
+ g.setColor(getForeground());
+ super.paintComponent(g);
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XDialogProvider.java b/odk/examples/java/Inspector/XDialogProvider.java
new file mode 100644
index 000000000..78b0c792e
--- /dev/null
+++ b/odk/examples/java/Inspector/XDialogProvider.java
@@ -0,0 +1,68 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+public interface XDialogProvider {
+
+ public static String SINVOKE = "Invoke";
+
+ public static String SADDTOSOURCECODE = "Add to Sourcecode";
+
+ public void enablePopupMenuItem(String _sMenuTitle, boolean _bdoEnable);
+
+ public void showPopUpMenu(Object invoker, int x, int y) throws java.lang.ClassCastException;
+
+ public InspectorPane getSelectedInspectorPage();
+
+ public void addInspectorPage(String _sTitle, Object _oContainer);
+
+ public InspectorPane getInspectorPage(int _nIndex);
+
+ public int getInspectorPageCount();
+
+ public void selectInspectorPageByIndex(int nTabIndex);
+
+ public void show(int _nPageIndex) throws java.lang.ClassCastException;
+
+ public void selectSourceCodeLanguage(int _nLanguage);
+
+
+
+ // returns one of the constants defined in XLanguageSourceCodeGenerator
+ public int getLanguage();
+
+ public String getIDLPath();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java b/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java
new file mode 100644
index 000000000..8729471e2
--- /dev/null
+++ b/odk/examples/java/Inspector/XLanguageSourceCodeGenerator.java
@@ -0,0 +1,108 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.uno.TypeClass;
+
+public interface XLanguageSourceCodeGenerator {
+
+ public static final int nJAVA = 0;
+ public static final int nCPLUSPLUS = 1;
+ public static final int nBASIC = 2;
+
+ public String getHeaderSourceCode(Object _oUnoObject, String _sClassName, TypeClass _aTypeClass);
+
+ public String getFinalHeaderStatements();
+
+ public void assignqueryInterfaceHeaderSourceCode();
+
+ public String getMainMethodSignatureSourceCode(XUnoNode _oUnoNode, String _soReturnObjectDescription);
+
+ public String getMethodTerminationSourceCode();
+
+ public String getStatementTerminationCharacter();
+
+ public boolean needsqueryInterface();
+
+ public String getqueryInterfaceSourceCode(String _sReturnValueDescription, String _sClassName, String _sObjectDescription);
+
+ public String getPropertyValueGetterSourceCode(String _sPropertyName, String _sReturnVariableName, String _sIncomingObjectName, TypeClass _aTypeClass, String _sTypeName);
+
+ public String getStructSourceCode(String _sReturnVariableDescription, String _sObjectDescription, String _sMember);
+
+ public String getObjectTypeDescription(String _sClassName, boolean _bAsHeader);
+
+ public String getbooleanTypeDescription();
+
+ public String getbyteTypeDescription();
+
+ public String getshortTypeDescription();
+
+
+
+ public String getlongTypeDescription();
+
+ public String getunsignedlongTypeDescription();
+
+ public String gethyperTypeDescription();
+
+ public String getunsignedhyperTypeDescription();
+
+ public String getfloatTypeDescription();
+
+ public String getdoubleTypeDescription();
+
+ public String getcharTypeDescription();
+
+ public String getstringTypeDescription(boolean _bAsHeaderSourceCode);
+
+
+
+ public String getanyTypeDescription(boolean _bAsHeaderSourceCode);
+
+
+
+ public String getVariableDeclaration(String _sTypeString, String _sVariableName, boolean _bIsArray, TypeClass aTypeClass, boolean _bInitialize);
+
+ public String getMethodSeparator();
+
+ public String getStringValue(String _sValue);
+
+ public String getConvertedSourceCodeValueOfObject(String _sReturnVariableName, String _sObjectDescription, TypeClass _aTypeClass, String _sTypeName);
+
+ public String castLiteral(String _sExpression, TypeClass _aTypeClass);
+
+ public String getCommentSign();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XTreeControlProvider.java b/odk/examples/java/Inspector/XTreeControlProvider.java
new file mode 100644
index 000000000..1cb69c972
--- /dev/null
+++ b/odk/examples/java/Inspector/XTreeControlProvider.java
@@ -0,0 +1,96 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.Type;
+
+public interface XTreeControlProvider {
+
+
+
+ public String enableFilterElements(XUnoNode _oUnoNode);
+
+ public void setSourceCode(String _sSourceCode);
+
+ public Object inspect(java.lang.Object _oUserDefinedObject, String _sTitle) throws com.sun.star.uno.RuntimeException;
+
+ public void nodeInserted(XUnoNode _oParentNode, XUnoNode _oChildNode, int index);
+
+ public void nodeChanged(XUnoNode _oNode);
+
+ public boolean setNodeVisible(Object node, boolean v);
+
+ public XUnoNode getSelectedNode();
+
+ public XTreePathProvider getSelectedPath();
+
+ public void expandPath(XTreePathProvider xTreePathProvider) throws java.lang.ClassCastException;
+
+ public void addTreeExpandListener();
+
+ public void addInspectorPane(InspectorPane _oInspectorPane);
+
+ public boolean isPropertyNode(XUnoNode _oUnoNode);
+
+ public boolean isMethodNode(XUnoNode _oUnoNode);
+
+ public boolean isFacetteNode(XUnoNode _oUnoNode);
+
+ public XUnoNode addUnoNode(Object _oUnoObject);
+
+ public XUnoNode addUnoNode(Object _oUnoObject, Type _aType);
+
+ public XUnoFacetteNode addUnoFacetteNode(XUnoNode _oParentNode, String _sNodeDescription, Object _oUnoObject);
+
+ public XUnoMethodNode addMethodNode(Object _objectElement, XIdlMethod _xIdlMethod);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithName(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithHandle(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithType(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNodeWithAttributesDescription(Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty);
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, PropertyValue _aPropertyValue, Object _oReturnObject);
+
+ public XUnoPropertyNode addUnoPropertyNode(Object _oUnoObject, Property _aProperty, Object _oUnoReturnObject);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XTreePathProvider.java b/odk/examples/java/Inspector/XTreePathProvider.java
new file mode 100644
index 000000000..ecbf52dd4
--- /dev/null
+++ b/odk/examples/java/Inspector/XTreePathProvider.java
@@ -0,0 +1,33 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+public interface XTreePathProvider {
+
+ public XUnoNode getLastPathComponent();
+
+ public XUnoNode getPathComponent(int i);
+
+ public int getPathCount();
+
+ public XTreePathProvider getParentPath();
+
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoFacetteNode.java b/odk/examples/java/Inspector/XUnoFacetteNode.java
new file mode 100644
index 000000000..ad1e114c1
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoFacetteNode.java
@@ -0,0 +1,66 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+
+public interface XUnoFacetteNode extends XUnoNode {
+
+ public static String SMETHODDESCRIPTION = "Methods";
+ public static String SPROPERTYDESCRIPTION = "Properties";
+ public static String SPROPERTYINFODESCRIPTION = "PropertyInfo";
+ public static String SCONTAINERDESCRIPTION = "Container";
+ public static String SSERVICEDESCRIPTION = "Services";
+ public static String SINTERFACEDESCRIPTION = "Interfaces";
+ public static String SCONTENTDESCRIPTION = "Content";
+ public static String SPROPERTYVALUEDESCRIPTION = "PropertyValues";
+
+
+ public boolean isMethodNode();
+
+ public boolean isPropertyNode();
+
+ public boolean isContainerNode();
+
+ public boolean isServiceNode();
+
+ public boolean isInterfaceNode();
+
+ public String getFilter();
+
+ public void setFilter(String _sFilter);
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoMethodNode.java b/odk/examples/java/Inspector/XUnoMethodNode.java
new file mode 100644
index 000000000..4749c92a0
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoMethodNode.java
@@ -0,0 +1,70 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.reflection.XIdlMethod;
+import com.sun.star.uno.TypeClass;
+
+
+public interface XUnoMethodNode extends XUnoNode {
+
+ public XIdlMethod getXIdlMethod();
+
+ public boolean isInvoked();
+
+ public Object invoke() throws com.sun.star.uno.Exception;
+
+ public Object invoke(Object _oUnoObject, Object[] _oParameters) throws com.sun.star.uno.Exception;
+
+ public boolean isInvokable();
+
+ public boolean hasParameters();
+
+ public Object[] getLastParameterObjects();
+
+ public Object getLastUnoReturnObject();
+
+ public TypeClass getTypeClass();
+
+ public boolean isPrimitive();
+
+ public java.util.List<Object> getMethodObjects();
+
+ public boolean isFoldable();
+
+ public String getStandardMethodDescription();
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoNode.java b/odk/examples/java/Inspector/XUnoNode.java
new file mode 100644
index 000000000..11eba35da
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoNode.java
@@ -0,0 +1,87 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+import com.sun.star.uno.Type;
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+
+public interface XUnoNode {
+
+ public static final int nINTERFACE = 1;
+ public static final int nSERVICE = 2;
+ public static final int nOTHERS = 3;
+
+ public String getAnchor();
+
+ public String getClassName();
+
+ public void openIdlDescription(String _sIDLUrl);
+
+ public boolean isFilterApplicable(String _sFilter);
+
+ public void setVisible(String _sFilter);
+
+ public void setParameterObjects(Object[] _oParamObjects);
+
+ public Object[] getParameterObjects();
+
+ public String getName();
+
+ public void setFoldable(boolean _bIsFoldable);
+
+ public Object getUnoObject();
+
+ public XUnoNode getParentNode();
+
+ public void addChildNode(XUnoNode _xUnoNode);
+
+ public void setLabel(String _sLabel);
+
+ public String getLabel();
+
+ public int getChildCount();
+
+ public XUnoNode getChild(int _index);
+
+ public int getNodeType();
+
+ // possible values are nINTERFACE, nSERVICE, nOTHERS
+ public void setNodeType(int _nNodeType);
+
+ /** delivers only the Uno-Type when the NodeType is set to nINTERFACE
+ * otherwise (when the NodeType has not been set returns null
+ */
+ public Type getUnoType();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/XUnoPropertyNode.java b/odk/examples/java/Inspector/XUnoPropertyNode.java
new file mode 100644
index 000000000..1902a5db2
--- /dev/null
+++ b/odk/examples/java/Inspector/XUnoPropertyNode.java
@@ -0,0 +1,54 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.beans.Property;
+
+
+public interface XUnoPropertyNode extends XUnoNode {
+
+ public static int nDEFAULT = 0;
+ public static int nPROPERTYSETINFOTYPE = 1;
+
+
+ public Object getUnoReturnObject();
+
+ public int getPropertyNodeType();
+
+ public void setPropertyNodeType(int _nPropertyType);
+
+ public Property getProperty();
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/description.xml b/odk/examples/java/Inspector/description.xml
new file mode 100644
index 000000000..6c4e2396b
--- /dev/null
+++ b/odk/examples/java/Inspector/description.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+-->
+<d:description xmlns:d="http://openoffice.org/extensions/description/2006">
+ <d:dependencies>
+ <l:LibreOffice-minimal-version value="4.1" d:name="LibreOffice 4.1"
+ xmlns:l="http://libreoffice.org/extensions/description/2011"/>
+ </d:dependencies>
+</d:description>
diff --git a/odk/examples/java/Inspector/images/containers_16.png b/odk/examples/java/Inspector/images/containers_16.png
new file mode 100644
index 000000000..0b4c62f11
--- /dev/null
+++ b/odk/examples/java/Inspector/images/containers_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/content_16.png b/odk/examples/java/Inspector/images/content_16.png
new file mode 100644
index 000000000..758169260
--- /dev/null
+++ b/odk/examples/java/Inspector/images/content_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/interfaces_16.png b/odk/examples/java/Inspector/images/interfaces_16.png
new file mode 100644
index 000000000..cf633ac9c
--- /dev/null
+++ b/odk/examples/java/Inspector/images/interfaces_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/methods_16.png b/odk/examples/java/Inspector/images/methods_16.png
new file mode 100644
index 000000000..25cd8b45c
--- /dev/null
+++ b/odk/examples/java/Inspector/images/methods_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/properties_16.png b/odk/examples/java/Inspector/images/properties_16.png
new file mode 100644
index 000000000..4e22dd1d5
--- /dev/null
+++ b/odk/examples/java/Inspector/images/properties_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/images/services_16.png b/odk/examples/java/Inspector/images/services_16.png
new file mode 100644
index 000000000..024a16ed6
--- /dev/null
+++ b/odk/examples/java/Inspector/images/services_16.png
Binary files differ
diff --git a/odk/examples/java/Inspector/manifest.mf b/odk/examples/java/Inspector/manifest.mf
new file mode 100644
index 000000000..328e8e5bc
--- /dev/null
+++ b/odk/examples/java/Inspector/manifest.mf
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+X-COMMENT: Main-Class will be added automatically by build
+
diff --git a/odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl b/odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl
new file mode 100644
index 000000000..81b396170
--- /dev/null
+++ b/odk/examples/java/Inspector/org/openoffice/InstanceInspector.idl
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#ifndef INCLUDED_ORG_OPENOFFICE_INSTANCEINSPECTOR_IDL
+#define INCLUDED_ORG_OPENOFFICE_INSTANCEINSPECTOR_IDL
+
+#include <XInstanceInspector.idl>
+
+
+module org { module openoffice {
+
+ /**
+ * This service describes an instance inspector which can inspect
+ * UNO objects and provides information about the implemented
+ * interfaces, the supported services and properties of this object.
+ */
+ service InstanceInspector: XInstanceInspector;
+
+}; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl b/odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl
new file mode 100644
index 000000000..ca96a27e1
--- /dev/null
+++ b/odk/examples/java/Inspector/org/openoffice/XInstanceInspector.idl
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#ifndef INCLUDED_ORG_OPENOFFICE_XINSTANCEINSPECTOR_IDL
+#define INCLUDED_ORG_OPENOFFICE_XINSTANCEINSPECTOR_IDL
+
+#include <com/sun/star/uno/XInterface.idl>
+
+module org { module openoffice {
+
+ interface XInstanceInspector {
+ /**
+ * For a given instance this method displays all services, interfaces,
+ * methods, attributes, and contents in a tree. All dependent
+ * instances are also inspected and displayed, so the user could browse
+ * the tree. If you press the key "F1", the API-documentation from
+ * www.openoffice.org for the current instance will be displayed in a
+ * new window.
+ */
+ void inspect( [in] any aInstance, [in] string sTitle );
+ };
+
+}; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */