From 9c7022893044078514b19f34bef44a83b66b11c2 Mon Sep 17 00:00:00 2001 From: "mikhail.kalyashin" Date: Mon, 29 Jan 2024 11:41:16 +0300 Subject: [PATCH] See RS-160938 fix loading file with encoding --- .../gui/browser/TraceManagerPanel.java | 86 ++++++++++++++----- .../managment/tracemanager/TablePanel.java | 1 + 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/src/org/executequery/gui/browser/TraceManagerPanel.java b/src/org/executequery/gui/browser/TraceManagerPanel.java index 574e95be7..e9111651e 100644 --- a/src/org/executequery/gui/browser/TraceManagerPanel.java +++ b/src/org/executequery/gui/browser/TraceManagerPanel.java @@ -30,6 +30,8 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.io.*; import java.nio.charset.Charset; import java.nio.file.Files; @@ -69,6 +71,7 @@ public class TraceManagerPanel extends AbstractServiceManagerPanel implements Ta private BuildConfigurationPanel confPanel; private int currentSessionId; ListSelectionPanel columnsCheckPanel; + final FileChooserDialog fileChooser = new FileChooserDialog(); private void initTraceManager(DatabaseConnection dc) { try { @@ -191,6 +194,44 @@ protected void initOtherComponents() { encodeCombobox = WidgetFactory.createComboBox("encodingCombobox", Charset.availableCharsets().keySet().toArray()); encodeCombobox.setSelectedItem(UserProperties.getInstance().getStringProperty("system.file.encoding")); encodeCombobox.setToolTipText(bundleString("Charset")); + encodeCombobox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + if (fileChooser.getSelectedFile() != null) { + + + SwingWorker sw = new SwingWorker("loadTraceFromFile") { + @Override + public Object construct() { + loadFromFile(); + return null; + } + + @Override + public void finished() { + GUIUtilities.showNormalCursor(); + tabPane.setEnabled(true); + loggerPanel.setEnableElements(true); + SwingWorker sw = new SwingWorker("buildAnalise") { + @Override + public Object construct() { + analisePanel.setMessages(loggerPanel.getTableRows()); + analisePanel.rebuildRows(); + return null; + } + }; + sw.start(); + + } + }; + GUIUtilities.showWaitCursor(); + tabPane.setEnabled(false); + loggerPanel.setEnableElements(false); + sw.start(); + tabPane.setSelectedComponent(loggerPanel); + } + } + }); toolBar.add(encodeCombobox, gbhToolBar.nextCol().setLabelDefault().get()); //toolBar.add(new JSeparator(),gbhToolBar.nextCol().setLabelDefault().get()); visibleColumnsButton = WidgetFactory.createRolloverButton("visibleColumnsButton", bundleString("VisibleColumns"), "FindAgain16.png"); @@ -239,7 +280,7 @@ public void actionPerformed(ActionEvent e) { }); openFileLog.addActionListener(new ActionListener() { - final FileChooserDialog fileChooser = new FileChooserDialog(); + @Override public void actionPerformed(ActionEvent e) { @@ -248,24 +289,7 @@ public void actionPerformed(ActionEvent e) { SwingWorker sw = new SwingWorker("loadTraceFromFile") { @Override public Object construct() { - clearAll(); - idLogMessage = 0; - BufferedReader reader = null; - try { - reader = new BufferedReader( - new InputStreamReader( - Files.newInputStream(Paths.get(fileChooser.getSelectedFile().getAbsolutePath())), (String) encodeCombobox.getSelectedItem())); - readFromBufferedReader(reader, true); - } catch (Exception e1) { - GUIUtilities.displayExceptionErrorDialog("file opening error", e1); - } finally { - if (reader != null) { - try { - reader.close(); - } catch (IOException e1) { - } - } - } + loadFromFile(); return null; } @@ -290,9 +314,10 @@ public Object construct() { tabPane.setEnabled(false); loggerPanel.setEnableElements(false); sw.start(); + tabPane.setSelectedComponent(loggerPanel); } - tabPane.setSelectedComponent(loggerPanel); + } }); @@ -410,6 +435,27 @@ public void actionPerformed(ActionEvent e) { } + protected void loadFromFile() { + clearAll(); + idLogMessage = 0; + BufferedReader reader = null; + try { + reader = new BufferedReader( + new InputStreamReader( + Files.newInputStream(Paths.get(fileChooser.getSelectedFile().getAbsolutePath())), (String) encodeCombobox.getSelectedItem())); + readFromBufferedReader(reader, true); + } catch (Exception e1) { + GUIUtilities.displayExceptionErrorDialog("file opening error", e1); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e1) { + } + } + } + } + @Override protected void postInitActions() { setEnableElements(); diff --git a/src/org/executequery/gui/browser/managment/tracemanager/TablePanel.java b/src/org/executequery/gui/browser/managment/tracemanager/TablePanel.java index 906911ff5..e4259392e 100644 --- a/src/org/executequery/gui/browser/managment/tracemanager/TablePanel.java +++ b/src/org/executequery/gui/browser/managment/tracemanager/TablePanel.java @@ -363,6 +363,7 @@ public void addRow(LogMessage message) { public void clearAll() { dataModel.clearAll(); + txtFieldRawSql.setSQLText(""); } public void cleanup() {