1*07d7dbdcSHerbert Dürr /************************************************************** 2*07d7dbdcSHerbert Dürr * 3*07d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one 4*07d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file 5*07d7dbdcSHerbert Dürr * distributed with this work for additional information 6*07d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file 7*07d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the 8*07d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance 9*07d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at 10*07d7dbdcSHerbert Dürr * 11*07d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0 12*07d7dbdcSHerbert Dürr * 13*07d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing, 14*07d7dbdcSHerbert Dürr * software distributed under the License is distributed on an 15*07d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*07d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the 17*07d7dbdcSHerbert Dürr * specific language governing permissions and limitations 18*07d7dbdcSHerbert Dürr * under the License. 19*07d7dbdcSHerbert Dürr * 20*07d7dbdcSHerbert Dürr *************************************************************/ 21*07d7dbdcSHerbert Dürr 22eba4d44aSLiu Zhe package fvt.uno.sc.rowcolumn; 2390175296SLiu Zhe 2490175296SLiu Zhe import static org.junit.Assert.*; 2590175296SLiu Zhe 2690175296SLiu Zhe import org.junit.After; 2790175296SLiu Zhe import org.junit.AfterClass; 2890175296SLiu Zhe import org.junit.Before; 2990175296SLiu Zhe import org.junit.BeforeClass; 3090175296SLiu Zhe import org.junit.Test; 3190175296SLiu Zhe 3290175296SLiu Zhe import org.openoffice.test.uno.UnoApp; 3390175296SLiu Zhe 3490175296SLiu Zhe import testlib.uno.SCUtil; 3590175296SLiu Zhe import testlib.uno.TestUtil; 3690175296SLiu Zhe 3790175296SLiu Zhe import com.sun.star.lang.XComponent; 3890175296SLiu Zhe import com.sun.star.sheet.XSpreadsheet; 3990175296SLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument; 4090175296SLiu Zhe import com.sun.star.table.CellAddress; 4190175296SLiu Zhe import com.sun.star.table.XCell; 4290175296SLiu Zhe import com.sun.star.uno.UnoRuntime; 4390175296SLiu Zhe import com.sun.star.sheet.XCellAddressable; 4490175296SLiu Zhe import com.sun.star.sheet.XSheetAnnotations; 4590175296SLiu Zhe import com.sun.star.sheet.XSheetAnnotationsSupplier; 4690175296SLiu Zhe import com.sun.star.sheet.XSheetAnnotation; 4790175296SLiu Zhe import com.sun.star.sheet.XSheetAnnotationAnchor; 4890175296SLiu Zhe import com.sun.star.sheet.XSpreadsheets; 4990175296SLiu Zhe import com.sun.star.container.XIndexAccess; 5090175296SLiu Zhe 5190175296SLiu Zhe 5290175296SLiu Zhe /** 5390175296SLiu Zhe * Test Create Show Hide Edit Delete Comments 5490175296SLiu Zhe * @author BinGuo 9/5/2012 5590175296SLiu Zhe * 5690175296SLiu Zhe */ 5790175296SLiu Zhe 5890175296SLiu Zhe public class CreateShowHideEditDeleteComments { 5990175296SLiu Zhe 6090175296SLiu Zhe UnoApp unoApp = new UnoApp(); 6190175296SLiu Zhe XSpreadsheetDocument scDocument = null; 6290175296SLiu Zhe XComponent scComponent = null; 6390175296SLiu Zhe 6490175296SLiu Zhe @Before setUp()6590175296SLiu Zhe public void setUp() throws Exception { 6690175296SLiu Zhe unoApp.start(); 6790175296SLiu Zhe } 6890175296SLiu Zhe 6990175296SLiu Zhe @After tearDown()7090175296SLiu Zhe public void tearDown() throws Exception { 7190175296SLiu Zhe unoApp.closeDocument(scComponent); 7290175296SLiu Zhe unoApp.close(); 7390175296SLiu Zhe } 7490175296SLiu Zhe 7590175296SLiu Zhe @BeforeClass setUpConnection()7690175296SLiu Zhe public static void setUpConnection() throws Exception { 7790175296SLiu Zhe // unoApp.start(); 7890175296SLiu Zhe } 7990175296SLiu Zhe 8090175296SLiu Zhe @AfterClass tearDownConnection()8190175296SLiu Zhe public static void tearDownConnection() throws InterruptedException, Exception { 8290175296SLiu Zhe // unoApp.close(); 8390175296SLiu Zhe SCUtil.clearTempDir(); 8490175296SLiu Zhe } 8590175296SLiu Zhe 8690175296SLiu Zhe /** 8790175296SLiu Zhe * New a spreadsheet 8890175296SLiu Zhe * Insert annotations for A1:A5 8990175296SLiu Zhe * Delete the 2nd annotations for A1:A5 9090175296SLiu Zhe * Edit text in annotation 9190175296SLiu Zhe */ 9290175296SLiu Zhe 9390175296SLiu Zhe @Test testCreateEditDeleteComments()9490175296SLiu Zhe public void testCreateEditDeleteComments() throws Exception { 9590175296SLiu Zhe 9690175296SLiu Zhe scComponent = unoApp.newDocument("scalc"); 9790175296SLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 9890175296SLiu Zhe XSpreadsheets xSpreadsheets = scDocument.getSheets(); 9990175296SLiu Zhe 10090175296SLiu Zhe // Gets the first sheet in the document. 10190175296SLiu Zhe XIndexAccess xSheetsIA = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 10290175296SLiu Zhe Object sheetObj = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, xSheetsIA.getByIndex(0)); 10390175296SLiu Zhe XSpreadsheet xSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 10490175296SLiu Zhe 10590175296SLiu Zhe // Get current sheet 10690175296SLiu Zhe xSheet = SCUtil.getCurrentSheet(scDocument); 10790175296SLiu Zhe 10890175296SLiu Zhe // Create cell range A2:A5 and Add annotation for cells 10990175296SLiu Zhe int nRow = 1; 11090175296SLiu Zhe 11190175296SLiu Zhe for (int i = 1; i < 5; ++i) { 11290175296SLiu Zhe XCell xCell = xSheet.getCellByPosition(0, nRow); 11390175296SLiu Zhe xCell.setValue(nRow); 11490175296SLiu Zhe 11590175296SLiu Zhe // Create the CellAddress structure 11690175296SLiu Zhe XCellAddressable xCellAddr = (XCellAddressable) 11790175296SLiu Zhe UnoRuntime.queryInterface(XCellAddressable.class, xCell); 11890175296SLiu Zhe CellAddress aAddress = xCellAddr.getCellAddress(); 11990175296SLiu Zhe 12090175296SLiu Zhe // Insert an annotation 12190175296SLiu Zhe XSheetAnnotationsSupplier xAnnotationsSupp = 12290175296SLiu Zhe (XSheetAnnotationsSupplier) UnoRuntime.queryInterface( 12390175296SLiu Zhe XSheetAnnotationsSupplier.class, xSheet); 12490175296SLiu Zhe XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); 12590175296SLiu Zhe xAnnotations.insertNew(aAddress, "This is an annotation"); 12690175296SLiu Zhe 12790175296SLiu Zhe nRow += 1; 12890175296SLiu Zhe } 12990175296SLiu Zhe 13090175296SLiu Zhe XSheetAnnotationsSupplier xAnnotationsSupp = 13190175296SLiu Zhe (XSheetAnnotationsSupplier) UnoRuntime.queryInterface( 13290175296SLiu Zhe XSheetAnnotationsSupplier.class, xSheet); 13390175296SLiu Zhe XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); 13490175296SLiu Zhe 13590175296SLiu Zhe // Verify results after insert annotations for cell range A2:A5 13690175296SLiu Zhe assertEquals("Verify total number of annotations after execute insert annotations." 13790175296SLiu Zhe ,4, xAnnotations.getCount()); 13890175296SLiu Zhe 13990175296SLiu Zhe // Remove annotation 14090175296SLiu Zhe xAnnotations.removeByIndex(1); 14190175296SLiu Zhe 14290175296SLiu Zhe // Verify results after delete annotations from cell range A2:A5 14390175296SLiu Zhe assertEquals("Verify number of annotations after execute delete annotations." 14490175296SLiu Zhe ,3, xAnnotations.getCount()); 14590175296SLiu Zhe 14690175296SLiu Zhe } 14790175296SLiu Zhe 14890175296SLiu Zhe /** 14990175296SLiu Zhe * New a spreadsheet 15090175296SLiu Zhe * Insert annotations for B2 15190175296SLiu Zhe * Show it 15290175296SLiu Zhe * Hide it 15390175296SLiu Zhe */ 15490175296SLiu Zhe 15590175296SLiu Zhe @Test testShowHideComments()15690175296SLiu Zhe public void testShowHideComments() throws Exception { 15790175296SLiu Zhe 15890175296SLiu Zhe scComponent = unoApp.newDocument("scalc"); 15990175296SLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 16090175296SLiu Zhe XSpreadsheets xSpreadsheets = scDocument.getSheets(); 16190175296SLiu Zhe 16290175296SLiu Zhe // Gets the first sheet in the document. 16390175296SLiu Zhe XIndexAccess xSheetsIA = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 16490175296SLiu Zhe Object sheetObj = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, xSheetsIA.getByIndex(0)); 16590175296SLiu Zhe XSpreadsheet xSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 16690175296SLiu Zhe 16790175296SLiu Zhe // Get current sheet 16890175296SLiu Zhe xSheet = SCUtil.getCurrentSheet(scDocument); 16990175296SLiu Zhe 17090175296SLiu Zhe // Create the CellAddress structure 17190175296SLiu Zhe 17290175296SLiu Zhe // Get Cell B2 17390175296SLiu Zhe int nColumn = 1; 17490175296SLiu Zhe int nRow = 1; 17590175296SLiu Zhe 17690175296SLiu Zhe XCell xCell = xSheet.getCellByPosition(nColumn, nRow); 17790175296SLiu Zhe XCellAddressable xCellAddr = (XCellAddressable) 17890175296SLiu Zhe UnoRuntime.queryInterface(XCellAddressable.class, xCell); 17990175296SLiu Zhe CellAddress aAddress = xCellAddr.getCellAddress(); 18090175296SLiu Zhe 18190175296SLiu Zhe // Insert an annotation 18290175296SLiu Zhe XSheetAnnotationsSupplier xAnnotationsSupp = 18390175296SLiu Zhe (XSheetAnnotationsSupplier) UnoRuntime.queryInterface( 18490175296SLiu Zhe XSheetAnnotationsSupplier.class, xSheet); 18590175296SLiu Zhe XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); 18690175296SLiu Zhe xAnnotations.insertNew(aAddress, "This is an annotation"); 18790175296SLiu Zhe 18890175296SLiu Zhe XSheetAnnotationAnchor xAnnotAnchor = 18990175296SLiu Zhe (XSheetAnnotationAnchor) UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, xCell); 19090175296SLiu Zhe XSheetAnnotation xAnnotation = xAnnotAnchor.getAnnotation(); 19190175296SLiu Zhe 19290175296SLiu Zhe // Make the annotation visible 19390175296SLiu Zhe xAnnotation.setIsVisible(true); 19490175296SLiu Zhe //////// 19590175296SLiu Zhe TestUtil.printPropertiesList(xAnnotAnchor); 19690175296SLiu Zhe //////////////// 19790175296SLiu Zhe // Verify annotation is visible. 19890175296SLiu Zhe assertTrue("Verify annotation is visible in cell B2.",xAnnotation.getIsVisible()); 19990175296SLiu Zhe 20090175296SLiu Zhe // Make the annotation invisible 20190175296SLiu Zhe xAnnotation.setIsVisible(false); 20290175296SLiu Zhe 20390175296SLiu Zhe // Verify annotation is invisible. 20490175296SLiu Zhe assertFalse("Verify annotation is invisible in cell B2.",xAnnotation.getIsVisible()); 20590175296SLiu Zhe 20690175296SLiu Zhe } 20790175296SLiu Zhe 20890175296SLiu Zhe } 20990175296SLiu Zhe 21090175296SLiu Zhe 21190175296SLiu Zhe 21290175296SLiu Zhe 213