View | Details | Raw Unified | Return to bug 243744 | Differences between
and this patch

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/CompareMessages.java (+11 lines)
Lines 120-125 Link Here
120
	public static String CompareWithOther_clear;
120
	public static String CompareWithOther_clear;
121
	public static String CompareWithOther_warning_two_way;
121
	public static String CompareWithOther_warning_two_way;
122
	public static String CompareWithOther_info;
122
	public static String CompareWithOther_info;
123
	public static String CompareWithOther_externalFileButton;
124
	public static String CompareWithOther_externalFile_errorTitle;
125
	public static String CompareWithOther_externalFile_errorMessage;
126
	public static String CompareWithOther_pathLabel;
127
	public static String CompareWithOther_externalFolderBUtton;
128
	public static String CompareWithOtherResourceDialog_externalFileMainButton;
129
	public static String CompareWithOtherResourceDialog_externalFileRadioButton;
130
	public static String CompareWithOtherResourceDialog_externalFolderMainButton;
131
	public static String CompareWithOtherResourceDialog_externalFolderRadioButton;
132
	public static String CompareWithOtherResourceDialog_workspaceMainButton;
133
	public static String CompareWithOtherResourceDialog_workspaceRadioButton;
123
134
124
	static {
135
	static {
125
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
136
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java (+2 lines)
Lines 23-28 Link Here
23
		// Show CompareWithOtherResourceDialog which return resources to compare
23
		// Show CompareWithOtherResourceDialog which return resources to compare
24
		// and ancestor if specified. Don't need to display the other dialog
24
		// and ancestor if specified. Don't need to display the other dialog
25
		showSelectAncestorDialog = false;
25
		showSelectAncestorDialog = false;
26
		// prevent reusing old temporary files
27
		CompareWithOtherResourceDialog.cleanup();
26
		super.run(selection);
28
		super.run(selection);
27
	}
29
	}
28
30
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java (-101 / +463 lines)
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 38-50 Link Here
38
import org.eclipse.swt.widgets.Button;
51
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Composite;
52
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Control;
53
import org.eclipse.swt.widgets.Control;
54
import org.eclipse.swt.widgets.DirectoryDialog;
55
import org.eclipse.swt.widgets.Event;
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.Listener;
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;
45
import org.eclipse.ui.forms.events.ExpansionAdapter;
61
import org.eclipse.ui.forms.events.ExpansionAdapter;
46
import org.eclipse.ui.forms.events.ExpansionEvent;
62
import org.eclipse.ui.forms.events.ExpansionEvent;
47
import org.eclipse.ui.forms.widgets.ExpandableComposite;
63
import org.eclipse.ui.forms.widgets.ExpandableComposite;
64
import org.eclipse.ui.internal.ide.dialogs.OpenResourceDialog;
48
import org.eclipse.ui.part.ResourceTransfer;
65
import org.eclipse.ui.part.ResourceTransfer;
49
66
50
/**
67
/**
Lines 53-93 Link Here
53
 * @since 3.4
70
 * @since 3.4
54
 */
71
 */
