chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From f...@apache.org
Subject svn commit: r1154553 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench: ./ details/
Date Sat, 06 Aug 2011 17:14:54 GMT
Author: fmui
Date: Sat Aug  6 17:14:53 2011
New Revision: 1154553

URL: http://svn.apache.org/viewvc?rev=1154553&view=rev
Log:
Workbench: changed clipboard format to CSV

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/FolderTable.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/QueryFrame.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypeSplitPane.java
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/AbstractDetailsTable.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=1154553&r1=1154552&r2=1154553&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
Sat Aug  6 17:14:53 2011
@@ -27,6 +27,10 @@ import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Desktop;
 import java.awt.Desktop.Action;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.io.BufferedOutputStream;
@@ -45,6 +49,7 @@ import java.net.URI;
 import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.GregorianCalendar;
 import java.util.List;
@@ -58,12 +63,14 @@ import javax.swing.JFileChooser;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
+import javax.swing.JTable;
 import javax.swing.KeyStroke;
 import javax.swing.UIManager;
 import javax.swing.text.DefaultEditorKit;
 
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.Document;
+import org.apache.chemistry.opencmis.client.api.ObjectId;
 import org.apache.chemistry.opencmis.client.api.Rendition;
 import org.apache.chemistry.opencmis.commons.data.ContentStream;
 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
@@ -338,6 +345,85 @@ public class ClientHelper {
         return null;
     }
 
+    public static void copyTableToClipboard(JTable table) {
+        final String newline = System.getProperty("line.separator");
+
+        final StringBuilder sb = new StringBuilder();
+        final int rows = table.getModel().getRowCount();
+        final int cols = table.getModel().getColumnCount();
+
+        for (int col = 0; col < cols; col++) {
+            if (col > 0) {
+                sb.append(",");
+            }
+
+            sb.append(formatCSVValue(table.getModel().getColumnName(col)));
+        }
+
+        sb.append(newline);
+
+        for (int row = 0; row < rows; row++) {
+            for (int col = 0; col < cols; col++) {
+                if (col > 0) {
+                    sb.append(",");
+                }
+
+                Object value = table.getModel().getValueAt(row, col);
+                sb.append(formatCSVValue(value));
+            }
+            sb.append(newline);
+        }
+
+        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+        Transferable transferable = new StringSelection(sb.toString());
+        clipboard.setContents(transferable, null);
+    }
+
+    private static String formatCSVValue(Object value) {
+        if (value == null) {
+            return "";
+        } else if (value instanceof GregorianCalendar) {
+            return getDateString((GregorianCalendar) value);
+        } else if (value instanceof String) {
+            String s = value.toString();
+
+            StringBuffer sb = new StringBuffer();
+            sb.append('\"');
+
+            for (int i = 0; i < s.length(); i++) {
+                char c = s.charAt(i);
+                sb.append(c);
+                if (c == '\"') {
+                    sb.append('\"');
+                }
+            }
+
+            sb.append('\"');
+
+            return sb.toString();
+        } else if (value instanceof Collection<?>) {
+            StringBuffer sb = new StringBuffer();
+            sb.append("[");
+
+            for (Object v : (Collection<?>) value) {
+                if (sb.length() > 1) {
+                    sb.append(",");
+                }
+                sb.append(formatCSVValue(v));
+            }
+
+            sb.append("]");
+
+            return sb.toString();
+        } else if (value instanceof ObjectId) {
+            return formatCSVValue(((ObjectId) value).getId());
+        } else if (value instanceof ImageIcon) {
+            return "<icon>";
+        }
+
+        return value.toString();
+    }
+
     public static String readFileAndRemoveHeader(String file) {
         if (file == null) {
             return "";

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/FolderTable.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/FolderTable.java?rev=1154553&r1=1154552&r2=1154553&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/FolderTable.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/FolderTable.java
Sat Aug  6 17:14:53 2011
@@ -22,6 +22,8 @@ import java.awt.Cursor;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
 import java.awt.datatransfer.UnsupportedFlavorException;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.awt.event.MouseAdapter;
@@ -37,6 +39,8 @@ import java.util.Map;
 import javax.swing.DropMode;
 import javax.swing.ImageIcon;
 import javax.swing.JComponent;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.ListSelectionModel;
 import javax.swing.TransferHandler;
@@ -88,6 +92,16 @@ public class FolderTable extends JTable 
             column.setPreferredWidth(COLUMN_WIDTHS[i]);
         }
 
+        final JPopupMenu popup = new JPopupMenu();
+        JMenuItem menuItem = new JMenuItem("Copy to clipboard");
+        popup.add(menuItem);
+
+        menuItem.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                ClientHelper.copyTableToClipboard(FolderTable.this);
+            }
+        });
+
         getSelectionModel().addListSelectionListener(new ListSelectionListener() {
             public void valueChanged(ListSelectionEvent e) {
                 if (e.getValueIsAdjusting()) {
@@ -117,6 +131,20 @@ public class FolderTable extends JTable 
                     doAction(e.isShiftDown());
                 }
             }
+
+            public void mousePressed(MouseEvent e) {
+                maybeShowPopup(e);
+            }
+
+            public void mouseReleased(MouseEvent e) {
+                maybeShowPopup(e);
+            }
+
+            private void maybeShowPopup(MouseEvent e) {
+                if (e.isPopupTrigger()) {
+                    popup.show(e.getComponent(), e.getX(), e.getY());
+                }
+            }
         });
 
         addKeyListener(new KeyListener() {

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/QueryFrame.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/QueryFrame.java?rev=1154553&r1=1154552&r2=1154553&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/QueryFrame.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/QueryFrame.java
Sat Aug  6 17:14:53 2011
@@ -22,14 +22,10 @@ import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-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;
 import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
@@ -161,30 +157,11 @@ public class QueryFrame extends JFrame {
 
         menuItem.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                StringBuilder sb = new StringBuilder();
-                int rows = resultsTable.getModel().getColumnCount();
-                for (int row = 0; row < rows; row++) {
-                    int cols = resultsTable.getModel().getColumnCount();
-                    for (int col = 0; col < cols; col++) {
-                        sb.append(resultsTable.getModel().getValueAt(row, col));
-                        sb.append("|");
-                    }
-                    sb.append("\n");
-                }
-
-                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
-                Transferable transferable = new StringSelection(sb.toString());
-                clipboard.setContents(transferable, null);
+                ClientHelper.copyTableToClipboard(resultsTable);
             }
         });
 
