You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ab...@apache.org on 2019/03/07 11:26:57 UTC
[cayenne] branch master updated: CAY-2549 Modeler: Redesign
ObjAttribute editor dialog
This is an automated email from the ASF dual-hosted git repository.
abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push:
new 6a62689 CAY-2549 Modeler: Redesign ObjAttribute editor dialog
6a62689 is described below
commit 6a6268912174638fe131ad69d41c4866e888fa70
Author: Arseni Bulatski <an...@gmail.com>
AuthorDate: Thu Mar 7 12:00:49 2019 +0300
CAY-2549 Modeler: Redesign ObjAttribute editor dialog
---
RELEASE-NOTES.txt | 1 +
.../dialog/objentity/ObjAttributeInfoDialog.java | 83 +++++++++++++++++----
.../objentity/ObjAttributeInfoDialogView.java | 86 +++++++++++-----------
3 files changed, 113 insertions(+), 57 deletions(-)
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 4f1f186..27ebf74 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -25,6 +25,7 @@ CAY-2522 Make ObjectSelect a direct query
CAY-2540 Modeler: redesign dbRelationship editor dialog
CAY-2542 Redesign ObjRelationship editor dialog
CAY-2543 Move ResultSetMapping generation from metadata to translator
+CAY-2549 Modeler: Redesign ObjAttribute editor dialog
Bug Fixes:
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java
index 71355fb..16c823f 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java
@@ -39,6 +39,7 @@ import org.apache.cayenne.modeler.util.CayenneController;
import org.apache.cayenne.modeler.util.EntityTreeAttributeRelationshipFilter;
import org.apache.cayenne.modeler.util.EntityTreeModel;
import org.apache.cayenne.modeler.util.ModelerUtil;
+import org.apache.cayenne.project.extension.info.ObjectInfo;
import org.apache.cayenne.swing.BindingBuilder;
import org.apache.cayenne.util.CayenneMapEntry;
@@ -51,6 +52,7 @@ import javax.swing.event.TreeSelectionListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.tree.TreePath;
+import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.KeyEvent;
@@ -63,6 +65,9 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
+import static org.apache.cayenne.modeler.dialog.objentity.ObjAttributeInfoDialogView.EMBEDDABLE_PANEL;
+import static org.apache.cayenne.modeler.dialog.objentity.ObjAttributeInfoDialogView.FLATTENED_PANEL;
+
public class ObjAttributeInfoDialog extends CayenneController implements TreeSelectionListener {
private ObjAttributeTableModel model;
@@ -82,7 +87,7 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
public ObjAttributeInfoDialog(ProjectController mediator, int row, ObjAttributeTableModel model) {
super(mediator);
- this.view = new ObjAttributeInfoDialogView(mediator);
+ this.view = new ObjAttributeInfoDialogView();
this.mediator = mediator;
this.model = model;
this.row = row;
@@ -148,8 +153,12 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
view.getCurrentPathLabel().setText("");
}
view.getSourceEntityLabel().setText(attribute.getEntity().getName());
-
view.getTypeComboBox().setSelectedItem(attribute.getType());
+ view.getUsedForLockingCheckBox().setSelected(attribute.isUsedForLocking());
+ view.getCommentField().setText(ObjectInfo
+ .getFromMetaData(mediator.getApplication().getMetaData(),
+ attr,
+ ObjectInfo.COMMENT));
BindingBuilder builder = new BindingBuilder(getApplication().getBindingFactory(), this);
builder.bindToAction(view.getCancelButton(), "closeAction()");
@@ -219,6 +228,25 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
}
});
+ view.getTypeComboBox().addActionListener(e -> {
+ boolean isType = false;
+ String[] typeNames = ModelerUtil.getRegisteredTypeNames();
+ for (String typeName : typeNames) {
+ if (view.getTypeComboBox().getSelectedItem() == null ||
+ typeName.equals(view.getTypeComboBox().getSelectedItem().toString())) {
+ isType = true;
+ }
+ }
+
+ if (isType || !mediator.getEmbeddableNamesInCurrentDataDomain()
+ .contains((String)view.getTypeComboBox().getSelectedItem())) {
+ ((CardLayout) view.getTypeManagerPane().getLayout()).show(view.getTypeManagerPane(), FLATTENED_PANEL);
+ } else {
+ ((CardLayout) view.getTypeManagerPane().getLayout()).show(view.getTypeManagerPane(), EMBEDDABLE_PANEL);
+ view.getCurrentPathLabel().setText("");
+ }
+ });
+
view.getAttributeName().addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
@@ -346,6 +374,11 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
attributeSaved.setType(view.getTypeComboBox().getSelectedItem().toString());
}
attributeSaved.setName(view.getAttributeName().getText());
+ attributeSaved.setUsedForLocking(view.getUsedForLockingCheckBox().isSelected());
+ ObjectInfo.putToMetaData(mediator.getApplication().getMetaData(),
+ attributeSaved,
+ ObjectInfo.COMMENT,
+ view.getCommentField().getText());
}
if (!(attributeSaved instanceof EmbeddedAttribute) || isRegistredType(attributeSaved.getType())) {
@@ -388,7 +421,7 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
attributeSaved.setDbAttributePath(attributePath.toString());
if (!attribute.getDbAttributePath().equals(attributePath.toString()) && isChange) {
- model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+ model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 2);
}
return true;
}
@@ -398,13 +431,14 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
attributeSaved.setDbAttributePath(attributePath.toString());
if (attributePath.length() == 0) {
- model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+ model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 2);
return false;
}
return true;
}
}
}
+
return false;
}
@@ -415,7 +449,21 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
return isOverrideTableChange
|| !attribute.getName().equals(view.getAttributeName().getText())
|| (attribute.getType() == null && view.getTypeComboBox().getSelectedItem() != null)
- || !Objects.equals(attribute.getType(), view.getTypeComboBox().getSelectedItem());
+ || !Objects.equals(attribute.getType(), view.getTypeComboBox().getSelectedItem())
+ || attribute.isUsedForLocking() != view.getUsedForLockingCheckBox().isSelected()
+ || !ObjectInfo.getFromMetaData(
+ mediator.getApplication().getMetaData(), attribute, ObjectInfo.COMMENT)
+ .equals(view.getCommentField().getText());
+ }
+
+ private void updateTable() {
+ model.setUpdatedValueAt(attributeSaved.getName(), row, 0);
+ model.setUpdatedValueAt(attributeSaved.getType(), row, 1);
+ model.setUpdatedValueAt(attributeSaved.isUsedForLocking(), row, 4);
+ model.setUpdatedValueAt(ObjectInfo
+ .getFromMetaData(mediator.getApplication().getMetaData(),
+ attributeSaved,
+ ObjectInfo.COMMENT), row, 5);
}
public void saveMapping() {
@@ -429,14 +477,12 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
if (attribute instanceof EmbeddedAttribute) {
changeAttributeObject();
} else {
- model.setUpdatedValueAt(attributeSaved.getName(), row, 1);
- model.setUpdatedValueAt(attributeSaved.getType(), row, 2);
+ updateTable();
}
- model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+ model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 2);
} else {
- model.setUpdatedValueAt(attributeSaved.getName(), row, 1);
- model.setUpdatedValueAt(attributeSaved.getType(), row, 2);
+ updateTable();
}
} else {
if ((attributeSaved instanceof EmbeddedAttribute && !(attribute instanceof EmbeddedAttribute))
@@ -450,14 +496,13 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
compareAndSetOverrideInEmbeddedAttribute(attributeSaved, overrides, currentOverrAttr);
}
- model.setUpdatedValueAt(attributeSaved.getName(), row, 1);
- model.setUpdatedValueAt(attributeSaved.getType(), row, 2);
- model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+ updateTable();
+ model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 2);
}
if (attributeSaved instanceof EmbeddedAttribute && attribute instanceof EmbeddedAttribute) {
- model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+ model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 2);
if (embeddableModel.isAttributeOverrideChange()) {
Map<String, String> overrides;
overrides = ((EmbeddedAttribute) attribute).getAttributeOverrides();
@@ -479,7 +524,7 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
}
if (attributeSaved instanceof EmbeddedAttribute) {
attributeSaved.setDbAttributePath(null);
- model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+ model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 2);
}
model.getEntity().removeAttribute(attribute.getName());
@@ -604,6 +649,14 @@ public class ObjAttributeInfoDialog extends CayenneController implements TreeSel
attributeSaved.setParent(attribute.getParent());
attributeSaved.setType(attribute.getType());
attributeSaved.setUsedForLocking(attribute.isUsedForLocking());
+ String comment = ObjectInfo
+ .getFromMetaData(mediator.getApplication().getMetaData(),
+ attribute,
+ ObjectInfo.COMMENT);
+ ObjectInfo.putToMetaData(mediator.getApplication().getMetaData(),
+ attributeSaved,
+ ObjectInfo.COMMENT,
+ comment);
if (attributeSaved instanceof EmbeddedAttribute) {
Map<String, String> attrOverrides;
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java
index d98ad0f..62b146a 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java
@@ -23,7 +23,6 @@ import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;
import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.ProjectController;
import org.apache.cayenne.modeler.pref.TableColumnPreferences;
import org.apache.cayenne.modeler.util.CayenneTable;
import org.apache.cayenne.modeler.util.ModelerUtil;
@@ -32,6 +31,7 @@ import org.apache.cayenne.modeler.util.PanelFactory;
import org.apache.cayenne.modeler.util.combo.AutoCompletion;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
@@ -47,36 +47,34 @@ import java.awt.event.ComponentListener;
public class ObjAttributeInfoDialogView extends JDialog {
+ static final String EMBEDDABLE_PANEL = "EMBEDDABLE_PANEL";
+ static final String FLATTENED_PANEL = "FLATTENED_PANEL";
+
/**
* // * Browser to select path for attribute //
*/
- protected MultiColumnBrowser pathBrowser;
+ private MultiColumnBrowser pathBrowser;
- protected JButton cancelButton;
- protected JButton saveButton;
- protected JButton selectPathButton;
+ private JButton cancelButton;
+ private JButton saveButton;
+ private JButton selectPathButton;
- protected JTextField attributeName;
- protected JLabel currentPathLabel;
- protected JLabel sourceEntityLabel;
+ private JTextField attributeName;
+ private JLabel currentPathLabel;
+ private JLabel sourceEntityLabel;
- protected JComboBox<String> typeComboBox;
- protected JPanel typeManagerPane;
+ private JComboBox<String> typeComboBox;
+ private JPanel typeManagerPane;
- protected CayenneTable overrideAttributeTable;
- protected TableColumnPreferences tablePreferences;
-
- ProjectController mediator;
+ private CayenneTable overrideAttributeTable;
+ private TableColumnPreferences tablePreferences;
- static final Dimension BROWSER_CELL_DIM = new Dimension(130, 200);
-
- static final String EMBEDDABLE_PANEL = "EMBEDDABLE_PANEL";
- static final String FLATTENED_PANEL = "FLATTENED_PANEL";
+ private JCheckBox usedForLockingCheckBox;
+ private JTextField commentField;
- public ObjAttributeInfoDialogView(final ProjectController mediator) {
-
- this.mediator = mediator;
+ private static final Dimension BROWSER_CELL_DIM = new Dimension(130, 200);
+ public ObjAttributeInfoDialogView() {
// create widgets
this.cancelButton = new JButton("Cancel");
this.saveButton = new JButton("Done");
@@ -90,6 +88,9 @@ public class ObjAttributeInfoDialogView extends JDialog {
AutoCompletion.enable(typeComboBox, false, true);
typeComboBox.getRenderer();
+ this.usedForLockingCheckBox = new JCheckBox();
+ this.commentField = new JTextField();
+
overrideAttributeTable = new CayenneTable();
tablePreferences = new TableColumnPreferences(getClass(), "overrideAttributeTable");
@@ -105,7 +106,7 @@ public class ObjAttributeInfoDialogView extends JDialog {
final PanelBuilder builder = new PanelBuilder(
new FormLayout(
"right:max(50dlu;pref), 3dlu, 200dlu, 15dlu, right:max(30dlu;pref), 3dlu, 200dlu",
- "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 6dlu, p, 6dlu, p, 3dlu, fill:p:grow"));
+ "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 6dlu, p, 6dlu, p, 3dlu, fill:p:grow"));
builder.setDefaultDialogBorder();
builder.addSeparator("ObjAttribute Information", cc.xywh(1, 1, 7, 1));
@@ -118,10 +119,16 @@ public class ObjAttributeInfoDialogView extends JDialog {
builder.addLabel("Current Db Path:", cc.xy(1, 7));
builder.add(currentPathLabel, cc.xywh(3, 7, 5, 1));
- builder.addLabel("Type:", cc.xy(1, 9));
+ builder.addLabel("Java Type:", cc.xy(1, 9));
builder.add(typeComboBox, cc.xywh(3, 9, 1, 1));
- builder.addSeparator("Mapping to DbAttributes", cc.xywh(1, 11, 7, 1));
+ builder.addLabel("Used for locking:", cc.xy(1, 11));
+ builder.add(usedForLockingCheckBox, cc.xywh(3, 11, 1, 1));
+
+ builder.addLabel("Comment:", cc.xy(1, 13));
+ builder.add(commentField, cc.xywh(3, 13, 1, 1));
+
+ builder.addSeparator("Mapping to DbAttributes", cc.xywh(1, 15, 7, 1));
typeManagerPane = new JPanel();
typeManagerPane.setLayout(new CardLayout());
@@ -160,7 +167,7 @@ public class ObjAttributeInfoDialogView extends JDialog {
typeManagerPane.add(builderPathPane.getPanel(), FLATTENED_PANEL);
typeManagerPane.add(embeddablePane.getPanel(), EMBEDDABLE_PANEL);
- builder.add(typeManagerPane, cc.xywh(1, 13, 7, 1));
+ builder.add(typeManagerPane, cc.xywh(1, 17, 7, 1));
add(builder.getPanel(), BorderLayout.CENTER);
@@ -189,23 +196,6 @@ public class ObjAttributeInfoDialogView extends JDialog {
JButton[] buttons = {cancelButton, saveButton};
add(PanelFactory.createButtonPanel(buttons), BorderLayout.SOUTH);
-
- typeComboBox.addActionListener(e -> {
- boolean isType = false;
- String[] typeNames = ModelerUtil.getRegisteredTypeNames();
- for (String typeName : typeNames) {
- if (typeComboBox.getSelectedItem() == null || typeName.equals(typeComboBox.getSelectedItem().toString())) {
- isType = true;
- }
- }
-
- if (isType || !mediator.getEmbeddableNamesInCurrentDataDomain().contains((String)typeComboBox.getSelectedItem())) {
- ((CardLayout) typeManagerPane.getLayout()).show(typeManagerPane, FLATTENED_PANEL);
- } else {
- ((CardLayout) typeManagerPane.getLayout()).show(typeManagerPane, EMBEDDABLE_PANEL);
- getCurrentPathLabel().setText("");
- }
- });
}
public CayenneTable getOverrideAttributeTable() {
@@ -247,4 +237,16 @@ public class ObjAttributeInfoDialogView extends JDialog {
public JLabel getSourceEntityLabel() {
return sourceEntityLabel;
}
+
+ public JCheckBox getUsedForLockingCheckBox() {
+ return usedForLockingCheckBox;
+ }
+
+ public JTextField getCommentField() {
+ return commentField;
+ }
+
+ public JPanel getTypeManagerPane() {
+ return typeManagerPane;
+ }
}