]> source.dussan.org Git - poi.git/commitdiff
Bug 49564 - Fixed default behaviour of XSSFCellStyle.getLocked()
authorYegor Kozlov <yegor@apache.org>
Fri, 24 Jun 2011 13:06:04 +0000 (13:06 +0000)
committerYegor Kozlov <yegor@apache.org>
Fri, 24 Jun 2011 13:06:04 +0000 (13:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1139288 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

index 5e268167d72ffdb2493fdbcb4e9b75dee7abcb86..edfcf676a21234f65244492fac1a2d532bb19b22 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="fix">49564 - Fixed default behaviour of XSSFCellStyle.getLocked() </action>
            <action dev="poi-developers" type="fix">48314 - Fixed setting column and row breaks in XSSF</action>
            <action dev="poi-developers" type="add">51424 - Ignore exceptions in ParagraphSprmUncompressor</action>
            <action dev="poi-developers" type="fix">51415 - Fixed Workbook.createSheet(sheetName) to truncate names longer than 31 characters</action>
index 86a8aac2358770a4a25559ba64a1ef5d9b05b0f2..51ffe6e06e9096e1bf46e863208456a18a876159 100644 (file)
@@ -565,7 +565,10 @@ public class XSSFCellStyle implements CellStyle {
      * @return boolean -  whether the cell using this style is hidden
      */
     public boolean getHidden() {
-        return getCellProtection().getHidden();
+        if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetHidden()) {
+            return false;
+        }
+        return _cellXf.getProtection().getHidden();
     }
 
     /**
@@ -619,7 +622,10 @@ public class XSSFCellStyle implements CellStyle {
      * @return whether the cell using this style are locked
      */
     public boolean getLocked() {
-        return getCellProtection().getLocked();
+        if (!_cellXf.isSetProtection() || !_cellXf.getProtection().isSetLocked()) {
+            return true;
+        }
+        return _cellXf.getProtection().getLocked();
     }
 
     /**
@@ -1169,7 +1175,10 @@ public class XSSFCellStyle implements CellStyle {
      * @param hidden - whether the cell using this style should be hidden
      */
     public void setHidden(boolean hidden) {
-        getCellProtection().setHidden(hidden);
+        if (!_cellXf.isSetProtection()) {
+             _cellXf.addNewProtection();
+         }
+        _cellXf.getProtection().setHidden(hidden);
     }
 
     /**
@@ -1218,7 +1227,10 @@ public class XSSFCellStyle implements CellStyle {
      * @param locked -  whether the cell using this style should be locked
      */
     public void setLocked(boolean locked) {
-        getCellProtection().setLocked(locked);
+        if (!_cellXf.isSetProtection()) {
+             _cellXf.addNewProtection();
+         }
+        _cellXf.getProtection().setLocked(locked);
     }
 
     /**
@@ -1388,17 +1400,6 @@ public class XSSFCellStyle implements CellStyle {
         return (int) _cellStyleXf.getFontId();
     }
 
-    /**
-     * get a cellProtection from the supplied XML definition
-     * @return CTCellProtection
-     */
-    private CTCellProtection getCellProtection() {
-        if (_cellXf.getProtection() == null) {
-            _cellXf.addNewProtection();
-        }
-        return _cellXf.getProtection();
-    }
-
     /**
      * get the cellAlignment object to use for manage alignment
      * @return XSSFCellAlignment - cell alignment
index 14259cf43c41f3ae620e30a9953e881f8369358b..a9c968c7e399c2b79e95cbbc41824c2b26c545f0 100644 (file)
@@ -526,15 +526,15 @@ public class TestXSSFCellStyle extends TestCase {
 
        public void testGetSetHidden() {
                assertFalse(cellStyle.getHidden());
-               cellXf.getProtection().setHidden(true);
+               cellStyle.setHidden(true);
                assertTrue(cellStyle.getHidden());
                cellStyle.setHidden(false);
                assertFalse(cellStyle.getHidden());
        }
 
        public void testGetSetLocked() {
-               assertFalse(cellStyle.getLocked());
-               cellXf.getProtection().setLocked(true);
+               assertTrue(cellStyle.getLocked());
+               cellStyle.setLocked(true);
                assertTrue(cellStyle.getLocked());
                cellStyle.setLocked(false);
                assertFalse(cellStyle.getLocked());
index e521aa59c7055f0299a2876e9284eab4a4f7a039..14f70295a626b8d1997f9b7b7f8d37f65c6a6b67 100644 (file)
@@ -544,4 +544,39 @@ public abstract class BaseTestCell extends TestCase {
         assertEquals(Cell.CELL_TYPE_ERROR, cell2.getCellType());
         assertEquals(ErrorConstants.ERROR_DIV_0, cell2.getErrorCellValue());
     }
+
+    public void testDefaultStyleProperties() {
+        Workbook wb = _testDataProvider.createWorkbook();
+
+        Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
+        CellStyle style = cell.getCellStyle();
+
+        assertTrue(style.getLocked());
+        assertFalse(style.getHidden());
+        assertEquals(0, style.getIndention());
+        assertEquals(0, style.getFontIndex());
+        assertEquals(0, style.getAlignment());
+        assertEquals(0, style.getDataFormat());
+        assertEquals(false, style.getWrapText());
+
+        CellStyle style2 = wb.createCellStyle();
+        assertTrue(style2.getLocked());
+        assertFalse(style2.getHidden());
+        style2.setLocked(false);
+        style2.setHidden(true);
+        assertFalse(style2.getLocked());
+        assertTrue(style2.getHidden());
+
+        wb = _testDataProvider.writeOutAndReadBack(wb);
+        cell = wb.getSheetAt(0).getRow(0).getCell(0);
+        style = cell.getCellStyle();
+        assertFalse(style2.getLocked());
+        assertTrue(style2.getHidden());
+
+        style2.setLocked(true);
+        style2.setHidden(false);
+        assertTrue(style2.getLocked());
+        assertFalse(style2.getHidden());
+    }
+
 }