Search in sources :

Example 1 with CMenuItem

use of org.compiere.swing.CMenuItem in project adempiere by adempiere.

the class AArchive method getArchives.

/**
	 * 	Display Request Options - New/Existing.
	 * 	@param invoker button
	 */
private void getArchives(JComponent invoker) {
    int reportCount = 0;
    int documentCount = 0;
    m_where = new StringBuffer();
    m_where.append("(AD_Table_ID=").append(m_AD_Table_ID).append(" AND Record_ID=").append(m_Record_ID).append(")");
    //	Get all for BP
    if (m_AD_Table_ID == MBPartner.Table_ID)
        m_where.append(" OR C_BPartner_ID=").append(m_Record_ID);
    //
    StringBuffer sql = new StringBuffer("SELECT IsReport, COUNT(*) FROM AD_Archive ").append("WHERE (AD_Table_ID=? AND Record_ID=?) ");
    if (m_AD_Table_ID == MBPartner.Table_ID)
        sql.append(" OR C_BPartner_ID=?");
    sql.append(" GROUP BY IsReport");
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql.toString(), null);
        pstmt.setInt(1, m_AD_Table_ID);
        pstmt.setInt(2, m_Record_ID);
        if (m_AD_Table_ID == MBPartner.Table_ID)
            pstmt.setInt(3, m_Record_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            if ("Y".equals(rs.getString(1)))
                reportCount += rs.getInt(2);
            else
                documentCount += rs.getInt(2);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql.toString(), e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    if (documentCount > 0) {
        m_documents = new CMenuItem(Msg.getMsg(Env.getCtx(), "ArchivedDocuments") + " (" + documentCount + ")");
        m_popup.add(m_documents).addActionListener(this);
    }
    if (reportCount > 0) {
        m_reports = new CMenuItem(Msg.getMsg(Env.getCtx(), "ArchivedReports") + " (" + reportCount + ")");
        m_popup.add(m_reports).addActionListener(this);
    }
    //	All Reports
    String sql1 = "SELECT COUNT(*) FROM AD_Archive WHERE AD_Table_ID=? AND IsReport='Y'";
    int allReports = DB.getSQLValue(null, sql1, m_AD_Table_ID);
    if (allReports > 0) {
        m_reportsAll = new CMenuItem(Msg.getMsg(Env.getCtx(), "ArchivedReportsAll") + " (" + reportCount + ")");
        m_popup.add(m_reportsAll).addActionListener(this);
    }
    if (documentCount == 0 && reportCount == 0 && allReports == 0)
        m_popup.add(Msg.getMsg(Env.getCtx(), "ArchivedNone"));
    m_graphicsconfig = invoker.getGraphicsConfiguration();
    //
    if (invoker.isShowing())
        //	below button
        m_popup.show(invoker, 0, invoker.getHeight());
}
Also used : CMenuItem(org.compiere.swing.CMenuItem) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with CMenuItem

use of org.compiere.swing.CMenuItem in project adempiere by adempiere.

the class Viewer method mouse_clicked.

//	cmd_drill
/**
	 * 	Mouse clicked
	 * 	@param e event
	 * 	@param rightClick true if right click
	 */
