1 12 13 package org.eclipse.team.internal.ui; 14 15 import java.io.File ; 16 import java.util.Arrays ; 17 import java.util.List ; 18 19 import org.eclipse.core.resources.IProject; 20 import org.eclipse.core.resources.IResource; 21 import org.eclipse.core.runtime.Assert; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.team.core.ProjectSetSerializationContext; 25 import org.eclipse.team.core.TeamException; 26 import org.eclipse.team.internal.ui.dialogs.IPromptCondition; 27 import org.eclipse.team.internal.ui.dialogs.PromptingDialog; 28 29 37 public class UIProjectSetSerializationContext extends ProjectSetSerializationContext { 38 39 42 private final Shell shell; 43 44 49 public UIProjectSetSerializationContext(Shell shell, String filename) { 50 super(filename); 51 Assert.isNotNull(shell); 52 this.shell = shell; 53 } 54 55 60 public Object getShell() { 61 return shell; 62 } 63 64 82 public IProject[] confirmOverwrite(final IProject[] projects) throws TeamException { 83 IPromptCondition prompt = new IPromptCondition() { 84 List resources = Arrays.asList(projects); 85 public boolean needsPrompt(IResource resource) { 86 if (resource instanceof IProject) { 87 IProject project = (IProject) resource; 88 return (project.exists() || getTargetFile(project).exists()) && resources.contains(resource); 89 } 90 return false; 91 } 92 public String promptMessage(IResource resource) { 93 if (resource.exists()) 94 return NLS.bind(TeamUIMessages.UIProjectSetSerializationContext_0, new String [] { resource.getName() }); 95 return NLS.bind(TeamUIMessages.UIProjectSetSerializationContext_2, new String [] { resource.getName(), getTargetFile((IProject)resource).getAbsolutePath() }); 96 } 97 public File getTargetFile(IProject project) { 98 return new File (project.getParent().getLocation().toFile(), project.getName()); 99 } 100 }; 101 PromptingDialog dialog = 102 new PromptingDialog( 103 (Shell)getShell(), 104 projects, 105 prompt, 106 TeamUIMessages.UIProjectSetSerializationContext_1); 107 IResource[] resourcesToOverwrite; 108 try { 109 resourcesToOverwrite = dialog.promptForMultiple(); 110 } catch (InterruptedException e) { 111 return null; 113 } 114 IProject[] projectsToOverwrite = new IProject[resourcesToOverwrite.length]; 115 System.arraycopy(resourcesToOverwrite, 0, projectsToOverwrite, 0, resourcesToOverwrite.length); 116 return projectsToOverwrite; 117 } 118 119 } 120 | Popular Tags |