Skip to content

Commit

Permalink
Revert "Added dropdown in file open Dialog to choose a working LogImp…
Browse files Browse the repository at this point in the history
…orter. (#593)"

This reverts commit 5f87512.
  • Loading branch information
svennissel committed Apr 9, 2022
1 parent 81006f4 commit 63921fe
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import pl.otros.logview.api.services.Services;
import pl.otros.logview.api.theme.Theme;
import pl.otros.logview.api.theme.ThemeConfig;
import pl.otros.logview.gui.open.LogVfsBrowserDialog;
import pl.otros.vfs.browser.JOtrosVfsBrowserDialog;

import javax.swing.*;
import java.awt.*;
Expand All @@ -48,7 +48,7 @@ public class OtrosApplication {
private JTextField searchField;
private MarkerColors selectedMarkColors;
private JMenu pluginsMenu;
private LogVfsBrowserDialog otrosVfsBrowserDialog;
private JOtrosVfsBrowserDialog otrosVfsBrowserDialog;
private AppProperties appProperties;
private final List<MenuActionProvider> menuActionProviders;
private LogLoader logLoader;
Expand All @@ -71,11 +71,11 @@ public JTabbedPane getjTabbedPane() {
return jTabbedPane;
}

public LogVfsBrowserDialog getOtrosVfsBrowserDialog() {
public JOtrosVfsBrowserDialog getOtrosVfsBrowserDialog() {
return otrosVfsBrowserDialog;
}

public void setOtrosVfsBrowserDialog(LogVfsBrowserDialog otrosVfsBrowserDialog) {
public void setOtrosVfsBrowserDialog(JOtrosVfsBrowserDialog otrosVfsBrowserDialog) {
this.otrosVfsBrowserDialog = otrosVfsBrowserDialog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import pl.otros.logview.gui.message.SearchResultColorizer;
import pl.otros.logview.gui.message.SoapMessageFormatter;
import pl.otros.logview.gui.message.update.MessageUpdateUtils;
import pl.otros.logview.gui.open.LogVfsBrowserDialog;
import pl.otros.logview.gui.renderers.MarkerColorsComboBoxRenderer;
import pl.otros.logview.gui.services.jumptocode.ServicesImpl;
import pl.otros.logview.gui.suggestion.PersistedSuggestionSource;
Expand All @@ -78,6 +77,7 @@
import pl.otros.swing.rulerbar.OtrosJTextWithRulerScrollPane;
import pl.otros.swing.rulerbar.RulerBarHelper;
import pl.otros.swing.suggest.SuggestDecorator;
import pl.otros.vfs.browser.JOtrosVfsBrowserDialog;

import javax.imageio.ImageIO;
import javax.swing.*;
Expand All @@ -89,10 +89,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Optional;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

Expand Down Expand Up @@ -181,7 +178,7 @@ public LogViewMainFrame(DataConfiguration c) {
otrosApplication.setjTabbedPane(logsTabbedPane);
otrosApplication.setStatusObserver(observer);
final LogParsableListener logParsableListener = new LogParsableListener(otrosApplication.getAllPluginables().getLogImportersContainer());
otrosApplication.setOtrosVfsBrowserDialog(new LogVfsBrowserDialog(logParsableListener, getVfsFavoritesConfiguration()));
otrosApplication.setOtrosVfsBrowserDialog(new JOtrosVfsBrowserDialog(getVfsFavoritesConfiguration(), logParsableListener));
otrosApplication.setServices(new ServicesImpl(otrosApplication));
otrosApplication.setLogLoader(new BasicLogLoader(otrosApplication.getServices().getStatsService()));
if (!runningForTests()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
import pl.otros.logview.api.loading.LogLoadingSession;
import pl.otros.logview.api.loading.VfsSource;
import pl.otros.logview.api.parser.ParsingContext;
import pl.otros.logview.gui.open.LogVfsBrowserDialog;
import pl.otros.logview.importer.DetectOnTheFlyLogImporter;
import pl.otros.vfs.browser.JOtrosVfsBrowserDialog;
import pl.otros.vfs.browser.SelectionMode;

Expand All @@ -60,7 +58,7 @@ public TailLogActionListener(OtrosApplication otrosApplication, LogImporter impo

@Override
protected void actionPerformedHook(ActionEvent e) {
LogVfsBrowserDialog chooser = getOtrosApplication().getOtrosVfsBrowserDialog();
JOtrosVfsBrowserDialog chooser = getOtrosApplication().getOtrosVfsBrowserDialog();
initFileChooser(chooser);

JOtrosVfsBrowserDialog.ReturnValue result = chooser.showOpenDialog((Component) e.getSource(), "Tail " + importer.getName() + " log");
Expand All @@ -69,22 +67,11 @@ protected void actionPerformedHook(ActionEvent e) {
}
final FileObject[] files = chooser.getSelectedFiles();
for (FileObject file : files) {
List<LogImporter> parsableLogImporters = chooser.getParsableLogImporters();
LogImporter logImporter;
if (parsableLogImporters.isEmpty()) {
logImporter = importer;
} else {
logImporter = new DetectOnTheFlyLogImporter(parsableLogImporters);
}
openFileObjectInTailMode(file, Utils.getFileObjectShortName(file), logImporter);
openFileObjectInTailMode(file, Utils.getFileObjectShortName(file));
}
}

public void openFileObjectInTailMode(final FileObject file, String tabName) {
openFileObjectInTailMode(file, tabName, importer);
}

public void openFileObjectInTailMode(final FileObject file, String tabName, LogImporter logImporter) {
final LoadingInfo loadingInfo;
try {
loadingInfo = new LoadingInfo(file, true);
Expand All @@ -95,7 +82,7 @@ public void openFileObjectInTailMode(final FileObject file, String tabName, LogI
return;
}

TableColumns[] tableColumnsToUse = determineTableColumnsToUse(loadingInfo, logImporter);
TableColumns[] tableColumnsToUse = determineTableColumnsToUse(loadingInfo, importer);

final LogViewPanelWrapper panel = new LogViewPanelWrapper(file.getName().getBaseName(), loadingInfo.getObservableInputStreamImpl(),
tableColumnsToUse, getOtrosApplication());
Expand All @@ -105,6 +92,7 @@ public void openFileObjectInTailMode(final FileObject file, String tabName, LogI

final LogLoader logLoader = getOtrosApplication().getLogLoader();
final VfsSource source = new VfsSource(file);
final LogImporter logImporter = this.importer;
final LogLoadingSession session = logLoader.startLoading(
source,
logImporter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@

public class TailLogWithAutoDetectActionListener extends TailLogActionListener {

// private final

public TailLogWithAutoDetectActionListener(OtrosApplication otrosApplication) {
super(otrosApplication, new DetectOnTheFlyLogImporter(otrosApplication.getAllPluginables().getLogImportersContainer().getElements()));
}

@Override
protected TableColumns[] determineTableColumnsToUse(LoadingInfo loadingInfo, LogImporter importer) {
Collection<LogImporter> logImporters = getOtrosApplication().getAllPluginables().getLogImportersContainer().getElements();
byte[] inputStreamBufferedStart = loadingInfo.getInputStreamBufferedStart();

if(importer instanceof DetectOnTheFlyLogImporter) {
Collection<LogImporter> logImporters = ((DetectOnTheFlyLogImporter) importer).getLogImporters();
Optional<LogImporter> detectLogImporter = Utils.detectLogImporter(logImporters, inputStreamBufferedStart);
if (detectLogImporter.isPresent()) {
return super.determineTableColumnsToUse(loadingInfo, detectLogImporter.get());
}
Optional<LogImporter> detectLogImporter = Utils.detectLogImporter(logImporters, inputStreamBufferedStart);
TableColumns[] determineTableColumnsToUse = super.determineTableColumnsToUse(loadingInfo, importer);
if (detectLogImporter.isPresent()) {
determineTableColumnsToUse = super.determineTableColumnsToUse(loadingInfo, detectLogImporter.get());
}

return super.determineTableColumnsToUse(loadingInfo, importer);
return determineTableColumnsToUse;
}

}
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
package pl.otros.logview.gui.browser;

import org.apache.commons.vfs2.FileObject;
import pl.otros.logview.api.gui.Icons;
import pl.otros.logview.api.importer.LogImporter;
import pl.otros.logview.api.importer.PossibleLogImporters;
import pl.otros.logview.api.io.Utils;
import pl.otros.logview.api.pluginable.PluginableElementsContainer;
import pl.otros.logview.gui.renderers.JComboBoxLogImporterRenderer;
import pl.otros.vfs.browser.listener.SelectionListener;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.util.List;
import java.util.*;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;

public class LogParsableListener implements SelectionListener {

private final JComboBoxLogImporterRenderer logParserComboBoxRenderer;
private CardLayout layout;
private JPanel content;
private final String PARSING = "parsing";
private final String OK = "ok";
private final PluginableElementsContainer<LogImporter> logImportersContainer;
private JComboBox<LogImporter> logParserComboBox;
private JLabel label;
private Optional<SwingWorker<PossibleLogImporters, Void>> worker = Optional.empty();
private Consumer<List<LogImporter>> parsableLogImporterConsumer;
private final List<LogImporter> parsableLogImporters = new ArrayList<>();

public LogParsableListener(PluginableElementsContainer<LogImporter> logImportersContainer) {
this.logImportersContainer = logImportersContainer;
Expand All @@ -38,15 +32,9 @@ public LogParsableListener(PluginableElementsContainer<LogImporter> logImporters
progressBar.setStringPainted(true);
progressBar.setString("Detecting logs");
progressBar.setIndeterminate(true);
label = new JLabel();
content.add(progressBar, PARSING);

logParserComboBox = new JComboBox<>();
logParserComboBoxRenderer = new JComboBoxLogImporterRenderer();
logParserComboBox.setRenderer(logParserComboBoxRenderer);
logParserComboBox.addItemListener(this::onLogParserComboBoxEvent);
logParserComboBox.setPrototypeDisplayValue(null);
content.add(logParserComboBox, OK);

content.add(label, OK);
}

@Override
Expand All @@ -57,22 +45,19 @@ public JComponent getView() {
@Override
public void selectedItem(FileObject... fileObjects) {
worker.ifPresent(w -> w.cancel(false));
logParserComboBoxRenderer.setFileNotParsable(null);
logParserComboBox.removeAllItems();
logParserComboBox.updateUI();//If change directory and before a not parsable file is selected the ui must be udpated
label.setText("");
label.setIcon(null);
layout.show(content, OK);
}

@Override
public void selectedContentPart(final FileObject fileObject, byte[] bytes) {
layout.show(content, PARSING);
logParserComboBox.removeAllItems();

worker.ifPresent(w -> w.cancel(false));
final SwingWorker<PossibleLogImporters, Void> swingWorker = new SwingWorker<PossibleLogImporters, Void>() {

@Override
protected PossibleLogImporters doInBackground() {
protected PossibleLogImporters doInBackground() throws Exception {
return Utils.detectPossibleLogImporter(logImportersContainer.getElements(), bytes);
}

Expand All @@ -82,33 +67,11 @@ protected void done() {
return;
}
try {
Optional<LogImporter> parsableLogImporter = get().getLogImporter();
final boolean logCanParse = parsableLogImporter.isPresent();
//Only displayed if no Logimporter found
logParserComboBoxRenderer.setFileNotParsable(fileObject.getName().getBaseName());

parsableLogImporters.clear();
parsableLogImporters.addAll(get().getAvailableImporters());
logParserComboBox.removeAllItems();

for (LogImporter availableImporter : get().getAvailableImporters()) {
logParserComboBox.addItem(availableImporter);

}
if (logCanParse) {
LogImporter logImporter = parsableLogImporter.get();
//Put selected importer at first position. This importer will try to use at first for parsing file.
putImporterOnFirstPosition(parsableLogImporters, logImporter);
logParserComboBox.setSelectedItem(logImporter);
}

if (parsableLogImporterConsumer != null)
parsableLogImporterConsumer.accept(parsableLogImporters);

final boolean present = get().getLogImporter().isPresent();
label.setText((present?"Can parse ":"Can't parse ") + fileObject.getName().getBaseName());
label.setIcon(present ? Icons.STATUS_OK : Icons.STATUS_ERROR);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
logParserComboBoxRenderer.setFileNotParsable(null);
logParserComboBox.removeAllItems();
label.setText("?");
} finally {
layout.show(content, OK);
}
Expand All @@ -120,38 +83,13 @@ protected void done() {

}

private void onLogParserComboBoxEvent(ItemEvent event) {
if (event.getStateChange() == ItemEvent.SELECTED) {
if (event.getItem() instanceof LogImporter) {
//Put selected importer at first position. This importer will try to use at first for parsing file.
putImporterOnFirstPosition(parsableLogImporters, (LogImporter) event.getItem());
if (parsableLogImporterConsumer != null)
parsableLogImporterConsumer.accept(parsableLogImporters);

}
}
}

private void putImporterOnFirstPosition(List<LogImporter> importers, LogImporter importer) {
for (int i = 0; i < importers.size(); i++) {
if (i > 0 && Objects.equals(importer.getName(), importers.get(i).getName())) {
Collections.swap(importers, 0, i);
break;
}
}
}

@Override
public void enteredDir(FileObject fileObject) {
worker.ifPresent(w -> w.cancel(false));
SwingUtilities.invokeLater(() -> {
logParserComboBox.removeAllItems();
logParserComboBoxRenderer.setFileNotParsable(null);
label.setText("");
label.setIcon(null);
layout.show(content, OK);
});
}

public void setParsableLogImporterConsumer(Consumer<List<LogImporter>> parsableLogImporterConsumer) {
this.parsableLogImporterConsumer = parsableLogImporterConsumer;
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 63921fe

Please sign in to comment.