cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/3] cayenne git commit: Brain methods of classes BaseGraphBuilder and ProjectTreeView automatically refactored with Bandago
Date Wed, 07 Feb 2018 12:18:09 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 383cfb0d0 -> c11adead8


Brain methods of classes BaseGraphBuilder and ProjectTreeView
automatically refactored with Bandago

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

Branch: refs/heads/master
Commit: 221bed687134243da14e220daa8df3686bdb183d
Parents: 750d3d5
Author: Santiago Vidal <santiagovidal@192.168.0.104>
Authored: Mon Feb 5 10:33:49 2018 -0300
Committer: Santiago Vidal <santiagovidal@192.168.0.104>
Committed: Mon Feb 5 10:33:49 2018 -0300

----------------------------------------------------------------------
 .../apache/cayenne/modeler/ProjectTreeView.java | 76 +++++++++--------
 .../cayenne/modeler/graph/BaseGraphBuilder.java | 90 +++++++++++---------
 2 files changed, 94 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/221bed68/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
index 9e38d81..fc1a938 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
@@ -148,7 +148,44 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
     }
 
     private void initController() {
-        treeSelectionListener = new TreeSelectionListener() {
+    		initTreeSelectionListener();
+
+        treeWillExpandListener = new TreeWillExpandListener() {
+            @Override
+            public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
+                TreePath path = e.getPath();
+                if (!isPathSelected(path) && !isSelectionEmpty()) {
+                    setSelectionPath(path);
+                }
+            }
+
+            @Override
+            public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException
{
+                TreePath path = e.getPath();
+                if (!isPathSelected(path) && !isSelectionEmpty()) {
+                    setSelectionPath(path);
+                }
+            }
+        };
+
+        addTreeSelectionListener(treeSelectionListener);
+        addTreeWillExpandListener(treeWillExpandListener);
+
+        addMouseListener(new MouseClickHandler());
+
+        setupMediator();
+        mediator.addQueryListener(this);
+        mediator.addQueryDisplayListener(this);
+        mediator.addMultipleObjectsDisplayListener(this);
+
+        mediator.getApplication().getActionManager().setupCutCopyPaste(
+                this,
+                CutAction.class,
+                CopyAction.class);
+    }
+
+	private void initTreeSelectionListener() {
+		treeSelectionListener = new TreeSelectionListener() {
 
             public void valueChanged(TreeSelectionEvent e) {
                 TreePath[] paths = getSelectionPaths();
@@ -193,31 +230,10 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
                 return projectPath;
             }
         };
+	}
 
-        treeWillExpandListener = new TreeWillExpandListener() {
-            @Override
-            public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
-                TreePath path = e.getPath();
-                if (!isPathSelected(path) && !isSelectionEmpty()) {
-                    setSelectionPath(path);
-                }
-            }
-
-            @Override
-            public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException
{
-                TreePath path = e.getPath();
-                if (!isPathSelected(path) && !isSelectionEmpty()) {
-                    setSelectionPath(path);
-                }
-            }
-        };
-
-        addTreeSelectionListener(treeSelectionListener);
-        addTreeWillExpandListener(treeWillExpandListener);
-
-        addMouseListener(new MouseClickHandler());
-
-        mediator.addDomainListener(this);
+	private void setupMediator() {
+		mediator.addDomainListener(this);
         mediator.addDomainDisplayListener(this);
         mediator.addDataNodeListener(this);
         mediator.addDataNodeDisplayListener(this);
@@ -231,15 +247,7 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
         mediator.addEmbeddableListener(this);
         mediator.addProcedureListener(this);
         mediator.addProcedureDisplayListener(this);
-        mediator.addQueryListener(this);
-        mediator.addQueryDisplayListener(this);
-        mediator.addMultipleObjectsDisplayListener(this);
-
-        mediator.getApplication().getActionManager().setupCutCopyPaste(
-                this,
-                CutAction.class,
-                CopyAction.class);
-    }
+	}
 
     private void initFromModel(Project project) {
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/221bed68/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java
index 6f3b94a..c649a47 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java
@@ -131,31 +131,9 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
         GraphLayoutCache view = new GraphLayoutCache(model, new DefaultCellViewFactory());
         graph.setGraphLayoutCache(view);
 
-        graph.addMouseListener(new MouseAdapter() {
-            @Override
-            public void mouseReleased(MouseEvent e) {
-                if (e.isPopupTrigger()) {
-                    Object selected = graph.getSelectionCell();
-                    if (selected != null && selected instanceof DefaultGraphCell)
{
-                        Object userObject = ((DefaultGraphCell) selected).getUserObject();
-                        if (userObject instanceof EntityCellMetadata) {
-                            showPopup(e.getPoint(), ((EntityCellMetadata) userObject).fetchEntity());
-                        }
-                    }
-                }
-            }
-        });
+        
 
-        graph.addMouseWheelListener(new MouseWheelListener() {
-            @Override
-            public void mouseWheelMoved(MouseWheelEvent e) {
-                // limit scale
-                double scale = graph.getScale() / Math.pow(ZOOM_FACTOR, e.getWheelRotation());
-                scale = Math.max(scale, 0.1);
-                scale = Math.min(scale, 3);
-                graph.setScale(scale);
-            }
-        });
+        addMouseListeners();
 
         entityCells = new HashMap<>();
         createdObjects = new ArrayList<>();
@@ -198,7 +176,24 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
         }
         view.insert(createdObjects.toArray());
 
