请教jbpm4.4如何在jsp页面上显示流程图并标出当前活动节点
chenxiao1981
2013-01-29
请教jbpm4.4如何在jsp页面上显示流程图并标出当前活动节点,求教了
|
|
forevercoding
2013-01-31
1、ExecutionImpl有个方法findActiveActivityNames可以获取激活的活动节点名;
2、也可以直接查询execution表的activityname字段获取激活的活动节点名; 至于生成图片可以用awt来实现 |
|
freezingsky
2013-02-25
请参考jbpm3的实现方式,原理相似。
|
|
wen19851025
2013-02-26
发图流程时需要把图片和XML打包成zip发布.
|
|
comsci
2013-02-26
因为我对JBPM的设计器设计不是很熟悉,所以只从原理上面来讲,要在JSP界面里面逆向调用XML文件,反向生成流程图,如果JBPM的eclipse设计器插件是开源的,那么从理论上是可以实现的
|
|
lydawen
2013-02-27
生成图片没那复杂。找到活动节点,结合jbpm提供的api,可以找到节点在流程图片上的坐标,接下来就非常简单了
|
|
freezingsky
2013-02-27
给个3.x实现例子,代码如下:
package com.freezing.tag; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.XPath; import org.dom4j.xpath.DefaultXPath; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.file.def.FileDefinition; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.Token; import org.jbpm.taskmgmt.exe.TaskInstance; public class ProcessImageTag extends TagSupport { private static final long serialVersionUID = 1L; private long taskInstanceId = -1; private long tokenInstanceId = -1; private byte[] gpdBytes = null; private byte[] imageBytes = null; private Token currentToken = null; private ProcessDefinition processDefinition = null; static String currentTokenColor = "red"; static String childTokenColor = "blue"; static String tokenNameColor = "blue"; private JbpmContext jbpmContext; public void release() { taskInstanceId = -1; gpdBytes = null; imageBytes = null; currentToken = null; try { jbpmContext.close(); }catch(Exception e) {} } public int doEndTag() throws JspException { try { initialize(); retrieveByteArrays(); if (gpdBytes != null && imageBytes != null) { writeTable(); } } catch (IOException e) { e.printStackTrace(); throw new JspException("table couldn't be displayed", e); } catch (DocumentException e) { e.printStackTrace(); throw new JspException("table couldn't be displayed", e); } release(); return EVAL_PAGE; } private void retrieveByteArrays() { try { FileDefinition fileDefinition = processDefinition.getFileDefinition(); gpdBytes = fileDefinition.getBytes("gpd.xml"); imageBytes = fileDefinition.getBytes("processimage.jpg"); } catch (Exception e) { e.printStackTrace(); } } private void writeTable() throws IOException, DocumentException { int borderWidth = 4; Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes,"utf-8")).getRootElement(); int[] boxConstraint; int[] imageDimension = extractImageDimension(rootDiagramElement); String imageLink = "processimage?definitionId=" + processDefinition.getId(); JspWriter jspOut = pageContext.getOut(); if (tokenInstanceId > 0) { List allTokens = new ArrayList(); walkTokens(currentToken, allTokens); jspOut.println("<div style='position:relative; background-image:url(" + imageLink + "); width: " + imageDimension[0] + "px; height: " + imageDimension[1] + "px;'>"); for (int i = 0; i < allTokens.size(); i++) { Token token = (Token) allTokens.get(i); //check how many tokens are on teh same level (= having the same parent) int offset = i; if(i > 0) { while(offset > 0 && ((Token) allTokens.get(offset - 1)).getParent().equals(token.getParent())) { offset--; } } boxConstraint = extractBoxConstraint(rootDiagramElement, token); //Adjust for borders //boxConstraint[2]-=borderWidth*2; //boxConstraint[3]-=borderWidth*2; jspOut.println("<div class='tooltips' style='position:absolute; left: "+ boxConstraint[0] +"px; top: "+ boxConstraint[1] +"px; "); if (i == (allTokens.size() - 1)) { jspOut.println("border: " + currentTokenColor); } else { jspOut.println("border: " + childTokenColor); } jspOut.println(" " + borderWidth + "px groove; "+ "width: "+ boxConstraint[2] +"px; height: "+ boxConstraint[3] +"px;'>"); if(token.getName()!=null) { jspOut.println("<span style='color:" + tokenNameColor + ";font-style:italic;position:absolute;left:"+ (boxConstraint[2] + 10) +"px;top:" +((i - offset) * 20) +";'> " + token.getName() +"</span>"); } jspOut.println("</div>"); } jspOut.println("</div>"); } else { boxConstraint = extractBoxConstraint(rootDiagramElement); jspOut.println("<table border=0 cellspacing=0 cellpadding=0 width=" + imageDimension[0] + " height=" + imageDimension[1] + ">"); jspOut.println(" <tr>"); jspOut.println(" <td width=" + imageDimension[0] + " height=" + imageDimension[1] + " style=\"background-image:url(" + imageLink + ")\" valign=top>"); jspOut.println(" <table border=0 cellspacing=0 cellpadding=0>"); jspOut.println(" <tr>"); jspOut.println(" <td width=" + (boxConstraint[0] - borderWidth) + " height=" + (boxConstraint[1] - borderWidth) + " style=\"background-color:transparent;\"></td>"); jspOut.println(" </tr>"); jspOut.println(" <tr>"); jspOut.println(" <td style=\"background-color:transparent;\"></td>"); jspOut.println(" <td style=\"border-color:" + currentTokenColor + "; border-width:" + borderWidth + "px; border-style:groove; background-color:transparent;\" width=" + boxConstraint[2] + " height=" + (boxConstraint[3] + (2 * borderWidth)) + "> </td>"); jspOut.println(" </tr>"); jspOut.println(" </table>"); jspOut.println(" </td>"); jspOut.println(" </tr>"); jspOut.println("</table>"); } } 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; } private int[] extractBoxConstraint(Element root, Token token) { int[] result = new int[4]; String nodeName = token.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; } private int[] extractImageDimension(Element root) { int[] result = new int[2]; result[0] = Integer.valueOf(root.attribute("width").getValue()).intValue(); result[1] = Integer.valueOf(root.attribute("height").getValue()).intValue(); return result; } private void initialize() { jbpmContext = JbpmConfiguration.getInstance().createJbpmContext(); 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(); } private void walkTokens(Token parent, List allTokens) { Map children = parent.getChildren(); if(children != null && children.size() > 0) { Collection childTokens = children.values(); for (Iterator iterator = childTokens.iterator(); iterator.hasNext();) { Token child = (Token) iterator.next(); walkTokens(child, allTokens); } } allTokens.add(parent); } public void setTask(long id) { this.taskInstanceId = id; } public void setToken(long id) { this.tokenInstanceId = id; } } 根据4.x的API换成对应的读取操作即可。我这是把图片的显示做成标签使用。 |
|
kingknight
2013-04-09
绘图的Action
@Action("paint") public void paint() { ProcessInstance processInstance = executionService .findProcessInstanceById(id); String processDefinitionId = processInstance.getProcessDefinitionId(); ProcessDefinition processDefinition = repositoryService .createProcessDefinitionQuery().processDefinitionId( processDefinitionId).uniqueResult(); InputStream inputStream = repositoryService.getResourceAsStream( processDefinition.getDeploymentId(), "leave.png"); byte[] b = new byte[1024]; int len = -1; try { while ((len = inputStream.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } 触发的Action private ActivityCoordinates ac; @Action("view") public String view(){ ProcessInstance processInstance = executionService.findProcessInstanceById(id); Set<String> activityNames = processInstance.findActiveActivityNames(); ac = repositoryService.getActivityCoordinates(processInstance.getProcessDefinitionId(),activityNames.iterator().next()); return SUCCESS; } JSP页面 <body> <img src="main/paint?id=${id }" style="position:absolute;left:0px;top:0px;"> <div style="position:absolute;border:1px solid red;left:${ac.x }px;top:${ac.y }px;width:${ac.width }px;height:${ac.height }px;"></div> </body> |