Author: thomasobrien95
Date: Mon Dec 15 15:24:44 2008
New Revision: 2882

Added:
trunk/src/ca/sqlpower/architect/swingui/action/ShowTableContentsAction.java
Modified:
   trunk/src/ca/sqlpower/architect/swingui/DBTree.java
   trunk/src/ca/sqlpower/architect/swingui/action/messages.properties
   trunk/src/ca/sqlpower/architect/swingui/query/QueryDialog.java

Log:
Fix for bug 1313. The SQL Query tool can now be opened from right
clicking on a table in the DBTree and selecting the "Show Contents.."
option. The SQL Query tool is initialized with a select * from the
table to give users an idea of what the table contains.

Modified: trunk/src/ca/sqlpower/architect/swingui/DBTree.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/DBTree.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/DBTree.java Mon Dec 15 15:24:44 2008
@@ -68,6 +68,7 @@
import ca.sqlpower.architect.swingui.action.DatabaseConnectionManagerAction;
 import ca.sqlpower.architect.swingui.action.NewDataSourceAction;
 import ca.sqlpower.architect.swingui.action.RemoveSourceDBAction;
+import ca.sqlpower.architect.swingui.action.ShowTableContentsAction;
 import ca.sqlpower.architect.swingui.dbtree.DBTreeCellRenderer;
 import ca.sqlpower.architect.swingui.dbtree.DBTreeModel;
 import ca.sqlpower.architect.swingui.dbtree.DnDTreePathTransferable;
@@ -545,6 +546,7 @@
                 newMenu.add(profile);
JMenuItem selectAllChildTables = new JMenuItem(this.selectAllChildTablesAction);
                 newMenu.add(selectAllChildTables);
+ newMenu.add(new JMenuItem(new ShowTableContentsAction(session, (SQLTable) p.getLastPathComponent())));
                 newMenu.addSeparator();
             }
                        

Added: trunk/src/ca/sqlpower/architect/swingui/action/ShowTableContentsAction.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/swingui/action/ShowTableContentsAction.java Mon Dec 15 15:24:44 2008
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2008, SQL Power Group Inc.
+ *
+ * This file is part of Power*Architect.
+ *
+ * Power*Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Power*Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.swingui.action;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.JDialog;
+
+import ca.sqlpower.architect.SQLTable;
+import ca.sqlpower.architect.swingui.ArchitectSwingSession;
+import ca.sqlpower.architect.swingui.query.QueryDialog;
+
+/**
+ * This action will pop up the query tool in Architect and select all of the
+ * values of the given table to give the user information about what is in
+ * the table.
+ */
+public class ShowTableContentsAction extends AbstractArchitectAction {
+
+    /**
+ * The contents of this table will be displayed when the action executes.
+     */
+    private final SQLTable table;
+
+ public ShowTableContentsAction(ArchitectSwingSession session, SQLTable table) { + super(session, Messages.getString("ShowTableContentsAction.name"), Messages.getString("ShowTableContentsAction.description"));
+        this.table = table;
+    }
+
+    public void actionPerformed(ActionEvent e) {
+        String sql = "SELECT * FROM " + table.toQualifiedName();
+ JDialog sqlQueryDialog = new QueryDialog(session, session.getArchitectFrame(), Messages.getString("SQLQueryAction.dialogTitle"), table.getParentDatabase().getDataSource(), sql);
+        sqlQueryDialog.setVisible(true);
+    }
+
+}

Modified: trunk/src/ca/sqlpower/architect/swingui/action/messages.properties
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/messages.properties (original) +++ trunk/src/ca/sqlpower/architect/swingui/action/messages.properties Mon Dec 15 15:24:44 2008
@@ -188,6 +188,8 @@
 SearchReplaceAction.name=Find/Replace...
 SelectAllAction.description=Select All
 SelectAllAction.name=Select All
+ShowTableContentsAction.name=Show Contents...
+ShowTableContentsAction.description=Show the contents of the current table
 SQLQueryAction.dialogTitle=SQL Query
 SQLQueryAction.description=A tool for executing SQL queries.
 SQLQueryAction.name=SQL Query...

Modified: trunk/src/ca/sqlpower/architect/swingui/query/QueryDialog.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/query/QueryDialog.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/query/QueryDialog.java Mon Dec 15 15:24:44 2008
@@ -34,6 +34,7 @@
 import ca.sqlpower.architect.ArchitectException;
 import ca.sqlpower.architect.swingui.ArchitectSwingSession;
 import ca.sqlpower.architect.swingui.DBTree;
+import ca.sqlpower.sql.SPDataSource;
 import ca.sqlpower.swingui.query.SQLQueryUIComponents;

 /**
@@ -52,9 +53,19 @@
      * Creates and displays the window for executing SQL queries.
      */
public QueryDialog(ArchitectSwingSession session, JFrame sessionframe, String title) {
+        this(session, sessionframe, title, null, null);
+    }
+
+    /**
+     * Creates and displays a window for executing SQL queries. Allows
+     * specifying an initial data source and SQL script for the query
+     * window. If a null value is passed in for the ds or initialSQL
+     * then no initial querying will be done.
+     */
+ public QueryDialog(ArchitectSwingSession session, JFrame sessionframe, String title, SPDataSource ds, String initialSQL) {
        super(sessionframe, title);
        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
-       setSize(900,450);
+       setSize(900,650);
        try {
            dbTree = new DBTree(session);
        } catch (ArchitectException e) {
@@ -64,7 +75,7 @@
        TreeModel model = session.getSourceDatabases().getModel();
        dbTree.setModel(model);

- queryPanel = SQLQueryUIComponents.createQueryPanel(session, session.getContext().getPlDotIni(),this); + queryPanel = SQLQueryUIComponents.createQueryPanel(session, session.getContext().getPlDotIni(), this, ds, initialSQL);
         queryPanel.setMinimumSize(new Dimension(100,100));

         buildUI(session);

Reply via email to