-        if (doLayout) {
+        setLayout(doLayout);
+
+        /*
+         * Adding isolated objects
+         * 
+         * We're placing them so that they will take maximum space in left top
+         * corner. The sample order is below:
+         * 
+         * 1 2 6 7... 3 5 8 ... 4 9... 10 ...
+         */
+        addIsolatedObjetcs(isolatedObjects);
+
+        view.insert(isolatedObjects.toArray());
+        graph.getModel().addUndoableEditListener(this);
+    }
+
+	private void setLayout(boolean doLayout) {
+		if (doLayout) {
             JGraphFacade facade = new JGraphFacade(graph);
 
             JGraphOrganicLayout layout = new JGraphOrganicLayout();
@@ -221,16 +216,38 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
             // Apply the results to the actual graph
             edit(nested);
         }
+	}
 
-        /*
-         * Adding isolated objects
-         * 
-         * We're placing them so that they will take maximum space in left top
-         * corner. The sample order is below:
-         * 
-         * 1 2 6 7... 3 5 8 ... 4 9... 10 ...
-         */
-        if (isolatedObjects.size() > 0) {
+	private void addMouseListeners() {
+		graph.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseReleased(MouseEvent e) {
+                if (e.isPopupTrigger()) {
+                    Object selected = graph.getSelectionCell();
+                    if (selected != null && selected instanceof DefaultGraphCell)
{
+                        Object userObject = ((DefaultGraphCell) selected).getUserObject();
+                        if (userObject instanceof EntityCellMetadata) {
+                            showPopup(e.getPoint(), ((EntityCellMetadata) userObject).fetchEntity());
+                        }
+                    }
+                }
+            }
+        });
+		
+		graph.addMouseWheelListener(new MouseWheelListener() {
+            @Override
+            public void mouseWheelMoved(MouseWheelEvent e) {
+                // limit scale
+                double scale = graph.getScale() / Math.pow(ZOOM_FACTOR, e.getWheelRotation());
+                scale = Math.max(scale, 0.1);
+                scale = Math.min(scale, 3);
+                graph.setScale(scale);
+            }
+        });
+	}
+
+	private void addIsolatedObjetcs(List<DefaultGraphCell> isolatedObjects) {
+		if (isolatedObjects.size() > 0) {
             int n = isolatedObjects.size() / 2; // number of isolated entities
             int x = (int) Math.ceil((Math.sqrt(1 + 8 * n) - 1) / 2); // side of
                                                                      // triangle
@@ -256,10 +273,7 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
                 row++;
             }
         }
-
-        view.insert(isolatedObjects.toArray());
-        graph.getModel().addUndoableEditListener(this);
-    }
+	}
 
     protected DefaultGraphCell createEntityCell(Entity entity) {
         DefaultGraphCell cell = new DefaultGraphCell(getCellMetadata(entity));


Mime
View raw message