You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2022/07/14 15:35:02 UTC

[cayenne] branch master updated: CAY-2751 Simplify DataNode configuration - update UI

This is an automated email from the ASF dual-hosted git repository.

ntimofeev pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new c1e3e91a0 CAY-2751 Simplify DataNode configuration  - update UI
c1e3e91a0 is described below

commit c1e3e91a0faf95166edc56001bde12c9fabdf805
Author: Nikita Timofeev <st...@gmail.com>
AuthorDate: Thu Jul 14 18:34:44 2022 +0300

    CAY-2751 Simplify DataNode configuration
     - update UI
---
 .../editor/datanode/CustomDataSourceEditor.java    | 33 +++++++++++++++------
 .../editor/datanode/CustomDataSourceView.java      | 11 +++++--
 .../editor/datanode/MainDataNodeEditor.java        | 34 ++++++++++++++++++----
 3 files changed, 61 insertions(+), 17 deletions(-)

diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceEditor.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceEditor.java
index 0315ed6fa..a3bf188ec 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceEditor.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceEditor.java
@@ -19,8 +19,7 @@
 
 package org.apache.cayenne.modeler.editor.datanode;
 
-import java.awt.Component;
-
+import org.apache.cayenne.configuration.DataNodeDescriptor;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.swing.BindingBuilder;
 import org.apache.cayenne.swing.BindingDelegate;
