Search in sources :

Example 21 with DataChannelDescriptor

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);
                    }
                }
            }
        }
    }
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 22 with DataChannelDescriptor

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);
}
Also used : DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Embeddable(org.apache.cayenne.map.Embeddable)

Example 23 with DataChannelDescriptor

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));
    }
}
Also used : CreateEmbAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateEmbAttributeUndoableEdit) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ObjAttribute(org.apache.cayenne.map.ObjAttribute) DbEntity(org.apache.cayenne.map.DbEntity) CreateAttributeUndoableEdit(org.apache.cayenne.modeler.undo.CreateAttributeUndoableEdit) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) ProjectController(org.apache.cayenne.modeler.ProjectController) Embeddable(org.apache.cayenne.map.Embeddable)

Example 24 with DataChannelDescriptor

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;
}
Also used : DataSourceInfo(org.apache.cayenne.conn.DataSourceInfo) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) XMLPoolingDataSourceFactory(org.apache.cayenne.configuration.server.XMLPoolingDataSourceFactory) SkipSchemaUpdateStrategy(org.apache.cayenne.access.dbsync.SkipSchemaUpdateStrategy) DataNodeDescriptor(org.apache.cayenne.configuration.DataNodeDescriptor) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 25 with DataChannelDescriptor

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()));
}
Also used : ProcedureDisplayEvent(org.apache.cayenne.modeler.event.ProcedureDisplayEvent) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent)

Aggregations

DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)100 DataMap (org.apache.cayenne.map.DataMap)50 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)28 Test (org.junit.Test)20 ObjEntity (org.apache.cayenne.map.ObjEntity)18 DbEntity (org.apache.cayenne.map.DbEntity)12 ProjectController (org.apache.cayenne.modeler.ProjectController)12 URL (java.net.URL)11 Embeddable (org.apache.cayenne.map.Embeddable)11 ArrayList (java.util.ArrayList)10 URLResource (org.apache.cayenne.resource.URLResource)10 ObjAttribute (org.apache.cayenne.map.ObjAttribute)8 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)8 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 DataNodeEvent (org.apache.cayenne.configuration.event.DataNodeEvent)6 Injector (org.apache.cayenne.di.Injector)6 Procedure (org.apache.cayenne.map.Procedure)6 ProcedureDisplayEvent (org.apache.cayenne.modeler.event.ProcedureDisplayEvent)6 Resource (org.apache.cayenne.resource.Resource)6