如何在部分视图中创建触发 Java 代码的命令
How to create a command in part view that fires Java code
我们想在部件视图中添加命令(按钮、菜单项、上下文菜单中的条目或类似内容)以执行 Java 代码。在 Java 代码中应该有对该部分的引用。
我们尝试在 psb-actionmodels.xml 和 cat-actions.xml 中添加条目但没有成功 - 没有出现菜单项。
我们还缺少什么?
我猜您正试图在部件信息页面的菜单下创建一个操作。
您添加操作按钮的方法不是 PTC 推荐的方法。虽然它可以工作,但您的自定义设置在升级期间将变得难以维护。
尝试按照以下步骤添加操作按钮以调用您的 java 代码
- 通过在浏览器上启用
jcaDebug
找到菜单的操作模型。
- 使用文件
custom-action.xml
和 custom-actionmodels.xml
添加您的动作模型并定义您的动作。这基本上会覆盖 ootb 操作条目。
Windchill 帮助中心对此有详细的程序
https://support.ptc.com/help/windchill/whc/whc_en/#page/Windchill_Help_Center%2FWCCG_UICust_AddActionsHook_WCClientArchAction.html
阅读文档(艰苦的工作)
感谢 Vignesh Vino 让我阅读文档...
我确实读过它。我之前确实读过它,但我迷路了。阅读并不是那么容易,因为(在我看来)文档不够深入,无法从中获取很好的示例。
有了这个答案,我想分享我学到的东西。如果我错了或者你知道更多细节请发表评论。
$windchill 是您的安装路径。
自定义-actions.xml
$windchill\codebase\config\actions\custom-actions.xml:
这是定义动作的地方。
我只定义了一个,名称是gbaction1
,嵌入在一个名为gbactiontype1
.
的objecttype中
要在菜单中查看文本,您必须创建所谓的 'resource bundle'。详情如下 - 这只是一个文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE listofactions SYSTEM "actions.dtd">
<listofactions>
<objecttype name="gbactiontype1" resourceBundle="com.gb.actions.GbActions1rb">
<action name="gbaction1">
<!—call function in a java class: -->
<!-- <command class="com.gb.actions.GbActionA" method="exec"/> -->
<!— or display a jsp site in a popup window: -->
<command url="netmarkets/jsp/gbactiontype1/gbaction1.jsp" windowType="popup"/>
<supportedTypes>
<!-- add this if you want to the action to be displayed for wtparts -->
<type value="wt.part.WTPart"/>
<!-- ECN (for change notices) -->
<type value="wt.change2.WTChangeOrder2"/>
<!-- for documents -->
<type value="wt.doc.WTDocument" />
</supportedTypes>
</action>
</objecttype>
</listofactions>
自定义菜单
$windchill\codebase\config\actions\PartClient-actionmodels.xml:
在这里我引用了上面定义的我的操作
<!-- Part information page Actions list -->
<model name="more parts actions" menufor="wt.part.WTPart">
<action name="gbaction1" type="gbactiontype1"/>
...
资源包
资源包文件在$windchill/src/com/gb/actions/GbActions1rb.rbInfo:
ResourceInfo.class=wt.tools.resource.StringResourceInfo
ResourceInfo.customizable=false
ResourceInfo.deprecated=false
gbactiontype1.gbaction1.description.value=menutext gbaction1
#doc: Note that icons for actions in the menus are only displayed for actions that also display in the toolbar
#gbactiontype1.gbaction1.tooltip.value=tooltip gbaction1
#relative to <windchill>/netmarkets/images?
#gbactiontype1.gbaction1.icon.value=multi_update.gif
gbactiontype1.gbaction1.icon.value=../../wtcore/images/gb/gb.png
Java 来源
java 源,当从上面显示的 custom-actions.xml 取消注释时被触发(配置的 'exec' 方法必须是 public static
并且带有显示的参数NmCommand
豆):
public class GbActionA extends JCAAction {
private static final Logger logger = LogR.getLogger(GbActionA.class.getName());
public GbActionA(ActionDefinition ad) {
super(ad); //never called?
}
public static void exec(NmCommandBean cmdBean) {
System.out.println("### GbActionA exec ###");
//how to get the WTPart:
cmdBean.getActionOid().getOidObject(); //ie. wt.part.WTPart:681208
...
}
...
}
编译java源码
您必须从 windchill shell(设置了多个环境变量的命令行)编译代码和资源文件:
windchill shell> ant -f bin\tools.xml class -Dclass.includes=com/gb/** -Dclass.force=true
重启服务器
完成此操作后,您可以重新启动 windchill 服务或(更快)在此处重新加载所有操作:
重新加载 WTPart 信息页面并在此处找到您的菜单:
JSP
如果您希望触发 jsp 页面:
jsp 文件的路径在自定义命令标签的 url 属性中给出-actions.xml(见上文):
<html>
<head>
<link rel="stylesheet" href="../../netmarkets/css/windchill-base.css">
<link rel="stylesheet" href="../../netmarkets/themes/windchill/xtheme-windchill.css">
</head>
<body>
<hr>
<%@ page import = "java.util.Map" %>
<%@page import="java.util.Enumeration"%>
<%@page import="java.lang.Exception"%>
<% request.setAttribute("hulla","true"); %><br>
<% out.println("hulla is " + request.getAttribute("hulla")); %><br>
<%
Enumeration e = request.getParameterNames();
while(e.hasMoreElements()) {
String paramName = e.nextElement().toString();
out.println(paramName + " = " + request.getParameter(paramName)+"<br>");
}
%>
<hr>
</body>
</html>
我添加了一些代码来获取参数名称。最有趣的可能是
oid
。在我的测试中,该参数包含 VR:wt.part.WTPart:626136
.
Tomcat模式
设置 tomcat mode=dev 以强制 jsp 每次在交付前编译:
windchill shell> ant -f WindchillConfigAssistant.xml configureTomcat
此命令要求您设置模式。如果要在交付前编译 jsp,则设置为 dev
,在生产模式下设置为 prod
。
我们想在部件视图中添加命令(按钮、菜单项、上下文菜单中的条目或类似内容)以执行 Java 代码。在 Java 代码中应该有对该部分的引用。
我们尝试在 psb-actionmodels.xml 和 cat-actions.xml 中添加条目但没有成功 - 没有出现菜单项。
我们还缺少什么?
我猜您正试图在部件信息页面的菜单下创建一个操作。 您添加操作按钮的方法不是 PTC 推荐的方法。虽然它可以工作,但您的自定义设置在升级期间将变得难以维护。
尝试按照以下步骤添加操作按钮以调用您的 java 代码
- 通过在浏览器上启用
jcaDebug
找到菜单的操作模型。 - 使用文件
custom-action.xml
和custom-actionmodels.xml
添加您的动作模型并定义您的动作。这基本上会覆盖 ootb 操作条目。
Windchill 帮助中心对此有详细的程序 https://support.ptc.com/help/windchill/whc/whc_en/#page/Windchill_Help_Center%2FWCCG_UICust_AddActionsHook_WCClientArchAction.html
阅读文档(艰苦的工作)
感谢 Vignesh Vino 让我阅读文档...
我确实读过它。我之前确实读过它,但我迷路了。阅读并不是那么容易,因为(在我看来)文档不够深入,无法从中获取很好的示例。
有了这个答案,我想分享我学到的东西。如果我错了或者你知道更多细节请发表评论。
$windchill 是您的安装路径。
自定义-actions.xml
$windchill\codebase\config\actions\custom-actions.xml:
这是定义动作的地方。
我只定义了一个,名称是gbaction1
,嵌入在一个名为gbactiontype1
.
的objecttype中
要在菜单中查看文本,您必须创建所谓的 'resource bundle'。详情如下 - 这只是一个文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE listofactions SYSTEM "actions.dtd">
<listofactions>
<objecttype name="gbactiontype1" resourceBundle="com.gb.actions.GbActions1rb">
<action name="gbaction1">
<!—call function in a java class: -->
<!-- <command class="com.gb.actions.GbActionA" method="exec"/> -->
<!— or display a jsp site in a popup window: -->
<command url="netmarkets/jsp/gbactiontype1/gbaction1.jsp" windowType="popup"/>
<supportedTypes>
<!-- add this if you want to the action to be displayed for wtparts -->
<type value="wt.part.WTPart"/>
<!-- ECN (for change notices) -->
<type value="wt.change2.WTChangeOrder2"/>
<!-- for documents -->
<type value="wt.doc.WTDocument" />
</supportedTypes>
</action>
</objecttype>
</listofactions>
自定义菜单
$windchill\codebase\config\actions\PartClient-actionmodels.xml:
在这里我引用了上面定义的我的操作
<!-- Part information page Actions list -->
<model name="more parts actions" menufor="wt.part.WTPart">
<action name="gbaction1" type="gbactiontype1"/>
...
资源包
资源包文件在$windchill/src/com/gb/actions/GbActions1rb.rbInfo:
ResourceInfo.class=wt.tools.resource.StringResourceInfo
ResourceInfo.customizable=false
ResourceInfo.deprecated=false
gbactiontype1.gbaction1.description.value=menutext gbaction1
#doc: Note that icons for actions in the menus are only displayed for actions that also display in the toolbar
#gbactiontype1.gbaction1.tooltip.value=tooltip gbaction1
#relative to <windchill>/netmarkets/images?
#gbactiontype1.gbaction1.icon.value=multi_update.gif
gbactiontype1.gbaction1.icon.value=../../wtcore/images/gb/gb.png
Java 来源
java 源,当从上面显示的 custom-actions.xml 取消注释时被触发(配置的 'exec' 方法必须是 public static
并且带有显示的参数NmCommand
豆):
public class GbActionA extends JCAAction {
private static final Logger logger = LogR.getLogger(GbActionA.class.getName());
public GbActionA(ActionDefinition ad) {
super(ad); //never called?
}
public static void exec(NmCommandBean cmdBean) {
System.out.println("### GbActionA exec ###");
//how to get the WTPart:
cmdBean.getActionOid().getOidObject(); //ie. wt.part.WTPart:681208
...
}
...
}
编译java源码
您必须从 windchill shell(设置了多个环境变量的命令行)编译代码和资源文件:
windchill shell> ant -f bin\tools.xml class -Dclass.includes=com/gb/** -Dclass.force=true
重启服务器
完成此操作后,您可以重新启动 windchill 服务或(更快)在此处重新加载所有操作:
重新加载 WTPart 信息页面并在此处找到您的菜单:
JSP
如果您希望触发 jsp 页面:
jsp 文件的路径在自定义命令标签的 url 属性中给出-actions.xml(见上文):
<html>
<head>
<link rel="stylesheet" href="../../netmarkets/css/windchill-base.css">
<link rel="stylesheet" href="../../netmarkets/themes/windchill/xtheme-windchill.css">
</head>
<body>
<hr>
<%@ page import = "java.util.Map" %>
<%@page import="java.util.Enumeration"%>
<%@page import="java.lang.Exception"%>
<% request.setAttribute("hulla","true"); %><br>
<% out.println("hulla is " + request.getAttribute("hulla")); %><br>
<%
Enumeration e = request.getParameterNames();
while(e.hasMoreElements()) {
String paramName = e.nextElement().toString();
out.println(paramName + " = " + request.getParameter(paramName)+"<br>");
}
%>
<hr>
</body>
</html>
我添加了一些代码来获取参数名称。最有趣的可能是
oid
。在我的测试中,该参数包含 VR:wt.part.WTPart:626136
.
Tomcat模式
设置 tomcat mode=dev 以强制 jsp 每次在交付前编译:
windchill shell> ant -f WindchillConfigAssistant.xml configureTomcat
此命令要求您设置模式。如果要在交付前编译 jsp,则设置为 dev
,在生产模式下设置为 prod
。