Package org.apache.cayenne.modeler

Examples of org.apache.cayenne.modeler.ProjectController


    /**
     * Adds DataMap into the project.
     */
    protected void addDataMap(DataMap map, DataMap currentMap) {

        ProjectController mediator = getProjectController();

        if (currentMap != null) {
            // merge with existing map... have to memorize map state before and after
            // to do the right events

            Collection originalOE = new ArrayList(currentMap.getObjEntities());
            Collection originalDE = new ArrayList(currentMap.getDbEntities());
            Collection originalQueries = new ArrayList(currentMap.getQueries());

            currentMap.mergeWithDataMap(map);
            map = currentMap;

            // postprocess changes
            Collection newOE = new ArrayList(currentMap.getObjEntities());
            Collection newDE = new ArrayList(currentMap.getDbEntities());
            Collection newQueries = new ArrayList(currentMap.getQueries());

            EntityEvent entityEvent = new EntityEvent(Application.getFrame(), null);
            QueryEvent queryEvent = new QueryEvent(Application.getFrame(), null);

            Collection addedOE = CollectionUtils.subtract(newOE, originalOE);
            Iterator it = addedOE.iterator();
            while (it.hasNext()) {
                Entity e = (Entity) it.next();
                entityEvent.setEntity(e);
                entityEvent.setId(MapEvent.ADD);
                mediator.fireObjEntityEvent(entityEvent);
            }

            Collection removedOE = CollectionUtils.subtract(originalOE, newOE);
            it = removedOE.iterator();
            while (it.hasNext()) {
                Entity e = (Entity) it.next();
                entityEvent.setEntity(e);
                entityEvent.setId(MapEvent.REMOVE);
                mediator.fireObjEntityEvent(entityEvent);
            }

            Collection addedDE = CollectionUtils.subtract(newDE, originalDE);
            it = addedDE.iterator();
            while (it.hasNext()) {
                Entity e = (Entity) it.next();
                entityEvent.setEntity(e);
                entityEvent.setId(MapEvent.ADD);
                mediator.fireDbEntityEvent(entityEvent);
            }

            Collection removedDE = CollectionUtils.subtract(originalDE, newDE);
            it = removedDE.iterator();
            while (it.hasNext()) {
                Entity e = (Entity) it.next();
                entityEvent.setEntity(e);
                entityEvent.setId(MapEvent.REMOVE);
                mediator.fireDbEntityEvent(entityEvent);
            }
           
            // queries
            Collection addedQueries = CollectionUtils.subtract(newQueries, originalQueries);
            it = addedQueries.iterator();
            while (it.hasNext()) {
                Query q = (Query) it.next();
                queryEvent.setQuery(q);
                queryEvent.setId(MapEvent.ADD);
                mediator.fireQueryEvent(queryEvent);
            }

            Collection removedQueries = CollectionUtils.subtract(originalQueries, newQueries);
            it = removedQueries.iterator();
            while (it.hasNext()) {
              Query q = (Query) it.next();
                queryEvent.setQuery(q);
                queryEvent.setId(MapEvent.REMOVE);
                mediator.fireQueryEvent(queryEvent);
            }

            mediator.fireDataMapDisplayEvent(new DataMapDisplayEvent(Application
                    .getFrame(), map, mediator.getCurrentDataDomain(), mediator
                    .getCurrentDataNode()));
        }
        else {
            // fix DataMap name, as there maybe a map with the same name already
            DataDomain domain = mediator.getCurrentDataDomain();
            map.setName(NamedObjectFactory.createName(DataMap.class, domain, map
                    .getName()));

            // side effect of this operation is that if a node was created, this DataMap
            // will be linked with it...
            mediator.addDataMap(Application.getFrame(), map);
        }
    }
