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