chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1785343 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench: ClientHelper.java ConsoleHelper.java ExceptionDialog.java ExpertLoginTab.java
Date Fri, 03 Mar 2017 16:26:28 GMT
Author: fmui
Date: Fri Mar  3 16:26:28 2017
New Revision: 1785343

URL: http://svn.apache.org/viewvc?rev=1785343&view=rev
Log:
Workbench improvements

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/ConsoleHelper.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.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=1785343&r1=1785342&r2=1785343&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
Fri Mar  3 16:26:28 2017
@@ -21,6 +21,8 @@ package org.apache.chemistry.opencmis.wo
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Desktop;
+import java.awt.Dialog;
+import java.awt.Frame;
 import java.awt.Image;
 import java.awt.Toolkit;
 import java.awt.Window;
@@ -53,13 +55,14 @@ import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.InputMap;
 import javax.swing.JComponent;
-import javax.swing.JFrame;
 import javax.swing.JRootPane;
 import javax.swing.JTable;
 import javax.swing.KeyStroke;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
 import javax.swing.text.DefaultEditorKit;
+import javax.swing.undo.CannotUndoException;
+import javax.swing.undo.UndoManager;
 
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.ObjectId;
@@ -84,6 +87,9 @@ public final class ClientHelper {
     public static final int OBJECT_ICON_SIZE = 16;
     public static final int ICON_BUTTON_ICON_SIZE = 16;
 
+    public static final String UNDO_ACTION_KEY = "Undo";
+    public static final String REDO_ACTION_KEY = "Redo";
+
     private static final Logger LOG = LoggerFactory.getLogger(ClientHelper.class);
 
     private static final ImageIcon CMIS_ICON = getIcon("icon256.png");
@@ -130,9 +136,18 @@ public final class ClientHelper {
     public static void showError(Component parent, Throwable t) {
         logError(t);
 
-        JFrame frame = (parent == null ? null : (JFrame) SwingUtilities.getRoot(parent));
-
-        new ExceptionDialog(frame, t);
+        if (parent == null) {
+            new ExceptionDialog((Frame) null, t);
+        } else {
+            Window window = (Window) SwingUtilities.getRoot(parent);
+            if (window instanceof Frame) {
+                new ExceptionDialog((Frame) window, t);
+            } else if (window instanceof Dialog) {
+                new ExceptionDialog((Dialog) window, t);
+            } else {
+                new ExceptionDialog((Frame) null, t);
+            }
+        }
     }
 
     public static boolean isMacOSX() {
@@ -194,6 +209,52 @@ public final class ClientHelper {
         });
     }
 
+    public static AbstractAction createAndAttachUndoAction(final UndoManager undoManager,
JComponent component) {
+        AbstractAction undoAction = new AbstractAction(UNDO_ACTION_KEY) {
+            private static final long serialVersionUID = 1L;
+
+            public void actionPerformed(ActionEvent evt) {
+                try {
+                    if (undoManager.canUndo()) {
+                        undoManager.undo();
+                    }
+                } catch (CannotUndoException e) {
+                }
+            }
+        };
+
+        component.getActionMap().put(UNDO_ACTION_KEY, undoAction);
+
+        KeyStroke undoKey = isMacOSX() ? KeyStroke.getKeyStroke("meta pressed Z")
+                : KeyStroke.getKeyStroke("control pressed Z");
+        component.getInputMap().put(undoKey, UNDO_ACTION_KEY);
+
+        return undoAction;
+    }
+
+    public static AbstractAction createAndAttachRedoAction(final UndoManager undoManager,
JComponent component) {
+        AbstractAction redoAction = new AbstractAction(REDO_ACTION_KEY) {
+            private static final long serialVersionUID = 1L;
+
+            public void actionPerformed(ActionEvent evt) {
+                try {
+                    if (undoManager.canRedo()) {
+                        undoManager.redo();
+                    }
+                } catch (CannotUndoException e) {
+                }
+            }
+        };
+
+        component.getActionMap().put(REDO_ACTION_KEY, redoAction);
+
+        KeyStroke redoKey = isMacOSX() ? KeyStroke.getKeyStroke("meta shift pressed Z")
+                : KeyStroke.getKeyStroke("control shift pressed Z");
+        component.getInputMap().put(redoKey, REDO_ACTION_KEY);
+
+        return redoAction;
+    }
+
     public static ImageIcon getIcon(String name) {
         URL imageURL = ClientHelper.class.getResource("/images/" + name);
         if (imageURL != null) {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConsoleHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConsoleHelper.java?rev=1785343&r1=1785342&r2=1785343&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConsoleHelper.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ConsoleHelper.java
Fri Mar  3 16:26:28 2017
@@ -25,8 +25,6 @@ import java.awt.Desktop.Action;
 import java.awt.Toolkit;
 import java.awt.datatransfer.Clipboard;
 import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.StringSelection;
-import java.awt.datatransfer.Transferable;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
@@ -49,6 +47,7 @@ import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 import javax.swing.text.AttributeSet;
 import javax.swing.text.BadLocationException;
+import javax.swing.text.DefaultEditorKit;
 
 import org.apache.chemistry.opencmis.client.api.Session;
 import org.apache.chemistry.opencmis.commons.SessionParameter;
@@ -146,64 +145,16 @@ public class ConsoleHelper {
 
             final JPopupMenu popup = new JPopupMenu();
 
-            final JMenuItem cutItem = new JMenuItem("Cut");
-            cutItem.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    try {
-                        String text = console.getInputArea().getSelectedText();
-                        if (text != null) {
-                            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
-                            Transferable transferable = new StringSelection(text);
-                            clipboard.setContents(transferable, null);
-
-                            int start = console.getInputArea().getSelectionStart();
-                            int end = console.getInputArea().getSelectionEnd();
-                            console.getInputArea().getDocument().remove(start, end - start);
-                        }
-                    } catch (Exception ex) {
-                        ClientHelper.showError(console.getFrame().getRootPane(), ex);
-                    }
-                }
-            });
+            final JMenuItem cutItem = new JMenuItem(new DefaultEditorKit.CutAction());
+            cutItem.setText("Cut");
             popup.add(cutItem);
 
-            final JMenuItem copyItem = new JMenuItem("Copy");
-            copyItem.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    String text = console.getInputArea().getSelectedText();
-                    if (text != null) {
-                        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
-                        Transferable transferable = new StringSelection(text);
-                        clipboard.setContents(transferable, null);
-                    }
-                }
-            });
+            final JMenuItem copyItem = new JMenuItem(new DefaultEditorKit.CopyAction());
+            copyItem.setText("Copy");
             popup.add(copyItem);
 
