use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class ObjEntityAttributePanel method objAttributeAdded.
public void objAttributeAdded(AttributeEvent e) {
ObjAttributeTableModel model = (ObjAttributeTableModel) table.getModel();
if (!model.isValid()) {
model.resetModel();
}
model.addRow(new ObjAttributeWrapper((ObjAttribute) e.getAttribute()));
model.fireTableDataChanged();
int ind = -1;
List<ObjAttributeWrapper> list = model.getObjectList();
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getValue() == e.getAttribute()) {
ind = i;
}
}
table.select(ind);
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class ObjEntityTab method getDuplicatedAttributes.
private List<ObjAttribute> getDuplicatedAttributes(ObjEntity superEntity) {
List<ObjAttribute> result = new LinkedList<>();
ObjEntity entity = mediator.getCurrentObjEntity();
for (ObjAttribute attribute : entity.getAttributes()) {
if (superEntity.getAttribute(attribute.getName()) != null) {
result.add(attribute);
}
}
return result;
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class ObjEntityTab method initController.
private void initController() {
// initialize events processing and tracking of UI updates...
mediator.addObjEntityDisplayListener(this);
dbEntityCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Change DbEntity for current ObjEntity
ObjEntity entity = mediator.getCurrentObjEntity();
DbEntity dbEntity = (DbEntity) dbEntityCombo.getSelectedItem();
if (dbEntity != entity.getDbEntity()) {
entity.setDbEntity(dbEntity);
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
superEntityCombo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Change super-entity
ObjEntity superEntity = (ObjEntity) superEntityCombo.getSelectedItem();
String name = (superEntity == null || superEntity == NO_INHERITANCE) ? null : superEntity.getName();
ObjEntity entity = mediator.getCurrentObjEntity();
if (!Util.nullSafeEquals(name, entity.getSuperEntityName())) {
List<ObjAttribute> duplicateAttributes = null;
if (name != null) {
duplicateAttributes = getDuplicatedAttributes(superEntity);
}
if (duplicateAttributes != null && duplicateAttributes.size() > 0) {
DuplicatedAttributesDialog.showDialog(Application.getFrame(), duplicateAttributes, superEntity, entity);
if (DuplicatedAttributesDialog.getResult().equals(DuplicatedAttributesDialog.CANCEL_RESULT)) {
superEntityCombo.setSelectedItem(entity.getSuperEntity());
superClassName.setText(entity.getSuperClassName());
return;
}
}
entity.setSuperEntityName(name);
// drop not valid dbAttributePath
if (name == null) {
for (ObjAttribute objAttribute : entity.getAttributes()) {
if (objAttribute.getDbAttribute() == null) {
objAttribute.setDbAttributePath(null);
}
}
}
if (name == null) {
dbEntityCombo.setEnabled(true);
} else {
dbEntityCombo.setEnabled(false);
dbEntityCombo.getModel().setSelectedItem(null);
}
// if a super-entity selected, disable table selection
// and also update parent DbEntity selection...
toggleEnabled(name == null, !serverOnly.isSelected());
dbEntityCombo.getModel().setSelectedItem(entity.getDbEntity());
superClassName.setText(entity.getSuperClassName());
// fire both EntityEvent and EntityDisplayEvent;
// the later is to update attribute and relationship display
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
DataMap map = mediator.getCurrentDataMap();
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, map, domain));
}
}
});
tableLabel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Jump to DbEntity of the current ObjEntity
DbEntity entity = mediator.getCurrentObjEntity().getDbEntity();
if (entity != null) {
DataChannelDescriptor dom = (DataChannelDescriptor) mediator.getProject().getRootNode();
mediator.fireDbEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), dom));
}
}
});
readOnly.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setReadOnly(readOnly.isSelected());
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
optimisticLocking.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setDeclaredLockType(optimisticLocking.isSelected() ? ObjEntity.LOCK_TYPE_OPTIMISTIC : ObjEntity.LOCK_TYPE_NONE);
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
serverOnly.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setServerOnly(serverOnly.isSelected());
toggleEnabled(dbEntityCombo.isEnabled(), !serverOnly.isSelected());
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
isAbstract.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
ObjEntity entity = mediator.getCurrentObjEntity();
if (entity != null) {
entity.setAbstract(isAbstract.isSelected());
mediator.fireObjEntityEvent(new EntityEvent(this, entity));
}
}
});
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class CreateAttributeAction method performAction.
/**
* Creates ObjAttribute, DbAttribute depending on context.
*/
@Override
public void performAction(ActionEvent e) {
ProjectController mediator = getProjectController();
if (getProjectController().getCurrentEmbeddable() != null) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
EmbeddableAttribute attr = new EmbeddableAttribute();
attr.setName(NameBuilder.builder(attr, embeddable).name());
createEmbAttribute(embeddable, attr);
application.getUndoManager().addEdit(new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
}
if (getProjectController().getCurrentObjEntity() != null) {
ObjEntity objEntity = mediator.getCurrentObjEntity();
ObjAttribute attr = new ObjAttribute();
attr.setName(NameBuilder.builder(attr, objEntity).name());
createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), objEntity, attr));
} else if (getProjectController().getCurrentDbEntity() != null) {
DbEntity dbEntity = getProjectController().getCurrentDbEntity();
DbAttribute attr = new DbAttribute();
attr.setName(NameBuilder.builder(attr, dbEntity).name());
attr.setType(TypesMapping.NOT_DEFINED);
attr.setEntity(dbEntity);
createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
application.getUndoManager().addEdit(new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap(), dbEntity, attr));
}
}
use of org.apache.cayenne.map.ObjAttribute in project cayenne by apache.
the class WarningDialogByDbTargetChange method showWarningDialog.
/*
Check the situation, when targetEntity in DbRelationship was changed.
After we have two cases:
- the user agrees to accept changes (all ObjRelationships and ObjAttributes),
that are related to current targetEntity and set new targetEntity.
- the user doesn't agree and wanna return back.
*/
public static boolean showWarningDialog(ProjectController mediator, DbRelationship relationship) {
Collection<ObjRelationship> objRelationshipsForDbRelationship = ProjectUtil.findObjRelationshipsForDbRelationship(mediator, relationship);
Collection<ObjAttribute> fObjAttributesForDbRelationship = ProjectUtil.findObjAttributesForDbRelationship(mediator, relationship);
if (fObjAttributesForDbRelationship.isEmpty() && objRelationshipsForDbRelationship.isEmpty()) {
return true;
}
JPanel dialogPanel = new JPanel();
dialogPanel.setLayout(new BorderLayout());
JLabel textLabel = new JLabel(String.format("<html><p>Following ObjAttributes and ObjRelationships " + "<br>will be affected by change of DbRelationship <br> '%s'" + " target and must be fixed manually. " + "<br>Are you sure you want to proceed?</p><br></html>", relationship.getName()));
dialogPanel.add(textLabel, BorderLayout.NORTH);
DefaultListModel<String> model = new DefaultListModel<>();
JList<String> objects = new JList<>(model);
JScrollPane scrollPane = new JScrollPane(objects);
if (!objRelationshipsForDbRelationship.isEmpty()) {
model.addElement("Relationships: ");
for (ObjRelationship objRelationship : objRelationshipsForDbRelationship) {
model.addElement(objRelationship.getSourceEntity().getName() + "." + objRelationship.getName());
}
}
if (!fObjAttributesForDbRelationship.isEmpty()) {
model.addElement("Attributes: ");
for (ObjAttribute objAttribute : fObjAttributesForDbRelationship) {
model.addElement(objAttribute.getEntity().getName() + "." + objAttribute.getName());
}
}
dialogPanel.add(scrollPane, BorderLayout.SOUTH);
int result = JOptionPane.showConfirmDialog(Application.getFrame(), dialogPanel, "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
return (result == JOptionPane.OK_OPTION);
}
Aggregations