diff --git a/org.adempiere.base/.classpath b/org.adempiere.base/.classpath index dcf6057cbc..7422ec0fd6 100644 --- a/org.adempiere.base/.classpath +++ b/org.adempiere.base/.classpath @@ -11,6 +11,7 @@ + diff --git a/org.adempiere.base/META-INF/MANIFEST.MF b/org.adempiere.base/META-INF/MANIFEST.MF index 0878765dfd..fabf71bca5 100644 --- a/org.adempiere.base/META-INF/MANIFEST.MF +++ b/org.adempiere.base/META-INF/MANIFEST.MF @@ -17,7 +17,8 @@ Bundle-ClassPath: base.jar, jnlp.jar, groovy-all-1.7.5.jar, vt-dictionary-3.0.jar, - vt-password-3.1.1.jar + vt-password-3.1.1.jar, + super-csv-2.0.0-beta-1.jar Export-Package: bsh, bsh.classpath, bsh.collection, @@ -237,7 +238,14 @@ Export-Package: bsh, org.jfree.ui.about.resources, org.jfree.ui.action, org.jfree.ui.tabbedui, - org.jfree.util + org.jfree.util, + org.supercsv.cellprocessor, + org.supercsv.cellprocessor.constraint, + org.supercsv.cellprocessor.ift, + org.supercsv.exception, + org.supercsv.io, + org.supercsv.prefs, + org.supercsv.util Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Import-Package: com.sun.mail.smtp;version="1.4.0", javax.jms;version="1.1.0", diff --git a/org.adempiere.base/build.properties b/org.adempiere.base/build.properties index e463d35f12..b6a4bb78c8 100644 --- a/org.adempiere.base/build.properties +++ b/org.adempiere.base/build.properties @@ -15,7 +15,8 @@ bin.includes = META-INF/,\ OSGI-INF/,\ groovy-all-1.7.5.jar,\ vt-dictionary-3.0.jar,\ - vt-password-3.1.1.jar + vt-password-3.1.1.jar,\ + super-csv-2.0.0-beta-1.jar output.base.jar = build/ source.base.jar = src/ src.includes = schema/ diff --git a/org.adempiere.base/plugin.xml b/org.adempiere.base/plugin.xml index 41d31e82ee..79aa4c8727 100644 --- a/org.adempiere.base/plugin.xml +++ b/org.adempiere.base/plugin.xml @@ -42,6 +42,15 @@ priority="0"> + + + + childs, boolean currentRowOnly, File file) { + + ICsvMapWriter mapWriter = null; + try { + mapWriter = new CsvMapWriter(new FileWriter(file), CsvPreference.STANDARD_PREFERENCE); + GridTable gt = gridTab.getTableModel(); + GridField[] gridFields = getFields(gridTab); + List headArray = new ArrayList(); + List colsArray = new ArrayList(); + List procArray = new ArrayList(); + MTable table = MTable.get(Env.getCtx(), gridTab.getTableName()); + for (int idxfld = 0; idxfld < gridFields.length; idxfld++) { + GridField field = gridFields[idxfld]; + colsArray.add(field.getColumnName()); + MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); + String headName = resolveColumnName(table, column); + headArray.add(headName); + if (DisplayType.Date == column.getAD_Reference_ID()) { + procArray.add(new Optional(new FmtDate(DisplayType.DEFAULT_DATE_FORMAT))); + } else if (DisplayType.DateTime == column.getAD_Reference_ID()) { + procArray.add(new Optional(new FmtDate(DisplayType.DEFAULT_TIMESTAMP_FORMAT))); + } else if (DisplayType.Time == column.getAD_Reference_ID()) { + procArray.add(new Optional(new FmtDate("DisplayType.DEFAULT_TIME_FORMAT"))); + } else if (DisplayType.Integer == column.getAD_Reference_ID() || DisplayType.isNumeric(column.getAD_Reference_ID())) { + procArray.add(new Optional(new FmtNumber(DisplayType.getNumberFormat(column.getAD_Reference_ID())))); + } else if (DisplayType.YesNo == column.getAD_Reference_ID()) { + procArray.add(new Optional(new FmtBool("Y", "N"))); + } else { // lookups and text + procArray.add(null); + } + } + // the header elements are used to map the bean values to each column (names must match) + String[] header = headArray.toArray(new String[headArray.size()]); + CellProcessor[] processors = procArray.toArray(new CellProcessor[procArray.size()]); + // write the header + mapWriter.writeHeader(header); + // write the beans + int start = 0; + int end = 0; + if (currentRowOnly) { + start = gridTab.getCurrentRow(); + end = start + 1; + } else { + end = gt.getRowCount(); + } + for (int idxrow = start; idxrow < end; idxrow++) { + Map row = new HashMap(); + for (int idxfld = 0; idxfld < header.length; idxfld++) { + GridField field = gridFields[idxfld]; + MColumn column = MColumn.get(Env.getCtx(), field.getAD_Column_ID()); + String headName = header[idxfld]; + Object value = resolveValue(gridTab, table, column, idxrow, headName); + row.put(headName, value); + } + mapWriter.write(row, header, processors); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (mapWriter != null) { + try { + mapWriter.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + } + + private Object resolveValue(GridTab gridTab, MTable table, MColumn column, int i, String headName) { + Object value = null; + if (headName.contains("[") && headName.endsWith("]")) { + String foreignTable = column.getReferenceTableName(); + Object idO = gridTab.getValue(i, column.getColumnName()); + if (idO != null) { + if (foreignTable.equals("AD_Ref_List")) { + String ref = (String) idO; + value = MRefList.getListName(Env.getCtx(), column.getAD_Reference_Value_ID(), ref); + } else { + int id = (Integer) idO; + int start = headName.indexOf("[")+1; + int end = headName.length()-1; + String foreignColumn = headName.substring(start, end); + StringBuilder select = new StringBuilder("SELECT ") + .append(foreignColumn).append(" FROM ") + .append(foreignTable).append(" WHERE ") + .append(foreignTable).append("_ID=?"); + value = DB.getSQLValueStringEx(null, select.toString(), id); + } + } + } else { + value = gridTab.getValue(i, headName); + } + return value; + } + + private String resolveColumnName(MTable table, MColumn column) { + StringBuilder name = new StringBuilder(column.getColumnName()); + if (DisplayType.isLookup(column.getAD_Reference_ID())) { + // resolve to identifier - search for value first, if not search for name - if not use the ID + String foreignTable = column.getReferenceTableName(); + if ( ! ("AD_Language".equals(foreignTable) || "AD_EntityType".equals(foreignTable))) { + MTable fTable = MTable.get(Env.getCtx(), foreignTable); + // Hardcoded / do not check for Value on AD_Org and AD_User, must use name for these two tables + if (! ("AD_Org".equals(foreignTable) || "AD_User".equals(foreignTable)) + && fTable.getColumn("Value") != null) { + name.append("[Value]"); // fully qualified + } else if (fTable.getColumn("Name") != null) { + name.append("[Name]"); + } + } + } + return name.toString(); + } + + @Override + public String getFileExtension() { + return "csv"; + } + + @Override + public String getFileExtensionLabel() { + return Msg.getMsg(Env.getCtx(), "FileCSV"); + } + + @Override + public String getContentType() { + return "application/csv"; + } + + private GridField[] getFields (GridTab gridTab) { + GridTable tableModel = gridTab.getTableModel(); + GridField[] tmpFields = tableModel.getFields(); + MTabCustomization tabCustomization = MTabCustomization.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()), gridTab.getAD_Tab_ID(), null); + GridField[] gridFields = null; + if (tabCustomization != null + && tabCustomization.getAD_Tab_Customization_ID() > 0 + && !Util.isEmpty(tabCustomization.getCustom(), true)) + { + String custom = tabCustomization.getCustom().trim(); + String[] customComponent = custom.split(";"); + String[] fieldIds = customComponent[0].split("[,]"); + List fieldList = new ArrayList(); + for(String fieldIdStr : fieldIds) + { + fieldIdStr = fieldIdStr.trim(); + if (fieldIdStr.length() == 0) continue; + int AD_Field_ID = Integer.parseInt(fieldIdStr); + for(GridField gridField : tmpFields) + { + if (gridField.getAD_Field_ID() == AD_Field_ID) + { + if(gridField.isDisplayedGrid()) + fieldList.add(gridField); + + break; + } + } + } + gridFields = fieldList.toArray(new GridField[0]); + } + else + { + ArrayList gridFieldList = new ArrayList(); + + for(GridField field:tmpFields) + { + if(field.isDisplayedGrid()) + gridFieldList.add(field); + } + + Collections.sort(gridFieldList, new Comparator() { + @Override + public int compare(GridField o1, GridField o2) { + return o1.getSeqNoGrid()-o2.getSeqNoGrid(); + } + }); + + gridFields = new GridField[gridFieldList.size()]; + gridFieldList.toArray(gridFields); + } + return gridFields; + } + + public boolean isColumnPrinted(GridTab tab, int col) + { + GridField field = tab.getField(col); + // field not displayed + if (!field.isDisplayed()) + return false; + // field encrypted + if (field.isEncrypted()) + return false; + // button without a reference value + if (field.getDisplayType() == DisplayType.Button && field.getAD_Reference_Value_ID() == 0) + return false; + return true; + } + +} diff --git a/org.adempiere.base/src/org/compiere/model/GridTable.java b/org.adempiere.base/src/org/compiere/model/GridTable.java index cf5258adf3..0bfa30cfe1 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTable.java +++ b/org.adempiere.base/src/org/compiere/model/GridTable.java @@ -537,7 +537,7 @@ public class GridTable extends AbstractTableModel } // getColumn /** - * Return Columns with Indentifier (ColumnName) + * Return Columns with Identifier (ColumnName) * @param identifier column name * @return MField */ diff --git a/org.adempiere.base/src/org/compiere/model/MColumn.java b/org.adempiere.base/src/org/compiere/model/MColumn.java index 60704a241e..3bff752597 100644 --- a/org.adempiere.base/src/org/compiere/model/MColumn.java +++ b/org.adempiere.base/src/org/compiere/model/MColumn.java @@ -603,4 +603,24 @@ public class MColumn extends X_AD_Column else return false; } + + public String getReferenceTableName() { + String foreignTable = null; + if (DisplayType.TableDir == getAD_Reference_ID() + || (DisplayType.Search == getAD_Reference_ID() && getAD_Reference_Value_ID() == 0)) { + foreignTable = getColumnName().substring(0, getColumnName().length()-3); + } else if (DisplayType.Table == getAD_Reference_ID() || DisplayType.Search == getAD_Reference_ID()) { + X_AD_Reference ref = new X_AD_Reference(getCtx(), getAD_Reference_Value_ID(), get_TrxName()); + if (X_AD_Reference.VALIDATIONTYPE_TableValidation.equals(ref.getValidationType())) { + MRefTable rt = new MRefTable(getCtx(), getAD_Reference_Value_ID(), get_TrxName()); + if (rt != null) + foreignTable = rt.getAD_Table().getTableName(); + } + } else if (DisplayType.List == getAD_Reference_ID()) { + foreignTable = "AD_Ref_List"; + } + + return foreignTable; + } + } // MColumn diff --git a/org.adempiere.base/src/org/compiere/util/DisplayType.java b/org.adempiere.base/src/org/compiere/util/DisplayType.java index 77e9e4ae2b..23ce0efcee 100644 --- a/org.adempiere.base/src/org/compiere/util/DisplayType.java +++ b/org.adempiere.base/src/org/compiere/util/DisplayType.java @@ -130,6 +130,10 @@ public final class DisplayType /** Default Amount Precision */ private static final int AMOUNT_FRACTION = 2; + public static final String DEFAULT_TIME_FORMAT = "HH:mm:ss"; + public static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; + /** Logger */ private static CLogger s_log = CLogger.getCLogger (DisplayType.class); @@ -398,7 +402,7 @@ public final class DisplayType */ static public SimpleDateFormat getDateFormat_JDBC() { - return new SimpleDateFormat ("yyyy-MM-dd"); + return new SimpleDateFormat (DEFAULT_DATE_FORMAT); } // getDateFormat_JDBC /** @@ -407,9 +411,14 @@ public final class DisplayType */ static public SimpleDateFormat getTimestampFormat_Default() { - return new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"); + return new SimpleDateFormat (DEFAULT_TIMESTAMP_FORMAT); } // getTimestampFormat_JDBC + static public SimpleDateFormat getTimeFormat_Default() + { + return new SimpleDateFormat (DEFAULT_TIME_FORMAT); + } // getTimeFormat_Default + /** * Return Storage Class. * (used for MiniTable) diff --git a/org.adempiere.extend/.classpath b/org.adempiere.extend/.classpath index 3496c3b589..aec6ab1f7d 100644 --- a/org.adempiere.extend/.classpath +++ b/org.adempiere.extend/.classpath @@ -1,9 +1,9 @@ - + diff --git a/org.adempiere.extend/META-INF/MANIFEST.MF b/org.adempiere.extend/META-INF/MANIFEST.MF index 143d9338f3..caa4981dfb 100644 --- a/org.adempiere.extend/META-INF/MANIFEST.MF +++ b/org.adempiere.extend/META-INF/MANIFEST.MF @@ -4,12 +4,13 @@ Bundle-Name: org.adempiere.extend Bundle-SymbolicName: org.adempiere.extend;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-ClassPath: extend.jar, - spiffy-with_source-all-0.05.jar, - SuperCSV-with_src-1.52.jar + spiffy-with_source-all-0.05.jar Eclipse-RegisterBuddy: org.adempiere.tools Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: compiere.model, test Fragment-Host: org.adempiere.base;bundle-version="0.0.0" Eclipse-PatchFragment: true -Import-Package: junit.framework;version="3.8.2" +Import-Package: junit.framework;version="3.8.2", + org.supercsv.io, + org.supercsv.prefs diff --git a/org.adempiere.extend/build.properties b/org.adempiere.extend/build.properties index 5134fd22a6..41403dca88 100644 --- a/org.adempiere.extend/build.properties +++ b/org.adempiere.extend/build.properties @@ -1,8 +1,7 @@ output.extend.jar = build/ bin.includes = META-INF/,\ extend.jar,\ - spiffy-with_source-all-0.05.jar,\ - SuperCSV-with_src-1.52.jar + spiffy-with_source-all-0.05.jar jars.compile.order = extend.jar source.extend.jar = src/ diff --git a/org.adempiere.extend/src/test/functional/inventory/CSVFactory.java b/org.adempiere.extend/src/test/functional/inventory/CSVFactory.java index f9d95910f4..3468ca553e 100644 --- a/org.adempiere.extend/src/test/functional/inventory/CSVFactory.java +++ b/org.adempiere.extend/src/test/functional/inventory/CSVFactory.java @@ -80,7 +80,7 @@ public class CSVFactory private String[] getCSVHeader() throws IOException { - String[] header = reader.getCSVHeader(true); + String[] header = reader.getHeader(true); for (int i = 0; i < header.length; i++) { header[i] = header[i].trim().replaceAll("\\s", "");