// Getting the first XSpreadsheet
XSpreadsheet xspreadsheet = (XSpreadsheet)UnoRuntime.queryInterface(
XSpreadsheet.class, xindexaccess.getByIndex( 0 ));
// Querying for the interface XCellRange on the XSpeadsheet
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 );
// Set the start date with the absolute start date
GregorianCalendar gregoriancalendarStartDate =
(GregorianCalendar) gregoriancalendarAbsoluteStartDate.clone();
/* Creating the service FunctionAccess, which allows generic access to
all spreadsheet functions */
Object objectFunctionAccess =
xmultiservicefactory.createInstance("com.sun.star.sheet.FunctionAccess" );
// Querying for the interface XFunctionAccess on service
// FunctionAccess
XFunctionAccess xfunctionaccess = (XFunctionAccess)
UnoRuntime.queryInterface(XFunctionAccess.class,
objectFunctionAccess );
// Creating vector for holidays
Vector vectorHolidays = new Vector();
// Get the Official Holidays
this.getOfficialHolidays( vectorHolidays, xcellrange,
xfunctionaccess,
gregoriancalendarStartDate.get( Calendar.YEAR ) );
// Get the private holidays
this.getPrivateHolidays( vectorHolidays, xcellrange, xfunctionaccess );
// Getting the object array of holidays
Object[] objectSortedHolidays = vectorHolidays.toArray();
// Sorting the holidays
Arrays.sort( objectSortedHolidays );
// Collect the Official Holidays and the private holidays
Object [][]objectHolidays =
new Object[][] { objectSortedHolidays };
// Row index
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 );
// Determine the last row with an entry in the first column
while ( ( stringFeature != null ) &&
( !stringFeature.equals( "" ) ) ) {
intRowTo++;
stringFeature = this.getStringFromCell( xcellrange,
intRowTo + 1, this.INT_COLUMN_FEATURE );
}
// Setting the last row to be calculated
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 intColumn = this.INT_COLUMN_STARTDATE;
intColumn <= this.INT_COLUMN_END_DAY_OF_WEEK;
intColumn++ ) {
this.setStringToCell( xcellrange, intRow, intColumn,
"" );
}
}
/* Clearing the background color of the due date cells and setting the
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
XPropertySet xpropertyset = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class,
xcellrange.getCellByPosition( this.INT_COLUMN_DUEDATE,
intRow ) );
// Changing the background color of the cell to white
xpropertyset.setPropertyValue( "CellBackColor",
new Integer( 16777215 ) );
// Getting the cell of the bug id
XCell xcell = xcellrange.getCellByPosition(
this.INT_COLUMN_FEATURE, intRow );
// Querying for the interface XSimpleText
XSimpleText xsimpletext = ( XSimpleText )
UnoRuntime.queryInterface( XSimpleText.class, xcell );
// Getting the text cursor
XTextCursor xtextcursor = xsimpletext.createTextCursor();
// Querying for the interface XTextRange
XTextRange xtextrange = ( XTextRange )
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";
// Querying for the interface XMultiServiceFactory
XMultiServiceFactory xmultiservicefactoryTextField =
(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class,
aInstance );
// Creating an instance of the text field URL
Object objectTextField =
xmultiservicefactoryTextField.createInstance(
"com.sun.star.text.TextField.URL" );
// Querying for the interface XTextField
XTextField xtextfield = ( XTextField )
UnoRuntime.queryInterface( XTextField.class,
objectTextField );
// Querying for the interface XPropertySet
XPropertySet xpropertysetTextField = ( XPropertySet )
UnoRuntime.queryInterface( XPropertySet.class,
xtextfield );
// Setting the URL
xpropertysetTextField.setPropertyValue( "URL", stringBugIDLink );
// Setting the representation of the URL
xpropertysetTextField.setPropertyValue( "Representation", stringBugID );
// Querying for the interface XText
XText xtext = ( XText )UnoRuntime.queryInterface( XText.class, xcell );
// Delete cell content
xtextrange.setString( "" );
// Inserting the text field URL to the cell
xtext.insertTextContent( xtextrange, xtextfield, false );
}
}
// 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 );
// 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,
intRow, this.INT_COLUMN_STATUS );
/* 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,
xfunctionaccess );
// Getting a string with the date format jjjj-mm-dd from the gregorian calendar
String stringDate = this.getStringFromGregorianCalendar(
gregoriancalendarStartDate );
// Set the start date in the specified cell of the table
this.setStringToCell( xcellrange, intRow,
this.INT_COLUMN_STARTDATE, stringDate );
// 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 );
// Getting the end date after a specified number of workdays
GregorianCalendar gregoriancalendarEndDate =
this.getWorkday( gregoriancalendarStartDate,
intNeededDays - 1,
objectHolidays, xfunctionaccess );
// Creating a string with the date format jjjj-mm-dd
stringDate = this.getStringFromGregorianCalendar(
gregoriancalendarEndDate );
// Set the end date in the specified cell of the table
this.setStringToCell( xcellrange, intRow,
this.INT_COLUMN_ENDDATE, stringDate );
// 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 );
// Set the initial date for the next loop
gregoriancalendarStartDate = ( GregorianCalendar )
gregoriancalendarEndDate.clone();
// Get the due date from the table
String stringDueDate = this.getStringFromCell(
xcellrange, intRow, this.INT_COLUMN_DUEDATE );
// Testing if the due date is not empty
if ( !stringDueDate.equals( "" ) ) {
GregorianCalendar gregoriancalendarDueDate =
this.getGregorianCalendarFromString( stringDueDate );
// 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
be started at the latest */
GregorianCalendar gregoriancalendarLatestDateToStart =
this.getWorkday( gregoriancalendarDueDate,
-( 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 =
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 ) ) {
// 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 );
// Search until a valid start date is found
while ( stringStartDate.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 GregorianCalender format for the start date
gregoriancalendarPreviousStartDate =
this.getGregorianCalendarFromString( stringStartDate );
}
// 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
int intNeededDaysWhereToInsert = (int)
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
gregoriancalendarPreviousDueDate = null;
if ( !stringPreviousDueDate.equals( "" ) ) {
gregoriancalendarPreviousDueDate =
this.getGregorianCalendarFromString( stringPreviousDueDate );
}
if ( ( intRowToInsert == intRow ) ||
( gregoriancalendarPreviousNewEndDate.after(
gregoriancalendarPreviousDueDate ) ) ) {
// 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 ) );
// Changing the background color of the cell to red
xpropertyset.setPropertyValue(