博客统计信息

51cto推荐博客
用户名:cownew
文章数:291
评论数:163
访问量:154310
无忧币:1853
博客积分:4106
博客等级:7
注册日期:2008-06-30

以图形化的方式显示JBPM当前流程的方法及原理分析
2007-11-19 17:44:00
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。
已经可以比较好的运行JBPM了,但是如果能以图形化的方式显示工作流,并且把当前节点高亮显示,这样可用性就更好了,用户可以很轻松的看到当前流程到哪个节点了。
       我发现JBPMstarters-kit的例子中就有类似的效果,所以决定分析一下它是怎么实现的。
       打开网页,浏览到有显示当前工作流节点的页面,查看到此页面的地址为task.jsp,发现其中的核心代码如下:
<jbpm:processimage task="${taskBean.taskInstanceId}"/>
       这里使用了JBPM提供的jbpm:processimage标签,此标签定义在jbpm.tld中,这个Tag的类为org.jbpm.webapp.tag.ProcessImageTag。所以只要使用这个标签我们就可以很轻松的在Web页面中显示图形化的工作流了。
       那么如果是在SwingSWT等非Web界面中也想显示这种效果怎么办呢?那么让我们来分析一下ProcessImageTag类。
 private void retrieveByteArrays() {
    try {
      FileDefinition fileDefinition = processDefinition.getFileDefinition();
      gpdBytes = fileDefinition.getBytes("gpd.xml");
      imageBytes = fileDefinition.getBytes("processimage.jpg");
    } catch (Exception e) {
      e.printStackTrace();
    }
 }
       gpd.xml中记录的是节点的位置关系,processimage.jpg是图形化的图片(只是基图,没有高亮显示当前节点),这两个文件是JBPMEclipse插件自动生成的。
       得到流程实例当前节点的方法:
 private void initialize() {
    JbpmContext jbpmContext = JbpmContext.getCurrentJbpmContext();
    if (this.taskInstanceId > 0) {
           TaskInstance taskInstance = jbpmContext.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
           currentToken = taskInstance.getToken();
    }
    else
    {
           if (this.tokenInstanceId > 0)
                  currentToken = jbpmContext.getGraphSession().loadToken(this.tokenInstanceId);
    }
    processDefinition = currentToken.getProcessInstance().getProcessDefinition();
 }
       currentToken中可以得到当前节点在显示的时候的长度、宽度、横纵坐标等值。得到的方式如下:
 private int[] extractBoxConstraint(Element root) {
    int[] result = new int[4];
    String nodeName = currentToken.getNode().getName();
    XPath xPath = new DefaultXPath("//node[@name='" + nodeName + "']");
    Element node = (Element) xPath.selectSingleNode(root);
    result[0] = Integer.valueOf(node.attribute("x").getValue()).intValue();
    result[1] = Integer.valueOf(node.attribute("y").getValue()).intValue();
    result[2] = Integer.valueOf(node.attribute("width").getValue()).intValue();
    result[3] = Integer.valueOf(node.attribute("height").getValue()).intValue();
    return result;
 }
       这样用<div/>标签就可以将当前节点框上一个红色的框框了:
           jspOut.println("<div style='position:relative; background-image:url(" + imageLink + "); width: " + imageDimension[0] + "px; height: " + imageDimension[1] + "px;'>");
       //详细代码参考:writeTable方法
原来高亮显示是在原有的图片上叠加一个高亮的框框实现的。所以如果要显示在SwingSWT中的话也只要参考这个思路,在当前节点位置显示一个高亮的框框就可以了!

本文出自 “CowNew开源团队” 博客,转载请与作者联系!

分享至
更多
一键收藏,随时查看,分享好友!
0人
了这篇文章
类别:未分类┆技术圈()┆阅读()┆评论() ┆ 推送到技术圈返回首页

文章评论

 
2008-07-18 11:35:24
恩 不错 图形化的方式 是比较直观的

 

发表评论            

【技术门诊】专家解析:软考重点难点及应试技巧
昵  称:
登录  快速注册
验证码:

请点击后输入验证码博客过2级,无需填写验证码

内  容: