cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From skolbac...@apache.org
Subject [4/7] cayenne git commit: Modeler Reengineer dialog improvement\nSelect newly created data source
Date Thu, 03 Nov 2016 20:13:25 GMT
Modeler Reengineer dialog improvement\nSelect newly created data source


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/963077f3
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/963077f3
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/963077f3

Branch: refs/heads/master
Commit: 963077f3b6d52cc3909976f46d5e916a31801ee5
Parents: 374fa27
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Tue Nov 1 12:33:01 2016 +0300
Committer: Savva Kolbachev <s.kolbachev@gmail.com>
Committed: Thu Nov 3 22:54:28 2016 +0300

----------------------------------------------------------------------
 .../cayenne/modeler/ProjectController.java      | 64 +++++++++-----------
 .../modeler/dialog/db/ConnectionWizard.java     |  6 +-
 .../modeler/dialog/db/DataSourceWizard.java     | 41 +++++++++++--
 .../dialog/pref/DataSourcePreferences.java      | 11 ++++
 4 files changed, 78 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/963077f3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
index 1872fb9..12f38c4 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectController.java
@@ -68,40 +68,7 @@ import org.apache.cayenne.modeler.action.SaveAction;
 import org.apache.cayenne.modeler.action.SaveAsAction;
 import org.apache.cayenne.modeler.editor.CallbackType;
 import org.apache.cayenne.modeler.editor.ObjCallbackMethod;
-import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
-import org.apache.cayenne.modeler.event.CallbackMethodEvent;
-import org.apache.cayenne.modeler.event.CallbackMethodListener;
-import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
-import org.apache.cayenne.modeler.event.DataMapDisplayListener;
-import org.apache.cayenne.modeler.event.DataNodeDisplayEvent;
-import org.apache.cayenne.modeler.event.DataNodeDisplayListener;
-import org.apache.cayenne.modeler.event.DbAttributeDisplayListener;
-import org.apache.cayenne.modeler.event.DbEntityDisplayListener;
-import org.apache.cayenne.modeler.event.DbRelationshipDisplayListener;
-import org.apache.cayenne.modeler.event.DisplayEvent;
-import org.apache.cayenne.modeler.event.DomainDisplayEvent;
-import org.apache.cayenne.modeler.event.DomainDisplayListener;
-import org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent;
-import org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayListener;
-import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
-import org.apache.cayenne.modeler.event.EmbeddableDisplayListener;
-import org.apache.cayenne.modeler.event.EntityDisplayEvent;
-import org.apache.cayenne.modeler.event.EntityListenerEvent;
-import org.apache.cayenne.modeler.event.EntityListenerListener;
-import org.apache.cayenne.modeler.event.MultipleObjectsDisplayEvent;
-import org.apache.cayenne.modeler.event.MultipleObjectsDisplayListener;
-import org.apache.cayenne.modeler.event.ObjAttributeDisplayListener;
-import org.apache.cayenne.modeler.event.ObjEntityDisplayListener;
-import org.apache.cayenne.modeler.event.ObjRelationshipDisplayListener;
-import org.apache.cayenne.modeler.event.ProcedureDisplayEvent;
-import org.apache.cayenne.modeler.event.ProcedureDisplayListener;
-import org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent;
-import org.apache.cayenne.modeler.event.ProcedureParameterDisplayListener;
-import org.apache.cayenne.modeler.event.ProjectOnSaveEvent;
-import org.apache.cayenne.modeler.event.ProjectOnSaveListener;
-import org.apache.cayenne.modeler.event.QueryDisplayEvent;
-import org.apache.cayenne.modeler.event.QueryDisplayListener;
-import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
+import org.apache.cayenne.modeler.event.*;
 import org.apache.cayenne.modeler.pref.DataMapDefaults;
 import org.apache.cayenne.modeler.pref.DataNodeDefaults;
 import org.apache.cayenne.modeler.pref.ProjectStatePreferences;
@@ -1778,7 +1745,34 @@ public class ProjectController extends CayenneController {
     		ProjectOnSaveListener temp = (ProjectOnSaveListener) listener;
     		temp.beforeSaveChanges(e);
     	}
-    	
+    }
+
+    public void addDataSourceModificationListener(DataSourceModificationListener listener)
{
+        listenerList.add(DataSourceModificationListener.class, listener);
+    }
+
+    public void removeDataSourceModificationListener(DataSourceModificationListener listener)
{
+        listenerList.remove(DataSourceModificationListener.class, listener);
+    }
+
+    public void fireDataSourceModificationEvent(DataSourceModificationEvent e) {
+        for (DataSourceModificationListener listener : listenerList.getListeners(DataSourceModificationListener.class))
{
+            switch (e.getId()) {
+                case MapEvent.ADD:
+                    listener.callbackDataSourceAdded(e);
+                    break;
+                // TODO Change event not supported for now. Nikita Timofeev
+                // There is no good place to catch data source modification
+                /*case MapEvent.CHANGE:
+                    listener.callbackDataSourceChanged(e);
+                    break;*/
+                case MapEvent.REMOVE:
+                    listener.callbackDataSourceRemoved(e);
+                    break;
+                default:
+                    throw new IllegalArgumentException("Invalid RelationshipEvent type: "
+ e.getId());
+            }
+        }
     }
 
     public ArrayList<Embeddable> getEmbeddablesInCurrentDataDomain() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/963077f3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
