Package org.apache.cayenne.modeler

Examples of org.apache.cayenne.modeler.ProjectController


    public void paste(
            Object where,
            Object content,
            DataChannelDescriptor domain,
            DataMap map) {
        final ProjectController mediator = getProjectController();

        /**
         * Add a little intelligence - if a tree leaf is selected, we can paste to a
         * parent datamap
         */
        if (isTreeLeaf(where) && isTreeLeaf(content)) {
            where = mediator.getCurrentDataMap();
        }

        if ((where instanceof DataChannelDescriptor || where instanceof DataNodeDescriptor)
                && content instanceof DataMap) {
            // paste DataMap to DataDomain or DataNode
            DataMap dataMap = ((DataMap) content);

            dataMap
                    .setName(getFreeName(new DataMapNameChecker(domain), dataMap
                            .getName()));

            /**
             * Update all names in the new DataMap, so that they would not conflict with
             * names from other datamaps of this domain
             */

            // add some intelligence - if we rename an entity, we should rename all links
            // to it as well
            Map<String, String> renamedDbEntities = new HashMap<String, String>();
            Map<String, String> renamedObjEntities = new HashMap<String, String>();

            Map<String, String> renamedEmbeddables = new HashMap<String, String>();

            for (DbEntity dbEntity : dataMap.getDbEntities()) {
                String oldName = dbEntity.getName();
                dbEntity.setName(getFreeName(new DbEntityNameChecker(domain), dbEntity
                        .getName()));

                if (!oldName.equals(dbEntity.getName())) {
                    renamedDbEntities.put(oldName, dbEntity.getName());
                }
            }
            for (ObjEntity objEntity : dataMap.getObjEntities()) {
                String oldName = objEntity.getName();
                objEntity.setName(getFreeName(new ObjEntityNameChecker(domain), objEntity
                        .getName()));

                if (!oldName.equals(objEntity.getName())) {
                    renamedObjEntities.put(oldName, objEntity.getName());
                }
            }

            for (Embeddable embeddable : dataMap.getEmbeddables()) {
                String oldName = embeddable.getClassName();
                embeddable.setClassName(getFreeName(
                        new EmbeddableNameChecker(domain),
                        embeddable.getClassName()));

                if (!oldName.equals(embeddable.getClassName())) {
                    renamedEmbeddables.put(oldName, embeddable.getClassName());
                }
            }

            for (Procedure procedure : dataMap.getProcedures()) {
                procedure.setName(getFreeName(new ProcedureNameChecker(domain), procedure
                        .getName()));
            }
            for (Query query : dataMap.getQueries()) {
                ((AbstractQuery) query).setName(getFreeName(
                        new QueryNameChecker(domain),
                        query.getName()));
            }

            // if an entity was renamed, we rename all links to it too
            for (DbEntity dbEntity : dataMap.getDbEntities()) {
                for (DbRelationship rel : dbEntity.getRelationships()) {
                    if (renamedDbEntities.containsKey(rel.getTargetEntityName())) {
                        rel.setTargetEntityName(renamedDbEntities.get(rel
                                .getTargetEntityName()));
                    }
                }
            }
            for (ObjEntity objEntity : dataMap.getObjEntities()) {
                if (renamedDbEntities.containsKey(objEntity.getDbEntityName())) {
                    objEntity.setDbEntityName(renamedDbEntities.get(objEntity
                            .getDbEntityName()));
                }

                if (renamedObjEntities.containsKey(objEntity.getSuperEntityName())) {
                    objEntity.setSuperEntityName(renamedDbEntities.get(objEntity
                            .getSuperEntityName()));
                }

                for (ObjRelationship rel : objEntity.getRelationships()) {
                    if (renamedObjEntities.containsKey(rel.getTargetEntityName())) {
                        rel.setTargetEntityName(renamedObjEntities.get(rel
                                .getTargetEntityName()));
                    }
                }
            }

            mediator.addDataMap(this, dataMap);
        }
        else if (where instanceof DataMap) {
            // paste DbEntity to DataMap
            final DataMap dataMap = ((DataMap) where);

            if (content instanceof DbEntity) {
                DbEntity dbEntity = (DbEntity) content;
                dbEntity.setName(getFreeName(new DbEntityNameChecker(domain), dbEntity
                        .getName()));

                dataMap.addDbEntity(dbEntity);
                CreateDbEntityAction.fireDbEntityEvent(this, mediator, dbEntity);
            }
            else if (content instanceof ObjEntity) {
                // paste ObjEntity to DataMap
                ObjEntity objEntity = (ObjEntity) content;
                objEntity.setName(getFreeName(new ObjEntityNameChecker(domain), objEntity
                        .getName()));

                dataMap.addObjEntity(objEntity);
                CreateObjEntityAction.fireObjEntityEvent(
                        this,
                        mediator,
                        dataMap,
                        objEntity);
            }
            else if (content instanceof Embeddable) {
                // paste Embeddable to DataMap
                Embeddable embeddable = (Embeddable) content;
                embeddable.setClassName(getFreeName(
                        new EmbeddableNameChecker(domain),
                        embeddable.getClassName()));

                dataMap.addEmbeddable(embeddable);
                CreateEmbeddableAction.fireEmbeddableEvent(
                        this,
                        mediator,
                        dataMap,
                        embeddable);
            }
            else if (content instanceof Query) {
                // paste Query to DataMap
                AbstractQuery query = (AbstractQuery) content;

                /**
                 * Change Query root do current datamap's
                 */
                Object root = query.getRoot();
                Object newRoot = root;

                if (root instanceof ObjEntity) {
                    newRoot = dataMap.getObjEntity(((ObjEntity) root).getName());
                }
                else if (root instanceof DbEntity) {
                    newRoot = dataMap.getDbEntity(((DbEntity) root).getName());
                }
                else if (root instanceof Procedure) {
                    newRoot = dataMap.getProcedure(((Procedure) root).getName());
                }

                if (newRoot == null) {
                    JOptionPane
                            .showMessageDialog(
                                    Application.getFrame(),
                                    "Query root cannot be resolved. Pasting has not been performed.",
                                    "Warning",
                                    JOptionPane.WARNING_MESSAGE);
                    return;
                }

                query.setName(getFreeName(new QueryNameChecker(domain), query.getName()));
                query.setDataMap(dataMap);

                dataMap.addQuery(query);
                QueryType.fireQueryEvent(this, mediator, dataMap, query);
            }
            else if (content instanceof Procedure) {
                // paste Procedure to DataMap
                Procedure procedure = (Procedure) content;
                procedure.setName(getFreeName(new ProcedureNameChecker(domain), procedure
                        .getName()));

                dataMap.addProcedure(procedure);
                CreateProcedureAction.fireProcedureEvent(
                        this,
                        mediator,
                        dataMap,
                        procedure);
            }
        }
        else if (where instanceof DbEntity) {
            final DbEntity dbEntity = (DbEntity) where;

            // attrs and rels must be unique in entity namespace
            FreeNameChecker checker = new FreeNameChecker() {

                public boolean isNameFree(String name) {
                    return dbEntity.getAttribute(name) == null
                            && dbEntity.getRelationship(name) == null;
                }
            };

            if (content instanceof DbAttribute) {
                DbAttribute attr = (DbAttribute) content;
                attr.setName(getFreeName(checker, attr.getName()));

                dbEntity.addAttribute(attr);
                CreateAttributeAction.fireDbAttributeEvent(this, mediator, mediator
                        .getCurrentDataMap(), dbEntity, attr);
            }
            else if (content instanceof DbRelationship) {
                DbRelationship rel = (DbRelationship) content;
                rel.setName(getFreeName(checker, rel.getName()));

                dbEntity.addRelationship(rel);
                CreateRelationshipAction.fireDbRelationshipEvent(
                        this,
                        mediator,
                        dbEntity,
                        rel);
            }
        }
        else if (where instanceof ObjEntity) {
            final ObjEntity objEntity = (ObjEntity) where;

            // attrs and rels must be unique in entity namespace
            FreeNameChecker checker = new FreeNameChecker() {

                public boolean isNameFree(String name) {
                    return objEntity.getAttribute(name) == null
                            && objEntity.getRelationship(name) == null;
                }
            };

            if (content instanceof ObjAttribute) {
                ObjAttribute attr = (ObjAttribute) content;
                attr.setName(getFreeName(checker, attr.getName()));

                objEntity.addAttribute(attr);
                CreateAttributeAction.fireObjAttributeEvent(this, mediator, mediator
                        .getCurrentDataMap(), objEntity, attr);
            }
            else if (content instanceof ObjRelationship) {
                ObjRelationship rel = (ObjRelationship) content;
                rel.setName(getFreeName(checker, rel.getName()));
View Full Code Here


        return "icon-new_embeddable.gif";
    }

    @Override
    public void performAction(ActionEvent e) {
        ProjectController mediator = getProjectController();

        DataMap dataMap = mediator.getCurrentDataMap();

        Embeddable embeddable = (Embeddable) NamedObjectFactory.createObject(
                Embeddable.class,
                mediator.getCurrentDataMap());

        createEmbeddable(dataMap, embeddable);

        application.getUndoManager().addEdit(
                new CreateEmbeddableUndoableEdit(dataMap, embeddable));
View Full Code Here

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

    protected void synchObjEntity() {
        ProjectController mediator = getProjectController();
        ObjEntity entity = mediator.getCurrentObjEntity();

        if (entity != null && entity.getDbEntity() != null) {
            EntityMergeSupport merger = new EntitySyncController(Application
                    .getInstance()
                    .getFrameController(), entity).createMerger();

            if (merger == null) {
                return;
            }

            if (merger.synchronizeWithDbEntity(entity)) {
                mediator
                        .fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
                mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(
                        this,
                        entity,
                        entity.getDataMap(),
                        mediator.getCurrentDataDomain()));
            }
        }
    }
View Full Code Here

  }

  @Override
  public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ProjectController mediator = getProjectController();

    ObjRelationship[] rels = getProjectController()
        .getCurrentObjRelationships();
    if (rels != null && rels.length > 0) {
      if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship",
          rels[0].getName()))
          || (rels.length > 1 && dialog
              .shouldDelete("selected ObjRelationships"))) {
        ObjEntity entity = mediator.getCurrentObjEntity();
        removeObjRelationships(entity, rels);
        Application.getInstance().getUndoManager().addEdit(
            new RemoveRelationshipUndoableEdit(entity, rels));
      }
    } else {
      DbRelationship[] dbRels = getProjectController()
          .getCurrentDbRelationships();
      if (dbRels != null && dbRels.length > 0) {
        if ((dbRels.length == 1 && dialog.shouldDelete(
            "DbRelationship", dbRels[0].getName()))
            || (dbRels.length > 1 && dialog
                .shouldDelete("selected DbRelationships"))) {
          DbEntity entity = mediator.getCurrentDbEntity();
          removeDbRelationships(entity, dbRels);
          Application.getInstance().getUndoManager().addEdit(
              new RemoveRelationshipUndoableEdit(entity, dbRels));
        }
      }
View Full Code Here

      }
    }
  }

  public void removeObjRelationships(ObjEntity entity, ObjRelationship[] rels) {
    ProjectController mediator = getProjectController();

    for (ObjRelationship rel : rels) {
      entity.removeRelationship(rel.getName());
      RelationshipEvent e = new RelationshipEvent(Application.getFrame(),
          rel, entity, MapEvent.REMOVE);
      mediator.fireObjRelationshipEvent(e);
    }
  }
