Search in sources :

Example 26 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WFileImport method cmd_loadFile.

/**************************************************************************
	 *	Load File
	 */
private void cmd_loadFile() {
    Media media = null;
    media = Fileupload.get();
    if (media == null)
        return;
    if (media.isBinary()) {
        m_file_istream = media.getStreamData();
    } else {
        ListItem listitem = fCharset.getSelectedItem();
        if (listitem == null) {
            m_file_istream = new ReaderInputStream(media.getReaderData());
        } else {
            Charset charset = (Charset) listitem.getValue();
            m_file_istream = new ReaderInputStream(media.getReaderData(), charset.name());
        }
    }
    log.config(media.getName());
    bFile.setLabel(media.getName());
    cmd_reloadFile();
}
Also used : ReaderInputStream(org.adempiere.webui.util.ReaderInputStream) Media(org.zkoss.util.media.Media) Charset(java.nio.charset.Charset) ListItem(org.adempiere.webui.component.ListItem)

Example 27 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WFileImport method dynInit.

/**
	 *	Dynamic Init
	 */
private void dynInit() {
    //	Load Formats
    pickFormat.appendItem(s_none, s_none);
    String sql = MRole.getDefault().addAccessSQL("SELECT Name FROM AD_ImpFormat", "AD_ImpFormat", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
    try {
        PreparedStatement pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) pickFormat.appendItem(rs.getString(1), rs.getString(1));
        rs.close();
        pstmt.close();
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    }
    pickFormat.setSelectedIndex(0);
    pickFormat.addEventListener(Events.ON_SELECT, this);
    Charset charset = Ini.getCharset();
    for (int i = 0; i < fCharset.getItemCount(); i++) {
        ListItem listitem = fCharset.getItemAtIndex(i);
        Charset compare = (Charset) listitem.getValue();
        if (charset == compare) {
            fCharset.setSelectedIndex(i);
            break;
        }
    }
    fCharset.addEventListener(Events.ON_SELECT, this);
    confirmPanel.setEnabled("Ok", false);
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Charset(java.nio.charset.Charset) PreparedStatement(java.sql.PreparedStatement) ListItem(org.adempiere.webui.component.ListItem)

Example 28 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WFileImport method cmd_reloadFile.

/**
	 * Reload/Load file
	 */
private void cmd_reloadFile() {
    if (m_file_istream == null)
        return;
    m_data.clear();
    rawData.setText("");
    try {
        //  see NaturalAccountMap
        ListItem listitem = fCharset.getSelectedItem();
        Charset charset = null;
        if (listitem == null)
            return;
        charset = (Charset) listitem.getValue();
        BufferedReader in = new BufferedReader(new InputStreamReader(m_file_istream, charset), 10240);
        //	not safe see p108 Network pgm
        String s = null;
        String concat = "";
        while ((s = in.readLine()) != null) {
            m_data.add(s);
            concat += s;
            concat += "\n";
            if (m_data.size() < MAX_LOADED_LINES) {
                rawData.setValue(concat);
            }
        }
        in.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "", e);
        bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile"));
    }
    //	second line as first may be heading
    int index = 1;
    if (m_data.size() == 1)
        index = 0;
    int length = 0;
    if (m_data.size() > 0)
        length = m_data.get(index).toString().length();
    info.setValue(Msg.getMsg(Env.getCtx(), "Records") + "=" + m_data.size() + ", " + Msg.getMsg(Env.getCtx(), "Length") + "=" + length + "   ");
    //setCursor (Cursor.getDefaultCursor());
    log.config("Records=" + m_data.size() + ", Length=" + length);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Charset(java.nio.charset.Charset) ListItem(org.adempiere.webui.component.ListItem) SQLException(java.sql.SQLException)

Example 29 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WBPartner method loadBPartner.

//	getGreeting
/**
	 *	Load BPartner
	 *  @param C_BPartner_ID - existing BPartner or 0 for new
	 * 	@return true if loaded
	 */
public boolean loadBPartner(int C_BPartner_ID) {
    log.config("C_BPartner_ID=" + C_BPartner_ID);
    //  New bpartner
    if (C_BPartner_ID == 0) {
        m_partner = null;
        m_pLocation = null;
        m_user = null;
        return true;
    }
    m_partner = new MBPartner(Env.getCtx(), C_BPartner_ID, null);
    if (m_partner.get_ID() == 0) {
        FDialog.error(m_WindowNo, this, "BPartnerNotFound");
        return false;
    }
    //	BPartner - Load values
    fValue.setText(m_partner.getValue());
    KeyNamePair keynamepair = getGreeting(m_partner.getC_Greeting_ID());
    for (int i = 0; i < fGreetingBP.getItemCount(); i++) {
        ListItem listitem = fGreetingBP.getItemAtIndex(i);
        KeyNamePair compare = (KeyNamePair) listitem.getValue();
        if (compare == keynamepair) {
            fGreetingBP.setSelectedIndex(i);
            break;
        }
    }
    fName.setText(m_partner.getName());
    fName2.setText(m_partner.getName2());
    fTaxId.setText(m_partner.getTaxID());
    //	Contact - Load values
    m_pLocation = m_partner.getLocation(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_BPartner_Location_ID"));
    if (m_pLocation != null) {
        int location = m_pLocation.getC_Location_ID();
        fAddress.setValue(new Integer(location));
        fPhone.setText(m_pLocation.getPhone());
        fPhone2.setText(m_pLocation.getPhone2());
        fFax.setText(m_pLocation.getFax());
    }
    //	User - Load values
    m_user = m_partner.getContact(Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_User_ID"));
    if (m_user != null) {
        keynamepair = getGreeting(m_user.getC_Greeting_ID());
        for (int i = 0; i < fGreetingC.getItemCount(); i++) {
            ListItem listitem = fGreetingC.getItemAtIndex(i);
            KeyNamePair compare = (KeyNamePair) listitem.getValue();
            if (compare == keynamepair) {
                fGreetingC.setSelectedIndex(i);
                break;
            }
        }
        fContact.setText(m_user.getName());
        fTitle.setText(m_user.getTitle());
        fEMail.setText(m_user.getEMail());
        fPhone.setText(m_user.getPhone());
        fPhone2.setText(m_user.getPhone2());
        fFax.setText(m_user.getFax());
    }
    return true;
}
Also used : MBPartner(org.compiere.model.MBPartner) KeyNamePair(org.compiere.util.KeyNamePair) ListItem(org.adempiere.webui.component.ListItem)

Example 30 with ListItem

use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.

the class WBPartner method actionSave.

//	loadBPartner
/**
	 *	Save.
	 *	Checks mandatory fields and saves Partner, Contact and Location
	 * 	@return true if saved
	 */
private boolean actionSave() {
    log.config("");
    //	Check Mandatory fields
    if (fName.getText().equals("")) {
        throw new WrongValueException(fName, Msg.translate(Env.getCtx(), "FillMandatory"));
    }
    if (fAddress.getC_Location_ID() == 0) {
        throw new WrongValueException(fAddress.getComponent(), Msg.translate(Env.getCtx(), "FillMandatory"));
    }
    if (m_partner == null) {
        int AD_Client_ID = Env.getAD_Client_ID(Env.getCtx());
        m_partner = MBPartner.getTemplate(Env.getCtx(), AD_Client_ID);
        // Elaine 2009/07/03
        m_partner.setAD_Org_ID(Env.getAD_Org_ID(Env.getCtx()));
        boolean isSOTrx = !"N".equals(Env.getContext(Env.getCtx(), m_WindowNo, "IsSOTrx"));
        m_partner.setIsCustomer(isSOTrx);
        m_partner.setIsVendor(!isSOTrx);
    }
    //	Check Value
    String value = fValue.getText();
    if (value == null || value.length() == 0) {
        //	get Table Document No
        value = DB.getDocumentNo(Env.getAD_Client_ID(Env.getCtx()), "C_BPartner", null);
        fValue.setText(value);
    }
    m_partner.setValue(fValue.getText());
    m_partner.setName(fName.getText());
    m_partner.setName2(fName2.getText());
    m_partner.setTaxID(fTaxId.getText());
    ListItem listitem = fGreetingBP.getSelectedItem();
    KeyNamePair p = listitem != null ? (KeyNamePair) listitem.getValue() : null;
    if (p != null && p.getKey() > 0)
        m_partner.setC_Greeting_ID(p.getKey());
    else
        m_partner.setC_Greeting_ID(0);
    if (m_partner.save())
        log.fine("C_BPartner_ID=" + m_partner.getC_BPartner_ID());
    else
        FDialog.error(m_WindowNo, this, "BPartnerNotSaved");
    if (m_pLocation == null)
        m_pLocation = new MBPartnerLocation(m_partner);
    m_pLocation.setC_Location_ID(fAddress.getC_Location_ID());
    m_pLocation.setEMail(fEMail.getText());
    m_pLocation.setPhone(fPhone.getText());
    m_pLocation.setPhone2(fPhone2.getText());
    m_pLocation.setFax(fFax.getText());
    if (m_pLocation.save())
        log.fine("C_BPartner_Location_ID=" + m_pLocation.getC_BPartner_Location_ID());
    else
        FDialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "C_BPartner_Location_ID"));
    //	***** Business Partner - User *****
    String contact = fContact.getText();
    String email = fEMail.getText();
    if (m_user == null && (contact.length() > 0 || email.length() > 0))
        m_user = new MUser(m_partner);
    if (m_user != null) {
        if (contact.length() == 0)
            contact = fName.getText();
        m_user.setName(contact);
        m_user.setEMail(email);
        m_user.setTitle(fTitle.getText());
        listitem = fGreetingC.getSelectedItem();
        p = listitem != null ? (KeyNamePair) listitem.getValue() : null;
        if (p != null && p.getKey() > 0)
            m_user.setC_Greeting_ID(p.getKey());
        else
            m_user.setC_Greeting_ID(0);
        m_user.setPhone(fPhone.getText());
        m_user.setPhone2(fPhone2.getText());
        m_user.setFax(fFax.getText());
        if (m_user.save())
            log.fine("AD_User_ID=" + m_user.getAD_User_ID());
        else
            FDialog.error(m_WindowNo, this, "BPartnerNotSaved", Msg.translate(Env.getCtx(), "AD_User_ID"));
    }
    return true;
}
Also used : ListItem(org.adempiere.webui.component.ListItem) KeyNamePair(org.compiere.util.KeyNamePair) MUser(org.compiere.model.MUser) WrongValueException(org.zkoss.zk.ui.WrongValueException) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Aggregations

ListItem (org.adempiere.webui.component.ListItem)52 KeyNamePair (org.compiere.util.KeyNamePair)22 Timestamp (java.sql.Timestamp)8 Listbox (org.adempiere.webui.component.Listbox)8 SQLException (java.sql.SQLException)7 BigDecimal (java.math.BigDecimal)6 Label (org.adempiere.webui.component.Label)5 ResultSet (java.sql.ResultSet)4 Date (java.util.Date)4 MLocator (org.compiere.model.MLocator)4 ValueNamePair (org.compiere.util.ValueNamePair)4 Charset (java.nio.charset.Charset)3 PreparedStatement (java.sql.PreparedStatement)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 NumberBox (org.adempiere.webui.component.NumberBox)3 Row (org.adempiere.webui.component.Row)3 Textbox (org.adempiere.webui.component.Textbox)3 MAttributeValue (org.compiere.model.MAttributeValue)3 BufferedImage (java.awt.image.BufferedImage)2