Search in sources :

Example 6 with CTextField

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

the class InfoProduct method actionPerformed.

/**************************************************************************
	 *  Action Listener
	 *	@param e event
	 */
public void actionPerformed(ActionEvent e) {
    if (!p_loadedOK)
        return;
    String cmd = e.getActionCommand();
    Object source = null;
    if (e.getSource() != null) {
        source = e.getSource();
        if (cmd.equals(ConfirmPanel.A_PATTRIBUTE)) {
            // when the attribute window is closed.
            if (p_table.isMultiSelection()) {
                int row = p_table.getSelectionModel().getLeadSelectionIndex();
                p_table.setRowChecked(row, true);
            }
            MProduct mp = MProduct.get(Env.getCtx(), m_M_Product_ID);
            //  Set title and parameters for the PattributeInstance window
            String title = "";
            int wh_id = 0;
            if (isValidVObject(fWarehouse_ID)) {
                title = fWarehouse_ID.getDisplay() + " - " + mp.getName();
                wh_id = ((Integer) (fWarehouse_ID.getValue())).intValue();
            }
            //  Get the business partner from the context - it may be different than the Vendor
            int bp_id = 0;
            String s_bp_id = Env.getContext(Env.getCtx(), p_WindowNo, p_TabNo, "C_BPartner_ID", false);
            if (s_bp_id != null && s_bp_id.length() != 0 && (new Integer(s_bp_id).intValue() > 0))
                bp_id = new Integer(s_bp_id).intValue();
            //  Display the window
            PAttributeInstance pai = new PAttributeInstance(this, title, wh_id, 0, p_table.getLeadRowKey(), bp_id);
            if (!pai.wasCancelled()) {
                //  Get the results and update the fASI criteria field
                m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
                m_M_Locator_ID = pai.getM_Locator_ID();
                if (m_M_AttributeSetInstance_ID > 0)
                    fASI_ID.setValue(m_M_AttributeSetInstance_ID);
                else
                    //  No instance
                    fASI_ID.setValue(0);
            }
            //  looking around.
            if (//  If the results are saved, we can save now - an ASI is product specific
            p_saveResults && m_M_AttributeSetInstance_ID != -1 && !pai.wasCancelled()) {
                dispose(p_saveResults);
                return;
            }
            return;
        } else if (source instanceof VComboBox) {
            if (((VComboBox) source).getParent() instanceof VLookup) {
                // Works for VLookups using DisplayType.TableDir
                source = ((VComboBox) source).getParent();
                VLookup vl = ((VLookup) source);
                m_heldLastFocus = vl;
                if (cmd.equals("comboBoxEdited")) {
                    if (!vl.hasChanged() && !hasOutstandingChanges()) {
                        vl.requestFocus();
                        return;
                    }
                    p_triggerRefresh = true;
                    //  perform field-specific changes
                    if (vl == fWarehouse_ID) {
                        if (!isValidVObject(fWarehouse_ID)) {
                            //  Disable the stock button
                            checkOnlyStock.setSelected(false);
                            checkOnlyStock.setEnabled(false);
                        } else
                            checkOnlyStock.setEnabled(true);
                    }
                }
            }
        } else if (source instanceof CTextField) {
            CTextField tf = ((CTextField) source);
            if (tf.getParent() instanceof VPAttribute) {
                source = tf.getParent();
                VPAttribute vpa = ((VPAttribute) source);
                //  The VPAttribute field can't hold the focus effectively
                m_heldLastFocus = fieldValue;
                if (vpa.hasChanged()) {
                    p_triggerRefresh = true;
                }
            }
        } else if (e.getSource() instanceof VCheckBox) {
            //  Check box changes generally always cause a refresh
            //  Capture changes that don't 	
            VCheckBox cb = (VCheckBox) e.getSource();
            //  ShowDetail check box
            if (cb.getName().equals("ShowDetail")) {
                // Refresh only the ATP tab 
                refreshAtpTab();
                return;
            }
        }
    }
    //  e.getSource() is null
    //  Let the info class decide what to do.
    super.actionPerformed(e);
}
Also used : MProduct(org.compiere.model.MProduct) VPAttribute(org.compiere.grid.ed.VPAttribute) CTextField(org.compiere.swing.CTextField) VLookup(org.compiere.grid.ed.VLookup) VComboBox(org.compiere.grid.ed.VComboBox) VCheckBox(org.compiere.grid.ed.VCheckBox) ALayoutConstraint(org.compiere.apps.ALayoutConstraint)

Example 7 with CTextField

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

the class Info method actionPerformed.

/**************************************************************************
	 *	(Button) Action Listener & Popup Menu
	 *  @param e event
	 */
