Skip to content

Commit

Permalink
See RS-160938 fix loading file with encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail.kalyashin committed Jan 29, 2024
1 parent 0036aef commit 9c70228
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 20 deletions.
86 changes: 66 additions & 20 deletions src/org/executequery/gui/browser/TraceManagerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -239,7 +280,7 @@ public void actionPerformed(ActionEvent e) {
});

openFileLog.addActionListener(new ActionListener() {
final FileChooserDialog fileChooser = new FileChooserDialog();


@Override
public void actionPerformed(ActionEvent e) {
Expand All @@ -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;
}

Expand All @@ -290,9 +314,10 @@ public Object construct() {
tabPane.setEnabled(false);
loggerPanel.setEnableElements(false);
sw.start();
tabPane.setSelectedComponent(loggerPanel);

}
tabPane.setSelectedComponent(loggerPanel);

}
});

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public void addRow(LogMessage message) {

public void clearAll() {
dataModel.clearAll();
txtFieldRawSql.setSQLText("");
}

public void cleanup() {
Expand Down

0 comments on commit 9c70228

Please sign in to comment.