Search in sources :

Example 46 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class VLookup method actionZoom.

//	actionBPartner
/**
	 *	Action - Zoom
	 *	@param selectedItem item
	 */
private void actionZoom(Object selectedItem) {
    if (m_lookup == null)
        return;
    //
    MQuery zoomQuery = m_lookup.getZoomQuery();
    Object value = getValue();
    if (value == null)
        value = selectedItem;
    //	If not already exist or exact value
    if (zoomQuery == null || value != null) {
        //	ColumnName might be changed in MTab.validateQuery
        zoomQuery = new MQuery();
        String keyTableName = null;
        String keyColumnName = null;
        //	Check if it is a Table Reference
        if (m_lookup != null && m_lookup instanceof MLookup) {
            int AD_Reference_ID = ((MLookup) m_lookup).getAD_Reference_Value_ID();
            if (DisplayType.List == m_lookup.getDisplayType()) {
                keyColumnName = "AD_Ref_List_ID";
                keyTableName = "AD_Ref_List";
                value = DB.getSQLValue(null, "SELECT AD_Ref_List_ID FROM AD_Ref_List WHERE AD_Reference_ID=? AND Value=?", AD_Reference_ID, value);
            } else {
                if (AD_Reference_ID != 0) {
                    String query = "SELECT kc.ColumnName, kt.TableName" + " FROM AD_Ref_Table rt" + " INNER JOIN AD_Column kc ON (rt.AD_Key=kc.AD_Column_ID)" + " INNER JOIN AD_Table kt ON (rt.AD_Table_ID=kt.AD_Table_ID)" + " WHERE rt.AD_Reference_ID=?";
                    PreparedStatement pstmt = null;
                    ResultSet rs = null;
                    try {
                        pstmt = DB.prepareStatement(query, null);
                        pstmt.setInt(1, AD_Reference_ID);
                        rs = pstmt.executeQuery();
                        if (rs.next()) {
                            keyColumnName = rs.getString(1);
                            keyTableName = rs.getString(2);
                        }
                    } catch (Exception e) {
                        log.log(Level.SEVERE, query, e);
                    } finally {
                        DB.close(rs, pstmt);
                        rs = null;
                        pstmt = null;
                    }
                }
            //	Table Reference
            }
        }
        if (keyColumnName != null && keyColumnName.length() != 0) {
            zoomQuery.addRestriction(keyColumnName, MQuery.EQUAL, value);
            zoomQuery.setZoomColumnName(keyColumnName);
            zoomQuery.setZoomTableName(keyTableName);
        } else {
            zoomQuery.addRestriction(m_columnName, MQuery.EQUAL, value);
            if (m_columnName.indexOf(".") > 0) {
                zoomQuery.setZoomColumnName(m_columnName.substring(m_columnName.indexOf(".") + 1));
                zoomQuery.setZoomTableName(m_columnName.substring(0, m_columnName.indexOf(".")));
            } else {
                zoomQuery.setZoomColumnName(m_columnName);
                //remove _ID to get table name
                zoomQuery.setZoomTableName(m_columnName.substring(0, m_columnName.length() - 3));
            }
        }
        zoomQuery.setZoomValue(value);
        //	guess
        zoomQuery.setRecordCount(1);
    }
    int AD_Window_ID = m_lookup.getZoom(zoomQuery);
    //
    log.info(m_columnName + " - AD_Window_ID=" + AD_Window_ID + " - Query=" + zoomQuery + " - Value=" + value);
    //
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    //
    AWindow frame = new AWindow(getGraphicsConfiguration());
    if (!frame.initWindow(AD_Window_ID, zoomQuery, false)) {
        setCursor(Cursor.getDefaultCursor());
        ValueNamePair pp = CLogger.retrieveError();
        String msg = pp == null ? "AccessTableNoView" : pp.getValue();
        ADialog.error(m_lookup.getWindowNo(), this, msg, pp == null ? "" : pp.getName());
    } else {
        AEnv.addToWindowManager(frame);
        if (Ini.isPropertyBool(Ini.P_OPEN_WINDOW_MAXIMIZED)) {
            AEnv.showMaximized(frame);
        } else {
            AEnv.showCenterScreen(frame);
        }
    }
    //  async window - not able to get feedback
    frame = null;
    //
    setCursor(Cursor.getDefaultCursor());
}
Also used : AWindow(org.compiere.apps.AWindow) MLookup(org.compiere.model.MLookup) ResultSet(java.sql.ResultSet) MQuery(org.compiere.model.MQuery) PreparedStatement(java.sql.PreparedStatement) ValueNamePair(org.compiere.util.ValueNamePair) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException)

