diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java index 1bc5affbc5..cc01a3a1a6 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabCSVImporter.java @@ -19,6 +19,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.PrintWriter; import java.nio.charset.Charset; import java.sql.Timestamp; import java.text.DecimalFormatSymbols; @@ -75,16 +76,16 @@ public class GridTabCSVImporter implements IGridTabImporter ICsvMapReader mapReader = null; File errFile = null; File logFile = null; - FileWriter errFileW = null; - FileWriter logFileW = null; + PrintWriter errFileW = null; + PrintWriter logFileW = null; CsvPreference csvpref = CsvPreference.STANDARD_PREFERENCE; String delimiter = String.valueOf((char) csvpref.getDelimiterChar()); String quoteChar = String.valueOf((char) csvpref.getQuoteChar()); try { String errFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_err.csv"); errFile = new File(errFileName); - errFileW = new FileWriter(errFile, false); - mapReader = new CsvMapReader(new InputStreamReader(filestream), csvpref); + errFileW = new PrintWriter(errFile, charset.name()); + mapReader = new CsvMapReader(new InputStreamReader(filestream, charset), csvpref); String[] header = mapReader.getHeader(true); List readProcArray = new ArrayList(); @@ -240,7 +241,7 @@ public class GridTabCSVImporter implements IGridTabImporter if (!m_isError) { String logFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_log.csv"); logFile = new File(logFileName); - logFileW = new FileWriter(logFile, false); + logFileW = new PrintWriter(logFile, charset.name()); // write the header logFileW.write(rawHeader + delimiter + LOG_HEADER + "\n"); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java index f6cc99865d..e3de2b2cd5 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WFileImport.java @@ -50,6 +50,7 @@ import org.compiere.util.Env; import org.compiere.util.Ini; import org.compiere.util.Msg; import org.zkoss.util.media.Media; +import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -262,6 +263,7 @@ public class WFileImport extends ADForm implements EventListener if (charset == compare) { fCharset.setSelectedIndex(i); + Executions.getCurrent().getDesktop().getWebApp().getConfiguration().setUploadCharset(compare.name()); break; } } @@ -282,10 +284,17 @@ public class WFileImport extends ADForm implements EventListener } else if (e.getTarget() == fCharset) { - int record = m_record; - cmd_reloadFile(); - m_record = record - 1; - cmd_applyFormat(true); + if (m_file_istream != null) { + m_file_istream.close(); + m_file_istream = null; + } + clearAll(); + ListItem listitem = fCharset.getSelectedItem(); + if (listitem == null) + return; + Charset charset = (Charset)listitem.getValue(); + Executions.getCurrent().getDesktop().getWebApp().getConfiguration().setUploadCharset(charset.name()); + bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile")); } else if (e.getTarget() == pickFormat) { @@ -316,6 +325,20 @@ public class WFileImport extends ADForm implements EventListener confirmPanel.getButton("Ok").setEnabled(false); } + private void clearAll() { + m_record = -1; + record.setValue("------"); + info.setValue(" "); + rawData.setText(null); + m_data.clear(); + if (m_fields != null) { + for (Textbox field : m_fields) + { + field.setText(null); + } + } + } + private void processUploadMedia(Media media) { if (media == null) return; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java index cdbd771e0e..6cd0a5724a 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java @@ -115,7 +115,7 @@ public class ExportAction implements EventListener Hbox hb = new Hbox(); Div div = new Div(); div.setAlign("right"); - div.appendChild(new Label("Files of Type: ")); + div.appendChild(new Label(Msg.getMsg(Env.getCtx(), "FilesOfType"))); hb.appendChild(div); hb.appendChild(cboType); cboType.setWidth("100%"); @@ -195,7 +195,7 @@ public class ExportAction implements EventListener winExportFile.onClose(); winExportFile = null; AMedia media = null; - media = new AMedia(panel.getActiveGridTab().getName() + "." + ext, null, exporter.getContentType(), file, true); + media = new AMedia(exporter.getSuggestedFileName(panel.getActiveGridTab()), null, exporter.getContentType(), file, true); Filedownload.save(media, panel.getActiveGridTab().getName() + "." + ext); } catch (Exception e) { throw new AdempiereException(e); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java index d8fd6aad1d..0ec2d649e0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java @@ -45,6 +45,7 @@ import org.compiere.util.Ini; import org.compiere.util.Msg; import org.zkoss.util.media.AMedia; import org.zkoss.util.media.Media; +import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; @@ -99,11 +100,11 @@ public class FileImportAction implements EventListener if (charset == compare) { fCharset.setSelectedIndex(i); + Executions.getCurrent().getDesktop().getWebApp().getConfiguration().setUploadCharset(compare.name()); break; } } - // TODO: change the streamreader when changing the charset - // fCharset.addEventListener(Events.ON_SELECT, this); + fCharset.addEventListener(Events.ON_SELECT, this); importerMap = new HashMap(); extensionMap = new HashMap(); @@ -150,6 +151,13 @@ public class FileImportAction implements EventListener cboType.setWidth("100%"); vb.appendChild(hb); + hb = new Hbox(); + fCharset.setMold("select"); + fCharset.setRows(0); + fCharset.setTooltiptext(Msg.getMsg(Env.getCtx(), "Charset", false)); + hb.appendChild(fCharset); + vb.appendChild(hb); + hb = new Hbox(); bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile")); bFile.setTooltiptext(Msg.getMsg(Env.getCtx(), "FileImportFileInfo")); @@ -158,13 +166,6 @@ public class FileImportAction implements EventListener hb.appendChild(bFile); vb.appendChild(hb); - hb = new Hbox(); - fCharset.setMold("select"); - fCharset.setRows(0); - fCharset.setTooltiptext(Msg.getMsg(Env.getCtx(), "Charset", false)); - hb.appendChild(fCharset); - vb.appendChild(hb); - vb.appendChild(confirmPanel); confirmPanel.addActionListener(this); } @@ -181,9 +182,20 @@ public class FileImportAction implements EventListener processUploadMedia(ue.getMedia()); } else if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) { winImportFile.onClose(); - } - else if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) { - // TODO: Verify that file and charset are mandatory + } else if (event.getTarget() == fCharset) { + if (m_file_istream != null) { + m_file_istream.close(); + m_file_istream = null; + } + ListItem listitem = fCharset.getSelectedItem(); + if (listitem == null) + return; + Charset charset = (Charset)listitem.getValue(); + Executions.getCurrent().getDesktop().getWebApp().getConfiguration().setUploadCharset(charset.name()); + bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile")); + } else if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) { + if (m_file_istream == null || fCharset.getSelectedItem() == null) + return; importFile(); } }