- 注册Action
通常是在WT_HOME/codebase/config/actions/custom-actionModels.xml
界面效果:
- Action指向页面(第一步只是告知有这个入口,入口具体做的动作是action里面要做的)
custom-actions.xml 文件中对三个搜索的子功能进行注册
MVC组件–table的注册到系统(jca-mvc.xml):
- 前台页面引入windchill的MVC组件:
前台页面效果:
- 对应后台代码
数据处理方法:
组件定义,以及列定义的方法:
@Override
public ComponentConfig buildComponentConfig(ComponentParams params) throws WTException {
if (log.isDebugEnabled()) {
log.debug("WhereUsedTreeBuilder - Entering buildComponentConfig");
}
if (log.isTraceEnabled()) {
log.trace("WhereUsedTreeBuilder.buildComponentConfig input params " + params);
}
String whereUsedTableID = "";
NmHelperBean helper = ((JcaComponentParams) params).getHelperBean();
NmCommandBean commandBean = (NmCommandBean) helper.getNmCommandBean();
NmSessionBean sessionBean = helper.getNmSessionBean();
ComponentConfigFactory factory = getComponentConfigFactory();
JcaTreeConfig treeConfig = (JcaTreeConfig) factory.newTreeConfig();
Object context = commandBean.getPageOid().getRef();
// boolean configurable = false;
// if the context object is in a project, set the table values appropriately (do
// not show the drop down, and make the table view to "Latest" only
if (EnterpriseHelper.isProjectLink((Persistable) context)) {
whereUsedTableID = "whereUsed";
}
// if the context object is not in a project, set the table values appropriately
// (show the drop down,
// and make the table view to "Latest" and "All Revisions"
else {
whereUsedTableID = "whereUsed.view";
}
if (commandBean.getTextParameter("viewchange") != null) {
sessionBean.removeAllNodes(commandBean, "whereUsed.view");
}
params.setAttribute("whereUsedTableID", whereUsedTableID);
treeConfig.setId(whereUsedTableID);
treeConfig.setShowCustomViewLink(false);
treeConfig.setNodeColumn(DescriptorConstants.ColumnIdentifiers.NUMBER);
treeConfig.setExpansionLevel(DescriptorConstants.TableTreeProperties.FULL_EXPAND);
treeConfig.setTargetObject("contextObject");
treeConfig.setLabel(messageWhereUsedResource.getMessage(PartListSearchResource.PRIVATE_CONSTANT_CS_6));
treeConfig.setSelectable(true);
treeConfig.setActionModel("whereUsedTablePart");
log.debug("set Tree setSelectable & ExpansionLevel is true,NodeColumn is NUMBER.");
// Define the columns present for when no view is used
ColumnConfig col = factory.newColumnConfig(DescriptorConstants.ColumnIdentifiers.NUMBER, true);
col.setWidth(200);
col.setInfoPageLink(false);
col.setDataUtilityId("whereUsedNumber");
treeConfig.addComponent(col);
col =factory.newColumnConfig(DescriptorConstants.ColumnIdentifiers.ORG_ID, false);
treeConfig.addComponent(col);
col = factory.newColumnConfig(DescriptorConstants.ColumnIdentifiers.NAME, true);
col.setWidth(799);
treeConfig.addComponent(col);
col =factory.newColumnConfig("PL_NUMBER", true);
col.setWidth(200);
col.setDataUtilityId("PartListSearchDataUtility");
treeConfig.addComponent(col);
col = factory.newColumnConfig(DescriptorConstants.ColumnIdentifiers.VERSION, false);
col.setDataUtilityId("PartListSearchDataUtility");
col.setWidth(100);
treeConfig.addComponent(col);
col =factory.newColumnConfig(DescriptorConstants.ColumnIdentifiers.STATE, true);
col.setWidth(100);
treeConfig.addComponent(col);
col = factory.newColumnConfig(DescriptorConstants.ColumnIdentifiers.CONTAINER_NAME, true);
col.setWidth(200);
col.setTargetObject("contained");
treeConfig.addComponent(col);
// end of column definition
treeConfig.setHelpContext("WhereUsedTableHelp");
treeConfig.setDataSourceMode(DataSourceMode.ASYNCHRONOUS);
System.out.println("end of column definition," + treeConfig.getComponents());
return treeConfig;
}
节点数据处理的方法
@Override
public void buildNodeData(Object node, ComponentResultProcessor resultProcessor) throws Exception {
// special case for root nodes
if (node == TreeNode.RootNode) {
treeHandler = new WhereUsedTreeHandler(resultProcessor.getParams());
if(treeHandler.getRootNodes()!=null) {
// should fetch rootNodes and to ResultProcessor
resultProcessor.addElements(treeHandler.getRootNodes());
}
}
// case for any other node
else {
List nodeList = new ArrayList();
nodeList.add(node);
if (treeHandler == null) {
treeHandler = new WhereUsedTreeHandler(resultProcessor.getParams());
}
Map<Object, List> map = treeHandler.getNodes(nodeList);
Set keySet = map.keySet();
for (Object key : keySet) {
resultProcessor.addElements(map.get(key));
}
}
}
6. 前后台对接,前台输入参数或者页面初始化,调用后台,数据加载到组件中
贴一下资源类给楼下留言的兄弟:
public final class PartListSearchResource extends WTListResourceBundle {
/**
* Where Used - typePicker Tag
**/
@RBEntry("PartList Search Tool")
@RBComment("Used as the label for the Browser Window Title")
public static final String PARTLIST_SEARCH = "0";
/**
* Where Used - typePicker Tag
**/
@RBEntry("Where Used")
@RBComment("Used as the label for the Where Used table label")
public static final String WHEREUSED_TABLELABEL = "1";
@RBEntry("All Revisions")
@RBComment("Used as the default view for the table")
public static final String WHEREUSED_ALLVERSION = "2";
@RBEntry("Latest")
@RBComment("Used as the alternate view for the table, displaying the latest verion of relationships only")
public static final String WHEREUSED_LATESTVERSION = "3";
@RBEntry("Context")
public static final String WHEREUSED_CONTEXT_COLUMN_HEADER = "4";
@RBEntry("PartList Search By PartNumber")
@RBComment("The text displayed on the Administrators sub tab under the PartList Search tab")
public static final String PRIVATE_CONSTANT_CS_6 = "commonsearch.partlistsearchbynumber.description";
@RBEntry("PartList Releaship BOM Search By PartList")
@RBComment("The text displayed on the Administrators sub tab under the PartList Releaship BOM tab")
public static final String PRIVATE_CONSTANT_CS_7 = "commonsearch.partlistsearchbybom.description";
@RBEntry("Export PartList Releaship BOM By Container")
@RBComment("The text displayed on the Administrators sub tab under the Export PartList tab")
public static final String PRIVATE_CONSTANT_CS_8 = "commonsearch.partlistsearchexport.description";
/**
* Entries for WhereUsed Table display
**/
@RBEntry("Copy")
public static final String OBJECT_WHERE_USED_COPY_TITLE = "OBJECT_WHERE_USED_COPY_TITLE";
@RBEntry("Where Used")
@RBComment("Used as the label for the Where Used table label")
public static final String PRIVATE_CONSTANT_0 = "whereUsed.tableLabel.description";
@RBEntry("Copy")
@RBComment("Used as the tooltip for the Where Used copy action")
public static final String PRIVATE_CONSTANT_1 = "object.whereused_copy.tooltip";
@RBEntry("Copy Selected Object")
public static final String PRIVATE_CONSTANT_2 = "object.whereused_copy.title";
@RBEntry("Copy")
public static final String PRIVATE_CONSTANT_3 = "object.whereused_copy.description";
@RBEntry("copy.gif")
@RBComment("DO NOT TRANSLATE")
public static final String PRIVATE_CONSTANT_4 = "object.whereused_copy.icon";
}
最近又有用MVC组件开发,这里更新两个知识点
第一个:如果table中的某个列需要做特殊处理,则需要自己定义一个DataUtility类,并且将这个DataUtility类注册到系统中
下面的截图是表格初始化的时候,指定哪些列需要用自己客制化的DataUtility类对该列的值做特殊处理
然后下面的图是自己对那些列需要做客制化处理的动作:
一般来说客制化的这个类要么是对值做显示的处理,权限的处理,要么是组件客制化
效果图如下:
上面部分的组件是一个搜索的组件,下面的组件是一个搜索结果的table
搜索条件主要包含三类:文本框,下拉的combox,日期组件,我都贴一小段代码作为例子
先讲下拉的,因为最有可能用到:
日期组件:
显示的列增加一些action操作按钮(编辑/查看/删除/提交),一种是后台写button,一种是icon类型
icon类型的显得更简洁明了:
private Object createButtonCommentByAction(String columnId, ExperienceSharingBean rowObject) {
boolean isEditable=rowObject.isEditable();
String formOid = rowObject.getExpOid();
GUIComponentArray componentArray = new GUIComponentArray();
IconComponent button4View = new IconComponent("netmarkets/images/info.gif");
button4View.addJsAction("onclick", "viewExp('"+formOid+"')");
IconComponent button4Edit = new IconComponent("netmarkets/images/edit.gif");
button4Edit.addJsAction("onclick", "editExp('"+formOid+"')");
IconComponent button4Obsolete = new IconComponent("netmarkets/images/delete.gif");
button4Obsolete.addJsAction("onclick", "obsoleteExp('"+formOid+"')");
IconComponent button4Monitor = new IconComponent("netmarkets/images/checkpoint.gif");
button4Monitor.addJsAction("onclick", "monitorExp('"+formOid+"')");
// componentArray.addGUIComponent(button4Monitor);
componentArray.addGUIComponent(button4View);
componentArray.addGUIComponent(button4Edit);
componentArray.addGUIComponent(button4Obsolete);
if(isEditable){
button4Edit.setEnabled(true);
if("RELEASED".equals(rowObject.getState())){
button4Obsolete.setEnabled(false);
}
}
return componentArray;
}
icon的效果图如下:
按钮的名称,是否可用,是否可编辑,以及点击按钮要做的动作都可以在后台定义好
比如我四个按钮对应的四个js事件,我定义好后,在页面去实现这四个方法就好
PS:目前我找到的是我们系统自己配置了一个相关的配置文件,
1)添加我业务模块定义的DataUtility类,
2)windchill shell中执行如下命令把服务注册到系统中:xconfmanager -p
第二个:windchill 10后的分页搜索都是系统自带的,不需要像10以前那样,自己在后台写分页搜索
要实现分页,你需要check两个东西,一个是系统的首选项配置,table默认的结果集是多少条,
另外一个是by用户的,进入首选项,然后看看table的结果集是多少条,不得不提的一点是,这个配置是针对整个系统全局的一个配置。