Search in sources :

Example 1 with CollapsiblePanel

use of org.compiere.swing.CollapsiblePanel in project adempiere by adempiere.

the class VPanel method addGroup.

//	addField
/**
	 *	Add Group
	 *  @param fieldGroup field group
	 *  @param fieldGroupType 
	 *  @return true if group added
	 */
private boolean addGroup(String fieldGroup, String fieldGroupType) {
    //	First time - add top
    if (m_oldFieldGroup == null) {
        m_oldFieldGroup = "";
        m_oldFieldGroupType = "";
    }
    if (fieldGroup == null || fieldGroup.length() == 0 || fieldGroup.equals(m_oldFieldGroup))
        return false;
    //[ 1757088 ]
    if (m_tablist.get(fieldGroup) != null) {
        return false;
    }
    //[ 1757088 ]
    if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Tab)) {
        CPanel m_tab = new CPanel();
        m_tab.setBackground(AdempierePLAF.getFormBackground());
        String tpConstraints = defaultLayoutConstraints;
        MigLayout layout = new MigLayout(tpConstraints);
        layout.addLayoutCallback(callback);
        m_tab.setLayout(layout);
        m_tab.setName(fieldGroup);
        CPanel dummy = new CPanel();
        dummy.setLayout(new BorderLayout());
        dummy.add(m_tab, BorderLayout.NORTH);
        dummy.setName(m_tab.getName());
        dummy.setBorder(BorderFactory.createEmptyBorder(10, 12, 0, 12));
        this.add(dummy);
        m_tablist.put(fieldGroup, m_tab);
    } else if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Collapse)) {
        CollapsiblePanel collapsibleSection = new CollapsiblePanel(fieldGroup);
        JXCollapsiblePane m_tab = collapsibleSection.getCollapsiblePane();
        m_tab.setAnimated(false);
        m_tab.getContentPane().setBackground(AdempierePLAF.getFormBackground());
        String cpConstraints = defaultLayoutConstraints;
        // 0 inset left and right as this is a nested panel
        // 0 inset top because of the struts added below
        cpConstraints += ", ins 0 0 n 0";
        MigLayout layout = new MigLayout(cpConstraints);
        layout.addLayoutCallback(callback);
        collapsibleSection.setName(fieldGroup);
        m_main.add(collapsibleSection, "newline, spanx, growx");
        m_tab.setLayout(layout);
        /* for compatibility with old layout, force collapsible field groups
			 *  to have a minimum of two columns by inserting invisible components
			 */
        Component strut1 = Box.createVerticalStrut(1);
        strut1.setName("vstrut1" + fieldGroup);
        Component strut2 = Box.createVerticalStrut(1);
        strut2.setName("vstrut2" + fieldGroup);
        m_tab.add(new CLabel(""), "gap 0 0 0 0");
        m_tab.add(strut1, "pushx, growx, gap 0 0 0 0");
        m_tab.add(new CLabel(""), "");
        m_tab.add(strut2, "pushx, growx, gap 0 0 0 0, wrap");
        m_tablist.put(fieldGroup, collapsibleSection);
    } else // Label or null
    {
        CLabel label = new CLabel(fieldGroup, CLabel.LEADING);
        label.setFont(AdempierePLAF.getFont_Label().deriveFont(Font.BOLDITALIC, AdempierePLAF.getFont_Label().getSize2D()));
        //	BR [ 359 ]
        //	Show label completely
        m_main.add(label, "newline, alignx leading, spanx, growx");
        m_main.add(new JSeparator(), "newline, spanx, growx");
    //	reset
    }
    m_oldFieldGroup = fieldGroup;
    m_oldFieldGroupType = fieldGroupType;
    return true;
}
Also used : CLabel(org.compiere.swing.CLabel) BorderLayout(java.awt.BorderLayout) MigLayout(net.miginfocom.swing.MigLayout) JXCollapsiblePane(org.jdesktop.swingx.JXCollapsiblePane) CPanel(org.compiere.swing.CPanel) Component(java.awt.Component) CollapsiblePanel(org.compiere.swing.CollapsiblePanel) JSeparator(javax.swing.JSeparator)

