自訂 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。
基於某些類別使用的資料結構,並非搜尋結果顯示的所有屬性都可以在搜尋結果中排序。wt.query.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 preference 偏好設定節點中,命名格式如下:
<排序偏好設定基底名稱>sortAttrib<#>
<排序偏好設定基底名稱>sortDirect<#>
<排序偏好設定基底名稱> 是來自 wt.query.SearchAttributeList 中的 sortPref 陣列之唯一字串,其在排序名稱中必須具唯一性。sortAttrib 是針對屬性名稱而言,而 sortDirect 表示使用遞增或遞減。false 表示遞增,true 表示遞減。<#> 為排序鍵的編號 (0 = 第一個排序鍵,依此類推)。以下是針對「全部」排序,使用 wt.load.LoadFromFile 與 Windchill\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 個排序鍵的測試。
這是否有幫助?