Search in sources :

Example 31 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class GridTable method dataDelete.

//	dataNew
/**************************************************************************
	 *	Delete Data
	 *  @param row row
	 *  @return true if success -
	 *  Error info (Access*, AccessNotDeleteable, DeleteErrorDependent,
	 *  DeleteError) is saved in the log
	 */
public boolean dataDelete(int row) {
    log.info("Row=" + row);
    if (row < 0)
        return false;
    //	Tab R/O
    if (m_readOnly) {
        //	previleges
        fireDataStatusEEvent("AccessCannotDelete", "", true);
        return false;
    }
    //	Is this record deletable?
    if (!m_deleteable) {
        //	audit
        fireDataStatusEEvent("AccessNotDeleteable", "", true);
        return false;
    }
    //	Processed Column and not an Import Table
    if (m_indexProcessedColumn > 0 && !m_tableName.startsWith("I_")) {
        Boolean processed = (Boolean) getValueAt(row, m_indexProcessedColumn);
        if (processed != null && processed.booleanValue()) {
            fireDataStatusEEvent("CannotDeleteTrx", "", true);
            return false;
        }
    }
    /** @todo check Access */
    //  fireDataStatusEvent(Log.retrieveError());
    MSort sort = (MSort) m_sort.get(row);
    Object[] rowData = getDataAtRow(row);
    //
    MTable table = MTable.get(m_ctx, m_AD_Table_ID);
    PO po = null;
    int Record_ID = getKeyID(m_rowChanged);
    if (Record_ID != -1)
        po = table.getPO(Record_ID, null);
    else
        //	Multi - Key
        po = table.getPO(getWhereClause(rowData), null);
    //	Delete via PO 
    if (po != null) {
        boolean ok = false;
        try {
            ok = po.delete(false);
        } catch (Throwable t) {
            log.log(Level.SEVERE, "Delete", t);
        }
        if (!ok) {
            ValueNamePair vp = CLogger.retrieveError();
            if (vp != null)
                fireDataStatusEEvent(vp);
            else
                fireDataStatusEEvent("DeleteError", "", true);
            return false;
        }
    } else //	Delete via SQL
    {
        StringBuffer sql = new StringBuffer("DELETE ");
        sql.append(m_tableName).append(" WHERE ").append(getWhereClause(rowData));
        int no = 0;
        PreparedStatement pstmt = null;
        try {
            pstmt = DB.prepareStatement(sql.toString(), ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, null);
            no = pstmt.executeUpdate();
        } catch (SQLException e) {
            log.log(Level.SEVERE, sql.toString(), e);
            String msg = "DeleteError";
            if (DBException.isChildRecordFoundError(e))
                msg = "DeleteErrorDependent";
            fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
            return false;
        } finally {
            DB.close(pstmt);
            pstmt = null;
        }
        //	Check Result
        if (no != 1) {
            log.log(Level.SEVERE, "Number of deleted rows = " + no);
            return false;
        }
    }
    //	Get Sort
    if (m_virtual) {
        m_virtualBuffer.remove(sort.index);
    } else {
        //	Delete row in Buffer and shifts all below up
        m_buffer.remove(sort.index);
    }
    m_rowCount--;
    //	Delete row in Sort
    m_sort.remove(row);
    if (!m_virtual) {
        //	Correct pointer in Sort
        for (int i = 0; i < m_sort.size(); i++) {
            MSort ptr = (MSort) m_sort.get(i);
            if (ptr.index > sort.index)
                //	move up
                ptr.index--;
        }
    }
    //	inform
    m_changed = false;
    m_rowChanged = -1;
    fireTableRowsDeleted(row, row);
    fireDataStatusIEvent("Deleted", "");
    log.fine("Row=" + row + " complete");
    return true;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) MSort(org.compiere.util.MSort) ValueNamePair(org.compiere.util.ValueNamePair)

Example 32 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class Lookup method put.