-            final JMenuItem pasteItem = new JMenuItem("Paste");
-            pasteItem.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    try {
-                        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
-                        Object content = clipboard.getData(DataFlavor.stringFlavor);
-                        if (content != null) {
-                            int start = console.getInputArea().getSelectionStart();
-                            int end = console.getInputArea().getSelectionEnd();
-                            if (end - start > 0) {
-                                console.getInputArea().getDocument().remove(start, end -
start);
-                            }
-
-                            console.getInputArea().getDocument().insertString(console.getInputArea().getCaretPosition(),
-                                    content.toString(), null);
-                        }
-                    } catch (Exception ex) {
-                        ClientHelper.showError(console.getFrame().getRootPane(), ex);
-                    }
-                }
-            });
+            final JMenuItem pasteItem = new JMenuItem(new DefaultEditorKit.PasteAction());
+            pasteItem.setText("Paste");
             popup.add(pasteItem);
 
             popup.addSeparator();
@@ -253,7 +204,7 @@ public class ConsoleHelper {
                 }
             });
 
-            // read source codeÏÍ
+            // read source code
             if (file != null) {
                 console.getInputArea().setText(ClientHelper.readFileAndRemoveHeader(file));
             } else if (soureCode != null) {

Modified: 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=1785343&r1=1785342&r2=1785343&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExceptionDialog.java
Fri Mar  3 16:26:28 2017
@@ -20,6 +20,7 @@ package org.apache.chemistry.opencmis.wo
 
 import java.awt.BorderLayout;
 import java.awt.Component;
+import java.awt.Dialog;
 import java.awt.Dimension;
 import java.awt.Frame;
 import java.awt.event.ActionEvent;
@@ -51,6 +52,13 @@ public class ExceptionDialog extends JDi
         createGUI();
     }
 