index 7af622b..45a8bca 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/ConnectionWizard.java
@@ -67,10 +67,8 @@ public class ConnectionWizard extends DataSourceWizard {
             reportError("Connection Error", th);
             return;
         }
-        
-        // set success flag, and unblock the caller...
-        canceled = false;
-        view.dispose();
+
+        onClose(false);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/963077f3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
index 101bb8b..70eb82a 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/DataSourceWizard.java
@@ -21,6 +21,8 @@ package org.apache.cayenne.modeler.dialog.db;
 
 import org.apache.cayenne.modeler.ClassLoadingService;
 import org.apache.cayenne.modeler.dialog.pref.PreferenceDialog;
+import org.apache.cayenne.modeler.event.DataSourceModificationEvent;
+import org.apache.cayenne.modeler.event.DataSourceModificationListener;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.swing.BindingBuilder;
@@ -31,7 +33,6 @@ import java.awt.*;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Arrays;
-import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -57,6 +58,8 @@ public class DataSourceWizard extends CayenneController {
 
 	protected boolean canceled;
 
+	protected DataSourceModificationListener dataSourceListener;
+
 	public DataSourceWizard(CayenneController parent, String title, String altDataSourceKey,
                             DBConnectionInfo altDataSource) {
 		super(parent);
@@ -68,6 +71,7 @@ public class DataSourceWizard extends CayenneController {
 		this.connectionInfo = new DBConnectionInfo();
 
 		initBindings();
+		initDataSourceListener();
 	}
 
 	/**
@@ -87,6 +91,26 @@ public class DataSourceWizard extends CayenneController {
 		builder.bindToAction(view.getConfigButton(), "dataSourceConfigAction()");
 	}
 
+	protected void initDataSourceListener() {
+		dataSourceListener = new DataSourceModificationListener() {
+			@Override
+			public void callbackDataSourceRemoved(DataSourceModificationEvent e) {}
+
+			@Override
+			public void callbackDataSourceAdded(DataSourceModificationEvent e) {
+				setDataSourceKey(e.getDataSourceName());
+				refreshDataSources();
+			}
+		};
+		getApplication().getFrameController().getProjectController()
+				.addDataSourceModificationListener(dataSourceListener);
+	}
+
+	protected void removeDataSourceListener() {
+		getApplication().getFrameController().getProjectController()
+				.removeDataSourceModificationListener(dataSourceListener);
+	}
+
 	public String getDataSourceKey() {
 		return dataSourceKey;
 	}
@@ -158,14 +182,21 @@ public class DataSourceWizard extends CayenneController {
 			return;
 		}
 
-		// set success flag, and unblock the caller...
-		canceled = false;
-		view.dispose();
+		onClose(false);
 	}
 
 	public void cancelAction() {
-		canceled = true;
+		onClose(true);
+	}
+
+	/**
+	 * On close handler. Introduced to remove data source listener.
+	 */
+	protected void onClose(boolean canceled) {
+		// set success flag, and unblock the caller...
+		this.canceled = canceled;
 		view.dispose();
+		removeDataSourceListener();
 	}
 
 	/**

http://git-wip-us.apache.org/repos/asf/cayenne/blob/963077f3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
index 19c031c..0f43513 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/pref/DataSourcePreferences.java
@@ -37,7 +37,10 @@ import javax.swing.DefaultComboBoxModel;
 import javax.swing.JOptionPane;
 
 import org.apache.cayenne.datasource.DriverDataSource;
+import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.FileClassLoadingService;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.event.DataSourceModificationEvent;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.pref.CayennePreferenceEditor;
@@ -137,6 +140,7 @@ public class DataSourcePreferences extends CayenneController {
 			view.getDataSources().setModel(new DefaultComboBoxModel(keys));
 			view.getDataSources().setSelectedItem(creatorWizard.getName());
 			editDataSourceAction();
+			fireEvent(creatorWizard.getName(), MapEvent.ADD);
 		}
 	}
 
@@ -158,6 +162,7 @@ public class DataSourcePreferences extends CayenneController {
 				view.getDataSources().setModel(new DefaultComboBoxModel(keys));
 				view.getDataSources().setSelectedItem(wizard.getName());
 				editDataSourceAction();
+				fireEvent(wizard.getName(), MapEvent.ADD);
 			}
 		}
 	}
@@ -175,9 +180,15 @@ public class DataSourcePreferences extends CayenneController {
 			Arrays.sort(keys);
 			view.getDataSources().setModel(new DefaultComboBoxModel(keys));
 			editDataSourceAction(keys.length > 0 ? keys[0] : null);
+			fireEvent(key, MapEvent.REMOVE);
 		}
 	}
 
+	private void fireEvent(String dataSourceKey, int eventId) {
+		DataSourceModificationEvent event = new DataSourceModificationEvent(this, dataSourceKey,
eventId);
+		getApplication().getFrameController().getProjectController().fireDataSourceModificationEvent(event);
+	}
+
 	/**
 	 * Opens specified DataSource in the editor.
 	 */


Mime
View raw message