Author: thomasobrien95
Date: Thu Apr 23 14:17:38 2009
New Revision: 3003
Modified:
trunk/src/ca/sqlpower/architect/swingui/DDLExportPanel.java
trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
Log:
The DDLExportPanel now listens to the data source collection to update
its list if it changes. The ExportDDLAction now recreates the panel
to set all of the fields with newer data since the DDLExportPanel only
listens to the data source collection when it is open.
Modified: trunk/src/ca/sqlpower/architect/swingui/DDLExportPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/DDLExportPanel.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/DDLExportPanel.java Thu Apr 23
14:17:38 2009
@@ -36,6 +36,9 @@
import ca.sqlpower.architect.ddl.DDLGenerator;
import ca.sqlpower.architect.ddl.DDLUtils;
import ca.sqlpower.architect.ddl.GenericDDLGenerator;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.DatabaseListChangeEvent;
+import ca.sqlpower.sql.DatabaseListChangeListener;
import ca.sqlpower.sql.SPDataSource;
import ca.sqlpower.swingui.DataEntryPanel;
@@ -61,6 +64,22 @@
private JLabel schemaLabel;
private JTextField schemaField;
+
+ private final DatabaseListChangeListener databaseListChangeListener = new
DatabaseListChangeListener() {
+
+ public void databaseRemoved(DatabaseListChangeEvent e) {
+ targetDB.removeItem(e.getDataSource());
+ }
+
+ public void databaseAdded(DatabaseListChangeEvent e) {
+ targetDB.addItem(e.getDataSource());
+ }
+ };
+
+ /**
+ * This is the available data sources that can be forward engineered
to.
+ */
+ private DataSourceCollection plDotIni;
public DDLExportPanel(ArchitectSwingSession session) {
this.session = session;
@@ -102,8 +121,10 @@
panelProperties.add(new
JLabel(Messages.getString("DDLExportPanel.generateDDLForDbType")));
//$NON-NLS-1$
DDLGenerator ddlg = session.getDDLGenerator();
- Vector<Class<? extends DDLGenerator>> ddlTypes =
- DDLUtils.getDDLTypes(session.getContext().getPlDotIni());
+ plDotIni = session.getContext().getPlDotIni();
+
plDotIni.addDatabaseListChangeListener(databaseListChangeListener);
+ Vector<Class<? extends DDLGenerator>> ddlTypes =
+ DDLUtils.getDDLTypes(plDotIni);
if (!ddlTypes.contains(ddlg.getClass())) {
ddlTypes.add(ddlg.getClass());
}
@@ -171,6 +192,7 @@
// ------------------------ Architect Panel Stuff
-------------------------
public boolean applyChanges() {
+ disconnect();
DDLGenerator ddlg = session.getDDLGenerator();
Class<? extends DDLGenerator> selectedGeneratorClass =
(Class<? extends DDLGenerator>) dbType.getSelectedItem();
@@ -226,7 +248,11 @@
}
public void discardChanges() {
- // nothing to discard
+ disconnect();
+ }
+
+ private void disconnect() {
+
plDotIni.removeDatabaseListChangeListener(databaseListChangeListener);
}
public JTextField getSchemaField() {
Modified:
trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java Thu
Apr 23 14:17:38 2009
@@ -65,7 +65,9 @@
public ExportDDLAction(final ArchitectSwingSession session) {
super(session, Messages.getString("ExportDDLAction.name"),
Messages.getString("ExportDDLAction.description"), "fwdSQL"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
-
+ }
+
+ public void actionPerformed(ActionEvent e) {
final DDLExportPanel ddlPanel = new DDLExportPanel(session);
Callable<Boolean> okCall, cancelCall;
@@ -209,10 +211,7 @@
okCall, cancelCall);
d.pack();
- d.setLocationRelativeTo(frame);
- }
-
- public void actionPerformed(ActionEvent e) {
+ d.setLocationRelativeTo(frame);
d.setVisible(true);
}