Search in sources :

Example 1 with GridController

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

the class VAccountDialog 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_gridController = new GridController();
    m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
    m_gridController.setPreferredSize(new Dimension(300, 100));
    panel.add(m_gridController, BorderLayout.CENTER);
    //  Prepare Parameter
    m_gbc.anchor = GridBagConstraints.NORTHWEST;
    //	line
    m_gbc.gridy = 0;
    m_gbc.gridx = 0;
    m_gbc.gridwidth = 1;
    m_gbc.insets = m_fieldInsets;
    m_gbc.fill = GridBagConstraints.HORIZONTAL;
    m_gbc.weightx = 0;
    m_gbc.weighty = 0;
    int TabNo = 0;
    //	Alias
    if (s_AcctSchema.isHasAlias()) {
        GridField alias = m_mTab.getField("Alias");
        f_Alias = VEditorFactory.getEditor(m_mTab, alias, false);
        addLine(alias, f_Alias, false);
    }
    //	Alias
    //	Combination
    GridField combination = m_mTab.getField("Combination");
    f_Combination = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, field, false);
            //	((VLookup)f_Account_ID).setWidth(400);
            addLine(field, f_Account_ID, isMandatory);
            f_Account_ID.addVetoableChangeListener(this);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_SubAccount)) {
            GridField field = m_mTab.getField("C_SubAcct_ID");
            f_SubAcct_ID = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, 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 = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User1_ID.getField().getVO();
            newFieldVO.Header = f_User1_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User1_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList2)) {
            GridField field = m_mTab.getField("User2_ID");
            f_User2_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User2_ID.getField().getVO();
            newFieldVO.Header = f_User2_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User2_ID, isMandatory);
        } else //	User3
        if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList3)) {
            GridField field = m_mTab.getField("User3_ID");
            f_User3_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User3_ID.getField().getVO();
            newFieldVO.Header = f_User3_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User3_ID, isMandatory);
        } else if (type.equals(MAcctSchemaElement.ELEMENTTYPE_UserList4)) {
            GridField field = m_mTab.getField("User4_ID");
            f_User4_ID = VEditorFactory.getEditor(m_mTab, field, false);
            GridFieldVO newFieldVO = f_User4_ID.getField().getVO();
            newFieldVO.Header = f_User4_ID.getName();
            field = new GridField(newFieldVO);
            addLine(field, f_User4_ID, isMandatory);
        }
    }
    //	Create Fields in Element Order
    //	Add description
    m_newRow = true;
    m_gbc.gridy = m_line++;
    m_gbc.gridx = 0;
    m_gbc.gridwidth = 4;
    // 	top,left,bottom,right
    m_gbc.insets = new Insets(5, 15, 2, 0);
    m_gbc.fill = GridBagConstraints.HORIZONTAL;
    f_Description.setFont(f_Description.getFont().deriveFont(Font.ITALIC));
    parameterPanel.add(f_Description, m_gbc);
    //	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_gridController.getTable().addMouseListener(new VAccountDialog_mouseAdapter(this));
    m_gridController.addDataStatusListener(this);
    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 : Insets(java.awt.Insets) GridWindow(org.compiere.model.GridWindow) GridFieldVO(org.compiere.model.GridFieldVO) MQuery(org.compiere.model.MQuery) GridField(org.compiere.model.GridField) Dimension(java.awt.Dimension) MAcctSchema(org.compiere.model.MAcctSchema) GridWindowVO(org.compiere.model.GridWindowVO) GridController(org.compiere.grid.GridController) MAcctSchemaElement(org.compiere.model.MAcctSchemaElement)

Example 2 with GridController

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

the class APanel method initPanel.

/**************************************************************************
	 *	Dynamic Panel Initialization - either single window or workbench.
	 *  <pre>
	 *  either
	 *  - Workbench tabPanel    (VTabbedPane)
	 *      - Tab               (GridController)
	 *  or
	 *  - Workbench tabPanel    (VTabbedPane)
	 *      - Window            (VTabbedPane)
	 *          - Tab           (GridController)
	 *  </pre>
	 *  tabPanel
	 *  @param AD_Workbench_ID  if > 0 this is a workbench, AD_Window_ID ignored
	 *  @param AD_Window_ID     if not a workbench, Window ID
	 *  @param query			if not a Workbench, Zoom Query - additional SQL where clause
	 *  @return true if Panel is initialized successfully
	 */