+    public ExceptionDialog(Dialog owner, Throwable throwable) {
+        super(owner, "Exception", true);
+        this.throwable = throwable;
+
+        createGUI();
+    }
+
     private void createGUI() {
         setMinimumSize(WorkbenchScale.scaleDimension(new Dimension(600, 150)));
         setPreferredSize(WorkbenchScale.scaleDimension(new Dimension(600, 200)));
@@ -70,8 +78,8 @@ public class ExceptionDialog extends JDi
         ClientHelper.encodeHtml(exceptionText, throwable.getMessage());
         exceptionText.append("</h2>");
         if (throwable.getCause() != null) {
-            exceptionText.append("<h3><font color=\"red\">Cause: <em>"
-                    + throwable.getCause().getClass().getSimpleName() + "</em></font><br>");
+            exceptionText.append("<h3><font color=\"red\">Cause: <em>"
+ throwable.getCause().getClass().getSimpleName()
+                    + "</em></font><br>");
             ClientHelper.encodeHtml(exceptionText, throwable.getCause().getMessage());
             exceptionText.append("</h3>");
         }

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java?rev=1785343&r1=1785342&r2=1785343&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
Fri Mar  3 16:26:28 2017
@@ -20,6 +20,8 @@ package org.apache.chemistry.opencmis.wo
 
 import java.awt.BorderLayout;
 import java.awt.Font;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
@@ -38,6 +40,7 @@ import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.AbstractAction;
 import javax.swing.BorderFactory;
 import javax.swing.DropMode;
 import javax.swing.JComboBox;
@@ -48,6 +51,11 @@ import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
 import javax.swing.TransferHandler;
+import javax.swing.event.UndoableEditEvent;
+import javax.swing.event.UndoableEditListener;
+import javax.swing.text.DefaultEditorKit;
+import javax.swing.text.JTextComponent;
+import javax.swing.undo.UndoManager;
 
 import org.apache.chemistry.opencmis.client.SessionParameterMap;
 import org.apache.chemistry.opencmis.client.bindings.spi.ClientCertificateAuthenticationProvider;
@@ -71,6 +79,7 @@ public class ExpertLoginTab extends Abst
 
     private JComboBox<FileEntry> configs;
     private JTextArea sessionParameterTextArea;
+    private UndoManager undoManager;
     private List<FileEntry> sessionConfigurations;
 
     public ExpertLoginTab() {
@@ -122,6 +131,17 @@ public class ExpertLoginTab extends Abst
                 .setFont(new Font(Font.MONOSPACED, Font.PLAIN, sessionParameterTextArea.getFont().getSize()));
         add(new JScrollPane(sessionParameterTextArea), BorderLayout.CENTER);
 
+        // undo
+        undoManager = new UndoManager();
+        sessionParameterTextArea.getDocument().addUndoableEditListener(new UndoableEditListener()
{
+            public void undoableEditHappened(UndoableEditEvent e) {
+                undoManager.addEdit(e.getEdit());
+            }
+        });
+
+        AbstractAction undoAction = ClientHelper.createAndAttachUndoAction(undoManager, sessionParameterTextArea);
+        AbstractAction redoAction = ClientHelper.createAndAttachRedoAction(undoManager, sessionParameterTextArea);
+
         // drag and drop support
         sessionParameterTextArea.setTransferHandler(new TextAreaTransferHandler());
         sessionParameterTextArea.setDragEnabled(true);
@@ -129,6 +149,31 @@ public class ExpertLoginTab extends Abst
 
         // context menu
         final JPopupMenu popup = new JPopupMenu("Session Parameters");
+
+        final JMenuItem cutItem = new JMenuItem(new DefaultEditorKit.CutAction());
+        cutItem.setText("Cut");
+        popup.add(cutItem);
+
+        final JMenuItem copyItem = new JMenuItem(new DefaultEditorKit.CopyAction());
+        copyItem.setText("Copy");
+        popup.add(copyItem);
+
+        final JMenuItem pasteItem = new JMenuItem(new DefaultEditorKit.PasteAction());
+        pasteItem.setText("Paste");
+        popup.add(pasteItem);
+
+        popup.addSeparator();
+
+        final JMenuItem undoItem = new JMenuItem(undoAction);
+        undoItem.setText("Undo");
+        popup.add(undoItem);
+
+        final JMenuItem redoItem = new JMenuItem(redoAction);
+        redoItem.setText("Redo");
+        popup.add(redoItem);
+
+        popup.addSeparator();
+
         popup.add(createMenuGroup("Binding", SessionParameter.BINDING_TYPE, SessionParameter.ATOMPUB_URL,
                 SessionParameter.BROWSER_URL, SessionParameter.BROWSER_SUCCINCT,
                 SessionParameter.BROWSER_DATETIME_FORMAT));
@@ -174,6 +219,21 @@ public class ExpertLoginTab extends Abst
 
             private void maybeShowPopup(MouseEvent e) {
                 if (e.isPopupTrigger()) {
+                    if (sessionParameterTextArea.getSelectedText() != null) {
+                        cutItem.setEnabled(true);
+                        copyItem.setEnabled(true);
+
+                    } else {
+                        cutItem.setEnabled(false);
+                        copyItem.setEnabled(false);
+                    }
+
+                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+                    pasteItem.setEnabled(clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor));
+
+                    undoItem.setEnabled(undoManager.canUndo());
+                    redoItem.setEnabled(undoManager.canRedo());
+
                     popup.show(e.getComponent(), e.getX(), e.getY());
                 }
             }
@@ -254,11 +314,7 @@ public class ExpertLoginTab extends Abst
             // we support files and strings
             if (!support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)
                     && !support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
-                return false;
-            }
-
-            if (!support.isDrop()) {
-                return false;
+                return super.canImport(support);
             }
 
             return true;