-        resultsTable.addMouseListener(new MouseListener() {
-            public void mouseExited(MouseEvent e) {
-            }
-
-            public void mouseEntered(MouseEvent e) {
-            }
-
+        resultsTable.addMouseListener(new MouseAdapter() {
             public void mouseClicked(MouseEvent e) {
                 int row = resultsTable.rowAtPoint(e.getPoint());
                 int column = resultsTable.columnAtPoint(e.getPoint());

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypeSplitPane.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypeSplitPane.java?rev=1154553&r1=1154552&r2=1154553&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypeSplitPane.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/TypeSplitPane.java
Sat Aug  6 17:14:53 2011
@@ -18,12 +18,18 @@
  */
 package org.apache.chemistry.opencmis.workbench;
 
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
 import javax.swing.JTable;
@@ -216,6 +222,32 @@ public class TypeSplitPane extends JSpli
                 column.setPreferredWidth(COLUMN_WIDTHS[i]);
             }
 
+            final JPopupMenu popup = new JPopupMenu();
+            JMenuItem menuItem = new JMenuItem("Copy to clipboard");
+            popup.add(menuItem);
+
+            menuItem.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+                    ClientHelper.copyTableToClipboard(PropertyDefinitionTable.this);
+                }
+            });
+
+            addMouseListener(new MouseAdapter() {
+                public void mousePressed(MouseEvent e) {
+                    maybeShowPopup(e);
+                }
+
+                public void mouseReleased(MouseEvent e) {
+                    maybeShowPopup(e);
+                }
+
+                private void maybeShowPopup(MouseEvent e) {
+                    if (e.isPopupTrigger()) {
+                        popup.show(e.getComponent(), e.getX(), e.getY());
+                    }
+                }
+            });
+
             setFillsViewportHeight(true);
         }
 

Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/AbstractDetailsTable.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/AbstractDetailsTable.java?rev=1154553&r1=1154552&r2=1154553&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/AbstractDetailsTable.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/details/AbstractDetailsTable.java
Sat Aug  6 17:14:53 2011
@@ -19,14 +19,10 @@
 package org.apache.chemistry.opencmis.workbench.details;
 
 import java.awt.Cursor;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-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;
 import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
 import java.util.Collection;
 
@@ -40,6 +36,7 @@ import javax.swing.table.TableColumn;
 
 import org.apache.chemistry.opencmis.client.api.CmisObject;
 import org.apache.chemistry.opencmis.client.api.ObjectId;
+import org.apache.chemistry.opencmis.workbench.ClientHelper;
 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
 import org.apache.chemistry.opencmis.workbench.model.ClientModelEvent;
 import org.apache.chemistry.opencmis.workbench.model.ObjectListener;
@@ -82,30 +79,11 @@ public abstract class AbstractDetailsTab
 
         menuItem.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
-                StringBuilder sb = new StringBuilder();
-                int rows = getDetailRowCount();
-                for (int row = 0; row < rows; row++) {
-                    int cols = getColumnNames().length;
-                    for (int col = 0; col < cols; col++) {
-                        sb.append(getDetailValueAt(row, col));
-                        sb.append("|");
-                    }
-                    sb.append("\n");
-                }
-
-                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
-                Transferable transferable = new StringSelection(sb.toString());
-                clipboard.setContents(transferable, null);
+                ClientHelper.copyTableToClipboard(AbstractDetailsTable.this);
             }
         });
 
-        addMouseListener(new MouseListener() {
-            public void mouseExited(MouseEvent e) {
-            }
-
-            public void mouseEntered(MouseEvent e) {
-            }
-
+        addMouseListener(new MouseAdapter() {
             public void mouseClicked(MouseEvent e) {
                 if (SwingUtilities.isLeftMouseButton(e)) {
                     int row = rowAtPoint(e.getPoint());



Mime
View raw message