|
Lines 13-25
Link Here
|
| 13 |
import java.io.*; |
13 |
import java.io.*; |
| 14 |
import java.lang.reflect.InvocationTargetException; |
14 |
import java.lang.reflect.InvocationTargetException; |
| 15 |
import java.util.*; |
15 |
import java.util.*; |
|
|
16 |
import java.util.List; |
| 16 |
|
17 |
|
| 17 |
import org.eclipse.core.resources.IProject; |
18 |
import org.eclipse.core.resources.IProject; |
| 18 |
import org.eclipse.core.runtime.*; |
19 |
import org.eclipse.core.runtime.*; |
| 19 |
import org.eclipse.jface.dialogs.IDialogConstants; |
20 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 20 |
import org.eclipse.jface.dialogs.MessageDialog; |
21 |
import org.eclipse.jface.dialogs.MessageDialog; |
| 21 |
import org.eclipse.osgi.util.NLS; |
22 |
import org.eclipse.osgi.util.NLS; |
| 22 |
import org.eclipse.swt.widgets.Shell; |
23 |
import org.eclipse.swt.graphics.Image; |
|
|
24 |
import org.eclipse.swt.widgets.*; |
| 23 |
import org.eclipse.team.core.*; |
25 |
import org.eclipse.team.core.*; |
| 24 |
import org.eclipse.team.internal.core.TeamPlugin; |
26 |
import org.eclipse.team.internal.core.TeamPlugin; |
| 25 |
import org.eclipse.ui.*; |
27 |
import org.eclipse.ui.*; |
|
Lines 89-94
Link Here
|
| 89 |
//try working sets |
91 |
//try working sets |
| 90 |
IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$ |
92 |
IMemento[] sets = xmlMemento.getChildren("workingSets"); //$NON-NLS-1$ |
| 91 |
IWorkingSetManager wsManager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager(); |
93 |
IWorkingSetManager wsManager = TeamUIPlugin.getPlugin().getWorkbench().getWorkingSetManager(); |
|
|
94 |
boolean replaceAll = false; |
| 95 |
boolean mergeAll = false; |
| 96 |
boolean skipAll = false; |
| 92 |
|
97 |
|
| 93 |
for (int i = 0; i < sets.length; i++) { |
98 |
for (int i = 0; i < sets.length; i++) { |
| 94 |
IWorkingSet newWs = wsManager.createWorkingSet(sets[i]); |
99 |
IWorkingSet newWs = wsManager.createWorkingSet(sets[i]); |
|
Lines 97-118
Link Here
|
| 97 |
.getName()); |
102 |
.getName()); |
| 98 |
if (oldWs == null) { |
103 |
if (oldWs == null) { |
| 99 |
wsManager.addWorkingSet(newWs); |
104 |
wsManager.addWorkingSet(newWs); |
| 100 |
} else { |
105 |
} else if (replaceAll) { |
|
|
106 |
replaceWorkingSet(wsManager, newWs, oldWs); |
| 107 |
} else if (mergeAll) { |
| 108 |
mergeWorkingSets(newWs, oldWs); |
| 109 |
} else if (!skipAll) { |
| 101 |
// a working set with the same name has been found |
110 |
// a working set with the same name has been found |
| 102 |
String title = TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_title; |
111 |
String title = TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_title; |
| 103 |
String msg = NLS |
112 |
String msg = NLS |
| 104 |
.bind( |
113 |
.bind( |
| 105 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message, |
114 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_message, |
| 106 |
newWs.getName()); |
115 |
newWs.getName()); |
| 107 |
String[] buttons = new String[] { |
116 |
String[] buttons; |
| 108 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace, |
117 |
int[] returnCodes; |
| 109 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge, |
118 |
final int REPLACE = 0; |
| 110 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip, |
119 |
final int MERGE = 1; |
| 111 |
IDialogConstants.CANCEL_LABEL }; |
120 |
final int SKIP = 2; |
| 112 |
|
121 |
final int REPLACE_ALL = 3; |
| 113 |
final MessageDialog dialog = new MessageDialog( |
122 |
final int MERGE_ALL = 4; |
|
|
123 |
final int SKIP_ALL = 5; |
| 124 |
final int CANCEL = 6; |
| 125 |
if ((i + 1) < sets.length) { |
| 126 |
// Only show the "all" buttons if there are more sets to deal with. |
| 127 |
buttons = new String[] { |
| 128 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace, |
| 129 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge, |
| 130 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip, |
| 131 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replaceAll, |
| 132 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_mergeAll, |
| 133 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skipAll, |
| 134 |
IDialogConstants.CANCEL_LABEL }; |
| 135 |
returnCodes = new int[]{REPLACE, MERGE, SKIP, REPLACE_ALL, MERGE_ALL, SKIP_ALL, CANCEL}; |
| 136 |
} else { |
| 137 |
buttons = new String[] { |
| 138 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_replace, |
| 139 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_merge, |
| 140 |
TeamUIMessages.ImportProjectSetDialog_duplicatedWorkingSet_skip, |
| 141 |
IDialogConstants.CANCEL_LABEL }; |
| 142 |
returnCodes = new int[]{REPLACE, MERGE, SKIP, CANCEL}; |
| 143 |
} |
| 144 |
final MessageDialog dialog = new CustomReturnCodesMessageDialog( |
| 114 |
shell, title, null, msg, |
145 |
shell, title, null, msg, |
| 115 |
MessageDialog.QUESTION, buttons, 0); |
146 |
MessageDialog.QUESTION, buttons, returnCodes, 0); |
| 116 |
|
147 |
|
| 117 |
shell.getDisplay().syncExec(new Runnable() { |
148 |
shell.getDisplay().syncExec(new Runnable() { |
| 118 |
public void run() { |
149 |
public void run() { |
|
Lines 121-144
Link Here
|
| 121 |
}); |
152 |
}); |
| 122 |
|
153 |
|
| 123 |
switch (dialog.getReturnCode()) { |
154 |
switch (dialog.getReturnCode()) { |
| 124 |
case 0: // overwrite |
155 |
case REPLACE: // overwrite |
| 125 |
if (oldWs != null) |
156 |
replaceWorkingSet(wsManager, newWs, oldWs); |
| 126 |
wsManager.removeWorkingSet(oldWs); |
157 |
break; |
| 127 |
wsManager.addWorkingSet(newWs); |
158 |
case REPLACE_ALL: |
|
|
159 |
replaceWorkingSet(wsManager, newWs, oldWs); |
| 160 |
replaceAll = true; |
| 161 |
break; |
| 162 |
case MERGE: // combine |
| 163 |
mergeWorkingSets(newWs, oldWs); |
| 128 |
break; |
164 |
break; |
| 129 |
case 1: // combine |
165 |
case MERGE_ALL: |
| 130 |
IAdaptable[] oldElements = oldWs.getElements(); |
166 |
mergeWorkingSets(newWs, oldWs); |
| 131 |
IAdaptable[] newElements = newWs.getElements(); |
167 |
mergeAll = true; |
| 132 |
|
168 |
case SKIP: // skip |
| 133 |
Set combinedElements = new HashSet(); |
|
|
| 134 |
combinedElements.addAll(Arrays.asList(oldElements)); |
| 135 |
combinedElements.addAll(Arrays.asList(newElements)); |
| 136 |
|
| 137 |
oldWs.setElements((IAdaptable[]) combinedElements.toArray(new IAdaptable[0])); |
| 138 |
break; |
169 |
break; |
| 139 |
case 2: // skip |
170 |
case SKIP_ALL: |
|
|
171 |
skipAll = true; |
| 140 |
break; |
172 |
break; |
| 141 |
case 3: // cancel |
173 |
case CANCEL: // cancel |
| 142 |
default: |
174 |
default: |
| 143 |
throw new OperationCanceledException(); |
175 |
throw new OperationCanceledException(); |
| 144 |
} |
176 |
} |
|
Lines 184-187
Link Here
|
| 184 |
} |
216 |
} |
| 185 |
} |
217 |
} |
| 186 |
|
218 |
|
|
|
219 |
private static void mergeWorkingSets(IWorkingSet newWs, IWorkingSet oldWs) { |
| 220 |
IAdaptable[] oldElements = oldWs.getElements(); |
| 221 |
IAdaptable[] newElements = newWs.getElements(); |
| 222 |
|
| 223 |
Set combinedElements = new HashSet(); |
| 224 |
combinedElements.addAll(Arrays.asList(oldElements)); |
| 225 |
combinedElements.addAll(Arrays.asList(newElements)); |
| 226 |
|
| 227 |
oldWs.setElements((IAdaptable[]) combinedElements.toArray(new IAdaptable[0])); |
| 228 |
} |
| 229 |
|
| 230 |
private static void replaceWorkingSet(IWorkingSetManager wsManager, IWorkingSet newWs, IWorkingSet oldWs) { |
| 231 |
if (oldWs != null) |
| 232 |
wsManager.removeWorkingSet(oldWs); |
| 233 |
wsManager.addWorkingSet(newWs); |
| 234 |
} |
| 235 |
|
| 236 |
protected static class CustomReturnCodesMessageDialog extends MessageDialog { |
| 237 |
private int[] returnCodes; |
| 238 |
public CustomReturnCodesMessageDialog( |
| 239 |
Shell parentShell, |
| 240 |
String dialogTitle, |
| 241 |
Image dialogTitleImage, |
| 242 |
String dialogMessage, |
| 243 |
int dialogImageType, |
| 244 |
String[] dialogButtonLabels, |
| 245 |
int[] returnCodes, |
| 246 |
int defaultIndex) { |
| 247 |
super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, dialogImageType, dialogButtonLabels, defaultIndex); |
| 248 |
this.returnCodes = returnCodes; |
| 249 |
} |
| 250 |
|
| 251 |
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) { |
| 252 |
Button button = super.createButton(parent, id, label, defaultButton); |
| 253 |
button.setData(new Integer(returnCodes[id])); |
| 254 |
return button; |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 187 |
} |
258 |
} |