View | Details | Raw Unified | Return to bug 56888
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidation.java (-4 lines)
Lines 87-94 Link Here
87
		this.validationConstraint = getConstraint(ctDataValidation);
87
		this.validationConstraint = getConstraint(ctDataValidation);
88
		this.ctDdataValidation = ctDataValidation;
88
		this.ctDdataValidation = ctDataValidation;
89
		this.regions = regions;
89
		this.regions = regions;
90
		this.ctDdataValidation.setErrorStyle(STDataValidationErrorStyle.STOP);
91
		this.ctDdataValidation.setAllowBlank(true);
92
	}	
90
	}	
93
91
94
	public XSSFDataValidation(XSSFDataValidationConstraint constraint,CellRangeAddressList regions,CTDataValidation ctDataValidation) {
92
	public XSSFDataValidation(XSSFDataValidationConstraint constraint,CellRangeAddressList regions,CTDataValidation ctDataValidation) {
Lines 96-103 Link Here
96
		this.validationConstraint = constraint;
94
		this.validationConstraint = constraint;
97
		this.ctDdataValidation = ctDataValidation;
95
		this.ctDdataValidation = ctDataValidation;
98
		this.regions = regions;
96
		this.regions = regions;
99
		this.ctDdataValidation.setErrorStyle(STDataValidationErrorStyle.STOP);
100
		this.ctDdataValidation.setAllowBlank(true);
101
	}
97
	}
102
 
98
 
103
	CTDataValidation getCtDdataValidation() {
99
	CTDataValidation getCtDdataValidation() {
(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDataValidationHelper.java (+3 lines)
Lines 26-31 Link Here
26
import org.apache.poi.ss.util.CellRangeAddress;
26
import org.apache.poi.ss.util.CellRangeAddress;
27
import org.apache.poi.ss.util.CellRangeAddressList;
27
import org.apache.poi.ss.util.CellRangeAddressList;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
28
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataValidation;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationErrorStyle;
29
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationOperator;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationOperator;
30
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationType;
31
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataValidationType;
31
32
Lines 166-171 Link Here
166
			sqref.add(cellRangeAddress.formatAsString());
167
			sqref.add(cellRangeAddress.formatAsString());
167
		}
168
		}
168
		newDataValidation.setSqref(sqref);
169
		newDataValidation.setSqref(sqref);
170
		newDataValidation.setAllowBlank(true);
171
		newDataValidation.setErrorStyle(STDataValidationErrorStyle.STOP);
169
		
172
		
170
		return new XSSFDataValidation(dataValidationConstraint,cellRangeAddressList,newDataValidation);
173
		return new XSSFDataValidation(dataValidationConstraint,cellRangeAddressList,newDataValidation);
171
	}
174
	}
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDataValidation.java (+49 lines)
Lines 261-264 Link Here
261
        lst = sheet.getDataValidations();
261
        lst = sheet.getDataValidations();
262
        assertEquals(1, lst.size());
262
        assertEquals(1, lst.size());
263
    }
263
    }
264
265
    public void testDefaultAllowBlank() {
266
        XSSFWorkbook wb = new XSSFWorkbook();
267
        XSSFSheet sheet = wb.createSheet();
268
269
        final XSSFDataValidation validation = createValidation(sheet);
270
        sheet.addValidationData(validation);
271
272
        final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
273
        assertEquals(true, dataValidations.get(0).getCtDdataValidation().getAllowBlank());
274
    }
275
276
    public void testSetAllowBlankToFalse() {
277
        XSSFWorkbook wb = new XSSFWorkbook();
278
        XSSFSheet sheet = wb.createSheet();
279
280
        final XSSFDataValidation validation = createValidation(sheet);
281
        validation.getCtDdataValidation().setAllowBlank(false);
282
283
        sheet.addValidationData(validation);
284
285
        final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
286
        assertEquals(false, dataValidations.get(0).getCtDdataValidation().getAllowBlank());
287
    }
288
289
    public void testSetAllowBlankToTrue() {
290
        XSSFWorkbook wb = new XSSFWorkbook();
291
        XSSFSheet sheet = wb.createSheet();
292
293
        final XSSFDataValidation validation = createValidation(sheet);
294
        validation.getCtDdataValidation().setAllowBlank(true);
295
296
        sheet.addValidationData(validation);
297
298
        final List<XSSFDataValidation> dataValidations = sheet.getDataValidations();
299
        assertEquals(true, dataValidations.get(0).getCtDdataValidation().getAllowBlank());
300
    }
301
302
    private XSSFDataValidation createValidation(XSSFSheet sheet) {
303
        //create the cell that will have the validation applied
304
        final XSSFRow row = sheet.createRow(0);
305
        row.createCell(0);
306
307
        DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
308
309
        XSSFDataValidationConstraint constraint = (XSSFDataValidationConstraint) dataValidationHelper.createCustomConstraint("true");
310
        final XSSFDataValidation validation = (XSSFDataValidation) dataValidationHelper.createValidation(constraint, new CellRangeAddressList(0, 0, 0, 0));
311
        return validation;
312
    }
264
}
313
}

Return to bug 56888