Skip to content
Snippets Groups Projects
Unverified Commit 61e15927 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #6394 from dannysmyda/6956-Add-IcePDF-Firewall

6956 - Gracefully handle IcePDF failures
parents 135c0299 4d0fe953
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Container;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.Arrays; import java.util.Arrays;
...@@ -97,6 +98,9 @@ public void setFile(AbstractFile file) { ...@@ -97,6 +98,9 @@ public void setFile(AbstractFile file) {
// Add the IcePDF view to the center of our container. // Add the IcePDF view to the center of our container.
this.container.add(icePdfPanel, BorderLayout.CENTER); this.container.add(icePdfPanel, BorderLayout.CENTER);
// Disable all components until the document is ready to view.
enableComponents(container, false);
// Document is the 'M' in IcePDFs MVC set up. Read the data needed to // Document is the 'M' in IcePDFs MVC set up. Read the data needed to
// populate the model in the background. // populate the model in the background.
...@@ -122,12 +126,13 @@ protected void done() { ...@@ -122,12 +126,13 @@ protected void done() {
// will cause UI widgets to be updated. // will cause UI widgets to be updated.
try { try {
Document doc = get(); Document doc = get();
controller.openDocument(doc, null); controller.openDocument(doc, file.getName());
// This makes the PDF viewer appear as one continuous // This makes the PDF viewer appear as one continuous
// document, which is the default for most popular PDF viewers. // document, which is the default for most popular PDF viewers.
controller.setPageViewMode(DocumentViewControllerImpl.ONE_COLUMN_VIEW, true); controller.setPageViewMode(DocumentViewControllerImpl.ONE_COLUMN_VIEW, true);
// This makes it possible to select text by left clicking and dragging. // This makes it possible to select text by left clicking and dragging.
controller.setDisplayTool(DocumentViewModelImpl.DISPLAY_TOOL_TEXT_SELECTION); controller.setDisplayTool(DocumentViewModelImpl.DISPLAY_TOOL_TEXT_SELECTION);
enableComponents(container, true);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
// Do nothing. // Do nothing.
} catch (ExecutionException ex) { } catch (ExecutionException ex) {
...@@ -140,10 +145,28 @@ protected void done() { ...@@ -140,10 +145,28 @@ protected void done() {
file.getId(), file.getName()), ex); file.getId(), file.getName()), ex);
showErrorDialog(); showErrorDialog();
} }
} catch (Throwable ex) {
logger.log(Level.WARNING, String.format("PDF content viewer "
+ "was unable to open document with id %d and name %s",
file.getId(), file.getName()), ex);
} }
} }
}.execute(); }.execute();
} }
/**
* Recursively enable/disable all components in this content viewer.
* This will disable/enable all internal IcePDF Swing components too.
*/
private void enableComponents(Container container, boolean enabled) {
Component[] components = container.getComponents();
for(Component component : components) {
component.setEnabled(enabled);
if (component instanceof Container) {
enableComponents((Container)component, enabled);
}
}
}
@Override @Override
public Component getComponent() { public Component getComponent() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment