cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From and...@apache.org
Subject svn commit: r886762 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: ./ editor/ editor/dbentity/ graph/ graph/action/
Date Thu, 03 Dec 2009 12:41:09 GMT
Author: andrey
Date: Thu Dec  3 12:41:09 2009
New Revision: 886762

URL: http://svn.apache.org/viewvc?rev=886762&view=rev
Log:
CAY-762 ERDiagram for Object Entities in Cayenne Modeler. Show on Graph buttons for entities

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/ShowGraphEntityAction.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ActionManager.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ActionManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ActionManager.java?rev=886762&r1=886761&r2=886762&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ActionManager.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ActionManager.java
Thu Dec  3 12:41:09 2009
@@ -91,6 +91,7 @@
 import org.apache.cayenne.modeler.action.ShowLogConsoleAction;
 import org.apache.cayenne.modeler.action.UndoAction;
 import org.apache.cayenne.modeler.action.ValidateAction;
+import org.apache.cayenne.modeler.graph.action.ShowGraphEntityAction;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.project.ProjectPath;
 
@@ -143,7 +144,8 @@
         OBJ_ENTITY_ACTIONS.addAll(Arrays.asList(
                 ObjEntitySyncAction.getActionName(),
                 CreateAttributeAction.getActionName(),
-                CreateRelationshipAction.getActionName()));
+                CreateRelationshipAction.getActionName(),
+                ShowGraphEntityAction.getActionName()));
     }
 
     static final Collection<String> DB_ENTITY_ACTIONS = new HashSet<String>(
@@ -152,7 +154,8 @@
         DB_ENTITY_ACTIONS.addAll(Arrays.asList(
                 CreateAttributeAction.getActionName(),
                 CreateRelationshipAction.getActionName(),
-                DbEntitySyncAction.getActionName()));
+                DbEntitySyncAction.getActionName(),
+                ShowGraphEntityAction.getActionName()));
     }
 
     static final Collection<String> EMBEDDABLE_ACTIONS = new HashSet<String>(
@@ -257,6 +260,7 @@
         registerAction(redoAction);
         
         registerAction(new CreateEmbeddableAction(application));
+        registerAction(new ShowGraphEntityAction(application));
     }
 
     private CayenneAction registerAction(CayenneAction action) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java?rev=886762&r1=886761&r2=886762&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/DataDomainTabbedView.java
Thu Dec  3 12:41:09 2009
@@ -24,12 +24,17 @@
 import javax.swing.event.ChangeListener;
 
 import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.event.DomainDisplayEvent;
+import org.apache.cayenne.modeler.event.DomainDisplayListener;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.graph.DataDomainGraphTab;
 
 /**
  * DataDomain editing tabs container 
  */
-public class DataDomainTabbedView extends JTabbedPane implements ChangeListener {
+public class DataDomainTabbedView extends JTabbedPane 
+    implements ChangeListener, DomainDisplayListener {
+    
     ProjectController mediator;
     
     DataDomainGraphTab graphTab;
@@ -61,6 +66,7 @@
         addTab("Graph", graphTab);
         
         addChangeListener(this);
+        mediator.addDomainDisplayListener(this);
     }
 
     public void stateChanged(ChangeEvent e) {
@@ -68,4 +74,11 @@
             graphTab.refresh();
         }
     }
