1 56 package org.objectstyle.cayenne.modeler.action; 57 58 import java.awt.event.ActionEvent ; 59 60 import org.objectstyle.cayenne.map.DataMap; 61 import org.objectstyle.cayenne.map.DbEntity; 62 import org.objectstyle.cayenne.map.event.EntityEvent; 63 import org.objectstyle.cayenne.modeler.Application; 64 import org.objectstyle.cayenne.modeler.ProjectController; 65 import org.objectstyle.cayenne.modeler.event.EntityDisplayEvent; 66 import org.objectstyle.cayenne.modeler.util.CayenneAction; 67 import org.objectstyle.cayenne.project.NamedObjectFactory; 68 import org.objectstyle.cayenne.project.ProjectPath; 69 70 73 public class CreateDbEntityAction extends CayenneAction { 74 75 public static String getActionName() { 76 return "Create DbEntity"; 77 } 78 79 82 public CreateDbEntityAction(Application application) { 83 super(getActionName(), application); 84 } 85 86 public String getIconName() { 87 return "icon-dbentity.gif"; 88 } 89 90 96 public void performAction(ActionEvent e) { 97 ProjectController mediator = getProjectController(); 98 DbEntity entity = createEntity(mediator.getCurrentDataMap()); 99 100 mediator.fireDbEntityEvent(new EntityEvent(this, entity, EntityEvent.ADD)); 101 EntityDisplayEvent displayEvent = new EntityDisplayEvent(this, entity, mediator 102 .getCurrentDataMap(), mediator.getCurrentDataNode(), mediator 103 .getCurrentDataDomain()); 104 mediator.fireDbEntityDisplayEvent(displayEvent); 105 } 106 107 110 protected DbEntity createEntity(DataMap map) { 111 DbEntity entity = (DbEntity) NamedObjectFactory.createObject(DbEntity.class, map); 112 entity.setSchema(map.getDefaultSchema()); 113 map.addDbEntity(entity); 114 return entity; 115 } 116 117 120 public boolean enableForPath(ProjectPath path) { 121 if (path == null) { 122 return false; 123 } 124 125 return path.firstInstanceOf(DataMap.class) != null; 126 } 127 } | Popular Tags |