1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package integration.extensions; 29 30 import com.sun.star.lang.ClassNotFoundException; 31 import com.sun.star.uno.*; 32 import com.sun.star.beans.*; 33 import com.sun.star.inspection.*; 34 import com.sun.star.frame.*; 35 import com.sun.star.lang.XServiceInfo; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.lang.XSingleComponentFactory; 38 39 /** 40 * 41 * @author fs93730 42 */ 43 public class ServicesHandler implements XPropertyHandler 44 { 45 private XComponentContext m_context; 46 private String[] m_supportedServices; 47 48 private class ClickHandler implements com.sun.star.awt.XActionListener 49 { 50 XComponentContext m_context; 51 private String m_serviceName; 52 53 public ClickHandler( XComponentContext _context, String _serviceName ) 54 { 55 m_context = _context; 56 m_serviceName = _serviceName; 57 } 58 59 public void disposing(com.sun.star.lang.EventObject eventObject) 60 { 61 // not interested in 62 } 63 64 public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) 65 { 66 try 67 { 68 // translate the service name into a URL to dispatch 69 String documentationURL = "http://api.openoffice.org/docs/common/ref/" + m_serviceName.replace('.','/') + ".html"; 70 System.out.println( documentationURL ); 71 72 // the OpenHyperlink command, to be dispatched to the Desktop 73 com.sun.star.util.URL dispatchURL[] = { new com.sun.star.util.URL() }; 74 dispatchURL[0].Complete = ".uno:OpenHyperlink"; 75 com.sun.star.util.XURLTransformer transformer = (com.sun.star.util.XURLTransformer)UnoRuntime.queryInterface( 76 com.sun.star.util.XURLTransformer.class, 77 m_context.getServiceManager().createInstanceWithContext( "com.sun.star.util.URLTransformer", m_context ) ); 78 transformer.parseStrict( dispatchURL ); 79 80 // the dispatcher for the OpenHyperlink command 81 Frame desktop = new Frame( 82 m_context.getServiceManager().createInstanceWithContext( "com.sun.star.frame.Desktop", m_context ) ); 83 XDispatch dispatcher = desktop.queryDispatch(dispatchURL[0],"",0); 84 85 // the arguments for the OpenHyperlink command 86 PropertyValue dispatchArgs[] = new PropertyValue[] { new PropertyValue() }; 87 dispatchArgs[0].Name = "URL"; 88 dispatchArgs[0].Value = documentationURL; 89 90 dispatcher.dispatch(dispatchURL[0], dispatchArgs ); 91 } 92 catch( com.sun.star.uno.Exception e ) 93 { 94 e.printStackTrace( System.err ); 95 } 96 } 97 } 98 99 /** Creates a new instance of ServicesHandler */ 100 public ServicesHandler( XComponentContext _context ) 101 { 102 m_context = _context; 103 m_supportedServices = new String[] { }; 104 } 105 106 public void actuatingPropertyChanged(String _propertyName, Object _newValue, Object _oldValue, com.sun.star.inspection.XObjectInspectorUI _objectInspectorUI, boolean _firstTimeInit) throws com.sun.star.lang.NullPointerException 107 { 108 // not interested in 109 } 110 111 public void addEventListener(com.sun.star.lang.XEventListener _eventListener) 112 { 113 // ingnoring this 114 } 115 116 public void addPropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) throws com.sun.star.lang.NullPointerException 117 { 118 // ingnoring this 119 } 120 121 public Object convertToControlValue(String _propertyName, Object _propertyValue, com.sun.star.uno.Type type) throws com.sun.star.beans.UnknownPropertyException 122 { 123 return _propertyValue; 124 } 125 126 public Object convertToPropertyValue(String _propertyName, Object _controlValue) throws com.sun.star.beans.UnknownPropertyException 127 { 128 return _controlValue; 129 } 130 131 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 132 { 133 com.sun.star.inspection.LineDescriptor descriptor = new com.sun.star.inspection.LineDescriptor(); 134 135 descriptor = new LineDescriptor(); 136 descriptor.Category = "Services"; 137 descriptor.DisplayName = "supports service"; 138 descriptor.HasPrimaryButton = descriptor.HasSecondaryButton = false; 139 descriptor.IndentLevel = 0; 140 try 141 { 142 XHyperlinkControl hyperlinkControl = (XHyperlinkControl)UnoRuntime.queryInterface( 143 XHyperlinkControl.class, _propertyControlFactory.createPropertyControl( PropertyControlType.HyperlinkField, true ) ); 144 hyperlinkControl.addActionListener( new ClickHandler( m_context, _propertyName ) ); 145 146 descriptor.Control = hyperlinkControl; 147 } 148 catch( com.sun.star.lang.IllegalArgumentException e ) 149 { 150 } 151 return descriptor; 152 } 153 154 public void dispose() 155 { 156 // nothing to do 157 } 158 159 public String[] getActuatingProperties() 160 { 161 // none 162 return new String[] { }; 163 } 164 165 public com.sun.star.beans.PropertyState getPropertyState(String _propertyName) throws com.sun.star.beans.UnknownPropertyException 166 { 167 return com.sun.star.beans.PropertyState.DIRECT_VALUE; 168 } 169 170 public Object getPropertyValue(String _propertyName) throws com.sun.star.beans.UnknownPropertyException 171 { 172 return _propertyName; 173 } 174 175 public String[] getSupersededProperties() 176 { 177 return new String[] { "SupportedServiceNames" }; 178 // we're used in conjunction with a GenericPropertyHandler, which (via inspection) finds 179 // a property SupportedServiceNames, resulting from the XServiceInfo.getSupportedServiceNames 180 // method. Since we handle those ourself, we supersede them. 181 } 182 183 public com.sun.star.beans.Property[] getSupportedProperties() 184 { 185 Property[] properties = new Property[ m_supportedServices.length ]; 186 for ( int i=0; i<m_supportedServices.length; ++i ) 187 properties[i] = new Property( m_supportedServices[i], 0, new Type( String.class ), (short)0 ); 188 return properties; 189 } 190 191 public void inspect(Object _component) throws com.sun.star.lang.NullPointerException 192 { 193 XServiceInfo serviceInfo = (XServiceInfo)UnoRuntime.queryInterface( XServiceInfo.class, _component ); 194 if ( serviceInfo != null ) 195 m_supportedServices = serviceInfo.getSupportedServiceNames(); 196 } 197 198 public boolean isComposable(String _propertyName) throws com.sun.star.beans.UnknownPropertyException 199 { 200 return true; 201 } 202 203 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 204 { 205 return InteractiveSelectionResult.Cancelled; 206 } 207 208 public void removeEventListener(com.sun.star.lang.XEventListener _eventListener) 209 { 210 // ignoring this 211 } 212 213 public void removePropertyChangeListener(com.sun.star.beans.XPropertyChangeListener _propertyChangeListener) 214 { 215 // ignoring this 216 } 217 218 public void setPropertyValue(String str, Object obj) throws com.sun.star.beans.UnknownPropertyException 219 { 220 // we declared our properties as readonly 221 throw new java.lang.RuntimeException(); 222 } 223 224 public boolean suspend(boolean param) 225 { 226 return true; 227 } 228 } 229