Search in sources :

Example 1 with MWFNodeNext

use of org.compiere.wf.MWFNodeNext in project adempiere by adempiere.

the class WFPanel method load.

//	load
/**
	 * 	Load Workflow & Nodes
	 * 	@param AD_Workflow_ID ID
	 * 	@param readWrite if true nodes can be moved
	 */
public void load(int AD_Workflow_ID, boolean readWrite) {
    log.fine("RW=" + readWrite + " - AD_Workflow_ID=" + AD_Workflow_ID);
    if (AD_Workflow_ID == 0)
        return;
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
    //	Get Workflow
    m_wf = new MWorkflow(Env.getCtx(), AD_Workflow_ID, null);
    centerPanel.removeAll();
    centerPanel.setReadWrite(readWrite);
    if (readWrite)
        centerPanel.setWorkflow(m_wf);
    //	Add Nodes for Paint
    MWFNode[] nodes = m_wf.getNodes(true, AD_Client_ID);
    for (int i = 0; i < nodes.length; i++) {
        WFNode wfn = new WFNode(nodes[i]);
        wfn.addPropertyChangeListener(WFNode.PROPERTY_SELECTED, this);
        boolean rw = //	in editor mode & owned
        readWrite && (AD_Client_ID == nodes[i].getAD_Client_ID());
        centerPanel.add(wfn, rw);
        //	Add Lines
        MWFNodeNext[] nexts = nodes[i].getTransitions(AD_Client_ID);
        for (int j = 0; j < nexts.length; j++) centerPanel.add(new WFLine(nexts[j]), false);
    }
    //	Info Text
    StringBuffer msg = new StringBuffer("<HTML>");
    msg.append("<H2>").append(m_wf.getName(true)).append("</H2>");
    String s = m_wf.getDescription(true);
    if (s != null && s.length() > 0)
        msg.append("<B>").append(s).append("</B>");
    s = m_wf.getHelp(true);
    if (s != null && s.length() > 0)
        msg.append("<BR>").append(s);
    msg.append("</HTML>");
    infoTextPane.setText(msg.toString());
    infoTextPane.setCaretPosition(0);
    //	Layout
    centerPanel.validate();
    centerPanel.repaint();
    validate();
}
Also used : MWFNode(org.compiere.wf.MWFNode) MWorkflow(org.compiere.wf.MWorkflow) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext) Point(java.awt.Point)

Example 2 with MWFNodeNext

use of org.compiere.wf.MWFNodeNext in project adempiere by adempiere.

the class MPPOrder method explotion.

/**
	 * Create PP_Order_BOM from PP_Product_BOM.
	 * Create PP_Order_Workflow from AD_Workflow.
	 */