View Full Code Here

      mediator.fireObjRelationshipEvent(e);
    }
  }

  public void removeDbRelationships(DbEntity entity, DbRelationship[] rels) {
    ProjectController mediator = getProjectController();

    for (DbRelationship rel : rels) {
      entity.removeRelationship(rel.getName());

      RelationshipEvent e = new RelationshipEvent(Application.getFrame(),
          rel, entity, MapEvent.REMOVE);
      mediator.fireDbRelationshipEvent(e);
    }

    ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
  }
View Full Code Here

    public CreateProcedureAction(Application application) {
        super(getActionName(), application);
    }

    public void performAction(ActionEvent e) {
        ProjectController mediator = getProjectController();
        DataMap map = mediator.getCurrentDataMap();

        Procedure procedure = (Procedure) NamedObjectFactory.createObject(
                Procedure.class,
                map);
View Full Code Here

                mediator.getCurrentDataMap(),
                mediator.getCurrentDataDomain()));
    }

    public void createProcedure(DataMap map, Procedure procedure) {
        ProjectController mediator = getProjectController();
        procedure.setSchema(map.getDefaultSchema());
        map.addProcedure(procedure);
        fireProcedureEvent(this, mediator, map, procedure);
    }
View Full Code Here

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

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

        DbEntity dbEntity = mediator.getCurrentDbEntity();

        if (dbEntity != null) {

            Iterator it = dbEntity.getDataMap().getMappedEntities(dbEntity).iterator();
            if (!it.hasNext()) {
                return;
            }

            EntityMergeSupport merger = new EntitySyncController(Application
                    .getInstance()
                    .getFrameController(), dbEntity).createMerger();

            if (merger == null) {
                return;
            }

            DbEntitySyncUndoableEdit undoableEdit = new DbEntitySyncUndoableEdit(mediator
                    .getCurrentDataDomain(), mediator.getCurrentDataMap());

            while (it.hasNext()) {
                ObjEntity entity = (ObjEntity) it.next();

                DbEntitySyncUndoableEdit.EntitySyncUndoableListener listener = undoableEdit.new EntitySyncUndoableListener(
                        entity);

                merger.addEntityMergeListener(listener);

                if (merger.isRemoveMeaningfulFKs()) {
                    undoableEdit.addEdit(undoableEdit.new MeaningfulFKsUndoableEdit(
                            entity,
                            merger.getMeaningfulFKs(entity)));
                }

                if (merger.synchronizeWithDbEntity(entity)) {
                    mediator.fireObjEntityEvent(new EntityEvent(
                            this,
                            entity,
                            MapEvent.CHANGE));
                }
View Full Code Here

    /**
     * Performs copying of items into system buffer
     */
    @Override
    public void performAction(ActionEvent e) {
        ProjectController mediator = getProjectController();
       
        Object content = copy(mediator);
       
        if (content != null) {
            Clipboard sysClip = Toolkit.getDefaultToolkit().getSystemClipboard();
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.