55
public class CompareWithOtherResourceDialog extends TitleAreaDialog {
72
public class CompareWithOtherResourceDialog extends TitleAreaDialog {
56
73
	
57
	private int CLEAR_RETURN_CODE = 150; // any number != 0
58
	private int MIN_WIDTH = 300;
74
	private int MIN_WIDTH = 300;
59
	private int MIN_HEIGHT = 175;
75
	private int MIN_HEIGHT = 175;
76
	
77
	private static final String TMP_PROJECT_NAME = ".org.eclipse.compare.tmp"; //$NON-NLS-1$
78
	private final static String TMP_PROJECT_FILE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$
79
			+ "<projectDescription>\n" //$NON-NLS-1$
80
			+ "\t<name>" + TMP_PROJECT_NAME + "\t</name>\n" //$NON-NLS-1$ //$NON-NLS-2$
81
			+ "\t<comment></comment>\n" //$NON-NLS-1$
82
			+ "\t<projects>\n" //$NON-NLS-1$
83
			+ "\t</projects>\n" //$NON-NLS-1$
84
			+ "\t<buildSpec>\n" //$NON-NLS-1$
85
			+ "\t</buildSpec>\n" //$NON-NLS-1$
86
			+ "\t<natures>\n" + "\t</natures>\n" //$NON-NLS-1$//$NON-NLS-2$
87
			+ "</projectDescription>"; //$NON-NLS-1$
88
	private final static String EXTERNAL_FILES_FOLDER_NAME = "ExternalFilesFolder"; //$NON-NLS-1$
60
89
61
	private class FileTextDragListener implements DragSourceListener {
90
	private class FileTextDragListener implements DragSourceListener {
62
91
63
		private InternalSection section;
92
		private ContentTypeElement element;
64
93
65
		public FileTextDragListener(InternalSection section) {
94
		public FileTextDragListener(ContentTypeElement element) {
66
			this.section = section;
95
			this.element = element;
67
		}
96
		}
68
97
69
		public void dragFinished(DragSourceEvent event) {
98
		public void dragFinished(DragSourceEvent event) {
70
			section.fileText.setText(""); //$NON-NLS-1$
99
			element.setText(""); //$NON-NLS-1$
71
		}
100
		}
72
101
73
		public void dragSetData(DragSourceEvent event) {
102
		public void dragSetData(DragSourceEvent event) {
74
			event.data = section.fileText.getText();
103
			event.data = element.getText();
75
		}
104
		}
76
105
77
		public void dragStart(DragSourceEvent event) {
106
		public void dragStart(DragSourceEvent event) {
78
			if (section.fileText.getText() == null)
107
			if (element.getText() == null)
79
				event.doit = false;
108
				event.doit = false;
80
		}
109
		}
81
	}
110
	}
82
111
83
	private class FileTextDropListener implements DropTargetListener {
112
	private class FileTextDropListener implements DropTargetListener {
84
113
85
		private InternalSection section;
114
		private ContentTypeElement element;
86
		private ResourceTransfer resourceTransfer;
115
		private ResourceTransfer resourceTransfer;
87
		private TextTransfer textTransfer;
116
		private TextTransfer textTransfer;
88
117
89
		public FileTextDropListener(InternalSection section) {
118
		public FileTextDropListener(ContentTypeElement element) {
90
			this.section = section;
119
			this.element = element;
91
			resourceTransfer = ResourceTransfer.getInstance();
120
			resourceTransfer = ResourceTransfer.getInstance();
92
			textTransfer = TextTransfer.getInstance();
121
			textTransfer = TextTransfer.getInstance();
93
		}
122
		}
Lines 139-148 Link Here
139
				String txt = (String) event.data;
168
				String txt = (String) event.data;
140
				IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt);
169
				IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt);
141
				if (r != null)
170
				if (r != null)
142
					section.setResource(r);
171
					element.setResource(r);
143
			} else if (resourceTransfer.isSupportedType(event.currentDataType)) {
172
			} else if (resourceTransfer.isSupportedType(event.currentDataType)) {
144
				IResource[] files = (IResource[]) event.data;
173
				IResource[] files = (IResource[]) event.data;
145
				section.setResource(files[0]);
174
				element.setResource(files[0]);
146
			}
175
			}
147
176
148
			updateErrorInfo();
177
			updateErrorInfo();
Lines 153-209 Link Here
153
		}
182
		}
154
183
155
	}
184
	}
156
185
	
157
	private abstract class InternalSection {
186
	private abstract class ContentTypeElement {
158
187
		
159
		protected Group group;
188
		private Button radioButton;
160
		protected Text fileText;
189
		protected Button mainButton;
190
		protected Text text;
191
		private String type;
192
		protected InternalSection section;
161
		private IResource resource;
193
		private IResource resource;
162
194
		
163
		public InternalSection(Composite parent) {
195
		public ContentTypeElement(Composite parent, String type, InternalSection section) {
196
			this.type = type;
197
			this.section = section;
164
			createContents(parent);
198
			createContents(parent);
165
		}
199
		}
166
200
		
167
		private InternalSection() {
201
		private void createContents(Composite parent) {
168
			// not to instantiate
202
			createRadioButton(parent);
203
			createText(parent);
204
			createMainButton(parent);
205
		}
206
		
207
		private void createRadioButton(Composite parent) {
208
			radioButton = new Button(parent, SWT.RADIO);
209
			radioButton.setText(type);
210
		}
211
212
		protected void createText(Composite parent) {
213
			text = new Text(parent, SWT.BORDER);
214
			text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
215
			text.setEditable(false);
216
		}
217
		
218
		protected void createMainButton(Composite parent) {
219
			mainButton = new Button(parent, SWT.PUSH);
220
			mainButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
221
		}
222
		
223
		protected Button getRadioButton() {
224
			return radioButton;
225
		}
226
		
227
		protected String getText() {
228
			return text.getText();
229
		}
230
		
231
		protected void setText(String string) {
232
			text.setText(string);
233
		}
234
		
235
		protected InternalSection getSection() {
236
			return section;
237
		}
238
		
239
		protected void setEnabled(boolean enabled) {
240
			radioButton.setSelection(enabled);
241
			mainButton.setEnabled(enabled);
242
			text.setEnabled(enabled);
169
		}
243
		}
170
244
		
171
		public void createContents(Composite parent) {
245
		protected void setResource(IResource resource) {
172
			createGroup(parent);
246
			this.resource = resource;
173
			createFileLabel();
247
			section.setResource(resource);
174
			createFileCombo();
175
			initDrag();
176
			initDrop();
177
		}
248
		}
178
249
179
		public IResource getResource() {
250
		public IResource getResource() {
180
			return resource;
251
			return resource;
181
		}
252
		}
182
253
		
183
		public void setResource(IResource resource) {
254
		void clearResource() {
184
			this.resource = resource;
255
			resource = null;
185
			String txt = resource.getFullPath().toString();
256
			text.setText(""); //$NON-NLS-1$
186
			fileText.setText(txt);
187
		}
257
		}
258
		
259
	}
260
	
261
	private class WorkspaceContent extends ContentTypeElement {
262
		
263
		public WorkspaceContent(Composite parent, InternalSection section) {
264
			super(parent, CompareMessages.CompareWithOtherResourceDialog_workspaceRadioButton, section);
265
		}
266
		
267
		protected void createMainButton(Composite parent) {
268
			super.createMainButton(parent);
269
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_workspaceMainButton);
270
			mainButton.addSelectionListener(new SelectionListener() {
271
				public void widgetDefaultSelected(SelectionEvent e) {
272
					widgetSelected(e);
273
				}
274
				public void widgetSelected(SelectionEvent e) {
275
					setResource(getResourceFromDialog());
276
				}
277
			});
278
		}
279
		
280
		protected void createText(Composite parent) {
281
			
282
			super.createText(parent);
283
			text.setEditable(true);
284
			
285
			text.addModifyListener(new ModifyListener() {
286
				public void modifyText(ModifyEvent e) {
287
					section.setResource(text.getText());
288
					updateErrorInfo();
289
				}
290
			});
188
291
189
		public void setResource(String s) {
292
			text.addSelectionListener(new SelectionListener() {
190
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
293
				public void widgetDefaultSelected(SelectionEvent e) {
191
					.findMember(s);
294
					widgetSelected(e);
192
			if (tmp instanceof IWorkspaceRoot)
295
				}
193
				resource = null;
296
				public void widgetSelected(SelectionEvent e) {
194
			else
297
					section.setResource(text.getText());
195
				resource = tmp;
298
					updateErrorInfo();
196
299
				}
300
			});
301
			
302
			initDrag();
303
			initDrop();
197
		}
304
		}
198
305
199
		protected void clearResource() {
306
		protected void setResource(IResource resource) {
200
			resource = null;
307
			super.setResource(resource);
201
			fileText.setText(""); //$NON-NLS-1$
308
			text.setText(resource.getFullPath().toOSString());
202
			updateErrorInfo();
309
		}
310
		
311
		private IResource getResourceFromDialog() {
312
			IResource r = null;
313
			IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
314
			OpenResourceDialog dialog = new OpenResourceDialog(getShell(), root, IResource.FILE);
315
			int returnCode = dialog.open();
316
			if (returnCode != IDialogConstants.OK_ID)
317
				return null;
318
			Object[] result = dialog.getResult();
319
			if (result.length > 0)
320
				r = (IResource) result[0];
321
			return r;
203
		}
322
		}
204
323
205
		protected void initDrag() {
324
		protected void initDrag() {
206
			DragSource source = new DragSource(fileText, DND.DROP_MOVE
325
			DragSource source = new DragSource(text, DND.DROP_MOVE
207
					| DND.DROP_COPY | DND.DROP_DEFAULT);
326
					| DND.DROP_COPY | DND.DROP_DEFAULT);
208
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
327
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
209
					ResourceTransfer.getInstance() };
328
					ResourceTransfer.getInstance() };
Lines 212-260 Link Here
212
		}