View Full Code Here


        view.dispose();
    }

    public void generateAction() {
       
        ProjectController mediator = application
                .getFrameController()
                .getProjectController();
       
        InferRelationshipsUndoableEdit undoableEdit = new InferRelationshipsUndoableEdit();
       
        for (InferRelationships temp : selectedEntities) {
            DbRelationship rel = new DbRelationship(uniqueRelName(temp.getSource(), temp
                    .getName()));

            RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, temp
                    .getSource(), MapEvent.ADD);
            mediator.fireDbRelationshipEvent(e);

            rel.setSourceEntity(temp.getSource());
            rel.setTargetEntity(temp.getTarget());
            DbJoin join = new DbJoin(rel, temp.getJoinSource().getName(), temp
                    .getJoinTarget()
View Full Code Here

    /**
     * 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 = (EmbeddableAttribute) NamedObjectFactory
                    .createObject(EmbeddableAttribute.class, embeddable);

            createEmbAttribute(embeddable, attr);

            application.getUndoManager().addEdit(
                    new CreateEmbAttributeUndoableEdit(
                            embeddable,
                            new EmbeddableAttribute[] {
                                attr
                            }));
        }

        if (getProjectController().getCurrentObjEntity() != null) {

            ObjEntity objEntity = mediator.getCurrentObjEntity();

            ObjAttribute attr = (ObjAttribute) NamedObjectFactory.createObject(
                    ObjAttribute.class,
                    objEntity);

            createObjAttribute(mediator.getCurrentDataDomain(), mediator
                    .getCurrentDataMap(), objEntity, attr);

            application.getUndoManager().addEdit(
                    new CreateAttributeUndoableEdit(
                            mediator.getCurrentDataDomain(),
                            mediator.getCurrentDataMap(),
                            objEntity,
                            attr));
        }
        else if (getProjectController().getCurrentDbEntity() != null) {
            DbEntity dbEntity = getProjectController().getCurrentDbEntity();

            DbAttribute attr = (DbAttribute) NamedObjectFactory.createObject(
                    DbAttribute.class,
                    dbEntity);

            createDbAttribute(mediator.getCurrentDataDomain(), mediator
                    .getCurrentDataMap(), dbEntity, attr);

            application.getUndoManager().addEdit(
                    new CreateAttributeUndoableEdit(
                            mediator.getCurrentDataDomain(),
                            mediator.getCurrentDataMap(),
                            dbEntity,
                            attr));
        }
    }
View Full Code Here

                            attr));
        }
    }

    public void createEmbAttribute(Embeddable embeddable, EmbeddableAttribute attr) {
        ProjectController mediator = getProjectController();
        embeddable.addAttribute(attr);
        fireEmbeddableAttributeEvent(this, mediator, embeddable, attr);
    }
View Full Code Here

            DataDomain domain,
            DataMap map,
            ObjEntity objEntity,
            ObjAttribute attr) {

        ProjectController mediator = getProjectController();
        objEntity.addAttribute(attr);
        fireObjAttributeEvent(this, mediator, domain, map, objEntity, attr);
    }
View Full Code Here

            DataDomain domain,
            DataMap map,
            DbEntity dbEntity,
            DbAttribute attr) {
        dbEntity.addAttribute(attr);
        ProjectController mediator = getProjectController();
        fireDbAttributeEvent(this, mediator, domain, map, dbEntity, attr);
    }
View Full Code Here

    public void performAction(ActionEvent e) {
        createObjEntity();
    }

    protected void createObjEntity() {
        ProjectController mediator = getProjectController();

        DataMap dataMap = mediator.getCurrentDataMap();
        ObjEntity entity = (ObjEntity) NamedObjectFactory.createObject(
                ObjEntity.class,
                mediator.getCurrentDataMap());

        // init defaults
        entity.setSuperClassName(dataMap.getDefaultSuperclass());
        entity.setDeclaredLockType(dataMap.getDefaultLockType());

        DbEntity dbEntity = mediator.getCurrentDbEntity();
        if (dbEntity != null) {
            entity.setDbEntity(dbEntity);
            String baseName = NameConverter.underscoredToJava(dbEntity.getName(), true);
            String entityName = NamedObjectFactory.createName(ObjEntity.class, dbEntity
                    .getDataMap(), baseName);
View Full Code Here

        application.getUndoManager().addEdit(
                new CreateObjEntityUndoableEdit(dataMap, entity));
    }

    public void createObjEntity(DataMap dataMap, ObjEntity entity) {
        ProjectController mediator = getProjectController();
        dataMap.addObjEntity(entity);
        fireObjEntityEvent(this, mediator, dataMap, entity);
    }
View Full Code Here

                ProcedureParameter.class,
                procedure);
               
        procedure.addCallParameter(parameter);

        ProjectController mediator = getProjectController();
        fireProcedureParameterEvent(this, mediator, procedure, parameter);
    }
View Full Code Here

    /**
     * Creates a new DataNode, adding to the current domain, but doesn't send any events.
     */
    public DataNode buildDataNode() {
        ProjectController mediator = getProjectController();
        DataDomain domain = mediator.getCurrentDataDomain();

        // use domain name as DataNode base, as node names must be unique across the
        // project...
        DataNode node = buildDataNode(domain);

View Full Code Here

TOP

Related Classes of org.apache.cayenne.modeler.ProjectController

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.