1 19 20 package org.netbeans.modules.refactoring.vcs; 21 import java.util.Arrays ; 22 import java.util.Collection ; 23 import java.util.HashSet ; 24 import java.util.WeakHashMap ; 25 import org.netbeans.api.vcs.VcsManager; 26 import org.netbeans.api.vcs.commands.Command; 27 import org.netbeans.modules.refactoring.api.Problem; 28 import org.netbeans.modules.refactoring.api.RefactoringSession; 29 import org.netbeans.modules.refactoring.spi.*; 30 import org.openide.filesystems.FileObject; 31 import org.openide.util.NbBundle; 32 33 37 public class ReadOnlyFilesHandlerImpl implements ReadOnlyFilesHandler { 38 39 private WeakHashMap sessions = new WeakHashMap (2); 40 41 public ReadOnlyFilesHandlerImpl() { 42 } 43 44 public Problem createProblem(RefactoringSession session, Collection files) { 45 CheckoutFiles cof = (CheckoutFiles) sessions.get(session); 46 Collection fileSet = null; 47 if (cof != null) { 48 fileSet = new HashSet (cof.getFiles()); 50 if (!fileSet.addAll(files)) { 51 return null; 53 } 54 } else { 55 fileSet = new HashSet (files); 57 } 58 59 FileObject[] fos = (FileObject[]) fileSet.toArray(new FileObject[0]); 60 Command editCmd; 61 try { 62 editCmd = VcsManager.getDefault().createCommand("EDIT", fos); } catch (IllegalArgumentException iaex) { 64 editCmd = null; 66 } 67 if (editCmd == null) return null; 68 fos = editCmd.getApplicableFiles(fos); 69 editCmd.setFiles(fos); 70 if (cof == null) { 71 cof = new CheckoutFiles(Arrays.asList(fos), editCmd); 72 sessions.put(session, cof); 73 return new Problem(false, NbBundle.getMessage(ReadOnlyFilesHandlerImpl.class, "MSG_CheckoutWarning"), ProblemDetailsFactory.createProblemDetails(cof)); 74 } else { 75 cof.setEditCmd(editCmd); 76 cof.setFiles(Arrays.asList(fos)); 77 return null; 78 } 79 } 80 } 81 | Popular Tags |