* feature request [ 1658127 ] Select charset encoding on import
* minor layout face lift
This commit is contained in:
parent
8ae47706da
commit
c08f9affc5
|
|
@ -19,6 +19,7 @@ package org.compiere.apps.form;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
@ -35,6 +36,7 @@ import org.compiere.util.*;
|
||||||
* <p>
|
* <p>
|
||||||
* Change log:
|
* Change log:
|
||||||
* <ul>
|
* <ul>
|
||||||
|
* <li>2007-02-12 - teo_sarca - [ 1658127 ] Select charset encoding on import
|
||||||
* <li>2007-01-27 - teo_sarca - [ 1619158 ] Import is not working with UTF-8
|
* <li>2007-01-27 - teo_sarca - [ 1619158 ] Import is not working with UTF-8
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
|
|
@ -78,6 +80,8 @@ public class VFileImport extends CPanel
|
||||||
private JLabel[] m_labels;
|
private JLabel[] m_labels;
|
||||||
private JTextField[] m_fields;
|
private JTextField[] m_fields;
|
||||||
private int m_record = -1;
|
private int m_record = -1;
|
||||||
|
/** Current selected file */
|
||||||
|
private File m_file = null;
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger(VFileImport.class);
|
private static CLogger log = CLogger.getCLogger(VFileImport.class);
|
||||||
//
|
//
|
||||||
|
|
@ -99,6 +103,7 @@ public class VFileImport extends CPanel
|
||||||
private JButton bNext = new JButton();
|
private JButton bNext = new JButton();
|
||||||
private JButton bPrevious = new JButton();
|
private JButton bPrevious = new JButton();
|
||||||
private JLabel record = new JLabel();
|
private JLabel record = new JLabel();
|
||||||
|
private CComboBox fCharset = new CComboBox(Ini.getAvailableCharsets());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static Init
|
* Static Init
|
||||||
|
|
@ -110,6 +115,7 @@ public class VFileImport extends CPanel
|
||||||
bFile.setText(Msg.getMsg(Env.getCtx(), "FileImportFile"));
|
bFile.setText(Msg.getMsg(Env.getCtx(), "FileImportFile"));
|
||||||
bFile.setToolTipText(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
|
bFile.setToolTipText(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
|
||||||
bFile.addActionListener(this);
|
bFile.addActionListener(this);
|
||||||
|
fCharset.setToolTipText(Msg.getMsg(Env.getCtx(), "Charset", false));
|
||||||
info.setText(" ");
|
info.setText(" ");
|
||||||
labelFormat.setText(Msg.translate(Env.getCtx(), "AD_ImpFormat_ID"));
|
labelFormat.setText(Msg.translate(Env.getCtx(), "AD_ImpFormat_ID"));
|
||||||
//
|
//
|
||||||
|
|
@ -125,6 +131,7 @@ public class VFileImport extends CPanel
|
||||||
//
|
//
|
||||||
northPanel.setBorder(BorderFactory.createEtchedBorder());
|
northPanel.setBorder(BorderFactory.createEtchedBorder());
|
||||||
northPanel.add(bFile, null);
|
northPanel.add(bFile, null);
|
||||||
|
northPanel.add(fCharset);
|
||||||
northPanel.add(info, null);
|
northPanel.add(info, null);
|
||||||
northPanel.add(labelFormat, null);
|
northPanel.add(labelFormat, null);
|
||||||
northPanel.add(pickFormat, null);
|
northPanel.add(pickFormat, null);
|
||||||
|
|
@ -137,8 +144,8 @@ public class VFileImport extends CPanel
|
||||||
rawData.setColumns(80);
|
rawData.setColumns(80);
|
||||||
rawData.setRows(5);
|
rawData.setRows(5);
|
||||||
rawDataPane.getViewport().add(rawData, null);
|
rawDataPane.getViewport().add(rawData, null);
|
||||||
centerPanel.add(rawDataPane, BorderLayout.NORTH);
|
centerPanel.add(rawDataPane, BorderLayout.CENTER);
|
||||||
centerPanel.add(previewPane, BorderLayout.CENTER);
|
centerPanel.add(previewPane, BorderLayout.SOUTH);
|
||||||
//
|
//
|
||||||
previewPanel.setLayout(previewLayout);
|
previewPanel.setLayout(previewLayout);
|
||||||
previewPane.getViewport().add(previewPanel, null);
|
previewPane.getViewport().add(previewPanel, null);
|
||||||
|
|
@ -181,6 +188,9 @@ public class VFileImport extends CPanel
|
||||||
pickFormat.setSelectedIndex(0);
|
pickFormat.setSelectedIndex(0);
|
||||||
pickFormat.addActionListener(this);
|
pickFormat.addActionListener(this);
|
||||||
//
|
//
|
||||||
|
fCharset.setSelectedItem(Ini.getCharset());
|
||||||
|
fCharset.addActionListener(this);
|
||||||
|
//
|
||||||
confirmPanel.getOKButton().setEnabled(false);
|
confirmPanel.getOKButton().setEnabled(false);
|
||||||
} // dynInit
|
} // dynInit
|
||||||
|
|
||||||
|
|
@ -197,6 +207,12 @@ public class VFileImport extends CPanel
|
||||||
invalidate();
|
invalidate();
|
||||||
m_frame.pack();
|
m_frame.pack();
|
||||||
}
|
}
|
||||||
|
else if (e.getSource() == fCharset) {
|
||||||
|
int record = m_record;
|
||||||
|
cmd_reloadFile();
|
||||||
|
m_record = record - 1;
|
||||||
|
cmd_applyFormat(true);
|
||||||
|
}
|
||||||
else if (e.getSource() == pickFormat)
|
else if (e.getSource() == pickFormat)
|
||||||
{
|
{
|
||||||
cmd_loadFormat();
|
cmd_loadFormat();
|
||||||
|
|
@ -253,16 +269,28 @@ public class VFileImport extends CPanel
|
||||||
chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
|
chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "FileImportFileInfo"));
|
||||||
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
|
if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION)
|
||||||
return;
|
return;
|
||||||
String fileName = chooser.getSelectedFile().getName();
|
m_file = chooser.getSelectedFile();
|
||||||
log.config(fileName);
|
log.config(m_file.getName());
|
||||||
bFile.setText(fileName);
|
bFile.setText(m_file.getName());
|
||||||
|
cmd_reloadFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload/Load file
|
||||||
|
*/
|
||||||
|
private void cmd_reloadFile()
|
||||||
|
{
|
||||||
|
if (m_file == null)
|
||||||
|
return;
|
||||||
|
|
||||||
setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
setCursor (Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
|
||||||
m_data.clear();
|
m_data.clear();
|
||||||
rawData.setText("");
|
rawData.setText("");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// see NaturalAccountMap
|
// see NaturalAccountMap
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(chooser.getSelectedFile()), "UTF-8"), 10240);
|
Charset charset = (Charset)fCharset.getSelectedItem();
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(m_file), charset), 10240);
|
||||||
// not safe see p108 Network pgm
|
// not safe see p108 Network pgm
|
||||||
String s = null;
|
String s = null;
|
||||||
while ((s = in.readLine()) != null)
|
while ((s = in.readLine()) != null)
|
||||||
|
|
@ -321,7 +349,7 @@ public class VFileImport extends CPanel
|
||||||
{
|
{
|
||||||
ImpFormatRow row = m_format.getRow(i);
|
ImpFormatRow row = m_format.getRow(i);
|
||||||
m_labels[i] = new JLabel (row.getColumnName());
|
m_labels[i] = new JLabel (row.getColumnName());
|
||||||
previewPanel.add(m_labels[i], new GridBagConstraints(i, 0, 1, 1, 0.0, 0.0,
|
previewPanel.add(m_labels[i], new GridBagConstraints(i, 0, 1, 1, 1.0, 1.0,
|
||||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
||||||
//
|
//
|
||||||
int length = row.getEndNo() - row.getStartNo();
|
int length = row.getEndNo() - row.getStartNo();
|
||||||
|
|
@ -330,8 +358,8 @@ public class VFileImport extends CPanel
|
||||||
else if (length > 20)
|
else if (length > 20)
|
||||||
length = 20;
|
length = 20;
|
||||||
m_fields[i] = new JTextField (length);
|
m_fields[i] = new JTextField (length);
|
||||||
previewPanel.add(m_fields[i], new GridBagConstraints(i, 1, 1, 1, 0.0, 0.0,
|
previewPanel.add(m_fields[i], new GridBagConstraints(i, 1, 1, 1, 1.0, 1.0,
|
||||||
GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
|
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
|
||||||
}
|
}
|
||||||
m_record = -1;
|
m_record = -1;
|
||||||
record.setText("-");
|
record.setText("-");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue