diff --git a/odk/examples/java/ToDo/ToDo.java b/odk/examples/java/ToDo/ToDo.java index b7bf43c3bb0f..353c77832ae1 100644 --- a/odk/examples/java/ToDo/ToDo.java +++ b/odk/examples/java/ToDo/ToDo.java @@ -2,9 +2,9 @@ * * $RCSfile: ToDo.java,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: obo $ $Date: 2003-10-20 13:14:13 $ + * last change: $Author: rt $ $Date: 2005-01-31 17:19:47 $ * * The Contents of this file are made available subject to the terms of * the BSD license. @@ -38,11 +38,12 @@ * *************************************************************************/ -import com.sun.star.comp.loader.FactoryHelper; +import com.sun.star.lib.uno.helper.Factory; import com.sun.star.lang.XInitialization; +import com.sun.star.lang.XMultiComponentFactory; +import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XServiceInfo; -import com.sun.star.lang.XSingleServiceFactory; import com.sun.star.lang.XTypeProvider; import com.sun.star.lib.uno.helper.WeakBase; import com.sun.star.registry.XRegistryKey; @@ -50,6 +51,7 @@ import com.sun.star.uno.Type; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.uno.XWeak; +import com.sun.star.uno.XComponentContext; import org.openoffice.*; // addintional interfaces used by the implementation @@ -83,63 +85,26 @@ import java.util.Arrays; */ public class ToDo { - /** Gives a factory for creating the service. - * This method is called by the JavaLoader - *

