From dea8e20bc7dbffd68b9e4233e85c240183b79d0a Mon Sep 17 00:00:00 2001 From: homebeaver Date: Thu, 14 Nov 2019 12:18:57 +0100 Subject: [PATCH] #4 : status quo --- .../com/klst/gossip/GenericDataLoader.java | 73 +++++++++++++++---- .../com/klst/gossip/GenericDataModel.java | 38 ++++++---- 2 files changed, 83 insertions(+), 28 deletions(-) diff --git a/client/src/main/java/com/klst/gossip/GenericDataLoader.java b/client/src/main/java/com/klst/gossip/GenericDataLoader.java index 127dbe5..cd2e269 100644 --- a/client/src/main/java/com/klst/gossip/GenericDataLoader.java +++ b/client/src/main/java/com/klst/gossip/GenericDataLoader.java @@ -6,14 +6,15 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.SwingWorker; import org.adempiere.exceptions.AdempiereException; -import org.compiere.model.GridField; import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.SecureEngine; @@ -43,7 +44,7 @@ public GenericDataLoader(GenericDataModel dm) { private int rowsToFind = -1; // Ergebnis von select count(*) private ResultSet resultSet; private List dbResultRows; - private GridField[] fields = null; + private GridFields fields = null; // GridFields extends DefaultTableColumnModelExt implements TableColumnModelExt private String trxName; /* @@ -68,12 +69,17 @@ protected List doInBackground() throws Exception { fields = dataModel.getColumns(); // Create SELECT Part StringBuffer select = new StringBuffer("SELECT "); - for (int i = 0; i < fields.length; i++) - { - if(i > 0) select.append(","); - GridField field = fields[i]; - select.append(field.getColumnSQL(true)); // ColumnName or Virtual Column // boolean withAS + for(int f=0; f 0) select.append(","); + GridFieldBridge field = (GridFieldBridge)fields.getColumn(f); + select.append(field.getColumnSQL()); // withAS } +// for (int i = 0; i < fields.length; i++) +// { +// if(i > 0) select.append(","); +// GridField field = fields[i]; +// select.append(field.getColumnSQL(true)); // ColumnName or Virtual Column // boolean withAS +// } select.append(" FROM ").append(dataModel.getDbTableName()); sql = select.toString(); LOG.config(sql + ";\n rowsToFind:"+rowsToFind + "; trxName:"+trxName); @@ -124,6 +130,43 @@ private String getSelectClause() { return null; } + private static Map DISPLAYTYPE = new HashMap(); // erleichtert das Testen + static { + DISPLAYTYPE.put(25, "Account"); + DISPLAYTYPE.put(12, "Amount"); + DISPLAYTYPE.put(33, "Assignment"); + DISPLAYTYPE.put(23, "Binary"); + DISPLAYTYPE.put(28, "Button "); + DISPLAYTYPE.put(53370, "Chart"); + DISPLAYTYPE.put(27, "Color"); + DISPLAYTYPE.put(37, "CostPrice"); + DISPLAYTYPE.put(15, "Date"); + DISPLAYTYPE.put(16, "DateTime"); + DISPLAYTYPE.put(39, "FileName"); + DISPLAYTYPE.put(38, "FilePath"); + DISPLAYTYPE.put(53670, "FilePathOrName"); + DISPLAYTYPE.put(13, "ID"); + DISPLAYTYPE.put(32, "Image"); + DISPLAYTYPE.put(11, "Integer"); + DISPLAYTYPE.put(17, "List"); + DISPLAYTYPE.put(21, "Location"); + DISPLAYTYPE.put(31, "Locator"); + DISPLAYTYPE.put(34, "Memo"); + DISPLAYTYPE.put(22, "Number"); + DISPLAYTYPE.put(35, "PAttribute"); + DISPLAYTYPE.put(42, "PrinterName"); + DISPLAYTYPE.put(29, "Quantity"); + DISPLAYTYPE.put(26, "RowID"); + DISPLAYTYPE.put(30, "Search"); + DISPLAYTYPE.put(10, "String"); + DISPLAYTYPE.put(18, "Table"); + DISPLAYTYPE.put(19, "TableDir"); + DISPLAYTYPE.put(14, "Text"); + DISPLAYTYPE.put(36, "TextLong"); + DISPLAYTYPE.put(24, "Time"); + DISPLAYTYPE.put(40, "URL"); + DISPLAYTYPE.put(20, "YesNo"); + } private Object[] readData(ResultSet rs, int row) throws SQLException { int size = dataModel.getColumnCount(); Object[] fieldData = new Object[size]; // renamed from rowData @@ -140,15 +183,19 @@ private Object[] readData(ResultSet rs, int row) throws SQLException { for (int f = 0; f < size; f++) { // field metadata - GridField field = this.fields[f]; + //GridField field = this.fields[f]; + GridFieldBridge field = (GridFieldBridge)fields.getColumn(f); columnName = field.getColumnName(); displayType = field.getDisplayType(); // aka AD_Reference_ID if(row==0) { - LOG.config(f+":SeqNoGrid="+field.getSeqNoGrid() + " columnName="+columnName - + " DisplayType="+displayType + " Field_ID="+field.getAD_Field_ID() - + " Reference="+field.getAD_Reference_Value_ID() + " DefaultValue="+field.getDefaultValue() - + " Tab_ID="+field.getAD_Tab_ID() + " Column_ID="+field.getAD_Column_ID() - ); + LOG.config(f+": SeqNoGrid="+field.getSeqNoGrid() + " DisplayedGrid="+field.isDisplayedGrid() + " Displayed="+field.isDisplayed() + + "\t"+DISPLAYTYPE.get(displayType) + "\t Header="+field.getHeader() + " columnName="+columnName + + " DisplayType="+displayType); +// LOG.config(f+":SeqNoGrid="+field.getSeqNoGrid() + " columnName="+columnName +// + " DisplayType="+displayType + " Field_ID="+field.getAD_Field_ID() +// + " Reference="+field.getAD_Reference_Value_ID() + " DefaultValue="+field.getDefaultValue() +// + " Tab_ID="+field.getAD_Tab_ID() + " Column_ID="+field.getAD_Column_ID() +// ); } if(displayType == DisplayType.String diff --git a/client/src/main/java/com/klst/gossip/GenericDataModel.java b/client/src/main/java/com/klst/gossip/GenericDataModel.java index 84c82e5..f3a36ec 100644 --- a/client/src/main/java/com/klst/gossip/GenericDataModel.java +++ b/client/src/main/java/com/klst/gossip/GenericDataModel.java @@ -8,7 +8,6 @@ import javax.swing.table.AbstractTableModel; -import org.compiere.model.GridField; import org.compiere.model.GridTab; import org.compiere.util.DisplayType; @@ -24,16 +23,21 @@ public class GenericDataModel extends AbstractTableModel { private int windowNo; private GridTab gridTab; - private GridField[] fields = null; + //private GridFieldBridge[] fields = null; // oder noch besser: + private GridFields fields; private int rowsToLoad = -1; // der Loader liefert es // ctor public GenericDataModel(GridTab gridTab, int windowNo) { this.windowNo = windowNo; this.gridTab = gridTab; - this.fields = this.gridTab.getFields(); + this.fields = new GridFields(this.gridTab.getFields()); } + public String toString() { + return getClass().getName() +" windowNo "+windowNo + " gridTab:["+gridTab+"]"; + } + /* * (non-Javadoc) * @see javax.swing.table.TableModel#getRowCount() @@ -49,7 +53,7 @@ public int getRowCount() { */ @Override public int getColumnCount() { - return fields.length; + return fields.getColumnCount(true); // includeHidden } /* @@ -69,15 +73,16 @@ public Object getValueAt(int rowIndex, int columnIndex) { // wird gerufen wenn celle angeckickt public boolean isCellEditable(int rowIndex, int columnIndex) { - GridField field = this.fields[columnIndex]; - boolean isEditable = field.isEditable(false); // checkContext - if(isEditable) { + GridFieldBridge field = (GridFieldBridge)this.fields.getColumn(columnIndex); + boolean isEditable = field.isEditable(); +// GridField field = this.fields[columnIndex]; +// boolean isEditable = field.isEditable(false); // checkContext + if(field.isEditable()) { LOG.config(""+rowIndex+" "+field + "isEditable no context, checkContext:"+field.isEditable(true)); } else { LOG.config(""+rowIndex+" "+field + "isNOTEditable no context"); - return isEditable; // false } - return field.isEditable(true); // checkContext + return isEditable; } // TODO das muss in Tab impementiert werden! @@ -100,8 +105,9 @@ public Object[] getRow(int rowIndex) { * @see javax.swing.table.AbstractTableModel#getColumnClass(int) */ @Override - public Class getColumnClass(int column) { - GridField field = this.fields[column]; + public Class getColumnClass(int columnIndex) { + GridFieldBridge field = (GridFieldBridge)this.fields.getColumn(columnIndex); +// GridField field = this.fields[column]; int displayType = field.getDisplayType(); if(logDisplayType.containsKey(field)) { // schon geloggt @@ -115,12 +121,14 @@ public Class getColumnClass(int column) { // TODO } // wg. LOG - private Map logDisplayType = new Hashtable(); + private Map logDisplayType = new Hashtable(); // <<< @Override - public String getColumnName(int column) { - return fields[column].getColumnName(); + public String getColumnName(int columnIndex) { + GridFieldBridge field = (GridFieldBridge)this.fields.getColumn(columnIndex); + LOG.config("column:"+columnIndex + " ColumnName/Identifier:"+field.getIdentifier() + " Header:"+field.getHeaderValue()); + return field.getColumnName(); } @@ -150,7 +158,7 @@ public int getWindowNo() { return this.windowNo; } - public GridField[] getColumns() { + public GridFields getColumns() { // ===> this.columnModel return this.fields; }