Example 2 with CollapsiblePanel

use of org.compiere.swing.CollapsiblePanel in project adempiere by adempiere.

the class VPanel method findChildComponents.

//  setBackground
private void findChildComponents(CPanel container, List<Component> list) {
    Component[] comp = container.getComponents();
    for (int c = 0; c < comp.length; c++) {
        list.add(comp[c]);
        if (comp[c] instanceof CollapsiblePanel) {
            CollapsiblePanel collapsiblePanel = (CollapsiblePanel) comp[c];
            Component[] nestedComps = collapsiblePanel.getCollapsiblePane().getContentPane().getComponents();
            for (int y = 0; y < nestedComps.length; y++) {
                if (nestedComps[y] instanceof CPanel) {
                    CPanel nestedPanel = (CPanel) nestedComps[y];
                    Component[] nestedPanelComps = nestedPanel.getComponents();
                    for (int x = 0; x < nestedPanelComps.length; x++) {
                        list.add(nestedPanelComps[x]);
                    }
                } else {
                    list.add(nestedComps[y]);
                }
            }
        } else if (comp[c] instanceof CPanel) {
            findChildComponents((CPanel) comp[c], list);
        }
    }
}
Also used : CPanel(org.compiere.swing.CPanel) Component(java.awt.Component) CollapsiblePanel(org.compiere.swing.CollapsiblePanel)

Example 3 with CollapsiblePanel

use of org.compiere.swing.CollapsiblePanel 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)

Example 4 with CollapsiblePanel

use of org.compiere.swing.CollapsiblePanel in project adempiere by adempiere.

the class VBrowser method initComponents.

/**
	 * Init View componets
	 */
private void initComponents() {
    toolsBar = new javax.swing.JToolBar();
    tabsPanel = new javax.swing.JTabbedPane();
    searchTab = new CPanel();
    topPanel = new CPanel();
    //	FR [ 344 ]
    searchPanel = new VBrowserSearch(getWindowNo(), getAD_Browse_ID(), BrowserSearch.COLUMNS_2);
    searchPanel.init();
    //	
    buttonSearchPanel = new CPanel();
    centerPanel = new javax.swing.JScrollPane();
    detail = new VBrowserTable(this);
    detail.setRowSelectionAllowed(true);
    detail.getSelectionModel().addListSelectionListener(this);
    footPanel = new CPanel();
    footButtonPanel = new CPanel(new FlowLayout(FlowLayout.CENTER));
    processPanel = new CPanel();
    graphPanel = new CPanel();
    setupToolBar();
    toolsBar.setRollover(true);
    bSelectAll.setText(Msg.getMsg(Env.getCtx(), "SelectAll").replaceAll("[&]", ""));
    bSelectAll.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    bSelectAll.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    bSelectAll.setEnabled(false);
    toolsBar.add(bSelectAll);
    bZoom.setText(Msg.getMsg(Env.getCtx(), "Zoom").replaceAll("[&]", ""));
    bZoom.setFocusable(false);
    bZoom.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    bZoom.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    bZoom.setEnabled(false);
    if (AD_Window_ID > 0)
        toolsBar.add(bZoom);
    bExport.setText(Msg.getMsg(Env.getCtx(), ("Export")));
    bExport.setFocusable(false);
    bExport.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    bExport.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    bExport.setEnabled(false);
    toolsBar.add(bExport);
    bDelete.setText(Msg.getMsg(Env.getCtx(), "Delete").replaceAll("[&]", ""));
    bDelete.setFocusable(false);
    bDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    bDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    bDelete.setEnabled(false);
    if (isDeleteable())
        toolsBar.add(bDelete);
    m_frame.getContentPane().add(toolsBar, java.awt.BorderLayout.PAGE_START);
    searchTab.setLayout(new java.awt.BorderLayout());
    topPanel.setLayout(new java.awt.BorderLayout());
    collapsibleSearch = new CollapsiblePanel(Msg.getMsg(Env.getCtx(), ("SearchCriteria")));
    collapsibleSearch.add(searchPanel.getPanel());
    topPanel.add(collapsibleSearch, java.awt.BorderLayout.NORTH);
    bSearch.setText(Msg.getMsg(Env.getCtx(), "StartSearch"));
    buttonSearchPanel.add(bSearch);
    collapsibleSearch.add(buttonSearchPanel);
    searchTab.add(topPanel, java.awt.BorderLayout.NORTH);
    centerPanel.setViewportView(detail);
    searchTab.add(centerPanel, java.awt.BorderLayout.CENTER);
    footPanel.setLayout(new java.awt.BorderLayout());
    footButtonPanel.add(bCancel);
    footButtonPanel.add(bOk);
    footPanel.add(footButtonPanel, java.awt.BorderLayout.SOUTH);
    processPanel.setLayout(new java.awt.BorderLayout());
    footPanel.add(processPanel, java.awt.BorderLayout.CENTER);
    searchTab.add(footPanel, java.awt.BorderLayout.SOUTH);
    tabsPanel.addTab(Msg.getMsg(Env.getCtx(), "Search"), searchTab);
    graphPanel.setLayout(new java.awt.BorderLayout());
    m_frame.getContentPane().add(tabsPanel, java.awt.BorderLayout.CENTER);
}
Also used : FlowLayout(java.awt.FlowLayout) CPanel(org.compiere.swing.CPanel) BorderLayout(java.awt.BorderLayout) CollapsiblePanel(org.compiere.swing.CollapsiblePanel) VBrowserTable(org.eevolution.grid.VBrowserTable)

