Search in sources :

Example 91 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class POSLookupProduct method captureProductFromCombo.

/**
     * Capture Product from combo box
     * 
     * @return void
     */
public void captureProductFromCombo() {
    KeyNamePair item = (KeyNamePair) productLookupComboBox.getSelectedItem();
    if (item != null && !selectLock) {
        String productValue = DB.getSQLValueString(null, "SELECT Value FROM M_Product p WHERE M_Product_ID=?", item.getKey());
        fieldProductName.setPlaceholder(productValue);
        try {
            lookupProductInterface.findProduct(true);
        } catch (Exception exception) {
            ADialog.error(0, null, exception.getLocalizedMessage());
        }
        productLookupComboBox.removeAllItems();
        fieldProductName.setText("");
    }
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 92 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class POSLookupProduct method executeQuery.

private void executeQuery() {
    searched = true;
    productLookupComboBox.removeAllItems();
    productLookupComboBox.addItem(new KeyNamePair(0, title));
    selectLock = true;
    for (java.util.Vector<Object> columns : CPOS.getQueryProduct(fieldProductName.getText(), warehouseId, priceListId, partnerId)) {
        Integer productId = (Integer) columns.elementAt(0);
        String productValue = (String) columns.elementAt(1);
        String productName = (String) columns.elementAt(2);
        String qtyAvailable = (String) columns.elementAt(3);
        String priceStd = (String) columns.elementAt(4);
        String priceList = (String) columns.elementAt(5);
        String line = new StringBuilder().append(StringUtils.trunc(productValue + fill, PRODUCT_VALUE_LENGTH)).append(separator).append(StringUtils.trunc(productName + fill, PRODUCT_NAME_LENGTH)).append(separator).append(StringUtils.trunc(qtyAvailable + fill, QUANTITY_LENGTH)).append(separator).append(StringUtils.trunc(priceStd + fill, QUANTITY_LENGTH)).append(separator).append(StringUtils.trunc(priceList + fill, QUANTITY_LENGTH)).toString();
        productLookupComboBox.addItem(new KeyNamePair(productId, line));
    }
    productLookupComboBox.showPopup();
    selectLock = false;
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair)

Example 93 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class VProductConfigurationBOM method actionPerformed.

//	getPreferredSize
/**************************************************************************
	 *	Action Listener
	 *  @param e event
	 */
public void actionPerformed(ActionEvent e) {
    log.config(e.getActionCommand());
    Object source = e.getSource();
    //	Toggle Qty Enabled
    if (source instanceof JCheckBox || source instanceof JRadioButton) {
        cmd_selection(source);
        //	need to de-select the others in group	
        if (source instanceof JRadioButton) {
            //	find Button Group
            Iterator it = m_buttonGroups.values().iterator();
            while (it.hasNext()) {
                ButtonGroup group = (ButtonGroup) it.next();
                Enumeration en = group.getElements();
                while (en.hasMoreElements()) {
                    //	We found the group
                    if (source == en.nextElement()) {
                        Enumeration info = group.getElements();
                        while (info.hasMoreElements()) {
                            Object infoObj = info.nextElement();
                            if (source != infoObj)
                                cmd_selection(infoObj);
                        }
                    }
                }
            }
        }
    } else //	Product / Qty
    if (source == productField || source == productQty) {
        m_qty = (BigDecimal) productQty.getValue();
        KeyNamePair pp = (KeyNamePair) productField.getSelectedItem();
        m_product = MProduct.get(Env.getCtx(), pp.getKey());
        createMainPanel();
        sizeIt();
    } else //	Order
    if (source == orderField) {
        KeyNamePair pp = (KeyNamePair) orderField.getSelectedItem();
        boolean valid = (pp != null && pp.getKey() > 0);
        //
        if (invoiceField != null)
            invoiceField.setReadWrite(!valid);
        if (projectField != null)
            projectField.setReadWrite(!valid);
    } else //	Invoice
    if (source == invoiceField) {
        KeyNamePair pp = (KeyNamePair) invoiceField.getSelectedItem();
        boolean valid = (pp != null && pp.getKey() > 0);
        //
        if (orderField != null)
            orderField.setReadWrite(!valid);
        if (projectField != null)
            projectField.setReadWrite(!valid);
    } else //	Project
    if (source == projectField) {
        KeyNamePair pp = (KeyNamePair) projectField.getSelectedItem();
        boolean valid = (pp != null && pp.getKey() > 0);
        //
        if (orderField != null)
            orderField.setReadWrite(!valid);
        if (invoiceField != null)
            invoiceField.setReadWrite(!valid);
    } else //	OK
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
        if (cmd_save())
            dispose();
    } else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
        dispose();
    //	Enable OK
    boolean OK = m_product != null;
    if (OK) {
        KeyNamePair pp = null;
        if (orderField != null)
            pp = (KeyNamePair) orderField.getSelectedItem();
        if ((pp == null || pp.getKey() <= 0) && invoiceField != null)
            pp = (KeyNamePair) invoiceField.getSelectedItem();
        if ((pp == null || pp.getKey() <= 0) && projectField != null)
            pp = (KeyNamePair) projectField.getSelectedItem();
        OK = (pp != null && pp.getKey() > 0);
    }
    confirmPanel.getOKButton().setEnabled(OK);
}
Also used : JCheckBox(javax.swing.JCheckBox) JRadioButton(javax.swing.JRadioButton) Enumeration(java.util.Enumeration) ButtonGroup(javax.swing.ButtonGroup) Iterator(java.util.Iterator) org.eevolution.form.bom.nodeUserObject(org.eevolution.form.bom.nodeUserObject) KeyNamePair(org.compiere.util.KeyNamePair) BigDecimal(java.math.BigDecimal)

