Author: jfuerth
Date: Mon Feb 23 13:43:12 2009
New Revision: 2950
Added:
trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java
trunk/src/icons/database_refresh.png (contents, props changed)
Modified:
trunk/src/ca/sqlpower/architect/swingui/DBTree.java
Log:
New refresh action that takes advantage of the new refresh feature in the
SQLObject API. You can try it out for yourself by right-clicking on a source
database object (in the DBTree) and choosing the "Refresh" item from the
popup menu.
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 Feb 23 13:43:12
2009
@@ -57,6 +57,7 @@
import ca.sqlpower.architect.swingui.action.DataSourcePropertiesAction;
import
ca.sqlpower.architect.swingui.action.DatabaseConnectionManagerAction;
import ca.sqlpower.architect.swingui.action.NewDataSourceAction;
+import ca.sqlpower.architect.swingui.action.RefreshAction;
import ca.sqlpower.architect.swingui.action.RemoveSourceDBAction;
import ca.sqlpower.architect.swingui.action.ShowTableContentsAction;
import ca.sqlpower.architect.swingui.dbtree.DBTreeCellRenderer;
@@ -301,8 +302,8 @@
}
/**
- * Creates a context sensitive menu for managing Database Connections.
There
- * are several modes of operations:
+ * Creates a context sensitive menu for manipulating the SQLObjects in
the
+ * tree. There are several modes of operations:
*
* <ol>
* <li>click on target database. the user can modify the properties
manually,
@@ -320,7 +321,7 @@
* contents of the playpen with the selected schema.
* </ol>
*
- * <p>FIXME: add in column, table, exported key, imported keys menus;
you can figure
+ * <p>TODO: add in column, table, exported key, imported keys menus;
you can figure
* out where the click came from by checking the TreePath.
*/
protected JPopupMenu refreshMenu(TreePath p) {
@@ -483,6 +484,10 @@
mi.setEnabled(false);
}
} else if (p != null && !isTargetDatabaseNode(p)) { // clicked on DBCS
item in DBTree
+ newMenu.addSeparator();
+
+ newMenu.add(new RefreshAction(session));
+
newMenu.addSeparator();
if (p.getLastPathComponent() instanceof SQLDatabase){
Added: trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java Mon
Feb 23 13:43:12 2009
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2009, 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 java.util.HashSet;
+import java.util.Set;
+
+import javax.swing.ImageIcon;
+import javax.swing.JOptionPane;
+import javax.swing.tree.TreePath;
+
+import ca.sqlpower.architect.swingui.ASUtils;
+import ca.sqlpower.architect.swingui.ArchitectSwingSession;
+import ca.sqlpower.architect.swingui.DBTree;
+import ca.sqlpower.sqlobject.SQLDatabase;
+import ca.sqlpower.sqlobject.SQLObject;
+import ca.sqlpower.sqlobject.SQLObjectException;
+import ca.sqlpower.sqlobject.SQLObjectUtils;
+
+public class RefreshAction extends AbstractArchitectAction {
+
+ public RefreshAction(ArchitectSwingSession session) {
+ super(session,
+ "Refresh",
+ "Refreshes the tree to match current structure in the
selected database",
+ new
ImageIcon(RefreshAction.class.getResource("/icons/database_refresh.png")));
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ DBTree dbTree = session.getSourceDatabases();
+
+ Set<SQLDatabase> databasesToRefresh = new HashSet<SQLDatabase>();
+ for (TreePath tp : dbTree.getSelectionPaths()) {
+ SQLObject so = (SQLObject) tp.getLastPathComponent();
+ SQLDatabase db = SQLObjectUtils.getAncestor(so,
SQLDatabase.class);
+ if (db != null && !db.isPlayPenDatabase()) {
+ databasesToRefresh.add(db);
+ }
+ }
+
+ if (databasesToRefresh.isEmpty()) {
+ JOptionPane.showMessageDialog(dbTree, "Please select a source
database to refresh");
+ return;
+ }
+
+ try {
+ for (SQLDatabase db : databasesToRefresh) {
+ db.refresh();
+ }
+ } catch (SQLObjectException ex) {
+ ASUtils.showExceptionDialogNoReport(dbTree, "Refresh failed",
ex);
+ }
+ }
+
+}
Added: trunk/src/icons/database_refresh.png
==============================================================================
Binary file. No diff available.