public boolean initPanel(int AD_Workbench_ID, int AD_Window_ID, MQuery query) {
    log.info("WB=" + AD_Workbench_ID + ", Win=" + AD_Window_ID + ", Query=" + query);
    this.setName("APanel" + AD_Window_ID);
    //  Single Window
    if (AD_Workbench_ID == 0)
        m_mWorkbench = new GridWorkbench(m_ctx, AD_Window_ID);
    else //  Workbench
    {
        //	m_mWorkbench = new MWorkbench(m_ctx);
        //	if (!m_mWorkbench.initWorkbench (AD_Workbench_ID))
        //	{
        //		log.log(Level.SEVERE, "APanel.initWindow - No Workbench Model");
        //		return false;
        //	}
        //	tabPanel.setWorkbench(true);
        //	tabPanel.addChangeListener(this);
        log.warning("Workbench Not implemented yet [" + this + "]");
        loadError = "Workbench Not implemented yet";
        return false;
    }
    Dimension windowSize = m_mWorkbench.getWindowSize();
    MQuery detailQuery = null;
    /**
		 *  WorkBench Loop
		 */
    for (int wb = 0; wb < m_mWorkbench.getWindowCount(); wb++) {
        //  Get/set WindowNo
        //  Timing: ca. 1.5 sec
        m_curWindowNo = Env.createWindowNo(this);
        m_mWorkbench.setWindowNo(wb, m_curWindowNo);
        //  Set AutoCommit for this Window
        Env.setAutoCommit(m_ctx, m_curWindowNo, Env.isAutoCommit(m_ctx));
        boolean autoNew = Env.isAutoNew(m_ctx);
        Env.setAutoNew(m_ctx, m_curWindowNo, autoNew);
        //  Workbench Window
        VTabbedPane window = null;
        //  just one window
        if (m_mWorkbench.getWindowCount() == 1) {
            window = tabPanel;
            window.setWorkbench(false);
        } else {
            VTabbedPane tp = new VTabbedPane(false);
            window = tp;
        }
        //  Window Init
        window.addChangeListener(this);
        /**
			 *  Init Model
			 */
        int wbType = m_mWorkbench.getWindowType(wb);
        /**
			 *  Window
			 */
        if (wbType == GridWorkbench.TYPE_WINDOW) {
            includedMap = new HashMap<Integer, GridController>(4);
            //
            GridWindowVO wVO = AEnv.getMWindowVO(m_curWindowNo, m_mWorkbench.getWindowID(wb), 0);
            if (wVO == null) {
                log.warning("AccessTableNoView for [" + this + "]");
                loadError = "AccessTableNoView";
                return false;
            }
            //  Timing: ca. 0.3-1 sec
            GridWindow mWindow = new GridWindow(wVO, true);
            //	Set SO/AutoNew for Window
            Env.setContext(m_ctx, m_curWindowNo, "IsSOTrx", mWindow.isSOTrx());
            if (!autoNew && mWindow.isTransaction())
                Env.setAutoNew(m_ctx, m_curWindowNo, true);
            m_mWorkbench.setMWindow(wb, mWindow);
            if (wb == 0)
                //	default = only current
                m_onlyCurrentRows = mWindow.isTransaction();
            if (windowSize == null)
                windowSize = mWindow.getWindowSize();
            /**
				 *  Window Tabs
				 */
            int tabSize = mWindow.getTabCount();
            //	Zoom Query
            boolean goSingleRow = query != null;
            for (int tab = 0; tab < tabSize; tab++) {
                boolean included = false;
                //  MTab
                if (tab == 0)
                    mWindow.initTab(0);
                GridTab gTab = mWindow.getTab(tab);
                Env.setContext(m_ctx, m_curWindowNo, tab, GridTab.CTX_TabLevel, Integer.toString(gTab.getTabLevel()));
                //  Query first tab
                if (tab == 0) {
                    //  initial user query for single workbench tab
                    if (m_mWorkbench.getWindowCount() == 1) {
                        if (query != null && query.getZoomTableName() != null && query.getZoomColumnName() != null && query.getZoomValue() instanceof Integer && (Integer) query.getZoomValue() > 0) {
                            if (!query.getZoomTableName().equalsIgnoreCase(gTab.getTableName())) {
                                detailQuery = query;
                                query = new MQuery();
                                query.addRestriction("1=2");
                            }
                        }
                        //Goodwill
                        isCancel = false;
                        query = initialQuery(query, gTab);
                        if (isCancel)
                            //Cancel opening window
                            return false;
                        if (query != null && query.getRecordCount() <= 1)
                            goSingleRow = true;
                    } else if (wb != 0) //  workbench dynamic query for dependent windows
                    {
                        query = m_mWorkbench.getQuery();
                    }
                    //	Set initial Query on first tab
                    if (query != null) {
                        //  Query might involve history
                        m_onlyCurrentRows = false;
                        gTab.setQuery(query);
                    }
                    if (wb == 0)
                        m_curTab = gTab;
                }
                //	query on first tab
                Component tabElement = null;
                //  GridController
                if (gTab.isSortTab()) {
                    VSortTab st = new VSortTab(m_curWindowNo, gTab.getAD_Table_ID(), gTab.getAD_ColumnSortOrder_ID(), gTab.getAD_ColumnSortYesNo_ID());
                    st.setTabLevel(gTab.getTabLevel());
                    tabElement = st;
                } else //	normal tab
                {
                    //  Timing: ca. .1 sec
                    GridController gc = new GridController();
                    CompiereColor cc = mWindow.getColor();
                    if (cc != null)
                        //  set color on Window level
                        gc.setBackgroundColor(cc);
                    //  will set color on Tab level
                    gc.initGrid(gTab, false, m_curWindowNo, this, mWindow, (tab != 0));
                    //  Timing: ca. 6-7 sec for first .2 for next
                    gc.addDataStatusListener(this);
                    //  register Escape Key
                    gc.registerESCAction(aIgnore);
                    //	Set First Tab
                    if (wb == 0 && tab == 0) {
                        m_curGC = gc;
                        //  Screen Sizing
                        Dimension size = gc.getPreferredSize();
                        size.width += 4;
                        size.height += 4;
                        gc.setPreferredSize(size);
                    }
                    tabElement = gc;
                    //	If we have a zoom query, switch to single row
                    if (tab == 0 && goSingleRow)
                        gc.switchSingleRow();
                    // FR [ 1757088 ]
                    GridField[] fields = gc.getMTab().getFields();
                    int m_tab_id = 0;
                    for (int f = 0; f < fields.length; f++) {
                        m_tab_id = fields[f].getIncluded_Tab_ID();
                        if (m_tab_id != 0) {
                            includedMap.put(m_tab_id, gc);
                        }
                    }
                    //	Is this tab included?
                    if (includedMap.size() > 0) {
                        GridController parent = (GridController) includedMap.get(new Integer(gTab.getAD_Tab_ID()));
                        if (parent != null) {
                            // FR [ 1757088 ]
                            gc.removeDataStatusListener(this);
                            GridSynchronizer synchronizer = new GridSynchronizer(mWindow, parent, gc);
                            if (parent == m_curGC)
                                synchronizer.activateChild();
                            included = parent.includeTab(gc, this, synchronizer);
                        }
                    }
                    initSwitchLineAction();
                }
                if (//  Add to TabbedPane
                !included) {
                    StringBuffer tabName = new StringBuffer();
                    tabName.append("<html>");
                    if (gTab.isReadOnly())
                        tabName.append("<i>");
                    int pos = gTab.getName().indexOf(" ");
                    if (pos == -1)
                        tabName.append(gTab.getName()).append("<br>&nbsp;");
                    else {
                        tabName.append(gTab.getName().substring(0, pos)).append("<br>").append(gTab.getName().substring(pos + 1));
                    }
                    if (gTab.isReadOnly())
                        tabName.append("</i>");
                    tabName.append("</html>");
                    //	Add Tab - sets ALT-<number> and Shift-ALT-<x>
                    window.addTab(tabName.toString(), gTab, tabElement);
                }
            }
        //  Tab Loop
        //  Tab background
        //	window.setBackgroundColor(new AdempiereColor(Color.magenta, Color.green));
        }
        //  Single Workbench Window Tab
        if (m_mWorkbench.getWindowCount() == 1) {
            window.setToolTipText(m_mWorkbench.getDescription(wb));
        } else //  Add Workbench Window Tab
        {
            tabPanel.addTab(m_mWorkbench.getName(wb), m_mWorkbench.getIcon(wb), window, m_mWorkbench.getDescription(wb));
        }
        //  Used for Env.getHeader
        Env.setContext(m_ctx, m_curWindowNo, "WindowName", m_mWorkbench.getName(wb));
    }
    //  Workbench Loop
    //  stateChanged (<->) triggered
    toolBar.setName(getTitle());
    m_curTab.getTableModel().setChanged(false);
    //	Set Detail Button
    aDetail.setEnabled(0 != m_curWinTab.getTabCount() - 1);
    //	Enable/Disable Tabs dynamically
    if (m_curWinTab instanceof VTabbedPane)
        ((VTabbedPane) m_curWinTab).evaluate(null);
    //	Size
    if (windowSize != null)
        setPreferredSize(windowSize);
    else
        revalidate();
    if (detailQuery != null && zoomToDetailTab(detailQuery)) {
        return true;
    }
    Dimension size = getPreferredSize();
    log.info("fini - " + size);
    m_curWinTab.requestFocusInWindow();
    return true;
}
Also used : GridWindow(org.compiere.model.GridWindow) MQuery(org.compiere.model.MQuery) Dimension(java.awt.Dimension) GridField(org.compiere.model.GridField) Point(java.awt.Point) VSortTab(org.compiere.grid.VSortTab) GridTab(org.compiere.model.GridTab) GridSynchronizer(org.compiere.grid.GridSynchronizer) GridWindowVO(org.compiere.model.GridWindowVO) CompiereColor(org.compiere.plaf.CompiereColor) VTabbedPane(org.compiere.grid.VTabbedPane) GridWorkbench(org.compiere.model.GridWorkbench) GridController(org.compiere.grid.GridController) Component(java.awt.Component)

Example 3 with GridController

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

the class VTrxMaterial method dynInit.

//  dynParameter
/**
	 *  Dynamic Layout (Grid).
	 * 	Based on AD_Window: Material Transactions
	 */
private void dynInit() {
    super.dynInit(statusBar);
    m_gridController = new GridController();
    m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
    mainPanel.add(m_gridController, BorderLayout.CENTER);
}
Also used : GridController(org.compiere.grid.GridController)

Example 4 with GridController

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

the class VStocktake method dynInit.

//  dynParameter
/**
	 *  Dynamic Layout (Grid).
	 * 	Based on AD_Window: Material Transactions
	 */
private void dynInit() {
    super.dynInit(statusBar);
    m_gridController = new GridController();
    m_gridController.initGrid(m_mTab, true, m_WindowNo, null, null);
    mainPanel.add(m_gridController, BorderLayout.CENTER);
}
Also used : GridController(org.compiere.grid.GridController)

Example 5 with GridController

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

the class APanel method stateChanged.

//	set Busy
/**************************************************************************
	 *	Change Listener - (tab change)			<->
	 *  @param e event
	 */
public void stateChanged(ChangeEvent e) {
    //Run LostFocus Event when change tab			
    if (m_curWinTab != null) {
        Component cp = m_window.getFocusOwner();
        if (cp != null) {
            m_window.dispatchEvent(new FocusEvent(cp, FocusEvent.FOCUS_LOST));
        }
    }
    if (m_disposing)
        return;
    log.info(e.toString());
    setBusy(true, true);
    VTabbedPane tp = (VTabbedPane) e.getSource();
    boolean back = false;
    boolean isAPanelTab = false;
    //  Workbench Tab Change
    if (tp.isWorkbench()) {
        int WBIndex = tabPanel.getSelectedIndex();
        m_curWindowNo = m_mWorkbench.getWindowNo(WBIndex);
        //  Window Change
        log.info("curWin=" + m_curWindowNo + " - Win=" + tp);
        if (tp.getSelectedComponent() instanceof JTabbedPane)
            m_curWinTab = (JTabbedPane) tp.getSelectedComponent();
        else
            throw new java.lang.IllegalArgumentException("Window does not contain Tabs");
        if (m_curWinTab.getSelectedComponent() instanceof GridController) {
            m_curGC = (GridController) m_curWinTab.getSelectedComponent();
            initSwitchLineAction();
        } else
            throw new java.lang.IllegalArgumentException("Window-Tab does not contain GridControler");
        //  change pointers
        m_curTabIndex = m_curWinTab.getSelectedIndex();
    } else {
        //  Just a Tab Change
        log.info("Tab=" + tp);
        m_curWinTab = tp;
        int tpIndex = m_curWinTab.getSelectedIndex();
        //	detect no tab change
        if (tpIndex == m_curTabIndex)
            return;
        back = tpIndex < m_curTabIndex;
        GridController gc = null;
        if (m_curWinTab.getSelectedComponent() instanceof GridController)
            gc = (GridController) m_curWinTab.getSelectedComponent();
        else if (m_curWinTab.getSelectedComponent() instanceof APanelTab)
            isAPanelTab = true;
        else
            throw new java.lang.IllegalArgumentException("Tab does not contain GridControler");
        //  Save old Tab
        if (m_curGC != null) {
            m_curGC.stopEditor(true);
            //  has anything changed?
            if (m_curTab.needSave(true, false)) {
                //  do we have real change
                if (m_curTab.needSave(true, true)) {
                    //	Automatic Save
                    if (Env.isAutoCommit(m_ctx, m_curWindowNo)) {
                        if (!m_curTab.dataSave(true)) {
                            //  there is a problem, so we go back
                            showLastError();
                            m_curWinTab.setSelectedIndex(m_curTabIndex);
                            setBusy(false, true);
                            return;
                        }
                    } else //  explicitly ask when changing tabs
                    if (ADialog.ask(m_curWindowNo, this, "SaveChanges?", m_curTab.getCommitWarning())) {
                        //  yes we want to save
                        if (!m_curTab.dataSave(true)) {
                            //  there is a problem, so we go back
                            showLastError();
                            m_curWinTab.setSelectedIndex(m_curTabIndex);
                            setBusy(false, true);
                            return;
                        }
                    } else //  Don't save
                    {
                        //VOSS COM
                        int newRecord = m_curTab.getTableModel().getNewRow();
                        if (newRecord == -1)
                            m_curTab.dataIgnore();
                        else {
                            m_curWinTab.setSelectedIndex(m_curTabIndex);
                            setBusy(false, true);
                            return;
                        }
                    }
                } else
                    //  new record, but nothing changed
                    m_curTab.dataIgnore();
            }
        //  there is a change
        }
        if (m_curAPanelTab != null) {
            m_curAPanelTab.saveData();
            m_curAPanelTab.unregisterPanel();
            m_curAPanelTab = null;
        }
        //	new tab
        //	if (m_curTabIndex >= 0)
        //		m_curWinTab.setForegroundAt(m_curTabIndex, AdempierePLAF.getTextColor_Normal());
        //	m_curWinTab.setForegroundAt(tpIndex, AdempierePLAF.getTextColor_OK());
        //	previousIndex = m_curTabIndex;
        m_curTabIndex = tpIndex;
        if (!isAPanelTab) {
            m_curGC = gc;
            initSwitchLineAction();
        }
    }
    //	Sort Tab Handling
    if (isAPanelTab) {
        m_curAPanelTab = (APanelTab) m_curWinTab.getSelectedComponent();
        m_curAPanelTab.registerAPanel(this);
        m_curAPanelTab.loadData();
        // Consider that APanelTab (e.g. VSortTab) is not navigable - teo_sarca [ 1705444 ]
        aFirst.setEnabled(false);
        aPrevious.setEnabled(false);
        aNext.setEnabled(false);
        aLast.setEnabled(false);
    } else //	Cur Tab Setting
    {
        int gwTabIndex = m_mWorkbench.getMWindow(0).getTabIndex(m_curGC.getMTab());
        //boolean needValidate = false;
        if (m_mWorkbench.getMWindow(0).isTabInitialized(gwTabIndex) == false) {
            m_mWorkbench.getMWindow(0).initTab(gwTabIndex);
        //needValidate = true;
        }
        m_curGC.activate();
        m_curTab = m_curGC.getMTab();
        //	Refresh only current row when tab is current
        if (back && m_curTab.isCurrent())
            m_curTab.dataRefresh();
        else //	Requery & autoSize
        {
            MRole role = MRole.getDefault();
            m_curGC.query(m_onlyCurrentRows, m_onlyCurrentDays, role.getMaxQueryRecords());
        /*
				if (m_curGC.isNeedToSaveParent())
				{
					// there is a problem, so we go back
					ADialog.error(m_curWindowNo, this, "SaveParentFirst");
					m_curWinTab.setSelectedIndex(previousIndex);
					setBusy(false, true);
					return;
				}*/
        }
        //  Set initial record
        if (m_curTab.getRowCount() == 0) {
            //	Automatically create New Record, if none & tab not RO
            if (!m_curTab.isReadOnly() && (Env.isAutoNew(m_ctx, m_curWindowNo) || m_curTab.isQueryNewRecord())) {
                log.config("No record - New - AutoNew=" + Env.isAutoNew(m_ctx, m_curWindowNo) + " - QueryNew=" + m_curTab.isQueryNewRecord());
                m_curTab.dataNew(false);
            } else //	No Records found
            {
                aSave.setEnabled(false);
                aDelete.setEnabled(false);
                aDeleteSelection.setEnabled(false);
            }
            //  updates counter
            m_curTab.navigateCurrent();
            m_curGC.dynamicDisplay(0);
        }
    /*
			if (needValidate)
			{
				JFrame frame = Env.getFrame(APanel.this);
				if (frame != null)
				{
					//not sure why, the following lines is needed to make dynamic resize work
					//tested on jdk1.5, 1.6 using jgoodies look and feel
					frame.getPreferredSize();

					if (frame.getExtendedState() != JFrame.MAXIMIZED_BOTH)
					{
						frame.setMinimumSize(frame.getSize());
						revalidate();
						SwingUtilities.invokeLater(new Runnable() {

							public void run() {
								JFrame frame = Env.getFrame(APanel.this);
								frame.validate();
								AEnv.showCenterScreen(frame);
								frame.setMinimumSize(null);
							}

						});
					}
				}
			}*/
    //	else		##CHANGE
    //		m_curTab.navigateCurrent();
    }
    //	Update <-> Navigation
    aDetail.setEnabled(m_curTabIndex != m_curWinTab.getTabCount() - 1);
    aParent.setEnabled(m_curTabIndex != 0 && m_curWinTab.getTabCount() > 1);
    //	History (on first tab only)
    if (m_mWorkbench.getMWindow(getWindowIndex()).isTransaction())
        aHistory.setEnabled(isFirstTab());
    else {
        aHistory.setPressed(false);
        aHistory.setEnabled(false);
    }
    //	Document Print
    aPrint.setEnabled(m_curTab.isPrinted());
    aPrintPreview.setEnabled(m_curTab.isPrinted());
    //	Query
    aFind.setPressed(m_curTab.isQueryActive());
    //	Order Tab
    if (isAPanelTab) {
        aMulti.setPressed(false);
        aMulti.setEnabled(false);
        aNew.setEnabled(false);
        aDelete.setEnabled(false);
        aDeleteSelection.setEnabled(false);
        aFind.setEnabled(false);
        aRefresh.setEnabled(false);
        aAttachment.setEnabled(false);
        aChat.setEnabled(false);
    } else //	Grid Tab
    {
        aMulti.setEnabled(true);
        aMulti.setPressed(!m_curGC.isSingleRow());
        aFind.setEnabled(true);
        aRefresh.setEnabled(true);
        aAttachment.setEnabled(true);
        aChat.setEnabled(true);
    }
    //
    m_curWinTab.requestFocusInWindow();
    setBusy(false, true);
    log.config("fini");
}
Also used : APanelTab(org.compiere.grid.APanelTab) JTabbedPane(javax.swing.JTabbedPane) MRole(org.compiere.model.MRole) FocusEvent(java.awt.event.FocusEvent) Point(java.awt.Point) VTabbedPane(org.compiere.grid.VTabbedPane) Component(java.awt.Component) GridController(org.compiere.grid.GridController)

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