use of org.apache.cayenne.modeler.event.EntityDisplayEvent in project cayenne by apache.
the class ObjAttributeTableModel method setObjAttributeType.
private void setObjAttributeType(ObjAttributeWrapper attribute, Object value) {
String oldType = attribute.getType();
String newType = value != null ? value.toString() : null;
attribute.setType(newType);
if (oldType == null || newType == null) {
return;
}
String[] registeredTypes = ModelerUtil.getRegisteredTypeNames();
Collection<String> registeredTypesList = Arrays.asList(registeredTypes);
if (registeredTypesList.contains(oldType) == registeredTypesList.contains(newType)) {
return;
}
ObjEntity entity = attribute.getEntity();
ObjAttribute attributeNew;
if (registeredTypesList.contains(newType) || !mediator.getEmbeddableNamesInCurrentDataDomain().contains(newType)) {
attributeNew = new ObjAttribute();
attributeNew.setDbAttributePath(attribute.getDbAttributePath());
} else {
attributeNew = new EmbeddedAttribute();
attributeNew.setDbAttributePath(null);
}
attributeNew.setName(attribute.getName());
attributeNew.setEntity(entity);
attributeNew.setParent(attribute.getParent());
attributeNew.setType(attribute.getType());
attributeNew.setUsedForLocking(attribute.isUsedForLocking());
entity.updateAttribute(attributeNew);
mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
mediator.fireObjAttributeEvent(new AttributeEvent(this, attributeNew, entity, MapEvent.CHANGE));
mediator.fireObjAttributeDisplayEvent(new AttributeDisplayEvent(this, attributeNew, mediator.getCurrentObjEntity(), mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
use of org.apache.cayenne.modeler.event.EntityDisplayEvent in project cayenne by apache.
the class ObjEntityCallbackMethodsTab method initController.
/**
* listeners initialization
*/
protected void initController() {
super.initController();
addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e) {
rebuildTables();
}
});
mediator.addObjEntityDisplayListener(new ObjEntityDisplayListener() {
public void currentObjEntityChanged(EntityDisplayEvent e) {
if (ObjEntityCallbackMethodsTab.this.isVisible()) {
rebuildTables();
}
}
});
}
use of org.apache.cayenne.modeler.event.EntityDisplayEvent 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.modeler.event.EntityDisplayEvent in project cayenne by apache.
the class DataDomainGraphTab method currentDomainChanged.
public void currentDomainChanged(DomainDisplayEvent e) {
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();
}
}
}
use of org.apache.cayenne.modeler.event.EntityDisplayEvent in project cayenne by apache.
the class ShowGraphEntityAction method showEntity.
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(), (DataChannelDescriptor) getProjectController().getProject().getRootNode());
getProjectController().fireDomainDisplayEvent(event);
}
Aggregations