private void explotion() {
    // Create BOM Head
    final MPPProductBOM PP_Product_BOM = MPPProductBOM.get(getCtx(), getPP_Product_BOM_ID());
    // Product from Order should be same as product from BOM - teo_sarca [ 2817870 ] 
    if (getM_Product_ID() != PP_Product_BOM.getM_Product_ID()) {
        throw new AdempiereException("@NotMatch@ @PP_Product_BOM_ID@ , @M_Product_ID@");
    }
    // Product BOM Configuration should be verified - teo_sarca [ 2817870 ]
    final MProduct product = MProduct.get(getCtx(), PP_Product_BOM.getM_Product_ID());
    if (!product.isVerified()) {
        // TODO: translate
        throw new AdempiereException("Product BOM Configuration not verified. Please verify the product first - " + product.getValue());
    }
    if (PP_Product_BOM.isValidFromTo(getDateStartSchedule())) {
        MPPOrderBOM PP_Order_BOM = new MPPOrderBOM(PP_Product_BOM, getPP_Order_ID(), get_TrxName());
        PP_Order_BOM.setAD_Org_ID(getAD_Org_ID());
        PP_Order_BOM.saveEx();
        for (MPPProductBOMLine PP_Product_BOMline : PP_Product_BOM.getLines(true)) {
            if (PP_Product_BOMline.isValidFromTo(getDateStartSchedule())) {
                MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(PP_Product_BOMline, getPP_Order_ID(), PP_Order_BOM.get_ID(), getM_Warehouse_ID(), get_TrxName());
                PP_Order_BOMLine.setAD_Org_ID(getAD_Org_ID());
                PP_Order_BOMLine.setM_Warehouse_ID(getM_Warehouse_ID());
                PP_Order_BOMLine.setM_Locator_ID(getM_Locator_ID());
                PP_Order_BOMLine.setQtyOrdered(getQtyOrdered());
                PP_Order_BOMLine.saveEx();
            } else // end if valid From / To    
            {
                log.fine("BOM Line skiped - " + PP_Product_BOMline);
            }
        }
    // end Create Order BOM
    } else // end if From / To parent
    {
        throw new BOMExpiredException(PP_Product_BOM, getDateStartSchedule());
    }
    // Create Workflow (Routing & Process)
    final MWorkflow AD_Workflow = MWorkflow.get(getCtx(), getAD_Workflow_ID());
    // Workflow should be validated first - teo_sarca [ 2817870 ]
    if (!AD_Workflow.isValid()) {
        // TODO: translate
        throw new AdempiereException("Routing is not valid. Please validate it first - " + AD_Workflow.getValue());
    }
    if (AD_Workflow.isValidFromTo(getDateStartSchedule())) {
        MPPOrderWorkflow PP_Order_Workflow = new MPPOrderWorkflow(AD_Workflow, get_ID(), get_TrxName());
        PP_Order_Workflow.setAD_Org_ID(getAD_Org_ID());
        PP_Order_Workflow.saveEx();
        for (MWFNode AD_WF_Node : AD_Workflow.getNodes(false, getAD_Client_ID())) {
            if (AD_WF_Node.isValidFromTo(getDateStartSchedule())) {
                MPPOrderNode PP_Order_Node = new MPPOrderNode(AD_WF_Node, PP_Order_Workflow, getQtyOrdered(), get_TrxName());
                PP_Order_Node.setAD_Org_ID(getAD_Org_ID());
                PP_Order_Node.saveEx();
                for (MWFNodeNext AD_WF_NodeNext : AD_WF_Node.getTransitions(getAD_Client_ID())) {
                    MPPOrderNodeNext nodenext = new MPPOrderNodeNext(AD_WF_NodeNext, PP_Order_Node);
                    nodenext.setAD_Org_ID(getAD_Org_ID());
                    nodenext.saveEx();
                }
                for (MPPWFNodeProduct wfnp : MPPWFNodeProduct.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
                    MPPOrderNodeProduct nodeOrderProduct = new MPPOrderNodeProduct(wfnp, PP_Order_Node);
                    nodeOrderProduct.setAD_Org_ID(getAD_Org_ID());
                    nodeOrderProduct.saveEx();
                }
                for (MPPWFNodeAsset wfna : MPPWFNodeAsset.forAD_WF_Node_ID(getCtx(), AD_WF_Node.get_ID())) {
                    MPPOrderNodeAsset nodeorderasset = new MPPOrderNodeAsset(wfna, PP_Order_Node);
                    nodeorderasset.setAD_Org_ID(getAD_Org_ID());
                    nodeorderasset.saveEx();
                }
            }
        // for node 
        }
        // Update transitions nexts and set first node
        // requery
        PP_Order_Workflow.getNodes(true);
        for (MPPOrderNode orderNode : PP_Order_Workflow.getNodes(false, getAD_Client_ID())) {
            // set workflow start node
            if (PP_Order_Workflow.getAD_WF_Node_ID() == orderNode.getAD_WF_Node_ID()) {
                PP_Order_Workflow.setPP_Order_Node_ID(orderNode.getPP_Order_Node_ID());
            }
            // set node next
            for (MPPOrderNodeNext next : orderNode.getTransitions(getAD_Client_ID())) {
                next.setPP_Order_Next_ID();
                next.saveEx();
            }
        }
        PP_Order_Workflow.saveEx();
    } else // workflow valid from/to
    {
        throw new RoutingExpiredException(AD_Workflow, getDateStartSchedule());
    }
}
Also used : MProduct(org.compiere.model.MProduct) MWorkflow(org.compiere.wf.MWorkflow) BOMExpiredException(org.eevolution.exceptions.BOMExpiredException) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext) RoutingExpiredException(org.eevolution.exceptions.RoutingExpiredException) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 3 with MWFNodeNext

use of org.compiere.wf.MWFNodeNext in project adempiere by adempiere.

the class WFContentPanel method mouseClicked.

//	getComponentAt
/**************************************************************************
	 * 	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())
                    //	same
                    continue;
                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());
        }
    } else //	Selection
    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;
}
Also used : MWFNode(org.compiere.wf.MWFNode) MWFNode(org.compiere.wf.MWFNode) MWFNodeNext(org.compiere.wf.MWFNodeNext) Point(java.awt.Point) JPopupMenu(javax.swing.JPopupMenu)

Example 4 with MWFNodeNext

use of org.compiere.wf.MWFNodeNext in project adempiere by adempiere.

the class WFPanel method load.

//	dispose
/**
	 * 	Load Workflow & Nodes
	 * 	@param AD_Workflow_ID ID
	 */
