Basic Customization > User Interface Customization > Presenting Information in the UI > Customizing the Find Number Field > Sample Code
  
Sample Code
// Generated DefaultValidateFindNumbersDelegate%43C7A40F0161: Fri 03/07/08
10:41:32
/* bcwti
*
* Copyright (c) 2007 Parametric Technology Corporation (PTC). All Rights
* Reserved.
*
* This software is the confidential and proprietary information of PTC
* and is subject to the terms of a software license agreement. You shall
* not disclose such confidential information and shall use it only in acco
rdance
* with the terms of the license agreement.
*
* ecwti
*/

package wt.part;

import java.lang.String;
import wt.part.ValidateFindNumbersDelegate;
import wt.part.WTPartUsageLink;
import wt.util.WTException;

//##begin user.imports preserve=yes
import wt.util.WTPropertyVetoException; // Preserved unmodeled dependency
//##end user.imports

//##begin DefaultValidateFindNumbersDelegate%43C7A40F0161.doc preserve=no
/**
* Standard delegate to handle validation of Find Numbers, i.e., OOTB behavior,
* which is doing nothing.
*
* <BR><BR><B>Supported API: </B>true
* <BR><BR><B>Extendable: </B>true
*
* @version 1.0
**/
//##end DefaultValidateFindNumbersDelegate%43C7A40F0161.doc

public class DefaultValidateFindNumbersDelegate implements
ValidateFindNumbersDelegate {


// --- Attribute Section ---


private static final String RESOURCE = "wt.part.partResource";
private static final String CLASSNAME =
DefaultValidateFindNumbersDelegate.class.getName();

//##begin user.attributes preserve=yes
//##end user.attributes

//##begin static.initialization preserve=yes
private static final String SPACE = " ";
private static final String HYPHEN = "-";
//##end static.initialization


// --- Operation Section ---

//##begin validateFindNumbers%43C6C7F300E8.doc preserve=no
/**
*
* <BR><BR><B>Supported API: </B>false
*
* @param partUsageLinks
* @exception wt.util.WTException
**/
//##end validateFindNumbers%43C6C7F300E8.doc

public void validateFindNumbers( WTPartUsageLink[] partUsageLinks )
throws WTException {
//##begin validateFindNumbers%43C6C7F300E8.body preserve=yes

//##end validateFindNumbers%43C6C7F300E8.body
}

//##begin validateFindNumbers%45A68DEC00D9.doc preserve=no
/**
*
* <BR><BR><B>Supported API: </B>false
*
* @param findNumbers
* @exception wt.util.WTException
**/
//##end validateFindNumbers%45A68DEC00D9.doc

public void validateFindNumbers( String[] findNumbers )
throws WTException {
//##begin validateFindNumbers%45A68DEC00D9.body preserve=yes
try
{
doValidation(findNumbers);
}
catch (WTPropertyVetoException wtpe)
{
throw new WTException (wtpe);
}
//##end validateFindNumbers%45A68DEC00D9.body
}

//##begin user.operations preserve=yes
/**
* Method to validate if the format of the "Find Number" field is correct
* or not.
* The default logic allows only alphanumeric entries for this field.
* A WTPropertyVetoException is thrown if the format of the string in this
* field does not
* match the constraints imposed. The consequence of this Exception is that
* an error dialog
* will be displayed with a message as defined in the rbinfo file.
* This method can be customized to incorporate any constraint that the user
* might wish to impose on this field.
* @param findNumbersArray The value being entered (and validated) for the
* "Find Number" field
* @throws WTPropertyVetoException
*/
private void doValidation(String[] findNumbersArray)
throws WTPropertyVetoException
{
for(int j = 0; j < findNumbersArray.length; j++)
{
String a_FindNumber = findNumbersArray[j];
// Find Number can only be alphanumeric with the exception that the "Find
// Number"
// string can contain a space (" ") or a hyphen ("-") as part of it. The
// string can
// start or end with a space, but cannot start or end with an hyphen.

if (a_FindNumber != null) {
for (int i = 0; i < a_FindNumber.length(); i++) {
if(a_FindNumber.startsWith(HYPHEN) ||
(a_FindNumber.endsWith(HYPHEN)))
{
Object[] args = {a_FindNumber};
throw new WTPropertyVetoException( RESOURCE,
wt.part.partResource.FIND_NUMBER_NOT_ALPHANUMERICAL_ERROR, args,
new java.beans.PropertyChangeEvent( this, "findNumber",
a_FindNumber, a_FindNumber ));
}
if (!Character.isLetterOrDigit(a_FindNumber.charAt(i))) {
if((a_FindNumber.substring(i, i + 1)).equals(SPACE) ||
(a_FindNumber.substring(i, i + 1)).equals(HYPHEN))
{
// We have already checked that the first and/or
// last character is not an hyphen
// in the if-condition above. So, if the code gets
// into this block, we can be sure
// that the hyphen is in the middle of the
// string and not at the beginning or end.
// Also, if the character is a space, we are
// allowing it, so we can continue.
continue;
}
else
{
Object[] args = {a_FindNumber};
throw new WTPropertyVetoException( RESOURCE,
wt.part.partResource.FIND_NUMBER_NOT_ALPHANUMERICAL_ERROR, args,
new java.beans.PropertyChangeEvent( this,
"findNumber", a_FindNumber, a_FindNumber ));
}
}
}
}
}
}
//##emd user.operations
}