From ff19a0323ceef157dde6e01b2f1ff1e17c37a9b2 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 9 Oct 2007 18:23:25 +0000 Subject: [PATCH] * [ 1798539 ] Cannot Save a User Query * Some UI changes for the new collapse grid features. Victor, please let me know if you don't like some of the changes. --- client/.classpath | 1 + client/src/org/compiere/apps/APanel.java | 10 +- client/src/org/compiere/apps/search/Find.java | 390 ++++++++++++++++-- .../compiere/apps/search/FindCellEditor.java | 154 +++++++ .../apps/search/FindValueRenderer.java | 8 +- .../src/org/compiere/grid/GridController.java | 11 +- client/src/org/compiere/grid/VPanel.java | 49 ++- .../org/compiere/grid/ed/AutoCompletion.java | 8 +- client/src/org/compiere/print/Viewer.java | 2 +- 9 files changed, 582 insertions(+), 51 deletions(-) create mode 100644 client/src/org/compiere/apps/search/FindCellEditor.java diff --git a/client/.classpath b/client/.classpath index d1ff5021d2..860bc76c52 100644 --- a/client/.classpath +++ b/client/.classpath @@ -7,5 +7,6 @@ + diff --git a/client/src/org/compiere/apps/APanel.java b/client/src/org/compiere/apps/APanel.java index b3c5491b57..8bb841e37b 100644 --- a/client/src/org/compiere/apps/APanel.java +++ b/client/src/org/compiere/apps/APanel.java @@ -169,7 +169,11 @@ public final class APanel extends CPanel // tabPanel mainLayout.setHgap(2); mainLayout.setVgap(2); - this.add(tabPanel, BorderLayout.CENTER); + CPanel dummy = new CPanel(); + dummy.setLayout(new BorderLayout()); + dummy.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 2)); + dummy.add(tabPanel, BorderLayout.CENTER); + this.add(dummy, BorderLayout.CENTER); // southPanel this.add(statusBar, BorderLayout.SOUTH); // northPanel @@ -819,7 +823,7 @@ public final class APanel extends CPanel { GridField[] findFields = mTab.getFields(); Find find = new Find (Env.getFrame(this), m_curWindowNo, mTab.getName(), - mTab.getAD_Table_ID(), mTab.getTableName(), + mTab.getAD_Tab_ID(), mTab.getAD_Table_ID(), mTab.getTableName(), where.toString(), findFields, 10); // no query below 10 query = find.getQuery(); isCancel = (query == null);//Goodwill @@ -1934,7 +1938,7 @@ public final class APanel extends CPanel // Gets Fields from AD_Field_v GridField[] findFields = GridField.createFields(m_ctx, m_curWindowNo, 0, m_curTab.getAD_Tab_ID()); Find find = new Find (Env.getFrame(this), m_curWindowNo, m_curTab.getName(), - m_curTab.getAD_Table_ID(), m_curTab.getTableName(), + m_curTab.getAD_Tab_ID(), m_curTab.getAD_Table_ID(), m_curTab.getTableName(), m_curTab.getWhereExtended(), findFields, 1); MQuery query = find.getQuery(); find.dispose(); diff --git a/client/src/org/compiere/apps/search/Find.java b/client/src/org/compiere/apps/search/Find.java index 90b0d1da12..f3a65c30e8 100644 --- a/client/src/org/compiere/apps/search/Find.java +++ b/client/src/org/compiere/apps/search/Find.java @@ -22,6 +22,7 @@ import java.math.*; import java.sql.*; import java.util.*; import java.util.logging.*; +import java.util.regex.Pattern; import javax.swing.*; import javax.swing.event.*; @@ -42,6 +43,8 @@ import org.compiere.util.*; public final class Find extends CDialog implements ActionListener, ChangeListener, DataStatusListener { + private int m_AD_Tab_ID; + /** * Find Constructor * @param owner Frame Dialog Onwer @@ -53,7 +56,7 @@ public final class Find extends CDialog * @param findFields * @param minRecords number of minimum records */ - public Find (Frame owner, int targetWindowNo, String title, + public Find (Frame owner, int targetWindowNo, String title, int AD_Tab_ID, int AD_Table_ID, String tableName, String whereExtended, GridField[] findFields, int minRecords) { @@ -61,6 +64,7 @@ public final class Find extends CDialog log.info(title); // m_targetWindowNo = targetWindowNo; + m_AD_Tab_ID = AD_Tab_ID; //red1 new field for UserQuery [ 1798539 ] m_AD_Table_ID = AD_Table_ID; m_tableName = tableName; m_whereExtended = whereExtended; @@ -140,6 +144,7 @@ public final class Find extends CDialog private ConfirmPanel confirmPanelA = new ConfirmPanel(true, true, false, false, false, false, true); private CButton bIgnore = new CButton(); private JToolBar toolBar = new JToolBar(); + private CComboBox fQueryName = new CComboBox(); private CButton bSave = new CButton(); private CButton bNew = new CButton(); private CButton bDelete = new CButton(); @@ -162,7 +167,30 @@ public final class Find extends CDialog private Component spaceW; private Component spaceS; private JScrollPane advancedScrollPane = new JScrollPane(); - private CTable advancedTable = new CTable(); + private CTable advancedTable = new CTable() { + public boolean isCellEditable(int row, int column) + { + boolean editable = ( column == INDEX_COLUMNNAME + || column == INDEX_OPERATOR ); + if (!editable && row >= 0) + { + String columnName = null; + Object value = + getModel().getValueAt(row, INDEX_COLUMNNAME); + if (value != null) + { + if (value instanceof ValueNamePair) + columnName = ((ValueNamePair)value).getValue(); + else + columnName = value.toString(); + } + + // Create Editor + editable = getTargetMField(columnName) != null; + } + return editable; + } + }; /** Index ColumnName = 0 */ public static final int INDEX_COLUMNNAME = 0; @@ -177,6 +205,11 @@ public final class Find extends CDialog public CComboBox columns = null; /** Advanced Search Operators */ public CComboBox operators = null; + private MUserQuery[] userQueries; + private ValueNamePair[] columnValueNamePairs; + + private static final String FIELD_SEPARATOR = "<^>"; + private static final String SEGMENT_SEPARATOR = "<~>"; /** * Static Init. @@ -204,6 +237,9 @@ public final class Find extends CDialog bIgnore.setMargin(new Insets(2, 2, 2, 2)); bIgnore.setToolTipText(Msg.getMsg(Env.getCtx(),"Ignore")); bIgnore.addActionListener(this); + fQueryName.setToolTipText (Msg.getMsg(Env.getCtx(),"QueryName")); + fQueryName.setEditable(true); + fQueryName.addActionListener(this); bSave.setIcon(new ImageIcon(org.compiere.Adempiere.class.getResource("images/Save24.gif"))); bSave.setMargin(new Insets(2, 2, 2, 2)); bSave.setToolTipText(Msg.getMsg(Env.getCtx(),"Save")); @@ -275,8 +311,9 @@ public final class Find extends CDialog toolBar.add(bIgnore, null); toolBar.addSeparator(); toolBar.add(bNew, null); - toolBar.add(bSave, null); toolBar.add(bDelete, null); + toolBar.add(fQueryName, null); + toolBar.add(bSave, null); advancedPanel.setLayout(advancedLayout); advancedPanel.add(toolBar, BorderLayout.NORTH); advancedPanel.add(confirmPanelA, BorderLayout.SOUTH); @@ -300,6 +337,7 @@ public final class Find extends CDialog cmd_cancel(); } }); + } // jbInit /** @@ -419,8 +457,41 @@ public final class Find extends CDialog { log.config(""); advancedTable.setModel(new DefaultTableModel(0, 4)); - advancedTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); + 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() + { + 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() + { + 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 items = new ArrayList(); for (int c = 0; c < m_findFields.length; c++) @@ -440,35 +511,68 @@ public final class Find extends CDialog // System.out.println(pp + " = " + field); items.add(pp); } - ValueNamePair[] cols = new ValueNamePair[items.size()]; - items.toArray(cols); - Arrays.sort(cols); // sort alpha - columns = new CComboBox(cols); - columns.addActionListener(this); + columnValueNamePairs = new ValueNamePair[items.size()]; + items.toArray(columnValueNamePairs); + Arrays.sort(columnValueNamePairs); // sort alpha + columns = new CComboBox(columnValueNamePairs); + columns.addActionListener(this); TableColumn tc = advancedTable.getColumnModel().getColumn(INDEX_COLUMNNAME); tc.setPreferredWidth(150); - tc.setCellEditor(new DefaultCellEditor(columns)); + 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")); // 1 = Operators operators = new CComboBox(MQuery.OPERATORS); tc = advancedTable.getColumnModel().getColumn(INDEX_OPERATOR); tc.setPreferredWidth(40); - tc.setCellEditor(new DefaultCellEditor(operators)); + dce = new FindCellEditor(operators); + tc.setCellEditor(dce); tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "Operator")); // 2 = QueryValue tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE); - tc.setCellEditor(new FindValueEditor(this, false)); - tc.setCellRenderer(new FindValueRenderer(this, false)); + FindValueEditor fve = new FindValueEditor(this, false); + tc.setCellEditor(fve); + tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false))); tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue")); // 3 = QueryValue2 tc = advancedTable.getColumnModel().getColumn(INDEX_VALUE2); tc.setPreferredWidth(50); - tc.setCellEditor(new FindValueEditor(this, true)); - tc.setCellRenderer(new FindValueRenderer(this, true)); + fve = new FindValueEditor(this, false); + tc.setCellEditor(fve); + tc.setCellRenderer(new ProxyRenderer(new FindValueRenderer(this, false))); tc.setHeaderValue(Msg.getMsg(Env.getCtx(), "QueryValue2")); + + AutoCompletion.enable(columns); + AutoCompletion.enable(operators); + + //user query + userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID); + String[] queries = new String[userQueries.length]; + for (int i = 0; i < userQueries.length; i++) + queries[i] = userQueries[i].getName(); + fQueryName.setModel(new DefaultComboBoxModel(queries)); + fQueryName.setValue(""); // No Row - Create one cmd_new(); @@ -530,16 +634,29 @@ public final class Find extends CDialog else if (e.getSource() == bNew) cmd_new(); else if (e.getSource() == bSave) - cmd_save(); + cmd_save(true); else if (e.getSource() == bDelete) cmd_delete(); // else if (e.getSource() == columns) { - ValueNamePair column = (ValueNamePair)columns.getSelectedItem(); - if (column != null) + 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) { - String columnName = column.getValue(); log.config("Column: " + columnName); if (columnName.endsWith("_ID") || columnName.endsWith("_Acct")) operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS_ID)); @@ -549,15 +666,84 @@ public final class Find extends CDialog operators.setModel(new DefaultComboBoxModel(MQuery.OPERATORS)); } } + else if (e.getSource() == fQueryName) + { + Object o = fQueryName.getSelectedItem(); + if (userQueries != null && o != null) + { + String selected = o.toString(); + for (int i = 0; i < userQueries.length; i++) + { + if (userQueries[i].getName().equals(selected)) + { + parseUserQuery(userQueries[i]); + return; + } + } + } + } else // ConfirmPanel.A_OK and enter in fields { if (e.getSource() == confirmPanelA.getOKButton()) cmd_ok_Advanced(); - else + else if (e.getSource() == confirmPanelS.getOKButton()) + cmd_ok_Simple(); + else if (e.getSource() instanceof JTextField && + tabbedPane.getSelectedIndex() == 0) cmd_ok_Simple(); } } // actionPerformed + private void parseUserQuery(MUserQuery userQuery) { + String code = userQuery.getCode(); + String[] segments = code.split(Pattern.quote(SEGMENT_SEPARATOR)); + advancedTable.stopEditor(true); + DefaultTableModel model = (DefaultTableModel)advancedTable.getModel(); + int cnt = model.getRowCount(); + for (int i = cnt - 1; i >=0; i--) + model.removeRow(i); + + for (int i = 0; i < segments.length; i++) + { + String[] fields = segments[i].split(Pattern.quote(FIELD_SEPARATOR)); + model.addRow(new Object[] {null, MQuery.OPERATORS[MQuery.EQUAL_INDEX], null, null}); + String columnName = null; + for (int j = 0; j < fields.length; j++) + { + if (j == INDEX_COLUMNNAME) + { + for (ValueNamePair vnp : columnValueNamePairs) + { + if (vnp.getValue().equals(fields[j])) + { + model.setValueAt(vnp, i, j); + columnName = fields[j]; + break; + } + } + } + else if (j == INDEX_OPERATOR) + { + for (ValueNamePair vnp : MQuery.OPERATORS) + { + if (vnp.getValue().equals(fields[j])) + { + model.setValueAt(vnp, i, j); + break; + } + } + } + else + { + GridField field = getTargetMField(columnName); + Object value = parseString(field, fields[j]); + model.setValueAt(value, i, j); + } + } + } + advancedTable.invalidate(); + } + /** * Change Listener (tab change) * @param e ChangeEbent @@ -571,6 +757,7 @@ public final class Find extends CDialog { initFindAdvanced(); this.getRootPane().setDefaultButton(confirmPanelA.getOKButton()); + advancedTable.requestFocusInWindow(); } } // stateChanged @@ -661,7 +848,7 @@ public final class Find extends CDialog m_isCancel = false; // teo_sarca [ 1708717 ] // save pending if (bSave.isEnabled()) - cmd_save(); + cmd_save(false); if (getNoOfRecords(m_query, true) != 0) dispose(); } // cmd_ok_Advanced @@ -671,6 +858,7 @@ public final class Find extends CDialog */ private void cmd_cancel() { + advancedTable.stopEditor(false); log.info(""); m_query = null; m_total = 999999; @@ -691,30 +879,34 @@ public final class Find extends CDialog */ private void cmd_new() { - log.info(""); + advancedTable.stopEditor(true); DefaultTableModel model = (DefaultTableModel)advancedTable.getModel(); model.addRow(new Object[] {null, MQuery.OPERATORS[MQuery.EQUAL_INDEX], null, null}); + advancedTable.requestFocusInWindow(); } // cmd_new /** * Save (Advanced) */ - private void cmd_save() + private void cmd_save(boolean saveQuery) { - log.info(""); advancedTable.stopEditor(true); // m_query = new MQuery(m_tableName); + StringBuffer code = new StringBuffer(); for (int row = 0; row < advancedTable.getRowCount(); row++) { // Column Object column = advancedTable.getValueAt(row, INDEX_COLUMNNAME); if (column == null) continue; - String ColumnName = ((ValueNamePair)column).getValue(); + String ColumnName = column instanceof ValueNamePair ? + ((ValueNamePair)column).getValue() : column.toString(); String infoName = column.toString(); // GridField field = getTargetMField(ColumnName); + if (field == null) + continue; boolean isProductCategoryField = isProductCategoryField(field.getAD_Column_ID()); String ColumnSQL = field.getColumnSQL(false); // Op @@ -736,9 +928,10 @@ public final class Find extends CDialog else if (field.getDisplayType() == DisplayType.YesNo) infoDisplay = Msg.getMsg(Env.getCtx(), infoDisplay); // Value2 ****** + Object value2 = null; if (MQuery.OPERATORS[MQuery.BETWEEN_INDEX].equals(op)) { - Object value2 = advancedTable.getValueAt(row, INDEX_VALUE2); + value2 = advancedTable.getValueAt(row, INDEX_VALUE2); if (value2 == null) continue; Object parsedValue2 = parseValue(field, value2); @@ -759,9 +952,67 @@ public final class Find extends CDialog else m_query.addRestriction(ColumnSQL, Operator, parsedValue, infoName, infoDisplay); + + if (code.length() > 0) + code.append(SEGMENT_SEPARATOR); + code.append(ColumnName) + .append(FIELD_SEPARATOR) + .append(Operator) + .append(FIELD_SEPARATOR) + .append(value.toString()) + .append(FIELD_SEPARATOR) + .append(value2 != null ? value2.toString() : ""); + } + Object selected = fQueryName.getSelectedItem(); + if (selected != null && saveQuery) { + String name = selected.toString(); + MUserQuery uq = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID, name); + if (uq == null && code.length() > 0) + { + uq = new MUserQuery (Env.getCtx(), 0, null); + uq.setName (name); + uq.setAD_Tab_ID(m_AD_Tab_ID); //red1 UserQuery [ 1798539 ] taking in new field from Compiere + uq.setAD_User_ID(Env.getAD_User_ID(Env.getCtx())); //red1 - [ 1798539 ] missing in Compiere delayed source :-) + } + else if (uq != null && code.length() == 0) + { + if (uq.delete(true)) + { + ADialog.info (m_targetWindowNo, this, "Deleted", name); + refreshUserQueries(); + } + else + ADialog.warn (m_targetWindowNo, this, "DeleteError", name); + return; + } + else + return; + uq.setCode (code.toString()); + uq.setAD_Table_ID (m_AD_Table_ID); + // + if (uq.save()) + { + ADialog.info (m_targetWindowNo, this, "Saved", name); + refreshUserQueries(); + } + else + ADialog.warn (m_targetWindowNo, this, "SaveError", name); } } // cmd_save + private void refreshUserQueries() + { + Object selected = fQueryName.getSelectedItem(); + userQueries = MUserQuery.get(Env.getCtx(), m_AD_Tab_ID); + String[] queries = new String[userQueries.length]; + for (int i = 0; i < userQueries.length; i++) + queries[i] = userQueries[i].getName(); + fQueryName.setModel(new DefaultComboBoxModel(queries)); + fQueryName.setSelectedItem(selected); + if (fQueryName.getSelectedIndex() < 0) + fQueryName.setValue(""); + } + /** * Checks the given column. * @param columnId @@ -927,17 +1178,71 @@ public final class Find extends CDialog return in; } // parseValue + /** + * Parse String + * @param field column + * @param in value + * @return data type corected value + */ + private Object parseString(GridField field, String in) + { + if (in == null) + return null; + int dt = field.getDisplayType(); + try + { + // Return Integer + if (dt == DisplayType.Integer + || (DisplayType.isID(dt) && field.getColumnName().endsWith("_ID"))) + { + int i = Integer.parseInt(in); + return new Integer(i); + } + // Return BigDecimal + else if (DisplayType.isNumeric(dt)) + { + return DisplayType.getNumberFormat(dt).parse(in); + } + // Return Timestamp + else if (DisplayType.isDate(dt)) + { + long time = 0; + try + { + time = DisplayType.getDateFormat_JDBC().parse(in).getTime(); + return new Timestamp(time); + } + catch (Exception e) + { + log.log(Level.SEVERE, in + "(" + in.getClass() + ")" + e); + time = DisplayType.getDateFormat(dt).parse(in).getTime(); + } + return new Timestamp(time); + } + else if (dt == DisplayType.YesNo) + return Boolean.valueOf(in); + else + return in; + } + catch (Exception ex) + { + log.log(Level.SEVERE, "Object=" + in, ex); + return null; + } + + } // parseValue /** * Delete */ private void cmd_delete() { - log.info(""); + advancedTable.stopEditor(false); DefaultTableModel model = (DefaultTableModel)advancedTable.getModel(); int row = advancedTable.getSelectedRow(); if (row >= 0) model.removeRow(row); - cmd_refresh(); + cmd_refresh(); + advancedTable.requestFocusInWindow(); } // cmd_delete /** @@ -945,7 +1250,7 @@ public final class Find extends CDialog */ private void cmd_refresh() { - log.info(""); + advancedTable.stopEditor(false); int records = getNoOfRecords(m_query, true); setStatusDB (records); statusBar.setStatusLine(""); @@ -1088,5 +1393,32 @@ public final class Find extends CDialog } return null; } // getTargetMField + + private class ProxyRenderer implements TableCellRenderer + { + /** + * Creates a Find.ProxyRenderer. + */ + public ProxyRenderer(TableCellRenderer renderer) + { + this.m_renderer = renderer; + } + + /** The renderer. */ + private TableCellRenderer m_renderer; + + /** + * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) + */ + public Component getTableCellRendererComponent(final JTable table, + Object value, boolean isSelected, boolean hasFocus, final int row, final int col) + { + Component comp = m_renderer.getTableCellRendererComponent(table, + value, isSelected, hasFocus, row, col); + if (hasFocus && table.isCellEditable(row, col)) + table.editCellAt(row, col); + return comp; + } + } // ProxyRenderer } // Find diff --git a/client/src/org/compiere/apps/search/FindCellEditor.java b/client/src/org/compiere/apps/search/FindCellEditor.java new file mode 100644 index 0000000000..137fad1366 --- /dev/null +++ b/client/src/org/compiere/apps/search/FindCellEditor.java @@ -0,0 +1,154 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * For the text or an alternative of this public license, you may reach us * + * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * + * or via info@compiere.org or http://www.compiere.org/license.html * + *****************************************************************************/ +package org.compiere.apps.search; + +import java.awt.*; +import java.awt.event.*; +import java.beans.*; +import java.util.*; +import javax.swing.*; +import javax.swing.table.*; + +import org.adempiere.plaf.AdempierePLAF; +import org.compiere.grid.ed.VComboBox; +import org.compiere.model.*; +import org.compiere.swing.CEditor; +import org.compiere.util.*; + +/** + * Cell Editor. + *
+ *		Sequence of events:
+ *			isCellEditable
+ *			getTableCellEditor
+ *			shouldSelectCell
+ *			getCellEditorValue
+ *  
+ * A new Editor is created for editable columns. + * @author Jorg Janke + * @version $Id: VCellEditor.java,v 1.2 2006/07/30 00:51:28 jjanke Exp $ + */ +public final class FindCellEditor extends AbstractCellEditor + implements TableCellEditor, ActionListener +{ + /** + * Constructor for Grid + * @param mField + */ + public FindCellEditor (CEditor component) + { + super(); + m_editor = component; + //m_editor.addActionListener(this); + // Click + } // FindCellEditor + + /** The Table Editor */ + private CEditor m_editor = null; + /** Table */ + private JTable m_table = null; + /** ClickCount */ + private static int CLICK_TO_START = 1; + /** Logger */ + private static CLogger log = CLogger.getCLogger(FindCellEditor.class); + + + /** + * @param anEvent event + * @return true if editable + */ + public boolean isCellEditable (EventObject anEvent) + { + return true; + } // isCellEditable + + /** + * Sets an initial value for the editor. This will cause the editor to + * stopEditing and lose any partially edited value if the editor is editing + * when this method is called. + * Returns the component that should be added to the client's Component hierarchy. + * Once installed in the client's hierarchy this component + * will then be able to draw and receive user input. + * + * @param table + * @param value + * @param isSelected + * @param row + * @param col + * @return component + */ + public Component getTableCellEditorComponent (JTable table, Object value, boolean isSelected, int row, int col) + { + if (row >= 0) + table.setRowSelectionInterval(row,row); // force moving to new row + + m_table = table; + + // Set Value + m_editor.setValue(value); + + // Set Background/Foreground to "normal" (unselected) colors + ((JComponent)m_editor).setForeground(AdempierePLAF.getTextColor_Normal()); + + // Other UI + ((JComponent)m_editor).setFont(table.getFont()); + if ( m_editor instanceof JComboBox) { + ((JComboBox)m_editor).setBorder(BorderFactory.createEmptyBorder()); + } else { + ((JComponent)m_editor).setBorder(UIManager.getBorder("Table.focusCellHighlightBorder")); + } + // + return (Component)m_editor; + } // getTableCellEditorComponent + + /** + * The editing cell should be selected or not + * @param e event + * @return true (constant) + */ + public boolean shouldSelectCell(EventObject e) + { + return true; + } // shouldSelectCell + + /** + * Returns the value contained in the editor + * @return value + */ + public Object getCellEditorValue() + { + return m_editor.getValue(); + } // getCellEditorValue + + /** + * Action Editor - Stop Editor + * @param e event + */ + public void actionPerformed (ActionEvent e) + { + } + + /** + * Dispose + */ + public void dispose() + { + m_editor = null; + m_table = null; + } // dispose + +} // FindCellEditor diff --git a/client/src/org/compiere/apps/search/FindValueRenderer.java b/client/src/org/compiere/apps/search/FindValueRenderer.java index 487313b2d9..4322288604 100644 --- a/client/src/org/compiere/apps/search/FindValueRenderer.java +++ b/client/src/org/compiere/apps/search/FindValueRenderer.java @@ -94,8 +94,12 @@ public final class FindValueRenderer extends DefaultTableCellRenderer // Column m_columnName = null; Object column = table.getModel().getValueAt(row, Find.INDEX_COLUMNNAME); - if (column != null) - m_columnName = ((ValueNamePair)column).getValue(); + if (column != null) { + if (column instanceof ValueNamePair) + m_columnName = ((ValueNamePair)column).getValue(); + else + m_columnName = column.toString(); + } // Between - enables valueToColumn m_between = false; diff --git a/client/src/org/compiere/grid/GridController.java b/client/src/org/compiere/grid/GridController.java index d6e1662ce5..8387a6a7c4 100644 --- a/client/src/org/compiere/grid/GridController.java +++ b/client/src/org/compiere/grid/GridController.java @@ -147,7 +147,7 @@ public class GridController extends CPanel private GridController detail = null; private CScrollPane mrPane = new CScrollPane(); private CPanel xPanel = new CPanel(); - private FlowLayout xLayout = new FlowLayout(); + private BorderLayout xLayout = new BorderLayout(); private VTable vTable = new VTable(); //FR [ 1757088 ] private VPanel vPanel = null; @@ -185,7 +185,8 @@ public class GridController extends CPanel //FR [ 1757088 ] xPanel.add(vPanel); xPanel.setLayout(xLayout); xPanel.setName("gc_xPanel"); - xLayout.setAlignment(FlowLayout.LEFT); + xPanel.setBorder(BorderFactory.createEmptyBorder()); + //xLayout.setAlignment(FlowLayout.LEFT); xLayout.setHgap(0); xLayout.setVgap(0); // multi-row @@ -196,6 +197,8 @@ public class GridController extends CPanel graphPanel.setBorder(null); graphPanel.setName("gc_graphPanel"); srPane.setDividerLocation(200); + + vPane.setBorder(BorderFactory.createEmptyBorder()); } // jbInit /** @@ -301,9 +304,9 @@ public class GridController extends CPanel m_aPanel = aPanel; setName("GC-" + mTab); //FR [ 1757088 ] - vPanel = new VPanel(mWindow.getName()); + vPanel = new VPanel(mTab.getName()); vPane.getViewport().add(xPanel, null); - xPanel.add(vPanel); + xPanel.add(vPanel, BorderLayout.CENTER); setTabLevel(m_mTab.getTabLevel()); diff --git a/client/src/org/compiere/grid/VPanel.java b/client/src/org/compiere/grid/VPanel.java index 514c760e98..c63743cff6 100644 --- a/client/src/org/compiere/grid/VPanel.java +++ b/client/src/org/compiere/grid/VPanel.java @@ -23,6 +23,7 @@ import javax.swing.*; import java.util.*; // +import org.adempiere.plaf.AdempierePLAF; import org.compiere.grid.ed.*; import org.compiere.model.*; import org.compiere.swing.*; @@ -57,6 +58,9 @@ import org.compiere.util.*; */ public final class VPanel extends CTabbedPane { + static { + UIManager.put("TaskPaneContainer.useGradient", Boolean.FALSE); + } /** * Constructor @@ -64,12 +68,20 @@ public final class VPanel extends CTabbedPane public VPanel(String Name) { //[ 1757088 ] - CTabbedPane T = new CTabbedPane(); m_main.setName(Name); m_main.setLayout(new GridBagLayout()); m_tablist.put("main", m_main); this.setBorder(marginBorder); - this.add(m_main); + CPanel dummy = new CPanel(); + FlowLayout f = new FlowLayout(); + f.setAlignment(FlowLayout.LEFT); + f.setHgap(0); + f.setVgap(0); + dummy.setBorder(BorderFactory.createEmptyBorder()); + dummy.setLayout(f); + dummy.add(m_main); + dummy.setName(m_main.getName()); + this.add(dummy); // Set initial values of constraint m_gbc.anchor = GridBagConstraints.NORTHWEST; @@ -155,10 +167,10 @@ public final class VPanel extends CTabbedPane m_gbc.gridx = 0; m_gbc.gridy = m_line++; m_gbc.gridwidth = 4; - org.jdesktop.swingx.JXTaskPaneContainer GroupPaneContainer = new org.jdesktop.swingx.JXTaskPaneContainer(); - org.jdesktop.swingx.JXTaskPane m_tab = new org.jdesktop.swingx.JXTaskPane(); + org.jdesktop.swingx.JXTaskPaneContainer GroupPaneContainer = createTaskPaneContainer(); + org.jdesktop.swingx.JXTaskPane m_tab = new org.jdesktop.swingx.JXTaskPane(); + m_tab.getContentPane().setBackground(AdempierePLAF.getFormBackground()); m_tab.setLayout(new BorderLayout()); - GroupPaneContainer.setBackground(org.compiere.plaf.CompiereColor.getDefaultBackground().getFlatColor()); GroupPaneContainer.add(m_tab); m_tabincludelist.put(AD_Tab_ID, m_tab); m_gbc.anchor = GridBagConstraints.NORTHWEST; @@ -319,7 +331,16 @@ public final class VPanel extends CTabbedPane CPanel m_tab = new CPanel(org.compiere.plaf.CompiereColor.getDefaultBackground()); m_tab.setLayout(new GridBagLayout()); m_tab.setName(fieldGroup); - this.add(m_tab); + CPanel dummy = new CPanel(); + FlowLayout f = new FlowLayout(); + f.setAlignment(FlowLayout.LEFT); + f.setHgap(0); + f.setVgap(0); + dummy.setLayout(f); + dummy.setBorder(BorderFactory.createEmptyBorder()); + dummy.add(m_tab); + dummy.setName(m_tab.getName()); + this.add(dummy); m_tablist.put(fieldGroup, m_tab); m_oldFieldGroup= fieldGroup; return true; @@ -327,9 +348,9 @@ public final class VPanel extends CTabbedPane } else if (typeGroup == 2) { - org.jdesktop.swingx.JXTaskPaneContainer GroupPaneContainer = new org.jdesktop.swingx.JXTaskPaneContainer(); - org.jdesktop.swingx.JXTaskPane m_tab = new org.jdesktop.swingx.JXTaskPane(); - GroupPaneContainer.setBackground(org.compiere.plaf.CompiereColor.getDefaultBackground().getFlatColor()); + org.jdesktop.swingx.JXTaskPaneContainer GroupPaneContainer = createTaskPaneContainer(); + org.jdesktop.swingx.JXTaskPane m_tab = new org.jdesktop.swingx.JXTaskPane(); + m_tab.getContentPane().setBackground(AdempierePLAF.getFormBackground()); m_tab.setLayout(new GridBagLayout()); m_tab.setTitle(fieldGroup); @@ -368,6 +389,16 @@ public final class VPanel extends CTabbedPane return false; } // addGroup + private org.jdesktop.swingx.JXTaskPaneContainer createTaskPaneContainer() { + Color c = AdempierePLAF.getFormBackground(); + Color containerBg = new Color(Math.max((int)(c.getRed() * 0.97), 0), + Math.max((int)(c.getGreen()*0.97), 0), + Math.max((int)(c.getBlue() *0.97), 0)); + org.jdesktop.swingx.JXTaskPaneContainer GroupPaneContainer = new org.jdesktop.swingx.JXTaskPaneContainer(); + GroupPaneContainer.setBackground(containerBg); + return GroupPaneContainer; + } + /** * Add Top (10) and right (12) gap */ diff --git a/client/src/org/compiere/grid/ed/AutoCompletion.java b/client/src/org/compiere/grid/ed/AutoCompletion.java index 0675442a08..7611541c96 100644 --- a/client/src/org/compiere/grid/ed/AutoCompletion.java +++ b/client/src/org/compiere/grid/ed/AutoCompletion.java @@ -5,6 +5,8 @@ import java.beans.PropertyChangeListener; import javax.swing.*; import javax.swing.text.*; +import org.compiere.swing.CComboBox; + //phib: this is from http://www.orbital-computer.de/JComboBox //with some minor revisions for Adempiere @@ -14,7 +16,7 @@ import javax.swing.text.*; * http://creativecommons.org/licenses/publicdomain/ */ public class AutoCompletion extends PlainDocument { - VComboBox comboBox; + CComboBox comboBox; ComboBoxModel model; JTextComponent editor; // flag to indicate if setSelectedItem has been called @@ -27,7 +29,7 @@ public class AutoCompletion extends PlainDocument { KeyListener editorKeyListener; FocusListener editorFocusListener; - public AutoCompletion(final VComboBox comboBox) { + public AutoCompletion(final CComboBox comboBox) { this.comboBox = comboBox; model = comboBox.getModel(); comboBox.addActionListener(new ActionListener() { @@ -81,7 +83,7 @@ public class AutoCompletion extends PlainDocument { highlightCompletedText(0); } - public static void enable(VComboBox comboBox) { + public static void enable(CComboBox comboBox) { // has to be editable comboBox.setEditable(true); // change the editor's document diff --git a/client/src/org/compiere/print/Viewer.java b/client/src/org/compiere/print/Viewer.java index 7967f94ac8..2418357bd7 100644 --- a/client/src/org/compiere/print/Viewer.java +++ b/client/src/org/compiere/print/Viewer.java @@ -989,7 +989,7 @@ public class Viewer extends CFrame else { Find find = new Find (this, m_WindowNo, title, - AD_Table_ID, tableName, "", findFields, 1); + AD_Tab_ID, AD_Table_ID, tableName, "", findFields, 1); m_reportEngine.setQuery(find.getQuery()); find.dispose(); find = null;