1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.checkout; 21 22 import org.netbeans.api.project.ProjectUtils; 23 import org.netbeans.modules.versioning.system.cvss.ui.wizards.CheckoutWizard; 24 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 25 import org.netbeans.modules.versioning.system.cvss.ExecutorGroup; 26 import org.netbeans.modules.versioning.system.cvss.FileStatusCache; 27 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 28 import org.netbeans.modules.versioning.system.cvss.executor.CheckoutExecutor; 29 import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand; 30 import org.netbeans.lib.cvsclient.command.GlobalOptions; 31 import org.netbeans.spi.project.ui.support.ProjectChooser; 32 import org.netbeans.spi.project.ui.support.CommonProjectActions; 33 import org.netbeans.api.project.ProjectManager; 34 import org.netbeans.api.project.Project; 35 import org.netbeans.api.project.ProjectInformation; 36 import org.netbeans.api.project.ui.OpenProjects; 37 import org.openide.util.*; 38 import org.openide.util.lookup.Lookups; 39 import org.openide.util.actions.SystemAction; 40 import org.openide.filesystems.FileUtil; 41 import org.openide.filesystems.FileObject; 42 import org.openide.ErrorManager; 43 import org.openide.DialogDescriptor; 44 import org.openide.DialogDisplayer; 45 46 import javax.swing.*; 47 import java.awt.event.ActionEvent ; 48 import java.awt.event.ActionListener ; 49 import java.awt.*; 50 import java.io.File ; 51 import java.io.IOException ; 52 import java.util.*; 53 import java.util.List ; 54 55 62 public final class CheckoutAction extends SystemAction { 63 64 private static final String SHOW_CHECKOUT_COMPLETED = "checkoutAction.showCheckoutCompleted"; 65 66 68 public CheckoutAction() { 69 setIcon(null); 70 putValue("noIconInMenu", Boolean.TRUE); } 72 73 public String getName() { 74 return NbBundle.getBundle(CheckoutAction.class).getString("CTL_MenuItem_Checkout_Label"); 75 } 76 77 public HelpCtx getHelpCtx() { 78 return new HelpCtx(CheckoutAction.class); 79 } 80 81 84 public void actionPerformed(ActionEvent ev) { 85 CheckoutWizard wizard = new CheckoutWizard(); 86 if (wizard.show() == false) return; 87 88 final String tag = wizard.getTag(); 89 final String modules = wizard.getModules(); 90 final String workDir = wizard.getWorkingDir(); 91 final String cvsRoot = wizard.getCvsRoot(); 92 RequestProcessor.getDefault().post(new Runnable () { 93 public void run() { 94 checkout(cvsRoot, modules, tag, workDir, true, null); 95 } 96 }); 97 } 98 99 100 112 public CheckoutExecutor checkout(String cvsRoot, String modules, String tag, String workingDir, boolean scanProject, ExecutorGroup group) { 113 CheckoutCommand cmd = new CheckoutCommand(); 114 115 String moduleString = modules; 116 if (moduleString == null || moduleString.length() == 0) { 117 moduleString = "."; } 119 StringTokenizer tokenizer = new StringTokenizer(moduleString, ",;"); if (tokenizer.countTokens() == 1) { 121 cmd.setModule(moduleString); 122 } else { 123 List moduleList = new ArrayList(); 124 while( tokenizer.hasMoreTokens()) { 125 String s = tokenizer.nextToken().trim(); 126 moduleList.add(s); 127 } 128 String [] modules2 = (String []) moduleList.toArray(new String [moduleList.size()]); 129 cmd.setModules(modules2); 130 } 131 132 cmd.setDisplayName(NbBundle.getMessage(CheckoutAction.class, "BK1006")); 133 134 if (tag != null) { 135 cmd.setCheckoutByRevision(tag); 136 } else { 137 cmd.setResetStickyOnes(true); 138 } 139 cmd.setPruneDirectories(true); 140 cmd.setRecursive(true); 141 142 File workingFolder = new File (workingDir); 143 File [] files = new File [] {workingFolder}; 144 cmd.setFiles(files); 145 146 CvsVersioningSystem cvs = CvsVersioningSystem.getInstance(); 147 GlobalOptions gtx = CvsVersioningSystem.createGlobalOptions(); 148 gtx.setCVSRoot(cvsRoot); 149 150 boolean execute = false; 151 if (group == null) { 152 execute = true; 153 group = new ExecutorGroup(NbBundle.getMessage(CheckoutAction.class, "BK1013")); 154 } 155 CheckoutExecutor executor = new CheckoutExecutor(cvs, cmd, gtx); 156 group.addExecutor(executor); 157 if (CvsModuleConfig.getDefault().getPreferences().getBoolean(SHOW_CHECKOUT_COMPLETED, true) && scanProject) { 158 group.addBarrier(new CheckoutCompletedController(executor, workingFolder, scanProject)); 159 } 160 161 if (execute) { 162 group.execute(); 163 } 164 return executor; 165 } 166 167 168 private class CheckoutCompletedController implements Runnable , ActionListener { 169 170 private final CheckoutExecutor executor; 171 private final File workingFolder; 172 private final boolean openProject; 173 174 private CheckoutCompletedPanel panel; 175 private Dialog dialog; 176 private Project projectToBeOpened; 177 178 public CheckoutCompletedController(CheckoutExecutor executor, File workingFolder, boolean openProject) { 179 this.executor = executor; 180 this.workingFolder = workingFolder; 181 this.openProject = openProject; 182 } 183 184 public void run() { 185 186 if (executor.isSuccessful() == false) { 187 return; 188 } 189 190 List checkedOutProjects = new LinkedList(); 191 File normalizedWorkingFolder = FileUtil.normalizeFile(workingFolder); 192 refreshRecursively(normalizedWorkingFolder); 194 FileObject fo = FileUtil.toFileObject(normalizedWorkingFolder); 195 if (fo != null) { 196 String name = NbBundle.getMessage(CheckoutAction.class, "BK1007"); 197 executor.getGroup().progress(name); 198 Iterator it = executor.getExpandedModules().iterator(); 199 while (it.hasNext()) { 200 String module = (String ) it.next(); 201 if (".".equals(module)) { checkedOutProjects = ProjectUtilities.scanForProjects(fo); 203 break; 204 } else { 205 FileObject subfolder = fo.getFileObject(module); 206 if (subfolder != null) { 207 executor.getGroup().progress(name); 208 checkedOutProjects.addAll(ProjectUtilities.scanForProjects(subfolder)); 209 } 210 } 211 } 212 } 213 214 panel = new CheckoutCompletedPanel(); 215 panel.openButton.addActionListener(this); 216 panel.createButton.addActionListener(this); 217 panel.closeButton.addActionListener(this); 218 panel.setBorder(BorderFactory.createEmptyBorder(6,6,6,6)); 219 panel.againCheckBox.setVisible(openProject == false); 220 String title = NbBundle.getMessage(CheckoutAction.class, "BK1008"); 221 DialogDescriptor descriptor = new DialogDescriptor(panel, title); 222 descriptor.setModal(true); 223 224 panel.remove(panel.openButton); 226 panel.remove(panel.createButton); 227 panel.remove(panel.closeButton); 228 229 Object [] options = null; 230 if (checkedOutProjects.size() > 1) { 231 String msg = NbBundle.getMessage(CheckoutAction.class, "BK1009", new Integer (checkedOutProjects.size())); 232 panel.jLabel1.setText(msg); 233 options = new Object [] { 234 panel.openButton, 235 panel.closeButton 236 }; 237 } else if (checkedOutProjects.size() == 1) { 238 Project project = (Project) checkedOutProjects.iterator().next(); 239 projectToBeOpened = project; 240 ProjectInformation projectInformation = ProjectUtils.getInformation(project); 241 String projectName = projectInformation.getDisplayName(); 242 String msg = NbBundle.getMessage(CheckoutAction.class, "BK1011", projectName); 243 panel.jLabel1.setText(msg); 244 panel.openButton.setText(NbBundle.getMessage(CheckoutAction.class, "BK1012")); 245 options = new Object [] { 246 panel.openButton, 247 panel.closeButton 248 }; 249 } else { 250 String msg = NbBundle.getMessage(CheckoutAction.class, "BK1010"); 251 panel.jLabel1.setText(msg); 252 options = new Object [] { 253 panel.createButton, 254 panel.closeButton 255 }; 256 257 } 258 259 descriptor.setMessageType(DialogDescriptor.INFORMATION_MESSAGE); 260 descriptor.setOptions(options); 261 descriptor.setClosingOptions(options); 262 descriptor.setHelpCtx(new HelpCtx(CheckoutCompletedPanel.class)); 263 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 264 dialog.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CheckoutAction.class, "ACSD_CheckoutCompleted_Dialog")); 265 266 SwingUtilities.invokeLater(new Runnable () { 267 public void run() { 268 dialog.setVisible(true); 269 } 270 }); 271 } 272 273 278 private void refreshRecursively(File folder) { 279 if (folder == null) return; 280 refreshRecursively(folder.getParentFile()); 281 CvsVersioningSystem.getInstance().getStatusCache().refresh(folder, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); 282 } 283 284 public void actionPerformed(ActionEvent e) { 285 Object src = e.getSource(); 286 dialog.setVisible(false); 287 if (panel.openButton.equals(src)) { 288 if (projectToBeOpened == null) { 290 JFileChooser chooser = ProjectChooser.projectChooser(); 291 chooser.setCurrentDirectory(workingFolder); 292 chooser.setMultiSelectionEnabled(true); 293 chooser.showOpenDialog(null); 294 File [] projectDirs = chooser.getSelectedFiles(); 295 for (int i = 0; i < projectDirs.length; i++) { 296 File projectDir = projectDirs[i]; 297 FileObject projectFolder = FileUtil.toFileObject(projectDir); 298 if (projectFolder != null) { 299 try { 300 Project p = ProjectManager.getDefault().findProject(projectFolder); 301 if (p != null) { 302 openProject(p); 303 } 304 } catch (IOException e1) { 305 ErrorManager err = ErrorManager.getDefault(); 306 err.annotate(e1, NbBundle.getMessage(CheckoutAction.class, "BK1014", projectFolder)); 307 err.notify(e1); 308 } 309 } 310 } 311 } else { 312 if (projectToBeOpened == null) return; 313 openProject(projectToBeOpened); 314 } 315 316 } else if (panel.createButton.equals(src)) { 317 ProjectUtilities.newProjectWizard(workingFolder); 318 } 319 if (panel.againCheckBox.isSelected()) { 320 CvsModuleConfig.getDefault().getPreferences().putBoolean(SHOW_CHECKOUT_COMPLETED, false); 321 } 322 } 323 324 private void openProject(Project p) { 325 Project[] projects = new Project[] {p}; 326 OpenProjects.getDefault().open(projects, false); 327 328 ContextAwareAction action = (ContextAwareAction) CommonProjectActions.setAsMainProjectAction(); 330 Lookup ctx = Lookups.singleton(p); 331 Action ctxAction = action.createContextAwareInstance(ctx); 332 ctxAction.actionPerformed(new ActionEvent (this, 0, "")); ProjectUtilities.selectAndExpandProject(p); 334 } 335 } 336 } 337 | Popular Tags |