public void actionPerformed(ActionEvent e) {
    if (!p_loadedOK)
        return;
    String cmd = e.getActionCommand();
    if (cmd.equals("CausedFocusEvent")) {
        return;
    }
    Object source = null;
    if (e.getSource() != null) {
        source = e.getSource();
        //  Keep the focus on the source field if the table updates
        m_heldLastFocus = this.getFocusOwner();
        //  Popup => Calculator
        if (source.equals(calcMenu)) {
            BigDecimal number = null;
            if (m_popupRow >= 0 && m_popupColumn >= 0) {
                Object data = p_table.getValueAt(m_popupRow, m_popupColumn);
                try {
                    if (data != null) {
                        if (data instanceof BigDecimal)
                            number = (BigDecimal) data;
                        else
                            number = new BigDecimal(data.toString());
                    }
                } catch (Exception ex) {
                }
                Calculator c = new Calculator(null, number);
                c.setVisible(true);
            }
            return;
        } else //  Popup => zoom
        if (e.getSource().equals(zoomMenu)) {
            if (m_popupRow >= 0 && m_popupColumn >= 0) {
                zoom(p_table.getRowKey(m_popupRow));
            }
            return;
        } else if (cmd.equals(ConfirmPanel.A_OK)) {
            //  VLookup fields in the criteria
            if (hasOutstandingChanges()) {
                return;
            } else {
                // We might close
                p_triggerRefresh = false;
            }
        } else if (source instanceof VComboBox) {
            if (((VComboBox) source).getParent() instanceof VLookup) {
                source = ((VComboBox) source).getParent();
                VLookup vl = ((VLookup) source);
                m_heldLastFocus = vl;
                //  events that don't have changes from the last action.
                if (cmd.equals("comboBoxChanged")) {
                    if (!vl.hasChanged())
                        return;
                    else
                        p_triggerRefresh = true;
                } else if (cmd.equals("comboBoxEdited")) {
                    if (!vl.hasChanged() && !hasOutstandingChanges()) {
                        vl.requestFocus();
                        return;
                    }
                    p_triggerRefresh = true;
                }
            }
        } else if (source instanceof CTextField) {
            CTextField tf = ((CTextField) source);
            if (tf.getParent() instanceof VLookup) {
                // instead.
                return;
            } else if (//  The change may have come from another field
            tf.hasChanged() || hasOutstandingChanges()) {
                p_triggerRefresh = true;
            } else {
                // if the dialog was opened from a menu.
                if (p_TabNo == 0)
                    return;
                else
                    //  Save the selection and close;
                    dispose(true);
            }
        } else if (e.getSource() instanceof VCheckBox) {
            //  Check box changes generally always cause a refresh
            //  Capture changes that don't 
            p_triggerRefresh = true;
            VCheckBox cb = (VCheckBox) e.getSource();
            if (cb.getName().equals("AutoQuery")) {
                //  Only trigger a refresh if the check box is selected
                if (!cb.isSelected()) {
                    return;
                }
            }
        }
        // Check if we need to reset the table.  The flag is reset when
        // the table is reset.  The first change triggers the reset.
        p_resetColumns = p_resetColumns || columnIsDynamic(source);
    }
    if (cmd.equals(ConfirmPanel.A_OK)) {
        dispose(p_saveResults);
    } else if (cmd.equals(ConfirmPanel.A_CANCEL)) {
        m_cancel = true;
        dispose(false);
    } else if (cmd.equals(ConfirmPanel.A_REFRESH)) {
        //  Refresh always causes a requery in case there are
        //  changes to the underlying tables - even if the 
        //  criteria haven't changed.
        p_resetColumns = true;
        p_triggerRefresh = true;
        p_refreshNow = true;
    } else if (cmd.equals(ConfirmPanel.A_HISTORY))
        showHistory(p_table.getLeadRowKey());
    else if (cmd.equals(ConfirmPanel.A_CUSTOMIZE))
        customize();
    else if (cmd.equals(ConfirmPanel.A_ZOOM))
        zoom(p_table.getLeadRowKey());
    else if (cmd.equals(ConfirmPanel.A_RESET)) {
        //  Go back to the defaults
        // Prevent other actions
        p_loadedOK = false;
        initInfo();
        p_loadedOK = true;
        //
        p_resetColumns = true;
        p_triggerRefresh = true;
    } else if (cmd.equals(ConfirmPanel.A_PRINT))
        PrintScreenPainter.printScreen(this);
    // Refresh if the autoquery feature is selected or the refresh button is clicked.
    if (p_triggerRefresh && (p_refreshNow || autoQuery())) {
        //  Something changed so save the state and prepare for the query
        executeQuery();
    }
    //  Reset the flags
    p_triggerRefresh = false;
    p_refreshNow = false;
}
Also used : Calculator(org.compiere.grid.ed.Calculator) CTextField(org.compiere.swing.CTextField) VLookup(org.compiere.grid.ed.VLookup) VComboBox(org.compiere.grid.ed.VComboBox) VCheckBox(org.compiere.grid.ed.VCheckBox) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException)

Aggregations

CTextField (org.compiere.swing.CTextField)7 VLookup (org.compiere.grid.ed.VLookup)4 VCheckBox (org.compiere.grid.ed.VCheckBox)3 VComboBox (org.compiere.grid.ed.VComboBox)3 GridBagConstraints (java.awt.GridBagConstraints)2 Insets (java.awt.Insets)2 SQLException (java.sql.SQLException)2 VEditor (org.compiere.grid.ed.VEditor)2 CComboBox (org.compiere.swing.CComboBox)2 CLabel (org.compiere.swing.CLabel)2 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 GridBagLayout (java.awt.GridBagLayout)1 GridLayout (java.awt.GridLayout)1 BigDecimal (java.math.BigDecimal)1 Box (javax.swing.Box)1 BoxLayout (javax.swing.BoxLayout)1 JComboBox (javax.swing.JComboBox)1 JRadioButton (javax.swing.JRadioButton)1 JRootPane (javax.swing.JRootPane)1