1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 import com.sun.star.uno.*; 29 import com.sun.star.util.*; 30 import com.sun.star.lang.*; 31 import com.sun.star.accessibility.*; 32 import com.sun.star.container.*; 33 import com.sun.star.beans.*; 34 import com.sun.star.form.binding.*; 35 36 /** 37 * 38 * @author fs@openoffice.org 39 */ 40 public class ControlValidation extends DocumentBasedExample 41 { 42 /** Creates a new instance of ControlValidation */ 43 public ControlValidation() 44 { 45 super( DocumentType.WRITER ); 46 } 47 48 /* ------------------------------------------------------------------ */ 49 /* public test methods */ 50 /* ------------------------------------------------------------------ */ 51 protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception 52 { 53 super.prepareDocument(); 54 55 SingleControlValidation validation; 56 XPropertySet focusField; 57 58 validation = new SingleControlValidation( m_document, 5, 5, "DatabaseFormattedField", new NumericValidator() ); 59 focusField = validation.getInputField(); 60 validation.setExplanatoryText( "Please enter a number between 0 and 100, with at most 1 decimal digit" ); 61 62 validation = new SingleControlValidation( m_document, 90, 5, "DatabaseTextField", new TextValidator() ); 63 validation.setExplanatoryText( "Please enter a text whose length is a multiple of 3, and which does not contain the letter 'Z'" ); 64 65 validation = new SingleControlValidation( m_document, 5, 55, "DatabaseDateField", new DateValidator() ); 66 validation.setExplanatoryText( "Please enter a date in the current month" ); 67 validation.getInputField().setPropertyValue( "Dropdown", new Boolean( true ) ); 68 69 validation = new SingleControlValidation( m_document, 90, 55, "DatabaseTimeField", new TimeValidator() ); 70 validation.setExplanatoryText( "Please enter a time. Valid values are all full hours." ); 71 72 validation = new SingleControlValidation( m_document, 5, 110, "DatabaseCheckBox", new BooleanValidator( false ) ); 73 validation.setExplanatoryText( "Please check (well, or uncheck) the box. Don't leave it in indetermined state." ); 74 validation.getInputField().setPropertyValue( "TriState", new Boolean( true ) ); 75 76 validation = new SingleControlValidation( m_document, 90, 110, "DatabaseRadioButton", new BooleanValidator( true ), 3, 0 ); 77 validation.setExplanatoryText( "Please check any but the first button" ); 78 79 validation = new SingleControlValidation( m_document, 5, 165, "DatabaseListBox", new ListSelectionValidator( ), 1, 24 ); 80 validation.setExplanatoryText( "Please select not more than two entries." ); 81 validation.getInputField().setPropertyValue( "MultiSelection", new Boolean( true ) ); 82 validation.getInputField().setPropertyValue( "StringItemList", new String[] { "first", "second", "third", "forth", "fivth" } ); 83 84 // switch to alive mode 85 m_document.getCurrentView( ).toggleFormDesignMode( ); 86 m_document.getCurrentView( ).grabControlFocus( focusField ); 87 88 // wait for the user telling us to exit 89 waitForUserInput(); 90 } 91 92 /* ------------------------------------------------------------------ */ 93 /** class entry point 94 */ 95 public static void main(String argv[]) throws java.lang.Exception 96 { 97 ControlValidation aSample = new ControlValidation(); 98 aSample.run( argv ); 99 } 100 } 101