__getServiceFactory
) and a
* method, that writes the information into the given registry key
* (__writeRegistryServiceInfo
).
*/
public class ToDo {
/** 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 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 initial component contextr, that gives access to
* the service manager, supported singletons, ...
* It's often later used
*/
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
private static final int INT_COLUMN_FEATURE = 0;
private static final int INT_COLUMN_NEEDEDDAYS = 2;
private static final int INT_COLUMN_STARTDATE = 3;
private static final int INT_COLUMN_START_DAY_OF_WEEK = 4;
private static final int INT_COLUMN_ENDDATE = 5;
private static final int INT_COLUMN_END_DAY_OF_WEEK = 6;
private static final int INT_COLUMN_DUEDATE = 7;
private static final int INT_COLUMN_STATUS = 8;
private static final int INT_ROW_FROM = 14; // 8
private static final int INT_ROW_HOLIDAYS_START = 4;
private static final int INT_COLUMN_HOLIDAYS_START = 7; // 10
private static final String STRING_SEPARATOR = "/";
/** The constructor of the inner class has a XComponenContext parameter.
* @param xCompContext the initial component context
*/
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() {
return getServiceNames();
}
private static String[] getServiceNames() {
String[] sSupportedServiceNames = { __serviceName };
return sSupportedServiceNames;
}
/** This method returns true, if the given service will be
* supported by the component.
* @return True, if the given service name will be supported.
*/
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 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.
* @param aInstance Spreadsheet document.
* @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 {
try {
// Querying for the interface XSpreadsheetDocument
XSpreadsheetDocument xspreadsheetdocument =
UnoRuntime.queryInterface(
XSpreadsheetDocument.class, aInstance );
// Querying for the interface XIndexAccess
XIndexAccess xindexaccess = UnoRuntime.queryInterface( XIndexAccess.class,
xspreadsheetdocument.getSheets() );
// Getting the first XSpreadsheet
XSpreadsheet xspreadsheet = UnoRuntime.queryInterface(
XSpreadsheet.class, xindexaccess.getByIndex( 0 ));
// Querying for the interface XCellRange on the XSpreadsheet
XCellRange xcellrange = UnoRuntime.queryInterface( XCellRange.class, xspreadsheet );
/* 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 gregCalStartDate =
(GregorianCalendar) gregCalAbsoluteStartDate.clone();
/* Creating the service FunctionAccess, which allows generic
access to all spreadsheet functions */
Object objectFunctionAccess =
m_xMCF.createInstanceWithContext(
"com.sun.star.sheet.FunctionAccess", m_cmpCtx );
// Querying for the interface XFunctionAccess on service
// FunctionAccess
XFunctionAccess xfunctionaccess = UnoRuntime.queryInterface(XFunctionAccess.class,
objectFunctionAccess );
// Creating vector for holidays
ArrayList