IDEMPIERE-454 Easy import / Fix problem found with character set - adapting to zk6 also the WFileImport
This commit is contained in:
parent
c621e93fe3
commit
33ad5aa0b7
|
@ -19,6 +19,7 @@ import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
|
@ -75,16 +76,16 @@ public class GridTabCSVImporter implements IGridTabImporter
|
||||||
ICsvMapReader mapReader = null;
|
ICsvMapReader mapReader = null;
|
||||||
File errFile = null;
|
File errFile = null;
|
||||||
File logFile = null;
|
File logFile = null;
|
||||||
FileWriter errFileW = null;
|
PrintWriter errFileW = null;
|
||||||
FileWriter logFileW = null;
|
PrintWriter logFileW = null;
|
||||||
CsvPreference csvpref = CsvPreference.STANDARD_PREFERENCE;
|
CsvPreference csvpref = CsvPreference.STANDARD_PREFERENCE;
|
||||||
String delimiter = String.valueOf((char) csvpref.getDelimiterChar());
|
String delimiter = String.valueOf((char) csvpref.getDelimiterChar());
|
||||||
String quoteChar = String.valueOf((char) csvpref.getQuoteChar());
|
String quoteChar = String.valueOf((char) csvpref.getQuoteChar());
|
||||||
try {
|
try {
|
||||||
String errFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_err.csv");
|
String errFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_err.csv");
|
||||||
errFile = new File(errFileName);
|
errFile = new File(errFileName);
|
||||||
errFileW = new FileWriter(errFile, false);
|
errFileW = new PrintWriter(errFile, charset.name());
|
||||||
mapReader = new CsvMapReader(new InputStreamReader(filestream), csvpref);
|
mapReader = new CsvMapReader(new InputStreamReader(filestream, charset), csvpref);
|
||||||
|
|
||||||
String[] header = mapReader.getHeader(true);
|
String[] header = mapReader.getHeader(true);
|
||||||
List<CellProcessor> readProcArray = new ArrayList<CellProcessor>();
|
List<CellProcessor> readProcArray = new ArrayList<CellProcessor>();
|
||||||
|
@ -240,7 +241,7 @@ public class GridTabCSVImporter implements IGridTabImporter
|
||||||
if (!m_isError) {
|
if (!m_isError) {
|
||||||
String logFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_log.csv");
|
String logFileName = FileUtil.getTempMailName("Import_" + gridTab.getTableName(), "_log.csv");
|
||||||
logFile = new File(logFileName);
|
logFile = new File(logFileName);
|
||||||
logFileW = new FileWriter(logFile, false);
|
logFileW = new PrintWriter(logFile, charset.name());
|
||||||
|
|
||||||
// write the header
|
// write the header
|
||||||
logFileW.write(rawHeader + delimiter + LOG_HEADER + "\n");
|
logFileW.write(rawHeader + delimiter + LOG_HEADER + "\n");
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.compiere.util.Env;
|
||||||
import org.compiere.util.Ini;
|
import org.compiere.util.Ini;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
import org.zkoss.util.media.Media;
|
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.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
@ -262,6 +263,7 @@ public class WFileImport extends ADForm implements EventListener
|
||||||
if (charset == compare)
|
if (charset == compare)
|
||||||
{
|
{
|
||||||
fCharset.setSelectedIndex(i);
|
fCharset.setSelectedIndex(i);
|
||||||
|
Executions.getCurrent().getDesktop().getWebApp().getConfiguration().setUploadCharset(compare.name());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,10 +284,17 @@ public class WFileImport extends ADForm implements EventListener
|
||||||
}
|
}
|
||||||
else if (e.getTarget() == fCharset)
|
else if (e.getTarget() == fCharset)
|
||||||
{
|
{
|
||||||
int record = m_record;
|
if (m_file_istream != null) {
|
||||||
cmd_reloadFile();
|
m_file_istream.close();
|
||||||
m_record = record - 1;
|
m_file_istream = null;
|
||||||
cmd_applyFormat(true);
|
}
|
||||||
|
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)
|
else if (e.getTarget() == pickFormat)
|
||||||
{
|
{
|
||||||
|
@ -316,6 +325,20 @@ public class WFileImport extends ADForm implements EventListener
|
||||||
confirmPanel.getButton("Ok").setEnabled(false);
|
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) {
|
private void processUploadMedia(Media media) {
|
||||||
if (media == null)
|
if (media == null)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -115,7 +115,7 @@ public class ExportAction implements EventListener<Event>
|
||||||
Hbox hb = new Hbox();
|
Hbox hb = new Hbox();
|
||||||
Div div = new Div();
|
Div div = new Div();
|
||||||
div.setAlign("right");
|
div.setAlign("right");
|
||||||
div.appendChild(new Label("Files of Type: "));
|
div.appendChild(new Label(Msg.getMsg(Env.getCtx(), "FilesOfType")));
|
||||||
hb.appendChild(div);
|
hb.appendChild(div);
|
||||||
hb.appendChild(cboType);
|
hb.appendChild(cboType);
|
||||||
cboType.setWidth("100%");
|
cboType.setWidth("100%");
|
||||||
|
@ -195,7 +195,7 @@ public class ExportAction implements EventListener<Event>
|
||||||
winExportFile.onClose();
|
winExportFile.onClose();
|
||||||
winExportFile = null;
|
winExportFile = null;
|
||||||
AMedia media = 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);
|
Filedownload.save(media, panel.getActiveGridTab().getName() + "." + ext);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new AdempiereException(e);
|
throw new AdempiereException(e);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.compiere.util.Ini;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
import org.zkoss.util.media.AMedia;
|
import org.zkoss.util.media.AMedia;
|
||||||
import org.zkoss.util.media.Media;
|
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.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
@ -99,11 +100,11 @@ public class FileImportAction implements EventListener<Event>
|
||||||
if (charset == compare)
|
if (charset == compare)
|
||||||
{
|
{
|
||||||
fCharset.setSelectedIndex(i);
|
fCharset.setSelectedIndex(i);
|
||||||
|
Executions.getCurrent().getDesktop().getWebApp().getConfiguration().setUploadCharset(compare.name());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: change the streamreader when changing the charset
|
fCharset.addEventListener(Events.ON_SELECT, this);
|
||||||
// fCharset.addEventListener(Events.ON_SELECT, this);
|
|
||||||
|
|
||||||
importerMap = new HashMap<String, IGridTabImporter>();
|
importerMap = new HashMap<String, IGridTabImporter>();
|
||||||
extensionMap = new HashMap<String, String>();
|
extensionMap = new HashMap<String, String>();
|
||||||
|
@ -150,6 +151,13 @@ public class FileImportAction implements EventListener<Event>
|
||||||
cboType.setWidth("100%");
|
cboType.setWidth("100%");
|
||||||
vb.appendChild(hb);
|
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();
|
hb = new Hbox();
|
||||||
bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile"));
|
bFile.setLabel(Msg.getMsg(Env.getCtx(), "FileImportFile"));
|
||||||
bFile.setTooltiptext(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
|
bFile.setTooltiptext(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
|
||||||
|
@ -158,13 +166,6 @@ public class FileImportAction implements EventListener<Event>
|
||||||
hb.appendChild(bFile);
|
hb.appendChild(bFile);
|
||||||
vb.appendChild(hb);
|
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);
|
vb.appendChild(confirmPanel);
|
||||||
confirmPanel.addActionListener(this);
|
confirmPanel.addActionListener(this);
|
||||||
}
|
}
|
||||||
|
@ -181,9 +182,20 @@ public class FileImportAction implements EventListener<Event>
|
||||||
processUploadMedia(ue.getMedia());
|
processUploadMedia(ue.getMedia());
|
||||||
} else if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
|
} else if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
|
||||||
winImportFile.onClose();
|
winImportFile.onClose();
|
||||||
}
|
} else if (event.getTarget() == fCharset) {
|
||||||
else if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) {
|
if (m_file_istream != null) {
|
||||||
// TODO: Verify that file and charset are mandatory
|
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();
|
importFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue