|
Added
Link Here
|
| 1 |
package org.eclipse.team.ui; |
| 2 |
|
| 3 |
import java.util.Arrays; |
| 4 |
import java.util.List; |
| 5 |
|
| 6 |
import org.eclipse.core.resources.IProject; |
| 7 |
import org.eclipse.core.resources.IResource; |
| 8 |
import org.eclipse.jface.util.Assert; |
| 9 |
import org.eclipse.swt.widgets.Shell; |
| 10 |
import org.eclipse.team.core.ProjectSetSerializationContext; |
| 11 |
import org.eclipse.team.core.TeamException; |
| 12 |
import org.eclipse.team.internal.ui.dialogs.IPromptCondition; |
| 13 |
import org.eclipse.team.internal.ui.dialogs.PromptingDialog; |
| 14 |
|
| 15 |
/** |
| 16 |
* The UI based context in which project serialization occurs. |
| 17 |
* The class may be subclasses to represent different UI based serialization contexts. |
| 18 |
* It is recommended that all UI based serialization contexts |
| 19 |
* use this class directly or indirectly as their superclass. |
| 20 |
* |
| 21 |
* @since 3.0 |
| 22 |
*/ |
| 23 |
public class UIProjectSetSerializationContext extends ProjectSetSerializationContext { |
| 24 |
|
| 25 |
/** |
| 26 |
* The parent shell for this UI context |
| 27 |
*/ |
| 28 |
private final Shell shell; |
| 29 |
|
| 30 |
/** |
| 31 |
* Construct a new instance |
| 32 |
* |
| 33 |
* @param shell The parent shell for this UI context |
| 34 |
*/ |
| 35 |
public UIProjectSetSerializationContext(Shell shell) { |
| 36 |
Assert.isNotNull(shell); |
| 37 |
this.shell = shell; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Answer the shell associated with this UI context. |
| 42 |
* |
| 43 |
* @return the shell (not <code>null</code>) |
| 44 |
*/ |
| 45 |
public Shell getShell() { |
| 46 |
return shell; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Answer the shell associated with this UI context. |
| 51 |
* |
| 52 |
* @return the shell (not <code>null</code>) |
| 53 |
* |
| 54 |
* @see ProjectSetSerializationContext#getIProjectSetSerializerContext() |
| 55 |
* |
| 56 |
* @deprecated |
| 57 |
* This method exist solely for backward compatibility |
| 58 |
* with the {@link IProjectSetSerializer} interface |
| 59 |
* and should not be used for any other purpose. |
| 60 |
*/ |
| 61 |
public Object getIProjectSetSerializerContext() { |
| 62 |
return getShell(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Given an array of projects that currently exist in the workspace |
| 67 |
* prompt the user to determine which of those projects should be overwritten. |
| 68 |
* <p> |
| 69 |
* This default implementation prompts the user |
| 70 |
* to determine which projects should be overwritten. |
| 71 |
* Subclasses may override this as appropriate. |
| 72 |
* |
| 73 |
* @param projects |
| 74 |
* an array of projects currently existing in the workspace |
| 75 |
* that are desired to be overwritten. |
| 76 |
* (not <code>null</code>, contains no <code>null</code>s) |
| 77 |
* @return |
| 78 |
* an array of zero or more projects that should be overwritten |
| 79 |
* or <code>null</code> if the operation is to be canceled |
| 80 |
* |
| 81 |
* @see org.eclipse.team.core.ProjectSetSerializationContext#confirmOverwrite(org.eclipse.core.resources.IProject[]) |
| 82 |
*/ |
| 83 |
public IProject[] confirmOverwrite(final IProject[] projects) throws TeamException { |
| 84 |
IPromptCondition prompt = new IPromptCondition() { |
| 85 |
List resources = Arrays.asList(projects); |
| 86 |
public boolean needsPrompt(IResource resource) { |
| 87 |
return resources.contains(resource); |
| 88 |
} |
| 89 |
public String promptMessage(IResource resource) { |
| 90 |
return "Overwrite " + resource.getName(); |
| 91 |
} |
| 92 |
}; |
| 93 |
PromptingDialog dialog = |
| 94 |
new PromptingDialog( |
| 95 |
getShell(), |
| 96 |
projects, |
| 97 |
prompt, |
| 98 |
"Overwrite projects?"); |
| 99 |
IResource[] resourcesToOverwrite; |
| 100 |
try { |
| 101 |
resourcesToOverwrite = dialog.promptForMultiple(); |
| 102 |
} catch (InterruptedException e) { |
| 103 |
// Return null indicating that the user canceled the operation |
| 104 |
return null; |
| 105 |
} |
| 106 |
IProject[] projectsToOverwrite = new IProject[resourcesToOverwrite.length]; |
| 107 |
System.arraycopy(resourcesToOverwrite, 0, projectsToOverwrite, 0, resourcesToOverwrite.length); |
| 108 |
return projectsToOverwrite; |
| 109 |
} |
| 110 |
|
| 111 |
} |