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: CAY-2475 Modeler: move inheritance icon to name column in objAttr table and objRel table
Date Wed, 19 Sep 2018 07:18:35 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 417f176a6 -> b88ecaf5b


CAY-2475 Modeler: move inheritance icon to name column in objAttr table and objRel table


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

Branch: refs/heads/master
Commit: 3b90c6816356fbe3534b2c5bd6e976da21bd6847
Parents: 6221d5e
Author: Arseni Bulatski <ancarseni@gmail.com>
Authored: Mon Sep 17 15:34:31 2018 +0300
Committer: Arseni Bulatski <ancarseni@gmail.com>
Committed: Tue Sep 18 09:58:57 2018 +0300

----------------------------------------------------------------------
 RELEASE-NOTES.txt                               |  1 +
 .../modeler/editor/ObjAttributeTableModel.java  | 25 ++-----
 .../modeler/editor/ObjEntityAttributePanel.java | 77 +++++++++++---------
 .../editor/ObjEntityRelationshipPanel.java      | 44 ++++++++++-
 4 files changed, 94 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/3b90c681/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index ab0495d..5e6c4c7 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -17,6 +17,7 @@ CAY-2446 Run Disjoint By Id queries outside of synchronized block
 CAY-2447 Crypto support for LocalDateTime
 CAY-2471 Support multiple XML project versions
 CAY-2473 Modeler: cleanup attributes and relationship editors
+CAY-2475 Modeler: move inheritance icon to name column in objAttr table and objRel table
 
 Bug Fixes:
 

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3b90c681/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
index fe0e69e..61fb98b 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
@@ -25,7 +25,6 @@ import org.apache.cayenne.dba.TypesMapping;
 import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.EmbeddedAttribute;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
@@ -60,14 +59,13 @@ import java.util.List;
 public class ObjAttributeTableModel extends CayenneTableModel<ObjAttributeWrapper>
{
 
     // Columns
-    public static final int INHERITED = 0;
-    public static final int OBJ_ATTRIBUTE = 1;
-    public static final int OBJ_ATTRIBUTE_TYPE = 2;
-    public static final int DB_ATTRIBUTE = 3;
-    public static final int DB_ATTRIBUTE_TYPE = 4;
-    public static final int LOCKING = 5;
-    public static final int COMMENT = 6;
-    public static final int COLUMN_COUNT = 7;
+    public static final int OBJ_ATTRIBUTE = 0;
+    public static final int OBJ_ATTRIBUTE_TYPE = 1;
+    public static final int DB_ATTRIBUTE = 2;
+    public static final int DB_ATTRIBUTE_TYPE = 3;
+    public static final int LOCKING = 4;
+    public static final int COMMENT = 5;
+    public static final int COLUMN_COUNT = 6;
 
     private ObjEntity entity;
     private DbEntity dbEntity;
@@ -154,8 +152,6 @@ public class ObjAttributeTableModel extends CayenneTableModel<ObjAttributeWrappe
 
