1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package org.openoffice.accessibility.awb.view;
23 
24 import java.awt.GridLayout;
25 import java.awt.Color;
26 import java.awt.Dimension;
27 import java.awt.GridBagLayout;
28 import java.awt.GridBagConstraints;
29 import java.lang.Integer;
30 import javax.swing.JScrollPane;
31 import javax.swing.JTree;
32 import javax.swing.tree.DefaultMutableTreeNode;
33 import javax.swing.tree.DefaultTreeModel;
34 
35 import com.sun.star.accessibility.AccessibleEventId;
36 import com.sun.star.accessibility.AccessibleEventObject;
37 import com.sun.star.accessibility.XAccessible;
38 import com.sun.star.accessibility.XAccessibleContext;
39 import com.sun.star.lang.IndexOutOfBoundsException;
40 import com.sun.star.lang.XServiceInfo;
41 import com.sun.star.lang.XTypeProvider;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 
45 import org.openoffice.accessibility.misc.NameProvider;
46 
47 
48 /** Show all supported services and interfaces.
49 */
50 public class ServiceInterfaceView
51     extends ObjectView
52 {
Create( ObjectViewContainer aContainer, XAccessibleContext xContext)53     static public ObjectView Create (
54         ObjectViewContainer aContainer,
55         XAccessibleContext xContext)
56     {
57         if (xContext != null)
58             return new ServiceInterfaceView (aContainer);
59         else
60             return null;
61     }
62 
63 
64 
65 
ServiceInterfaceView(ObjectViewContainer aContainer)66     public ServiceInterfaceView (ObjectViewContainer aContainer)
67     {
68         super (aContainer);
69 
70         maImplementationNameRoot = new DefaultMutableTreeNode ("Implementation Name");
71         maServiceRoot = new DefaultMutableTreeNode ("Supported Services");
72         maInterfaceRoot = new DefaultMutableTreeNode ("Supported Interfaces");
73         maTree = new JTree (new DefaultMutableTreeNode[]
74             {maServiceRoot,maInterfaceRoot});
75         JScrollPane aScrollPane = new JScrollPane (
76             maTree,
77             JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
78             JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
79 
80         setMinimumSize (new Dimension(300,200));
81         setLayout (new GridLayout (1,1));
82         add (aScrollPane);
83     }
84 
85 
86 
87 
Update()88     public void Update ()
89     {
90         DefaultTreeModel aModel = (DefaultTreeModel)maTree.getModel();
91 
92         // Clear old tree.
93         DefaultMutableTreeNode aRoot =(DefaultMutableTreeNode)aModel.getRoot();
94         aRoot.removeAllChildren();
95 
96         // Create the new tree.
97         CreateImplementationNameTree ();
98         CreateServiceTree ();
99         CreateInterfaceTree ();
100         aRoot.add (maImplementationNameRoot);
101         aRoot.add (maServiceRoot);
102         aRoot.add (maInterfaceRoot);
103         aModel.setRoot (aRoot);
104 
105         // Expand whole tree.
106         for (int i=0; i<maTree.getRowCount(); i++)
107             maTree.expandRow (i);
108     }
109 
CreateImplementationNameTree()110     private void CreateImplementationNameTree ()
111     {
112         XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(
113             XServiceInfo.class, mxContext);
114         maImplementationNameRoot.removeAllChildren();
115         if (xServiceInfo != null)
116         {
117             maImplementationNameRoot.add (
118                 new DefaultMutableTreeNode (
119                     (xServiceInfo!=null
120                         ? xServiceInfo.getImplementationName()
121                         : "<XServiceInfo not supported>")));
122         }
123     }
124 
CreateServiceTree()125     private void CreateServiceTree ()
126     {
127         XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(
128             XServiceInfo.class, mxContext);
129         maServiceRoot.removeAllChildren();
130         if (xServiceInfo != null)
131         {
132             String[] aServiceNames = xServiceInfo.getSupportedServiceNames();
133             int nCount = aServiceNames.length;
134             for (int i=0; i<nCount; i++)
135                 maServiceRoot.add (
136                     new DefaultMutableTreeNode (aServiceNames[i]));
137         }
138         else
139             maServiceRoot.add (
140                 new DefaultMutableTreeNode("XServiceInfo not supported"));
141     }
142 
CreateInterfaceTree()143     private void CreateInterfaceTree ()
144     {
145         XTypeProvider xTypeProvider = (XTypeProvider)UnoRuntime.queryInterface(
146             XTypeProvider.class, mxContext);
147         maInterfaceRoot.removeAllChildren();
148         if (xTypeProvider != null)
149         {
150             Type[] aTypes = xTypeProvider.getTypes();
151             int nCount = aTypes.length;
152             for (int i=0; i<nCount; i++)
153                 maInterfaceRoot.add (
154                     new DefaultMutableTreeNode (aTypes[i].getTypeName()));
155         }
156         else
157             maInterfaceRoot.add (
158                 new DefaultMutableTreeNode("XTypeProvider not supported"));
159     }
160 
GetTitle()161     public String GetTitle ()
162     {
163         return ("Supported Services and Interfaces");
164     }
165 
166 
167     private JTree maTree;
168     private DefaultMutableTreeNode maImplementationNameRoot;
169     private DefaultMutableTreeNode maServiceRoot;
170     private DefaultMutableTreeNode maInterfaceRoot;
171 }
172