自定义检索号字段
依预设,产品结构浏览器中编辑结构窗口的检索号字段不接受包含空格的值。但是,可对检索号字段进行自定义,以使其接受包含空格的值,包括前导或尾随空格。
|
如果执行此自定义,则当移动到 Windchill 的更高版本时,必须保持并沿用此自定义。
|
|
如果要允许前导或尾随空格,请执行下方的步骤 1 和 3;否则,执行步骤 2 即可。
|
1. 必须将条目 "wt.load.preserveSpace=true" 添加到文件 Windchill\codebase\wt.properties 中,以允许前导/尾随空格。
2. 要在此字段中自定义逻辑,请执行以下步骤:
a. 实现接口 "ValidateFindNumberDelegate.java"
b. 如下方提供的示例代码中所述,覆盖 "validateFindNumbers (String[])" 方法。
c. 确保违反任何约束时实现会抛出 WTPropertyVetoException (如示例所示)。
d. 在 Windchill\codebase\service.properties.xconf 中注册此新委派:
此文件中有一个包含以下条目的部分:
<!--
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>
用刚刚创建的新委派的完整路径和名称替换 wt.part.DefaultValidateFindNumbersDelegate。
e. 运行 "xconfmanager -Fpv" 以传播更改。
f. 创建一个包含发生错误时所要显示消息的 rbinfo 条目。
3. 如果从加载文件加载数据时也必须遵循与前导/尾随空格有关的自定义规则,则以下代码示例将提供有关如何在方法 "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;
}
示例代码
// 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
}