cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [3/3] cayenne git commit: Code cleanup
Date Wed, 07 Feb 2018 12:18:11 GMT
Code cleanup


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

Branch: refs/heads/master
Commit: c11adead8319b8fb62e4bafcc24284913144041d
Parents: e8cae77
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Wed Feb 7 15:13:07 2018 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Wed Feb 7 15:13:07 2018 +0300

----------------------------------------------------------------------
 .../apache/cayenne/modeler/ProjectTreeView.java | 80 ++++++++++----------
 .../cayenne/modeler/graph/BaseGraphBuilder.java | 51 +++----------
 2 files changed, 51 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/c11adead/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 fc1a938..90ceb58 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
@@ -97,7 +97,6 @@ import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 import javax.swing.event.TreeWillExpandListener;
 import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.ExpandVetoException;
 import javax.swing.tree.MutableTreeNode;
 import javax.swing.tree.TreePath;
 import javax.swing.tree.TreeSelectionModel;
@@ -148,40 +147,10 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
     }
 
     private void initController() {
-    		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);
-
+        initTreeSelectionListener();
+        initTreeExpandListener();
         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() {
@@ -224,14 +193,37 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
              */
             private ConfigurationNode createProjectPath(TreePath treePath) {
                 Object[] path = treePath.getPath();
-                ConfigurationNode projectPath = (ConfigurationNode) ((DefaultMutableTreeNode)
path[path.length - 1])
-                        .getUserObject();
-
-                return projectPath;
+                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)path[path.length
- 1];
+                return (ConfigurationNode) treeNode.getUserObject();
             }
         };
+
+        addTreeSelectionListener(treeSelectionListener);
 	}
 
+	private void initTreeExpandListener() {
+        treeWillExpandListener = new TreeWillExpandListener() {
+            @Override
+            public void treeWillExpand(TreeExpansionEvent e) {
+                TreePath path = e.getPath();
+                if (!isPathSelected(path) && !isSelectionEmpty()) {
+                    setSelectionPath(path);
+                }
+            }
+
+            @Override
+            public void treeWillCollapse(TreeExpansionEvent e) {
+                TreePath path = e.getPath();
+                if (!isPathSelected(path) && !isSelectionEmpty()) {
+                    setSelectionPath(path);
+                }
+            }
+        };
+
+
+        addTreeWillExpandListener(treeWillExpandListener);
+    }
+
 	private void setupMediator() {
 		mediator.addDomainListener(this);
         mediator.addDomainDisplayListener(this);
@@ -247,6 +239,13 @@ 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) {
@@ -302,8 +301,7 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
 
             return (value != null) ? String.valueOf(PropertyUtils.getProperty(value, "name"))
: "";
         } catch (Exception e) {
-            String objectClass = (value == null) ? "(unknown)" : value.getClass().getName();
-            logObj.warn("Exception reading property 'name', class " + objectClass, e);
+            logObj.warn("Exception reading property 'name', class " + value.getClass().getName(),
e);
             return "";
         }
     }
@@ -430,7 +428,7 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
     public void procedureChanged(ProcedureEvent e) {
         if (e.isNameChange()) {
             Object[] path = new Object[] {
-                    (DataChannelDescriptor) mediator.getProject().getRootNode(),
+                    mediator.getProject().getRootNode(),
                     e.getProcedure().getDataMap(), e.getProcedure()
             };
 
@@ -443,7 +441,7 @@ public class ProjectTreeView extends JTree implements DomainDisplayListener,
     public void procedureRemoved(ProcedureEvent e) {
 
         removeNode(new Object[] {
-                (DataChannelDescriptor) mediator.getProject().getRootNode(),
+                mediator.getProject().getRootNode(),
                 e.getProcedure().getDataMap(), e.getProcedure()
         });
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/c11adead/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 c649a47..b11ac64 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
@@ -24,8 +24,6 @@ import java.awt.Font;
 import java.awt.Point;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.util.ArrayList;
@@ -131,8 +129,6 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
         GraphLayoutCache view = new GraphLayoutCache(model, new DefaultCellViewFactory());
         graph.setGraphLayoutCache(view);
 
-        
-
         addMouseListeners();
 
         entityCells = new HashMap<>();
@@ -186,7 +182,7 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
          * 
          * 1 2 6 7... 3 5 8 ... 4 9... 10 ...
          */
-        addIsolatedObjetcs(isolatedObjects);
+        addIsolatedObjects(isolatedObjects);
 
         view.insert(isolatedObjects.toArray());
         graph.getModel().addUndoableEditListener(this);
@@ -234,19 +230,16 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
             }
         });
 		
-		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);
-            }
+		graph.addMouseWheelListener(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) {
+	private void addIsolatedObjects(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
@@ -413,12 +406,7 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
     protected void removeEntityCell(Entity e) {
         final DefaultGraphCell cell = entityCells.get(e.getName());
         if (cell != null) {
-            runWithUndoDisabled(new Runnable() {
-                @Override
-                public void run() {
-                    graph.getGraphLayoutCache().remove(new Object[] { cell }, true, true);
-                }
-            });
+            runWithUndoDisabled(() -> graph.getGraphLayoutCache().remove(new Object[]
{ cell }, true, true));
             entityCells.remove(e.getName());
         }
     }
@@ -426,12 +414,7 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
     protected void removeRelationshipCell(Relationship rel) {
         final DefaultEdge edge = relCells.get(getQualifiedName(rel));
         if (edge != null) {
-            runWithUndoDisabled(new Runnable() {
-                @Override
-                public void run() {
-                    graph.getGraphLayoutCache().remove(new Object[] { edge });
-                }
-            });
+            runWithUndoDisabled(() -> graph.getGraphLayoutCache().remove(new Object[]
{ edge }));
             relCells.remove(getQualifiedName(rel));
         }
     }
@@ -593,21 +576,11 @@ abstract class BaseGraphBuilder implements GraphBuilder, DataMapListener
{
     }
 
     private void edit(final Map map) {
-        runWithUndoDisabled(new Runnable() {
-
-            public void run() {
-                graph.getGraphLayoutCache().edit(map);
-            }
-        });
+        runWithUndoDisabled(() -> graph.getGraphLayoutCache().edit(map));
     }
 
     private void insert(final Object cell) {
-        runWithUndoDisabled(new Runnable() {
-
-            public void run() {
-                graph.getGraphLayoutCache().insert(cell);
-            }
-        });
+        runWithUndoDisabled(() -> graph.getGraphLayoutCache().insert(cell));
     }
 
     private void runWithUndoDisabled(Runnable r) {


Mime
View raw message