Example 94 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WLogin method doPost.

//	doGet
/**
	 *	Process the HTTP Post request.
	 *  <pre>
	 *  - Optionally create Session
	 *  - Check database connection
	 *  - LoginInfo from request?
	 *      - Yes: DoLogin success ?
	 *          - Yes: return (second) preferences page
	 *          - No: return (first) user/password page
	 *      - No: User Principal ?
	 *          - Yes: DoLogin success ?
	 *              - Yes: return (second) preferences page
	 *              - No: return (first) user/password page
	 *          - No: return (first) user/password page
	 *  </pre>
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.info("");
    //  Create New Session
    HttpSession sess = request.getSession(true);
    sess.setMaxInactiveInterval(WebEnv.TIMEOUT);
    //  Get Cookie Properties
    Properties cProp = WebUtil.getCookieProprties(request);
    //  Create Context
    WebSessionCtx wsc = WebSessionCtx.get(request);
    //  Page
    WebDoc doc = null;
    //  Check DB connection
    if (!DB.isConnected()) {
        String msg = Msg.getMsg(wsc.ctx, "WLoginNoDB");
        if (msg.equals("WLoginNoDB"))
            msg = "No Database Connection";
        doc = WebDoc.createWindow(msg);
    } else //  Login Info from request?
    {
        //  Get Parameters:     UserName/Password
        String usr = WebUtil.getParameter(request, P_USERNAME);
        String pwd = WebUtil.getParameter(request, P_PASSWORD);
        //  Get Principle
        Principal userPrincipal = request.getUserPrincipal();
        log.info("Principal=" + userPrincipal + "; User=" + usr);
        //  Login info not from request and not pre-authorized
        if (userPrincipal == null && (usr == null || pwd == null))
            doc = createFirstPage(cProp, request, "");
        else //  Login info from request or authorized
        {
            KeyNamePair[] roles = null;
            Login login = new Login(wsc.ctx);
            //  Pre-authorized
            if (userPrincipal != null) {
                roles = login.getRoles(userPrincipal);
                usr = userPrincipal.getName();
            } else
                roles = login.getRoles(usr, pwd);
            //
            if (roles == null)
                doc = createFirstPage(cProp, request, Msg.getMsg(wsc.ctx, "UserPwdError"));
            else {
                doc = createSecondPage(request, WebUtil.convertToOption(roles, null), "");
                //	Create adempiere Session - user id in ctx
                MSession.get(wsc.ctx, request.getRemoteAddr(), request.getRemoteHost(), sess.getId());
            }
            //  Can we save Cookie ?
            if (WebUtil.getParameter(request, P_STORE) == null) {
                //  erase all
                cProp.clear();
            } else //  Save Cookie Parameter
            {
                cProp.setProperty(P_USERNAME, usr);
                cProp.setProperty(P_STORE, "Y");
                //  For test only
                cProp.setProperty(P_PASSWORD, pwd);
            }
        }
    }
    WebUtil.createResponse(request, response, this, cProp, doc, false);
}
Also used : HttpSession(javax.servlet.http.HttpSession) WebDoc(org.compiere.util.WebDoc) KeyNamePair(org.compiere.util.KeyNamePair) Login(org.compiere.util.Login) Properties(java.util.Properties) WebSessionCtx(org.compiere.util.WebSessionCtx) Principal(java.security.Principal)

Example 95 with KeyNamePair

use of org.compiere.util.KeyNamePair in project adempiere by adempiere.

the class WFieldUpdate method reply_Login2_Org.

//  reply_Login2_Client
/**
	 *  Login 2nd page Response - Field Org.
	 *  <p>
	 *  fill Warehouse
	 *  @param body document body
	 *  @param wsc web session context
	 *  @param formName
	 *  @param fieldValue
	 */
