Search in sources :

Example 6 with GridController

use of org.compiere.grid.GridController in project adempiere by adempiere.

the class APanel 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())) {
            m_mWorkbench.getMWindow(0).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 = m_mWorkbench.getMWindow(0).getTab(index);
                    if (pTab.getTabLevel() < currentTab.getTabLevel()) {
                        m_mWorkbench.getMWindow(0).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 = m_mWorkbench.getMWindow(0).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);
                    GridController gc = (GridController) tabPanel.getComponentAt(entry.getKey());
                    gc.activate();
                    gc.query(false, 0, 0);
                }
                MQuery targetQuery = new MQuery(gTab.getAD_Table_ID());
                targetQuery.addRestriction(gTab.getLinkColumnName(), "=", parentId);
                gTab.setQuery(targetQuery);
                GridController gc = null;
                if (!includedMap.containsKey(gTab.getAD_Tab_ID())) {
                    int target = tabPanel.findTabindex(gTab);
                    gc = (GridController) tabPanel.getComponentAt(target);
                } else {
                    GridController parent = includedMap.get(gTab.getAD_Tab_ID());
                    gc = parent.findChild(gTab);
                }
                gc.activate();
                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())) {
                            tabPanel.setSelectedIndex(tabPanel.findTabindex(gTab));
                        } else {
                            GridController parent = includedMap.get(gTab.getAD_Tab_ID());
                            int pindex = tabPanel.findTabindex(parent.getMTab());
                            if (pindex >= 0)
                                tabPanel.setSelectedIndex(pindex);
                        }
                        gTab.navigate(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) Point(java.awt.Point) GridTab(org.compiere.model.GridTab) GridController(org.compiere.grid.GridController) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

GridController (org.compiere.grid.GridController)6 Point (java.awt.Point)3 GridField (org.compiere.model.GridField)3 MQuery (org.compiere.model.MQuery)3 Component (java.awt.Component)2 Dimension (java.awt.Dimension)2 VTabbedPane (org.compiere.grid.VTabbedPane)2 GridTab (org.compiere.model.GridTab)2 GridWindow (org.compiere.model.GridWindow)2 GridWindowVO (org.compiere.model.GridWindowVO)2 Insets (java.awt.Insets)1 FocusEvent (java.awt.event.FocusEvent)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 JTabbedPane (javax.swing.JTabbedPane)1 APanelTab (org.compiere.grid.APanelTab)1 GridSynchronizer (org.compiere.grid.GridSynchronizer)1 VSortTab (org.compiere.grid.VSortTab)1 GridFieldVO (org.compiere.model.GridFieldVO)1