1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package integration.extensions; 25 26 import com.sun.star.lang.ClassNotFoundException; 27 import com.sun.star.uno.*; 28 import com.sun.star.beans.*; 29 import com.sun.star.inspection.*; 30 import com.sun.star.frame.*; 31 import com.sun.star.lang.XServiceInfo; 32 import com.sun.star.lang.XMultiServiceFactory; 33 import com.sun.star.lang.XSingleComponentFactory; 34 35 /** 36 * 37 * @author fs93730 38 */ 39 public class ServicesHandler implements XPropertyHandler 40 { 41 private XComponentContext m_context; 42 private String[] m_supportedServices; 43 44 private class ClickHandler implements com.sun.star.awt.XActionListener 45 { 46 XComponentContext m_context; 47 private String m_serviceName; 48 ClickHandler( XComponentContext _context, String _serviceName )49 public ClickHandler( XComponentContext _context, String _serviceName ) 50 { 51 m_context = _context; 52 m_serviceName = _serviceName; 53 } 54 disposing(com.sun.star.lang.EventObject eventObject)55 public void disposing(com.sun.star.lang.EventObject eventObject) 56 { 57 // not interested in 58 } 59 actionPerformed(com.sun.star.awt.ActionEvent actionEvent)60 public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) 61 { 62 try 63 { 64 // translate the service name into a URL to dispatch 65 String documentationURL = "http://api.openoffice.org/docs/common/ref/" + m_serviceName.replace('.','/') + ".html"; 66 System.out.println( documentationURL ); 67 68 // the OpenHyperlink command, to be dispatched to the Desktop 69 com.sun.star.util.URL dispatchURL[] = { new com.sun.star.util.URL() }; 70 dispatchURL[0].Complete = ".uno:OpenHyperlink"; 71 com.sun.star.util.XURLTransformer transformer = (com.sun.star.util.XURLTransformer)UnoRuntime.queryInterface( 72 com.sun.star.util.XURLTransformer.class, 73 m_context.getServiceManager().createInstanceWithContext( "com.sun.star.util.URLTransformer", m_context ) ); 74 transformer.parseStrict( dispatchURL ); 75 76 // the dispatcher for the OpenHyperlink command 77 Frame desktop = new Frame( 78 m_context.getServiceManager().createInstanceWithContext( "com.sun.star.frame.Desktop", m_context ) ); 79 XDispatch dispatcher = desktop.queryDispatch(dispatchURL[0],"",0); 80 81 // the arguments for the OpenHyperlink command 82 PropertyValue dispatchArgs[] = new PropertyValue[] { new PropertyValue() }; 83 dispatchArgs[0].Name = "URL"; 84 dispatchArgs[0].Value = documentationURL; 85 86 dispatcher.dispatch(dispatchURL[0], dispatchArgs ); 87 } 88 catch( com.sun.star.uno.Exception e ) 89 { 90 e.printStackTrace( System.err ); 91 } 92 } 93 } 94 95 /** Creates a new instance of ServicesHandler */ ServicesHandler( XComponentContext _context )96 public ServicesHandler( XComponentContext _context ) 97 { 98 m_context = _context; 99 m_supportedServices = new String[] { }; 100 } 101 actuatingPropertyChanged(String _propertyName, Object _newValue, Object _oldValue, com.sun.star.inspection.XObjectInspectorUI _objectInspectorUI, boolean _firstTimeInit)102 public void actuatingPropertyChanged(String _propertyName, Object _newValue, Object _oldValue, com.sun.star.inspection.XObjectInspectorUI _objectInspectorUI, boolean _firstTimeInit) throws com.sun.star.lang.NullPointerException 103 { 104 // not interested in 105 } 106 addEventListener(com.sun.star.lang.XEventListener _eventListener)107 public void addEventListener(com.sun.star.lang.XEventListener _eventListener) 108 { 109 // ingnoring this 110 } 111 addPropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener)112 public void addPropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) throws com.sun.star.lang.NullPointerException 113 { 114 // ingnoring this 115 } 116 convertToControlValue(String _propertyName, Object _propertyValue, com.sun.star.uno.Type type)117 public Object convertToControlValue(String _propertyName, Object _propertyValue, com.sun.star.uno.Type type) throws com.sun.star.beans.UnknownPropertyException 118 { 119 return _propertyValue; 120 } 121 convertToPropertyValue(String _propertyName, Object _controlValue)122 public Object convertToPropertyValue(String _propertyName, Object _controlValue) throws com.sun.star.beans.UnknownPropertyException 123 { 124 return _controlValue; 125 } 126 describePropertyLine(String _propertyName, com.sun.star.inspection.XPropertyControlFactory _propertyControlFactory)127 public com.sun.star.inspection.LineDescriptor describePropertyLine(String _propertyName, com.sun.star.inspection.XPropertyControlFactory _propertyControlFactory) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.NullPointerException 128 { 129 com.sun.star.inspection.LineDescriptor descriptor = new com.sun.star.inspection.LineDescriptor(); 130 131 descriptor = new LineDescriptor(); 132 descriptor.Category = "Services"; 133 descriptor.DisplayName = "supports service"; 134 descriptor.HasPrimaryButton = descriptor.HasSecondaryButton = false; 135 descriptor.IndentLevel = 0; 136 try 137 { 138 XHyperlinkControl hyperlinkControl = (XHyperlinkControl)UnoRuntime.queryInterface( 139 XHyperlinkControl.class, _propertyControlFactory.createPropertyControl( PropertyControlType.HyperlinkField, true ) ); 140 hyperlinkControl.addActionListener( new ClickHandler( m_context, _propertyName ) ); 141 142 descriptor.Control = hyperlinkControl; 143 } 144 catch( com.sun.star.lang.IllegalArgumentException e ) 145 { 146 } 147 return descriptor; 148 } 149 dispose()150 public void dispose() 151 { 152 // nothing to do 153 } 154 getActuatingProperties()155 public String[] getActuatingProperties() 156 { 157 // none 158 return new String[] { }; 159 } 160 getPropertyState(String _propertyName)161 public com.sun.star.beans.PropertyState getPropertyState(String _propertyName) throws com.sun.star.beans.UnknownPropertyException 162 { 163 return com.sun.star.beans.PropertyState.DIRECT_VALUE; 164 } 165 getPropertyValue(String _propertyName)166 public Object getPropertyValue(String _propertyName) throws com.sun.star.beans.UnknownPropertyException 167 { 168 return _propertyName; 169 } 170 getSupersededProperties()171 public String[] getSupersededProperties() 172 { 173 return new String[] { "SupportedServiceNames" }; 174 // we're used in conjunction with a GenericPropertyHandler, which (via inspection) finds 175 // a property SupportedServiceNames, resulting from the XServiceInfo.getSupportedServiceNames 176 // method. Since we handle those ourself, we supersede them. 177 } 178 getSupportedProperties()179 public com.sun.star.beans.Property[] getSupportedProperties() 180 { 181 Property[] properties = new Property[ m_supportedServices.length ]; 182 for ( int i=0; i<m_supportedServices.length; ++i ) 183 properties[i] = new Property( m_supportedServices[i], 0, new Type( String.class ), (short)0 ); 184 return properties; 185 } 186 inspect(Object _component)187 public void inspect(Object _component) throws com.sun.star.lang.NullPointerException 188 { 189 XServiceInfo serviceInfo = (XServiceInfo)UnoRuntime.queryInterface( XServiceInfo.class, _component ); 190 if ( serviceInfo != null ) 191 m_supportedServices = serviceInfo.getSupportedServiceNames(); 192 } 193 isComposable(String _propertyName)194 public boolean isComposable(String _propertyName) throws com.sun.star.beans.UnknownPropertyException 195 { 196 return true; 197 } 198 onInteractivePropertySelection(String str, boolean param, Object[] obj, com.sun.star.inspection.XObjectInspectorUI xObjectInspectorUI)199 public com.sun.star.inspection.InteractiveSelectionResult onInteractivePropertySelection(String str, boolean param, Object[] obj, com.sun.star.inspection.XObjectInspectorUI xObjectInspectorUI) throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.NullPointerException 200 { 201 return InteractiveSelectionResult.Cancelled; 202 } 203 removeEventListener(com.sun.star.lang.XEventListener _eventListener)204 public void removeEventListener(com.sun.star.lang.XEventListener _eventListener) 205 { 206 // ignoring this 207 } 208 removePropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener)209 public void removePropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) 210 { 211 // ignoring this 212 } 213 setPropertyValue(String str, Object obj)214 public void setPropertyValue(String str, Object obj) throws com.sun.star.beans.UnknownPropertyException 215 { 216 // we declared our properties as readonly 217 throw new java.lang.RuntimeException(); 218 } 219 suspend(boolean param)220 public boolean suspend(boolean param) 221 { 222 return true; 223 } 224 } 225