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; 23eba4d44aSLiu Zhe 24eba4d44aSLiu Zhe import static org.junit.Assert.*; 25eba4d44aSLiu Zhe 26eba4d44aSLiu Zhe import org.junit.After; 27eba4d44aSLiu Zhe import org.junit.AfterClass; 28eba4d44aSLiu Zhe import org.junit.Before; 29eba4d44aSLiu Zhe import org.junit.BeforeClass; 30eba4d44aSLiu Zhe import org.junit.Test; 31eba4d44aSLiu Zhe 32eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 33eba4d44aSLiu Zhe 34eba4d44aSLiu Zhe import testlib.uno.SCUtil; 35eba4d44aSLiu Zhe import testlib.uno.TestUtil; 36eba4d44aSLiu Zhe 37eba4d44aSLiu Zhe import com.sun.star.lang.XComponent; 38eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet; 39eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument; 40eba4d44aSLiu Zhe import com.sun.star.table.CellAddress; 41eba4d44aSLiu Zhe import com.sun.star.table.XCell; 42eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime; 43eba4d44aSLiu Zhe import com.sun.star.sheet.XCellAddressable; 44eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetAnnotations; 45eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetAnnotationsSupplier; 46eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetAnnotation; 47eba4d44aSLiu Zhe import com.sun.star.sheet.XSheetAnnotationAnchor; 48eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheets; 49eba4d44aSLiu Zhe import com.sun.star.container.XIndexAccess; 50eba4d44aSLiu Zhe 51eba4d44aSLiu Zhe 52eba4d44aSLiu Zhe /** 53eba4d44aSLiu Zhe * Test Create Show Hide Edit Delete Comments 54eba4d44aSLiu Zhe * @author BinGuo 9/5/2012 55eba4d44aSLiu Zhe * 56eba4d44aSLiu Zhe */ 57eba4d44aSLiu Zhe 58eba4d44aSLiu Zhe public class CreateShowHideEditDeleteComments { 59eba4d44aSLiu Zhe 60eba4d44aSLiu Zhe UnoApp unoApp = new UnoApp(); 61eba4d44aSLiu Zhe XSpreadsheetDocument scDocument = null; 62eba4d44aSLiu Zhe XComponent scComponent = null; 63eba4d44aSLiu Zhe 64eba4d44aSLiu Zhe @Before setUp()65eba4d44aSLiu Zhe public void setUp() throws Exception { 66eba4d44aSLiu Zhe unoApp.start(); 67eba4d44aSLiu Zhe } 68eba4d44aSLiu Zhe 69eba4d44aSLiu Zhe @After tearDown()70eba4d44aSLiu Zhe public void tearDown() throws Exception { 71eba4d44aSLiu Zhe unoApp.closeDocument(scComponent); 72eba4d44aSLiu Zhe unoApp.close(); 73eba4d44aSLiu Zhe } 74eba4d44aSLiu Zhe 75eba4d44aSLiu Zhe @BeforeClass setUpConnection()76eba4d44aSLiu Zhe public static void setUpConnection() throws Exception { 77eba4d44aSLiu Zhe // unoApp.start(); 78eba4d44aSLiu Zhe } 79eba4d44aSLiu Zhe 80eba4d44aSLiu Zhe @AfterClass tearDownConnection()81eba4d44aSLiu Zhe public static void tearDownConnection() throws InterruptedException, Exception { 82eba4d44aSLiu Zhe // unoApp.close(); 83eba4d44aSLiu Zhe SCUtil.clearTempDir(); 84eba4d44aSLiu Zhe } 85eba4d44aSLiu Zhe 86eba4d44aSLiu Zhe /** 87eba4d44aSLiu Zhe * New a spreadsheet 88eba4d44aSLiu Zhe * Insert annotations for A1:A5 89eba4d44aSLiu Zhe * Delete the 2nd annotations for A1:A5 90eba4d44aSLiu Zhe * Edit text in annotation 91eba4d44aSLiu Zhe */ 92eba4d44aSLiu Zhe 93eba4d44aSLiu Zhe @Test testCreateEditDeleteComments()94eba4d44aSLiu Zhe public void testCreateEditDeleteComments() throws Exception { 95eba4d44aSLiu Zhe 96eba4d44aSLiu Zhe scComponent = unoApp.newDocument("scalc"); 97eba4d44aSLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 98eba4d44aSLiu Zhe XSpreadsheets xSpreadsheets = scDocument.getSheets(); 99eba4d44aSLiu Zhe 100eba4d44aSLiu Zhe // Gets the first sheet in the document. 101eba4d44aSLiu Zhe XIndexAccess xSheetsIA = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 102eba4d44aSLiu Zhe Object sheetObj = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, xSheetsIA.getByIndex(0)); 103eba4d44aSLiu Zhe XSpreadsheet xSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 104eba4d44aSLiu Zhe 105eba4d44aSLiu Zhe // Get current sheet 106eba4d44aSLiu Zhe xSheet = SCUtil.getCurrentSheet(scDocument); 107eba4d44aSLiu Zhe 108eba4d44aSLiu Zhe // Create cell range A2:A5 and Add annotation for cells 109eba4d44aSLiu Zhe int nRow = 1; 110eba4d44aSLiu Zhe 111eba4d44aSLiu Zhe for (int i = 1; i < 5; ++i) { 112eba4d44aSLiu Zhe XCell xCell = xSheet.getCellByPosition(0, nRow); 113eba4d44aSLiu Zhe xCell.setValue(nRow); 114eba4d44aSLiu Zhe 115eba4d44aSLiu Zhe // Create the CellAddress structure 116eba4d44aSLiu Zhe XCellAddressable xCellAddr = (XCellAddressable) 117eba4d44aSLiu Zhe UnoRuntime.queryInterface(XCellAddressable.class, xCell); 118eba4d44aSLiu Zhe CellAddress aAddress = xCellAddr.getCellAddress(); 119eba4d44aSLiu Zhe 120eba4d44aSLiu Zhe // Insert an annotation 121eba4d44aSLiu Zhe XSheetAnnotationsSupplier xAnnotationsSupp = 122eba4d44aSLiu Zhe (XSheetAnnotationsSupplier) UnoRuntime.queryInterface( 123eba4d44aSLiu Zhe XSheetAnnotationsSupplier.class, xSheet); 124eba4d44aSLiu Zhe XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); 125eba4d44aSLiu Zhe xAnnotations.insertNew(aAddress, "This is an annotation"); 126eba4d44aSLiu Zhe 127eba4d44aSLiu Zhe nRow += 1; 128eba4d44aSLiu Zhe } 129eba4d44aSLiu Zhe 130eba4d44aSLiu Zhe XSheetAnnotationsSupplier xAnnotationsSupp = 131eba4d44aSLiu Zhe (XSheetAnnotationsSupplier) UnoRuntime.queryInterface( 132eba4d44aSLiu Zhe XSheetAnnotationsSupplier.class, xSheet); 133eba4d44aSLiu Zhe XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); 134eba4d44aSLiu Zhe 135eba4d44aSLiu Zhe // Verify results after insert annotations for cell range A2:A5 136eba4d44aSLiu Zhe assertEquals("Verify total number of annotations after execute insert annotations." 137eba4d44aSLiu Zhe ,4, xAnnotations.getCount()); 138eba4d44aSLiu Zhe 139eba4d44aSLiu Zhe // Remove annotation 140eba4d44aSLiu Zhe xAnnotations.removeByIndex(1); 141eba4d44aSLiu Zhe 142eba4d44aSLiu Zhe // Verify results after delete annotations from cell range A2:A5 143eba4d44aSLiu Zhe assertEquals("Verify number of annotations after execute delete annotations." 144eba4d44aSLiu Zhe ,3, xAnnotations.getCount()); 145eba4d44aSLiu Zhe 146eba4d44aSLiu Zhe } 147eba4d44aSLiu Zhe 148eba4d44aSLiu Zhe /** 149eba4d44aSLiu Zhe * New a spreadsheet 150eba4d44aSLiu Zhe * Insert annotations for B2 151eba4d44aSLiu Zhe * Show it 152eba4d44aSLiu Zhe * Hide it 153eba4d44aSLiu Zhe */ 154eba4d44aSLiu Zhe 155eba4d44aSLiu Zhe @Test testShowHideComments()156eba4d44aSLiu Zhe public void testShowHideComments() throws Exception { 157eba4d44aSLiu Zhe 158eba4d44aSLiu Zhe scComponent = unoApp.newDocument("scalc"); 159eba4d44aSLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent); 160eba4d44aSLiu Zhe XSpreadsheets xSpreadsheets = scDocument.getSheets(); 161eba4d44aSLiu Zhe 162eba4d44aSLiu Zhe // Gets the first sheet in the document. 163eba4d44aSLiu Zhe XIndexAccess xSheetsIA = (XIndexAccess)UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets); 164eba4d44aSLiu Zhe Object sheetObj = (XSpreadsheet)UnoRuntime.queryInterface(XSpreadsheet.class, xSheetsIA.getByIndex(0)); 165eba4d44aSLiu Zhe XSpreadsheet xSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj); 166eba4d44aSLiu Zhe 167eba4d44aSLiu Zhe // Get current sheet 168eba4d44aSLiu Zhe xSheet = SCUtil.getCurrentSheet(scDocument); 169eba4d44aSLiu Zhe 170eba4d44aSLiu Zhe // Create the CellAddress structure 171eba4d44aSLiu Zhe 172eba4d44aSLiu Zhe // Get Cell B2 173eba4d44aSLiu Zhe int nColumn = 1; 174eba4d44aSLiu Zhe int nRow = 1; 175eba4d44aSLiu Zhe 176eba4d44aSLiu Zhe XCell xCell = xSheet.getCellByPosition(nColumn, nRow); 177eba4d44aSLiu Zhe XCellAddressable xCellAddr = (XCellAddressable) 178eba4d44aSLiu Zhe UnoRuntime.queryInterface(XCellAddressable.class, xCell); 179eba4d44aSLiu Zhe CellAddress aAddress = xCellAddr.getCellAddress(); 180eba4d44aSLiu Zhe 181eba4d44aSLiu Zhe // Insert an annotation 182eba4d44aSLiu Zhe XSheetAnnotationsSupplier xAnnotationsSupp = 183eba4d44aSLiu Zhe (XSheetAnnotationsSupplier) UnoRuntime.queryInterface( 184eba4d44aSLiu Zhe XSheetAnnotationsSupplier.class, xSheet); 185eba4d44aSLiu Zhe XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); 186eba4d44aSLiu Zhe xAnnotations.insertNew(aAddress, "This is an annotation"); 187eba4d44aSLiu Zhe 188eba4d44aSLiu Zhe XSheetAnnotationAnchor xAnnotAnchor = 189eba4d44aSLiu Zhe (XSheetAnnotationAnchor) UnoRuntime.queryInterface(XSheetAnnotationAnchor.class, xCell); 190eba4d44aSLiu Zhe XSheetAnnotation xAnnotation = xAnnotAnchor.getAnnotation(); 191eba4d44aSLiu Zhe 192eba4d44aSLiu Zhe // Make the annotation visible 193eba4d44aSLiu Zhe xAnnotation.setIsVisible(true); 194eba4d44aSLiu Zhe //////// 195eba4d44aSLiu Zhe TestUtil.printPropertiesList(xAnnotAnchor); 196eba4d44aSLiu Zhe //////////////// 197eba4d44aSLiu Zhe // Verify annotation is visible. 198eba4d44aSLiu Zhe assertTrue("Verify annotation is visible in cell B2.",xAnnotation.getIsVisible()); 199eba4d44aSLiu Zhe 200eba4d44aSLiu Zhe // Make the annotation invisible 201eba4d44aSLiu Zhe xAnnotation.setIsVisible(false); 202eba4d44aSLiu Zhe 203eba4d44aSLiu Zhe // Verify annotation is invisible. 204eba4d44aSLiu Zhe assertFalse("Verify annotation is invisible in cell B2.",xAnnotation.getIsVisible()); 205eba4d44aSLiu Zhe 206eba4d44aSLiu Zhe } 207eba4d44aSLiu Zhe 208eba4d44aSLiu Zhe } 209eba4d44aSLiu Zhe 210eba4d44aSLiu Zhe 211eba4d44aSLiu Zhe 212eba4d44aSLiu Zhe 213