1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.List ; 19 import java.util.Map ; 20 21 import org.eclipse.core.resources.*; 22 import org.eclipse.core.resources.mapping.ResourceTraversal; 23 import org.eclipse.core.runtime.*; 24 import org.eclipse.jface.operation.IRunnableWithProgress; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.team.core.IFileContentManager; 27 import org.eclipse.team.core.Team; 28 import org.eclipse.team.internal.ccvs.core.CVSException; 29 import org.eclipse.team.internal.ccvs.core.ICVSFile; 30 import org.eclipse.team.internal.ccvs.core.resources.CVSWorkspaceRoot; 31 import org.eclipse.team.internal.ccvs.ui.*; 32 import org.eclipse.team.internal.ccvs.ui.operations.AddOperation; 33 import org.eclipse.ui.PlatformUI; 34 35 public class AddWizard extends ResizableWizard { 36 37 private final AddOperation op; 38 private final IFile[] unknowns; 39 private CommitWizardFileTypePage fFileTypePage; 40 41 public static void run(Shell shell, final AddOperation op) throws InvocationTargetException , InterruptedException { 42 PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { 44 public void run(IProgressMonitor monitor) throws InvocationTargetException , 45 InterruptedException { 46 try { 47 op.buildScope(monitor); 48 } catch (CVSException e) { 49 throw new InvocationTargetException (e); 50 } 51 } 52 }); 53 54 IFile[] unknowns = getUnaddedWithUnknownFileType(op.getTraversals()); 55 if (unknowns.length == 0) { 56 op.run(); 57 } else { 58 AddWizard wizard = new AddWizard(op, unknowns); 59 ResizableWizard.open(shell, wizard); 60 } 61 } 62 63 private static IFile[] getUnaddedWithUnknownFileType(final ResourceTraversal[] traversals) throws InvocationTargetException , InterruptedException { 64 final List unadded = new ArrayList (); 65 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 66 public void run(IProgressMonitor monitor) throws InvocationTargetException , 67 InterruptedException { 68 final IFileContentManager manager= Team.getFileContentManager(); 69 for (int i = 0; i < traversals.length; i++) { 70 ResourceTraversal traversal = traversals[i]; 71 IResource[] resources = traversal.getResources(); 72 for (int j = 0; j < resources.length; j++) { 73 final IResource resource = resources[j]; 74 try { 75 resource.accept(new IResourceVisitor() { 76 public boolean visit(IResource resource) throws CoreException { 77 if (resource.getType() == IResource.FILE) { 78 ICVSFile file = CVSWorkspaceRoot.getCVSFileFor((IFile)resource); 79 if (!file.isManaged()) { 80 if (!file.isIgnored() || file.equals(resource)) { 81 final String extension= ((IFile)resource).getFileExtension(); 82 if (manager.getType((IFile)resource) == Team.UNKNOWN) { 83 if (extension != null && !manager.isKnownExtension(extension)) { 84 unadded.add(resource); 85 } else { 86 final String name= file.getName(); 87 if (extension == null && name != null && !manager.isKnownFilename(name)) 88 unadded.add(resource); 89 } 90 } 91 } 92 } 93 } 94 return true; 95 } 96 }, traversal.getDepth(), false); 97 } catch (CoreException e) { 98 throw new InvocationTargetException (e); 99 } 100 } 101 } 102 } 103 104 }); 105 return (IFile[]) unadded.toArray(new IFile[unadded.size()]); 106 } 107 108 public AddWizard(AddOperation op, IFile[] unknowns) { 109 super("AddWizard", CVSUIPlugin.getPlugin().getDialogSettings()); this.op = op; 111 this.unknowns = unknowns; 112 setWindowTitle(CVSUIMessages.AddWizard_0); 113 setDefaultPageImageDescriptor(CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_NEW_LOCATION)); 114 } 115 116 public void addPages() { 117 118 final Collection names= new HashSet (); 119 final Collection extensions= new HashSet (); 120 getUnknownNamesAndExtension(unknowns, names, extensions); 121 122 if (names.size() + extensions.size() > 0) { 123 fFileTypePage= new CommitWizardFileTypePage(extensions, names); 124 addPage(fFileTypePage); 125 } 126 127 super.addPages(); 128 } 129 130 private static void getUnknownNamesAndExtension(IFile[] files, Collection names, Collection extensions) { 131 132 final IFileContentManager manager= Team.getFileContentManager(); 133 134 for (int i = 0; i < files.length; i++) { 135 IFile file = files[i]; 136 137 final String extension= file.getFileExtension(); 138 if (extension != null && !manager.isKnownExtension(extension)) { 139 extensions.add(extension); 140 } 141 142 final String name= file.getName(); 143 if (extension == null && name != null && !manager.isKnownFilename(name)) 144 names.add(name); 145 } 146 } 147 148 public boolean performFinish() { 149 final Map extensionsToSave= new HashMap (); 150 final Map extensionsNotToSave= new HashMap (); 151 152 fFileTypePage.getModesForExtensions(extensionsToSave, extensionsNotToSave); 153 CommitWizardFileTypePage.saveExtensionMappings(extensionsToSave); 154 op.addModesForExtensions(extensionsNotToSave); 155 156 final Map namesToSave= new HashMap (); 157 final Map namesNotToSave= new HashMap (); 158 159 fFileTypePage.getModesForNames(namesToSave, namesNotToSave); 160 CommitWizardFileTypePage.saveNameMappings(namesToSave); 161 op.addModesForNames(namesNotToSave); 162 163 try { 164 op.run(); 165 } catch (InvocationTargetException e) { 166 return false; 167 } catch (InterruptedException e) { 168 return false; 169 } 170 171 return super.performFinish(); 172 } 173 174 } 175 | Popular Tags |