Example 47 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class VLocator method actionZoom.

//  addActionListener
/**
	 *	Action - Zoom
	 */
private void actionZoom() {
    int AD_Window_ID = MTable.get(Env.getCtx(), MLocator.Table_ID).getAD_Window_ID();
    if (AD_Window_ID <= 0)
        //	hardcoded window Warehouse & Locators
        AD_Window_ID = 139;
    log.info("");
    //
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    AWindow frame = new AWindow();
    MQuery zoomQuery = new MQuery();
    zoomQuery.addRestriction(MLocator.COLUMNNAME_M_Locator_ID, MQuery.EQUAL, getValue());
    //	guess
    zoomQuery.setRecordCount(1);
    if (!frame.initWindow(AD_Window_ID, zoomQuery))
        return;
    AEnv.addToWindowManager(frame);
    AEnv.showCenterScreen(frame);
    frame = null;
    setCursor(Cursor.getDefaultCursor());
}
Also used : AWindow(org.compiere.apps.AWindow) MQuery(org.compiere.model.MQuery)

Example 48 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class WGraph method chartMouseClicked.

/**************************************************************************
	 * Paint Component
	 * 
	 * @param g
	 *            graphics
	 */
public void chartMouseClicked(int index) {
    GraphColumn bgc = list.get(index);
    if (null == bgc)
        return;
    MQuery query = bgc.getMQuery(builder.getMGoal());
    if (query != null)
        AEnv.zoom(query);
    else
        log.warning("Nothing to zoom to - " + bgc);
}
Also used : MQuery(org.compiere.model.MQuery) GraphColumn(org.adempiere.apps.graph.GraphColumn)

Example 49 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class WPAttributeDialog method cmd_zoom.

//	cmd_newEdit
/**
	 * 	Zoom M_Lot
	 */
private void cmd_zoom() {
    int M_Lot_ID = 0;
    ListItem pp = fieldLot.getSelectedItem();
    if (pp != null)
        M_Lot_ID = (Integer) pp.getValue();
    MQuery zoomQuery = new MQuery("M_Lot");
    zoomQuery.addRestriction("M_Lot_ID", MQuery.EQUAL, M_Lot_ID);
    log.info(zoomQuery.toString());
    //
    //	Lot
    int AD_Window_ID = MWindow.getWindow_ID("Lot");
    AEnv.zoom(AD_Window_ID, zoomQuery);
}
Also used : MQuery(org.compiere.model.MQuery) ListItem(org.adempiere.webui.component.ListItem)

Example 50 with MQuery

use of org.compiere.model.MQuery in project adempiere by adempiere.

the class WAccountDialog method initAccount.

//	jbInit
/**
	 *	Dyanmic Init.
	 *  When a row is selected, the editor values are set
	 *  (editors do not change grid)
	 *  @return true if initialized
	 */
