Branch libreoffice-5-0-4
[LibreOffice.git] / odk / examples / java / Spreadsheet / CalcAddins.java
blob0422eccb5e915e7399adb313b4d9fee2e8c8a562
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * the BSD license.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *************************************************************************/
35 // Template for an Office Calc add-in Java implementation file.
37 /** You can find more
38 * information on the following web page:
39 * http://api.libreoffice.org/
41 import com.sun.star.comp.loader.FactoryHelper;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.lang.XSingleServiceFactory;
44 import com.sun.star.registry.XRegistryKey;
45 import com.sun.star.lib.uno.helper.WeakBase;
46 import com.sun.star.lang.XServiceInfo;
47 import com.sun.star.lang.XServiceName;
48 import com.sun.star.sheet.XAddIn;
49 import com.sun.star.lang.Locale;
50 import org.openoffice.sheet.addin.XCalcAddins;
52 /** This outer class provides an inner class to implement the service
53 * description, a method to instantiate the
54 * component on demand (__getServiceFactory()), and a method to give
55 * information about the component (__writeRegistryServiceInfo()).
57 public class CalcAddins {
59 /** This inner class provides the component as a concrete implementation
60 * of the service description. It implements the needed interfaces.
61 * @implements XCalcAddins, XAddIn, XServiceName, XServiceInfo, XTypeProvider
63 static public class _CalcAddins extends WeakBase implements
64 XCalcAddins,
65 XAddIn,
66 XServiceName,
67 XServiceInfo
70 /** The component will be registered under this name.
72 static private final String __serviceName = "org.openoffice.sheet.addin.CalcAddins";
74 static private final String ADDIN_SERVICE = "com.sun.star.sheet.AddIn";
76 private Locale aFuncLoc;
78 private static final String[] stringFunctionName = {
79 /** TO DO:
80 * You should replace these method names by the method names of your interface.
82 "getMyFirstValue",
83 "getMySecondValue"
86 /** TO DO:
87 * For each of your methods you should make up a new constant with a different value.
89 private static final short shortGETMYFIRSTVALUE = 0;
90 private static final short shortGETMYSECONDVALUE = 1;
92 /** TO DO:
93 * This is where you implement all methods of your interface. The parameters have to
94 * be the same as in your IDL file and their types have to be the correct
95 * IDL-to-Java mappings of their types in the IDL file.
97 public int getMyFirstValue(
98 com.sun.star.beans.XPropertySet xOptions
99 ) {
100 return 1;
103 public int getMySecondValue(
104 com.sun.star.beans.XPropertySet xOptions,
105 int intDummy
107 return 2 + intDummy;
110 // Implement method from interface XServiceName
111 public String getServiceName() {
112 return __serviceName;
115 // Implement methods from interface XServiceInfo
116 public boolean supportsService(String stringServiceName) {
117 return( stringServiceName.equals( ADDIN_SERVICE ) ||
118 stringServiceName.equals( __serviceName ) );
121 public String getImplementationName() {
122 return _CalcAddins.class.getName();
125 public String[] getSupportedServiceNames() {
126 String[] stringSupportedServiceNames = { ADDIN_SERVICE, __serviceName };
127 return stringSupportedServiceNames;
130 // Implement methods from interface XAddIn
131 public String getDisplayArgumentName(String stringProgrammaticFunctionName,int intArgument) {
132 String stringReturn = "";
134 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
135 /** TO DO:
136 * You should list all argument names for each of your methods, here.
138 case shortGETMYFIRSTVALUE:
139 switch( intArgument ) {
140 case 0:
141 stringReturn = "(internal)";
142 break;
144 break;
145 case shortGETMYSECONDVALUE:
146 switch( intArgument ) {
147 case 0:
148 stringReturn = "(internal)";
149 break;
150 case 1:
151 stringReturn = "intDummy";
152 break;
154 break;
156 return stringReturn;
159 public String getDisplayFunctionName(String stringProgrammaticName) {
160 String stringReturn = "";
162 switch( this.getFunctionID( stringProgrammaticName ) ) {
163 /** TO DO:
164 * Assign the name of each of your methods.
166 case shortGETMYFIRSTVALUE:
167 stringReturn = "getMyFirstValue";
168 break;
169 case shortGETMYSECONDVALUE:
170 stringReturn = "getMySecondValue";
171 break;
174 return stringReturn;
177 public String getProgrammaticCategoryName(String p1) {
178 return "Add-In";
181 public String getDisplayCategoryName(String p1) {
182 return "Add-In";
185 public String getFunctionDescription(String stringProgrammaticName) {
186 String stringReturn = "";
188 switch( this.getFunctionID( stringProgrammaticName ) ) {
189 /** TO DO:
190 * Enter a description for each of your methods that office users will understand.
192 case shortGETMYFIRSTVALUE:
193 stringReturn = "This is your first method.";
194 break;
195 case shortGETMYSECONDVALUE:
196 stringReturn = "This is your second method.";
197 break;
200 return stringReturn;
203 public String getArgumentDescription(String stringProgrammaticFunctionName,int intArgument) {
204 String stringReturn = "";
206 switch( this.getFunctionID( stringProgrammaticFunctionName ) ) {
207 /** TO DO:
208 * Enter a description for every argument of every method. Make them so that office users will understand.
210 case shortGETMYFIRSTVALUE:
211 switch( intArgument ) {
212 case 0:
213 stringReturn = "(internal)";
214 break;
216 break;
217 case shortGETMYSECONDVALUE:
218 switch( intArgument ) {
219 case 0:
220 stringReturn = "(internal)";
221 break;
222 case 1:
223 stringReturn = "You can add this value.";
224 break;
226 break;
228 return stringReturn;
231 public String getProgrammaticFuntionName(String p1) {
232 return "";
235 // Implement methods from interface XLocalizable
236 public Locale getLocale() {
237 return aFuncLoc;
240 public void setLocale(Locale p1) {
241 aFuncLoc = p1;
244 // Auxiliary functions
245 private short getFunctionID( String stringProgrammaticName ) {
246 for ( int i = 0; i < stringFunctionName.length; i++ ) {
247 if ( stringProgrammaticName.equals( stringFunctionName[ i ] ) ) {
248 return ( short ) i;
252 return -1;
257 * Returns a factory for creating the service.
258 * This method is called by the <code>JavaLoader</code>
259 * <p>
260 * @return returns a <code>XSingleServiceFactory</code> for creating the component
261 * @param implName the name of the implementation for which a service is desired
262 * @param multiFactory the service manager to be used if needed
263 * @param regKey the registryKey
264 * @see com.sun.star.comp.loader.JavaLoader
266 public static XSingleServiceFactory __getServiceFactory(String implName,
267 XMultiServiceFactory multiFactory,
268 XRegistryKey regKey) {
269 XSingleServiceFactory xSingleServiceFactory = null;
271 if (implName.equals(_CalcAddins.class.getName()) )
272 xSingleServiceFactory = FactoryHelper.getServiceFactory(_CalcAddins.class,
273 _CalcAddins.__serviceName,
274 multiFactory,
275 regKey);
277 return xSingleServiceFactory;