You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2016/08/19 16:37:35 UTC

svn commit: r1756938 - in /chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main: java/org/apache/chemistry/opencmis/workbench/ resources/query/

Author: fmui
Date: Fri Aug 19 16:37:35 2016
New Revision: 1756938

URL: http://svn.apache.org/viewvc?rev=1756938&view=rev
Log:
Workbench: reorganized query snippets

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/from.txt
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/orderby.txt
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/properties.txt
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/queries.txt
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/select.txt
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/where.txt
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/QueryFrame.java

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=1756938&r1=1756937&r2=1756938&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 Fri Aug 19 16:37:35 2016
@@ -29,6 +29,9 @@ import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseMotionListener;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.List;
@@ -40,6 +43,7 @@ import javax.swing.JCheckBox;
 import javax.swing.JFormattedTextField;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
+import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
@@ -60,7 +64,7 @@ import org.apache.chemistry.opencmis.cli
 import org.apache.chemistry.opencmis.client.runtime.ObjectIdImpl;
 import org.apache.chemistry.opencmis.commons.PropertyIds;
 import org.apache.chemistry.opencmis.commons.data.PropertyData;
-import org.apache.chemistry.opencmis.workbench.icons.CopyIcon;
+import org.apache.chemistry.opencmis.commons.impl.IOUtils;
 import org.apache.chemistry.opencmis.workbench.icons.QueryIcon;
 import org.apache.chemistry.opencmis.workbench.model.ClientModel;
 import org.apache.chemistry.opencmis.workbench.swing.IdRenderer;