public void load(int AD_Workflow_ID) {
    log.fine("AD_Workflow_ID=" + AD_Workflow_ID);
    if (AD_Workflow_ID == 0)
        return;
    int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
    //	Get Workflow
    m_wf = new MWorkflow(Env.getCtx(), AD_Workflow_ID, null);
    nodeContainer.removeAll();
    nodeContainer.setWorkflow(m_wf);
    //	Add Nodes for Paint
    MWFNode[] nodes = m_wf.getNodes(true, AD_Client_ID);
    for (int i = 0; i < nodes.length; i++) {
        WFNode wfn = new WFNode(nodes[i]);
        nodeContainer.add(wfn);
        //	Add Lines
        MWFNodeNext[] nexts = nodes[i].getTransitions(AD_Client_ID);
        for (int j = 0; j < nexts.length; j++) nodeContainer.add(new WFLine(nexts[j]));
    }
    Dimension dimension = nodeContainer.getDimension();
    BufferedImage bi = new BufferedImage(dimension.width + 2, dimension.height + 2, BufferedImage.TYPE_INT_ARGB);
    nodeContainer.paint(bi.createGraphics());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        ImageIO.write(bi, "png", os);
        AImage imageContent = new AImage("workflow.png", os.toByteArray());
        Imagemap image = new Imagemap();
        image.setWidth(dimension.width + "px");
        image.setHeight(dimension.height + "px");
        image.setContent(imageContent);
        contentPanel.appendChild(image);
        image.addEventListener(Events.ON_CLICK, this);
        for (WFNode node : nodeContainer.getNodes()) {
            Area area = new Area();
            Rectangle rect = node.getBounds();
            area.setCoords(rect.x + "," + rect.y + "," + (rect.x + rect.width) + "," + (rect.y + rect.height));
            image.appendChild(area);
            area.setId("WFN_" + node.getAD_WF_Node_ID());
            StringBuffer tooltip = new StringBuffer();
            String s = node.getNode().getDescription(true);
            if (s != null && s.trim().length() > 0)
                tooltip.append(s);
            String h = node.getNode().getHelp(true);
            if (h != null && h.trim().length() > 0) {
                if (tooltip.length() > 0)
                    tooltip.append(". ");
                tooltip.append(h);
            }
            area.setTooltiptext(tooltip.toString());
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
    //	Info Text
    StringBuffer msg = new StringBuffer("");
    msg.append("<H2>").append(m_wf.getName(true)).append("</H2>");
    String s = m_wf.getDescription(true);
    if (s != null && s.length() > 0)
        msg.append("<B>").append(s).append("</B>");
    s = m_wf.getHelp(true);
    if (s != null && s.length() > 0)
        msg.append("<BR>").append(s);
    infoTextPane.setContent(msg.toString());
}
Also used : MWFNode(org.compiere.wf.MWFNode) MWorkflow(org.compiere.wf.MWorkflow) Rectangle(java.awt.Rectangle) MWFNode(org.compiere.wf.MWFNode) Dimension(java.awt.Dimension) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MWFNodeNext(org.compiere.wf.MWFNodeNext) BufferedImage(java.awt.image.BufferedImage) ApplicationException(org.adempiere.webui.exception.ApplicationException) Area(org.zkoss.zul.Area) WFLine(org.compiere.apps.wf.WFLine) AImage(org.zkoss.image.AImage) Imagemap(org.zkoss.zul.Imagemap)

Example 5 with MWFNodeNext

use of org.compiere.wf.MWFNodeNext in project adempiere by adempiere.

the class WorkflowNodeNextElementHandler method startElement.

public void startElement(Properties ctx, Element element) throws SAXException {
    Attributes atts = element.attributes;
    String entitytype = atts.getValue("EntityType");
    log.info("entitytype " + atts.getValue("EntityType"));
    if (isProcessElement(ctx, entitytype)) {
        if (element.parent != null && element.parent.skip) {
            element.skip = true;
            return;
        }
        String workflowName = atts.getValue("ADWorkflowNameID");
        int workflowId = get_IDWithColumn(ctx, "AD_Workflow", "name", workflowName);
        if (workflowId <= 0) {
            element.defer = true;
            element.unresolved = "AD_Workflow: " + workflowName;
            return;
        }
        String workflowNodeName = atts.getValue("ADWorkflowNodeNameID").trim();
        String workflowNodeNextName = atts.getValue("ADWorkflowNodeNextNameID").trim();
        StringBuffer sqlB = new StringBuffer("SELECT ad_wf_node_id FROM AD_WF_Node WHERE AD_Workflow_ID=? and Name =?");
        int wfNodeId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeName);
        if (wfNodeId <= 0) {
            element.defer = true;
            element.unresolved = "AD_WF_Node: " + workflowNodeName;
            return;
        }
        int wfNodeNextId = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), workflowId, workflowNodeNextName);
        if (wfNodeNextId <= 0) {
            element.defer = true;
            element.unresolved = "AD_WF_Node: " + workflowNodeNextName;
            return;
        }
        sqlB = new StringBuffer("SELECT  ad_wf_nodenext_id FROM AD_WF_NodeNext  WHERE ad_wf_node_id =? and ad_wf_next_id =?");
        int id = DB.getSQLValue(getTrxName(ctx), sqlB.toString(), wfNodeId, wfNodeNextId);
        MWFNodeNext m_WFNodeNext = new MWFNodeNext(ctx, id, getTrxName(ctx));
        int AD_Backup_ID = -1;
        String Object_Status = null;
        if (id <= 0 && atts.getValue("AD_WF_NodeNext_ID") != null && Integer.parseInt(atts.getValue("AD_WF_NodeNext_ID")) <= PackOut.MAX_OFFICIAL_ID)
            m_WFNodeNext.setAD_WF_NodeNext_ID(Integer.parseInt(atts.getValue("AD_WF_NodeNext_ID")));
        if (id > 0) {
            AD_Backup_ID = copyRecord(ctx, "AD_WF_NodeNext", m_WFNodeNext);
            Object_Status = "Update";
        } else {
            Object_Status = "New";
            AD_Backup_ID = 0;
        }
        m_WFNodeNext.setAD_WF_Node_ID(wfNodeId);
        m_WFNodeNext.setAD_WF_Next_ID(wfNodeNextId);
        m_WFNodeNext.setEntityType(atts.getValue("EntityType"));
        m_WFNodeNext.setSeqNo(Integer.valueOf(atts.getValue("SeqNo")));
        m_WFNodeNext.setIsActive(atts.getValue("isActive") != null ? Boolean.valueOf(atts.getValue("isActive")).booleanValue() : true);
        m_WFNodeNext.setIsStdUserWorkflow(atts.getValue("IsStdUserWorkflow") != null ? Boolean.valueOf(atts.getValue("IsStdUserWorkflow")).booleanValue() : true);
        log.info("about to execute m_WFNodeNext.save");
        if (m_WFNodeNext.save(getTrxName(ctx)) == true) {
            log.info("m_WFNodeNext save success");
            record_log(ctx, 1, String.valueOf(m_WFNodeNext.get_ID()), "WFNodeNext", m_WFNodeNext.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_NodeNext", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_NodeNext"));
        } else {
            log.info("m_WFNodeNext save failure");
            record_log(ctx, 0, String.valueOf(m_WFNodeNext.get_ID()), "WFNodeNext", m_WFNodeNext.get_ID(), AD_Backup_ID, Object_Status, "AD_WF_NodeNext", get_IDWithColumn(ctx, "AD_Table", "TableName", "AD_WF_NodeNext"));
            throw new POSaveFailedException("WorkflowNodeNext");
        }
    } else {
        element.skip = true;
    }
}
Also used : Attributes(org.xml.sax.Attributes) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException) MWFNodeNext(org.compiere.wf.MWFNodeNext)

Aggregations

MWFNodeNext (org.compiere.wf.MWFNodeNext)10 MWFNode (org.compiere.wf.MWFNode)8 MWorkflow (org.compiere.wf.MWorkflow)7 BufferedImage (java.awt.image.BufferedImage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 WFLine (org.compiere.apps.wf.WFLine)3 AImage (org.zkoss.image.AImage)3 Dimension (java.awt.Dimension)2 Point (java.awt.Point)2 Query (org.compiere.model.Query)2 Rectangle (java.awt.Rectangle)1 JPopupMenu (javax.swing.JPopupMenu)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 WFNode (org.adempiere.webui.apps.wf.WFNode)1 WFNodeContainer (org.adempiere.webui.apps.wf.WFNodeContainer)1 ApplicationException (org.adempiere.webui.exception.ApplicationException)1 MProduct (org.compiere.model.MProduct)1 MWFProcess (org.compiere.wf.MWFProcess)1 MWorkflowProcessor (org.compiere.wf.MWorkflowProcessor)1