Lines 10-21
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.compare.internal; |
11 |
package org.eclipse.compare.internal; |
12 |
|
12 |
|
|
|
13 |
import java.io.FileOutputStream; |
14 |
import java.io.IOException; |
15 |
|
13 |
import org.eclipse.compare.CompareConfiguration; |
16 |
import org.eclipse.compare.CompareConfiguration; |
|
|
17 |
import org.eclipse.compare.CompareUI; |
18 |
import org.eclipse.core.resources.IFile; |
19 |
import org.eclipse.core.resources.IFolder; |
20 |
import org.eclipse.core.resources.IProject; |
21 |
import org.eclipse.core.resources.IProjectDescription; |
14 |
import org.eclipse.core.resources.IResource; |
22 |
import org.eclipse.core.resources.IResource; |
|
|
23 |
import org.eclipse.core.resources.IWorkspace; |
15 |
import org.eclipse.core.resources.IWorkspaceRoot; |
24 |
import org.eclipse.core.resources.IWorkspaceRoot; |
16 |
import org.eclipse.core.resources.ResourcesPlugin; |
25 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
|
26 |
import org.eclipse.core.runtime.CoreException; |
27 |
import org.eclipse.core.runtime.IPath; |
28 |
import org.eclipse.core.runtime.Path; |
17 |
import org.eclipse.jface.dialogs.IDialogConstants; |
29 |
import org.eclipse.jface.dialogs.IDialogConstants; |
18 |
import org.eclipse.jface.dialogs.IMessageProvider; |
30 |
import org.eclipse.jface.dialogs.IMessageProvider; |
|
|
31 |
import org.eclipse.jface.dialogs.MessageDialog; |
19 |
import org.eclipse.jface.dialogs.TitleAreaDialog; |
32 |
import org.eclipse.jface.dialogs.TitleAreaDialog; |
20 |
import org.eclipse.jface.viewers.ISelection; |
33 |
import org.eclipse.jface.viewers.ISelection; |
21 |
import org.eclipse.jface.viewers.StructuredSelection; |
34 |
import org.eclipse.jface.viewers.StructuredSelection; |
Lines 36-47
Link Here
|
36 |
import org.eclipse.swt.layout.GridData; |
49 |
import org.eclipse.swt.layout.GridData; |
37 |
import org.eclipse.swt.layout.GridLayout; |
50 |
import org.eclipse.swt.layout.GridLayout; |
38 |
import org.eclipse.swt.widgets.Button; |
51 |
import org.eclipse.swt.widgets.Button; |
|
|
52 |
import org.eclipse.swt.widgets.Combo; |
39 |
import org.eclipse.swt.widgets.Composite; |
53 |
import org.eclipse.swt.widgets.Composite; |
40 |
import org.eclipse.swt.widgets.Control; |
54 |
import org.eclipse.swt.widgets.Control; |
|
|
55 |
import org.eclipse.swt.widgets.DirectoryDialog; |
56 |
import org.eclipse.swt.widgets.FileDialog; |
41 |
import org.eclipse.swt.widgets.Group; |
57 |
import org.eclipse.swt.widgets.Group; |
42 |
import org.eclipse.swt.widgets.Label; |
58 |
import org.eclipse.swt.widgets.Label; |
43 |
import org.eclipse.swt.widgets.Shell; |
59 |
import org.eclipse.swt.widgets.Shell; |
44 |
import org.eclipse.swt.widgets.Text; |
60 |
import org.eclipse.swt.widgets.Text; |
|
|
61 |
import org.eclipse.ui.PlatformUI; |
45 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
62 |
import org.eclipse.ui.forms.events.ExpansionAdapter; |
46 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
63 |
import org.eclipse.ui.forms.events.ExpansionEvent; |
47 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
64 |
import org.eclipse.ui.forms.widgets.ExpandableComposite; |
Lines 55-63
Link Here
|
55 |
public class CompareWithOtherResourceDialog extends TitleAreaDialog { |
72 |
public class CompareWithOtherResourceDialog extends TitleAreaDialog { |
56 |
|
73 |
|
57 |
private int CLEAR_RETURN_CODE = 150; // any number != 0 |
74 |
private int CLEAR_RETURN_CODE = 150; // any number != 0 |
|
|
75 |
private int OPEN_EXTERNAL_RETURN_CODE = 153; |
58 |
private int MIN_WIDTH = 300; |
76 |
private int MIN_WIDTH = 300; |
59 |
private int MIN_HEIGHT = 175; |
77 |
private int MIN_HEIGHT = 175; |
60 |
|
78 |
|
|
|
79 |
public static final String TMP_PROJECT_NAME = ".org.eclipse.compare.tmp"; //$NON-NLS-1$ |
80 |
private final static String TMP_PROJECT_FILE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$ |
81 |
+ "<projectDescription>\n" //$NON-NLS-1$ |
82 |
+ "\t<name>" + TMP_PROJECT_NAME + "\t</name>\n" //$NON-NLS-1$ //$NON-NLS-2$ |
83 |
+ "\t<comment></comment>\n" //$NON-NLS-1$ |
84 |
+ "\t<projects>\n" //$NON-NLS-1$ |
85 |
+ "\t</projects>\n" //$NON-NLS-1$ |
86 |
+ "\t<buildSpec>\n" //$NON-NLS-1$ |
87 |
+ "\t</buildSpec>\n" //$NON-NLS-1$ |
88 |
+ "\t<natures>\n" + "\t</natures>\n" //$NON-NLS-1$//$NON-NLS-2$ |
89 |
+ "</projectDescription>"; //$NON-NLS-1$ |
90 |
public final static String EXTERNAL_FILES_FOLDER_NAME = "ExternalFilesFolder"; //$NON-NLS-1$ |
91 |
|
61 |
private class FileTextDragListener implements DragSourceListener { |
92 |
private class FileTextDragListener implements DragSourceListener { |
62 |
|
93 |
|
63 |
private InternalSection section; |
94 |
private InternalSection section; |
Lines 67-81
Link Here
|
67 |
} |
98 |
} |
68 |
|
99 |
|
69 |
public void dragFinished(DragSourceEvent event) { |
100 |
public void dragFinished(DragSourceEvent event) { |
70 |
section.fileText.setText(""); //$NON-NLS-1$ |
101 |
section.fileCombo.setText(""); //$NON-NLS-1$ |
71 |
} |
102 |
} |
72 |
|
103 |
|
73 |
public void dragSetData(DragSourceEvent event) { |
104 |
public void dragSetData(DragSourceEvent event) { |
74 |
event.data = section.fileText.getText(); |
105 |
if (TextTransfer.getInstance().isSupportedType(event.dataType)) { |
|
|
106 |
event.data = section.fileCombo.getText(); |
107 |
} else |
108 |
event.data = section.fileCombo.getText(); |
75 |
} |
109 |
} |
76 |
|
110 |
|
77 |
public void dragStart(DragSourceEvent event) { |
111 |
public void dragStart(DragSourceEvent event) { |
78 |
if (section.fileText.getText() == null) |
112 |
if (section.fileCombo.getText() == null) |
79 |
event.doit = false; |
113 |
event.doit = false; |
80 |
} |
114 |
} |
81 |
} |
115 |
} |
Lines 137-148
Link Here
|
137 |
|
171 |
|
138 |
if (textTransfer.isSupportedType(event.currentDataType)) { |
172 |
if (textTransfer.isSupportedType(event.currentDataType)) { |
139 |
String txt = (String) event.data; |
173 |
String txt = (String) event.data; |
140 |
IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt); |
174 |
section.setResource(ResourcesPlugin.getWorkspace().getRoot() |
141 |
if (r != null) |
175 |
.findMember(txt)); |
142 |
section.setResource(r); |
176 |
section.updateAllSectionInfo(); |
143 |
} else if (resourceTransfer.isSupportedType(event.currentDataType)) { |
177 |
} else if (resourceTransfer.isSupportedType(event.currentDataType)) { |
144 |
IResource[] files = (IResource[]) event.data; |
178 |
IResource[] files = (IResource[]) event.data; |
145 |
section.setResource(files[0]); |
179 |
section.setResource(files[0]); |
|
|
180 |
section.updateAllSectionInfo(); |
146 |
} |
181 |
} |
147 |
|
182 |
|
148 |
updateErrorInfo(); |
183 |
updateErrorInfo(); |
Lines 157-164
Link Here
|
157 |
private abstract class InternalSection { |
192 |
private abstract class InternalSection { |
158 |
|
193 |
|
159 |
protected Group group; |
194 |
protected Group group; |
160 |
protected Text fileText; |
195 |
protected Combo fileCombo; |
161 |
private IResource resource; |
196 |
private IResource resource; |
|
|
197 |
private Button openExternalFileButton, openExternalFolderButton; |
198 |
private String path = ""; //$NON-NLS-1$ |
199 |
private Text pathLabel; |
200 |
protected Label pLabel; |
162 |
|
201 |
|
163 |
public InternalSection(Composite parent) { |
202 |
public InternalSection(Composite parent) { |
164 |
createContents(parent); |
203 |
createContents(parent); |
Lines 169-177
Link Here
|
169 |
} |
208 |
} |
170 |
|
209 |
|
171 |
public void createContents(Composite parent) { |
210 |
public void createContents(Composite parent) { |
172 |
createGroup(parent); |
211 |
|
173 |
createFileLabel(); |
212 |
group = new Group(parent, SWT.NONE); |
174 |
createFileCombo(); |
213 |
group.setLayout(new GridLayout(2, false)); |
|
|
214 |
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
215 |
|
216 |
Composite infoComposite = new Composite(group, SWT.NONE); |
217 |
infoComposite.setLayout(new GridLayout(2, false)); |
218 |
infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
219 |
createInfo(infoComposite); |
220 |
|
221 |
Composite buttonsComposite = new Composite(group, SWT.NONE); |
222 |
buttonsComposite.setLayout(new GridLayout(-1, true)); |
223 |
buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true)); |
224 |
createButtons(buttonsComposite); |
225 |
|
175 |
initDrag(); |
226 |
initDrag(); |
176 |
initDrop(); |
227 |
initDrop(); |
177 |
} |
228 |
} |
Lines 182-209
Link Here
|
182 |
|
233 |
|
183 |
public void setResource(IResource resource) { |
234 |
public void setResource(IResource resource) { |
184 |
this.resource = resource; |
235 |
this.resource = resource; |
185 |
String txt = resource.getFullPath().toString(); |
236 |
path = resource.getLocation().toOSString(); |
186 |
fileText.setText(txt); |
237 |
pathLabel.setText(dividePath(path)); |
187 |
} |
238 |
} |
188 |
|
239 |
|
189 |
public void setResource(String s) { |
240 |
public void setResource(String s) { |
190 |
IResource tmp = ResourcesPlugin.getWorkspace().getRoot() |
241 |
IResource tmp = ResourcesPlugin.getWorkspace().getRoot() |
191 |
.findMember(s); |
242 |
.findMember(s); |
192 |
if (tmp instanceof IWorkspaceRoot) |
243 |
if (tmp instanceof IWorkspaceRoot) { |
193 |
resource = null; |
244 |
resource = null; |
194 |
else |
245 |
pathLabel.setText(""); //$NON-NLS-1$ |
|
|
246 |
} |
247 |
else { |
195 |
resource = tmp; |
248 |
resource = tmp; |
196 |
|
249 |
path = resource.getLocation().toOSString(); |
|
|
250 |
pathLabel.setText(dividePath(path)); |
251 |
} |
197 |
} |
252 |
} |
198 |
|
253 |
|
199 |
protected void clearResource() { |
254 |
protected void clearResource() { |
200 |
resource = null; |
255 |
resource = null; |
201 |
fileText.setText(""); //$NON-NLS-1$ |
256 |
fileCombo.setText(""); //$NON-NLS-1$ |
202 |
updateErrorInfo(); |
257 |
updateErrorInfo(); |
203 |
} |
258 |
} |
204 |
|
259 |
|
205 |
protected void initDrag() { |
260 |
protected void initDrag() { |
206 |
DragSource source = new DragSource(fileText, DND.DROP_MOVE |
261 |
DragSource source = new DragSource(fileCombo, DND.DROP_MOVE |
207 |
| DND.DROP_COPY | DND.DROP_DEFAULT); |
262 |
| DND.DROP_COPY | DND.DROP_DEFAULT); |
208 |
Transfer[] types = new Transfer[] { TextTransfer.getInstance(), |
263 |
Transfer[] types = new Transfer[] { TextTransfer.getInstance(), |
209 |
ResourceTransfer.getInstance() }; |
264 |
ResourceTransfer.getInstance() }; |
Lines 212-218
Link Here
|
212 |
} |
267 |
} |
213 |
|
268 |
|
214 |
protected void initDrop() { |
269 |
protected void initDrop() { |
215 |
DropTarget target = new DropTarget(fileText, DND.DROP_MOVE |
270 |
DropTarget target = new DropTarget(fileCombo, DND.DROP_MOVE |
216 |
| DND.DROP_COPY | DND.DROP_DEFAULT); |
271 |
| DND.DROP_COPY | DND.DROP_DEFAULT); |
217 |
Transfer[] types = new Transfer[] { TextTransfer.getInstance(), |
272 |
Transfer[] types = new Transfer[] { TextTransfer.getInstance(), |
218 |
ResourceTransfer.getInstance() }; |
273 |
ResourceTransfer.getInstance() }; |
Lines 220-261
Link Here
|
220 |
target.addDropListener(new FileTextDropListener(this)); |
275 |
target.addDropListener(new FileTextDropListener(this)); |
221 |
} |
276 |
} |
222 |
|
277 |
|
223 |
protected void createGroup(Composite parent) { |
278 |
protected void createButtons(Composite parent) { |
224 |
group = new Group(parent, SWT.NONE); |
279 |
createOpenExternalFileButton(parent); |
225 |
group.setLayout(new GridLayout(3, false)); |
280 |
createOpenExternalFolderButton(parent); |
226 |
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
281 |
} |
|
|
282 |
|
283 |
protected void createInfo(Composite parent) { |
284 |
createFileLabel(parent); |
285 |
createFileCombo(parent); |
286 |
createPathLabel(parent); |
227 |
} |
287 |
} |
228 |
|
288 |
|
229 |
protected void createFileCombo() { |
289 |
protected void createFileCombo(Composite parent) { |
230 |
fileText = new Text(group, SWT.BORDER); |
290 |
fileCombo = new Combo(parent, SWT.NONE); |
231 |
fileText |
291 |
fileCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
232 |
.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); |
292 |
fileCombo.setItems(new String[] {""}); //$NON-NLS-1$ |
|
|
293 |
fileCombo.setText(fileCombo.getItem(0)); |
233 |
|
294 |
|
234 |
fileText.addModifyListener(new ModifyListener() { |
295 |
fileCombo.addModifyListener(new ModifyListener() { |
235 |
public void modifyText(ModifyEvent e) { |
296 |
public void modifyText(ModifyEvent e) { |
236 |
setResource(fileText.getText()); |
297 |
setResource(fileCombo.getText()); |
|
|
298 |
if (getResource() != null) { |
299 |
path = resource.getLocation().toOSString(); |
300 |
pathLabel.setText(dividePath(path)); |
301 |
} else { |
302 |
pathLabel.setText(""); //$NON-NLS-1$ |
303 |
} |
237 |
updateErrorInfo(); |
304 |
updateErrorInfo(); |
238 |
} |
305 |
} |
239 |
}); |
306 |
}); |
240 |
|
307 |
|
241 |
fileText.addSelectionListener(new SelectionListener() { |
308 |
fileCombo.addSelectionListener(new SelectionListener() { |
242 |
|
|
|
243 |
public void widgetDefaultSelected(SelectionEvent e) { |
309 |
public void widgetDefaultSelected(SelectionEvent e) { |
244 |
widgetSelected(e); |
310 |
widgetSelected(e); |
245 |
} |
311 |
} |
246 |
|
|
|
247 |
public void widgetSelected(SelectionEvent e) { |
312 |
public void widgetSelected(SelectionEvent e) { |
248 |
setResource(fileText.getText()); |
313 |
setResource(fileCombo.getText()); |
249 |
updateErrorInfo(); |
314 |
updateErrorInfo(); |
250 |
} |
315 |
} |
|
|
316 |
}); |
317 |
} |
251 |
|
318 |
|
|
|
319 |
protected void createOpenExternalFileButton(Composite parent) { |
320 |
openExternalFileButton = createButton(parent, |
321 |
OPEN_EXTERNAL_RETURN_CODE, |
322 |
CompareMessages.CompareWithOther_externalFileButton, false); |
323 |
openExternalFileButton.addSelectionListener(new SelectionListener() { |
324 |
public void widgetDefaultSelected(SelectionEvent e) { |
325 |
widgetSelected(e); |
326 |
} |
327 |
public void widgetSelected(SelectionEvent e) { |
328 |
resource = getExtenalFile(); |
329 |
updateAllSectionInfo(); |
330 |
} |
252 |
}); |
331 |
}); |
253 |
} |
332 |
} |
254 |
|
333 |
|
255 |
protected void createFileLabel() { |
334 |
protected void createOpenExternalFolderButton(Composite parent) { |
256 |
final Label fileLabel = new Label(group, SWT.NONE); |
335 |
openExternalFolderButton = createButton(parent, |
|
|
336 |
OPEN_EXTERNAL_RETURN_CODE, |
337 |
CompareMessages.CompareWithOther_externalFolderBUtton, false); |
338 |
openExternalFolderButton.addSelectionListener(new SelectionListener() { |
339 |
public void widgetDefaultSelected(SelectionEvent e) { |
340 |
widgetSelected(e); |
341 |
} |
342 |
public void widgetSelected(SelectionEvent e) { |
343 |
resource = getExternalDirectory(); |
344 |
updateAllSectionInfo(); |
345 |
} |
346 |
}); |
347 |
} |
348 |
|
349 |
private void updateAllSectionInfo() { |
350 |
addToHistory(resource); |
351 |
pathLabel.setText(dividePath(path)); |
352 |
getShell().pack(); |
353 |
pathLabel.getParent().layout(); |
354 |
updateErrorInfo(); |
355 |
} |
356 |
|
357 |
private void addToHistory(IResource r) { |
358 |
String txt = r.getFullPath().toString(); |
359 |
fileCombo.add(txt); |
360 |
fileCombo.setText(txt); |
361 |
} |
362 |
|
363 |
private IFile getExtenalFile() { |
364 |
FileDialog dialog = new FileDialog(getShell()); |
365 |
path = dialog.open(); |
366 |
IFile f = (IFile) getIResource(new Path(path), IResource.FILE); |
367 |
return f; |
368 |
} |
369 |
|
370 |
private IFolder getExternalDirectory() { |
371 |
DirectoryDialog dialog = new DirectoryDialog(getShell()); |
372 |
path = dialog.open(); |
373 |
IFolder f = (IFolder) getIResource(new Path(path), IResource.FOLDER); |
374 |
return f; |
375 |
} |
376 |
|
377 |
private IResource getIResource(IPath iPath, int type) { |
378 |
IResource r = null; |
379 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
380 |
IWorkspaceRoot root = workspace.getRoot(); |
381 |
IProject project = root.getProject(TMP_PROJECT_NAME); |
382 |
String resourceName = iPath.lastSegment(); |
383 |
try { |
384 |
project = createTmpProject(); |
385 |
if (!project.isOpen()) |
386 |
project.open(null); |
387 |
IFolder folderForExternal = project.getFolder(EXTERNAL_FILES_FOLDER_NAME); |
388 |
if (!folderForExternal.exists()) |
389 |
folderForExternal.create(IResource.NONE, true, null); |
390 |
if (type == IResource.FILE) { |
391 |
r = folderForExternal.getFile(resourceName); |
392 |
if (!r.exists()) |
393 |
((IFile)r).createLink(iPath, IResource.REPLACE, null); |
394 |
} |
395 |
else { |
396 |
r = folderForExternal.getFolder(resourceName); |
397 |
if (!r.exists()) |
398 |
((IFolder)r).createLink(iPath, IResource.REPLACE, null); |
399 |
} |
400 |
} catch (CoreException e) { |
401 |
CompareUIPlugin.log(e); |
402 |
MessageDialog.openError(getShell(), |
403 |
CompareMessages.CompareWithOther_externalFile_errorTitle, |
404 |
CompareMessages.CompareWithOther_externalFile_errorMessage); |
405 |
} |
406 |
return r; |
407 |
} |
408 |
|
409 |
/* |
410 |
* (non-javadoc) |
411 |
* |
412 |
* Implementation based on org.eclipse.jdt.internakl.core.ExternalFoldersManager#createExternalFoldersProject |
413 |
*/ |
414 |
private IProject createTmpProject() throws CoreException { |
415 |
IProject tmpProject = getTmpProject(); |
416 |
if (!tmpProject.isAccessible()) { |
417 |
try { |
418 |
if (!tmpProject.exists()) { |
419 |
IProjectDescription desc = tmpProject.getWorkspace() |
420 |
.newProjectDescription(tmpProject.getName()); |
421 |
IPath location = CompareUI.getPlugin() |
422 |
.getStateLocation(); |
423 |
desc.setLocation(location.append(TMP_PROJECT_NAME)); |
424 |
tmpProject.create(desc, null); |
425 |
} |
426 |
try { |
427 |
tmpProject.open(null); |
428 |
} catch (CoreException e1) { // in case .project file or folder has been deleted |
429 |
IPath location1 = CompareUI.getPlugin() |
430 |
.getStateLocation(); |
431 |
IPath projectPath1 = location1.append(TMP_PROJECT_NAME); |
432 |
projectPath1.toFile().mkdirs(); |
433 |
FileOutputStream output = new FileOutputStream( |
434 |
projectPath1.append(".project").toOSString()); //$NON-NLS-1$ |
435 |
try { |
436 |
output.write(TMP_PROJECT_FILE.getBytes()); |
437 |
} finally { |
438 |
output.close(); |
439 |
} |
440 |
tmpProject.open(null); |
441 |
} |
442 |
} catch (IOException ioe) { |
443 |
return tmpProject; |
444 |
} catch (CoreException ce) { |
445 |
throw new CoreException(ce.getStatus()); |
446 |
} |
447 |
} |
448 |
return tmpProject; |
449 |
} |
450 |
|
451 |
/* |
452 |
* (non-javadoc) |
453 |
* |
454 |
* Following method is analogical to org.eclipse.jdt.internal |
455 |
*/ |
456 |
private IProject getTmpProject() { |
457 |
return ResourcesPlugin.getWorkspace().getRoot().getProject( |
458 |
TMP_PROJECT_NAME); |
459 |
} |
460 |
|
461 |
protected void createFileLabel(Composite parent) { |
462 |
final Label fileLabel = new Label(parent, SWT.NONE); |
257 |
fileLabel.setText(CompareMessages.CompareWithOther_fileLabel); |
463 |
fileLabel.setText(CompareMessages.CompareWithOther_fileLabel); |
258 |
} |
464 |
} |
|
|
465 |
|
466 |
protected void createPathLabel(Composite parent) { |
467 |
pLabel = new Label(parent, SWT.NONE); |
468 |
pLabel.setText(CompareMessages.CompareWithOther_pathLabel); |
469 |
pLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true)); |
470 |
pathLabel = new Text(parent, SWT.MULTI); |
471 |
pathLabel.setBackground(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); |
472 |
pathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
473 |
} |
474 |
|
475 |
private String dividePath(String text) { |
476 |
String[] parts; |
477 |
int lineLengthLimit = computeLineLengthLimit(this); |
478 |
int lineLength = 0; |
479 |
String s = new String(); |
480 |
String separator = new String(System.getProperty("file.separator")); //$NON-NLS-1$ |
481 |
if (separator.equals("\\")) //$NON-NLS-1$ |
482 |
parts = text.split("\\" + separator); //$NON-NLS-1$ |
483 |
else |
484 |
parts = text.split(separator); |
485 |
for (int i = 0; i < parts.length; i++) { |
486 |
lineLength += parts[i].length(); |
487 |
if (lineLength >= lineLengthLimit) { |
488 |
s += "\n"; //$NON-NLS-1$ |
489 |
lineLength = 0; |
490 |
} |
491 |
s += parts[i]; |
492 |
s += separator; |
493 |
} |
494 |
return s; |
495 |
} |
259 |
} |
496 |
} |
260 |
|
497 |
|
261 |
private class InternalGroup extends InternalSection { |
498 |
private class InternalGroup extends InternalSection { |
Lines 283-317
Link Here
|
283 |
} |
520 |
} |
284 |
|
521 |
|
285 |
public void createContents(Composite parent) { |
522 |
public void createContents(Composite parent) { |
286 |
createGroup(parent); |
|
|
287 |
createFileLabel(); |
288 |
createFileCombo(); |
289 |
createClearButton(group); |
290 |
initDrag(); |
291 |
initDrop(); |
292 |
} |
293 |
|
294 |
public void createGroup(Composite parent) { |
295 |
final Composite p = parent; |
523 |
final Composite p = parent; |
296 |
expandable = new ExpandableComposite(parent, SWT.NONE, |
524 |
expandable = new ExpandableComposite(parent, SWT.NONE, |
297 |
ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE); |
525 |
ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE); |
298 |
super.createGroup(expandable); |
526 |
super.createContents(expandable); |
299 |
expandable.setClient(group); |
527 |
expandable.setClient(group); |
300 |
expandable.addExpansionListener(new ExpansionAdapter() { |
528 |
expandable.addExpansionListener(new ExpansionAdapter() { |
301 |
public void expansionStateChanged(ExpansionEvent e) { |
529 |
public void expansionStateChanged(ExpansionEvent e) { |
302 |
p.layout(); |
530 |
p.layout(); |
|
|
531 |
getShell().pack(); |
303 |
} |
532 |
} |
304 |
}); |
533 |
}); |
305 |
} |
534 |
} |
306 |
|
535 |
|
307 |
protected void createClearButton(Composite parent) { |
536 |
protected void createInfo(Composite parent) { |
|
|
537 |
createFileLabel(parent); |
538 |
createFileCombo(parent); |
539 |
createClearButton(parent); |
540 |
createPathLabel(parent); |
541 |
} |
542 |
|
543 |
private void createClearButton(Composite parent) { |
308 |
clearButton = createButton(parent, CLEAR_RETURN_CODE, |
544 |
clearButton = createButton(parent, CLEAR_RETURN_CODE, |
309 |
CompareMessages.CompareWithOther_clear, false); |
545 |
CompareMessages.CompareWithOther_clear, false); |
310 |
clearButton.addSelectionListener(new SelectionListener() { |
546 |
clearButton.addSelectionListener(new SelectionListener() { |
311 |
public void widgetDefaultSelected(SelectionEvent e) { |
547 |
public void widgetDefaultSelected(SelectionEvent e) { |
312 |
widgetSelected(e); |
548 |
widgetSelected(e); |
313 |
} |
549 |
} |
314 |
|
|
|
315 |
public void widgetSelected(SelectionEvent e) { |
550 |
public void widgetSelected(SelectionEvent e) { |
316 |
clearResource(); |
551 |
clearResource(); |
317 |
} |
552 |
} |
Lines 332-337
Link Here
|
332 |
private InternalGroup rightPanel, leftPanel; |
567 |
private InternalGroup rightPanel, leftPanel; |
333 |
private InternalExpandable ancestorPanel; |
568 |
private InternalExpandable ancestorPanel; |
334 |
private ISelection fselection; |
569 |
private ISelection fselection; |
|
|
570 |
private int lineLimit = 0; |
335 |
|
571 |
|
336 |
/** |
572 |
/** |
337 |
* Creates the dialog. |
573 |
* Creates the dialog. |
Lines 441-447
Link Here
|
441 |
IMessageProvider.ERROR); |
677 |
IMessageProvider.ERROR); |
442 |
okButton.setEnabled(false); |
678 |
okButton.setEnabled(false); |
443 |
} else if (ancestorPanel.getResource() == null |
679 |
} else if (ancestorPanel.getResource() == null |
444 |
&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$ |
680 |
&& ancestorPanel.fileCombo.getText() != "") { //$NON-NLS-1$ |
445 |
setMessage(CompareMessages.CompareWithOther_warning_two_way, |
681 |
setMessage(CompareMessages.CompareWithOther_warning_two_way, |
446 |
IMessageProvider.WARNING); |
682 |
IMessageProvider.WARNING); |
447 |
okButton.setEnabled(true); |
683 |
okButton.setEnabled(true); |
Lines 457-462
Link Here
|
457 |
} |
693 |
} |
458 |
} |
694 |
} |
459 |
|
695 |
|
|
|
696 |
public int computeLineLengthLimit(InternalSection section) { |
697 |
int leftLenght = leftPanel.fileCombo.getText().length(); |
698 |
int rightLength = rightPanel.fileCombo.getText().length(); |
699 |
int maxLenght = (leftLenght > rightLength ? leftLenght : rightLength); |
700 |
if (maxLenght > lineLimit) |
701 |
lineLimit = maxLenght; |
702 |
if (section instanceof InternalExpandable) |
703 |
return Math.max(lineLimit * 2 + 20, 90); |
704 |
return maxLenght; |
705 |
} |
706 |
|
460 |
/** |
707 |
/** |
461 |
* Returns table with selected resources. If any resource wasn't chosen in |
708 |
* Returns table with selected resources. If any resource wasn't chosen in |
462 |
* the ancestor panel, table has only two elements -- resources chosen in |
709 |
* the ancestor panel, table has only two elements -- resources chosen in |