cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [cayenne] branch master updated: fix NullPointerException and minor cleanup
Date Thu, 16 Jan 2020 08:52:56 GMT
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 e4809a0  fix NullPointerException and minor cleanup
e4809a0 is described below

commit e4809a008e3d084ad26c62e419eff35c8009b65c
Author: Nikita Timofeev <stariy95@gmail.com>
AuthorDate: Thu Jan 16 11:52:48 2020 +0300

    fix NullPointerException and minor cleanup
---
 .../action/dbimport/TreeManipulationAction.java    | 68 ++++++++--------------
 .../modeler/editor/dbimport/DbImportView.java      |  4 +-
 .../dbimport/ReverseEngineeringTreePanel.java      |  9 ++-
 3 files changed, 30 insertions(+), 51 deletions(-)

diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/dbimport/TreeManipulationAction.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/dbimport/TreeManipulationAction.java
index a76f523..5b6c7d0 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/dbimport/TreeManipulationAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/dbimport/TreeManipulationAction.java
@@ -38,6 +38,8 @@ import org.apache.cayenne.modeler.util.CayenneAction;
 import javax.swing.JTree;
 import javax.swing.tree.TreePath;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -54,10 +56,10 @@ public abstract class TreeManipulationAction extends CayenneAction {
     DbImportTreeNode parentElement;
     DbImportTreeNode foundNode;
     String insertableNodeName;
-    Class insertableNodeClass;
+    Class<?> insertableNodeClass;
     boolean isMultipleAction;
     private boolean movedFromDbSchema;
-    private Map<Class, List<Class>> levels;
+    private Map<Class<?>, List<Class<?>>> levels;
     protected String name;
     protected boolean updateSelected;
 
@@ -91,7 +93,7 @@ public abstract class TreeManipulationAction extends CayenneAction {
         } else {
             selectedElement = foundNode;
         }
-        parentElement = (DbImportTreeNode) selectedElement.getParent();
+        parentElement = selectedElement.getParent();
         if (parentElement == null) {
             parentElement = selectedElement;
         }
@@ -120,44 +122,23 @@ public abstract class TreeManipulationAction extends CayenneAction {
     private void initLevels() {
         levels = new HashMap<>();
 
-        List<Class> rootChilds = new ArrayList<>();
-        rootChilds.add(Schema.class);
-        rootChilds.add(IncludeTable.class);
-        rootChilds.add(ExcludeTable.class);
-        rootChilds.add(IncludeColumn.class);
-        rootChilds.add(ExcludeColumn.class);
-        rootChilds.add(IncludeProcedure.class);
-        rootChilds.add(ExcludeProcedure.class);
-        levels.put(ReverseEngineering.class, rootChilds);
-
-        List<Class> catalogChilds = new ArrayList<>();
-        catalogChilds.add(Schema.class);
-        catalogChilds.add(IncludeTable.class);
-        catalogChilds.add(ExcludeTable.class);
-        catalogChilds.add(IncludeColumn.class);
-        catalogChilds.add(ExcludeColumn.class);
-        catalogChilds.add(IncludeProcedure.class);
-        catalogChilds.add(ExcludeProcedure.class);
-        levels.put(Catalog.class, catalogChilds);
-
-        List<Class> schemaChilds = new ArrayList<>();
-        schemaChilds.add(IncludeTable.class);
-        schemaChilds.add(ExcludeTable.class);
-        schemaChilds.add(IncludeColumn.class);
-        schemaChilds.add(ExcludeColumn.class);
-        schemaChilds.add(IncludeProcedure.class);
-        schemaChilds.add(ExcludeProcedure.class);
-        levels.put(Schema.class, schemaChilds);
-
-        List<Class> includeTableChilds = new ArrayList<>();
-        includeTableChilds.add(IncludeColumn.class);
-        includeTableChilds.add(ExcludeColumn.class);
-        levels.put(IncludeTable.class, includeTableChilds);
-        levels.put(ExcludeTable.class, null);
-        levels.put(IncludeColumn.class, null);
-        levels.put(ExcludeColumn.class, null);
-        levels.put(IncludeProcedure.class, null);
-        levels.put(ExcludeProcedure.class, null);
+        List<Class<?>> schemaChildren = Arrays.asList(
+                IncludeTable.class, ExcludeTable.class,
+                IncludeColumn.class, ExcludeColumn.class,
+                IncludeProcedure.class, ExcludeProcedure.class
+        );
+        List<Class<?>> rootChildren = new ArrayList<>(schemaChildren);
+        rootChildren.add(Schema.class);
+
+        levels.put(ReverseEngineering.class, rootChildren);
+        levels.put(Catalog.class, rootChildren);
+        levels.put(Schema.class, schemaChildren);
+        levels.put(IncludeTable.class, Arrays.asList(IncludeColumn.class, ExcludeColumn.class));
+        levels.put(ExcludeTable.class, Collections.emptyList());
+        levels.put(IncludeColumn.class, Collections.emptyList());
+        levels.put(ExcludeColumn.class, Collections.emptyList());
+        levels.put(IncludeProcedure.class, Collections.emptyList());
+        levels.put(ExcludeProcedure.class, Collections.emptyList());
     }
 
     public void setTree(DbImportTree tree) {
@@ -172,9 +153,8 @@ public abstract class TreeManipulationAction extends CayenneAction {
         if (node == null) {
             return false;
         }
-        Class selectedObjectClass = node.getUserObject().getClass();
-        List<Class> childs = levels.get(selectedObjectClass);
-        return childs != null && childs.contains(insertableNodeClass);
+        Class<?> selectedObjectClass = node.getUserObject().getClass();
+        return levels.get(selectedObjectClass).contains(insertableNodeClass);
     }
 
     boolean canInsert() {
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
index 3a7dd3d..c99be26 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/DbImportView.java
@@ -201,9 +201,9 @@ public class DbImportView extends JPanel {
             ReverseEngineering reverseEngineering = DbImportView.this.projectController.getApplication()
                     .getMetaData().get(map, ReverseEngineering.class);
             if(reverseEngineering == null) {
-                // create config with default values, but not store it into metadata
-                // config will be stored on change only, this is for not making project dirty
on just selecting dbimport tab
+                // create config with default values
                 reverseEngineering = new ReverseEngineering();
+                DbImportView.this.projectController.getApplication().getMetaData().add(map,
reverseEngineering);
             }
             configPanel.fillCheckboxes(reverseEngineering);
             configPanel.initializeTextFields(reverseEngineering);
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/ReverseEngineeringTreePanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/ReverseEngineeringTreePanel.java
index 2d9b0b5..fc2e42a 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/ReverseEngineeringTreePanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbimport/ReverseEngineeringTreePanel.java
@@ -39,7 +39,6 @@ import org.apache.cayenne.modeler.dialog.db.load.SchemaPopUpMenu;
 
 import javax.swing.JScrollPane;
 import javax.swing.JTree;
-import javax.swing.ScrollPaneLayout;
 import javax.swing.SwingUtilities;
 import javax.swing.tree.DefaultTreeCellRenderer;
 import javax.swing.tree.TreePath;
@@ -58,7 +57,7 @@ class ReverseEngineeringTreePanel extends JScrollPane {
 
     private ProjectController projectController;
     private TreeToolbarPanel treeToolbar;
-    private Map<Class, DefaultPopUpMenu> popups;
+    private Map<Class<?>, DefaultPopUpMenu> popups;
 
     ReverseEngineeringTreePanel(ProjectController projectController, DbImportTree reverseEngineeringTree,
                                 DbImportTree dbSchemaTree) {
@@ -122,7 +121,7 @@ class ReverseEngineeringTreePanel extends JScrollPane {
                     if (popupMenu != null) {
                         popupMenu.setProjectController(projectController);
                         popupMenu.setSelectedElement(selectedElement);
-                        popupMenu.setParentElement((DbImportTreeNode) selectedElement.getParent());
+                        popupMenu.setParentElement(selectedElement.getParent());
                         popupMenu.setTree(reverseEngineeringTree);
                         popupMenu.show(e.getComponent(), e.getX(), e.getY());
                     }
@@ -130,7 +129,7 @@ class ReverseEngineeringTreePanel extends JScrollPane {
                     DbImportTreeNode selectedNode = reverseEngineeringTree.getSelectedNode();
 
                     if( selectedNode.isExcludeColumn() || selectedNode.isIncludeColumn())
{
-                        DbImportTreeNode expandNode = (DbImportTreeNode) selectedNode.getParent();
+                        DbImportTreeNode expandNode = selectedNode.getParent();
 
                         DbImportTreeNode parentPath = dbSchemaTree.findNode(
                                 dbSchemaTree.getRootNode(), expandNode, 0
@@ -149,7 +148,7 @@ class ReverseEngineeringTreePanel extends JScrollPane {
 
 
                         if (findNode != null) {
-                            dbSchemaTree.expandPath(new TreePath(((DbImportTreeNode) findNode.getParent()).getPath()));
+                            dbSchemaTree.expandPath(new TreePath(findNode.getParent().getPath()));
                             scrollToNode(dbSchemaTree, findNode);
                         }
                     }


Mime
View raw message