Author: jfuerth
Date: Thu Oct 16 12:11:38 2008
New Revision: 2783
Added:
trunk/src/ca/sqlpower/architect/swingui/action/AddDataSourceAction.java
trunk/src/ca/sqlpower/architect/swingui/action/NewDataSourceAction.java
Removed:
trunk/regress/ca/sqlpower/architect/swingui/TestASUtilsMenu.java
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
trunk/src/ca/sqlpower/architect/swingui/ASUtils.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTree.java
Log:
Pulled out a few actions from DBTree into various places (some to the
session, some to their own classes in the swingui.action package). No
functional changes; just code reorganization.
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
==============================================================================
---
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
(original)
+++
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
Thu Oct 16 12:11:38 2008
@@ -25,6 +25,7 @@
import java.util.List;
import javax.swing.JDialog;
+import javax.swing.JMenu;
import ca.sqlpower.architect.AlwaysOKUserPrompter;
import ca.sqlpower.architect.ArchitectException;
@@ -361,6 +362,10 @@
public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener) {
// do-nothing stub
+ }
+
+ public JMenu createDataSourcesMenu() {
+ return new JMenu();
}
}
Modified: trunk/src/ca/sqlpower/architect/swingui/ASUtils.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ASUtils.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/ASUtils.java Thu Oct 16
12:11:38 2008
@@ -39,8 +39,6 @@
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import org.apache.log4j.Logger;
@@ -348,60 +346,6 @@
static double det(double a, double b, double c, double d) {
return a * d - b * c;
- }
-
- /**
- * Update a potentially-long JMenu with the nth-last items replaced by
sub-menus.
- * If the menu seems to fit the current frame, it is unchanged.
- * @param frame The parent Frame or JFrame, used to compute insets and to
listen for resizes
- * (neither of these is implemented at present).
- * @param input The JMenu.
- */
- public static void breakLongMenu(final Window frame, final JMenu input)
{
-
- if ( input.getItemCount() <= 0 )
- return;
-
- final int windowHeight = frame.getSize().height;
- final int totalRows = input.getItemCount();
- final int preferredHeight =
input.getItem(0).getPreferredSize().height;
- final int FUDGE = 3; // XXX find a better way to compute this...
-
- int rowsPerSubMenu = (windowHeight/ preferredHeight) - FUDGE;
- if ( rowsPerSubMenu < 3 )
- rowsPerSubMenu = 3;
- if (totalRows <= rowsPerSubMenu) {
- return;
- }
-
- JMenu parentMenu = input;
- JMenu subMenu = new JMenu(Messages.getString("ASUtils.moreSubmenu"));
//$NON-NLS-1$
- parentMenu.add(subMenu);
-
- while (input.getItemCount() > rowsPerSubMenu + 1) {
- final JMenuItem item = input.getItem(rowsPerSubMenu);
- subMenu.add(item); // Note that this removes it
from the original menu!
-
- if (subMenu.getItemCount() >= rowsPerSubMenu &&
- input.getItemCount() > rowsPerSubMenu + 1 ) {
- parentMenu = subMenu;
- subMenu = new JMenu(Messages.getString("ASUtils.moreSubmenu"));
//$NON-NLS-1$
- parentMenu.add(subMenu);
- }
- }
-
-
- /** TODO: Resizing the main window does not change the height of the
menu.
- * This is left as an exercise for the reader:
- * frame.addComponentListener(new ComponentAdapter() {
- * @Override
- * public void componentResized(ComponentEvent e) {
- * JMenu oldMenu = fileMenu;
- * // Loop over oldMenu, if JMenu, replace with its elements,
recursively...!
- * ASUtils.breakLongMenu(fileMenu);
- * }
- * });
- */
}
/**
Modified: trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/ArchitectFrame.java Thu Oct 16
12:11:38 2008
@@ -533,7 +533,7 @@
menuBar.add(connectionsMenu);
connectionsMenu.removeAll();
- final JMenu dbcsMenu = dbTree.setupDBCSMenu();
+ final JMenu dbcsMenu = session.createDataSourcesMenu();
final JMenuItem propertiesMenu = new
JMenuItem(dbTree.dbcsPropertiesAction);
final JMenuItem removeDBCSMenu = new
JMenuItem(dbTree.removeDBCSAction);
@@ -557,7 +557,7 @@
public void menuSelected(MenuEvent e) {
// updates for new connections
connectionsMenu.remove(dbcs);
- dbcs = dbTree.setupDBCSMenu();
+ dbcs = session.createDataSourcesMenu();
connectionsMenu.add(dbcs, 0);
// enable/disable dbcs related menu items
Modified: trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSession.java Thu
Oct 16 12:11:38 2008
@@ -22,6 +22,7 @@
import java.util.List;
import javax.swing.JDialog;
+import javax.swing.JMenu;
import ca.sqlpower.architect.ArchitectException;
import ca.sqlpower.architect.ArchitectSession;
@@ -317,4 +318,12 @@
* session closes.
*/
public void
removeSessionLifecycleListener(SessionLifecycleListener<ArchitectSwingSession>
listener);
+
+ /**
+ * Creates a new JMenu containing one item per data source in this
+ * session context's data source collection. When an item from this
+ * menu is selected, a new connection to that database will be created
+ * and added to this session's DB Tree as a source database.
+ */
+ public JMenu createDataSourcesMenu();
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Thu Oct 16 12:11:38 2008
@@ -33,6 +33,8 @@
import javax.swing.Action;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
@@ -60,12 +62,15 @@
import ca.sqlpower.architect.profile.ProfileManager;
import ca.sqlpower.architect.profile.ProfileManagerImpl;
import ca.sqlpower.architect.swingui.action.AboutAction;
+import ca.sqlpower.architect.swingui.action.AddDataSourceAction;
+import ca.sqlpower.architect.swingui.action.NewDataSourceAction;
import ca.sqlpower.architect.swingui.action.OpenProjectAction;
import ca.sqlpower.architect.swingui.action.PreferencesAction;
import ca.sqlpower.architect.swingui.dbtree.DBTree;
import ca.sqlpower.architect.swingui.olap.OLAPEditSession;
import ca.sqlpower.architect.swingui.olap.OLAPSchemaManager;
import ca.sqlpower.architect.undo.UndoManager;
+import ca.sqlpower.sql.SPDataSource;
import ca.sqlpower.swingui.SPSUtils;
import ca.sqlpower.swingui.SPSwingWorker;
import ca.sqlpower.swingui.event.SessionLifecycleEvent;
@@ -900,5 +905,20 @@
}
}
return new OLAPEditSession(this, olapSession);
+ }
+
+ // docs inherit from interface
+ public JMenu createDataSourcesMenu() {
+ JMenu dbcsMenu = new
JMenu(Messages.getString("DBTree.addSourceConnectionMenuName"));
//$NON-NLS-1$
+ dbcsMenu.add(new JMenuItem(new NewDataSourceAction(this)));
+ dbcsMenu.addSeparator();
+
+ // populate
+ for (SPDataSource dbcs : getContext().getConnections()) {
+ dbcsMenu.add(new JMenuItem(new
AddDataSourceAction(sourceDatabases, dbcs)));
+ }
+ SPSUtils.breakLongMenu(getArchitectFrame(), dbcsMenu);
+
+ return dbcsMenu;
}
}
Added:
trunk/src/ca/sqlpower/architect/swingui/action/AddDataSourceAction.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/swingui/action/AddDataSourceAction.java
Thu Oct 16 12:11:38 2008
@@ -0,0 +1,38 @@
+package ca.sqlpower.architect.swingui.action;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+
+import ca.sqlpower.architect.swingui.dbtree.DBTree;
+import ca.sqlpower.sql.SPDataSource;
+
+/**
+ * When invoked, this action adds the data source that was given in the
+ * constructor to the DBTree's model. There is normally one
+ * AddDataSourceAction associated with each item in the "Set Connection"
+ * menu.
+ */
+public class AddDataSourceAction extends AbstractAction {
+
+ /**
+ * The tree to add the data source to.
+ */
+ private final DBTree tree;
+
+ /**
+ * The data source to add to the tree.
+ */
+ private SPDataSource ds;
+
+ public AddDataSourceAction(DBTree tree, SPDataSource ds) {
+ super(ds.getName());
+ this.tree = tree;
+ this.ds = ds;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ tree.addSourceConnection(ds);
+ }
+
+}
\ No newline at end of file
Added:
trunk/src/ca/sqlpower/architect/swingui/action/NewDataSourceAction.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/swingui/action/NewDataSourceAction.java
Thu Oct 16 12:11:38 2008
@@ -0,0 +1,41 @@
+package ca.sqlpower.architect.swingui.action;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+
+import ca.sqlpower.architect.swingui.ASUtils;
+import ca.sqlpower.architect.swingui.ArchitectSwingSession;
+import ca.sqlpower.architect.swingui.Messages;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.SPDataSource;
+
+/**
+ * When invoked, this action creates a new data source and pops up the
+ * connection properties dialog to edit the new data source.
+ * <p>
+ * If the dialog is not canceled, the new data source will be added to the
db
+ * tree as well as the session context's data source collection (pl.ini).
+ */
+public class NewDataSourceAction extends AbstractAction {
+
+ private final ArchitectSwingSession session;
+
+ public NewDataSourceAction(ArchitectSwingSession session) {
+ super(Messages.getString("DBTree.newDbcsActionName"));
//$NON-NLS-1$
+ this.session = session;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ final DataSourceCollection plDotIni =
session.getContext().getPlDotIni();
+ final SPDataSource dataSource = new SPDataSource(plDotIni);
+ Runnable onAccept = new Runnable() {
+ public void run() {
+
session.getSourceDatabases().addSourceConnection(dataSource);
+ plDotIni.addDataSource(dataSource);
+ }
+ };
+
dataSource.setDisplayName(Messages.getString("DBTree.newConnectionName"));
//$NON-NLS-1$
+ ASUtils.showDbcsDialog(session.getArchitectFrame(), dataSource,
onAccept);
+ }
+}
\ No newline at end of file
Modified: trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTree.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTree.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTree.java Thu Oct 16
12:11:38 2008
@@ -72,11 +72,12 @@
import ca.sqlpower.architect.swingui.Messages;
import ca.sqlpower.architect.swingui.MultiDragTreeUI;
import
ca.sqlpower.architect.swingui.action.DatabaseConnectionManagerAction;
-import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.architect.swingui.action.NewDataSourceAction;
import ca.sqlpower.sql.SPDataSource;
import ca.sqlpower.swingui.JTreeCollapseAllAction;
import ca.sqlpower.swingui.JTreeExpandAllAction;
import ca.sqlpower.swingui.SPDataSourcePanel;
+import ca.sqlpower.swingui.SPSUtils;
import ca.sqlpower.swingui.SPSwingWorker;
public class DBTree extends JTree implements DragSourceListener {
@@ -86,7 +87,7 @@
protected JPopupMenu popup;
protected JMenu dbcsMenu;
protected SPDataSourcePanel spDataSourcePanel;
- protected NewDBCSAction newDBCSAction;
+ protected NewDataSourceAction newDBCSAction;
// XXX temporarily public while we sever dbtree from rest of architect
public DBCSPropertiesAction dbcsPropertiesAction;
@@ -103,17 +104,9 @@
/**
* The architect session, so we can access common objects
*/
- private final ArchitectSwingSession session;
+ final ArchitectSwingSession session;
/**
- * This is set to true when the SPDataSourcePanel is editting a new
- * connection spec. The dialog's "ok" and "cancel" button
- * handlers need to do different things for new and existing
- * specs.
- */
- protected boolean panelHoldsNewDBCS;
-
- /**
* The ActionMap key for the action that deletes the selected
* object in this DBTree.
*/
@@ -134,7 +127,7 @@
(this, DnDConstants.ACTION_COPY, new
DBTreeDragGestureListener());
setConnAsTargetDB = new SetConnAsTargetDB(null);
- newDBCSAction = new NewDBCSAction();
+ newDBCSAction = new NewDataSourceAction(session);
dbcsPropertiesAction = new DBCSPropertiesAction();
removeDBCSAction = new RemoveDBCSAction();
showInPlayPenAction = new ShowInPlayPenAction();
@@ -311,7 +304,7 @@
protected JPopupMenu refreshMenu(TreePath p) {
logger.debug("refreshMenu is being called."); //$NON-NLS-1$
JPopupMenu newMenu = new JPopupMenu();
- newMenu.add(setupDBCSMenu());
+ newMenu.add(session.createDataSourcesMenu());
newMenu.add(new DatabaseConnectionManagerAction(session));
@@ -490,7 +483,7 @@
newMenu.add(popupCompareToCurrent);
}
} catch (ArchitectException e) {
- ASUtils.showExceptionDialog(session,
Messages.getString("DBTree.errorCommunicatingWithDb"), e); //$NON-NLS-1$
+ SPSUtils.showExceptionDialogNoReport(this,
Messages.getString("DBTree.errorCommunicatingWithDb"), e); //$NON-NLS-1$
}
JMenuItem profile = new
JMenuItem(session.getArchitectFrame().getProfileAction());
@@ -524,7 +517,7 @@
newMenu.add(popupCompareToCurrent);
}
} catch (ArchitectException e) {
- ASUtils.showExceptionDialog(session,
Messages.getString("DBTree.errorCommunicatingWithDb"), e); //$NON-NLS-1$
+ SPSUtils.showExceptionDialogNoReport(this,
Messages.getString("DBTree.errorCommunicatingWithDb"), e); //$NON-NLS-1$
}
JMenuItem profile = new
JMenuItem(session.getArchitectFrame().getProfileAction());
@@ -548,7 +541,7 @@
final SQLExceptionNode node = (SQLExceptionNode)
p.getLastPathComponent();
newMenu.add(new JMenuItem(new
AbstractAction(Messages.getString("DBTree.showExceptionDetails")) {
//$NON-NLS-1$
public void actionPerformed(ActionEvent e) {
-
ASUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
+
SPSUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
Messages.getString("DBTree.exceptionNodeReport"), node.getException());
//$NON-NLS-1$
}
}));
@@ -568,10 +561,10 @@
parent.addChild(new SQLExceptionNode(ex,
Messages.getString("DBTree.exceptionDuringRetry"))); //$NON-NLS-1$
} catch
(ArchitectException e1) {
logger.error("Couldn't add SQLExceptionNode to menu:", e1);
//$NON-NLS-1$
-
ASUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
+
SPSUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
Messages.getString("DBTree.failedToAddSQLExceptionNode"),
e1); //$NON-NLS-1$
}
-
ASUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
+
SPSUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
Messages.getString("DBTree.exceptionDuringRetry"), ex); //$NON-NLS-1$
}
}
@@ -632,32 +625,12 @@
}
/**
- * When invoked, this action adds the DBCS that was given in the
- * constructor to the DBTree's model. There is normally one
- * AddDBCSAction associated with each item in the "Set Connection"
- * menu.
- */
- protected class AddDBCSAction extends AbstractAction {
- protected SPDataSource dbcs;
-
- public AddDBCSAction(SPDataSource dbcs) {
- super(dbcs.getName());
- this.dbcs = dbcs;
- }
-
- public void actionPerformed(ActionEvent e) {
- addSourceConnection(dbcs);
- }
-
- }
-
- /**
* Adds the given data source to the db tree as a source database
* connection.
*
* @param dbcs The data source to be added to the db tree.
*/
- private void addSourceConnection(SPDataSource dbcs) {
+ public void addSourceConnection(SPDataSource dbcs) {
SQLObject root = (SQLObject) getModel().getRoot();
try {
// check to see if we've already seen this one
@@ -676,7 +649,7 @@
}
} catch (ArchitectException ex) {
logger.warn("Couldn't add new database to tree", ex);
//$NON-NLS-1$
- ASUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
+
SPSUtils.showExceptionDialogNoReport(session.getArchitectFrame(),
Messages.getString("DBTree.couldNotAddNewConnection"),
ex); //$NON-NLS-1$
}
}
@@ -695,36 +668,6 @@
}
/**
- * When invoked, this action creates a new DBCS, sets the
- * panelHoldsNewDBCS flag, and pops up the propDialog to edit the
- * new DBCS.
- * <p>
- * If the database connection is created it will be added to the
- * db tree as well as the PL.ini.
- */
- protected class NewDBCSAction extends AbstractAction {
-
- public NewDBCSAction() {
- super(Messages.getString("DBTree.newDbcsActionName"));
//$NON-NLS-1$
- }
-
- public void actionPerformed(ActionEvent e) {
- final DataSourceCollection plDotIni =
session.getContext().getPlDotIni();
- final SPDataSource dataSource = new SPDataSource(plDotIni);
- Runnable onAccept = new Runnable() {
- public void run() {
- addSourceConnection(dataSource);
- plDotIni.addDataSource(dataSource);
- }
- };
-
dataSource.setDisplayName(Messages.getString("DBTree.newConnectionName"));
//$NON-NLS-1$
- ASUtils.showDbcsDialog(session.getArchitectFrame(),
dataSource, onAccept);
-
- panelHoldsNewDBCS = true;
- }
- }
-
- /**
* A Swing Worker that descends a tree of SQLObjects, stopping when a
* SQLColumn is encountered. This is useful in making the application
* more responsive: As soon as a source database is added to the tree,
@@ -1054,22 +997,5 @@
throw new ArchitectRuntimeException(ex);
}
}
- }
-
- /**
- * Returns a new updated connections menu.
- */
- public JMenu setupDBCSMenu() {
- dbcsMenu = new
JMenu(Messages.getString("DBTree.addSourceConnectionMenuName"));
//$NON-NLS-1$
- dbcsMenu.add(new JMenuItem(new NewDBCSAction()));
- dbcsMenu.addSeparator();
-
- // populate
- for (SPDataSource dbcs : session.getContext().getConnections()) {
- dbcsMenu.add(new JMenuItem(new AddDBCSAction(dbcs)));
- }
- ASUtils.breakLongMenu(session.getArchitectFrame(), dbcsMenu);
-
- return dbcsMenu;
}
}