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.Procedure; 62 import org.objectstyle.cayenne.map.event.MapEvent; 63 import org.objectstyle.cayenne.map.event.ProcedureEvent; 64 import org.objectstyle.cayenne.modeler.Application; 65 import org.objectstyle.cayenne.modeler.ProjectController; 66 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayEvent; 67 import org.objectstyle.cayenne.modeler.util.CayenneAction; 68 import org.objectstyle.cayenne.project.NamedObjectFactory; 69 import org.objectstyle.cayenne.project.ProjectPath; 70 71 76 public class CreateProcedureAction extends CayenneAction { 77 78 public static String getActionName() { 79 return "Create Stored Procedure"; 80 } 81 82 public CreateProcedureAction(Application application) { 83 super(getActionName(), application); 84 } 85 86 public void performAction(ActionEvent e) { 87 ProjectController mediator = getProjectController(); 88 Procedure procedure = createProcedure(mediator.getCurrentDataMap()); 89 90 mediator.fireProcedureEvent(new ProcedureEvent(this, procedure, MapEvent.ADD)); 91 mediator.fireProcedureDisplayEvent(new ProcedureDisplayEvent( 92 this, 93 procedure, 94 mediator.getCurrentDataMap(), 95 mediator.getCurrentDataDomain())); 96 } 97 98 protected Procedure createProcedure(DataMap map) { 99 Procedure procedure = (Procedure) NamedObjectFactory.createObject( 100 Procedure.class, 101 map); 102 procedure.setSchema(map.getDefaultSchema()); 103 104 map.addProcedure(procedure); 105 return procedure; 106 } 107 108 111 public boolean enableForPath(ProjectPath path) { 112 if (path == null) { 113 return false; 114 } 115 116 return path.firstInstanceOf(DataMap.class) != null; 117 } 118 119 public String getIconName() { 120 return "icon-stored-procedure.gif"; 121 } 122 } | Popular Tags |