1 56 package org.objectstyle.cayenne.modeler.action; 57 58 import java.awt.event.ActionEvent ; 59 60 import org.objectstyle.cayenne.modeler.Application; 61 import org.objectstyle.cayenne.modeler.CayenneModelerController; 62 import org.objectstyle.cayenne.modeler.ProjectController; 63 import org.objectstyle.cayenne.modeler.dialog.UnsavedChangesDialog; 64 import org.objectstyle.cayenne.modeler.util.CayenneAction; 65 import org.objectstyle.cayenne.project.ProjectPath; 66 67 70 public class ProjectAction extends CayenneAction { 71 72 public static String getActionName() { 73 return "Close Project"; 74 } 75 76 public ProjectAction(Application application) { 77 super(getActionName(), application); 78 } 79 80 85 public ProjectAction(String name, Application application) { 86 super(name, application); 87 } 88 89 92 public void performAction(ActionEvent e) { 93 closeProject(); 94 } 95 96 97 public boolean closeProject() { 98 if (getProjectController() == null || getProjectController().getProject() == null) { 100 return true; 101 } 102 103 if (!checkSaveOnClose()) { 104 return false; 105 } 106 107 CayenneModelerController controller = Application 108 .getInstance() 109 .getFrameController(); 110 controller.projectClosedAction(); 111 112 return true; 113 } 114 115 118 public boolean checkSaveOnClose() { 119 ProjectController projectController = getProjectController(); 120 if (projectController != null && projectController.isDirty()) { 121 UnsavedChangesDialog dialog = new UnsavedChangesDialog(Application.getFrame()); 122 dialog.show(); 123 124 if (dialog.shouldCancel()) { 125 return false; 127 } 128 else if (dialog.shouldSave()) { 129 ActionEvent e = new ActionEvent ( 131 this, 132 ActionEvent.ACTION_PERFORMED, 133 "SaveAll"); 134 Application 135 .getFrame() 136 .getAction(SaveAction.getActionName()) 137 .actionPerformed(e); 138 if (projectController.isDirty()) { 139 return false; 141 } 142 } 143 } 144 145 return true; 146 } 147 148 151 public boolean enableForPath(ProjectPath path) { 152 return true; 153 } 154 } | Popular Tags |