Search in sources :

Example 21 with GridField

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

the class GridTabDataBinder method valueChange.

/**
	 * @param e
	 */
public void valueChange(ValueChangeEvent e) {
    if (//  only active records
    gridTab.isProcessed()) {
        Object source = e.getSource();
        if (source instanceof WEditor) {
            // Elaine 2009/05/06
            WEditor editor = (WEditor) source;
            GridField gridField = editor.getGridField();
            if (gridField != null) {
                if (!gridField.isEditable(true)) {
                    logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
                    return;
                }
            } else if (!editor.isReadWrite()) {
                logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
                return;
            }
        } else {
            logger.config("(" + gridTab.toString() + ") " + e.getPropertyName());
            return;
        }
    }
    //  processed
    logger.config("(" + gridTab.toString() + ") " + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));
    //  Get Row/Col Info
    GridTable mTable = gridTab.getTableModel();
    int row = gridTab.getCurrentRow();
    int col = mTable.findColumn(e.getPropertyName());
    //
    if (e.getNewValue() == null && e.getOldValue() != null && //  some editors return "" instead of null
    e.getOldValue().toString().length() > 0)
        //        	  this is the original code from GridController, don't know what it does there but it breaks ignore button for web ui        
        //            mTable.setChanged (true);  
        mTable.setValueAt(e.getNewValue(), row, col);
    else {
        Object newValue = e.getNewValue();
        Integer[] newValues = null;
        if (newValue instanceof Integer[]) {
            newValues = ((Integer[]) newValue);
            newValue = newValues[0];
            if (newValues.length > 1) {
                Integer[] valuesCopy = new Integer[newValues.length - 1];
                System.arraycopy(newValues, 1, valuesCopy, 0, valuesCopy.length);
                newValues = valuesCopy;
            } else {
                newValues = null;
            }
        } else if (newValue instanceof Object[]) {
            logger.severe("Multiple values can only be processed for IDs (Integer)");
            throw new IllegalArgumentException("Multiple Selection values not available for this field. " + e.getPropertyName());
        }
        mTable.setValueAt(newValue, row, col);
        //  Force Callout
        if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
            GridField mField = gridTab.getField(col);
            if (mField != null && mField.getCallout().length() > 0) {
                //  Dependencies & Callout
                gridTab.processFieldChange(mField);
            }
        }
        if (newValues != null && newValues.length > 0) {
            // Save data, since record need to be used for generating clones.
            if (!gridTab.dataSave(false)) {
                throw new AdempiereException("SaveError");
            }
            // Retrieve the current record ID
            int recordId = gridTab.getKeyID(gridTab.getCurrentRow());
            Trx trx = Trx.get(Trx.createTrxName(), true);
            trx.start();
            try {
                saveMultipleRecords(Env.getCtx(), gridTab.getTableName(), e.getPropertyName(), recordId, newValues, trx.getTrxName());
                trx.commit();
                gridTab.dataRefreshAll();
            } catch (Exception ex) {
                trx.rollback();
                logger.severe(ex.getMessage());
                throw new AdempiereException("SaveError");
            } finally {
                trx.close();
            }
        }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) GridTable(org.compiere.model.GridTable) WEditor(org.adempiere.webui.editor.WEditor) GridField(org.compiere.model.GridField) Trx(org.compiere.util.Trx) AdempiereException(org.adempiere.exceptions.AdempiereException)

Example 22 with GridField

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

the class BrowserRow method getValue.

/**
	 * BR[ 268 ]
	 * Get Value from a column name in a row
	 * @param p_Row
	 * @param p_ColumnName
	 * @return
	 */
public Object getValue(int p_Row, String p_ColumnName) {
    Integer columnIndex = columnNamesIndex.get(p_ColumnName);
    //	Valid Index
    if (columnIndex == null)
        return null;
    //	Get current Value
    GridField gridField = getValue(p_Row, columnIndex);
    if (gridField == null)
        return null;
    //	Return value of GridField
    return gridField.getValue();
}
Also used : GridField(org.compiere.model.GridField)

Example 23 with GridField

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

the class DeleteSelectionController method getValue.

/**
	 * Get value from index
	 * @param index
	 * @return
	 */
