自定义 HTML 搜索
要自定义 HTML 搜索以更改默认搜索对象的显示或者添加新类,请参阅以下被分配为源 Windchill\src\wt\query\SearchAttributeList.java 的文件。如在该类的 javadoc 中所述,创建 SearchAttributeList 的子类并在 service.properties 和 wt.properties 中生成相应条目。以下方法应在自定义 SearchAttributeList 中实现:
public final class MySearchAttributeList extends SearchAttributeList implements
Externalizable {
public void setLocale( Locale locale ) {
// Load in the values for the drop down list for selecting what to search against.
clientLocale = locale;
// **Customize --------------------------------------------------------------
--------------
// Add new classes to search to list below.
// Make sure that they are assigned numbers in sequence from 0 to N.
// Set dropDownListCount to N+1.
final int ALL = 0;
final int WTPART = 1;

final int MYCLASS = 22
int dropDownListCount = 23;
// -------------------------------------------------------------------------
------------…
pickList = new String[classCount];
pickList[ALL] =
WTMessage.getLocalizedMessage(RESOURCE,queryResource.ALL,null,clientLocale);
pickList[WTPART] =
WTMessage.getLocalizedMessage(RESOURCE,queryResource.WTPART,null,clientLocale);

pickList[MYCLASS] = WTMessage.getLocalizedMessage(RESOURCE,queryResource.
MYCLASS,null,clientLocale);
pickValues = new String[classCount];
pickValues[ALL] = queryResource.ALL;
pickValues[WTPART] = queryResource.WTPART;

pickValues[MYCLASS] = queryResource.MYCLASS;
// **Customize You will need a string in here to correspond to each item in
pickList
// The string is a space separated list of what classes to query
// against. If you want to query against multiple classes that have a common
parent that
// has all of the attributes that you are interested in use that one class. If
you want
// to query against multiple classes that don't have a good common parent then
you can
// add them to a list and the search will loop through each class and combine
the results
// at the end. All classes in one list must only search against COMMON
attributes or
// attributes with the same name and of the same class! If you add both a
parent and
// a child class to the list you will get duplicate entries, when the results
are
// combined duplicate entries are not deleted.
queryClass = new String[classCount];
queryClass[ALL] =
"wt.part.WTPart wt.doc.WTDocument wt.change2.WTChangeIssue
wt.change2.WTChangeRequest2 " +
"wt.change2.WTChangeInvestigation wt.change2.WTAnalysisActivity
wt.change2.WTChangeProposal " +
"wt.change2.WTChangeOrder2 wt.change2.WTChangeActivity2
wt.csm.businessentity.BusinessEntity " +
"wt.effectivity.ConfigurationItem wt.epm.EPMDocument " +
"wt.replication.unit.WTUnit " +
"wt.part.WTProductConfiguration " +
"wt.part.WTProductInstance2 "; // Please remember to keep a space at the
end so that conditionally added items work.

queryClass[WTPART] = "wt.part.WTPart";

queryClass[MYCLASS] = "?.?.MyClass";
// **Customize These are the
// attributes that can be queried against.
inputAttributes = new String[classCount];
inputAttributes[ALL] =
"number name lifeCycleState projectId cabinet creator modifier
modifyTimestamp";
inputAttributes[WTPART] =
"number name view versionIdentifier partType source lifeCycleState projectId
cabinet creator modifier modifyTimestamp";

inputAttributes[MYCLASS] =
"name modifyTimestamp";
// **Customize Each individual
// string must match with the string listed above for the inputAttributes. "0"
stands for no
// input processing. If an attribute is an enumerated type use "0" and the
code will generate
// the drop down list. In the first string: projectId is in the fourth
position in inputAttributes
// so the method to generate the drop down list for it is also in the fourth
position in the
// string. The "0"s and methods must match in number with the number of
attributes listed
// under inputAttributes. You may add a fully qualified method from your
customization package
// as long as it is static and returns a vector of strings.
inputProcessing = new String[classCount];
inputProcessing[ALL] =
"0 0 0 wt.query.LocalSearchProcessor.getProjectList
wt.query.LocalSearchProcessor.getCabinetList 0 0 0";
inputProcessing[WTPART] =
"0 0 wt.query.LocalSearchProcessor.getViewList 0 0 0 0
wt.query.LocalSearchProcessor.getProjectList
wt.query.LocalSearchProcessor.getCabinetList 0 0 0";

inputProcessing[MYCLASS] =
"0 0";
// **Customize This is similar in concept to inputAttributes only these are
the attributes
// that will be displayed in the search results.
outputAttributes = new String[classCount];
outputAttributes[ALL] =
"number name versionDisplayIdentifier displayType lifeCycleState projectId
modifyTimestamp";
outputAttributes[WTPART] =
"number name versionDisplayIdentifier projectId lifeCycleState
modifyTimestamp";

outputProcessing[MYCLASS] =
"ObjProps 0";
// **New for 6.0
// **Customize This is similar in concept to outputAttributes only this list
is used
// to indicate which attributes can be sorted, can't be sorted, or an alternate
attribute
// that can be sorted to have the same affect as the display attribute. The
string that is used
// here should be the column descriptor so that it can be used to create the
ClassAttribute for
// the query. The query that is used for search is a simple query that will
not sort on all
// of the display attributes. Changing the 0 to 1 for an unsupported attribute
will
// either cause exceptions or sorts that don't work. Attributes of the
following types are
// just some examples of the attributes that will either throw exceptions or
sort incorrectly:
// EnumeratedType, CabinetReference, DataFormatReference,
LifeCycleTemplateReference, ProjectReference,
// and ViewReference.
sortAttributes = new String[classCount];
sortAttributes[ALL] =
"1 1 versionInfo.identifier.versionId 0 0 01";
sortAttributes[WTPART] =
"1 1 versionInfo.identifier.versionId 0 0 1";

sortAttributes[MYCLASS] =
"1 1";
// **New for 6.0
// **Customize This is similar in concept to outputAttributes only this list
is used
// for assigning a unique key to the sort preferences for this search. This
string will
// be persisted and used to retrieve the sort preferences for users. If the
value of one
// of these strings is changed or deleted after the system is in operation it
will create orphaned
// preferences in the system and users will lose the value that they had
persisted for that
// search. New entries can be added when a new search is added so that sort
preferences
// can be saved for that new search. These strings are arbitrary and never
displayed to the user.
sortPref = new String[classCount];
sortPref[ALL] =
"all";
sortPref[WTPART] =
"wtpart";

sortPref[MYCLASS] =
"myclass";
}
/**
*
* <BR><BR><B> Supported API: </B>false
*
* @param locale
* @return MySearchAttributeList
**/
public MySearchAttributeList( Locale locale ) {
setLocale(locale);
}
/**
*
* <BR><BR><B> Supported API: </B>false
*
* @return MySearchAttributeList
**/
public MySearchAttributeList() {
return;
}
}
wt.query.SearchAttributeList 始终都是最新的,应将其用作参考。
本节的后面部分说明了 wt.query.SearchAttributeList 中的两个新数组:sortAttributes 和 sortPref。
由于对某些类使用的数据结构所限,在搜索结果中显示的属性并不都可进行排序。SearchAttributeList 中的 sortAttributes 数组用于指定哪些属性可排序,以及是否应使用替代属性进行排序。版本属性就是用于排序的替代属性的示例。用于显示的属性是 versionDisplayIdentifier,但用于排序的属性是 versionInfo.identifier.versionId。基本 java 类型 (例如字符串和整型) 可进行排序。请使用 wt.query.SearchAttributeList 中的示例确定是否所有自定义类型都可排序。否则,简单测试会显示属性正常、无效、还是会产生异常。
sortPref 数组 (上述代码中所示) 用于定义排序首选项基本名称,从而使用户能够为该“搜索”对象定义自己的排序首选项。应在系统级别定义排序首选项的默认设置,以便用户首次使用系统或者用户未定义首选项时,按逻辑对各列排序。可以定义默认设置,方法为:使用 wt.load.LoadFromFile 或者使用“系统管理员”门户页面的“首选项管理器”编辑器。
如果是新数据库,则在运行 wt.load.Demo (其运行 wt.load.LoadFromFile) 的必要部分期间加载默认设置。使用“首选项管理器”可以轻松添加或修改站点默认设置。如果数据库是在 6.0 版本之前的系统上创建的,则 wt.load.LoadFromFile 可用于为 HTML 搜索类别的已传送配置加载基本默认设置。有关示例,请参阅 Windchill\loadFiles\preferences.txt 中的 "PrefEntry…/wt/query/htmlsearch" 条目。
每个用户首选项都有一个内部名称,在客户端看不到该名称,但在“首选项管理器”中可看到该名称。因为当前搜索使用 wt.query.SearchAttributeList 来让用户添加新搜索,并且因为每个新搜索都必须有一组排序首选项,所以“搜索”列表中的每个名称都需要唯一的排序名称。“搜索”列表中的每个对象不一定是一个对象,可以是一个对象列表。wt.query.SearchAttributeList 中的 sortPref 数组定义构成首选项名称一部分的唯一字符串。排序的首选项存储在 /wt/query/htmlsearch 首选项节点下,并且命名格式如下:
<sort preference base name>sortAttrib<#>
<sort preference base name>sortDirect<#>
<sort preference base name> 是 wt.query.SearchAttributeList 中的 sortPref 数组的唯一字符串;它只需在排序名称中唯一。sortAttrib 表示属性名,sortDirect 用于指示升序或降序。升序为 false,降序为 true。<#> 是排序键的编号,0 = 第一个键,以此类推。以下是针对“全部”排序而使用 wt.load.LoadFromFile 和 WindchillWindchill\loadFiles\preferences.txt 加载的首选项:
#All
PrefEntry~allsortAttrib0~number~/wt/query/htmlsearch
PrefEntry~allsortDirect0~false~/wt/query/htmlsearch
PrefEntry~allsortAttrib1~versionInfo.identifier.versionId~/wt/query/htmlsearch
PrefEntry~allsortDirect1~true~/wt/query/htmlsearch
在“全部默认”示例中,依次按编号列和版本列对结果排序,其中编号按升序排序,版本按降序排序。当前,虽然理论上排序键的数目只受 Oracle 性能的限制,但是所支持的排序键的数目为 3。尚未在系统上执行超过 3 个键的测试。
这对您有帮助吗?