6 Replies Latest reply on Mar 17, 2009 10:50 AM by Kris R

    showing image of current process stage

    yair friedman Newbie

      hi ,

      i develped a small program that reads the gpd.xml and the processdefinition.xml of the process and show the map of the process with a red rectangle arround the current task of the process .
      sometimes the rectange is not sorrounding the Node but is in other location , i suspect it is because of changes that was done to the diagram
      that changed or not changed the XML .

      anyway the code the determine the X,Y of the Rectange is :

       public int[] extractBoxConstraint(Element root, Token currentToken) {
       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;
       }
      


      thanks in Advance .
      Yair

        • 1. Re: showing image of current process stage
          Heiner Niehues Newbie

          Hi,

          I intend to create a similar program. Maybe you can give me a tip how you realized to show the red rectangle. Would be very nice.

          Heiner

          • 2. Re: showing image of current process stage
            yair friedman Newbie

            here it is.
            you need to print via JSPout the output. to see.
            th function get the process instance id

             public StringBuffer showProcessImage (long processInstanceId) {
             byte[] gpdBytes = null;
             byte[] imageBytes = null;
             Token currentToken=null;
             String currentTokenColor = "red";
             long taskInstanceId=0;
             StringBuffer Sb = new StringBuffer();
             TaskInstance taskInstance=null;
             JbpmContext context = conf.createJbpmContext();
             GraphSession graphSession = context.getGraphSession();
             ProcessInstance pi = graphSession.loadProcessInstance(processInstanceId);
            
             TaskMgmtInstance tmi = pi.getTaskMgmtInstance();
             try {
             Collection tis = tmi.getUnfinishedTasks(pi.getRootToken());
            
             Iterator taskInstances = tis.iterator();
             if (taskInstances.hasNext()) {
             TaskInstance ti = (TaskInstance)taskInstances.next();
             taskInstanceId = ti.getId();
             taskInstance = context.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
             }
             else //process has finished
             {
             Collection allTasks = tmi.getTaskInstances();
             Iterator AlltaskInstances = allTasks.iterator();
             TaskInstance LastInstance=null;
             while (AlltaskInstances.hasNext()) {
             LastInstance = (TaskInstance)AlltaskInstances.next();
             }
             taskInstanceId = LastInstance.getId();
             taskInstance = context.getTaskMgmtSession().loadTaskInstance(taskInstanceId);
             }
            
             currentToken = taskInstance.getToken();
             ProcessDefinition processDefinition = currentToken.getProcessInstance().getProcessDefinition();
             //String NodeName = currentToken.getProcessInstance().getRootToken().getNode().getName();
            
             FileDefinition fileDefinition = processDefinition.getFileDefinition();
             if (fileDefinition == null) {
             fileDefinition = new FileDefinition();
             processDefinition.addDefinition(fileDefinition);
             }
            
             String Path = Configuration.instance().GetParameter("","ProcessPath");
            
             Path += processDefinition.getName();
            
             addFileResourceToFileDefinition(fileDefinition, Path, "processimage.jpg");
             addFileResourceToFileDefinition(fileDefinition, Path, "gpd.xml");
            
            
             if (new File(Path + "\\gpd.xml").exists())
             {
             //if(fileDefinition!=null)
             //{
             //gpdBytes = fileDefinition.getBytes("gpd.xml");
             gpdBytes = processDefinition.getFileDefinition().getBytes("gpd.xml");
             imageBytes = processDefinition.getFileDefinition().getBytes("processimage.jpg");
            
             if (gpdBytes != null && imageBytes != null) {
             int borderWidth = 4;
             Element rootDiagramElement = DocumentHelper.parseText(new String(gpdBytes)).getRootElement();
             int[] boxConstraint;
             int[] imageDimension = extractImageDimension(rootDiagramElement);
             //String imageLink = "processimage?definitionId="+ processDefinition.getId();
             String imageLink = Path + "\\processimage.jpg";
            
            
             //jspOut.println("</div>");
             //}
             //else {
             boxConstraint = extractBoxConstraint(rootDiagramElement,currentToken);
            
             Sb.append("<script language='javascript'>");
             Sb.append("window.contentHeight = " + imageDimension[1] +";");
             Sb.append("window.contentWidth=" + imageDimension[0]+";");
             Sb.append("</script>");
             Sb.append("<table border=0 cellspacing=0 cellpadding=0 width="
             + imageDimension[0]
             + " height="
             + imageDimension[1] + ">");
             Sb.append(" <tr>");
             Sb.append(" <td width=" + imageDimension[0]
             + " height=" + imageDimension[1]
             + " style=\"background-image:url(" + imageLink
             + ")\" valign=top>");
             Sb.append(" <table border=0 cellspacing=0 cellpadding=0>");
             Sb.append(" <tr>");
             Sb.append(" <td width="
             + (boxConstraint[0] - borderWidth)
             + " height="
             + (boxConstraint[1] - borderWidth)
             + " style=\"background-color:transparent;\"></td>");
            
            
             Sb.append(" </tr>");
             Sb.append(" <tr>");
             Sb.append(" <td style=\"background-color:transparent;\"></td>");
             Sb.append(" <td style=\"border-color:"
             + currentTokenColor
             + "; border-width:"
             + borderWidth
             + "px; border-style:groove; background-color:transparent;\" width="
             + boxConstraint[2]
             + " height="
             + (boxConstraint[3] + (2 * borderWidth))
             + "> </td>");
             Sb.append(" </tr>");
             Sb.append(" </table>");
             Sb.append(" </td>");
             Sb.append(" </tr>");
             Sb.append("</table>");
             }
             }
             }
             catch (Exception e) {
             e.printStackTrace();
             //throw new JspException("table couldn't be displayed", e);
             }
            
             context.close();
            
             taskInstanceId = -1;
             gpdBytes = null;
             imageBytes = null;
             currentToken = null;
             return Sb;
             }
            


            • 3. Re: showing image of current process stage
              Heiner Niehues Newbie

              Thanks a lot - I will try it..

              Heiner

              • 4. Re: showing image of current process stage
                Heiner Niehues Newbie

                I have also this problem.. that the rectangle are not at the right place.
                But i used a javascript library (http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm)
                to create the rectangle.
                I use a offset to fix it. I will take a look tomorrow more.

                <html>
                <head><title>Show the Picture</title>
                 <script type="text/javascript" src="js/wz_jsgraphics.js"></script>
                </head>
                <body>
                <div style="left:0px; top:0px; position:absolute;">
                <img src="img\processimage.jpg" alt="">
                </div>
                <script type="text/javascript">
                 <!--
                 function drawRect(x,y,width, height)
                 {
                 jg_doc.setColor("red");
                 jg_doc.setStroke(4);
                 jg_doc.drawRect(x, y, width, height);
                 jg_doc.paint();
                 }
                
                 var jg_doc = new jsGraphics();
                 drawRect(${coord[0]} + 217,${coord[1]} - 2 ,${coord[2]},${coord[3]});
                 //-->
                </script>
                </body>
                </html>
                
                


                Heiner

                • 5. Re: showing image of current process stage
                  David Roberts Apprentice

                  Try this thread. I posted my solution there which works perfectly for me: http://www.jboss.com/index.html?module=bb&op=viewtopic&t=102817

                  • 6. Re: showing image of current process stage
                    Kris R Newbie

                    Hi...

                    really a nice post...

                    i am working on the same example but i know very little about java

                    the line "Configuration.instance().GetParameter("","ProcessPath");" is not compiling as i am unable to find any class with name configuration....

                    please help me regarding some file inclusions sso that the code will get compiled....

                    thanks in advance...
                    Raje