@@ -32,21 +31,37 @@ public class CustomDataSourceEditor extends DataSourceEditor {
 
     protected CustomDataSourceView view;
 
-    public CustomDataSourceEditor(ProjectController controller,
-            BindingDelegate nodeChangeProcessor) {
+    protected String factoryName;
+
+    public CustomDataSourceEditor(ProjectController controller, BindingDelegate nodeChangeProcessor) {
         super(controller, nodeChangeProcessor);
     }
 
+    @Override
+    public void setNode(DataNodeDescriptor node) {
+        setFactoryName(node.getDataSourceFactoryType());
+        super.setNode(node);
+    }
+
+    @Override
     protected void prepareBindings(BindingBuilder builder) {
         this.view = new CustomDataSourceView();
 
-        fieldAdapters = new ObjectBinding[1];
-        fieldAdapters[0] = builder.bindToTextField(
-                view.getLocationHint(),
-                "node.parameters");
+        fieldAdapters = new ObjectBinding[2];
+        fieldAdapters[0] = builder.bindToTextField(view.getFactoryName(), "factoryName");
+        fieldAdapters[1] = builder.bindToTextField(view.getLocationHint(), "node.parameters");
     }
 
-    public Component getView() {
+    @Override
+    public CustomDataSourceView getView() {
         return view;
     }
+
+    public String getFactoryName() {
+        return factoryName;
+    }
+
+    public void setFactoryName(String factoryName) {
+        this.factoryName = factoryName;
+    }
 }
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java
index b5e95fc1e..78dd079a7 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/CustomDataSourceView.java
@@ -31,10 +31,12 @@ import com.jgoodies.forms.layout.FormLayout;
 
 public class CustomDataSourceView extends JPanel {
 
+    protected JTextField factoryName;
     protected JTextField locationHint;
 
     public CustomDataSourceView() {
 
+        factoryName = new JTextFieldUndoable();
         locationHint = new JTextFieldUndoable();
 
         // assemble
@@ -42,9 +44,10 @@ public class CustomDataSourceView extends JPanel {
         DefaultFormBuilder builder = new DefaultFormBuilder(layout);
         builder.setDefaultDialogBorder();
 
-        builder.appendSeparator("Custom Configuration");
+        builder.appendSeparator("Custom Data Source Factory");
 
-        builder.append("Location Hint:", locationHint);
+        builder.append("Factory Class:", factoryName);
+        builder.append("Location Hint (optional):", locationHint);
 
         this.setLayout(new BorderLayout());
         this.add(builder.getPanel(), BorderLayout.CENTER);
@@ -53,4 +56,8 @@ public class CustomDataSourceView extends JPanel {
     public JTextField getLocationHint() {
         return locationHint;
     }
+
+    public JTextField getFactoryName() {
+        return factoryName;
+    }
 }
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
index 5cb47cb65..a6a1d188c 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/datanode/MainDataNodeEditor.java
@@ -54,9 +54,11 @@ import org.apache.cayenne.validation.ValidationException;
 public class MainDataNodeEditor extends CayenneController {
 
 	protected static final String NO_LOCAL_DATA_SOURCE = "Select DataSource for Local Work...";
+	private final static String XML_POOLING_DATA_SOURCE_FACTORY = XMLPoolingDataSourceFactory.class.getName();
 
 	private final static String[] STANDARD_DATA_SOURCE_FACTORIES = new String[] {
-	        XMLPoolingDataSourceFactory.class.getName()
+			DataSourceFactoryType.CAYENNE.getLabel(),
+			DataSourceFactoryType.CUSTOM.getLabel()
 	};
 
 	private final static String[] STANDARD_SCHEMA_UPDATE_STRATEGY = new String[] {
@@ -71,7 +73,7 @@ public class MainDataNodeEditor extends CayenneController {
 	protected DataNodeDescriptor node;
 	protected Map<String, DataSourceEditor> datasourceEditors;
 
-	protected DataSourceEditor defaultSubeditor;
+	protected CustomDataSourceEditor defaultSubeditor;
 	protected BindingDelegate nodeChangeProcessor;
 	protected ObjectBinding[] bindings;
 	protected ObjectBinding localDataSourceBinding;
@@ -106,12 +108,18 @@ public class MainDataNodeEditor extends CayenneController {
 	}
 
 	public String getFactoryName() {
-		return (node != null) ? node.getDataSourceFactoryType() : null;
+		return XML_POOLING_DATA_SOURCE_FACTORY.equals(node.getDataSourceFactoryType())
+				? DataSourceFactoryType.CAYENNE.getLabel()
+				: DataSourceFactoryType.CUSTOM.getLabel();
 	}
 
 	public void setFactoryName(String factoryName) {
 		if (node != null) {
-			node.setDataSourceFactoryType(factoryName);
+			if(DataSourceFactoryType.CAYENNE.getLabel().equals(factoryName)) {
+				node.setDataSourceFactoryType(XML_POOLING_DATA_SOURCE_FACTORY);
+			} else {
+				node.setDataSourceFactoryType(defaultSubeditor.getFactoryName());
+			}
 			showDataSourceSubview(factoryName);
 		}
 	}
@@ -162,7 +170,7 @@ public class MainDataNodeEditor extends CayenneController {
 
 	protected void initController() {
 		view.getDataSourceDetail().add(defaultSubeditor.getView(), "default");
-		view.getFactories().setEditable(true);
+		view.getFactories().setEditable(false);
 		// init combo box choices
 		view.getFactories().setModel(new DefaultComboBoxModel<>(STANDARD_DATA_SOURCE_FACTORIES));
 
@@ -251,7 +259,7 @@ public class MainDataNodeEditor extends CayenneController {
 		DataSourceEditor c = datasourceEditors.get(factoryName);
 		// create subview dynamically...
 		if (c == null) {
-			if (XMLPoolingDataSourceFactory.class.getName().equals(factoryName)) {
+			if (DataSourceFactoryType.CAYENNE.getLabel().equals(factoryName)) {
 				c = new JDBCDataSourceEditor((ProjectController) getParent(), nodeChangeProcessor);
 			} else {
 				// special case - no detail view, just show it and bail..
@@ -280,4 +288,18 @@ public class MainDataNodeEditor extends CayenneController {
 	public void setAdapterName(String name) {
 		node.setAdapterType(name);
 	}
+
+	enum DataSourceFactoryType {
+		CAYENNE("Cayenne Data Source Factory"),
+		CUSTOM("Custom Data Source Factory");
+		private final String label;
+
+		DataSourceFactoryType(String label) {
+			this.label = label;
+		}
+
+		public String getLabel() {
+			return label;
+		}
+	}
 }