Branch libreoffice-5-0-4
[LibreOffice.git] / odk / examples / DevelopersGuide / Forms / ControlValidation.java
bloba7a6d8347386f99236a205bbde6fd6016aaa8bea
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import com.sun.star.beans.*;
21 public class ControlValidation extends DocumentBasedExample
23 /** Creates a new instance of ControlValidation */
24 public ControlValidation()
26 super( DocumentType.WRITER );
29 /* ------------------------------------------------------------------ */
30 /* public test methods */
31 /* ------------------------------------------------------------------ */
32 @Override
33 protected void prepareDocument() throws com.sun.star.uno.Exception, java.lang.Exception
35 super.prepareDocument();
37 SingleControlValidation validation;
38 XPropertySet focusField;
40 validation = new SingleControlValidation( m_document, 5, 5, "DatabaseFormattedField", new NumericValidator() );
41 focusField = validation.getInputField();
42 validation.setExplanatoryText( "Please enter a number between 0 and 100, with at most 1 decimal digit" );
44 validation = new SingleControlValidation( m_document, 90, 5, "DatabaseTextField", new TextValidator() );
45 validation.setExplanatoryText( "Please enter a text whose length is a multiple of 3, and which does not contain the letter 'Z'" );
47 validation = new SingleControlValidation( m_document, 5, 55, "DatabaseDateField", new DateValidator() );
48 validation.setExplanatoryText( "Please enter a date in the current month" );
49 validation.getInputField().setPropertyValue( "Dropdown", Boolean.TRUE );
51 validation = new SingleControlValidation( m_document, 90, 55, "DatabaseTimeField", new TimeValidator() );
52 validation.setExplanatoryText( "Please enter a time. Valid values are all full hours." );
54 validation = new SingleControlValidation( m_document, 5, 110, "DatabaseCheckBox", new BooleanValidator( false ) );
55 validation.setExplanatoryText( "Please check (well, or uncheck) the box. Don't leave it in indetermined state." );
56 validation.getInputField().setPropertyValue( "TriState", Boolean.TRUE );
58 validation = new SingleControlValidation( m_document, 90, 110, "DatabaseRadioButton", new BooleanValidator( true ), 3, 0 );
59 validation.setExplanatoryText( "Please check any but the first button" );
61 validation = new SingleControlValidation( m_document, 5, 165, "DatabaseListBox", new ListSelectionValidator( ), 1, 24 );
62 validation.setExplanatoryText( "Please select not more than two entries." );
63 validation.getInputField().setPropertyValue( "MultiSelection", Boolean.TRUE );
64 validation.getInputField().setPropertyValue( "StringItemList", new String[] { "first", "second", "third", "forth", "fivth" } );
66 // switch to alive mode
67 m_document.getCurrentView( ).toggleFormDesignMode( );
68 m_document.getCurrentView( ).grabControlFocus( focusField );
70 // wait for the user telling us to exit
71 waitForUserInput();
74 /* ------------------------------------------------------------------ */
75 /** class entry point
77 public static void main(String argv[]) throws java.lang.Exception
79 ControlValidation aSample = new ControlValidation();
80 aSample.run( argv );