1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import com
.sun
.star
.beans
.*;
22 public class ControlValidation
extends DocumentBasedExample
24 /** Creates a new instance of ControlValidation */
25 public ControlValidation()
27 super( DocumentType
.WRITER
);
30 /* ------------------------------------------------------------------ */
31 /* public test methods */
32 /* ------------------------------------------------------------------ */
34 protected void prepareDocument() throws com
.sun
.star
.uno
.Exception
, java
.lang
.Exception
36 super.prepareDocument();
38 SingleControlValidation validation
;
39 XPropertySet focusField
;
41 validation
= new SingleControlValidation( m_document
, 5, 5, "DatabaseFormattedField", new NumericValidator() );
42 focusField
= validation
.getInputField();
43 validation
.setExplanatoryText( "Please enter a number between 0 and 100, with at most 1 decimal digit" );
45 validation
= new SingleControlValidation( m_document
, 90, 5, "DatabaseTextField", new TextValidator() );
46 validation
.setExplanatoryText( "Please enter a text whose length is a multiple of 3, and which does not contain the letter 'Z'" );
48 validation
= new SingleControlValidation( m_document
, 5, 55, "DatabaseDateField", new DateValidator() );
49 validation
.setExplanatoryText( "Please enter a date in the current month" );
50 validation
.getInputField().setPropertyValue( "Dropdown", Boolean
.TRUE
);
52 validation
= new SingleControlValidation( m_document
, 90, 55, "DatabaseTimeField", new TimeValidator() );
53 validation
.setExplanatoryText( "Please enter a time. Valid values are all full hours." );
55 validation
= new SingleControlValidation( m_document
, 5, 110, "DatabaseCheckBox", new BooleanValidator( false ) );
56 validation
.setExplanatoryText( "Please check (well, or uncheck) the box. Don't leave it in indetermined state." );
57 validation
.getInputField().setPropertyValue( "TriState", Boolean
.TRUE
);
59 validation
= new SingleControlValidation( m_document
, 90, 110, "DatabaseRadioButton", new BooleanValidator( true ), 3, 0 );
60 validation
.setExplanatoryText( "Please check any but the first button" );
62 validation
= new SingleControlValidation( m_document
, 5, 165, "DatabaseListBox", new ListSelectionValidator( ), 1, 24 );
63 validation
.setExplanatoryText( "Please select not more than two entries." );
64 validation
.getInputField().setPropertyValue( "MultiSelection", Boolean
.TRUE
);
65 validation
.getInputField().setPropertyValue( "StringItemList", new String
[] { "first", "second", "third", "forth", "fivth" } );
67 // switch to alive mode
68 m_document
.getCurrentView( ).toggleFormDesignMode( );
69 m_document
.getCurrentView( ).grabControlFocus( focusField
);
71 // wait for the user telling us to exit
75 /* ------------------------------------------------------------------ */
78 public static void main(String argv
[]) throws java
.lang
.Exception
80 ControlValidation aSample
= new ControlValidation();
85 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */