Search in sources :

Example 6 with GridTable

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

the class AbstractADWindowPanel method doZoomToDetail.

private boolean doZoomToDetail(GridTab gTab, MQuery query, int tabIndex) {
    GridField[] fields = gTab.getFields();
    for (GridField field : fields) {
        if (field.getColumnName().equalsIgnoreCase(query.getZoomColumnName())) {
            gridWindow.initTab(tabIndex);
            int parentId = DB.getSQLValue(null, "SELECT " + gTab.getLinkColumnName() + " FROM " + gTab.getTableName() + " WHERE " + query.getWhereClause());
            if (parentId > 0) {
                Map<Integer, Object[]> parentMap = new TreeMap<Integer, Object[]>();
                int index = tabIndex;
                int oldpid = parentId;
                GridTab currentTab = gTab;
                while (index > 0) {
                    index--;
                    GridTab pTab = gridWindow.getTab(index);
                    if (pTab.getTabLevel() < currentTab.getTabLevel()) {
                        gridWindow.initTab(index);
                        if (index > 0) {
                            if (pTab.getLinkColumnName() != null && pTab.getLinkColumnName().trim().length() > 0) {
                                int pid = DB.getSQLValue(null, "SELECT " + pTab.getLinkColumnName() + " FROM " + pTab.getTableName() + " WHERE " + currentTab.getLinkColumnName() + " = ?", oldpid);
                                if (pid > 0) {
                                    parentMap.put(index, new Object[] { currentTab.getLinkColumnName(), oldpid });
                                    oldpid = pid;
                                    currentTab = pTab;
                                } else {
                                    parentMap.clear();
                                    break;
                                }
                            }
                        } else {
                            parentMap.put(index, new Object[] { currentTab.getLinkColumnName(), oldpid });
                        }
                    }
                }
                for (Map.Entry<Integer, Object[]> entry : parentMap.entrySet()) {
                    GridTab pTab = gridWindow.getTab(entry.getKey());
                    Object[] value = entry.getValue();
                    MQuery pquery = new MQuery(pTab.getAD_Table_ID());
                    pquery.addRestriction((String) value[0], "=", value[1]);
                    pTab.setQuery(pquery);
                    IADTabPanel tp = adTab.findADTabpanel(pTab);
                    tp.createUI();
                    tp.query();
                }
                MQuery targetQuery = new MQuery(gTab.getAD_Table_ID());
                targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentId);
                gTab.setQuery(targetQuery);
                IADTabPanel gc = null;
                if (!includedMap.containsKey(gTab.getAD_Tab_ID())) {
                    gc = adTab.findADTabpanel(gTab);
                } else {
                    ADTabPanel parent = (ADTabPanel) includedMap.get(gTab.getAD_Tab_ID());
                    gc = parent.findEmbeddedPanel(gTab);
                }
                gc.createUI();
                gc.query(false, 0, 0);
                GridTable table = gTab.getTableModel();
                int count = table.getRowCount();
                for (int i = 0; i < count; i++) {
                    int id = table.getKeyID(i);
                    if (id == ((Integer) query.getZoomValue()).intValue()) {
                        if (!includedMap.containsKey(gTab.getAD_Tab_ID())) {
                            setActiveTab(gridWindow.getTabIndex(gTab));
                        } else {
                            IADTabPanel parent = includedMap.get(gTab.getAD_Tab_ID());
                            int pindex = gridWindow.getTabIndex(parent.getGridTab());
                            if (pindex >= 0)
                                setActiveTab(pindex);
                        }
                        gTab.setCurrentRow(i);
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : GridTable(org.compiere.model.GridTable) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) TreeMap(java.util.TreeMap) GridTab(org.compiere.model.GridTab) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

GridTable (org.compiere.model.GridTable)6 GridField (org.compiere.model.GridField)5 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 GridTab (org.compiere.model.GridTab)2 MQuery (org.compiere.model.MQuery)2 Trx (org.compiere.util.Trx)2 Point (java.awt.Point)1 StringSelection (java.awt.datatransfer.StringSelection)1 PropertyVetoException (java.beans.PropertyVetoException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 TableModel (javax.swing.table.TableModel)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 WEditor (org.adempiere.webui.editor.WEditor)1 GridController (org.compiere.grid.GridController)1 VEditor (org.compiere.grid.ed.VEditor)1 Lookup (org.compiere.model.Lookup)1