1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 import com.sun.star.uno.*;
25 import com.sun.star.util.*;
26 import com.sun.star.lang.*;
27 import com.sun.star.accessibility.*;
28 import com.sun.star.container.*;
29 import com.sun.star.beans.*;
30 import com.sun.star.form.binding.*;
31 
32 /**
33  *
34  * @author  fs@openoffice.org
35  */
36 public class ControlValidation extends DocumentBasedExample
37 {
38     /** Creates a new instance of ControlValidation */
ControlValidation()39     public ControlValidation()
40     {
41         super( DocumentType.WRITER );
42     }
43 
44     /* ------------------------------------------------------------------ */
45     /* public test methods                                                */
46     /* ------------------------------------------------------------------ */
prepareDocument()47     protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception
48     {
49         super.prepareDocument();
50 
51         SingleControlValidation validation;
52         XPropertySet focusField;
53 
54         validation = new SingleControlValidation( m_document, 5, 5, "DatabaseFormattedField", new NumericValidator() );
55         focusField = validation.getInputField();
56         validation.setExplanatoryText( "Please enter a number between 0 and 100, with at most 1 decimal digit" );
57 
58         validation = new SingleControlValidation( m_document, 90, 5, "DatabaseTextField", new TextValidator() );
59         validation.setExplanatoryText( "Please enter a text whose length is a multiple of 3, and which does not contain the letter 'Z'" );
60 
61         validation = new SingleControlValidation( m_document, 5, 55, "DatabaseDateField", new DateValidator() );
62         validation.setExplanatoryText( "Please enter a date in the current month" );
63         validation.getInputField().setPropertyValue( "Dropdown", new Boolean( true ) );
64 
65         validation = new SingleControlValidation( m_document, 90, 55, "DatabaseTimeField", new TimeValidator() );
66         validation.setExplanatoryText( "Please enter a time. Valid values are all full hours." );
67 
68         validation = new SingleControlValidation( m_document, 5, 110, "DatabaseCheckBox", new BooleanValidator( false ) );
69         validation.setExplanatoryText( "Please check (well, or uncheck) the box. Don't leave it in indetermined state." );
70         validation.getInputField().setPropertyValue( "TriState", new Boolean( true ) );
71 
72         validation = new SingleControlValidation( m_document, 90, 110, "DatabaseRadioButton", new BooleanValidator( true ), 3, 0 );
73         validation.setExplanatoryText( "Please check any but the first button" );
74 
75         validation = new SingleControlValidation( m_document, 5, 165, "DatabaseListBox", new ListSelectionValidator( ), 1, 24 );
76         validation.setExplanatoryText( "Please select not more than two entries." );
77         validation.getInputField().setPropertyValue( "MultiSelection", new Boolean( true ) );
78         validation.getInputField().setPropertyValue( "StringItemList", new String[] { "first", "second", "third", "forth", "fivth" } );
79 
80         // switch to alive mode
81         m_document.getCurrentView( ).toggleFormDesignMode( );
82         m_document.getCurrentView( ).grabControlFocus( focusField );
83 
84         // wait for the user telling us to exit
85         waitForUserInput();
86     }
87 
88     /* ------------------------------------------------------------------ */
89     /** class entry point
90     */
main(String argv[])91     public static void main(String argv[]) throws java.lang.Exception
92     {
93         ControlValidation aSample = new ControlValidation();
94         aSample.run( argv );
95     }
96 }
97