updates for async behavior

This commit is contained in:
Greg DiCristofaro 2020-03-05 07:37:51 -05:00
parent dc53c93eec
commit 1f7ab40a4d

View File

@ -22,6 +22,7 @@ import java.awt.Component;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea; import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.texttranslation.NoServiceProviderException; import org.sleuthkit.autopsy.texttranslation.NoServiceProviderException;
@ -103,12 +104,15 @@ final class TextTranslatableComponent implements TranslatablePanel.TranslatableC
this.translate = translate; this.translate = translate;
if (this.translate) { if (this.translate) {
if (this.translated == null) { if (this.translated == null) {
try { final String originalContent = this.origContent;
this.translated = this.translationService.translate(this.origContent); SwingUtilities.invokeLater(() -> {
} catch (NoServiceProviderException | TranslationException ex) { try {
LOGGER.log(Level.WARNING, "Unable to translate text with translation service", ex); this.translated = this.translationService.translate(originalContent);
return Bundle.TextTranslatableComponent_setTranslated_onTranslateError(); } catch (NoServiceProviderException | TranslationException ex) {
} LOGGER.log(Level.WARNING, "Unable to translate text with translation service", ex);
return Bundle.TextTranslatableComponent_setTranslated_onTranslateError();
}
});
} }
return onErr(setPanelContent(this.translated == null ? "" : this.translated)); return onErr(setPanelContent(this.translated == null ? "" : this.translated));
} else { } else {