CalcAddins.java (34dd1e25) | CalcAddins.java (5f946091) |
---|---|
1/************************************************************** | 1/************************************************************** |
2 * | 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 | 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 * | 10 * |
11 * http://www.apache.org/licenses/LICENSE-2.0 | 11 * http://www.apache.org/licenses/LICENSE-2.0 |
12 * | 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. | 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 * | 19 * |
20 *************************************************************/ 21 22 23 24// Template for an Office Calc add-in Java implementation file. 25 26/** You can find more 27 * information on the following web page: --- 17 unchanged lines hidden (view full) --- 45import org.openoffice.sheet.addin.XCalcAddins; 46 47/** This outer class provides an inner class to implement the service 48 * description, a method to instantiate the 49 * component on demand (__getServiceFactory()), and a method to give 50 * information about the component (__writeRegistryServiceInfo()). 51 */ 52public class CalcAddins { | 20 *************************************************************/ 21 22 23 24// Template for an Office Calc add-in Java implementation file. 25 26/** You can find more 27 * information on the following web page: --- 17 unchanged lines hidden (view full) --- 45import org.openoffice.sheet.addin.XCalcAddins; 46 47/** This outer class provides an inner class to implement the service 48 * description, a method to instantiate the 49 * component on demand (__getServiceFactory()), and a method to give 50 * information about the component (__writeRegistryServiceInfo()). 51 */ 52public class CalcAddins { |
53 | 53 |
54/** This inner class provides the component as a concrete implementation 55 * of the service description. It implements the needed interfaces. 56 * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider 57 */ 58 static public class _CalcAddins extends WeakBase implements 59 XCalcAddins, 60 XAddIn, 61 XServiceName, 62 XServiceInfo 63 { | 54/** This inner class provides the component as a concrete implementation 55 * of the service description. It implements the needed interfaces. 56 * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider 57 */ 58 static public class _CalcAddins extends WeakBase implements 59 XCalcAddins, 60 XAddIn, 61 XServiceName, 62 XServiceInfo 63 { |
64 | 64 |
65/** The component will be registered under this name. 66 */ 67 static private final String __serviceName = "org.openoffice.sheet.addin.CalcAddins"; | 65/** The component will be registered under this name. 66 */ 67 static private final String __serviceName = "org.openoffice.sheet.addin.CalcAddins"; |
68 | 68 |
69 static private final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn"; | 69 static private final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn"; |
70 | 70 |
71 private Locale aFuncLoc; | 71 private Locale aFuncLoc; |
72 | 72 |
73 private static final String[] stringFunctionName = { 74/** TO DO: 75 * You should replace these method names by the method names of your interface. 76 */ 77 "getMyFirstValue", 78 "getMySecondValue" 79 }; | 73 private static final String[] stringFunctionName = { 74/** TO DO: 75 * You should replace these method names by the method names of your interface. 76 */ 77 "getMyFirstValue", 78 "getMySecondValue" 79 }; |
80 | 80 |
81 private static final short shortINVALID = -1; | 81 private static final short shortINVALID = -1; |
82 | 82 |
83/** TO DO: 84 * For each of your methods you should make up a new constant with a different value. 85 */ 86 private static final short shortGETMYFIRSTVALUE = 0; 87 private static final short shortGETMYSECONDVALUE = 1; | 83/** TO DO: 84 * For each of your methods you should make up a new constant with a different value. 85 */ 86 private static final short shortGETMYFIRSTVALUE = 0; 87 private static final short shortGETMYSECONDVALUE = 1; |
88 89 | 88 89 |
90/** TO DO: 91 * This is where you implement all methods of your interface. The parameters have to | 90/** TO DO: 91 * This is where you implement all methods of your interface. The parameters have to |
92 * be the same as in your IDL file and their types have to be the correct | 92 * be the same as in your IDL file and their types have to be the correct |
93 * IDL-to-Java mappings of their types in the IDL file. 94 */ 95 public int getMyFirstValue( 96 com.sun.star.beans.XPropertySet xOptions 97 ) { 98 return (int) 1; 99 } | 93 * IDL-to-Java mappings of their types in the IDL file. 94 */ 95 public int getMyFirstValue( 96 com.sun.star.beans.XPropertySet xOptions 97 ) { 98 return (int) 1; 99 } |
100 | 100 |
101 public int getMySecondValue( 102 com.sun.star.beans.XPropertySet xOptions, 103 int intDummy 104 ) { 105 return( (int) ( 2 + intDummy ) ); 106 } | 101 public int getMySecondValue( 102 com.sun.star.beans.XPropertySet xOptions, 103 int intDummy 104 ) { 105 return( (int) ( 2 + intDummy ) ); 106 } |
107 108 | 107 108 |
109 // Implement method from interface XServiceName 110 public String getServiceName() { 111 return( __serviceName ); 112 } | 109 // Implement method from interface XServiceName 110 public String getServiceName() { 111 return( __serviceName ); 112 } |
113 | 113 |
114 // Implement methods from interface XServiceInfo 115 public boolean supportsService(String stringServiceName) { 116 return( stringServiceName.equals( ADDIN_SERVICE ) || 117 stringServiceName.equals( __serviceName ) ); 118 } | 114 // Implement methods from interface XServiceInfo 115 public boolean supportsService(String stringServiceName) { 116 return( stringServiceName.equals( ADDIN_SERVICE ) || 117 stringServiceName.equals( __serviceName ) ); 118 } |
119 | 119 |
120 public String getImplementationName() { 121 return( _CalcAddins.class.getName() ); 122 } | 120 public String getImplementationName() { 121 return( _CalcAddins.class.getName() ); 122 } |
123 | 123 |
124 public String[] getSupportedServiceNames() { 125 String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName }; 126 return( stringSupportedServiceNames ); 127 } | 124 public String[] getSupportedServiceNames() { 125 String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName }; 126 return( stringSupportedServiceNames ); 127 } |
128 | 128 |
129 // Implement methods from interface XAddIn 130 public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) { 131 String stringReturn = ""; | 129 // Implement methods from interface XAddIn 130 public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) { 131 String stringReturn = ""; |
132 | 132 |
133 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) { 134/** TO DO: 135 * You should list all argument names for each of your methods, here. 136 */ 137 case shortGETMYFIRSTVALUE: 138 switch( intArgument ) { 139 case 0: 140 stringReturn = "(internal)"; --- 8 unchanged lines hidden (view full) --- 149 case 1: 150 stringReturn = "intDummy"; 151 break; 152 } 153 break; 154 } 155 return( stringReturn ); 156 } | 133 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) { 134/** TO DO: 135 * You should list all argument names for each of your methods, here. 136 */ 137 case shortGETMYFIRSTVALUE: 138 switch( intArgument ) { 139 case 0: 140 stringReturn = "(internal)"; --- 8 unchanged lines hidden (view full) --- 149 case 1: 150 stringReturn = "intDummy"; 151 break; 152 } 153 break; 154 } 155 return( stringReturn ); 156 } |
157 | 157 |
158 public String getDisplayFunctionName(String stringProgrammaticName) { 159 String stringReturn = ""; | 158 public String getDisplayFunctionName(String stringProgrammaticName) { 159 String stringReturn = ""; |
160 | 160 |
161 switch( this.getFunctionID( stringProgrammaticName ) ) { 162/** TO DO: 163 * Assign the name of each of your methods. 164 */ 165 case shortGETMYFIRSTVALUE: 166 stringReturn = "getMyFirstValue"; 167 break; 168 case shortGETMYSECONDVALUE: 169 stringReturn = "getMySecondValue"; 170 break; 171 } | 161 switch( this.getFunctionID( stringProgrammaticName ) ) { 162/** TO DO: 163 * Assign the name of each of your methods. 164 */ 165 case shortGETMYFIRSTVALUE: 166 stringReturn = "getMyFirstValue"; 167 break; 168 case shortGETMYSECONDVALUE: 169 stringReturn = "getMySecondValue"; 170 break; 171 } |
172 | 172 |
173 return( stringReturn ); 174 } | 173 return( stringReturn ); 174 } |
175 | 175 |
176 public String getProgrammaticCategoryName(String p1) { 177 return( "Add-In" ); 178 } | 176 public String getProgrammaticCategoryName(String p1) { 177 return( "Add-In" ); 178 } |
179 | 179 |
180 public String getDisplayCategoryName(String p1) { 181 return( "Add-In" ); 182 } | 180 public String getDisplayCategoryName(String p1) { 181 return( "Add-In" ); 182 } |
183 | 183 |
184 public String getFunctionDescription(String stringProgrammaticName) { 185 String stringReturn = ""; | 184 public String getFunctionDescription(String stringProgrammaticName) { 185 String stringReturn = ""; |
186 | 186 |
187 switch( this.getFunctionID( stringProgrammaticName ) ) { 188/** TO DO: 189 * Enter a description for each of your methods that office users will understand. 190 */ 191 case shortGETMYFIRSTVALUE: 192 stringReturn = "This is your first method."; 193 break; 194 case shortGETMYSECONDVALUE: 195 stringReturn = "This is your second method."; 196 break; 197 } | 187 switch( this.getFunctionID( stringProgrammaticName ) ) { 188/** TO DO: 189 * Enter a description for each of your methods that office users will understand. 190 */ 191 case shortGETMYFIRSTVALUE: 192 stringReturn = "This is your first method."; 193 break; 194 case shortGETMYSECONDVALUE: 195 stringReturn = "This is your second method."; 196 break; 197 } |
198 | 198 |
199 return( stringReturn ); 200 } | 199 return( stringReturn ); 200 } |
201 | 201 |
202 public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) { 203 String stringReturn = ""; | 202 public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) { 203 String stringReturn = ""; |
204 | 204 |
205 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) { 206/** TO DO: 207 * Enter a description for every argument of every method. Make them so that office users will understand. 208 */ 209 case shortGETMYFIRSTVALUE: 210 switch( intArgument ) { 211 case 0: 212 stringReturn = "(internal)"; --- 8 unchanged lines hidden (view full) --- 221 case 1: 222 stringReturn = "You can add this value."; 223 break; 224 } 225 break; 226 } 227 return( stringReturn ); 228 } | 205 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) { 206/** TO DO: 207 * Enter a description for every argument of every method. Make them so that office users will understand. 208 */ 209 case shortGETMYFIRSTVALUE: 210 switch( intArgument ) { 211 case 0: 212 stringReturn = "(internal)"; --- 8 unchanged lines hidden (view full) --- 221 case 1: 222 stringReturn = "You can add this value."; 223 break; 224 } 225 break; 226 } 227 return( stringReturn ); 228 } |
229 | 229 |
230 public String getProgrammaticFuntionName(String p1) { 231 return( "" ); 232 } | 230 public String getProgrammaticFuntionName(String p1) { 231 return( "" ); 232 } |
233 | 233 |
234 // Implement methods from interface XLocalizable 235 public Locale getLocale() { 236 return( aFuncLoc ); 237 } | 234 // Implement methods from interface XLocalizable 235 public Locale getLocale() { 236 return( aFuncLoc ); 237 } |
238 | 238 |
239 public void setLocale(Locale p1) { 240 aFuncLoc = p1; 241 } | 239 public void setLocale(Locale p1) { 240 aFuncLoc = p1; 241 } |
242 | 242 |
243 // Auxiliary functions 244 private short getFunctionID( String stringProgrammaticName ) { 245 for ( int i = 0; i < stringFunctionName.length; i++ ) { 246 if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) { 247 return( ( short ) i ); 248 } 249 } | 243 // Auxiliary functions 244 private short getFunctionID( String stringProgrammaticName ) { 245 for ( int i = 0; i < stringFunctionName.length; i++ ) { 246 if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) { 247 return( ( short ) i ); 248 } 249 } |
250 | 250 |
251 return( -1 ); 252 } 253 } | 251 return( -1 ); 252 } 253 } |
254 | 254 |
255 /** 256 * Returns a factory for creating the service. 257 * This method is called by the <code>JavaLoader</code> 258 * <p> 259 * @return returns a <code>XSingleServiceFactory</code> for creating the component 260 * @param implName the name of the implementation for which a service is desired 261 * @param multiFactory the service manager to be used if needed 262 * @param regKey the registryKey 263 * @see com.sun.star.comp.loader.JavaLoader 264 */ 265 public static XSingleServiceFactory __getServiceFactory(String implName, 266 XMultiServiceFactory multiFactory, 267 XRegistryKey regKey) { 268 XSingleServiceFactory xSingleServiceFactory = null; | 255 /** 256 * Returns a factory for creating the service. 257 * This method is called by the <code>JavaLoader</code> 258 * <p> 259 * @return returns a <code>XSingleServiceFactory</code> for creating the component 260 * @param implName the name of the implementation for which a service is desired 261 * @param multiFactory the service manager to be used if needed 262 * @param regKey the registryKey 263 * @see com.sun.star.comp.loader.JavaLoader 264 */ 265 public static XSingleServiceFactory __getServiceFactory(String implName, 266 XMultiServiceFactory multiFactory, 267 XRegistryKey regKey) { 268 XSingleServiceFactory xSingleServiceFactory = null; |
269 | 269 |
270 if (implName.equals(_CalcAddins.class.getName()) ) 271 xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class, 272 _CalcAddins.__serviceName, 273 multiFactory, 274 regKey); | 270 if (implName.equals(_CalcAddins.class.getName()) ) 271 xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class, 272 _CalcAddins.__serviceName, 273 multiFactory, 274 regKey); |
275 | 275 |
276 return xSingleServiceFactory; 277 } | 276 return xSingleServiceFactory; 277 } |
278 | 278 |
279 /** 280 * Writes the service information into the given registry key. 281 * This method is called by the <code>JavaLoader</code> 282 * <p> 283 * @return returns true if the operation succeeded 284 * @param regKey the registryKey 285 * @see com.sun.star.comp.loader.JavaLoader 286 */ 287 // This method not longer necessary since OOo 3.4 where the component registration 288 // was changed to passive component registration. For more details see | 279 /** 280 * Writes the service information into the given registry key. 281 * This method is called by the <code>JavaLoader</code> 282 * <p> 283 * @return returns true if the operation succeeded 284 * @param regKey the registryKey 285 * @see com.sun.star.comp.loader.JavaLoader 286 */ 287 // This method not longer necessary since OOo 3.4 where the component registration 288 // was changed to passive component registration. For more details see |
289 // http://wiki.services.openoffice.org/wiki/Passive_Component_Registration | 289 // https://wiki.openoffice.org/wiki/Passive_Component_Registration |
290 291// public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { 292// return FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(), 293// _CalcAddins.__serviceName, regKey) 294// && FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(), 295// _CalcAddins.ADDIN_SERVICE, regKey); 296// } 297} | 290 291// public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { 292// return FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(), 293// _CalcAddins.__serviceName, regKey) 294// && FactoryHelper.writeRegistryServiceInfo(_CalcAddins.class.getName(), 295// _CalcAddins.ADDIN_SERVICE, regKey); 296// } 297} |
298 |
|