use of org.compiere.grid.ed.VEditor in project adempiere by adempiere.
the class ProcessPanel method formatEditor.
public void formatEditor(CEditor editor1, CEditor editor2) {
log.fine("");
VEditor editor = (VEditor) editor1;
VEditor editorTo = (VEditor) editor2;
if (editor == null) {
return;
}
configColumns(editor, editorTo);
// Create label
CLabel label = VEditorFactory.getLabel(editor.getField());
if (label == null) {
// left gap
centerPanel.add(Box.createHorizontalStrut(12), new ALayoutConstraint(row, cols++));
} else {
int currentWidth = label.getPreferredSize().width;
labelMinWidth = currentWidth > labelMinWidth ? currentWidth : labelMinWidth;
// label.setSize(label.getPreferredSize());
// label.setMinimumSize(label.getPreferredSize());
// label.putClientProperty("LabelUI.truncationString", ">");
centerPanel.add(label, new ALayoutConstraint(row, cols++));
}
//
Component component = (Component) editor;
fieldMinWidth = component.getPreferredSize().width > fieldMinWidth ? component.getPreferredSize().width : fieldMinWidth;
centerPanel.add((Component) editor, new ALayoutConstraint(row, cols++));
// To
if (editorTo == null) {
m_separators.add(null);
return;
}
// Add
CLabel dash = new CLabel(" - ");
centerPanel.add(dash, new ALayoutConstraint(row, cols++));
m_separators.add(dash);
//
centerPanel.add((Component) editorTo, new ALayoutConstraint(row, cols++));
}
use of org.compiere.grid.ed.VEditor in project adempiere by adempiere.
the class GridController method vetoableChange.
/**************************************************************************
* Vetoable Change Listener.
* Called from VEditor
* <pre>
* - for Save Confirmation dialog
* - for Single Row from VEditor: Update MTable
* </pre>
* @param e event
* @throws PropertyVetoException
*/
public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException {
if (// only active records
m_mTab.isProcessed() || !m_mTab.isActive()) {
Object source = e.getSource();
if (source instanceof VEditor) {
if (!((VEditor) source).isReadWrite()) {
log.config("(" + m_mTab.toString() + ") " + e.getPropertyName());
return;
}
} else {
log.config("(" + m_mTab.toString() + ") " + e.getPropertyName());
return;
}
}
// processed
log.config("(" + m_mTab.toString() + ") " + e.getPropertyName() + "=" + e.getNewValue() + " (" + e.getOldValue() + ") " + (e.getOldValue() == null ? "" : e.getOldValue().getClass().getName()));
// Save Confirmation dialog MTable-RowSave
if (e.getPropertyName().equals(GridTable.PROPERTY)) {
// throw new PropertyVetoException will call this listener again to revert to old value
if (m_vetoActive) {
//ignore
m_vetoActive = false;
return;
}
if (!Env.isAutoCommit(Env.getCtx(), m_WindowNo) || m_mTab.getCommitWarning().length() > 0) {
if (!ADialog.ask(m_WindowNo, this, "SaveChanges?", m_mTab.getCommitWarning())) {
m_vetoActive = true;
throw new PropertyVetoException("UserDeniedSave", e);
}
}
return;
}
// saveConfirmation
// Get Row/Col Info
GridTable mTable = m_mTab.getTableModel();
int row = m_mTab.getCurrentRow();
int col = mTable.findColumn(e.getPropertyName());
//
if ((e.getNewValue() == null || e.getNewValue().toString().isEmpty()) && e.getOldValue() != null && // some editors return "" instead of null
e.getOldValue().toString().length() > 0) {
// #283 Set value to null
GridField gridField = m_mTab.getField(col);
if (!gridField.getVO().IsMandatory)
// -> dataStatusChanged -> dynamicDisplay
mTable.setValueAt(null, row, col);
mTable.setChanged(true);
} else {
// mTable.setValueAt (e.getNewValue(), row, col, true);
/*
* Changes: Added the logic below to handle multiple values for a single field
* due to multiple selection in Lookup (Info).
* @author ashley
*/
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[]) {
log.severe("Multiple values can only be processed for IDs (Integer)");
throw new PropertyVetoException("Multiple Selection values not available for this field", e);
}
// -> dataStatusChanged -> dynamicDisplay
mTable.setValueAt(newValue, row, col);
// Force Callout
if (e.getPropertyName().equals("S_ResourceAssignment_ID")) {
GridField mField = m_mTab.getField(col);
if (mField != null && mField.getCallout().length() > 0)
// Dependencies & Callout
m_mTab.processFieldChange(mField);
}
if (newValues != null && newValues.length > 0) {
// Save data, since record need to be used for generating clones.
if (!m_mTab.dataSave(false)) {
throw new PropertyVetoException("SaveError", e);
}
// Retrieve the current record ID
int recordId = m_mTab.getKeyID(m_mTab.getCurrentRow());
Trx trx = Trx.get(Trx.createTrxName(), true);
trx.start();
try {
saveMultipleRecords(Env.getCtx(), mTable.getTableName(), e.getPropertyName(), recordId, newValues, trx.getTrxName());
trx.commit();
m_mTab.dataRefreshAll();
} catch (Exception ex) {
trx.rollback();
log.severe(ex.getMessage());
throw new PropertyVetoException("SaveError", e);
} finally {
trx.close();
}
}
}
// log.config( "GridController.vetoableChange (" + m_mTab.toString() + ") - fini", e.getPropertyName() + "=" + e.getNewValue());
}
use of org.compiere.grid.ed.VEditor 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"));
}
use of org.compiere.grid.ed.VEditor in project adempiere by adempiere.
the class VBrowserSearch method formatEditor.
@Override
public void formatEditor(CEditor editor1, CEditor editor2) {
log.fine("");
VEditor editor = (VEditor) editor1;
VEditor editorTo = (VEditor) editor2;
if (editor == null) {
return;
}
configColumns(editor, editorTo);
// Create label
CLabel label = VEditorFactory.getLabel(editor.getField());
if (label == null) {
// left gap
centerPanel.add(Box.createHorizontalStrut(12), new ALayoutConstraint(row, cols++));
} else {
centerPanel.add(label, new ALayoutConstraint(row, cols++));
}
//
centerPanel.add((Component) editor, new ALayoutConstraint(row, cols++));
// To
if (editorTo == null) {
m_separators.add(null);
return;
}
// Add
CLabel dash = new CLabel(" - ");
centerPanel.add(dash, new ALayoutConstraint(row, cols++));
m_separators.add(dash);
//
centerPanel.add((Component) editorTo, new ALayoutConstraint(row, cols++));
}
use of org.compiere.grid.ed.VEditor in project adempiere by adempiere.
the class Find method addSelectionColumn.
// initFind
/**
* Add Selection Column to first Tab
* @param mField field
*/
private void addSelectionColumn(GridField mField) {
log.config(mField.getHeader());
int displayLength = mField.getDisplayLength();
if (displayLength > FIELDLENGTH)
mField.setDisplayLength(FIELDLENGTH);
else
displayLength = 0;
// Editor
VEditor editor = null;
//#221
VEditor editor2 = null;
CLabel label = null;
if (mField.isLookup()) {
VLookup vl = new VLookup(mField.getColumnName(), false, false, true, mField.getLookup());
//setting mField to avoid NPE
vl.setField(mField);
vl.setName(mField.getColumnName());
editor = vl;
//
if (// set it back
displayLength > 0)
mField.setDisplayLength(displayLength);
//
label = VEditorFactory.getLabel(mField);
//m_sLine++;
int lpos = 1;
int fpos = 2;
if (isTwoColumns) {
if (!isPair) {
lpos = 1;
fpos = 2;
m_sLine++;
} else {
lpos = 3;
fpos = 4;
}
} else {
lpos = 1;
fpos = 2;
m_sLine++;
}
if (// may be null for Y/N
label != null)
scontentPanel.add(label, new GridBagConstraints(lpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add((Component) editor, new GridBagConstraints(fpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
} else {
if (mField.isRangeLookup()) {
new Box(BoxLayout.X_AXIS);
Box box = Box.createHorizontalBox();
editor = VEditorFactory.getEditor(mField, false);
label = VEditorFactory.getLabel(mField);
editor.setMandatory(false);
editor.setReadWrite(true);
box.add((Component) editor);
//#221
editor2 = VEditorFactory.getEditor(mField, false);
editor2.setMandatory(false);
editor2.setReadWrite(true);
if (editor2 instanceof CTextField) {
((CTextField) editor2).addActionListener(this);
}
CLabel separator = new CLabel(" - ");
box.add(separator);
box.add((Component) editor2);
if (// set it back
displayLength > 0)
mField.setDisplayLength(displayLength);
int lpos = 1;
int fpos = 2;
if (isTwoColumns) {
if (!isPair) {
lpos = 1;
fpos = 2;
m_sLine++;
} else {
lpos = 3;
fpos = 4;
}
} else {
lpos = 1;
fpos = 2;
m_sLine++;
}
if (// may be null for Y/N
label != null)
scontentPanel.add(label, new GridBagConstraints(lpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add((Component) box, new GridBagConstraints(fpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
} else {
editor = VEditorFactory.getEditor(mField, false);
editor.setMandatory(false);
editor.setReadWrite(true);
label = VEditorFactory.getLabel(mField);
//
if (// set it back
displayLength > 0)
mField.setDisplayLength(displayLength);
int lpos = 1;
int fpos = 2;
if (isTwoColumns) {
if (!isPair) {
lpos = 1;
fpos = 2;
m_sLine++;
} else {
lpos = 3;
fpos = 4;
}
} else {
lpos = 1;
fpos = 2;
m_sLine++;
}
//
label = VEditorFactory.getLabel(mField);
//m_sLine++;
if (// may be null for Y/N
label != null)
scontentPanel.add(label, new GridBagConstraints(lpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(7, 5, 5, 5), 0, 0));
scontentPanel.add((Component) editor, new GridBagConstraints(fpos, m_sLine, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 5), 0, 0));
}
}
// Add action listener to custom text fields - teo_sarca [ 1709292 ]
if (editor instanceof CTextField) {
((CTextField) editor).addActionListener(this);
}
m_sEditors.add(editor);
// #221
m_sEditors2.add(editor2);
}
Aggregations