+
+    public void currentDomainChanged(DomainDisplayEvent e) {
+        if (e instanceof EntityDisplayEvent) {
+            //need select an entity
+            setSelectedComponent(graphTab);
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java?rev=886762&r1=886761&r2=886762&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
Thu Dec  3 12:41:09 2009
@@ -25,8 +25,8 @@
 import java.awt.event.ActionListener;
 import java.util.Arrays;
 import java.util.EventObject;
-import java.util.List;
 import java.util.LinkedList;
+import java.util.List;
 
 import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
@@ -42,8 +42,8 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.event.EntityEvent;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
@@ -54,6 +54,7 @@
 import org.apache.cayenne.modeler.dialog.validator.DuplicatedAttributesDialog;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.event.ObjEntityDisplayListener;
+import org.apache.cayenne.modeler.graph.action.ShowGraphEntityAction;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.CellRenderers;
 import org.apache.cayenne.modeler.util.Comparators;
@@ -134,6 +135,8 @@
                 .add(app
                         .getAction(CreateRelationshipAction.getActionName())
                         .buildButton());
+        toolBar.addSeparator();
+        toolBar.add(app.getAction(ShowGraphEntityAction.getActionName()).buildButton());
         add(toolBar, BorderLayout.NORTH);
 
         // create widgets

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityTab.java?rev=886762&r1=886761&r2=886762&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityTab.java
Thu Dec  3 12:41:09 2009
@@ -45,6 +45,7 @@
 import org.apache.cayenne.modeler.editor.ExistingSelectionProcessor;
 import org.apache.cayenne.modeler.event.DbEntityDisplayListener;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+import org.apache.cayenne.modeler.graph.action.ShowGraphEntityAction;
 import org.apache.cayenne.modeler.util.ExpressionConvertor;
 import org.apache.cayenne.modeler.util.TextAdapter;
 import org.apache.cayenne.util.Util;
@@ -100,6 +101,8 @@
                 .add(app
                         .getAction(CreateRelationshipAction.getActionName())
                         .buildButton());
+        toolBar.addSeparator();
+        toolBar.add(app.getAction(ShowGraphEntityAction.getActionName()).buildButton());
 
         // create widgets
         name = new TextAdapter(new JTextField()) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java?rev=886762&r1=886761&r2=886762&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java
Thu Dec  3 12:41:09 2009
@@ -32,11 +32,14 @@
 import javax.swing.JToolBar;
 
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.action.ModelerProjectConfiguration;
 import org.apache.cayenne.modeler.event.DomainDisplayEvent;
 import org.apache.cayenne.modeler.event.DomainDisplayListener;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.graph.action.RebuildGraphAction;
 import org.apache.cayenne.modeler.graph.action.SaveAsImageAction;
 import org.apache.cayenne.modeler.graph.action.ZoomInAction;
@@ -118,9 +121,26 @@
     }
 
     public void currentDomainChanged(DomainDisplayEvent e) {
-        if (domain != e.getDomain()) {
-            domain = e.getDomain();
+        if (e instanceof EntityDisplayEvent) {
+            //selecting an event
+            
+            //choose type of diagram
+            Entity entity = ((EntityDisplayEvent) e).getEntity();
+            diagramCombo.setSelectedIndex(entity instanceof ObjEntity ? 1 : 0);
+            refresh();
+            
+            GraphBuilder builder = getGraphRegistry().getGraphMap(domain).get(getSelectedType());
+            
+            Object cell = builder.getEntityCell(entity.getName());
+            
+            if (cell != null) {
+                graph.setSelectionCell(cell);
+                graph.scrollCellToVisible(cell);
+            }
+        }
+        else if (domain != e.getDomain()) {
             needRebuild = true;
+            domain = e.getDomain();
             
             if (isVisible()) {
                 refresh();
@@ -134,9 +154,7 @@
      */
     public synchronized void refresh() {
         if (needRebuild && domain != null) {
-            ModelerProjectConfiguration conf = (ModelerProjectConfiguration)
-                mediator.getProject().getConfiguration();
-            graph = conf.getGraphRegistry().loadGraph(mediator, domain, 
+            graph = getGraphRegistry().loadGraph(mediator, domain, 
                     getSelectedType());
             scrollPane.setViewportView(graph);
             
@@ -177,4 +195,9 @@
     public JGraph getGraph() {
         return graph;
     }
+    
+    GraphRegistry getGraphRegistry() {
+        return ((ModelerProjectConfiguration) mediator.getProject().getConfiguration())
+            .getGraphRegistry();
+    }
 }

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/ShowGraphEntityAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/ShowGraphEntityAction.java?rev=886762&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/ShowGraphEntityAction.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/ShowGraphEntityAction.java
Thu Dec  3 12:41:09 2009
@@ -0,0 +1,88 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.graph.action;
+
+import java.awt.event.ActionEvent;
+
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.CayenneModelerFrame;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.editor.EditorView;
+import org.apache.cayenne.modeler.event.DomainDisplayEvent;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+import org.apache.cayenne.modeler.util.CayenneAction;
+import org.apache.cayenne.project.ProjectPath;
+
+/**
+ * Action that shows entity on the graph
+ */
+public class ShowGraphEntityAction extends CayenneAction {
+    public static String getActionName() {
+        return "ShowGraphEntity";
+    }
+    
+    public ShowGraphEntityAction(Application application) {
+        super(getActionName(), application, "Show on Graph");
+        setEnabled(true);
+    }
+
+    @Override
+    public String getIconName() {
+        return "icon-save-as-image.png";
+    }
+    
+    @Override
+    public void performAction(ActionEvent e) {
+        Entity entity = null;
+        
+        ProjectController mediator = getProjectController();
+        if (mediator.getCurrentDbEntity() != null) {
+            entity = mediator.getCurrentDbEntity();
+        }
+        else if (mediator.getCurrentObjEntity() != null) {
+            entity = mediator.getCurrentObjEntity();
+        }
+        
+        if (entity != null) {
+            showEntity(entity);
+        }
+    }
+    
+    @Override
+    public boolean enableForPath(ProjectPath obj) {
+        return obj.getObject() instanceof Entity;
+    }
+    
+    void showEntity(Entity entity) {
+        //we're always in same domain
+        EditorView editor = ((CayenneModelerFrame) Application.getInstance()
+                .getFrameController()
+                .getView()).getView();
+        
+        editor.getProjectTreeView().getSelectionModel().setSelectionPath(
+                editor.getProjectTreeView().getSelectionPath().getParentPath().getParentPath());
+        DomainDisplayEvent event = new EntityDisplayEvent(
+                editor.getProjectTreeView(),
+                entity,
+                entity.getDataMap(),
+                getProjectController().getCurrentDataDomain());
+        getProjectController().fireDomainDisplayEvent(event);
+    }
+}



Mime
View raw message