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