@@ -75,19 +79,6 @@ public class QueryFrame extends JFrame {
     private static final String WINDOW_TITLE = "CMIS Query";
     private static final String DEFAULT_QUERY = "SELECT * FROM cmis:document";
 
-    private static final String[] QUERY_SNIPPETS = new String[] { //
-    "SELECT * FROM cmis:document", //
-            "SELECT * FROM cmis:folder", //
-            "SELECT cmis:objectId, cmis:name, SCORE() AS score FROM cmis:document WHERE CONTAINS('?')", //
-            "WHERE cmis:name LIKE '%'", //
-            "WHERE ? IN (?, ?, ?)", //
-            "WHERE IN_FOLDER('?')", //
-            "WHERE IN_TREE('?')", //
-            "WHERE ? = TIMESTAMP 'YYYY-MM-DDThh:mm:ss.sss[Z|+hh:mm|-hh:mm]'", //
-            "WHERE '?' = ANY ?", //
-            "ORDER BY cmis:name", //
-            "ORDER BY cmis:creationDate" };
-
     private final ClientModel model;
 
     private JTextArea queryText;
@@ -167,30 +158,35 @@ public class QueryFrame extends JFrame {
         inputPanel2.add(buttonPanel, BorderLayout.LINE_END);
 
         // snippets
-        final JPopupMenu snippetsPopup = new JPopupMenu();
-        for (final String s : QUERY_SNIPPETS) {
-            JMenuItem menuItem = new JMenuItem(s);
-            menuItem.addActionListener(new ActionListener() {
-                @Override
-                public void actionPerformed(ActionEvent e) {
-                    queryText.insert(s, queryText.getCaretPosition());
-                }
-            });
-            snippetsPopup.add(menuItem);
-        }
+        final JPopupMenu queryPopup = new JPopupMenu("Snippets");
+        queryPopup.add(createMenuGroup("Properties", readSnippets("properties.txt")));
+        queryPopup.add(createMenuGroup("Queries", readSnippets("queries.txt")));
+        queryPopup.add(createMenuGroup("SELECT", readSnippets("select.txt")));
+        queryPopup.add(createMenuGroup("FROM", readSnippets("from.txt")));
+        queryPopup.add(createMenuGroup("WHERE", readSnippets("where.txt")));
+        queryPopup.add(createMenuGroup("ORDER BY", readSnippets("orderby.txt")));
 
-        final JButton snippetButton = new JButton("Query Snippets", new CopyIcon(20, 20));
-        snippetButton.setFocusPainted(true);
-        snippetButton.setBorderPainted(false);
-        snippetButton.setContentAreaFilled(false);
-        snippetButton.addActionListener(new ActionListener() {
+        queryText.addMouseListener(new MouseAdapter() {
             @Override
-            public void actionPerformed(ActionEvent e) {
-                snippetsPopup.show(snippetButton, 0, snippetButton.getHeight());
+            public void mouseClicked(MouseEvent e) {
+            }
+
+            @Override
+            public void mousePressed(MouseEvent e) {
+                maybeShowPopup(e);
             }
-        });
 
-        inputPanel2.add(snippetButton, BorderLayout.LINE_START);
+            @Override
+            public void mouseReleased(MouseEvent e) {
+                maybeShowPopup(e);
+            }
+
+            private void maybeShowPopup(MouseEvent e) {
+                if (e.isPopupTrigger()) {
+                    queryPopup.show(e.getComponent(), e.getX(), e.getY());
+                }
+            }
+        });
 
         // query time label
         queryTimeLabel = new JLabel("");
@@ -285,6 +281,48 @@ public class QueryFrame extends JFrame {
         setVisible(true);
     }
 
+    private List<String> readSnippets(String filename) {
+        InputStream stream = null;
+        try {
+            stream = this.getClass().getResourceAsStream("/query/" + filename);
+            if (stream != null) {
+                return IOUtils.readAllLinesAsList(stream);
+            }
+        } catch (IOException e) {
+            IOUtils.closeQuietly(stream);
+        }
+
+        return Collections.emptyList();
+    }
+
+    private JMenu createMenuGroup(String name, List<String> subs) {
+        JMenu result = new JMenu(name);
+
+        PopupMenuActionListener listener = new PopupMenuActionListener(queryText);
+
+        for (String text : subs) {
+            JMenuItem textItem = new JMenuItem(text);
+            textItem.addActionListener(listener);
+
+            result.add(textItem);
+        }
+
+        return result;
+    }
+
+    private static class PopupMenuActionListener implements ActionListener {
+        private final JTextArea textArea;
+
+        public PopupMenuActionListener(JTextArea textArea) {
+            this.textArea = textArea;
+        }
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            textArea.insert(((JMenuItem) e.getSource()).getText(), textArea.getCaretPosition());
+        }
+    }
+
     private synchronized void doQuery() {
         String text = queryText.getText();
         text = text.replace('\n', ' ');

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/from.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/from.txt?rev=1756938&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/from.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/from.txt Fri Aug 19 16:37:35 2016
@@ -0,0 +1,6 @@
+FROM cmis:document 
+FROM cmis:folder 
+FROM cmis:relationship 
+FORM cmis:policy 
+FROM cmis:item 
+FROM type1 AS a JOIN type2 AS b ON a.cmis:objectId = b.cmis:objectId 
\ No newline at end of file

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/orderby.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/orderby.txt?rev=1756938&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/orderby.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/orderby.txt Fri Aug 19 16:37:35 2016
@@ -0,0 +1,2 @@
+ORDER BY cmis:name
+ORDER BY cmis:creationDate
\ No newline at end of file

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/properties.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/properties.txt?rev=1756938&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/properties.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/properties.txt Fri Aug 19 16:37:35 2016
@@ -0,0 +1,21 @@
+cmis:name
+cmis:objectId
+cmis:objectTypeId
+cmis:baseTypeId
+cmis:createdBy
+cmis:creationDate
+cmis:lastModifiedBy
+cmis:lastModificationDate
+cmis:isPrivateWorkingCopy
+cmis:isLatestVersion
+cmis:isMajorVersion
+cmis:isLatestMajorVersion
+cmis:versionSeriesId
+cmis:isVersionSeriesCheckedOut
+cmis:versionSeriesCheckedOutBy
+cmis:versionSeriesCheckedOutId
+cmis:contentStreamLength
+cmis:contentStreamMimeType
+cmis:contentStreamFileName
+cmis:parentId
+cmis:path
\ No newline at end of file

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/queries.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/queries.txt?rev=1756938&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/queries.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/queries.txt Fri Aug 19 16:37:35 2016
@@ -0,0 +1,3 @@
+SELECT * FROM cmis:document
+SELECT * FROM cmis:folder
+SELECT cmis:objectId, cmis:name, SCORE() AS score FROM cmis:document WHERE CONTAINS('?')
\ No newline at end of file

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/select.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/select.txt?rev=1756938&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/select.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/select.txt Fri Aug 19 16:37:35 2016
@@ -0,0 +1,2 @@
+SELECT * 
+SELECT cmis:objectId, cmis:name 
\ No newline at end of file

Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/where.txt
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/where.txt?rev=1756938&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/where.txt (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/resources/query/where.txt Fri Aug 19 16:37:35 2016
@@ -0,0 +1,6 @@
+WHERE cmis:name LIKE '%' 
+WHERE ? IN (?, ?, ?) 
+WHERE IN_FOLDER('?') 
+WHERE IN_TREE('?') 
+WHERE ? = TIMESTAMP 'YYYY-MM-DDThh:mm:ss.sss[Z|+hh:mm|-hh:mm]' 
+WHERE '?' = ANY ? 
\ No newline at end of file