private static void reply_Login2_Org(body body, WebSessionCtx wsc, WWindowStatus ws, String formName, String fieldValue, String locationValue) {
    //  Formname
    String form = null;
    log.info("Location-Org: " + locationValue);
    //if (locationValue!=null)
    form = locationValue + WebEnv.TARGET_WINDOW + ".document." + formName + ".";
    //else
    //form = "top." + WebEnv.TARGET_WINDOW + ".document." + formName + ".";
    //log.info("form_org->"+form);
    StringBuffer script = new StringBuffer();
    //  Set Warehouse ----
    //  var A=top.WWindow.document.formName.selectName.options;
    script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
    //  A.length=0;                         //  resets options
    script.append("C.length=0; ");
    //  A[0]=new Option('text','value');    //  add new oprtion
    KeyNamePair org = new KeyNamePair(Integer.parseInt(fieldValue), fieldValue);
    Login login = new Login(wsc.ctx);
    String error = login.validateLogin(org);
    if (error != null && error.length() > 0) {
        //todo graceful dead
        log.severe(error);
        ws.mWindow = null;
        wsc.ctx = new Properties();
        return;
    }
    KeyNamePair[] whs = login.getWarehouses(org);
    if (whs != null) {
        for (int i = 0; i < whs.length; i++) {
            KeyNamePair p = whs[i];
            script.append("C[").append(i).append("]=new Option('");
            //  text
            script.append(p.getName());
            script.append("','");
            //  value
            script.append(p.getKey());
            script.append("'); ");
        }
    }
    //  add script
    body.addElement(new p().addElement(WLogin.P_WAREHOUSE + "="));
    body.addElement(new script(script.toString()));
//	log.trace(log.l6_Database, "Login2-Org - Script=" + script.toString());
}
Also used : org.apache.ecs.xhtml.p(org.apache.ecs.xhtml.p) KeyNamePair(org.compiere.util.KeyNamePair) Login(org.compiere.util.Login) Properties(java.util.Properties) org.apache.ecs.xhtml.script(org.apache.ecs.xhtml.script)

Aggregations

KeyNamePair (org.compiere.util.KeyNamePair)286 SQLException (java.sql.SQLException)66 ResultSet (java.sql.ResultSet)65 PreparedStatement (java.sql.PreparedStatement)62 BigDecimal (java.math.BigDecimal)46 ArrayList (java.util.ArrayList)38 ValueNamePair (org.compiere.util.ValueNamePair)36 Timestamp (java.sql.Timestamp)32 Vector (java.util.Vector)22 ListItem (org.adempiere.webui.component.ListItem)22 Login (org.compiere.util.Login)22 MProduct (org.compiere.model.MProduct)17 IDColumn (org.compiere.minigrid.IDColumn)13 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)12 AdempiereException (org.adempiere.exceptions.AdempiereException)10 MLookup (org.compiere.model.MLookup)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)9 org.apache.ecs.xhtml.p (org.apache.ecs.xhtml.p)8 org.apache.ecs.xhtml.script (org.apache.ecs.xhtml.script)8 MUOM (org.compiere.model.MUOM)7