Personalización básica > User Interface Customization > Presenting Information in the UI > Customizing the Find Number Field
  
Customizing the Find Number Field
Outof-the-box, the Find Number Field of the Edit Structure Window in the Product Structure browser will not accept values which contain spaces. However, the Find Number field can be customized to accept values that include spaces, including leading or trailing spaces.
* 
If you perform this customization you must maintain and carry-forward this customization when you move to a later release of Windchill.
* 
If you want to allow leading or trailing spaces, perform steps 1 and 3 below; otherwise step 2 is sufficient.
1. The entry "wt.load.preserveSpace=true" has to be added to the file Windchill\codebase\wt.properties to allow for leading/trailing spaces.
2. To customize the logic in this field, perform the following steps:
a. Implement the interface "ValidateFindNumberDelegate.java"
b. Override the 'validateFindNumbers (String[])' method as described in the sample code provided below.
c. Ensure that the implementation throws a WTPropertyVetoException (as in the example) if any of the contraints are violated.
d. Register this new delegate in Windchill\codebase\service.properties.xconf:
There is a section with the following entry in this file:
<!--
The wt.part.ValidateFindNumbersDelegate service.

Delegate validation for Find Numbers on WTPartUsageLink
objects subclasses thereof
-->
<Service context="default"
name="wt.part.ValidateFindNumbersDelegate">
<Option cardinality="duplicate" requestor="java.lang.Object"
serviceClass="wt.part.DefaultValidateFindNumbersDelegate"/>
</Service>
Replace wt.part.DefaultValidateFindNumbersDelegate with the full path and name of the new delegate that was just created.
e. Run "xconfmanager -Fpv" to propagate the changes.
f. Create an rbinfo entry with the message you want to display when an error occurs.
3. If the customization rules pertaining to leading/trailing spaces have to be obeyed while loading data from a load file as well, then the following code samples provide an example of how to do this in the method "getValue(String, Hashtable, HashTable, boolean)".
OOTB Implementation
protected static String getValue( String name, Hashtable nv,
Hashtable cmd_line, boolean required ) throws WTException {
String value =
LoadServerHelper.getValue(name,nv,cmd_line,required?LoadServerH
elper.REQUIRED:LoadServerHelper.NOT_REQUIRED);

if (value != null) {
value = value.trim();
if (value.equals("")) {
value = null;
}
}

return value;
}
Customized implementation allowing leading and trailing spaces while loading from a file:
protected static String getValue( String name, Hashtable nv,
Hashtable cmd_line, boolean required ) throws WTException {
String value =
LoadServerHelper.getValue(name,nv,cmd_line,required?LoadServerH
elper.REQUIRED:LoadServerHelper.NOT_REQUIRED);

// Don't trim leading/trailing spaces if reading Find
Number field.
if(!name.equalsIgnoreCase("findNumber"))
{
if (value != null) {
value = value.trim();
if (value.equals("")) {
value = null;
}
}
}

return value;
}
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
}
Presenting Information in the UI