private void mouse_clicked(MouseEvent e, boolean rightClick) {
    Point point = e.getPoint();
    log.info("Right=" + rightClick + " - " + point.toString());
    if (rightClick) {
        m_ddQ = m_viewPanel.getDrillDown(point);
        m_daQ = m_viewPanel.getDrillAcross(point);
        m_ddM = null;
        m_daM = null;
        if (m_ddQ == null && m_daQ == null)
            return;
        //	Create Menu
        JPopupMenu pop = new JPopupMenu();
        Icon wi = Env.getImageIcon("mWindow.gif");
        if (m_ddQ != null) {
            m_ddM = new CMenuItem(m_ddQ.getDisplayName(Env.getCtx()), wi);
            m_ddM.setToolTipText(m_ddQ.toString());
            m_ddM.addActionListener(this);
            pop.add(m_ddM);
        }
        if (m_daQ != null) {
            m_daM = new CMenuItem(m_daQ.getDisplayName(Env.getCtx()), wi);
            m_daM.setToolTipText(m_daQ.toString());
            m_daM.addActionListener(this);
            pop.add(m_daM);
        }
        Point pp = e.getPoint();
        pop.show((Component) e.getSource(), pp.x, pp.y);
        return;
    }
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    if (m_drillDown) {
        MQuery query = m_viewPanel.getDrillDown(point);
        if (query != null) {
            log.info("Drill Down: " + query.getWhereClause(true));
            executeDrill(query);
        }
    } else if (comboDrill.getSelectedItem() != null && comboDrill.getSelectedIndex() > 0) {
        MQuery query = m_viewPanel.getDrillAcross(point);
        if (query != null) {
            NamePair pp = (NamePair) comboDrill.getSelectedItem();
            query.setTableName(pp.getID());
            log.info("Drill Accross: " + query.getWhereClause(true));
            executeDrill(query);
        }
    }
    //	setCursor
    cmd_drill();
}
Also used : CMenuItem(org.compiere.swing.CMenuItem) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair) MQuery(org.compiere.model.MQuery) Point(java.awt.Point) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) JPopupMenu(javax.swing.JPopupMenu)

Example 3 with CMenuItem

use of org.compiere.swing.CMenuItem in project adempiere by adempiere.

the class myJTree method jbInit.

//  dynInit
/**
	 * 	Static init
	 *	@throws Exception
	 */
private void jbInit() {
    this.setLayout(mainLayout);
    // 4Layers - Set initial window dimension 
    this.setPreferredSize(new Dimension(640, 480));
    labelProduct.setText(Msg.getElement(getCtx(), "M_Product_ID"));
    implosion.setText(Msg.getElement(getCtx(), "Implosion"));
    treeInfo.setText("    ");
    spacer.setText("    ");
    northPanel.setLayout(northLayout);
    northLayout.setAlignment(FlowLayout.LEFT);
    //
    this.add(northPanel, BorderLayout.NORTH);
    northPanel.add(labelProduct, null);
    northPanel.add(fieldProduct, null);
    northPanel.add(implosion, null);
    northPanel.add(spacer, null);
    northPanel.add(spacer, null);
    northPanel.add(treeInfo, null);
    treeExpand.setText(Msg.getMsg(Env.getCtx(), "ExpandTree"));
    treeExpand.setActionCommand("Expand");
    treeExpand.addMouseListener(mouseListener);
    treeExpand.addActionListener(this);
    //
    treeSearchLabel.setText(Msg.getMsg(Env.getCtx(), "TreeSearch") + " ");
    treeSearchLabel.setLabelFor(treeSearch);
    treeSearchLabel.setToolTipText(Msg.getMsg(Env.getCtx(), "TreeSearchText"));
    treeSearch.setBackground(AdempierePLAF.getInfoBackground());
    treeSearch.addKeyListener(keyListener);
    this.add(southPanel, BorderLayout.SOUTH);
    southPanel.setLayout(southLayout);
    confirmPanel.addActionListener(this);
    southPanel.add(confirmPanel, BorderLayout.SOUTH);
    southPanel2.setLayout(southLayout2);
    southLayout2.setAlignment(FlowLayout.LEFT);
    southPanel.add(southPanel2, BorderLayout.NORTH);
    //BorderLayout.EAST);
    southPanel2.add(treeExpand, null);
    southPanel2.add(spacer, null);
    //BorderLayout.WEST);
    southPanel2.add(treeSearchLabel, null);
    //BorderLayout.CENTER);
    southPanel2.add(treeSearch, null);
    this.add(splitPane, BorderLayout.CENTER);
    // 4Layers - Set divider location
    splitPane.setDividerLocation(DIVIDER_LOCATION);
    mBOM = new CMenuItem(Msg.getMsg(Env.getCtx(), "BOM"), Env.getImageIcon("Detail16.gif"));
    mBOM.addActionListener(this);
    popupMenu.add(mBOM);
    mImplosion = new CMenuItem(Msg.getMsg(Env.getCtx(), "Implosion"), Env.getImageIcon("Parent16.gif"));
    mImplosion.addActionListener(this);
    popupMenu.add(mImplosion);
}
Also used : CMenuItem(org.compiere.swing.CMenuItem) Dimension(java.awt.Dimension)

