1 56 package org.objectstyle.cayenne.modeler.action; 57 58 import java.awt.event.ActionEvent ; 59 60 import org.objectstyle.cayenne.access.DataDomain; 61 import org.objectstyle.cayenne.map.event.DomainEvent; 62 import org.objectstyle.cayenne.modeler.Application; 63 import org.objectstyle.cayenne.modeler.ProjectController; 64 import org.objectstyle.cayenne.modeler.event.DomainDisplayEvent; 65 import org.objectstyle.cayenne.modeler.util.CayenneAction; 66 import org.objectstyle.cayenne.project.ApplicationProject; 67 import org.objectstyle.cayenne.project.NamedObjectFactory; 68 import org.objectstyle.cayenne.project.ProjectPath; 69 70 73 public class CreateDomainAction extends CayenneAction { 74 75 public static String getActionName() { 76 return "Create DataDomain"; 77 } 78 79 84 public CreateDomainAction(Application application) { 85 super(getActionName(), application); 86 } 87 88 public String getIconName() { 89 return "icon-dom.gif"; 90 } 91 92 public void performAction(ActionEvent e) { 93 createDomain(); 94 } 95 96 protected void createDomain() { 97 ApplicationProject project = (ApplicationProject) getCurrentProject(); 99 100 ProjectController mediator = getProjectController(); 101 DataDomain domain = (DataDomain) NamedObjectFactory.createObject( 102 DataDomain.class, 103 project.getConfiguration()); 104 domain.getEntityResolver().setIndexedByClass(false); 105 project.getConfiguration().addDomain(domain); 106 mediator.fireDomainEvent(new DomainEvent(this, domain, DomainEvent.ADD)); 107 mediator.fireDomainDisplayEvent(new DomainDisplayEvent(this, domain)); 108 } 109 110 113 public boolean enableForPath(ProjectPath path) { 114 if (path == null) { 115 return false; 116 } 117 118 return path.firstInstanceOf(ApplicationProject.class) != null; 119 } 120 } | Popular Tags |