use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ProjectTreeView method dataNodeChanged.
public void dataNodeChanged(DataNodeEvent e) {
DefaultMutableTreeNode node = getProjectModel().getNodeForObjectPath(new Object[] { e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode(), e.getDataNode() });
if (node != null) {
if (e.isNameChange()) {
positionNode((DefaultMutableTreeNode) node.getParent(), node, Comparators.getDataDomainChildrenComparator());
showNode(node);
} else {
getProjectModel().nodeChanged(node);
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
// check for DataMap additions/removals...
String[] mapsName = e.getDataNode().getDataMapNames().toArray(new String[0]);
int mapCount = mapsName.length;
// DataMap was linked
if (mapCount > node.getChildCount()) {
for (String aMapsName : mapsName) {
boolean found = false;
for (int j = 0; j < node.getChildCount(); j++) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(j);
if (domain.getDataMap(aMapsName) == child.getUserObject()) {
found = true;
break;
}
}
if (!found) {
DefaultMutableTreeNode newMapNode = new DefaultMutableTreeNode(domain.getDataMap(aMapsName), false);
positionNode(node, newMapNode, Comparators.getNamedObjectComparator());
break;
}
}
} else if (mapCount < node.getChildCount()) {
// DataMap was unlinked
int j = 0;
while (j < node.getChildCount()) {
boolean found = false;
DefaultMutableTreeNode child;
child = (DefaultMutableTreeNode) node.getChildAt(j);
Object obj = child.getUserObject();
for (Object aMapsName : mapsName) {
if (domain.getDataMap(aMapsName.toString()) == obj) {
found = true;
j++;
}
}
if (!found) {
removeNode(child);
}
}
}
}
}
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class ProjectTreeView method embeddableAdded.
public void embeddableAdded(EmbeddableEvent e, DataMap map) {
Embeddable embeddable = e.getEmbeddable();
DefaultMutableTreeNode mapNode = getProjectModel().getNodeForObjectPath(new Object[] { e.getDomain() != null ? e.getDomain() : (DataChannelDescriptor) mediator.getProject().getRootNode(), map });
if (mapNode == null) {
return;
}
DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(embeddable, false);
positionNode(mapNode, currentNode, Comparators.getDataMapChildrenComparator());
showNode(currentNode);
}
use of org.apache.cayenne.configuration.DataChannelDescriptor 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.configuration.DataChannelDescriptor in project cayenne by apache.
the class CreateNodeAction method buildDataNode.
/**
* Creates a new DataNode, adding to the current domain, but doesn't send
* any events.
*/
public DataNodeDescriptor buildDataNode() {
ProjectController mediator = getProjectController();
DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
DataNodeDescriptor node = buildDataNode(domain);
DataSourceInfo src = new DataSourceInfo();
node.setDataSourceDescriptor(src);
// by default create JDBC Node
node.setDataSourceFactoryType(XMLPoolingDataSourceFactory.class.getName());
node.setSchemaUpdateStrategyType(SkipSchemaUpdateStrategy.class.getName());
return node;
}
use of org.apache.cayenne.configuration.DataChannelDescriptor in project cayenne by apache.
the class CreateProcedureAction method fireProcedureEvent.
/**
* Fires events when a procedure was added
*/
static void fireProcedureEvent(Object src, ProjectController mediator, DataMap dataMap, Procedure procedure) {
mediator.fireProcedureEvent(new ProcedureEvent(src, procedure, MapEvent.ADD));
mediator.fireProcedureDisplayEvent(new ProcedureDisplayEvent(src, procedure, mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
}
Aggregations