@@ -272,7 +328,7 @@ public class ExpertLoginTab extends Abst
             }
 
             if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
-                // we have file
+                // we have a file
                 File file = null;
                 try {
                     List<File> fileList = (List<File>) support.getTransferable()
@@ -303,8 +359,21 @@ public class ExpertLoginTab extends Abst
             } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                 // we have string
                 try {
-                    sessionParameterTextArea
-                            .setText((String) support.getTransferable().getTransferData(DataFlavor.stringFlavor));
+                    String s = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
+
+                    if (support.isDrop()) {
+                        int index = ((JTextComponent.DropLocation) support.getDropLocation()).getIndex();
+                        sessionParameterTextArea.insert(s, index);
+                    } else {
+                        int start = sessionParameterTextArea.getSelectionStart();
+                        int end = sessionParameterTextArea.getSelectionEnd();
+
+                        if (start == end) {
+                            sessionParameterTextArea.insert(s, sessionParameterTextArea.getCaretPosition());
+                        } else {
+                            sessionParameterTextArea.replaceRange(s, start, end);
+                        }
+                    }
                 } catch (Exception e) {
                     ClientHelper.showError(ExpertLoginTab.this, e);
                 }
@@ -317,7 +386,16 @@ public class ExpertLoginTab extends Abst
 
         @Override
         public int getSourceActions(JComponent c) {
-            return COPY;
+            return COPY_OR_MOVE;
+        }
+
+        @Override
+        protected void exportDone(JComponent c, Transferable data, int action) {
+            if ((action & MOVE) > 0) {
+                int start = sessionParameterTextArea.getSelectionStart();
+                int end = sessionParameterTextArea.getSelectionEnd();
+                sessionParameterTextArea.replaceRange("", start, end);
+            }
         }
 
         @Override



Mime
View raw message