- * @return Returns a XSingleServiceFactory for creating the - * component. - * @see com.sun.star.comp.loader.JavaLoader# - * @param stringImplementationName The implementation name of the component. - * @param xmultiservicefactory The service manager, who gives access to every - * known service. - * @param xregistrykey Makes structural information (except regarding tree - * structures) of a single - * registry key accessible. - */ - public static XSingleServiceFactory __getServiceFactory(String stringImplementationName, - XMultiServiceFactory xmultiservicefactory, - XRegistryKey xregistrykey) { - XSingleServiceFactory xsingleservicefactory = null; - - if ( stringImplementationName.equals( - ToDoImplementation.class.getName() ) ) - xsingleservicefactory = FactoryHelper.getServiceFactory( - ToDoImplementation.class, - ToDoImplementation.__serviceName, - xmultiservicefactory, - xregistrykey ); - - return xsingleservicefactory; - } - - /** Writes the service information into the given registry key. - * This method is called by the JavaLoader. - * @return returns true if the operation succeeded - * @see com.sun.star.comp.loader.JavaLoader# - * @param xregistrykey Makes structural information (except regarding tree - * structures) of a single - * registry key accessible. - */ - public static boolean __writeRegistryServiceInfo(XRegistryKey xregistrykey) { - return FactoryHelper.writeRegistryServiceInfo( - ToDoImplementation.class.getName(), - ToDoImplementation.__serviceName, - xregistrykey ); - } - /** This class implements the component. At least the interfaces * XInterface, XTypeProvider, and XWeak implemented by the helper class * WeakBase and XServiceInfo should be provided by the service. */ - public static class ToDoImplementation extends WeakBase implements XServiceInfo, XToDo { + public static class ToDoImpl extends WeakBase implements XServiceInfo, XToDo { /** The service name, that must be used to get an instance of this service. */ private static final String __serviceName = "org.openoffice.ToDo"; - /** The service manager, that gives access to all registered services. + /** The initial component contextr, that gives access to + * the service manager, supported singletons, ... + * It's often later used */ - private XMultiServiceFactory xmultiservicefactory; + private XComponentContext m_cmpCtx; + + /** The service manager, that gives access to all registered services. + * It's often later used + */ + private XMultiComponentFactory m_xMCF; // Implementation helper variables static private final int INT_COLUMN_FEATURE = 0; @@ -160,59 +125,60 @@ public class ToDo { static private final String STRING_SEPARATOR = "/"; - /** The constructor of the inner class has a XMultiServiceFactory parameter. - * @param xmultiservicefactoryInitialization A special service factory - * could be introduced while initializing. + /** The constructor of the inner class has a XComponenContext parameter. + * @param xCompContext the initial component context */ - public ToDoImplementation(XMultiServiceFactory xmultiservicefactoryInitialization) { - xmultiservicefactory = xmultiservicefactoryInitialization; + public ToDoImpl(XComponentContext xCompContext) { + try { + m_cmpCtx = xCompContext; + m_xMCF = m_cmpCtx.getServiceManager(); + } + catch( Exception e ) { + e.printStackTrace(System.err); + } } /** This method returns an array of all supported service names. * @return Array of supported service names. */ public String[] getSupportedServiceNames() { - String []stringSupportedServiceNames = new String[ 1 ]; + return getServiceNames(); + } - stringSupportedServiceNames[ 0 ] = __serviceName; - - return( stringSupportedServiceNames ); + public static String[] getServiceNames() { + String[] sSupportedServiceNames = { __serviceName }; + return sSupportedServiceNames; } /** This method returns true, if the given service will be * supported by the component. - * @param stringService Service name. + * @param sService Service name. * @return True, if the given service name will be supported. */ - public boolean supportsService(String stringService) { - boolean booleanSupportsService = false; - - if ( stringService.equals( __serviceName ) ) { - booleanSupportsService = true; - } - - return( booleanSupportsService ); + public boolean supportsService(String sServiceName) { + return sServiceName.equals( __serviceName ); } /** Return the class name of the component. * @return Class name of the component. */ public String getImplementationName() { - return( ToDoImplementation.class.getName() ); + return ToDoImpl.class.getName(); } - /** For every bug/feature listed in a spreadsheet document this method calculates - * the start date, day of week of the start date, the end date and the day of week - * of the end date. All calculations are dependent on the values of "Needed Days", - * "Due Date" and "Status". The columns "Needed Days" and "Status" are mandatory. - * The first feature/bug should be placed in row nine. The date to start the - * calculation should be placed in cell C6. The private holidays should be placed - * in cell K4/K5 and below. - * All rows will be calculated up to the first empty cell in the first column. - * If a cell in the column "Due Date" will be colored red, you should take a look - * at your entries. + /** For every bug/feature listed in a spreadsheet document this method + * calculates the start date, day of week of the start date, the end date + * and the day of week of the end date. All calculations are dependent + * on the values of "Needed Days", "Due Date" and "Status". The columns + * "Needed Days" and "Status" are mandatory. The first feature/bug should + * be placed in row nine. The date to start the calculation should be + * placed in cell C6. The private holidays should be placed in cell K4/K5 + * and below. All rows will be calculated up to the first empty cell in + * the first column. If a cell in the column "Due Date" will be colored + * red, you should take a look at your entries. * @param aInstance Spreadsheet document. - * @throws com.sun.star.uno.RuntimeException This exception could occur at every interface method. + * @throws com.sun.star.uno.RuntimeException This exception could occur + * at every interface method. */ public void recalc( java.lang.Object aInstance ) throws com.sun.star.uno.RuntimeException { @@ -235,20 +201,22 @@ public class ToDo { XCellRange xcellrange = ( XCellRange ) UnoRuntime.queryInterface( XCellRange.class, xspreadsheet ); - /* Getting the gregorian calendar with the date on which to start the - calculation */ - GregorianCalendar gregoriancalendarAbsoluteStartDate = - this.getGregorianCalendarFromString(this.getStringFromCell( xcellrange, 5, 2 ) ); - gregoriancalendarAbsoluteStartDate.add( Calendar.DATE, -1 ); + /* Getting the gregorian calendar with the date on which to start + the calculation */ + GregorianCalendar gregCalAbsoluteStartDate = + this.getGregorianCalendarFromString(this.getStringFromCell( + xcellrange, 5, 2 ) ); + gregCalAbsoluteStartDate.add( Calendar.DATE, -1 ); // Set the start date with the absolute start date - GregorianCalendar gregoriancalendarStartDate = - (GregorianCalendar) gregoriancalendarAbsoluteStartDate.clone(); + GregorianCalendar gregCalStartDate = + (GregorianCalendar) gregCalAbsoluteStartDate.clone(); - /* Creating the service FunctionAccess, which allows generic access to - all spreadsheet functions */ + /* Creating the service FunctionAccess, which allows generic + access to all spreadsheet functions */ Object objectFunctionAccess = - xmultiservicefactory.createInstance("com.sun.star.sheet.FunctionAccess" ); + m_xMCF.createInstanceWithContext( + "com.sun.star.sheet.FunctionAccess", m_cmpCtx ); // Querying for the interface XFunctionAccess on service // FunctionAccess @@ -262,10 +230,12 @@ public class ToDo { // Get the Official Holidays this.getOfficialHolidays( vectorHolidays, xcellrange, xfunctionaccess, - gregoriancalendarStartDate.get( Calendar.YEAR ) ); + gregCalStartDate.get( + Calendar.YEAR ) ); // Get the private holidays - this.getPrivateHolidays( vectorHolidays, xcellrange, xfunctionaccess ); + this.getPrivateHolidays(vectorHolidays, xcellrange, + xfunctionaccess); // Getting the object array of holidays Object[] objectSortedHolidays = vectorHolidays.toArray(); @@ -281,14 +251,15 @@ public class ToDo { int intRowTo = this.INT_ROW_FROM - 1; // Getting the feature of the first cell - String stringFeature = this.getStringFromCell( xcellrange, - intRowTo + 1, this.INT_COLUMN_FEATURE ); + String sFeature = this.getStringFromCell(xcellrange, + intRowTo + 1, + this.INT_COLUMN_FEATURE); // Determine the last row with an entry in the first column - while ( ( stringFeature != null ) && - ( !stringFeature.equals( "" ) ) ) { + while ( ( sFeature != null ) && + ( !sFeature.equals( "" ) ) ) { intRowTo++; - stringFeature = this.getStringFromCell( xcellrange, + sFeature = this.getStringFromCell( xcellrange, intRowTo + 1, this.INT_COLUMN_FEATURE ); } @@ -296,24 +267,26 @@ public class ToDo { final int INT_ROW_TO = intRowTo + 1; // Deleting cells which will be recalculated - for ( int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO + 5; intRow++ ) { + for ( int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO + 5; + intRow++ ) { for ( int intColumn = this.INT_COLUMN_STARTDATE; intColumn <= this.INT_COLUMN_END_DAY_OF_WEEK; intColumn++ ) { - this.setStringToCell( xcellrange, intRow, intColumn, - "" ); + this.setStringToCell(xcellrange, intRow, intColumn, ""); } } - /* Clearing the background color of the due date cells and setting the + /* Clearing the background color of the due date cells and setting the hyperlink to the bugtracker */ - for ( int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++ ) { - - // Querying for the interface XPropertySet for the cell providing the due date + for (int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++) + { + // Querying for the interface XPropertySet for the cell + // providing the due date XPropertySet xpropertyset = ( XPropertySet ) - UnoRuntime.queryInterface( XPropertySet.class, - xcellrange.getCellByPosition( this.INT_COLUMN_DUEDATE, - intRow ) ); + UnoRuntime.queryInterface(XPropertySet.class, + xcellrange.getCellByPosition( + this.INT_COLUMN_DUEDATE, + intRow )); // Changing the background color of the cell to white xpropertyset.setPropertyValue( "CellBackColor", @@ -335,21 +308,20 @@ public class ToDo { UnoRuntime.queryInterface( XTextRange.class, xtextcursor ); // Getting the bug ID from the cell - String stringBugID = xtextrange.getString(); - if ( !stringBugID.startsWith( "http://so-web1.germany.sun.com/bis/servlet/" + - "intray.ControlPanel?system=1&update=true&id=" ) ) { - String stringBugIDLink = "http://so-web1.germany.sun.com/bis/servlet/" + - "intray.ControlPanel?system=1&update=true&id=" + stringBugID + - "&showframeset=true"; + String sBugID = xtextrange.getString(); + if ( !sBugID.startsWith( + "http://www.openoffice.org/issues/show_bug.cgi?id=") ) { + String sBugIDLink = + "http://www.openoffice.org/issues/show_bug.cgi?id=" + sBugID; // Querying for the interface XMultiServiceFactory - XMultiServiceFactory xmultiservicefactoryTextField = - (XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, - aInstance ); + XMultiServiceFactory xMSFTextField = + (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory.class, aInstance ); // Creating an instance of the text field URL Object objectTextField = - xmultiservicefactoryTextField.createInstance( + xMSFTextField.createInstance( "com.sun.star.text.TextField.URL" ); // Querying for the interface XTextField @@ -363,13 +335,16 @@ public class ToDo { xtextfield ); // Setting the URL - xpropertysetTextField.setPropertyValue( "URL", stringBugIDLink ); + xpropertysetTextField.setPropertyValue( "URL", + sBugIDLink ); // Setting the representation of the URL - xpropertysetTextField.setPropertyValue( "Representation", stringBugID ); + xpropertysetTextField.setPropertyValue( "Representation", + sBugID ); // Querying for the interface XText - XText xtext = ( XText )UnoRuntime.queryInterface( XText.class, xcell ); + XText xtext = ( XText )UnoRuntime.queryInterface( + XText.class, xcell ); // Delete cell content xtextrange.setString( "" ); @@ -380,162 +355,196 @@ public class ToDo { } // Processing all features/bugs in the table - for ( int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++ ) { - // Getting the cell of the column "Needed Days" in the current row - XCell xcell = xcellrange.getCellByPosition( INT_COLUMN_NEEDEDDAYS, intRow ); + for (int intRow = this.INT_ROW_FROM; intRow < INT_ROW_TO; intRow++) + { + // Getting the cell of the column "Needed Days" in the + // current row + XCell xcell = xcellrange.getCellByPosition( + INT_COLUMN_NEEDEDDAYS, intRow ); // Getting the number of needed days to perform the feature int intNeededDays = (int) Math.round( xcell.getValue() ); // Getting the content of a specified cell - String stringStatus = this.getStringFromCell( xcellrange, + String sStatus = this.getStringFromCell( xcellrange, intRow, this.INT_COLUMN_STATUS ); - /* Testing if the number of needed days is greater than zero and if + /* Testing if the number of needed days is greater than + zero and if the status is not "done" */ if ( ( intNeededDays > 0 ) - && !( stringStatus.toLowerCase().trim().equals( "done" ) ) ) { - // Getting the start date after a specified number of workdays - gregoriancalendarStartDate = this.getWorkday( - gregoriancalendarStartDate, 1, objectHolidays, + && !( sStatus.toLowerCase().trim().equals("done")) ) { + // Getting the start date after a specified number of + // workdays + gregCalStartDate = this.getWorkday( + gregCalStartDate, 1, objectHolidays, xfunctionaccess ); - // Getting a string with the date format jjjj-mm-dd from the gregorian calendar - String stringDate = this.getStringFromGregorianCalendar( - gregoriancalendarStartDate ); + // Getting a string with the date format jjjj-mm-dd from + // the gregorian calendar + String sDate = this.getStringFromGregorianCalendar( + gregCalStartDate ); // Set the start date in the specified cell of the table - this.setStringToCell( xcellrange, intRow, - this.INT_COLUMN_STARTDATE, stringDate ); + this.setStringToCell(xcellrange, intRow, + this.INT_COLUMN_STARTDATE, sDate); - // For the start day set the day of week in the specified cell of the table - this.setDayOfWeek( gregoriancalendarStartDate, - xcellrange, intRow, this.INT_COLUMN_START_DAY_OF_WEEK ); + // For the start day set the day of week in the specified + // cell of the table + this.setDayOfWeek( gregCalStartDate, + xcellrange, intRow, + this.INT_COLUMN_START_DAY_OF_WEEK ); // Getting the end date after a specified number of workdays - GregorianCalendar gregoriancalendarEndDate = - this.getWorkday( gregoriancalendarStartDate, + GregorianCalendar gregCalEndDate = + this.getWorkday( gregCalStartDate, intNeededDays - 1, objectHolidays, xfunctionaccess ); // Creating a string with the date format jjjj-mm-dd - stringDate = this.getStringFromGregorianCalendar( - gregoriancalendarEndDate ); + sDate = this.getStringFromGregorianCalendar( + gregCalEndDate ); // Set the end date in the specified cell of the table this.setStringToCell( xcellrange, intRow, - this.INT_COLUMN_ENDDATE, stringDate ); + this.INT_COLUMN_ENDDATE, sDate ); - // For the end day set the day of week in the specified cell of the table - this.setDayOfWeek( gregoriancalendarEndDate, xcellrange, - intRow, this.INT_COLUMN_END_DAY_OF_WEEK ); + // For the end day set the day of week in the specified + // cell of the table + this.setDayOfWeek(gregCalEndDate, xcellrange, + intRow, this.INT_COLUMN_END_DAY_OF_WEEK); // Set the initial date for the next loop - gregoriancalendarStartDate = ( GregorianCalendar ) - gregoriancalendarEndDate.clone(); + gregCalStartDate = ( GregorianCalendar ) + gregCalEndDate.clone(); // Get the due date from the table - String stringDueDate = this.getStringFromCell( + String sDueDate = this.getStringFromCell( xcellrange, intRow, this.INT_COLUMN_DUEDATE ); // Testing if the due date is not empty - if ( !stringDueDate.equals( "" ) ) { - GregorianCalendar gregoriancalendarDueDate = - this.getGregorianCalendarFromString( stringDueDate ); + if ( !sDueDate.equals( "" ) ) { + GregorianCalendar gregCalDueDate = + this.getGregorianCalendarFromString(sDueDate); - // Testing if the due date is before the calculated end date - if ( gregoriancalendarDueDate.before( gregoriancalendarEndDate ) ) { - /* Getting the date when the processing of the feature/bug should + // Testing if the due date is before the calculated + // end date + if ( gregCalDueDate.before( + gregCalEndDate ) ) { + /* Getting the date when the processing of the + feature/bug should be started at the latest */ - GregorianCalendar gregoriancalendarLatestDateToStart = - this.getWorkday( gregoriancalendarDueDate, - -( intNeededDays - 1 ), - objectHolidays, xfunctionaccess ); + GregorianCalendar gregCalLatestDateToStart = + this.getWorkday(gregCalDueDate, + -( intNeededDays - 1 ), + objectHolidays, + xfunctionaccess); // Begin with the current row int intRowToInsert = intRow; - // Get the start date for the feature/bug in the current row - GregorianCalendar gregoriancalendarPreviousStartDate = + // Get the start date for the feature/bug in the + // current row + GregorianCalendar gregCalPreviousStartDate = this.getGregorianCalendarFromString( this.getStringFromCell( xcellrange, intRowToInsert, this.INT_COLUMN_STARTDATE ) ); - // Testing if we have to search for an earlier date to begin - while ( ( gregoriancalendarLatestDateToStart.before( - gregoriancalendarPreviousStartDate ) ) && - ( INT_ROW_FROM != intRowToInsert ) ) { + // Testing if we have to search for an earlier date + // to begin + while ((gregCalLatestDateToStart.before( + gregCalPreviousStartDate)) && + (INT_ROW_FROM != intRowToInsert)) { // Decrease the row intRowToInsert--; - // Get the start date for the feature/bug in the current row - String stringStartDate = this.getStringFromCell( - xcellrange, intRowToInsert, this.INT_COLUMN_STARTDATE ); + // Get the start date for the feature/bug in + // the current row + String sStartDate = this.getStringFromCell( + xcellrange, intRowToInsert, + this.INT_COLUMN_STARTDATE ); // Search until a valid start date is found - while ( stringStartDate.equals( "" ) ) { + while ( sStartDate.equals( "" ) ) { // Decrease the row intRowToInsert--; - // Get the start date for the feature/bug in the current row - stringStartDate = this.getStringFromCell( - xcellrange, intRowToInsert, this.INT_COLUMN_STARTDATE ); + // Get the start date for the feature/bug + // in the current row + sStartDate = this.getStringFromCell( + xcellrange, intRowToInsert, + this.INT_COLUMN_STARTDATE ); } - // Get the GregorianCalender format for the start date - gregoriancalendarPreviousStartDate = - this.getGregorianCalendarFromString( stringStartDate ); + // Get the GregorianCalender format for the + // start date + gregCalPreviousStartDate = + this.getGregorianCalendarFromString( + sStartDate ); } - // Getting the cell of the column "Needed Days" in the row where to insert + // Getting the cell of the column "Needed Days" + // in the row where to insert XCell xcellNeededDaysWhereToInsert = - xcellrange.getCellByPosition( INT_COLUMN_NEEDEDDAYS, intRowToInsert ); - // Getting the number of needed days to perform the feature + xcellrange.getCellByPosition( + INT_COLUMN_NEEDEDDAYS, intRowToInsert ); + // Getting the number of needed days to perform + // the feature int intNeededDaysWhereToInsert = (int) - Math.round( xcellNeededDaysWhereToInsert.getValue() ); + Math.round( + xcellNeededDaysWhereToInsert.getValue()); - GregorianCalendar gregoriancalendarPreviousNewEndDate = - this.getWorkday( gregoriancalendarPreviousStartDate, - intNeededDays - 1 + intNeededDaysWhereToInsert, - objectHolidays, xfunctionaccess ); - String stringPreviousDueDate = this.getStringFromCell( - xcellrange, intRowToInsert, this.INT_COLUMN_DUEDATE ); + GregorianCalendar gregCalPreviousNewEndDate = + this.getWorkday(gregCalPreviousStartDate, + intNeededDays - 1 + + intNeededDaysWhereToInsert, + objectHolidays, + xfunctionaccess); + String sPreviousDueDate = this.getStringFromCell( + xcellrange, intRowToInsert, + this.INT_COLUMN_DUEDATE ); - GregorianCalendar - gregoriancalendarPreviousDueDate = null; + GregorianCalendar gregCalPreviousDueDate = null; - if ( !stringPreviousDueDate.equals( "" ) ) { - gregoriancalendarPreviousDueDate = - this.getGregorianCalendarFromString( stringPreviousDueDate ); + if ( !sPreviousDueDate.equals( "" ) ) { + gregCalPreviousDueDate = + this.getGregorianCalendarFromString( + sPreviousDueDate ); } if ( ( intRowToInsert == intRow ) || - ( gregoriancalendarPreviousNewEndDate.after( - gregoriancalendarPreviousDueDate ) ) ) { - // Querying for the interface XPropertySet for the cell providing - // the due date + ( gregCalPreviousNewEndDate.after( + gregCalPreviousDueDate ) ) ) { + // Querying for the interface XPropertySet for + // the cell providing the due date XPropertySet xpropertyset = ( XPropertySet ) - UnoRuntime.queryInterface( XPropertySet.class, - xcellrange.getCellByPosition( - this.INT_COLUMN_DUEDATE, - intRow ) ); + UnoRuntime.queryInterface( + XPropertySet.class, + xcellrange.getCellByPosition( + this.INT_COLUMN_DUEDATE, + intRow ) ); - // Changing the background color of the cell to red + // Changing the background color of the cell + // to red xpropertyset.setPropertyValue( "CellBackColor", new Integer( 16711680 ) ); } else { - // Querying for the interface XColumnRowRange on the XCellRange - XColumnRowRange xcolumnrowrange = ( XColumnRowRange ) - UnoRuntime.queryInterface( + // Querying for the interface XColumnRowRange + // on the XCellRange + XColumnRowRange xcolumnrowrange = + ( XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, xcellrange ); // Inserting one row to the table - XTableRows xTableRows = xcolumnrowrange.getRows(); + XTableRows xTableRows = + xcolumnrowrange.getRows(); xTableRows.insertByIndex( intRowToInsert, 1 ); - // Querying for the interface XCellRangeMovement on XCellRange - XCellRangeMovement xcellrangemovement = ( XCellRangeMovement ) - UnoRuntime.queryInterface( XCellRangeMovement.class, xcellrange ); + // Querying for the interface + // XCellRangeMovement on XCellRange + XCellRangeMovement xcellrangemovement = + (XCellRangeMovement)UnoRuntime.queryInterface( + XCellRangeMovement.class, xcellrange ); // Creating the cell address of the destination CellAddress celladdress = new CellAddress(); @@ -552,26 +561,32 @@ public class ToDo { cellrangeaddress.EndColumn = 8; cellrangeaddress.EndRow = intRow + 1; - // Moves the cell range to another position in the document - xcellrangemovement.moveRange( celladdress, cellrangeaddress ); + // Moves the cell range to another position in + // the document + xcellrangemovement.moveRange(celladdress, + cellrangeaddress); // Removing the row not needed anymore - xcolumnrowrange.getRows().removeByIndex( intRow + 1, 1 ); + xcolumnrowrange.getRows().removeByIndex(intRow + + 1, 1); - // Set the current row, because we want to recalculate all rows below + // Set the current row, because we want to + // recalculate all rows below intRow = intRowToInsert - 1; // Tests at which line we want to insert if ( intRow >= this.INT_ROW_FROM ) { // Get the start date - gregoriancalendarStartDate = this.getGregorianCalendarFromString( - this.getStringFromCell( xcellrange, - intRow, this.INT_COLUMN_ENDDATE ) ); + gregCalStartDate = + this.getGregorianCalendarFromString( + this.getStringFromCell( xcellrange, + intRow,this.INT_COLUMN_ENDDATE)); } else { - // Set the start date with the absolute start date - gregoriancalendarStartDate = ( GregorianCalendar ) - gregoriancalendarAbsoluteStartDate.clone(); + // Set the start date with the absolute s + // tart date + gregCalStartDate = (GregorianCalendar) + gregCalAbsoluteStartDate.clone(); } } } @@ -585,51 +600,51 @@ public class ToDo { } /** Getting a string from a gregorian calendar. - * @param gregoriancalendar Date to be converted. + * @param gregCal Date to be converted. * @return string (converted gregorian calendar). */ - public String getStringFromGregorianCalendar( GregorianCalendar gregoriancalendar ) { - String stringDate = ( gregoriancalendar.get( Calendar.MONTH ) + 1 ) - + STRING_SEPARATOR + gregoriancalendar.get( Calendar.DATE ) -// + STRING_SEPARATOR + ( gregoriancalendar.get( Calendar.MONTH ) + 1 ) - + STRING_SEPARATOR + gregoriancalendar.get( Calendar.YEAR ); + public String getStringFromGregorianCalendar( GregorianCalendar gregCal ) { + String sDate = ( gregCal.get( Calendar.MONTH ) + 1 ) + + STRING_SEPARATOR + gregCal.get( Calendar.DATE ) +// + STRING_SEPARATOR + ( gregCal.get( Calendar.MONTH ) + 1 ) + + STRING_SEPARATOR + gregCal.get( Calendar.YEAR ); - return( stringDate ); + return sDate; } /** Getting a GregorianCalendar from a string. - * @param stringDate String to be converted. + * @param sDate String to be converted. * @return The result of the converting of the string. */ - public GregorianCalendar getGregorianCalendarFromString( String stringDate ) { - int []intDateValue = this.getDateValuesFromString( stringDate ); + public GregorianCalendar getGregorianCalendarFromString( String sDate ) { + int []intDateValue = this.getDateValuesFromString( sDate ); return( new GregorianCalendar( intDateValue[ 2 ], intDateValue[ 0 ], intDateValue[ 1 ] ) ); } /** Getting the day, month and year from a string. - * @param stringDate String to be parsed. + * @param sDate String to be parsed. * @return Returns an array of integer variables. */ - public int[] getDateValuesFromString( String stringDate) { + public int[] getDateValuesFromString( String sDate) { int[] intDateValues = new int[ 3 ]; - int intPositionFirstTag = stringDate.indexOf( STRING_SEPARATOR ); - int intPositionSecondTag = stringDate.indexOf( STRING_SEPARATOR, - intPositionFirstTag + 1 ); + int intPositionFirstTag = sDate.indexOf( STRING_SEPARATOR ); + int intPositionSecondTag = sDate.indexOf(STRING_SEPARATOR, + intPositionFirstTag + 1); // Getting the value of the month - intDateValues[ 0 ] = Integer.parseInt( stringDate.substring( 0, - intPositionFirstTag ) ) - 1; + intDateValues[ 0 ] = Integer.parseInt( + sDate.substring(0, intPositionFirstTag)) - 1; // Getting the value of the day - intDateValues[ 1 ] = Integer.parseInt( stringDate.substring( intPositionFirstTag + 1, - intPositionSecondTag ) ); + intDateValues[ 1 ] = Integer.parseInt( + sDate.substring(intPositionFirstTag + 1, intPositionSecondTag)); // Getting the value of the year intDateValues[ 2 ] = Integer.parseInt( - stringDate.substring( intPositionSecondTag + 1, stringDate.length() ) ); + sDate.substring(intPositionSecondTag + 1, sDate.length())); - return( intDateValues ); + return intDateValues; } /** Getting a content from a specified cell. @@ -638,40 +653,43 @@ public class ToDo { * @param intColumn Number of column. * @return String from the specified cell. */ - public String getStringFromCell( XCellRange xcellrange, int intRow, int intColumn ) { + public String getStringFromCell( XCellRange xcellrange, int intRow, + int intColumn ) { XTextRange xtextrangeStartDate = null; try { // Getting the cell holding the information about the start date - XCell xcellStartDate = xcellrange.getCellByPosition( intColumn, intRow ); + XCell xcellStartDate = xcellrange.getCellByPosition(intColumn, + intRow); // Querying for the interface XTextRange on the XCell xtextrangeStartDate = (XTextRange) - UnoRuntime.queryInterface( XTextRange.class, xcellStartDate ); + UnoRuntime.queryInterface(XTextRange.class, xcellStartDate); } catch( Exception exception ) { this.showExceptionMessage( exception ); } // Getting the start date - return( xtextrangeStartDate.getString().trim() ); + return xtextrangeStartDate.getString().trim(); } /** Writing a specified string to a specified cell. * @param xcellrange Providing access to the cells. * @param intRow Number of row. * @param intColumn Number of column. - * @param stringDate Date to write to the cell. + * @param sDate Date to write to the cell. */ public void setStringToCell( XCellRange xcellrange, int intRow, - int intColumn, String stringDate ) { + int intColumn, String sDate ) { try { // Getting the cell holding the information on the day to start - XCell xcellStartDate = xcellrange.getCellByPosition( intColumn, intRow ); + XCell xcellStartDate = xcellrange.getCellByPosition(intColumn, + intRow); // Querying for the interface XTextRange on the XCell XTextRange xtextrange = (XTextRange) - UnoRuntime.queryInterface( XTextRange.class, xcellStartDate ); + UnoRuntime.queryInterface(XTextRange.class, xcellStartDate); // Setting the new start date - xtextrange.setString( stringDate ); + xtextrange.setString( sDate ); } catch( Exception exception ) { this.showExceptionMessage( exception ); @@ -679,32 +697,34 @@ public class ToDo { } /** Calculates the week of day and calls the method "setStringToCell". - * @param gregoriancalendar Day to be written to the cell. + * @param gregCal Day to be written to the cell. * @param xcellrange Providing access to the cells. * @param intRow Number of row. * @param intColumn Number of column. */ - public void setDayOfWeek( GregorianCalendar gregoriancalendar, - XCellRange xcellrange, int intRow, int intColumn ) { - int intDayOfWeek = gregoriancalendar.get( Calendar.DAY_OF_WEEK ); - String stringDayOfWeek = ""; + public void setDayOfWeek( GregorianCalendar gregCal, + XCellRange xcellrange, int intRow, + int intColumn) { + int intDayOfWeek = gregCal.get( Calendar.DAY_OF_WEEK ); + String sDayOfWeek = ""; if ( intDayOfWeek == Calendar.MONDAY ) { - stringDayOfWeek = "MON"; + sDayOfWeek = "MON"; } else if ( intDayOfWeek == Calendar.TUESDAY ) { - stringDayOfWeek = "TUE"; + sDayOfWeek = "TUE"; } else if ( intDayOfWeek == Calendar.WEDNESDAY ) { - stringDayOfWeek = "WED"; + sDayOfWeek = "WED"; } else if ( intDayOfWeek == Calendar.THURSDAY ) { - stringDayOfWeek = "THU"; + sDayOfWeek = "THU"; } else if ( intDayOfWeek == Calendar.FRIDAY ) { - stringDayOfWeek = "FRI"; + sDayOfWeek = "FRI"; } this.setStringToCell( xcellrange, intRow, intColumn, - stringDayOfWeek ); + sDayOfWeek ); } - /** Calculates the dates of the official holidays with help of Calc functions. + /** Calculates the dates of the official holidays with help of Calc + * functions. * @param vectorHolidays Holding all holidays. * @param xcellrange Providing the cells. * @param xfunctionaccess Provides access to functions of the Calc. @@ -726,17 +746,20 @@ public class ToDo { intYear += intNumberOfYear; // Getting the Easter sunday - Double doubleEasterSunday = ( Double ) + Double dEasterSunday = ( Double ) xfunctionaccess.callFunction( - "EASTERSUNDAY", new Object[] { new Integer( intYear ) } ); + "EASTERSUNDAY", new Object[] { new Integer(intYear) }); - int intEasterSunday = ( int ) Math.round( doubleEasterSunday.doubleValue() ); + int intEasterSunday = (int)Math.round( + dEasterSunday.doubleValue()); // New-year vectorHolidays.addElement( xfunctionaccess.callFunction( - "DATE", - new Object[] { new Integer( intYear ), new Integer( 1 ), - new Integer( 1 ) } ) ); + "DATE", + new Object[] { + new Integer( intYear ), + new Integer( 1 ), + new Integer( 1 ) } )); // Good Friday vectorHolidays.addElement( @@ -749,32 +772,40 @@ public class ToDo { // Labour Day vectorHolidays.addElement( xfunctionaccess.callFunction( "DATE", - new Object[] { new Integer( intYear ), new Integer( 5 ), - new Integer( 1 ) } ) ); + new Object[] { + new Integer( intYear ), + new Integer( 5 ), + new Integer( 1 ) } )); // Ascension Day - vectorHolidays.addElement( new Double( intEasterSunday + 39 ) ); + vectorHolidays.addElement(new Double(intEasterSunday + 39 )); // Pentecost monday - vectorHolidays.addElement( new Double( intEasterSunday + 50 ) ); + vectorHolidays.addElement(new Double(intEasterSunday + 50 )); // German Unification vectorHolidays.addElement( xfunctionaccess.callFunction( "DATE", - new Object[] { new Integer( intYear ), new Integer( 10 ), - new Integer( 3 ) } ) ); + new Object[] { + new Integer( intYear ), + new Integer( 10 ), + new Integer( 3 ) } )); // Christmas Day First vectorHolidays.addElement( xfunctionaccess.callFunction( "DATE", - new Object[] { new Integer( intYear ), new Integer( 12 ), - new Integer( 25 ) } ) ); + new Object[] { + new Integer( intYear ), + new Integer( 12 ), + new Integer( 25 ) } )); // Christmas Day Second vectorHolidays.addElement( xfunctionaccess.callFunction( "DATE", - new Object[] { new Integer( intYear ), new Integer( 12 ), - new Integer( 26 ) } ) ); + new Object[] { + new Integer( intYear ), + new Integer( 12 ), + new Integer( 26 ) } )); } } catch( Exception exception ) { @@ -782,51 +813,52 @@ public class ToDo { } } - /** Returns the serial number of the date before or after a specified number of - * workdays. - * @param gregoriancalendarStartDate Date to start with the calculation. + /** Returns the serial number of the date before or after a specified + * number of workdays. + * @param gregCalStartDate Date to start with the calculation. * @param intDays Number of workdays (e.g. 5 or -3). * @param objectHolidays Private and public holidays to take into account. * @param xfunctionaccess Allows to call functions from the Calc. - * @return The gregorian date before or after a specified number of workdays. + * @return The gregorian date before or after a specified number of + * workdays. */ public GregorianCalendar getWorkday( - GregorianCalendar gregoriancalendarStartDate, + GregorianCalendar gregCalStartDate, int intDays, Object[][] objectHolidays, XFunctionAccess xfunctionaccess ) { - GregorianCalendar gregoriancalendarWorkday = null; + GregorianCalendar gregCalWorkday = null; try { // Getting the value of the start date - Double doubleDate = ( Double ) xfunctionaccess.callFunction( + Double dDate = ( Double ) xfunctionaccess.callFunction( "DATE", new Object[] { - new Integer( gregoriancalendarStartDate.get( Calendar.YEAR ) ), - new Integer( gregoriancalendarStartDate.get( Calendar.MONTH ) + 1 ), - new Integer( gregoriancalendarStartDate.get( Calendar.DATE ) ) + new Integer( gregCalStartDate.get( Calendar.YEAR ) ), + new Integer( gregCalStartDate.get( Calendar.MONTH ) + 1 ), + new Integer( gregCalStartDate.get( Calendar.DATE ) ) } ); - Double doubleWorkday = ( Double ) xfunctionaccess.callFunction( + Double dWorkday = ( Double ) xfunctionaccess.callFunction( "com.sun.star.sheet.addin.Analysis.getWorkday", - new Object[] { doubleDate, new Integer( intDays ), objectHolidays } ); + new Object[] { dDate, new Integer( intDays ), objectHolidays } ); - Double doubleYear = ( Double ) xfunctionaccess.callFunction( - "YEAR", new Object[] { doubleWorkday } ); - Double doubleMonth = ( Double ) xfunctionaccess.callFunction( - "MONTH", new Object[] { doubleWorkday } ); - Double doubleDay = ( Double ) xfunctionaccess.callFunction( - "DAY", new Object[] { doubleWorkday } ); + Double dYear = ( Double ) xfunctionaccess.callFunction( + "YEAR", new Object[] { dWorkday } ); + Double dMonth = ( Double ) xfunctionaccess.callFunction( + "MONTH", new Object[] { dWorkday } ); + Double dDay = ( Double ) xfunctionaccess.callFunction( + "DAY", new Object[] { dWorkday } ); - gregoriancalendarWorkday = new GregorianCalendar( - doubleYear.intValue(), - doubleMonth.intValue() - 1, - doubleDay.intValue() ); + gregCalWorkday = new GregorianCalendar( + dYear.intValue(), + dMonth.intValue() - 1, + dDay.intValue() ); } catch( Exception exception ) { this.showExceptionMessage( exception ); } - return( gregoriancalendarWorkday ); + return gregCalWorkday; } /** Getting the holidays from the spreadsheet. @@ -841,30 +873,32 @@ public class ToDo { int intRow = this.INT_ROW_HOLIDAYS_START; int intColumn = this.INT_COLUMN_HOLIDAYS_START; - double doubleHolidayStart = xcellrange.getCellByPosition( + double dHolidayStart = xcellrange.getCellByPosition( intColumn, intRow ).getValue(); - double doubleHolidayEnd = xcellrange.getCellByPosition( + double dHolidayEnd = xcellrange.getCellByPosition( intColumn + 1, intRow ).getValue(); - while ( doubleHolidayStart != 0 ) { - if ( doubleHolidayEnd == 0 ) { + while ( dHolidayStart != 0 ) { + if ( dHolidayEnd == 0 ) { vectorHolidays.addElement( new Integer( (int) Math.round( - doubleHolidayStart ) ) ); + dHolidayStart ) ) ); } else { for ( int intHoliday = (int) Math.round( - doubleHolidayStart ); - intHoliday <= (int) Math.round( doubleHolidayEnd ); + dHolidayStart ); + intHoliday <= (int) Math.round( dHolidayEnd ); intHoliday++ ) { vectorHolidays.addElement( new Double( intHoliday ) ); } } intRow++; - doubleHolidayStart = xcellrange.getCellByPosition( intColumn, intRow ).getValue(); - doubleHolidayEnd = xcellrange.getCellByPosition( intColumn + 1, intRow ).getValue(); + dHolidayStart = xcellrange.getCellByPosition( + intColumn, intRow).getValue(); + dHolidayEnd = xcellrange.getCellByPosition( + intColumn + 1, intRow).getValue(); } } catch( Exception exception ) { @@ -873,34 +907,65 @@ public class ToDo { } /** Showing the stack trace in a JOptionPane. - * @param stringMessage The message to show. + * @param sMessage The message to show. */ - public void showMessage( String stringMessage ) { + public void showMessage( String sMessage ) { javax.swing.JFrame jframe = new javax.swing.JFrame(); jframe.setLocation(100, 100); jframe.setSize(300, 200); jframe.setVisible(true); - javax.swing.JOptionPane.showMessageDialog( jframe, stringMessage, - "Debugging information", - javax.swing.JOptionPane.INFORMATION_MESSAGE ); + javax.swing.JOptionPane.showMessageDialog( + jframe, sMessage, "Debugging information", + javax.swing.JOptionPane.INFORMATION_MESSAGE); jframe.dispose(); } - /** Writing the stack trace from an exception to a string and calling the method - * showMessage() with this string. + /** Writing the stack trace from an exception to a string and calling + * the method showMessage() with this string. * @param exception The occured exception. * @see showMessage */ public void showExceptionMessage( Exception exception ) { - java.io.StringWriter stringwriter = new java.io.StringWriter(); + java.io.StringWriter swriter = new java.io.StringWriter(); java.io.PrintWriter printwriter = - new java.io.PrintWriter( stringwriter ); + new java.io.PrintWriter( swriter ); exception.printStackTrace( printwriter); System.err.println( exception ); - this.showMessage( stringwriter.getBuffer().substring(0) ); + this.showMessage( swriter.getBuffer().substring(0) ); } - } + /** + * Gives a factory for creating the service. + * This method is called by the JavaLoader + *

+ * @return returns a XSingleComponentFactory for creating + * the component + * @param sImplName the name of the implementation for which a + * service is desired + * @see com.sun.star.comp.loader.JavaLoader + */ + public static XSingleComponentFactory __getComponentFactory(String sImplName) { + XSingleComponentFactory xFactory = null; + + if ( sImplName.equals( ToDoImpl.class.getName() ) ) + xFactory = Factory.createComponentFactory(ToDoImpl.class, + ToDoImpl.getServiceNames()); + + return xFactory; + } + + /** + * Writes the service information into the given registry key. + * This method is called by the JavaLoader + *

+ * @return returns true if the operation succeeded + * @param regKey the registryKey + * @see com.sun.star.comp.loader.JavaLoader + */ + public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) { + return Factory.writeRegistryServiceInfo(ToDoImpl.class.getName(), + ToDoImpl.getServiceNames(), regKey); + } }