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.access.DataNode; 62 import org.objectstyle.cayenne.conf.DriverDataSourceFactory; 63 import org.objectstyle.cayenne.conn.DataSourceInfo; 64 import org.objectstyle.cayenne.map.event.DataNodeEvent; 65 import org.objectstyle.cayenne.modeler.Application; 66 import org.objectstyle.cayenne.modeler.ProjectController; 67 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayEvent; 68 import org.objectstyle.cayenne.modeler.util.CayenneAction; 69 import org.objectstyle.cayenne.project.NamedObjectFactory; 70 import org.objectstyle.cayenne.project.ProjectDataSource; 71 import org.objectstyle.cayenne.project.ProjectPath; 72 73 76 public class CreateNodeAction extends CayenneAction { 77 78 public static String getActionName() { 79 return "Create DataNode"; 80 } 81 82 87 public CreateNodeAction(Application application) { 88 super(getActionName(), application); 89 } 90 91 public String getIconName() { 92 return "icon-node.gif"; 93 } 94 95 98 public void performAction(ActionEvent e) { 99 createDataNode(); 100 } 101 102 105 protected DataNode createDataNode() { 106 ProjectController mediator = getProjectController(); 107 DataDomain domain = mediator.getCurrentDataDomain(); 108 109 DataNode node = buildDataNode(); 112 mediator.fireDataNodeEvent(new DataNodeEvent(this, node, DataNodeEvent.ADD)); 113 mediator.fireDataNodeDisplayEvent(new DataNodeDisplayEvent(this, domain, node)); 114 115 return node; 116 } 117 118 121 protected DataNode buildDataNode() { 122 ProjectController mediator = getProjectController(); 123 DataDomain domain = mediator.getCurrentDataDomain(); 124 125 DataNode node = (DataNode) NamedObjectFactory.createObject( 128 DataNode.class, 129 domain, 130 domain.getName() + "Node"); 131 ProjectDataSource src = new ProjectDataSource(new DataSourceInfo()); 132 node.setDataSource(src); 133 134 node.setDataSourceFactory(DriverDataSourceFactory.class.getName()); 136 137 domain.addNode(node); 138 return node; 139 } 140 141 144 public boolean enableForPath(ProjectPath path) { 145 if (path == null) { 146 return false; 147 } 148 149 return path.firstInstanceOf(DataDomain.class) != null; 150 } 151 } | Popular Tags |