1 31 32 33 package org.antlr.works.menu; 34 35 import org.antlr.xjlib.appkit.utils.XJAlert; 36 import org.antlr.xjlib.appkit.utils.XJDialogProgress; 37 import org.antlr.works.components.grammar.CEditorGrammar; 38 import org.antlr.works.prefs.AWPrefs; 39 import org.antlr.works.scm.SCM; 40 import org.antlr.works.scm.SCMDelegate; 41 import org.antlr.works.scm.p4.P4; 42 import org.antlr.works.scm.p4.P4SubmitDialog; 43 import org.antlr.works.stats.StatisticsAW; 44 45 public class MenuSCM extends MenuAbstract implements SCMDelegate { 46 47 protected XJDialogProgress progress; 48 protected SCM scm; 49 protected boolean silent; 50 51 public MenuSCM(CEditorGrammar editor) { 52 super(editor); 53 } 54 55 public void awake() { 56 scm = new P4(this, editor.console); 57 } 58 59 public void setSilent(boolean silent) { 60 this.silent = silent; 61 } 62 63 public void queryFileStatus() { 64 if(getFilePath() != null && AWPrefs.getP4Enabled()) 65 scm.queryFileStatus(getFilePath()); 66 } 67 68 public boolean isFileWritable() { 69 return scm.isFileWritable(); 70 } 71 72 public void editFile() { 73 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SCM_EDIT); 74 if(check()) { 75 showProgress("Open for Edit"); 76 scm.editFile(getFilePath()); 77 } 78 } 79 80 public void addFile() { 81 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SCM_ADD); 82 if(check()) { 83 showProgress("Mark for Add"); 84 scm.addFile(getFilePath()); 85 } 86 } 87 88 public void deleteFile() { 89 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SCM_DELETE); 90 if(check()) { 91 showProgress("Mark for Delete"); 92 scm.deleteFile(getFilePath()); 93 } 94 } 95 96 public void revertFile() { 97 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SCM_REVERT); 98 if(check()) { 99 if(XJAlert.displayAlertYESNO(editor.getWindowContainer(), "Revert", "Are you sure you want to discard your changes to the file ?") == XJAlert.YES) { 100 showProgress("Revert"); 101 scm.revertFile(getFilePath()); 102 } 103 } 104 } 105 106 public void submitFile() { 107 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SCM_SUBMIT); 108 if(check()) { 109 P4SubmitDialog dialog = new P4SubmitDialog(editor.getWindowContainer()); 110 if(dialog.runModal() == P4SubmitDialog.BUTTON_OK) { 111 showProgress("Submit"); 112 scm.submitFile(getFilePath(), dialog.getDescription(), dialog.getRemainOpen()); 113 } 114 } 115 } 116 117 public void sync() { 118 StatisticsAW.shared().recordEvent(StatisticsAW.EVENT_SCM_SYNC); 119 if(check()) { 120 showProgress("Sync"); 121 scm.sync(); 122 } 123 } 124 125 protected boolean check() { 126 if(getFilePath() == null) { 127 XJAlert.display(editor.getWindowContainer(), "SCM Error", "The file must be saved to the disk before any SCM command can be executed."); 128 return false; 129 } 130 return true; 131 } 132 133 protected void displayErrors() { 134 if(scm.hasErrors()) { 135 XJAlert.display(editor.getWindowContainer(), "SCM Error", scm.getErrorsDescription()); 136 scm.resetErrors(); 137 } 138 } 139 140 protected void showProgress(String title) { 141 if(progress == null) 142 progress = new XJDialogProgress(editor.getWindowContainer()); 143 144 progress.setInfo(title); 145 progress.setCancellable(false); 146 progress.setIndeterminate(true); 147 progress.display(); 148 setSilent(false); 149 } 150 151 protected void hideProgress() { 152 progress.close(); 153 } 154 155 protected String getFilePath() { 156 return editor.getFilePath(); 157 } 158 159 public void scmCommandsDidComplete() { 160 if(!silent) { 161 hideProgress(); 162 displayErrors(); 163 } 164 editor.scmCommandsDidComplete(); 165 } 166 167 public void scmFileStatusDidChange(String status) { 168 editor.updateSCMStatus(status); 169 } 170 171 public void scmLog(String log) { 172 editor.console.println(log); 173 } 174 175 } 176 | Popular Tags |