Example 4 with CMenuItem

use of org.compiere.swing.CMenuItem in project adempiere by adempiere.

the class ARequest method getRequests.

/**
	 * 	Display Request Options - New/Existing.
	 * 	@param invoker button
	 */
private void getRequests(JComponent invoker) {
    m_new = new CMenuItem(Msg.getMsg(Env.getCtx(), "RequestNew"));
    m_new.setIcon(Env.getImageIcon("New16.gif"));
    m_popup.add(m_new).addActionListener(this);
    m_graphicsconfig = invoker.getGraphicsConfiguration();
    //
    int activeCount = 0;
    int inactiveCount = 0;
    m_where = new StringBuffer();
    m_where.append("(AD_Table_ID=").append(m_AD_Table_ID).append(" AND Record_ID=").append(m_Record_ID).append(")");
    //
    if (m_AD_Table_ID == MUser.Table_ID)
        m_where.append(" OR AD_User_ID=").append(m_Record_ID).append(" OR SalesRep_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_C_BPartner.Table_ID)
        m_where.append(" OR C_BPartner_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_C_Order.Table_ID)
        m_where.append(" OR C_Order_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_C_Invoice.Table_ID)
        m_where.append(" OR C_Invoice_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_C_Payment.Table_ID)
        m_where.append(" OR C_Payment_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_M_Product.Table_ID)
        m_where.append(" OR M_Product_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_C_Project.Table_ID)
        m_where.append(" OR C_Project_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_C_Campaign.Table_ID)
        m_where.append(" OR C_Campaign_ID=").append(m_Record_ID);
    else if (m_AD_Table_ID == I_A_Asset.Table_ID)
        m_where.append(" OR A_Asset_ID=").append(m_Record_ID);
    //
    String sql = "SELECT Processed, COUNT(*) " + "FROM R_Request WHERE " + m_where + " GROUP BY Processed " + "ORDER BY Processed DESC";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            if ("Y".equals(rs.getString(1)))
                inactiveCount = rs.getInt(2);
            else
                activeCount += rs.getInt(2);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //
    if (activeCount > 0) {
        m_active = new CMenuItem(Msg.getMsg(Env.getCtx(), "RequestActive") + " (" + activeCount + ")");
        m_popup.add(m_active).addActionListener(this);
    }
    if (inactiveCount > 0) {
        m_all = new CMenuItem(Msg.getMsg(Env.getCtx(), "RequestAll") + " (" + (activeCount + inactiveCount) + ")");
        m_popup.add(m_all).addActionListener(this);
    }
    //
    if (invoker.isShowing())
        //	below button
        m_popup.show(invoker, 0, invoker.getHeight());
}
Also used : CMenuItem(org.compiere.swing.CMenuItem) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 5 with CMenuItem

use of org.compiere.swing.CMenuItem in project adempiere by adempiere.

the class VPAttributeDialog method initAttributes.

//	jbInit
/**
	 *	Dyanmic Init.
	 *  @return true if initialized
	 */
private boolean initAttributes() {
    if (m_M_Product_ID == 0 && !m_productWindow)
        return false;
    MAttributeSet as = null;
    if (m_M_Product_ID != 0) {
        //	Get Model
        m_product = MProduct.get(Env.getCtx(), m_M_Product_ID);
        if (m_product.getM_AttributeSetInstance_ID() > 0) {
            m_productASI = true;
            //  The product has an instance associated with it.
            if (m_M_AttributeSetInstance_ID != m_product.getM_AttributeSetInstance_ID()) {
                log.fine("Different ASI than what is specified on Product!");
            }
        } else {
            // Only show product attributes when in the product window.
            m_productASI = m_productWindow;
        }
        m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
        if (m_masi == null) {
            log.severe("No Model for M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + ", M_Product_ID=" + m_M_Product_ID);
            return false;
        }
        Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", m_masi.getM_AttributeSet_ID());
        //	Get Attribute Set
        as = m_masi.getMAttributeSet();
    } else {
        int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
        m_masi = new MAttributeSetInstance(Env.getCtx(), 0, M_AttributeSet_ID, null);
        as = m_masi.getMAttributeSet();
    }
    //	Product has no Attribute Set
    if (as == null) {
    //ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
    //return false;
    }
    //  always read/write.  The two are exclusive and can't co-exist.  
    if (//	Set Instance Attributes and dialog controls
    !m_productWindow || !m_productASI) {
        if (// Instance attributes possible.  Set up controls.
        !m_productASI) {
            //	New/Edit - Selection
            if (//	new
            m_M_AttributeSetInstance_ID == 0)
                cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "NewRecord"));
            else
                cbNewEdit.setText(Msg.getMsg(Env.getCtx(), "EditRecord"));
            cbNewEdit.addActionListener(this);
            centerPanel.add(cbNewEdit, new ALayoutConstraint(m_row++, 0));
            bSelect.setText(Msg.getMsg(Env.getCtx(), "SelectExisting"));
            bSelect.addActionListener(this);
            centerPanel.add(bSelect, null);
        }
        //	Add the Instance Attributes if any.  If its a product attribute set
        //  this will do nothing.
        MAttribute[] attributes = as.getMAttributes(true);
        log.fine("Instance Attributes=" + attributes.length);
        for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], false, false);
    }
    if (as != null) {
        //  Product attributes can be shown in any window but are read/write in the Product window only.
        //  This will do nothing if it is an instance attribute set. 
        // False = product attribute instances
        MAttribute[] attributes = as.getMAttributes(false);
        log.fine("Product Attributes=" + attributes.length);
        for (int i = 0; i < attributes.length; i++) addAttributeLine(attributes[i], true, !m_productWindow);
    }
    //	Lot
    if ((!m_productWindow || !m_productASI) && as.isLot()) {
        CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Lot"));
        label.setLabelFor(fieldLotString);
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldLotString, null);
        fieldLotString.setText(m_masi.getLot());
        //	M_Lot_ID
        //	int AD_Column_ID = 9771;	//	M_AttributeSetInstance.M_Lot_ID
        //	fieldLot = new VLookup ("M_Lot_ID", false,false, true, 
        //		MLookupFactory.get(Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
        String sql = "SELECT M_Lot_ID, Name " + "FROM M_Lot l " + "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p " + "WHERE p.M_AttributeSet_ID=" + m_masi.getM_AttributeSet_ID() + " AND p.M_Product_ID=l.M_Product_ID)";
        fieldLot = new CComboBox(DB.getKeyNamePairs(sql, true));
        label = new CLabel(Msg.translate(Env.getCtx(), "M_Lot_ID"));
        label.setLabelFor(fieldLot);
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldLot, null);
        if (m_masi.getM_Lot_ID() != 0) {
            for (int i = 1; i < fieldLot.getItemCount(); i++) {
                KeyNamePair pp = (KeyNamePair) fieldLot.getItemAt(i);
                if (pp.getKey() == m_masi.getM_Lot_ID()) {
                    fieldLot.setSelectedIndex(i);
                    fieldLotString.setEditable(false);
                    break;
                }
            }
        }
        fieldLot.addActionListener(this);
        //	New Lot Button
        if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0 && m_readWrite) {
            if (MRole.getDefault().isTableAccess(MLot.Table_ID, false) && MRole.getDefault().isTableAccess(MLotCtl.Table_ID, false) && !m_masi.isExcludeLot(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                centerPanel.add(bLot, null);
                bLot.addActionListener(this);
            }
        }
        //	Popup 
        //  popup
        fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this));
        mZoom = new CMenuItem(Msg.getMsg(Env.getCtx(), "Zoom"), Env.getImageIcon("Zoom16.gif"));
        mZoom.addActionListener(this);
        popupMenu.add(mZoom);
    }
    //	SerNo
    if ((!m_productWindow || !m_productASI) && as.isSerNo()) {
        CLabel label = new CLabel(Msg.translate(Env.getCtx(), "SerNo"));
        label.setLabelFor(fieldSerNo);
        fieldSerNo.setText(m_masi.getSerNo());
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldSerNo, null);
        //	New SerNo Button
        if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0 && m_readWrite) {
            if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false) && !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent))) {
                centerPanel.add(bSerNo, null);
                bSerNo.addActionListener(this);
            }
        }
    }
    //	GuaranteeDate
    if ((!m_productWindow || !m_productASI) && as.isGuaranteeDate()) {
        CLabel label = new CLabel(Msg.translate(Env.getCtx(), "GuaranteeDate"));
        label.setLabelFor(fieldGuaranteeDate);
        if (m_M_AttributeSetInstance_ID == 0)
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
        else
            fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
        centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
        centerPanel.add(fieldGuaranteeDate, null);
    }
    if (m_row == 0) {
        ADialog.error(m_WindowNo, this, "PAttributeNoInfo");
    //return false;
    }
    //	New/Edit Window
    if ((!m_productWindow || !m_productASI) && m_AD_Column_ID != 0 && m_readWrite) {
        cbNewEdit.setSelected(m_M_AttributeSetInstance_ID == 0);
        cmd_newEdit();
    }
    //	Attribute Set Instance Description
    CLabel label = new CLabel(Msg.translate(Env.getCtx(), "Description"));
    label.setLabelFor(fieldDescription);
    fieldDescription.setText(m_masi.getDescription());
    fieldDescription.setEditable(false);
    centerPanel.add(label, new ALayoutConstraint(m_row++, 0));
    centerPanel.add(fieldDescription, null);
    //	Window usually to wide (??)
    Dimension dd = centerPanel.getPreferredSize();
    dd.width = Math.min(500, dd.width);
    centerPanel.setPreferredSize(dd);
    return true;
}
Also used : CLabel(org.compiere.swing.CLabel) CComboBox(org.compiere.swing.CComboBox) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) Dimension(java.awt.Dimension) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) ALayoutConstraint(org.compiere.apps.ALayoutConstraint) MAttributeSet(org.compiere.model.MAttributeSet) CMenuItem(org.compiere.swing.CMenuItem) KeyNamePair(org.compiere.util.KeyNamePair) MAttribute(org.compiere.model.MAttribute)

Aggregations

CMenuItem (org.compiere.swing.CMenuItem)13 Dimension (java.awt.Dimension)3 KeyNamePair (org.compiere.util.KeyNamePair)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 ImageIcon (javax.swing.ImageIcon)2 JPopupMenu (javax.swing.JPopupMenu)2 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)2 MAttribute (org.compiere.model.MAttribute)2 MAttributeSet (org.compiere.model.MAttributeSet)2 MAttributeSetInstance (org.compiere.model.MAttributeSetInstance)2 CComboBox (org.compiere.swing.CComboBox)2 CLabel (org.compiere.swing.CLabel)2 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Icon (javax.swing.Icon)1 I_AD_Process (org.compiere.model.I_AD_Process)1 MQuery (org.compiere.model.MQuery)1 CCheckBoxMenuItem (org.compiere.swing.CCheckBoxMenuItem)1