Skip to content

Commit

Permalink
#4 : status quo
Browse files Browse the repository at this point in the history
  • Loading branch information
homebeaver committed Nov 14, 2019
1 parent d12297a commit dea8e20
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 28 deletions.
73 changes: 60 additions & 13 deletions client/src/main/java/com/klst/gossip/GenericDataLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +44,7 @@ public GenericDataLoader(GenericDataModel dm) {
private int rowsToFind = -1; // Ergebnis von select count(*)
private ResultSet resultSet;
private List<Object[]> dbResultRows;
private GridField[] fields = null;
private GridFields fields = null; // GridFields extends DefaultTableColumnModelExt implements TableColumnModelExt
private String trxName;

/*
Expand All @@ -68,12 +69,17 @@ protected List<Object[]> 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<fields.getColumnCount(true); f++) {
if(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);
Expand Down Expand Up @@ -124,6 +130,43 @@ private String getSelectClause() {
return null;
}

private static Map<Integer,String> DISPLAYTYPE = new HashMap<Integer,String>(); // 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
Expand All @@ -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
Expand Down
38 changes: 23 additions & 15 deletions client/src/main/java/com/klst/gossip/GenericDataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import javax.swing.table.AbstractTableModel;

import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.util.DisplayType;

Expand All @@ -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()
Expand All @@ -49,7 +53,7 @@ public int getRowCount() {
*/
@Override
public int getColumnCount() {
return fields.length;
return fields.getColumnCount(true); // includeHidden
}

/*
Expand All @@ -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!
Expand All @@ -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
Expand All @@ -115,12 +121,14 @@ public Class<?> getColumnClass(int column) {
// TODO
}
// wg. LOG
private Map<GridField, Integer> logDisplayType = new Hashtable<GridField, Integer>();
private Map<GridFieldBridge, Integer> logDisplayType = new Hashtable<GridFieldBridge, Integer>();
// <<<

@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();
}


Expand Down Expand Up @@ -150,7 +158,7 @@ public int getWindowNo() {
return this.windowNo;
}

public GridField[] getColumns() {
public GridFields getColumns() { // ===> this.columnModel
return this.fields;
}

Expand Down

0 comments on commit dea8e20

Please sign in to comment.