private String getValue(int index) {
    StringBuffer displayValue = new StringBuffer();
    if (keyColumnName.trim().length() == 0) {
        ArrayList<String> parentColumnNames = currentTab.getParentColumnNames();
        for (Iterator<String> iter = parentColumnNames.iterator(); iter.hasNext(); ) {
            String columnName = iter.next();
            GridField field = currentTab.getField(columnName);
            if (field.isLookup()) {
                Lookup lookup = field.getLookup();
                if (lookup != null) {
                    displayValue = displayValue.append(lookup.getDisplay(currentTab.getValue(index, columnName))).append(" | ");
                } else {
                    displayValue = displayValue.append(currentTab.getValue(index, columnName)).append(" | ");
                }
            } else {
                displayValue = displayValue.append(currentTab.getValue(index, columnName)).append(" | ");
            }
        }
    } else {
        final int id = currentTab.getKeyID(index);
        String value = DB.getSQLValueStringEx(null, sql, id);
        if (value != null)
            value = value.replace(" - ", " | ");
        displayValue.append(value);
        // Append ID
        if (displayValue.length() == 0 || CLogMgt.isLevelFine()) {
            if (displayValue.length() > 0)
                displayValue.append(" | ");
            displayValue.append("<").append(id).append(">");
        }
    }
    //	Return
    return displayValue.toString();
}
Also used : Lookup(org.compiere.model.Lookup) GridField(org.compiere.model.GridField)

Example 24 with GridField

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

the class SmallViewController method createEditors.

/**
	 * Create editors for each field/fieldTo.  The function calls the View to create
	 * the appropriate editor for the field.
	 * 
	 * TODO The GridFields are Model level entities and the view should not have to 
	 * deal with the Model. An intermediate factory could be used to create Controller 
	 * level editors common to all interfaces.  The View would then only have to implement
	 * the actual editor.  There is a CEditor interface used but an abstract class would be 
	 * better. 
	 */
private void createEditors() {
    for (int i = 0; i < fields.size(); i++) {
        //    Get Values
        GridField field = (GridField) fields.get(i);
        GridField field_To = (GridField) fieldsTo.get(i);
        createEditors(field, field_To);
    }
}
Also used : GridField(org.compiere.model.GridField)

Example 25 with GridField

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

the class Find method initFind.

/**
	 *	Dynamic Init.6
	 *  Set up GridController
	 */
