Esempio n. 1
0
  /**
   * Load workflw and initialize the session attributes.
   *
   * @param ctx
   * @param AD_Workflow_ID
   * @param sess
   */
  private void loadWorkflow(Properties ctx, int AD_Workflow_ID, HttpSession sess) {

    MWorkflow wf = new MWorkflow(ctx, AD_Workflow_ID, null);
    // get the MWFNode in order
    MWFNode[] nodes = wf.getNodes(true, Env.getContextAsInt(ctx, "#AD_Client_ID"));
    MWFNode wfn = null;
    ArrayList nodes_ID = new ArrayList();
    for (int i = 0; i < nodes.length; i++) {
      wfn = nodes[i];
      nodes_ID.add(new Integer(wfn.getAD_WF_Node_ID()));
    } // for
    int imageMap[][] = generateImageMap(nodes_ID);
    // printMap(imageMap);
    // set session attribtes
    sess.setAttribute(WORKFLOW, wf);
    sess.setAttribute(NODES, nodes);
    sess.setAttribute(NODES_ID, nodes_ID);
    sess.setAttribute(IMAGE_MAP, imageMap);
    sess.setAttribute(ACTIVE_NODE, new Integer(-999));
  } // loadWorkflow
  /**
   * ************************************************************************ Mouse Clicked. Pressed
   * - Released - Clicked.
   *
   * @param e event
   */
  public void mouseClicked(MouseEvent e) {
    if (m_readWrite && SwingUtilities.isRightMouseButton(e)) {
      int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
      if (e.getSource() == this && m_wf != null) {
        m_NewPopupMenu.show(this, e.getX(), e.getY());
      } else if (e.getSource() instanceof WFNode) {
        MWFNode node = ((WFNode) e.getSource()).getModel();
        m_LinePopupMenu = new JPopupMenu(node.getName());
        if (node.getAD_Client_ID() == AD_Client_ID) {
          String title = Msg.getMsg(Env.getCtx(), "DeleteNode") + ": " + node.getName();
          addMenuItem(m_LinePopupMenu, title, node, -1);
          m_LinePopupMenu.addSeparator();
        }
        MWFNode[] nodes = m_wf.getNodes(true, AD_Client_ID);
        MWFNodeNext[] lines = node.getTransitions(AD_Client_ID);
        //	Add New Line
        for (int n = 0; n < nodes.length; n++) {
          MWFNode nn = nodes[n];
          if (nn.getAD_WF_Node_ID() == node.getAD_WF_Node_ID()) continue; // 	same
          boolean found = false;
          for (int i = 0; i < lines.length; i++) {
            MWFNodeNext line = lines[i];
            if (nn.getAD_WF_Node_ID() == line.getAD_WF_Next_ID()) {
              found = true;
              break;
            }
          }
          if (!found) {
            String title =
                Msg.getMsg(Env.getCtx(), "AddLine") + ": " + node.getName() + " -> " + nn.getName();
            addMenuItem(m_LinePopupMenu, title, node, nn.getAD_WF_Node_ID());
          }
        }
        m_LinePopupMenu.addSeparator();
        //	Delete Lines
        for (int i = 0; i < lines.length; i++) {
          MWFNodeNext line = lines[i];
          if (line.getAD_Client_ID() != AD_Client_ID) continue;
          MWFNode next = MWFNode.get(Env.getCtx(), line.getAD_WF_Next_ID());
          String title =
              Msg.getMsg(Env.getCtx(), "DeleteLine")
                  + ": "
                  + node.getName()
                  + " -> "
                  + next.getName();
          addMenuItem(m_LinePopupMenu, title, line);
        }
        m_LinePopupMenu.show(this, e.getX(), e.getY());
      }
    }

    //	Selection
    else if (e.getSource() instanceof WFNode) {
      WFNode selected = (WFNode) e.getSource();
      log.fine(selected.toString());
      for (int i = 0; i < m_nodes.size(); i++) {
        WFNode node = (WFNode) m_nodes.get(i);
        if (selected.getAD_WF_Node_ID() == node.getAD_WF_Node_ID()) node.setSelected(true);
        else node.setSelected(false);
      }
    }
    m_dragged = false;
  } //	mouseClicked