Search in sources :

Example 1 with LWTitledOptionPaneDialog

use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.

the class DialogUtils method showWarningDialog.

public static void showWarningDialog(final Component requester, final String message) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Doer doer = () -> {
        JPanel panel = MessagePanelFactory.createSimple(message);
        JOptionPane pane = new JOptionPane(panel, JOptionPane.WARNING_MESSAGE);
        LWDialog dialog = new LWTitledOptionPaneDialog(lwParent, "Warning", pane);
        dialog.setResizable(true);
        showOnce(dialog);
    };
    VCSwingFunction.executeAsRuntimeException(doer);
}
Also used : JPanel(javax.swing.JPanel) LWDialog(org.vcell.client.logicalwindow.LWDialog) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) Doer(org.vcell.util.gui.VCSwingFunction.Doer) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane)

Example 2 with LWTitledOptionPaneDialog

use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog 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)

Example 3 with LWTitledOptionPaneDialog

use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.

the class DialogUtils method showComponentOKCancelDialog.

public static int showComponentOKCancelDialog(final Component requester, final Component stayOnTopComponent, final String title, final OKEnabler okEnabler, boolean isResizeable) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Producer<Integer> prod = () -> {
        JOptionPane inputDialog = new JOptionPane(stayOnTopComponent, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new String[] { getOKText(), getCancelText() });
        JDialog d = new LWTitledOptionPaneDialog(lwParent, title, inputDialog);
        d.setResizable(isResizeable);
        if (okEnabler != null) {
            okEnabler.setJOptionPane(inputDialog);
        }
        try {
            d.setVisible(true);
            if (inputDialog.getValue() instanceof String) {
                if (inputDialog.getValue().equals(getOKText())) {
                    return JOptionPane.OK_OPTION;
                }
                if (inputDialog.getValue().equals(getCancelText())) {
                    return JOptionPane.CANCEL_OPTION;
                }
            } else if (inputDialog.getValue() == null) {
                return JOptionPane.CLOSED_OPTION;
            } else if (inputDialog.getValue().equals(JOptionPane.UNINITIALIZED_VALUE)) {
                return JOptionPane.CLOSED_OPTION;
            }
            throw new RuntimeException("Unexpected return value=" + inputDialog.getValue().toString());
        } finally {
            d.dispose();
        }
    };
    return VCSwingFunction.executeAsRuntimeException(prod);
}
Also used : LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 4 with LWTitledOptionPaneDialog

use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.

the class DialogUtils method showDialog.

/**
 * Insert the method's description here.
 * Creation date: (5/21/2004 3:23:18 AM)
 * @return int
 * @param owner java.awt.Component
 * @param message java.lang.String
 * @param preferences cbit.vcell.client.UserPreferences
 * @param preferenceName java.lang.String
 */
protected static String showDialog(final Component requester, final UserPreferences preferences, final UserMessage userMessage, final String replacementText, final int jOptionPaneMessageType) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Producer<String> prod = () -> {
        // 
        if (userMessage.getUserPreferenceWarning() > -1 && preferences != null && !preferences.getShowWarning(userMessage.getUserPreferenceWarning())) {
            return userMessage.getDefaultSelection();
        }
        String message = userMessage.getMessage(replacementText);
        JPanel panel = MessagePanelFactory.createSimple(message);
        JCheckBox checkBox = null;
        if (userMessage.getUserPreferenceWarning() >= 0) {
            checkBox = new JCheckBox("Do not show this warning again");
            panel.add(checkBox, BorderLayout.SOUTH);
        }
        JOptionPane pane = new JOptionPane(panel, jOptionPaneMessageType, 0, null, userMessage.getOptions(), userMessage.getDefaultSelection());
        String title;
        switch(jOptionPaneMessageType) {
            case JOptionPane.WARNING_MESSAGE:
                title = "WARNING:";
                break;
            case JOptionPane.ERROR_MESSAGE:
                title = "ERROR:";
                break;
            case JOptionPane.INFORMATION_MESSAGE:
                title = "INFO:";
                break;
            default:
                title = null;
        }
        LWDialog dialog = new LWTitledOptionPaneDialog(lwParent, title, pane);
        dialog.setResizable(true);
        try {
            dialog.setVisible(true);
            if (checkBox != null) {
                preferences.setShowWarning(userMessage.getUserPreferenceWarning(), !checkBox.isSelected());
            }
            Object selectedValue = pane.getValue();
            if (selectedValue == null || selectedValue.equals(JOptionPane.UNINITIALIZED_VALUE)) {
                return UserMessage.OPTION_CANCEL;
            } else {
                return objectToString(selectedValue);
            }
        } finally {
            dialog.dispose();
        }
    };
    return VCSwingFunction.executeAsRuntimeException(prod);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) LWDialog(org.vcell.client.logicalwindow.LWDialog) LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane)

Example 5 with LWTitledOptionPaneDialog

use of org.vcell.client.logicalwindow.LWTitledOptionPaneDialog in project vcell by virtualcell.

the class DialogUtils method showComponentCloseDialog.

/**
 * Insert the method's description here.
 * Creation date: (5/21/2004 3:17:45 AM)
 * @param owner java.awt.Component
 * @param message java.lang.Object
 */
public static void showComponentCloseDialog(final Component requester, final Component stayOnTopComponent, final String title) {
    checkForNull(requester);
    LWContainerHandle lwParent = LWNamespace.findLWOwner(requester);
    Doer doer = () -> {
        JOptionPane inputDialog = new JOptionPane(stayOnTopComponent, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[] { "Close" });
        final JDialog d = new LWTitledOptionPaneDialog(lwParent, title, inputDialog);
        d.setResizable(true);
        try {
            d.setVisible(true);
        } finally {
            d.dispose();
        }
    };
    VCSwingFunction.executeAsRuntimeException(doer);
}
Also used : LWContainerHandle(org.vcell.client.logicalwindow.LWContainerHandle) Doer(org.vcell.util.gui.VCSwingFunction.Doer) LWTitledOptionPaneDialog(org.vcell.client.logicalwindow.LWTitledOptionPaneDialog) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

JOptionPane (javax.swing.JOptionPane)12 LWContainerHandle (org.vcell.client.logicalwindow.LWContainerHandle)12 LWTitledOptionPaneDialog (org.vcell.client.logicalwindow.LWTitledOptionPaneDialog)12 JDialog (javax.swing.JDialog)8 JPanel (javax.swing.JPanel)8 Doer (org.vcell.util.gui.VCSwingFunction.Doer)5 BorderLayout (java.awt.BorderLayout)4 LWDialog (org.vcell.client.logicalwindow.LWDialog)4 Dimension (java.awt.Dimension)3 JScrollPane (javax.swing.JScrollPane)3 JTextArea (javax.swing.JTextArea)2 Collection (java.util.Collection)1 Hashtable (java.util.Hashtable)1 JCheckBox (javax.swing.JCheckBox)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 UserCancelException (org.vcell.util.UserCancelException)1 UtilCancelException (org.vcell.util.UtilCancelException)1