use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class Find method initFindAdvanced.
// addSelectionColumn
/**
* Init Find GridController
*/
private void initFindAdvanced() {
log.config("");
advancedTable.setModel(new DefaultTableModel(0, 7));
advancedTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
advancedTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
advancedTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
TableCellRenderer renderer = new ProxyRenderer(advancedTable.getDefaultRenderer(Object.class));
advancedTable.setDefaultRenderer(Object.class, renderer);
InputMap im = advancedTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
final Action tabAction = advancedTable.getActionMap().get(im.get(tab));
Action tabActionWrapper = new AbstractAction() {
private static final long serialVersionUID = -6868476640719619801L;
public void actionPerformed(ActionEvent e) {
tabAction.actionPerformed(e);
JTable table = (JTable) e.getSource();
table.requestFocusInWindow();
}
};
advancedTable.getActionMap().put(im.get(tab), tabActionWrapper);
KeyStroke shiftTab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
final Action shiftTabAction = advancedTable.getActionMap().get(im.get(shiftTab));
Action shiftTabActionWrapper = new AbstractAction() {
private static final long serialVersionUID = 5493691483070046620L;
public void actionPerformed(ActionEvent e) {
shiftTabAction.actionPerformed(e);
JTable table = (JTable) e.getSource();
table.requestFocusInWindow();
}
};
advancedTable.getActionMap().put(im.get(shiftTab), shiftTabActionWrapper);
// 0 = Columns
ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
for (int c = 0; c < m_findFields.length; c++) {
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
if (header == null || header.length() == 0) {
header = Msg.translate(Env.getCtx(), columnName);
if (header == null || header.length() == 0)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
// System.out.println(pp + " = " + field);
items.add(pp);
}
columnValueNamePairs = new ValueNamePair[items.size()];
items.toArray(columnValueNamePairs);
// sort alpha
Arrays.sort(columnValueNamePairs);
columns = new CComboBox(columnValueNamePairs);
columns.addActionListener(this);
TableColumn tc = advancedTable.getColumnModel().getColumn(INDEX_COLUMNNAME);
tc.setPreferredWidth(120);
FindCellEditor dce = new FindCellEditor(columns);
dce.addCellEditorListener(new CellEditorListener() {
public void editingCanceled(ChangeEvent ce) {
}
public void editingStopped(ChangeEvent ce) {
int col = advancedTable.getSelectedColumn();
int row = advancedTable.getSelectedRow();
if (col == INDEX_COLUMNNAME && row >= 0) {
advancedTable.setValueAt(null, row, INDEX_VALUE);
advancedTable.setValueAt(null, row, INDEX_VALUE2);
}
}
});
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.translate(Env.getCtx(), "AD_Column_ID"));
// 0 = And/Or
andOr = new CComboBox(new String[] { "", Msg.getMsg(Env.getCtx(), "AND"), Msg.getMsg(Env.getCtx(), "OR") });
tc = advancedTable.getColumnModel().getColumn(INDEX_ANDOR);
tc.setPreferredWidth(45);
dce = new FindCellEditor(andOr);
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "And/Or"));
// 1 = Left Bracket
leftBrackets = new CComboBox(new String[] { "", "(", "((", "(((" });
tc = advancedTable.getColumnModel().getColumn(INDEX_LEFTBRACKET);
tc.setPreferredWidth(25);
dce = new FindCellEditor(leftBrackets);
tc.setCellEditor(dce);
tc.setHeaderValue("(");
// 3 = Operators
operators = new CComboBox(MQuery.OPERATORS);
tc = advancedTable.getColumnModel().getColumn(INDEX_OPERATOR);
tc.setPreferredWidth(55);
dce = new FindCellEditor(operators);
tc.setCellEditor(dce);
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "Operator"));
// 4 = QueryValue
tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE);
FindValueEditor fve = new FindValueEditor(this, false);
tc.setCellEditor(fve);
tc.setPreferredWidth(120);
tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue"));
// 5 = QueryValue2
tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE2);
tc.setPreferredWidth(120);
fve = new FindValueEditor(this, true);
tc.setCellEditor(fve);
tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false)));
tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue2"));
// 6 = Right Bracket
rightBrackets = new CComboBox(new String[] { "", ")", "))", ")))" });
tc = advancedTable.getColumnModel().getColumn(INDEX_RIGHTBRACKET);
tc.setPreferredWidth(25);
dce = new FindCellEditor(rightBrackets);
tc.setCellEditor(dce);
tc.setHeaderValue(")");
// phib: disabled auto-completion as it causes date fields to have to be entered twice
//AutoCompletion.enable(columns);
//AutoCompletion.enable(operators);
//user query
refreshUserQueries();
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class Find method actionPerformed.
// dispose
/**************************************************************************
* Action Listener
* @param e ActionEvent
*/
public void actionPerformed(ActionEvent e) {
log.info(e.getActionCommand());
//
if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
cmd_cancel();
else if (e.getActionCommand().equals(ConfirmPanel.A_REFRESH))
cmd_refresh();
else //
if (e.getActionCommand().equals(ConfirmPanel.A_NEW)) {
m_query = MQuery.getNoRecordQuery(m_tableName, true);
m_total = 0;
dispose();
} else //
if (e.getSource() == bIgnore)
cmd_ignore();
else if (e.getSource() == bNew)
cmd_new();
else if (e.getSource() == bSave)
cmd_save(true);
else if (e.getSource() == bDelete)
cmd_delete();
else //
if (e.getSource() == columns) {
String columnName = null;
Object selected = columns.getSelectedItem();
if (selected != null) {
if (selected instanceof ValueNamePair) {
ValueNamePair column = (ValueNamePair) selected;
columnName = column.getValue();
} else {
columnName = selected.toString();
}
}
if (columnName != null) {
log.config("Column: " + columnName);
if (columnName.endsWith("_ID") || columnName.endsWith("_Acct"))
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_ID));
else if (columnName.startsWith("Is"))
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_YN));
else
operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS));
}
} else if (e.getSource() == fQueryName) {
// fQueryName has changed.
int index = fQueryName.getSelectedIndex();
if (index < 0) {
if (fQueryName.getSelectedItem() == null || fQueryName.getSelectedItem().equals(m_sTipText)) {
return;
}
} else if (index == 0) {
// no query - wipe and start over.
advancedTable.stopEditor(false);
DefaultTableModel model = (DefaultTableModel) advancedTable.getModel();
int cnt = model.getRowCount();
if (cnt > 0) {
for (int i = cnt - 1; i >= 0; i--) {
model.removeRow(i);
}
// No row - create one.
cmd_new();
}
fQueryName.setSelectedIndex(-1);
fQueryName.setSelectedItem(m_sTipText);
advancedTable.requestFocusInWindow();
} else
parseUserQuery(userQueries[index - 1]);
} else // ConfirmPanel.A_OK and enter in fields
{
if (e.getSource() == confirmPanelA.getOKButton())
cmd_ok_Advanced();
else if (e.getSource() == confirmPanelS.getOKButton())
cmd_ok_Simple();
else if (e.getSource() instanceof JTextField && tabbedPane.getSelectedIndex() == 0)
cmd_ok_Simple();
}
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class FindValueEditor method getTableCellEditorComponent.
// getCellEditorValue
/**
* Get Editor
*
* @param table Table
* @param value Value
* @param isSelected cell is selected
* @param row row
* @param col column
* @return Editor component
*/
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int col) {
// log.config( "FindValueEditor.getTableCellEditorComponent", "r=" + row + ", c=" + col);
// Between - enables valueToColumn
m_between = false;
Object betweenValue = table.getModel().getValueAt(row, Find.INDEX_OPERATOR);
if (m_valueToColumn && betweenValue != null && betweenValue.equals(MQuery.OPERATORS[MQuery.BETWEEN_INDEX]))
m_between = true;
boolean enabled = !m_valueToColumn || (m_valueToColumn && m_between);
log.config("(" + value + ") - Enabled=" + enabled);
if (enabled) {
String columnName = null;
Object column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME);
if (column != null)
columnName = ((ValueNamePair) column).getValue();
// Create Editor
GridField field = m_find.getTargetMField(columnName);
// log.fine( "Field=" + field.toStringX());
if (field.isKey())
m_editor = new VNumber(columnName, false, false, true, DisplayType.Integer, columnName);
else
m_editor = VEditorFactory.getEditor(field, true);
if (m_editor == null)
m_editor = new VString();
m_editor.setValue(value);
m_editor.setReadWrite(enabled);
m_editor.setBorder(null);
} else {
m_editor = null;
}
//
return (Component) m_editor;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class FindValueRenderer method getTableCellRendererComponent.
// getCheck
/*************************************************************************
* Get TableCell RendererComponent
* @param table table
* @param value value
* @param isSelected selected
* @param hasFocus focus
* @param row row
* @param col col
* @return renderer component (Label or CheckBox)
*/
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
// log.config( "FindValueRenderer.getTableCellRendererComponent", "r=" + row + ", c=" + col );
// Column
m_columnName = null;
Object column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME);
if (column != null) {
if (column instanceof ValueNamePair)
m_columnName = ((ValueNamePair) column).getValue();
else
m_columnName = column.toString();
}
// Between - enables valueToColumn
m_between = false;
Object betweenValue = table.getModel().getValueAt(row, Find.INDEX_OPERATOR);
if (m_valueToColumn && betweenValue != null && betweenValue.equals(MQuery.OPERATORS[MQuery.BETWEEN_INDEX]))
m_between = true;
boolean enabled = !m_valueToColumn || (m_valueToColumn && m_between);
// set Background
if (enabled)
setBackground(AdempierePLAF.getFieldBackground_Normal());
else
setBackground(AdempierePLAF.getFieldBackground_Inactive());
// log.config( "FindValueRenderer.getTableCellRendererComponent - (" + value + ") - Enabled=" + enabled);
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
if (value == null || (m_valueToColumn && !m_between))
return c;
//
GridField field = getMField();
if (field != null && field.getDisplayType() == DisplayType.YesNo) {
JCheckBox cb = getCheck();
if (value instanceof Boolean)
cb.setSelected(((Boolean) value).booleanValue());
else
cb.setSelected(value.toString().indexOf('Y') != -1);
return cb;
}
return c;
}
use of org.compiere.util.ValueNamePair in project adempiere by adempiere.
the class VPayPrint method cmd_print.
// cmd_EFT
/**
* Print Checks and/or Remittance
*/
private void cmd_print() {
ValueNamePair valueNamePair = (ValueNamePair) fPaymentRule.getSelectedItem();
if (valueNamePair == null)
return;
String paymentRule = valueNamePair.getValue();
log.info(paymentRule);
if (!getChecks(paymentRule))
return;
panel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
AtomicBoolean somethingPrinted = new AtomicBoolean(false);
boolean directPrint = !Ini.isPropertyBool(Ini.P_PRINTPREVIEW);
// for all checks
paySelectionChecks.stream().filter(paySelectionCheck -> paySelectionCheck != null).forEach(paySelectionCheck -> {
boolean ok = ReportCtl.startDocumentPrint(ReportEngine.CHECK, paySelectionCheck.get_ID(), null, Env.getWindowNo(panel), directPrint);
if (!somethingPrinted.get() && ok)
somethingPrinted.set(true);
});
// Confirm Print and Update BankAccountDoc
if (somethingPrinted.get() && ADialog.ask(windowNo, panel, "VPayPrintSuccess?")) {
int lastDocumentNo = MPaySelectionCheck.confirmPrint(paySelectionChecks, paymentBatch);
if (lastDocumentNo != 0) {
StringBuffer sb = new StringBuffer();
sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo).append(" WHERE C_BankAccount_ID=").append(bankAccountId).append(" AND PaymentRule='").append(paymentRule).append("'");
DB.executeUpdate(sb.toString(), null);
}
}
if (ADialog.ask(windowNo, panel, "VPayPrintPrintRemittance")) {
paySelectionChecks.stream().filter(paySelectionCheck -> paySelectionCheck != null).forEach(paySelectionCheck -> {
ReportCtl.startDocumentPrint(ReportEngine.REMITTANCE, paySelectionCheck.get_ID(), null, Env.getWindowNo(panel), directPrint);
});
}
// remittance
panel.setCursor(Cursor.getDefaultCursor());
dispose();
}
Aggregations