Example 5 with CollapsiblePanel

use of org.compiere.swing.CollapsiblePanel in project adempiere by adempiere.

the class VPanel method addField.

/**
	 *	Add the previous Field and Label to Panel
	 *  @param editor editor
	 *  @param mField field model
	 *  @param wrap move to next line after this field
	 */
public void addField(VEditor editor, GridField mField) {
    //[ 1757088 ]
    int AD_Tab_ID = mField.getIncluded_Tab_ID();
    if (AD_Tab_ID != 0) {
        CollapsiblePanel m_tab = new CollapsiblePanel("");
        m_tabincludelist.put(AD_Tab_ID, m_tab);
        m_main.add(m_tab, "newline, spanx, growx");
        m_tab.setName("IncludedTab#" + AD_Tab_ID);
        if (includedTabList.containsKey(AD_Tab_ID)) {
            includeTab(includedTabList.get(AD_Tab_ID));
        }
        return;
    }
    CLabel label = VEditorFactory.getLabel(mField);
    if (label == null && editor == null)
        return;
    boolean sameLine = mField.isSameLine();
    //[ 1757088 ]              		//	sets top
    String fieldGroup = mField.getFieldGroup();
    String fieldGroupType = mField.getFieldGroupType();
    if (Util.isEmpty(fieldGroup)) {
        fieldGroup = m_oldFieldGroup;
        fieldGroupType = m_oldFieldGroupType;
    }
    if (//	sets top			
    addGroup(fieldGroup, fieldGroupType)) {
        if (X_AD_FieldGroup.FIELDGROUPTYPE_Collapse.equals(fieldGroupType)) {
            CollapsiblePanel panel = (CollapsiblePanel) m_tablist.get(fieldGroup);
            panel.getCollapsiblePane().setCollapsed(mField.getIsCollapsedByDefault());
        }
        sameLine = false;
    } else {
        fieldGroup = m_oldFieldGroup;
        fieldGroupType = m_oldFieldGroupType;
    }
    // label constraints
    String constraints = "align trailing";
    if (!sameLine) {
        constraints += ", newline";
    }
    //	*** The Label ***
    if (label == null) {
        label = new CLabel("");
        label.setName(mField.getColumnName());
    }
    //
    if (mField.isCreateMnemonic())
        setMnemonic(label, mField.getMnemonic());
    if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Tab)) {
        CPanel m_tab = (CPanel) m_tablist.get(fieldGroup);
        m_tab.add(label, constraints);
    } else if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Collapse)) {
        CollapsiblePanel m_tab = (CollapsiblePanel) m_tablist.get(fieldGroup);
        m_tab.getCollapsiblePane().getContentPane().add(label, constraints);
    } else // Label
    {
        m_main.add(label, constraints);
    }
    int currentWidth = label.getPreferredSize().width;
    labelMinWidth = currentWidth > labelMinWidth ? currentWidth : labelMinWidth;
    //	*** The Field ***
    if (editor != null) {
        Component field = (Component) editor;
        //	field constraints
        //  long fields span all remaining columns
        constraints = "growx, pushx";
        if (mField.isLongField()) {
            constraints += mField.isLongField() ? ",spanx" : "";
        }
        if (wrap) {
            //   Vertical Spacing in Swing Client
            // - https://sourceforge.net/tracker/?func=detail&aid=3073406&group_id=176962&atid=883808
            constraints += ", wrap 0";
        }
        //[ 1757088 ]
        if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Tab)) {
            CPanel m_tab = (CPanel) m_tablist.get(fieldGroup);
            m_tab.add(field, constraints);
        } else if (fieldGroupType.equals(X_AD_FieldGroup.FIELDGROUPTYPE_Collapse)) {
            CollapsiblePanel m_tab = (CollapsiblePanel) m_tablist.get(fieldGroup);
            Component comp = (Component) editor;
            comp.setMinimumSize(comp.getPreferredSize());
            if (mField.getDisplayType() == DisplayType.Text || mField.getDisplayType() == DisplayType.Memo || mField.getDisplayType() == DisplayType.TextLong) {
                Component component = (Component) editor;
                component.setMinimumSize(component.getPreferredSize());
            }
            if (!mField.isLongField())
                fieldMinWidth = field.getPreferredSize().width > fieldMinWidth ? field.getPreferredSize().width : fieldMinWidth;
            m_tab.getCollapsiblePane().getContentPane().add(field, constraints);
        } else // Label or null
        {
            m_main.add(field, constraints);
            if (!mField.isLongField())
                fieldMinWidth = field.getPreferredSize().width > fieldMinWidth ? field.getPreferredSize().width : fieldMinWidth;
        }
        //	Link Label to Field
        if (label != null)
            label.setLabelFor(field);
        else if (mField.isCreateMnemonic())
            setMnemonic(editor, mField.getMnemonic());
    }
}
Also used : CLabel(org.compiere.swing.CLabel) CPanel(org.compiere.swing.CPanel) Component(java.awt.Component) CollapsiblePanel(org.compiere.swing.CollapsiblePanel)

Aggregations

CollapsiblePanel (org.compiere.swing.CollapsiblePanel)7 Component (java.awt.Component)4 CPanel (org.compiere.swing.CPanel)4 BorderLayout (java.awt.BorderLayout)3 CLabel (org.compiere.swing.CLabel)2 FlowLayout (java.awt.FlowLayout)1 HashSet (java.util.HashSet)1 JSeparator (javax.swing.JSeparator)1 MigLayout (net.miginfocom.swing.MigLayout)1 APanel (org.compiere.apps.APanel)1 ProcessPanel (org.compiere.apps.ProcessPanel)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 VBrowserTable (org.eevolution.grid.VBrowserTable)1 JXCollapsiblePane (org.jdesktop.swingx.JXCollapsiblePane)1