1*34dd1e25SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*34dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*34dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*34dd1e25SAndrew Rist * distributed with this work for additional information 6*34dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*34dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*34dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 9*34dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*34dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*34dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*34dd1e25SAndrew Rist * software distributed under the License is distributed on an 15*34dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*34dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 17*34dd1e25SAndrew Rist * specific language governing permissions and limitations 18*34dd1e25SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*34dd1e25SAndrew Rist *************************************************************/ 21*34dd1e25SAndrew Rist 22*34dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir /** 25cdf0e10cSrcweir * 26cdf0e10cSrcweir * @author fs93730 27cdf0e10cSrcweir */ 28cdf0e10cSrcweir public class BooleanValidator extends ControlValidator 29cdf0e10cSrcweir { 30cdf0e10cSrcweir private boolean m_preventChecked; 31cdf0e10cSrcweir private com.sun.star.uno.AnyConverter m_converter; 32cdf0e10cSrcweir 33cdf0e10cSrcweir /** Creates a new instance of BooleanValidator */ BooleanValidator( boolean preventChecked )34cdf0e10cSrcweir public BooleanValidator( boolean preventChecked ) 35cdf0e10cSrcweir { 36cdf0e10cSrcweir m_preventChecked = preventChecked; 37cdf0e10cSrcweir m_converter = new com.sun.star.uno.AnyConverter(); 38cdf0e10cSrcweir } 39cdf0e10cSrcweir explainInvalid( Object Value )40cdf0e10cSrcweir public String explainInvalid( Object Value ) 41cdf0e10cSrcweir { 42cdf0e10cSrcweir try 43cdf0e10cSrcweir { 44cdf0e10cSrcweir if ( m_converter.isVoid( Value ) ) 45cdf0e10cSrcweir return "'indetermined' is not an allowed state"; 46cdf0e10cSrcweir boolean value = ((Boolean)Value).booleanValue(); 47cdf0e10cSrcweir if ( m_preventChecked && ( value == true ) ) 48cdf0e10cSrcweir return "no no no. Don't check it."; 49cdf0e10cSrcweir } 50cdf0e10cSrcweir catch( java.lang.Exception e ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir return "ooops. Unknown error"; 53cdf0e10cSrcweir } 54cdf0e10cSrcweir return ""; 55cdf0e10cSrcweir } 56cdf0e10cSrcweir isValid( Object Value )57cdf0e10cSrcweir public boolean isValid( Object Value ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir try 60cdf0e10cSrcweir { 61cdf0e10cSrcweir if ( m_converter.isVoid( Value ) ) 62cdf0e10cSrcweir return false; 63cdf0e10cSrcweir 64cdf0e10cSrcweir boolean value = ((Boolean)Value).booleanValue(); 65cdf0e10cSrcweir if ( m_preventChecked && ( value == true ) ) 66cdf0e10cSrcweir return false; 67cdf0e10cSrcweir return true; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir catch( java.lang.Exception e ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir } 72cdf0e10cSrcweir return false; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir } 75