Search in sources :

Example 1 with DialogMessagePanel

use of org.vcell.util.gui.MessagePanelFactory.DialogMessagePanel in project vcell by virtualcell.

the class DialogUtils method showErrorDialog.

/**
 * show error dialog in standard way. If modelInfo is not null user is prompted to allow sending of context information
 * @param requester parent Component, may be null
 * @param message message to display
 * @param exception exception to dialog and possibility email to VCellSupport; may be null
 * @param modelInfo information to include in email to VCellSupport; may be null
 */
public static void showErrorDialog(final Component requester, final String message, final Throwable exception, final ErrorContext errorContext) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Doer doer = () -> {
        String errMsg = message;
        boolean sendErrorReport = false;
        if (errMsg == null || errMsg.trim().length() == 0) {
            errMsg = "Virtual Cell has encountered a problem. Please tell Virtual Cell about this problem to help improve Virtual Cell.";
            if (exception != null) {
                sendErrorReport = true;
            }
        }
        if (exception instanceof ClassCastException || exception instanceof ArrayIndexOutOfBoundsException || exception instanceof NullPointerException || exception instanceof Error) {
            sendErrorReport = true;
        }
        final boolean goingToEmail = sendErrorReport && VCellClientTest.getVCellClient() != null;
        DialogMessagePanel dialogMessagePanel;
        if (goingToEmail) {
            dialogMessagePanel = MessagePanelFactory.createExtended(errMsg, errorContext);
        } else {
            dialogMessagePanel = MessagePanelFactory.createNonSending(errMsg);
        }
        Collection<String> suggestions = ExceptionInterpreter.instance().suggestions(message);
        if (suggestions != null) {
            SuggestionPanel sp = new SuggestionPanel();
            sp.setSuggestedSolution(suggestions);
            dialogMessagePanel.add(sp, BorderLayout.NORTH);
        }
        JOptionPane pane = new JOptionPane(dialogMessagePanel, JOptionPane.ERROR_MESSAGE, dialogMessagePanel.optionType());
        JDialog dialog = new LWTitledOptionPaneDialog(lwParent, "Error", pane);
        dialog.setResizable(true);
        try {
            dialog.setVisible(true);
            if (goingToEmail) {
                Object ro = pane.getValue();
                Integer reply = BeanUtils.downcast(Integer.class, ro);
                boolean userSaidYes = reply != null ? reply == JOptionPane.YES_OPTION : false;
                if (userSaidYes) {
                    Throwable throwableToSend = exception;
                    String extra = dialogMessagePanel.getSupplemental();
                    extra = BeanUtils.PLAINTEXT_EMAIL_NEWLINE + (extra == null ? "" : extra) + collectRecordedUserEvents();
                    throwableToSend = new RuntimeException(extra, exception);
                    VCellClientTest.getVCellClient().getClientServerManager().sendErrorReport(throwableToSend);
                }
            }
        } finally {
            dialog.dispose();
        }
    };
    VCSwingFunction.executeConsumeException(doer);
}
Also used : LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) DialogMessagePanel(org.vcell.util.gui.MessagePanelFactory.DialogMessagePanel) Doer(org.vcell.util.gui.VCSwingFunction.Doer) Collection(java.util.Collection) JDialog(javax.swing.JDialog)

Aggregations

Collection (java.util.Collection)1 JDialog (javax.swing.JDialog)1 JOptionPane (javax.swing.JOptionPane)1 LWContainerHandle (org.vcell.client.logicalwindow.LWContainerHandle)1 LWTitledOptionPaneDialog (org.vcell.client.logicalwindow.LWTitledOptionPaneDialog)1 DialogMessagePanel (org.vcell.util.gui.MessagePanelFactory.DialogMessagePanel)1 Doer (org.vcell.util.gui.VCSwingFunction.Doer)1