summaryrefslogtreecommitdiff
path: root/accessibility/workben/org/openoffice/accessibility/awb/view/ServiceInterfaceView.java
blob: 7c41ff01c97e53891003cdb41a96fc5d1ace43df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package org.openoffice.accessibility.awb.view;

import java.awt.GridLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.lang.Integer;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import com.sun.star.accessibility.AccessibleEventId;
import com.sun.star.accessibility.AccessibleEventObject;
import com.sun.star.accessibility.XAccessible;
import com.sun.star.accessibility.XAccessibleContext;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XTypeProvider;
import com.sun.star.uno.Type;
import com.sun.star.uno.UnoRuntime;

import org.openoffice.accessibility.misc.NameProvider;


/** Show all supported services and interfaces.
*/
public class ServiceInterfaceView
    extends ObjectView
{
    static public ObjectView Create (
        ObjectViewContainer aContainer,
        XAccessibleContext xContext)
    {
        if (xContext != null)
            return new ServiceInterfaceView (aContainer);
        else
            return null;
    }




    public ServiceInterfaceView (ObjectViewContainer aContainer)
    {
        super (aContainer);

        maImplementationNameRoot = new DefaultMutableTreeNode ("Implementation Name");
        maServiceRoot = new DefaultMutableTreeNode ("Supported Services");
        maInterfaceRoot = new DefaultMutableTreeNode ("Supported Interfaces");
        maTree = new JTree (new DefaultMutableTreeNode[]
            {maServiceRoot,maInterfaceRoot});
        JScrollPane aScrollPane = new JScrollPane (
            maTree,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        setMinimumSize (new Dimension(300,200));
        setLayout (new GridLayout (1,1));
        add (aScrollPane);
    }




    public void Update ()
    {
        DefaultTreeModel aModel = (DefaultTreeModel)maTree.getModel();

        // Clear old tree.
        DefaultMutableTreeNode aRoot =(DefaultMutableTreeNode)aModel.getRoot();
        aRoot.removeAllChildren();

        // Create the new tree.
        CreateImplementationNameTree ();
        CreateServiceTree ();
        CreateInterfaceTree ();
        aRoot.add (maImplementationNameRoot);
        aRoot.add (maServiceRoot);
        aRoot.add (maInterfaceRoot);
        aModel.setRoot (aRoot);

        // Expand whole tree.
        for (int i=0; i<maTree.getRowCount(); i++)
            maTree.expandRow (i);
    }

    private void CreateImplementationNameTree ()
    {
        XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(
            XServiceInfo.class, mxContext);
        maImplementationNameRoot.removeAllChildren();
        if (xServiceInfo != null)
        {
            maImplementationNameRoot.add (
                new DefaultMutableTreeNode (
                    (xServiceInfo!=null
                        ? xServiceInfo.getImplementationName()
                        : "<XServiceInfo not supported>")));
        }
    }

    private void CreateServiceTree ()
    {
        XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface(
            XServiceInfo.class, mxContext);
        maServiceRoot.removeAllChildren();
        if (xServiceInfo != null)
        {
            String[] aServiceNames = xServiceInfo.getSupportedServiceNames();
            int nCount = aServiceNames.length;
            for (int i=0; i<nCount; i++)
                maServiceRoot.add (
                    new DefaultMutableTreeNode (aServiceNames[i]));
        }
        else
            maServiceRoot.add (
                new DefaultMutableTreeNode("XServiceInfo not supported"));
    }

    private void CreateInterfaceTree ()
    {
        XTypeProvider xTypeProvider = (XTypeProvider)UnoRuntime.queryInterface(
            XTypeProvider.class, mxContext);
        maInterfaceRoot.removeAllChildren();
        if (xTypeProvider != null)
        {
            Type[] aTypes = xTypeProvider.getTypes();
            int nCount = aTypes.length;
            for (int i=0; i<nCount; i++)
                maInterfaceRoot.add (
                    new DefaultMutableTreeNode (aTypes[i].getTypeName()));
        }
        else
            maInterfaceRoot.add (
                new DefaultMutableTreeNode("XTypeProvider not supported"));
    }

    public String GetTitle ()
    {
        return ("Supported Services and Interfaces");
    }


    private JTree maTree;
    private DefaultMutableTreeNode maImplementationNameRoot;
    private DefaultMutableTreeNode maServiceRoot;
    private DefaultMutableTreeNode maInterfaceRoot;
}