private boolean initAccount() {
    m_AD_Client_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "AD_Client_ID");
    //	Get AcctSchema Info
    if (s_AcctSchema == null || s_AcctSchema.getC_AcctSchema_ID() != m_C_AcctSchema_ID)
        s_AcctSchema = new MAcctSchema(Env.getCtx(), m_C_AcctSchema_ID, null);
    log.config(s_AcctSchema.toString() + ", #" + s_AcctSchema.getAcctSchemaElements().length);
    Env.setContext(Env.getCtx(), m_WindowNo, "C_AcctSchema_ID", m_C_AcctSchema_ID);
    //  Model
    //	Maintain Account Combinations
    int AD_Window_ID = 153;
    GridWindowVO wVO = AEnv.getMWindowVO(m_WindowNo, AD_Window_ID, 0);
    if (wVO == null)
        return false;
    m_mWindow = new GridWindow(wVO);
    m_mTab = m_mWindow.getTab(0);
    // Make sure is the tab is loaded - teo_sarca [ 1659124 ]
    if (!m_mTab.isLoadComplete())
        m_mWindow.initTab(0);
    //  ParameterPanel restrictions
    m_mTab.getField("Alias").setDisplayLength(15);
    m_mTab.getField("Combination").setDisplayLength(15);
    //  Grid restrictions
    m_mTab.getField("AD_Client_ID").setDisplayed(false);
    m_mTab.getField("C_AcctSchema_ID").setDisplayed(false);
    m_mTab.getField("IsActive").setDisplayed(false);
    m_mTab.getField("IsFullyQualified").setDisplayed(false);
    //  don't show fields not being displayed in this environment
    for (int i = 0; i < m_mTab.getFieldCount(); i++) {
        GridField field = m_mTab.getField(i);
        if (//  check context
        !field.isDisplayed(true))
            field.setDisplayed(false);
    }
    //  GridController
    m_adTabPanel.init(null, m_WindowNo, m_mTab, null);
    //  Prepare Parameter
    parameterLayout.makeNoStrip();
    parameterLayout.setOddRowSclass("even");
    parameterLayout.setParent(parameterPanel);
    parameterLayout.setStyle("background-color: transparent;");
    m_rows = new Rows();
    m_rows.setParent(parameterLayout);
    int TabNo = 0;
    //	Alias
    if (s_AcctSchema.isHasAlias()) {
        GridField alias = m_mTab.getField("Alias");
        f_Alias = WebEditorFactory.getEditor(alias, false);
        addLine(alias, f_Alias, false);
    }
    //	Alias
    //	Combination
    GridField combination = m_mTab.getField("Combination");
    f_Combination = WebEditorFactory.getEditor(combination, false);
    addLine(combination, f_Combination, false);
    m_newRow = true;
    /**
		 *	Create Fields in Element Order
		 */
    MAcctSchemaElement[] elements = s_AcctSchema.getAcctSchemaElements();
    for (int i = 0; i < elements.length; i++) {
        MAcctSchemaElement ase = elements[i];
        String type = ase.getElementType();
        boolean isMandatory = ase.isMandatory();
        //
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Organization)) {
            GridField field = m_mTab.getField("AD_Org_ID");
            f_AD_Org_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_AD_Org_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Account)) {
            GridField field = m_mTab.getField("Account_ID");
            f_Account_ID = WebEditorFactory.getEditor(field, false);
            //	((VLookup)f_Account_ID).setWidth(400);
            addLine(field, f_Account_ID, isMandatory);
            f_Account_ID.addValueChangeListener(this);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
            GridField field = m_mTab.getField("C_SubAcct_ID");
            f_SubAcct_ID = WebEditorFactory.getEditor(field, false);
            //	((VLookup)f_SubAcct_ID).setWidth(400);
            addLine(field, f_SubAcct_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Product)) {
            GridField field = m_mTab.getField("M_Product_ID");
            f_M_Product_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_M_Product_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_BPartner)) {
            GridField field = m_mTab.getField("C_BPartner_ID");
            f_C_BPartner_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_BPartner_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Campaign)) {
            GridField field = m_mTab.getField("C_Campaign_ID");
            f_C_Campaign_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_Campaign_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationFrom)) {
            GridField field = m_mTab.getField("C_LocFrom_ID");
            f_C_LocFrom_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_LocFrom_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_LocationTo)) {
            GridField field = m_mTab.getField("C_LocTo_ID");
            f_C_LocTo_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_LocTo_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Project)) {
            GridField field = m_mTab.getField("C_Project_ID");
            f_C_Project_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_Project_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SalesRegion)) {
            GridField field = m_mTab.getField("C_SalesRegion_ID");
            f_C_SalesRegion_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_SalesRegion_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_OrgTrx)) {
            GridField field = m_mTab.getField("AD_OrgTrx_ID");
            f_AD_OrgTrx_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_AD_OrgTrx_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_Activity)) {
            GridField field = m_mTab.getField("C_Activity_ID");
            f_C_Activity_ID = WebEditorFactory.getEditor(field, false);
            addLine(field, f_C_Activity_ID, isMandatory);
        } else //	User1
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList1)) {
            GridField field = m_mTab.getField("User1_ID");
            f_User1_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User1_ID.setLabel(ase.getName());				
            addLine(field, f_User1_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
            GridField field = m_mTab.getField("User2_ID");
            f_User2_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User2_ID.setLabel(ase.getName());				
            addLine(field, f_User2_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
            GridField field = m_mTab.getField("User3_ID");
            f_User3_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User3_ID.setLabel(ase.getName());
            addLine(field, f_User3_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
            GridField field = m_mTab.getField("User4_ID");
            f_User4_ID = WebEditorFactory.getEditor(field, false);
            // Change the label from the default to the user defined name
            //f_User4_ID.setLabel(ase.getName());
            addLine(field, f_User4_ID, isMandatory);
        }
    }
    //	Create Fields in Element Order
    //	Add description
    m_newRow = true;
    Row row = new Row();
    f_Description.setStyle("font-decoration: italic;");
    row.appendChild(f_Description);
    row.setSpans("4");
    row.setStyle("background-color: transparent;");
    m_rows.appendChild(row);
    //	Finish
    m_query = new MQuery();
    m_query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
    m_query.addRestriction("IsFullyQualified", MQuery.EQUAL, "Y");
    if (m_mAccount.C_ValidCombination_ID == 0)
        m_mTab.setQuery(MQuery.getEqualQuery("1", "2"));
    else {
        MQuery query = new MQuery();
        query.addRestriction("C_AcctSchema_ID", MQuery.EQUAL, m_C_AcctSchema_ID);
        query.addRestriction("C_ValidCombination_ID", MQuery.EQUAL, m_mAccount.C_ValidCombination_ID);
        m_mTab.setQuery(query);
    }
    m_mTab.query(false);
    m_adTabPanel.getGridTab().addDataStatusListener(this);
    m_adTabPanel.activate(true);
    if (!m_adTabPanel.isGridView())
        m_adTabPanel.switchRowPresentation();
    statusBar.setStatusLine(s_AcctSchema.toString());
    statusBar.setStatusDB("?");
    //	Initial value
    if (m_mAccount.C_ValidCombination_ID != 0)
        m_mTab.navigate(0);
    log.config("fini");
    return true;
}
Also used : MAcctSchema(org.compiere.model.MAcctSchema) GridWindow(org.compiere.model.GridWindow) GridWindowVO(org.compiere.model.GridWindowVO) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) Row(org.adempiere.webui.component.Row) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement) Rows(org.adempiere.webui.component.Rows)

Aggregations

MQuery (org.compiere.model.MQuery)109 PrintInfo (org.compiere.model.PrintInfo)19 GridField (org.compiere.model.GridField)15 MPrintFormat (org.compiere.print.MPrintFormat)14 ReportEngine (org.compiere.print.ReportEngine)12 Point (java.awt.Point)11 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)9 GridWindowVO (org.compiere.model.GridWindowVO)9 SQLException (java.sql.SQLException)8 GridTab (org.compiere.model.GridTab)8 GridWindow (org.compiere.model.GridWindow)7 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 AWindow (org.compiere.apps.AWindow)6 File (java.io.File)5 IOException (java.io.IOException)5 Language (org.compiere.util.Language)4 AdempiereException (org.adempiere.exceptions.AdempiereException)3 MClient (org.compiere.model.MClient)3 MLookup (org.compiere.model.MLookup)3