private void initFind() {
    log.config("");
    //  Get Info from target Tab
    int parameterNo = 0;
    for (int i = 0; i < m_findFields.length; i++) {
        GridField mField = m_findFields[i];
        if (mField.isSelectionColumn())
            parameterNo++;
    }
    if (parameterNo >= 7)
        isTwoColumns = true;
    //	Get Info from target Tab
    for (int i = 0; i < m_findFields.length; i++) {
        GridField mField = m_findFields[i];
        // Make Yes-No searchable as list
        if (mField.getVO().displayType == DisplayType.YesNo) {
            GridFieldVO vo = mField.getVO();
            GridFieldVO ynvo = vo.clone(vo.ctx, vo.WindowNo, vo.TabNo, vo.AD_Window_ID, vo.AD_Tab_ID, vo.tabReadOnly);
            ynvo.IsDisplayed = true;
            ynvo.displayType = DisplayType.List;
            ynvo.AD_Reference_Value_ID = AD_REFERENCE_ID_YESNO;
            ynvo.lookupInfo = MLookupFactory.getLookupInfo(ynvo.ctx, ynvo.WindowNo, ynvo.AD_Column_ID, ynvo.displayType, Env.getLanguage(ynvo.ctx), ynvo.ColumnName, ynvo.AD_Reference_Value_ID, ynvo.IsParent, ynvo.ValidationCode);
            ynvo.lookupInfo.InfoFactoryClass = ynvo.InfoFactoryClass;
            GridField ynfield = new GridField(ynvo);
            // replace the original field by the YN List field
            m_findFields[i] = ynfield;
            mField = ynfield;
        }
        // Make Buttons searchable
        if (mField.getVO().displayType == DisplayType.Button) {
            GridFieldVO vo = mField.getVO();
            if (vo.AD_Reference_Value_ID > 0) {
                GridFieldVO postedvo = vo.clone(vo.ctx, vo.WindowNo, vo.TabNo, vo.AD_Window_ID, vo.AD_Tab_ID, vo.tabReadOnly);
                postedvo.IsDisplayed = true;
                postedvo.displayType = DisplayType.List;
                postedvo.lookupInfo = MLookupFactory.getLookupInfo(postedvo.ctx, postedvo.WindowNo, postedvo.AD_Column_ID, postedvo.displayType, Env.getLanguage(postedvo.ctx), postedvo.ColumnName, postedvo.AD_Reference_Value_ID, postedvo.IsParent, postedvo.ValidationCode);
                postedvo.lookupInfo.InfoFactoryClass = postedvo.InfoFactoryClass;
                GridField postedfield = new GridField(postedvo);
                // replace the original field by the Posted List field
                m_findFields[i] = postedfield;
                mField = postedfield;
            }
        }
        /** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214
			if (columnName.equals("Value"))
				hasValue = true;
			else if (columnName.equals("Name"))
				hasName = true;
			else if (columnName.equals("DocumentNo"))
				hasDocNo = true;
			else if (columnName.equals("Description"))
				hasDescription = true;
			else
			/**/
        if (mField.isSelectionColumn()) {
            addSelectionColumn(mField);
            isPair = !isPair;
        }
        /** metas: teo_sarca: Specify exactly which are the search fields - http://sourceforge.net/projects/adempiere/forums/forum/610548/topic/3736214
			else if (columnName.indexOf("Name") != -1)
				addSelectionColumn (mField);
			/**/
        //  TargetFields
        m_targetFields.put(new Integer(mField.getAD_Column_ID()), mField);
    }
    //  for all target tab fields
    //	Disable simple query fields
    valueLabel.setVisible(hasValue);
    valueField.setVisible(hasValue);
    if (hasValue)
        valueField.addActionListener(this);
    docNoLabel.setVisible(hasDocNo);
    docNoField.setVisible(hasDocNo);
    if (hasDocNo)
        docNoField.addActionListener(this);
    nameLabel.setVisible(hasName);
    nameField.setVisible(hasName);
    if (hasName)
        nameField.addActionListener(this);
    descriptionLabel.setVisible(hasDescription);
    descriptionField.setVisible(hasDescription);
    if (hasDescription)
        descriptionField.addActionListener(this);
    //	Get Total
    m_total = getNoOfRecords(null, false);
    setStatusDB(m_total);
    statusBar.setStatusLine("");
    tabbedPane.addChangeListener(this);
    //	Better Labels for OK/Cancel
    confirmPanelA.getOKButton().setToolTipText(Msg.getMsg(Env.getCtx(), "QueryEnter"));
    confirmPanelA.getCancelButton().setToolTipText(Msg.getMsg(Env.getCtx(), "QueryCancel"));
    confirmPanelS.getOKButton().setToolTipText(Msg.getMsg(Env.getCtx(), "QueryEnter"));
    confirmPanelS.getCancelButton().setToolTipText(Msg.getMsg(Env.getCtx(), "QueryCancel"));
}
Also used : GridFieldVO(org.compiere.model.GridFieldVO) GridField(org.compiere.model.GridField)

Aggregations

GridField (org.compiere.model.GridField)114 MQuery (org.compiere.model.MQuery)15 WEditor (org.adempiere.webui.editor.WEditor)11 GridFieldVO (org.compiere.model.GridFieldVO)10 GridTab (org.compiere.model.GridTab)10 Lookup (org.compiere.model.Lookup)9 org.apache.ecs.xhtml.tr (org.apache.ecs.xhtml.tr)8 MLookup (org.compiere.model.MLookup)8 Component (java.awt.Component)7 AdempiereException (org.adempiere.exceptions.AdempiereException)7 org.apache.ecs.xhtml.form (org.apache.ecs.xhtml.form)7 org.apache.ecs.xhtml.input (org.apache.ecs.xhtml.input)7 ValueNamePair (org.compiere.util.ValueNamePair)7 SQLException (java.sql.SQLException)6 MBrowseField (org.adempiere.model.MBrowseField)6 org.apache.ecs.xhtml.td (org.apache.ecs.xhtml.td)6 VEditor (org.compiere.grid.ed.VEditor)6 Point (java.awt.Point)5 org.apache.ecs.xhtml.a (org.apache.ecs.xhtml.a)5 org.apache.ecs.xhtml.div (org.apache.ecs.xhtml.div)5