You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2026/05/01 21:08:51 UTC

(cayenne) 02/02: Modeler: Better-looking "Update Entity Class Name" dialog CAY-2927

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git

commit bf9f87495d901b31f7ddfb0bfcf6c8754d3c0167
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Fri May 1 17:07:10 2026 -0400

    Modeler: Better-looking "Update Entity Class Name" dialog CAY-2927
---
 RELEASE-NOTES.txt                                  |  1 +
 .../classname/ClassNameUpdaterController.java      | 65 +++++++------------
 .../objentity/classname/ClassNameUpdaterView.java  | 75 ----------------------
 3 files changed, 25 insertions(+), 116 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 2bb00caee..50d0b8ed0 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -28,6 +28,7 @@ CAY-2920 Remove "Reengineer Database Schema" menu
 CAY-2922 Modeler: remove support for upgrading from file-based preferences
 CAY-2923 Modeler: Restore table cell editor borders
 CAY-2924 Move MapEvent and subclasses from the core to the Modeler
+CAY-2927 Modeler: Better-looking "Update Entity Class Name" dialog
 
 Bug Fixes:
 
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterController.java
index 4364e853f..0c3a93779 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterController.java
@@ -25,61 +25,54 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.mvc.ChildController;
 import org.apache.cayenne.modeler.mvc.RootController;
 
-import java.awt.*;
+import javax.swing.JOptionPane;
+import java.awt.Component;
 
 public class ClassNameUpdaterController extends ChildController<RootController> {
 
+    private static final String UPDATE = "Update";
+    private static final String CANCEL = "Cancel";
+
     private final ObjEntity entity;
-    private ClassNameUpdaterView view;
-    private boolean updatePerformed;
 
     public ClassNameUpdaterController(RootController parent, ObjEntity entity) {
         super(parent);
-
         this.entity = entity;
-
-        // don't init view here... we may simply skip update if there is nothing to do
     }
 
     /**
      * Executes entity class name update. Returns true if entity was changed, false otherwise.
      */
     public boolean doNameUpdate() {
-        this.view = null;
-        this.updatePerformed = false;
-
-        boolean askForUpdate = true;
-
         String oldName = entity.getClassName();
         String suggestedName = suggestedClassName();
 
         if (oldName == null || oldName.isEmpty()) {
             // generic entity...
-            askForUpdate = false;
-        } else if (suggestedName == null || suggestedName.equals(oldName)) {
-            askForUpdate = false;
-        } else if (oldName.contains("UntitledObjEntity")) {
+            return false;
+        }
+        if (suggestedName == null || suggestedName.equals(oldName)) {
+            return false;
+        }
+        if (oldName.contains("UntitledObjEntity")) {
             // update without user interaction
             entity.setClassName(suggestedName);
-            updatePerformed = true;
-            askForUpdate = false;
+            return true;
         }
 
-        if (askForUpdate) {
-            // start dialog
-            view = new ClassNameUpdaterView();
-            view.getClassName().setText("Update class name to " + suggestedName + " to match current entity name?");
+        JOptionPane pane = new JOptionPane(
+                "Update class name to '" + suggestedName + "' to match the current entity name?",
+                JOptionPane.QUESTION_MESSAGE);
+        pane.setOptions(new Object[]{UPDATE, CANCEL});
+        pane.setInitialValue(UPDATE);
 
-            initBindings(suggestedName);
+        pane.createDialog(parent.getView(), "Update Class Name").setVisible(true);
 
-            view.pack();
-            view.setModal(true);
-            centerView();
-            makeCloseableOnEscape();
-            view.setVisible(true);
+        if (UPDATE.equals(pane.getValue())) {
+            entity.setClassName(suggestedName);
+            return true;
         }
-
-        return this.updatePerformed;
+        return false;
     }
 
     private String suggestedClassName() {
@@ -111,18 +104,8 @@ public class ClassNameUpdaterController extends ChildController<RootController>
         return DataMap.getNameWithPackage(pkg, entityName);
     }
 
-    protected void initBindings(final String suggestedName) {
-
-        view.getUpdateButton().addActionListener(e -> {
-            entity.setClassName(suggestedName);
-            updatePerformed = true;
-            view.dispose();
-        });
-
-        view.getCancelButton().addActionListener(e -> view.dispose());
-    }
-
+    @Override
     public Component getView() {
-        return view;
+        return null;
     }
 }
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterView.java
deleted file mode 100644
index 4da5f011b..000000000
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/project/editor/objentity/classname/ClassNameUpdaterView.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*****************************************************************
- *   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
- *
- *    https://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.ui.project.editor.objentity.classname;
-
-import com.jgoodies.forms.builder.DefaultFormBuilder;
-import com.jgoodies.forms.layout.FormLayout;
-
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import java.awt.BorderLayout;
-import java.awt.Container;
-import java.awt.FlowLayout;
-
-public class ClassNameUpdaterView extends JDialog {
-
-    private final JLabel className;
-    private final JButton updateButton;
-    private final JButton cancelButton;
-
-    public ClassNameUpdaterView() {
-        className = new JLabel("Update class name to _______________________ to match current entity name?");
-        updateButton = new JButton("Update");
-        cancelButton = new JButton("Cancel");
-
-        getRootPane().setDefaultButton(updateButton);
-
-        // assemble
-        FormLayout layout = new FormLayout("left:200dlu", "");
-        DefaultFormBuilder builder = new DefaultFormBuilder(layout);
-        builder.setDefaultDialogBorder();
-        builder.append(className);
-
-        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        buttons.add(cancelButton);
-        buttons.add(updateButton);
-
-        Container contentPane = getContentPane();
-        contentPane.setLayout(new BorderLayout());
-        contentPane.add(className, BorderLayout.CENTER);
-        contentPane.add(buttons, BorderLayout.SOUTH);
-
-        setTitle("Update Entity Class Name");
-    }
-
-    public JLabel getClassName() {
-        return className;
-    }
-
-    public JButton getCancelButton() {
-        return cancelButton;
-    }
-
-    public JButton getUpdateButton() {
-        return updateButton;
-    }
-}