331
		}
213
332
214
		protected void initDrop() {
333
		protected void initDrop() {
215
			DropTarget target = new DropTarget(fileText, DND.DROP_MOVE
334
			DropTarget target = new DropTarget(text, DND.DROP_MOVE
216
					| DND.DROP_COPY | DND.DROP_DEFAULT);
335
					| DND.DROP_COPY | DND.DROP_DEFAULT);
217
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
336
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
218
					ResourceTransfer.getInstance() };
337
					ResourceTransfer.getInstance() };
219
			target.setTransfer(types);
338
			target.setTransfer(types);
220
			target.addDropListener(new FileTextDropListener(this));
339
			target.addDropListener(new FileTextDropListener(this));
221
		}
340
		}
222
341
		
223
		protected void createGroup(Composite parent) {
342
	}
224
			group = new Group(parent, SWT.NONE);
343
	
225
			group.setLayout(new GridLayout(3, false));
344
	private class ExternalFileContent extends ContentTypeElement {
226
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
345
		
227
		}
346
		public ExternalFileContent(Composite parent, InternalSection section) {
228
347
			super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFileRadioButton, section);
229
		protected void createFileCombo() {
348
		}
230
			fileText = new Text(group, SWT.BORDER);
349
		
231
			fileText
350
		protected void createMainButton(Composite parent) {
232
					.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
351
			super.createMainButton(parent);
233
352
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFileMainButton);
234
			fileText.addModifyListener(new ModifyListener() {
353
			mainButton.addSelectionListener(new SelectionListener() {
235
				public void modifyText(ModifyEvent e) {
354
				public void widgetDefaultSelected(SelectionEvent e) {
236
					setResource(fileText.getText());
355
					widgetSelected(e);
237
					updateErrorInfo();
356
				}
357
				public void widgetSelected(SelectionEvent e) {
358
					IResource r = getExtenalFile();
359
					if (r == null) 
360
						return;
361
					setResource(r);
238
				}
362
				}
239
			});
363
			});
364
		}
240
365
241
			fileText.addSelectionListener(new SelectionListener() {
366
		protected void setResource(IResource resource) {
242
367
			super.setResource(resource);
368
			text.setText(resource.getLocation().toOSString());
369
		}
370
		
371
	}
372
	
373
	private class ExternalFolderContent extends ContentTypeElement {
374
		
375
		public ExternalFolderContent(Composite parent, InternalSection section) {
376
			super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFolderRadioButton, section);
377
		}
378
		
379
		protected void createMainButton(Composite parent) {
380
			super.createMainButton(parent);
381
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFolderMainButton);
382
			mainButton.addSelectionListener(new SelectionListener() {
243
				public void widgetDefaultSelected(SelectionEvent e) {
383
				public void widgetDefaultSelected(SelectionEvent e) {
244
					widgetSelected(e);
384
					widgetSelected(e);
245
				}
385
				}
246
247
				public void widgetSelected(SelectionEvent e) {
386
				public void widgetSelected(SelectionEvent e) {
248
					setResource(fileText.getText());
387
					IResource r = getExternalDirectory();
249
					updateErrorInfo();
388
					if (r == null)
389
						return;
390
					setResource(r);
250
				}
391
				}
251
252
			});
392
			});
