Author: fmui
Date: Tue Aug 11 12:17:04 2015
New Revision: 1695289

URL: http://svn.apache.org/r1695289
Log:
CMIS-933: Workbench: added exception dialog

Added:
    
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
Modified:
    
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
    
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConnectionErrorDialog.java

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
URL: 
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java?rev=1695289&r1=1695288&r2=1695289&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
 Tue Aug 11 12:17:04 2015
@@ -67,10 +67,10 @@ import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.JRootPane;
 import javax.swing.JTable;
 import javax.swing.KeyStroke;
+import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.text.AttributeSet;
 import javax.swing.text.DefaultEditorKit;
@@ -148,33 +148,9 @@ public final class ClientHelper {
     public static void showError(Component parent, Exception ex) {
         logError(ex);
 
-        String exceptionName = ex.getClass().getSimpleName();
-        if (ex instanceof CmisBaseException) {
-            exceptionName = ((CmisBaseException) ex).getExceptionName();
-        }
-
-        StringBuilder sb = new StringBuilder(ex.getMessage() == null ? "null" 
: ex.getMessage());
-
-        int width = 80;
-        while (sb.length() > width) {
-            int p = width;
-
-            int x = sb.indexOf(" ", p);
-            if (x < 0 || x > p + 10) {
-                x = sb.indexOf("/", p);
-            }
-            if (x < 0 || x > p + 10) {
-                x = sb.indexOf(":", p);
-            }
-            if (x < 0 || x > p + 10) {
-                x = p;
-            }
+        JFrame frame = (parent == null ? null : (JFrame) 
SwingUtilities.getRoot(parent));
 
-            sb.insert(x, '\n');
-            width = x + 80;
-        }
-
-        JOptionPane.showMessageDialog(parent, exceptionName + ":\n" + sb, 
"Error", JOptionPane.ERROR_MESSAGE);
+        new ExceptionDialog(frame, ex);
     }
 
     public static boolean isMacOSX() {
@@ -207,6 +183,12 @@ public final class ClientHelper {
             textAreaMap.put(cutKeyStroke, DefaultEditorKit.cutAction);
             textAreaMap.put(allKeyStroke, DefaultEditorKit.selectAllAction);
 
+            InputMap editorPaneMap = (InputMap) 
UIManager.get("EditorPane.focusInputMap");
+            editorPaneMap.put(copyKeyStroke, DefaultEditorKit.copyAction);
+            editorPaneMap.put(pasteKeyStroke, DefaultEditorKit.pasteAction);
+            editorPaneMap.put(cutKeyStroke, DefaultEditorKit.cutAction);
+            editorPaneMap.put(allKeyStroke, DefaultEditorKit.selectAllAction);
+
             InputMap passwordFieldMap = (InputMap) 
UIManager.get("PasswordField.focusInputMap");
             passwordFieldMap.put(pasteKeyStroke, DefaultEditorKit.pasteAction);
         }
@@ -463,7 +445,7 @@ public final class ClientHelper {
             } else if (c == '"') {
                 sb.append("&quot;");
             } else if (c == '\'') {
-                sb.append("&apos;");
+                sb.append("&#39;");
             } else if (c > 127) {
                 sb.append("&#" + (int) c + ";");
             } else {

Modified: 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConnectionErrorDialog.java
URL: 
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConnectionErrorDialog.java?rev=1695289&r1=1695288&r2=1695289&view=diff
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConnectionErrorDialog.java
 (original)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConnectionErrorDialog.java
 Tue Aug 11 12:17:04 2015
@@ -72,17 +72,21 @@ public class ConnectionErrorDialog exten
     }
 
     private void createGUI() {
-        setMinimumSize(new Dimension(600, 400));
-        setPreferredSize(new Dimension(600, 450));
+        setMinimumSize(new Dimension(WorkbenchScale.scaleInt(600), 
WorkbenchScale.scaleInt(400)));
+        setPreferredSize(new Dimension(WorkbenchScale.scaleInt(600), 
WorkbenchScale.scaleInt(450)));
 
         setLayout(new BorderLayout());
 
         StringBuilder hint = new StringBuilder(1024);
         hint.append("<h2><font color=\"red\">Exception: <em>" + 
exception.getClass().getSimpleName()
-                + "</em></font><br>" + exception.getMessage() + "</h2>");
+                + "</em></font><br>");
+        ClientHelper.encodeHtml(hint, exception.getMessage());
+        hint.append("</h2>");
         if (exception.getCause() != null) {
             hint.append("<h3><font color=\"red\">Cause: <em>" + 
exception.getCause().getClass().getSimpleName()
-                    + "</em></font><br>" + exception.getCause().getMessage() + 
"</h3>");
+                    + "</em></font><br>");
+            ClientHelper.encodeHtml(hint, exception.getCause().getMessage());
+            hint.append("</h3>");
         }
         hint.append("<hr><br>");
         hint.append(getHint());
@@ -95,6 +99,7 @@ public class ConnectionErrorDialog exten
 
         JEditorPane hints = new JEditorPane("text/html", hint.toString());
         hints.setEditable(false);
+        hints.setCaretPosition(0);
 
         hintsPanel.add(new JScrollPane(hints, 
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));

Added: 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
URL: 
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java?rev=1695289&view=auto
==============================================================================
--- 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
 (added)
+++ 
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
 Tue Aug 11 12:17:04 2015
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.workbench;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+
+public class ExceptionDialog extends JDialog {
+
+    private static final long serialVersionUID = 1L;
+
+    private final Exception exception;
+
+    public ExceptionDialog(Frame owner, Exception exception) {
+        super(owner, "Exception", true);
+        this.exception = exception;
+
+        createGUI();
+    }
+
+    private void createGUI() {
+        setMinimumSize(new Dimension(WorkbenchScale.scaleInt(600), 
WorkbenchScale.scaleInt(150)));
+        setPreferredSize(new Dimension(WorkbenchScale.scaleInt(600), 
WorkbenchScale.scaleInt(150)));
+
+        setLayout(new BorderLayout());
+
+        // exception name
+        String exceptionName;
+        if (exception instanceof CmisBaseException) {
+            exceptionName = "CMIS Exception: <em>" + ((CmisBaseException) 
exception).getExceptionName() + "</em>";
+        } else {
+            exceptionName = "Exception: <em>" + 
exception.getClass().getSimpleName() + "</em>";
+        }
+
+        StringBuilder exceptionText = new StringBuilder(1024);
+        exceptionText.append("<h2><font color=\"red\">" + exceptionName + 
"</font><br>");
+        ClientHelper.encodeHtml(exceptionText, exception.getMessage());
+        exceptionText.append("</h2>");
+        if (exception.getCause() != null) {
+            exceptionText.append("<h3><font color=\"red\">Cause: <em>"
+                    + exception.getCause().getClass().getSimpleName() + 
"</em></font><br>");
+            ClientHelper.encodeHtml(exceptionText, 
exception.getCause().getMessage());
+            exceptionText.append("</h3>");
+        }
+        if (exception instanceof CmisBaseException) {
+            String errorContent = ((CmisBaseException) 
exception).getErrorContent();
+            if (errorContent != null && errorContent.length() > 0) {
+                exceptionText.append("<hr><br><b>Error Content:</b><br>");
+                ClientHelper.encodeHtml(exceptionText, errorContent);
+                setPreferredSize(new Dimension(getPreferredSize().width, 
WorkbenchScale.scaleInt(250)));
+            }
+        }
+
+        // exception panel
+        JPanel exceptionPanel = new JPanel();
+        exceptionPanel.setLayout(new BoxLayout(exceptionPanel, 
BoxLayout.PAGE_AXIS));
+        
exceptionPanel.setBorder(WorkbenchScale.scaleBorder(BorderFactory.createEmptyBorder(5,
 5, 5, 5)));
+        add(exceptionPanel, BorderLayout.CENTER);
+
+        JEditorPane exceptionTextPane = new JEditorPane("text/html", 
exceptionText.toString());
+        exceptionTextPane.setEditable(false);
+        exceptionTextPane.setCaretPosition(0);
+
+        exceptionPanel.add(new JScrollPane(exceptionTextPane, 
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
+
+        // close button
+        JPanel buttonPanel = new JPanel();
+        buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.PAGE_AXIS));
+        
buttonPanel.setBorder(WorkbenchScale.scaleBorder(BorderFactory.createEmptyBorder(0,
 5, 5, 5)));
+        add(buttonPanel, BorderLayout.PAGE_END);
+
+        JButton closeButton = new JButton("Close");
+        closeButton.setPreferredSize(new Dimension(Short.MAX_VALUE, 
WorkbenchScale.scaleInt(30)));
+        closeButton.setMaximumSize(new Dimension(Short.MAX_VALUE, 
Short.MAX_VALUE));
+        closeButton.setAlignmentX(Component.CENTER_ALIGNMENT);
+
+        closeButton.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ExceptionDialog.this.dispose();
+            }
+        });
+
+        buttonPanel.add(closeButton);
+
+        getRootPane().setDefaultButton(closeButton);
+
+        ClientHelper.installEscapeBinding(this, getRootPane(), true);
+
+        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+        pack();
+        setLocationRelativeTo(getOwner());
+
+        setVisible(true);
+    }
+}


Reply via email to