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.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<CellProcessor> readProcArray = new ArrayList<CellProcessor>();
|
||||
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -115,7 +115,7 @@ public class ExportAction implements EventListener<Event>
|
|||
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<Event>
|
|||
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);
|
||||
|
|
|
@ -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<Event>
|
|||
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<String, IGridTabImporter>();
|
||||
extensionMap = new HashMap<String, String>();
|
||||
|
@ -150,6 +151,13 @@ public class FileImportAction implements EventListener<Event>
|
|||
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<Event>
|
|||
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<Event>
|
|||
processUploadMedia(ue.getMedia());
|
||||
} else if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
|
||||
winImportFile.onClose();
|
||||
} else if (event.getTarget() == fCharset) {
|
||||
if (m_file_istream != null) {
|
||||
m_file_istream.close();
|
||||
m_file_istream = null;
|
||||
}
|
||||
else if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) {
|
||||
// TODO: Verify that file and charset are mandatory
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue