Search in sources :

Example 1 with VChart

use of org.compiere.grid.ed.VChart in project adempiere by adempiere.

the class GridController method dynamicDisplay.

//  propertyChange
/**
	 *  Dynamic Display.
	 *  - Single Row Screen layout and update of dynamic Lookups
	 *  <p>
	 *  Single Row layout:
	 *  the components's name is the ColumnName; if it matches, the
	 *  MField.isDisplayed(true) is used to determine if it is visible
	 *  if the component is a VEditor, setEnabled is set from the MField
	 *  <p>
	 *  Multi Row layout is not changed:
	 *  VCellRenderer calls JTable.isCellEditable -> checks MField.isEditable (Active, isDisplayed)
	 *  VCellEditor.isCellEditable calls MField.isEditable(true) <br>
	 *  If a column is not displayed, the width is set to 0 in dynInit
	 *  <p>
	 *  Dynamic update of data is handeled in VLookup.focusGained/Lost.
	 *  When focus is gained the model is temporarily updated with the
	 *  specific validated data, if lost, it is switched back to the
	 *  unvalidated data (i.e. everything). This allows that the display
	 *  methods have a lookup to display. <br>
	 *  Here: if the changed field has dependents and the dependent
	 *  is a Lookup and this lookup has a dynamic dependence of the changed field,
	 *  the value of that field is set to null (in MTab.processDependencies -
	 *  otherwise it would show an invalid value).
	 *  As Editors listen for value changed of their MField, the display is updated.
	 *  <p>
	 *  Called from GridController.valueChanged/dataStatusChanged, APane;.stateChanged/unlock/cmd_...
	 *  @param col selective column number or 0 if all
	 */
public void dynamicDisplay(int col) {
    //	Don't update if multi-row
    if (!isSingleRow() || m_onlyMultiRow)
        return;
    if (!m_mTab.isOpen())
        return;
    //  Selective
    if (col > 0) {
        GridField changedField = m_mTab.getField(col);
        String columnName = changedField.getColumnName();
        ArrayList<GridField> dependants = m_mTab.getDependantFields(columnName);
        log.config("(" + m_mTab.toString() + ") " + columnName + " - Dependents=" + dependants.size());
        //	No Dependents and no Callout - Set just Background
        if (dependants.size() == 0 && changedField.getCallout().length() == 0) {
            Component[] comp = vPanel.getComponentsRecursive();
            for (int i = 0; i < comp.length; i++) {
                if (columnName.equals(comp[i].getName()) && comp[i] instanceof VEditor) {
                    VEditor ve = (VEditor) comp[i];
                    boolean manMissing = false;
                    boolean noValue = changedField.getValue() == null || changedField.getValue().toString().length() == 0;
                    if (//  check context
                    noValue && changedField.isEditable(true) && changedField.isMandatory(true))
                        manMissing = true;
                    ve.setBackground(manMissing || changedField.isError());
                    break;
                }
            }
            return;
        }
    }
    //  selective
    //  complete single row re-display
    boolean noData = m_mTab.getRowCount() == 0;
    log.config(m_mTab.toString() + " - Rows=" + m_mTab.getRowCount());
    //  All Components in vPanel (Single Row)
    Set<String> hiddens = new HashSet<String>();
    Component[] comps = vPanel.getComponentsRecursive();
    for (int i = 0; i < comps.length; i++) {
        Component comp = comps[i];
        String columnName = comp.getName();
        if (comp instanceof VChart && isSingleRow()) {
            ((VChart) comp).createChart();
        }
        if (columnName != null && columnName.length() > 0) {
            GridField mField = m_mTab.getField(columnName);
            if (mField != null) {
                if (//  check context
                mField.isDisplayed(true)) {
                    if (!comp.isVisible())
                        //  visibility
                        comp.setVisible(true);
                    /**
						 * Feature Request [1707462]
						 * Enable runtime change of VFormat
						 * @author fer_luck
						 */
                    if (comp instanceof VString) {
                        VString vs = (VString) comp;
                        if ((vs.getVFormat() != null && vs.getVFormat().length() > 0 && mField.getVFormat() == null) || (vs.getVFormat() == null && mField.getVFormat() != null && mField.getVFormat().length() > 0) || (vs.getVFormat() != null && mField.getVFormat() != null && !vs.getVFormat().equals(mField.getVFormat()))) {
                            vs.setVFormat(mField.getVFormat());
                        }
                    }
                    //End Feature Request [1707462]
                    if (comp instanceof VEditor) {
                        VEditor ve = (VEditor) comp;
                        if (noData)
                            ve.setReadWrite(false);
                        else {
                            //  r/w - check Context
                            boolean rw = mField.isEditable(true);
                            ve.setReadWrite(rw);
                            //	log.log(Level.FINEST, "RW=" + rw + " " + mField);
                            boolean manMissing = false;
                            //  least expensive operations first        //  missing mandatory
                            if (rw && (mField.getValue() == null || mField.getValue().toString().isEmpty()) && //  check context. Some fields can return "" instead of null
                            mField.isMandatory(true))
                                manMissing = true;
                            ve.setBackground(manMissing || mField.isError());
                        }
                    }
                } else {
                    if (comp.isVisible())
                        comp.setVisible(false);
                    hiddens.add(columnName);
                }
            }
        }
    }
    // hide empty field group based on the environment
    for (int i = 0; i < comps.length; i++) {
        Component comp = comps[i];
        if (comp instanceof CollapsiblePanel) {
            if (comp.getName() == null || comp.getName().startsWith("IncludedTab#"))
                continue;
            else {
                boolean hasVisible = false;
                Component[] childs = ((CollapsiblePanel) comp).getCollapsiblePane().getContentPane().getComponents();
                for (int j = 0; j < childs.length; j++) {
                    if (childs[j].isVisible()) {
                        String columnName = childs[j].getName();
                        if (columnName != null && columnName.length() > 0) {
                            GridField mField = m_mTab.getField(columnName);
                            if (mField != null) {
                                hasVisible = true;
                                break;
                            }
                        }
                    }
                }
                if (comp.isVisible() != hasVisible)
                    comp.setVisible(hasVisible);
            }
        }
    }
    //
    log.config(m_mTab.toString() + " - fini - " + (col <= 0 ? "complete" : "seletive"));
}
Also used : VChart(org.compiere.grid.ed.VChart) GridField(org.compiere.model.GridField) VString(org.compiere.grid.ed.VString) VEditor(org.compiere.grid.ed.VEditor) CollapsiblePanel(org.compiere.swing.CollapsiblePanel) VString(org.compiere.grid.ed.VString) Component(java.awt.Component) HashSet(java.util.HashSet)

Aggregations

Component (java.awt.Component)1 HashSet (java.util.HashSet)1 VChart (org.compiere.grid.ed.VChart)1 VEditor (org.compiere.grid.ed.VEditor)1 VString (org.compiere.grid.ed.VString)1 GridField (org.compiere.model.GridField)1 CollapsiblePanel (org.compiere.swing.CollapsiblePanel)1