Save This Page
Home » openjdk-7 » net.sf.raptor » ui » testdata » [javadoc | source]
    1   /*********************************************************************************
    2    *                                                                               *
    3    * Raptor - Rapid prototyping of Swing GUIs based on JavaBeans like Java objects *
    4    * Copyright (C) 2003  XCOM AG                                                   *
    5    *                                                                               *
    6    * This library is free software; you can redistribute it and/or                 *
    7    * modify it under the terms of the GNU Lesser General Public                    *
    8    * License as published by the Free Software Foundation; either                  *
    9    * version 2.1 of the License, or (at your option) any later version.            *
   10    *                                                                               *
   11    * This library is distributed in the hope that it will be useful,               *
   12    * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
   13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
   14    * Lesser General Public License for more details.                               *
   15    *                                                                               *
   16    * You should have received a copy of the GNU Lesser General Public              *
   17    * License along with this library; if not, write to the Free Software           *
   18    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA     *
   19    *                                                                               *
   20    *********************************************************************************/
   21   package net.sf.raptor.ui.testdata;
   22   
   23   import java.beans.BeanDescriptor;
   24   import java.beans.BeanInfo;
   25   import java.beans.IntrospectionException;
   26   import java.beans.Introspector;
   27   import java.beans.PropertyDescriptor;
   28   import java.beans.SimpleBeanInfo;
   29   import java.util.ArrayList;
   30   import java.util.HashMap;
   31   import java.util.List;
   32   import java.util.Map;
   33   
   34   import net.sf.raptor.ui.BeanInfoUtils;
   35   import net.sf.raptor.ui.components.ComponentWrapper;
   36   
   37   /** @author Hibernate CodeGenerator */
   38   public class AddressBeanInfo extends SimpleBeanInfo {
   39   
   40     private PropertyDescriptor[] propertyDescriptors;
   41     private BeanDescriptor beanDescriptor;
   42     private Map classWrapper;
   43     private List propertyDescriptorList;
   44     private static String[] mappingFields = {
   45           "id", 
   46           "version", 
   47           "validfrom", 
   48           "street", 
   49           "streettown", 
   50           "poboxtown", 
   51           "email", 
   52           "state", 
   53           "country", 
   54           "streetpostalcode", 
   55           "poboxpostalcode", 
   56           "pobox", 
   57           "phone", 
   58           "fax", 
   59           "mobilephone" };
   60   
   61     public AddressBeanInfo() throws IntrospectionException{
   62     	super();
   63     	try {
   64     		BeanInfo beanInfo =
   65     			Introspector
   66     				.getBeanInfo(Address.class, Introspector.IGNORE_IMMEDIATE_BEANINFO);
   67     		beanDescriptor = beanInfo.getBeanDescriptor();
   68     		propertyDescriptors = beanInfo.getPropertyDescriptors();
   69     	}
   70     	catch (IntrospectionException e) {
   71     		beanDescriptor = new BeanDescriptor(Address.class);
   72     	  propertyDescriptors = new PropertyDescriptor[15];
   73     	  for(int i=0; i<mappingFields.length; i++) {
   74     	  	propertyDescriptors[i] = new PropertyDescriptor(mappingFields[i], Address.class);
   75     	  }
   76   
   77     	}
   78   
   79     	propertyDescriptorList = new ArrayList(propertyDescriptors.length);
   80       for( int i=0; i<propertyDescriptors.length; i++ ) {
   81         propertyDescriptorList.add(propertyDescriptors[i].getName());
   82       }
   83       int index;
   84   
   85       index = propertyDescriptorList.indexOf("version");
   86     	propertyDescriptors[index].setValue( "length", new Integer(38) );
   87   
   88       index = propertyDescriptorList.indexOf("validfrom");
   89     	propertyDescriptors[index].setValue( "length", new Integer(7) );
   90   
   91       index = propertyDescriptorList.indexOf("street");
   92     	propertyDescriptors[index].setValue( "length", new Integer(80) );
   93   
   94       index = propertyDescriptorList.indexOf("streettown");
   95     	propertyDescriptors[index].setValue( "length", new Integer(80) );
   96   
   97       index = propertyDescriptorList.indexOf("poboxtown");
   98     	propertyDescriptors[index].setValue( "length", new Integer(80) );
   99   
  100       index = propertyDescriptorList.indexOf("email");
  101     	propertyDescriptors[index].setValue( "length", new Integer(80) );
  102   
  103       index = propertyDescriptorList.indexOf("state");
  104     	propertyDescriptors[index].setValue( "length", new Integer(38) );
  105   
  106       index = propertyDescriptorList.indexOf("country");
  107     	propertyDescriptors[index].setValue( "length", new Integer(38) );
  108   
  109       index = propertyDescriptorList.indexOf("streetpostalcode");
  110     	propertyDescriptors[index].setValue( "length", new Integer(5) );
  111   
  112       index = propertyDescriptorList.indexOf("poboxpostalcode");
  113     	propertyDescriptors[index].setValue( "length", new Integer(5) );
  114   
  115       index = propertyDescriptorList.indexOf("pobox");
  116     	propertyDescriptors[index].setValue( "length", new Integer(25) );
  117   
  118       index = propertyDescriptorList.indexOf("phone");
  119     	propertyDescriptors[index].setValue( "length", new Integer(25) );
  120   
  121       index = propertyDescriptorList.indexOf("fax");
  122     	propertyDescriptors[index].setValue( "length", new Integer(25) );
  123   
  124       index = propertyDescriptorList.indexOf("mobilephone");
  125     	propertyDescriptors[index].setValue( "length", new Integer(25) );
  126   
  127     	BeanInfoUtils.annotateFeatureDescriptor(Address.class.getName(), beanDescriptor);
  128     	BeanInfoUtils.annotateFeatureDescriptors(Address.class.getName(), propertyDescriptors);
  129   
  130    	}
  131     /* (non-Javadoc)
  132      * @see java.beans.BeanInfo#getPropertyDescriptors()
  133      */
  134     public PropertyDescriptor[] getPropertyDescriptors() {
  135     	return propertyDescriptors;
  136     }
  137   
  138     /* (non-Javadoc)
  139      * @see java.beans.BeanInfo#getBeanDescriptor()
  140      */
  141     public BeanDescriptor getBeanDescriptor() {
  142     	return beanDescriptor;
  143     }
  144   
  145     private void checkName(String name) throws IllegalArgumentException{
  146       boolean nameExists=false;
  147       for(int i=0; i<mappingFields.length; i++) {
  148         if(mappingFields[i].equals(name)) {
  149           nameExists=true;
  150           break;
  151         }
  152       }
  153       if(!nameExists) {
  154         throw new IllegalArgumentException("name must be a property of this bean");
  155       }
  156     }
  157     public void setWrapperFor(String name, Class componentWrapper) {
  158       if(!ComponentWrapper.class.isAssignableFrom(componentWrapper)) {
  159         throw new IllegalArgumentException("Class provided must be a ComponentWrapper");
  160       }
  161       checkName(name);
  162       if(classWrapper==null) {
  163         classWrapper=new HashMap();
  164       }
  165       classWrapper.put(name, componentWrapper);
  166     }
  167     public Class getWrapperFor(String name) {
  168       checkName(name);
  169       if(classWrapper==null) {
  170         return null;
  171       }
  172       return (Class)classWrapper.get(name);
  173     }
  174     public void setAllVisible( boolean visible ) {
  175     	for(int i=0; i<propertyDescriptors.length; i++ ) {
  176     	  propertyDescriptors[i].setHidden(!visible);
  177     	}
  178     }
  179     public void setVisibleForName( String name, boolean visible ) {
  180     	int index = propertyDescriptorList.indexOf( name );
  181     	if( index>0 && index<propertyDescriptors.length) {
  182     	  propertyDescriptors[index].setHidden(!visible);
  183     	}
  184     }
  185     public void setIdVisible( boolean visible ) {
  186     	  setVisibleForName("id", visible);
  187     }
  188     public void setVersionVisible( boolean visible ) {
  189     	  setVisibleForName("version", visible);
  190     }
  191     public void setValidfromVisible( boolean visible ) {
  192     	  setVisibleForName("validfrom", visible);
  193     }
  194     public void setStreetVisible( boolean visible ) {
  195     	  setVisibleForName("street", visible);
  196     }
  197     public void setStreettownVisible( boolean visible ) {
  198     	  setVisibleForName("streettown", visible);
  199     }
  200     public void setPoboxtownVisible( boolean visible ) {
  201     	  setVisibleForName("poboxtown", visible);
  202     }
  203     public void setEmailVisible( boolean visible ) {
  204     	  setVisibleForName("email", visible);
  205     }
  206     public void setStateVisible( boolean visible ) {
  207     	  setVisibleForName("state", visible);
  208     }
  209     public void setCountryVisible( boolean visible ) {
  210     	  setVisibleForName("country", visible);
  211     }
  212     public void setStreetpostalcodeVisible( boolean visible ) {
  213     	  setVisibleForName("streetpostalcode", visible);
  214     }
  215     public void setPoboxpostalcodeVisible( boolean visible ) {
  216     	  setVisibleForName("poboxpostalcode", visible);
  217     }
  218     public void setPoboxVisible( boolean visible ) {
  219     	  setVisibleForName("pobox", visible);
  220     }
  221     public void setPhoneVisible( boolean visible ) {
  222     	  setVisibleForName("phone", visible);
  223     }
  224     public void setFaxVisible( boolean visible ) {
  225     	  setVisibleForName("fax", visible);
  226     }
  227     public void setMobilephoneVisible( boolean visible ) {
  228     	  setVisibleForName("mobilephone", visible);
  229     }
  230   }

Save This Page
Home » openjdk-7 » net.sf.raptor » ui » testdata » [javadoc | source]