//  removeAllElements
/**************************************************************************
	 *	Put Value
	 *  @param key key
	 *  @param value value
	 */
public void put(String key, String value) {
    NamePair pp = new ValueNamePair(key, value);
    addElement(pp);
}
Also used : KeyNamePair(org.compiere.util.KeyNamePair) NamePair(org.compiere.util.NamePair) ValueNamePair(org.compiere.util.ValueNamePair) ValueNamePair(org.compiere.util.ValueNamePair)

Example 33 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class PO method set_Value.

//  setValueE
/**
	 *  Set Value if updteable and correct class.
	 *  (and to NULL if not mandatory)
	 *  @param index index
	 *  @param value value
	 *  @return true if value set
	 */
protected final boolean set_Value(int index, Object value) {
    if (index < 0 || index >= get_ColumnCount()) {
        log.log(Level.WARNING, "Index invalid - " + index);
        return false;
    }
    String ColumnName = p_info.getColumnName(index);
    String colInfo = " - " + ColumnName;
    //
    if (p_info.isVirtualColumn(index)) {
        log.log(Level.WARNING, "Virtual Column" + colInfo);
        return false;
    }
    // if (!p_info.isColumnUpdateable(index))
    if ((!p_info.isColumnUpdateable(index)) && (!is_new())) {
        colInfo += " - NewValue=" + value + " - OldValue=" + get_Value(index);
        log.log(Level.WARNING, "Column not updateable" + colInfo);
        return false;
    }
    //
    if (value == null) {
        if (p_info.isColumnMandatory(index)) {
            throw new IllegalArgumentException(ColumnName + " is mandatory.");
        }
        //  correct
        m_newValues[index] = Null.NULL;
        log.finer(ColumnName + " = null");
    } else {
        //  matching class or generic object
        if (value.getClass().equals(p_info.getColumnClass(index)) || p_info.getColumnClass(index) == Object.class)
            //  correct
            m_newValues[index] = value;
        else //  Integer can be set as BigDecimal
        if (value.getClass() == BigDecimal.class && p_info.getColumnClass(index) == Integer.class)
            m_newValues[index] = new Integer(((BigDecimal) value).intValue());
        else //	Set Boolean
        if (p_info.getColumnClass(index) == Boolean.class && ("Y".equals(value) || "N".equals(value)))
            m_newValues[index] = new Boolean("Y".equals(value));
        else // although is ID (integer) in database
        if (value.getClass() == Integer.class && p_info.getColumnClass(index) == String.class)
            m_newValues[index] = value;
        else if (value.getClass() == String.class && p_info.getColumnClass(index) == Integer.class)
            try {
                m_newValues[index] = new Integer((String) value);
            } catch (NumberFormatException e) {
                log.log(Level.SEVERE, ColumnName + " - Class invalid: " + value.getClass().toString() + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value);
                return false;
            }
        else {
            log.log(Level.SEVERE, ColumnName + " - Class invalid: " + value.getClass().toString() + ", Should be " + p_info.getColumnClass(index).toString() + ": " + value);
            return false;
        }
        //	Validate (Min/Max)
        String error = p_info.validate(index, value);
        if (error != null) {
            log.log(Level.WARNING, ColumnName + "=" + value + " - " + error);
            return false;
        }
        //	Length for String
        if (p_info.getColumnClass(index) == String.class) {
            String stringValue = value.toString();
            int length = p_info.getFieldLength(index);
            if (stringValue.length() > length && length > 0) {
                log.warning(ColumnName + " - Value too long - truncated to length=" + length);
                m_newValues[index] = stringValue.substring(0, length);
            }
        }
        // Validate reference list [1762461]
        if (p_info.getColumn(index).DisplayType == DisplayType.List && p_info.getColumn(index).AD_Reference_Value_ID > 0 && value instanceof String) {
            if (MRefList.get(getCtx(), p_info.getColumn(index).AD_Reference_Value_ID, (String) value, get_TrxName()) != null)
                ;
            else {
                StringBuffer validValues = new StringBuffer();
                for (ValueNamePair vp : MRefList.getList(getCtx(), p_info.getColumn(index).AD_Reference_Value_ID, false)) validValues.append(" - ").append(vp.getValue());
                throw new IllegalArgumentException(ColumnName + " Invalid value - " + value + " - Reference_ID=" + p_info.getColumn(index).AD_Reference_Value_ID + validValues.toString());
            }
        }
        if (CLogMgt.isLevelFinest())
            log.finest(ColumnName + " = " + m_newValues[index] + " (OldValue=" + m_oldValues[index] + ")");
    }
    set_Keys(ColumnName, m_newValues[index]);
    // FR 2962094 Fill ProcessedOn when the Processed column is changing from N to Y
    setProcessedOn(ColumnName, value, m_oldValues[index]);
    return true;
}
Also used : ValueNamePair(org.compiere.util.ValueNamePair) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BigDecimal(java.math.BigDecimal) Savepoint(java.sql.Savepoint)

Example 34 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class PO method deleteEx.

//	delete
/**
	 * Delete Current Record
	 * @param force delete also processed records
	 * @throws AdempiereException
	 * @see #delete(boolean)
	 */
public void deleteEx(boolean force) throws AdempiereException {
    if (!delete(force)) {
        String msg = null;
        ValueNamePair err = CLogger.retrieveError();
        if (err != null)
            msg = err.getName();
        if (msg == null || msg.length() == 0)
            msg = "DeleteError";
        throw new AdempiereException(msg);
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) ValueNamePair(org.compiere.util.ValueNamePair)

Example 35 with ValueNamePair

use of org.compiere.util.ValueNamePair in project adempiere by adempiere.

the class ColorEditor method cmd_type.

//  actionPerformed
/**
	 *  Set Type with default values
	 */
private void cmd_type() {
    ValueNamePair vp = (ValueNamePair) typeField.getSelectedItem();
    if (vp.getValue().equals(CompiereColor.TYPE_FLAT))
        m_cc = new CompiereColor(CompiereColor.TYPE_FLAT);
    else if (vp.getValue().equals(CompiereColor.TYPE_GRADIENT))
        m_cc = new CompiereColor(CompiereColor.TYPE_GRADIENT);
    else if (vp.getValue().equals(CompiereColor.TYPE_TEXTURE))
        m_cc = new CompiereColor(CompiereColor.TYPE_TEXTURE);
    else if (vp.getValue().equals(CompiereColor.TYPE_LINES))
        m_cc = new CompiereColor(CompiereColor.TYPE_LINES);
    setColor(m_cc);
}
Also used : CompiereColor(org.compiere.plaf.CompiereColor) ValueNamePair(org.compiere.util.ValueNamePair)

Aggregations

ValueNamePair (org.compiere.util.ValueNamePair)109 KeyNamePair (org.compiere.util.KeyNamePair)35 SQLException (java.sql.SQLException)22 ArrayList (java.util.ArrayList)22 PreparedStatement (java.sql.PreparedStatement)20 ResultSet (java.sql.ResultSet)19 Timestamp (java.sql.Timestamp)9 GridField (org.compiere.model.GridField)7 BigDecimal (java.math.BigDecimal)5 MetalLookAndFeel (javax.swing.plaf.metal.MetalLookAndFeel)5 MetalTheme (javax.swing.plaf.metal.MetalTheme)5 MInvoice (org.compiere.model.MInvoice)5 MLookup (org.compiere.model.MLookup)5 MLookupInfo (org.compiere.model.MLookupInfo)5 HRPayPrint (org.eevolution.service.HRPayPrint)5 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)4 ListItem (org.adempiere.webui.component.ListItem)4 MCashLine (org.compiere.model.MCashLine)4 AdempiereUserError (org.compiere.util.AdempiereUserError)4 NamePair (org.compiere.util.NamePair)4