     public String getColumnName(int column) {
         switch (column) {
-            case INHERITED:
-                return "In";
             case OBJ_ATTRIBUTE:
                 return "Name";
             case OBJ_ATTRIBUTE_TYPE:
@@ -178,8 +174,6 @@ public class ObjAttributeTableModel extends CayenneTableModel<ObjAttributeWrappe
         DbAttribute dbAttribute = attribute.getDbAttribute();
 
         switch (column) {
-            case INHERITED:
-                return attribute.isInherited();
             case OBJ_ATTRIBUTE:
                 return attribute.getName();
             case OBJ_ATTRIBUTE_TYPE:
@@ -399,7 +393,7 @@ public class ObjAttributeTableModel extends CayenneTableModel<ObjAttributeWrappe
             return col == DB_ATTRIBUTE;
         }
 
-        return col != DB_ATTRIBUTE_TYPE && col != INHERITED;
+        return col != DB_ATTRIBUTE_TYPE;
     }
 
     public ObjEntity getEntity() {
@@ -426,9 +420,6 @@ public class ObjAttributeTableModel extends CayenneTableModel<ObjAttributeWrappe
     @Override
     public void sortByColumn(final int sortCol, boolean isAscent) {
         switch (sortCol) {
-            case INHERITED:
-                sortByElementProperty("inherited", isAscent);
-                break;
             case OBJ_ATTRIBUTE:
                 sortByElementProperty("name", isAscent);
                 break;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3b90c681/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
index 13aab58..6d300ae 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
@@ -46,22 +46,21 @@ import org.apache.cayenne.modeler.pref.TableColumnPreferences;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneTableModel;
-import org.apache.cayenne.modeler.util.DbAttributePathComboBoxRenderer;
 import org.apache.cayenne.modeler.util.DbAttributePathComboBoxEditor;
+import org.apache.cayenne.modeler.util.DbAttributePathComboBoxRenderer;
 import org.apache.cayenne.modeler.util.ModelerUtil;
 import org.apache.cayenne.modeler.util.PanelFactory;
 import org.apache.cayenne.modeler.util.ProjectUtil;
 import org.apache.cayenne.modeler.util.UIUtil;
 import org.apache.cayenne.modeler.util.combo.AutoCompletion;
-import org.apache.cayenne.swing.components.image.FilteredIconFactory;
 
 import javax.swing.BorderFactory;
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
-import javax.swing.JOptionPane;
 import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JTable;
@@ -71,30 +70,31 @@ import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.TableCellEditor;
+import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
-import java.awt.event.ActionEvent;
+import java.awt.Point;
+import java.awt.Rectangle;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+
 /**
  * Detail view of the ObjEntity attributes.
  */
 public class ObjEntityAttributePanel extends JPanel implements ObjEntityDisplayListener,
         ObjEntityListener, ObjAttributeListener, ProjectOnSaveListener {
 
-    private static final int INHERITANCE_COLUMN_WIDTH = 35;
-
     private ProjectController mediator;
     private CayenneTable table;
     private TableColumnPreferences tablePreferences;
@@ -142,10 +142,13 @@ public class ObjEntityAttributePanel extends JPanel implements ObjEntityDisplayL
             public void mouseReleased(MouseEvent e) {
                 int row = table.rowAtPoint(e.getPoint());
                 int col = table.columnAtPoint(e.getPoint());
-                if (row >= 0 && col == ObjAttributeTableModel.INHERITED) {
-                    if (Boolean.TRUE.equals(table.getValueAt(row, col))) {
-                        ActionManager actionManager = Application.getInstance().getActionManager();
-                        actionManager.getAction(ObjEntityToSuperEntityAction.class).performAction(null);
+                ObjAttribute objAttribute = ((ObjAttributeTableModel)table.getModel()).getAttribute(row).getValue();
+                int columnFromModel = table.getColumnModel().getColumn(col).getModelIndex();
+                if (row >= 0 && columnFromModel == ObjAttributeTableModel.OBJ_ATTRIBUTE)
{
+                    if(objAttribute.isInherited()) {
+                        TableCellRenderer renderer = table.getCellRenderer(row, col);
+                        Rectangle rectangle = table.getCellRect(row, col, false);
+                        ((CellRenderer) renderer).mouseClicked(e, rectangle.x);
                     }
                 }
             }
@@ -379,20 +382,17 @@ public class ObjEntityAttributePanel extends JPanel implements ObjEntityDisplayL
 
     protected void setUpTableStructure() {
         Map<Integer, Integer> minSizes = new HashMap<>();
-        Map<Integer, Integer> maxSizes = new HashMap<>();
-
-        minSizes.put(ObjAttributeTableModel.INHERITED, INHERITANCE_COLUMN_WIDTH);
-        maxSizes.put(ObjAttributeTableModel.INHERITED, INHERITANCE_COLUMN_WIDTH);
+        minSizes.put(ObjAttributeTableModel.OBJ_ATTRIBUTE, 150);
 
         initComboBoxes();
 
-        table.getColumnModel().getColumn(3).setCellRenderer(new DbAttributePathComboBoxRenderer());
-        table.getColumnModel().getColumn(3).setCellEditor(new DbAttributePathComboBoxEditor());
+        table.getColumnModel().getColumn(ObjAttributeTableModel.DB_ATTRIBUTE).setCellRenderer(new
DbAttributePathComboBoxRenderer());
+        table.getColumnModel().getColumn(ObjAttributeTableModel.DB_ATTRIBUTE).setCellEditor(new
DbAttributePathComboBoxEditor());
 
         tablePreferences.bind(
                 table,
                 minSizes,
-                maxSizes,
+                null,
                 null,
                 ObjAttributeTableModel.OBJ_ATTRIBUTE,
                 true);
@@ -446,32 +446,39 @@ public class ObjEntityAttributePanel extends JPanel implements ObjEntityDisplayL
             ObjAttributeTableModel model = (ObjAttributeTableModel) table.getModel();
             column = table.getColumnModel().getColumn(column).getModelIndex();
             ObjAttribute attribute = model.getAttribute(row).getValue();
-            if (column != ObjAttributeTableModel.INHERITED) {
 
-                if (!model.isCellEditable(row, column)) {
-                    setForeground(Color.GRAY);
-                } else {
-                    setForeground(isSelected && !hasFocus ? table.getSelectionForeground()
: table.getForeground());
-                }
-
-                if (attribute.isInherited()) {
-                    Font font = getFont();
-                    Font newFont = font.deriveFont(Font.ITALIC);
-                    setFont(newFont);
-                }
-                setIcon(null);
+            if (!model.isCellEditable(row, column)) {
+                setForeground(isSelected ? new Color(0xCECECE) : Color.GRAY);
             } else {
-                if (attribute.isInherited()) {
-                    Icon objEntityIcon = ModelerUtil.buildIcon("icon-inheritance.png");
-                    setIcon(objEntityIcon);
+                setForeground(isSelected && !hasFocus ? table.getSelectionForeground()
: table.getForeground());
+            }
+
+            setIcon(null);
+
+            if (attribute.isInherited()) {
+                Font font = getFont();
+                Font newFont = font.deriveFont(Font.ITALIC);
+                setFont(newFont);
+                if(column == ObjAttributeTableModel.OBJ_ATTRIBUTE) {
+                    ImageIcon icon = ModelerUtil.buildIcon("icon-inheritance.png");
+                    setIcon(icon);
                 }
-                setText("");
             }
+
             setFont(UIManager.getFont("Label.font"));
             setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
 
             return this;
         }
+
+        public void mouseClicked(MouseEvent event, int x) {
+            Point point = event.getPoint();
+            ImageIcon icon = ModelerUtil.buildIcon("icon-inheritance.png");
+            if(point.x - x <= icon.getIconWidth()) {
+                ActionManager actionManager = Application.getInstance().getActionManager();
+                actionManager.getAction(ObjEntityToSuperEntityAction.class).performAction(null);
+            }
+        }
     }
 
     private void resetTableModel() {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/3b90c681/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
index 4b53d8e..bd65ec0 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipPanel.java
@@ -31,6 +31,7 @@ import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.action.ActionManager;
 import org.apache.cayenne.modeler.action.CopyAttributeRelationshipAction;
 import org.apache.cayenne.modeler.action.CutAttributeRelationshipAction;
+import org.apache.cayenne.modeler.action.ObjEntityToSuperEntityAction;
 import org.apache.cayenne.modeler.action.PasteAction;
 import org.apache.cayenne.modeler.action.RemoveAttributeRelationshipAction;
 import org.apache.cayenne.modeler.dialog.objentity.ObjRelationshipInfo;
@@ -52,6 +53,7 @@ import org.slf4j.LoggerFactory;
 import javax.swing.BorderFactory;
 import javax.swing.DefaultCellEditor;
 import javax.swing.Icon;
+import javax.swing.ImageIcon;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
@@ -64,11 +66,16 @@ import javax.swing.UIManager;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableColumn;
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Component;
+import java.awt.Point;
+import java.awt.Rectangle;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.util.List;
 
 /**
@@ -127,6 +134,24 @@ public class ObjEntityRelationshipPanel extends JPanel implements ObjEntityDispl
                 ObjRelationshipTableModel.class,
                 "objEntity/relationshipTable");
 
+        table.addMouseListener(new MouseAdapter() {
+            @Override
+            public void mouseReleased(MouseEvent e) {
+                int row = table.rowAtPoint(e.getPoint());
+                int col = table.columnAtPoint(e.getPoint());
+                ObjRelationshipTableModel tableModel = ((ObjRelationshipTableModel) table.getModel());
+                ObjRelationship relationship = tableModel.getRelationship(row);
+                int columnFromModel = table.getColumnModel().getColumn(col).getModelIndex();
+                if (row >= 0 && columnFromModel == ObjRelationshipTableModel.REL_NAME)
{
+                    if(relationship.getSourceEntity() != tableModel.getEntity()) {
+                        TableCellRenderer renderer = table.getCellRenderer(row, col);
+                        Rectangle rectangle = table.getCellRect(row, col, false);
+                        ((StringRenderer) renderer).mouseClicked(e, rectangle.x);
+                    }
+                }
+            }
+        });
+
         // Create and install a popup
         Icon ico = ModelerUtil.buildIcon("icon-edit.png");
         resolveMenu = new CayenneAction.CayenneMenuItem("Database Mapping", ico);
@@ -412,19 +437,36 @@ public class ObjEntityRelationshipPanel extends JPanel implements ObjEntityDispl
                     .getModel();
             ObjRelationship relationship = model.getRelationship(row);
 
+            setIcon(null);
+
+            column = table.getColumnModel().getColumn(column).getModelIndex();
             if (relationship != null
                     && relationship.getSourceEntity() != model.getEntity()) {
-                setForeground(Color.GRAY);
+                setForeground(isSelected ? new Color(0xCECECE) : Color.GRAY);
+                if(column == ObjRelationshipTableModel.REL_NAME) {
+                    ImageIcon icon = ModelerUtil.buildIcon("icon-inheritance.png");
+                    setIcon(icon);
+                }
             } else {
                 setForeground(isSelected && !hasFocus
                         ? table.getSelectionForeground()
                         : table.getForeground());
             }
+
             setBorder(BorderFactory.createEmptyBorder(0,5,0,0));
             setFont(UIManager.getFont("Label.font"));
 
             return this;
         }
+
+        public void mouseClicked(MouseEvent event, int x) {
+            Point point = event.getPoint();
+            ImageIcon icon = ModelerUtil.buildIcon("icon-inheritance.png");
+            if(point.x - x <= icon.getIconWidth()) {
+                ActionManager actionManager = Application.getInstance().getActionManager();
+                actionManager.getAction(ObjEntityToSuperEntityAction.class).performAction(null);
+            }
+        }
     }
 
     private class ObjRelationshipListSelectionListener implements ListSelectionListener {


Mime
View raw message