253
		}
393
		}
254
394
255
		protected void createFileLabel() {
395
		protected void setResource(IResource resource) {
256
			final Label fileLabel = new Label(group, SWT.NONE);
396
			super.setResource(resource);
257
			fileLabel.setText(CompareMessages.CompareWithOther_fileLabel);
397
			text.setText(resource.getLocation().toOSString());
398
		}
399
		
400
	}
401
402
	private abstract class InternalSection {
403
		
404
		// there is no "enum" support in Java 1.4. Sigh...
405
		public static final int WORKSPACE = 0;
406
		public static final int EXTERNAL_FILE = 1;
407
		public static final int EXTERNAL_FOLDER = 2;
408
409
		protected Group group;
410
		private IResource resource;
411
		
412
		ExternalFileContent externalFileContent;
413
		ExternalFolderContent externalFolderContent;
414
		WorkspaceContent workspaceContent;
415
		
416
		public InternalSection(Composite parent) {
417
			createContents(parent);
418
		}
419
420
		private InternalSection() {
421
			// not to instantiate
422
		}
423
424
		protected void createContents(Composite parent) {
425
426
			group = new Group(parent, SWT.NONE);
427
			group.setLayout(new GridLayout(3, false));
428
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
429
			
430
			workspaceContent = new WorkspaceContent(group, this);
431
			externalFileContent = new ExternalFileContent(group, this);
432
			externalFolderContent = new ExternalFolderContent(group, this);
433
			
434
			addListenersToRadioButtons();
435
		}
436
		
437
		private void addListenersToRadioButtons() {
438
			final ContentTypeElement[] elements = new ContentTypeElement[] { workspaceContent, 
439
					externalFileContent, externalFolderContent };
440
			for (int i = 0; i < elements.length; i++)
441
				elements[i].getRadioButton().addListener(SWT.Selection, new Listener() {
442
					public void handleEvent(Event event) {
443
						for (int j = 0; j < elements.length; j++)
444
							if (event.widget != elements[j].getRadioButton())
445
								elements[j].setEnabled(false);
446
							else {
447
								elements[j].setEnabled(true);
448
								setResource(elements[j].getResource());
449
							}
450
					}
451
				});
452
		}
453
454
		protected IResource getResource() {
455
			return resource;
456
		}
457
458
		protected void setResource(IResource resource) {
459
			this.resource = resource;
460
			updateErrorInfo();
461
		}
462
463
		protected void setResource(String s) {
464
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
465
					.findMember(s);
466
			if (tmp instanceof IWorkspaceRoot) 
467
				resource = null;
468
			else 
469
				resource = tmp;
470
			updateErrorInfo();
471
		}
472
473
		protected void clearResource() {
474
			resource = null;
475
			workspaceContent.clearResource();
476
			externalFileContent.clearResource();
477
			externalFolderContent.clearResource();
478
			updateErrorInfo();
479
		}
480
		
481
		protected void setContentType(int type) {
482
			switch(type) {
483
			case WORKSPACE: 
484
				workspaceContent.setEnabled(true);
485
				externalFileContent.setEnabled(false);
486
				externalFolderContent.setEnabled(false);
487
				break;
488
			case EXTERNAL_FILE:
489
				workspaceContent.setEnabled(false);
490
				externalFileContent.setEnabled(true);
491
				externalFolderContent.setEnabled(false);
492
				break;
493
			case EXTERNAL_FOLDER:
494
				workspaceContent.setEnabled(false);
495
				externalFileContent.setEnabled(false);
496
				externalFolderContent.setEnabled(true);
497
			}
258
		}
498
		}
259
	}
499
	}
260
500
Lines 282-317 Link Here
282
			createContents(parent);
522
			createContents(parent);
283
		}
523
		}
284
524
285
		public void createContents(Composite parent) {
525
		protected 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;
526
			final Composite p = parent;
296
			expandable = new ExpandableComposite(parent, SWT.NONE,
527
			expandable = new ExpandableComposite(parent, SWT.NONE,
297
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
528
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
298
			super.createGroup(expandable);
529
			super.createContents(expandable);
530
			createClearButton(group);
299
			expandable.setClient(group);
531
			expandable.setClient(group);
300
			expandable.addExpansionListener(new ExpansionAdapter() {
532
			expandable.addExpansionListener(new ExpansionAdapter() {
301
				public void expansionStateChanged(ExpansionEvent e) {
533
				public void expansionStateChanged(ExpansionEvent e) {
302
					p.layout();
534
					p.layout();
535
					getShell().pack();
303
				}
536
				}
304
			});
537
			});
305
		}
538
		}
306
539
307
		protected void createClearButton(Composite parent) {
540
		private void createClearButton(Composite parent) {
308
			clearButton = createButton(parent, CLEAR_RETURN_CODE,
541
			clearButton = new Button(parent, SWT.PUSH);
309
					CompareMessages.CompareWithOther_clear, false);
542
			clearButton.setText(CompareMessages.CompareWithOther_clear);
310
			clearButton.addSelectionListener(new SelectionListener() {
543
			clearButton.addSelectionListener(new SelectionListener() {
311
				public void widgetDefaultSelected(SelectionEvent e) {
544
				public void widgetDefaultSelected(SelectionEvent e) {
312
					widgetSelected(e);
545
					widgetSelected(e);
313
				}
546
				}
314
315
				public void widgetSelected(SelectionEvent e) {
547
				public void widgetSelected(SelectionEvent e) {
316
					clearResource();
548
					clearResource();
317
				}
549
				}
Lines 332-337 Link Here
332
	private InternalGroup rightPanel, leftPanel;
564
	private InternalGroup rightPanel, leftPanel;
333
	private InternalExpandable ancestorPanel;
565
	private InternalExpandable ancestorPanel;
334
	private ISelection fselection;
566
	private ISelection fselection;
567
	private int externalFilesCounter = 0;
335
568
336
	/**
569
	/**
337
	 * Creates the dialog.
570
	 * Creates the dialog.
Lines 403-432 Link Here
403
		IResource[] selectedResources = Utilities.getResources(selection);
636
		IResource[] selectedResources = Utilities.getResources(selection);
404
		switch (selectedResources.length) {
637
		switch (selectedResources.length) {
405
		case 1:
638
		case 1:
406
			leftPanel.setResource(selectedResources[0]);
639
			leftPanel.workspaceContent.setResource(selectedResources[0]);
407
			break;
640
			break;
408
		case 2:
641
		case 2:
409
			leftPanel.setResource(selectedResources[0]);
642
			leftPanel.workspaceContent.setResource(selectedResources[0]);
410
			rightPanel.setResource(selectedResources[1]);
643
			rightPanel.workspaceContent.setResource(selectedResources[1]);
411
			break;
644
			break;
412
		case 3:
645
		case 3:
413
			ancestorPanel.setResource(selectedResources[0]);
646
			ancestorPanel.workspaceContent.setResource(selectedResources[0]);
414
			ancestorPanel.expandable.setExpanded(true);
647
			ancestorPanel.expandable.setExpanded(true);
415
			leftPanel.setResource(selectedResources[1]);
648
			leftPanel.workspaceContent.setResource(selectedResources[1]);
416
			rightPanel.setResource(selectedResources[2]);
649
			rightPanel.workspaceContent.setResource(selectedResources[2]);
417
			break;
650
			break;
418
		}
651
		}
652
		setInitialContentTypes();
653
	}
654
655
	private void setInitialContentTypes() {
656
		ancestorPanel.setContentType(InternalSection.WORKSPACE);
657
		leftPanel.setContentType(InternalSection.WORKSPACE);
658
		rightPanel.setContentType(InternalSection.WORKSPACE);
419
	}
659
	}
420
660
421
	private boolean isComparePossible() {
661
	private boolean isComparePossible() {
422
		IResource[] resources;
662
		IResource[] resources;
423
		if (ancestorPanel.getResource() == null) {
663
		if (ancestorPanel.getResource() == null)
424
			resources = new IResource[] { leftPanel.getResource(),
664
			resources = new IResource[] { leftPanel.getResource(),
425
					rightPanel.getResource() };
665
					rightPanel.getResource() };
426
		} else {
666
		else
427
			resources = new IResource[] { ancestorPanel.getResource(),
667
			resources = new IResource[] { ancestorPanel.getResource(),
428
					leftPanel.getResource(), rightPanel.getResource() };
668
					leftPanel.getResource(), rightPanel.getResource() };
429
		}
430
669
431
		ResourceCompareInput r = new ResourceCompareInput(
670
		ResourceCompareInput r = new ResourceCompareInput(
432
				new CompareConfiguration());
671
				new CompareConfiguration());
Lines 440-447 Link Here
440
				setMessage(CompareMessages.CompareWithOther_error_empty,
679
				setMessage(CompareMessages.CompareWithOther_error_empty,
441
						IMessageProvider.ERROR);
680
						IMessageProvider.ERROR);
442
				okButton.setEnabled(false);
681
				okButton.setEnabled(false);
443
			} else if (ancestorPanel.getResource() == null
682
			} else if (ancestorPanel.getResource() == null && isComparePossible()) {
444
					&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$
445
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
683
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
446
						IMessageProvider.WARNING);
684
						IMessageProvider.WARNING);
447
				okButton.setEnabled(true);
685
				okButton.setEnabled(true);
Lines 456-461 Link Here
456
			}
694
			}
457
		}
695
		}
458
	}
696
	}
697
	
698
	private IFile getExtenalFile() {
699
		FileDialog dialog = new FileDialog(getShell());
700
		String path = dialog.open();
701
		if (path != null)
702
			return (IFile) getResource(new Path(path), IResource.FILE);
703
		return null;
704
	}
705
706
	private IFolder getExternalDirectory() {
707
		DirectoryDialog dialog = new DirectoryDialog(getShell());
708
		String path = dialog.open();
709
		if (path != null)
710
			return (IFolder) getResource(new Path(path), IResource.FOLDER);
711
		return null;
712
	}
713
714
	private IResource getResource(IPath path, int type) {
715
		IResource r = null;
716
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
717
		IWorkspaceRoot root = workspace.getRoot();
718
		IProject project = root.getProject(TMP_PROJECT_NAME);
719
		String resourceName = path.lastSegment();
720
		try {
721
			project = createTmpProject();
722
			if (!project.isOpen())
723
				project.open(null);
724
			IFolder folderForExternal = project.getFolder(EXTERNAL_FILES_FOLDER_NAME);
725
			if (!folderForExternal.exists())
726
				folderForExternal.create(IResource.NONE, true, null);
727
			if (type == IResource.FILE) {
728
				r = folderForExternal.getFile(resourceName);
729
				if (r.exists()) { 	// add a number to file's name when there already is a file with that name in a folder
730
					String extension = path.getFileExtension();
731
					String newName = path.removeFileExtension().lastSegment(); 
732
					newName += "-" + externalFilesCounter + "." + extension; //$NON-NLS-1$ //$NON-NLS-2$
733
					r = folderForExternal.getFile(newName);
734
				}
735
				((IFile)r).createLink(path, IResource.REPLACE, null);
736
				externalFilesCounter++;
737
			}
738
			else {
739
				r = folderForExternal.getFolder(resourceName);
740
				if (r.exists()) {
741
					String newName = resourceName + "-" + externalFilesCounter; //$NON-NLS-1$
742
					r = folderForExternal.getFolder(newName);
743
				}
744
				((IFolder)r).createLink(path, IResource.REPLACE, null);
745
				externalFilesCounter++;
746
			}
747
		} catch (CoreException e) {
748
			CompareUIPlugin.log(e);
749
			MessageDialog.openError(getShell(),
750
							CompareMessages.CompareWithOther_externalFile_errorTitle,
751
							CompareMessages.CompareWithOther_externalFile_errorMessage);
752
		}
753
		return r;
754
	}
755
756
	/*
757
	 * (non-javadoc)
758
	 *
759
	 * Implementation based on org.eclipse.jdt.internal.core.ExternalFoldersManager#createExternalFoldersProject
760
	 */
761
	private IProject createTmpProject() throws CoreException {
762
		IProject tmpProject = getTmpProject();
763
		if (!tmpProject.isAccessible()) {
764
			try {
765
				if (!tmpProject.exists()) {
766
					IProjectDescription desc = tmpProject.getWorkspace()
767
							.newProjectDescription(tmpProject.getName());
768
					IPath location = CompareUI.getPlugin()
769
							.getStateLocation();
770
					desc.setLocation(location.append(TMP_PROJECT_NAME));
771
					tmpProject.create(desc, null);
772
				}
773
				try {
774
					tmpProject.open(null);
775
				} catch (CoreException e1) { // in case .project file or folder has been deleted
776
					IPath location1 = CompareUI.getPlugin()
777
							.getStateLocation();
778
					IPath projectPath1 = location1.append(TMP_PROJECT_NAME);
779
					projectPath1.toFile().mkdirs();
780
					FileOutputStream output = new FileOutputStream(
781
							projectPath1.append(".project").toOSString()); //$NON-NLS-1$
782
					try {
783
						output.write(TMP_PROJECT_FILE.getBytes());
784
					} finally {
785
						output.close();
786
					}
787
					tmpProject.open(null);
788
				}
789
			} catch (IOException ioe) {
790
				return tmpProject;
791
			} catch (CoreException ce) {
792
				throw new CoreException(ce.getStatus());
793
			}
794
		}
795
		return tmpProject;
796
	}
797
798
	/*
799
	 * (non-javadoc)
800
	 *
801
	 * Following method is analogical to org.eclipse.jdt.internal
802
	 */
803
	private IProject getTmpProject() {
804
		return ResourcesPlugin.getWorkspace().getRoot().getProject(
805
				TMP_PROJECT_NAME);
806
	}
459
807
460
	/**
808
	/**
461
	 * Returns table with selected resources. If any resource wasn't chosen in
809
	 * Returns table with selected resources. If any resource wasn't chosen in
Lines 477-480 Link Here
477
					rightResource };
825
					rightResource };
478
		return resources;
826
		return resources;
479
	}
827
	}
828
	
829
	/**
830
	 * Removes temporary files created from clipboard's content or imported to 
831
	 * workspace only for comparing.
832
	 */
833
	public static void cleanup() {
834
		try {
835
			IProject project = ResourcesPlugin.getWorkspace().getRoot()
836
					.getProject(TMP_PROJECT_NAME);
837
			project.delete(true, true, null);
838
		} catch (CoreException e) {
839
			CompareUIPlugin.log(e);
840
		}
841
	}
480
}
842
}
(-)compare/org/eclipse/compare/internal/CompareMessages.properties (+11 lines)
Lines 132-134 Link Here
132
CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed.
132
CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed.
133
CompareWithOther_clear=Clear
133
CompareWithOther_clear=Clear
134
CompareWithOther_info=Drag files from a view or between dialog's fields.
134
CompareWithOther_info=Drag files from a view or between dialog's fields.
135
CompareWithOther_externalFileButton=External file...
136
CompareWithOther_externalFolderBUtton=External folder...
137
CompareWithOther_externalFile_errorTitle=Compare With Other Resource Error
138
CompareWithOther_externalFile_errorMessage=Cannot create a link to an external file.
139
CompareWithOther_pathLabel=Path:
140
CompareWithOtherResourceDialog_externalFileMainButton=Browse...
141
CompareWithOtherResourceDialog_externalFileRadioButton=External file
142
CompareWithOtherResourceDialog_externalFolderMainButton=Browse...
143
CompareWithOtherResourceDialog_externalFolderRadioButton=External folder
144
CompareWithOtherResourceDialog_workspaceMainButton=Browse...
145
CompareWithOtherResourceDialog_workspaceRadioButton=Workspace

Return to bug 243744