View | Details | Raw Unified | Return to bug 73923 | 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 (-105 / +444 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-45 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;
Lines 53-93 Link Here
53
 * @since 3.4
69
 * @since 3.4
54
 */
70
 */
55
public class CompareWithOtherResourceDialog extends TitleAreaDialog {
71
public class CompareWithOtherResourceDialog extends TitleAreaDialog {
56
72
	
57
	private int CLEAR_RETURN_CODE = 150; // any number != 0
58
	private int MIN_WIDTH = 300;
73
	private int MIN_WIDTH = 300;
59
	private int MIN_HEIGHT = 175;
74
	private int MIN_HEIGHT = 175;
75
	
76
	public static final String TMP_PROJECT_NAME = ".org.eclipse.compare.tmp"; //$NON-NLS-1$
77
	private final static String TMP_PROJECT_FILE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" //$NON-NLS-1$
78
			+ "<projectDescription>\n" //$NON-NLS-1$
79
			+ "\t<name>" + TMP_PROJECT_NAME + "\t</name>\n" //$NON-NLS-1$ //$NON-NLS-2$
80
			+ "\t<comment></comment>\n" //$NON-NLS-1$
81
			+ "\t<projects>\n" //$NON-NLS-1$
82
			+ "\t</projects>\n" //$NON-NLS-1$
83
			+ "\t<buildSpec>\n" //$NON-NLS-1$
84
			+ "\t</buildSpec>\n" //$NON-NLS-1$
85
			+ "\t<natures>\n" + "\t</natures>\n" //$NON-NLS-1$//$NON-NLS-2$
86
			+ "</projectDescription>"; //$NON-NLS-1$
87
	private final static String EXTERNAL_FILES_FOLDER_NAME = "ExternalFilesFolder"; //$NON-NLS-1$
60
88
61
	private class FileTextDragListener implements DragSourceListener {
89
	private class FileTextDragListener implements DragSourceListener {
62
90
63
		private InternalSection section;
91
		private ContentTypeElement element;
64
92
65
		public FileTextDragListener(InternalSection section) {
93
		public FileTextDragListener(ContentTypeElement element) {
66
			this.section = section;
94
			this.element = element;
67
		}
95
		}
68
96
69
		public void dragFinished(DragSourceEvent event) {
97
		public void dragFinished(DragSourceEvent event) {
70
			section.fileText.setText(""); //$NON-NLS-1$
98
			element.setText(""); //$NON-NLS-1$
71
		}
99
		}
72
100
73
		public void dragSetData(DragSourceEvent event) {
101
		public void dragSetData(DragSourceEvent event) {
74
			event.data = section.fileText.getText();
102
			event.data = element.getText();
75
		}
103
		}
76
104
77
		public void dragStart(DragSourceEvent event) {
105
		public void dragStart(DragSourceEvent event) {
78
			if (section.fileText.getText() == null)
106
			if (element.getText() == null)
79
				event.doit = false;
107
				event.doit = false;
80
		}
108
		}
81
	}
109
	}
82
110
83
	private class FileTextDropListener implements DropTargetListener {
111
	private class FileTextDropListener implements DropTargetListener {
84
112
85
		private InternalSection section;
113
		private ContentTypeElement element;
86
		private ResourceTransfer resourceTransfer;
114
		private ResourceTransfer resourceTransfer;
87
		private TextTransfer textTransfer;
115
		private TextTransfer textTransfer;
88
116
89
		public FileTextDropListener(InternalSection section) {
117
		public FileTextDropListener(ContentTypeElement element) {
90
			this.section = section;
118
			this.element = element;
91
			resourceTransfer = ResourceTransfer.getInstance();
119
			resourceTransfer = ResourceTransfer.getInstance();
92
			textTransfer = TextTransfer.getInstance();
120
			textTransfer = TextTransfer.getInstance();
93
		}
121
		}
Lines 139-151 Link Here
139
				String txt = (String) event.data;
167
				String txt = (String) event.data;
140
				IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt);
168
				IResource r = ResourcesPlugin.getWorkspace().getRoot().findMember(txt);
141
				if (r != null)
169
				if (r != null)
142
					section.setResource(r);
170
					element.setResource(r);
143
			} else if (resourceTransfer.isSupportedType(event.currentDataType)) {
171
			} else if (resourceTransfer.isSupportedType(event.currentDataType)) {
144
				IResource[] files = (IResource[]) event.data;
172
				IResource[] files = (IResource[]) event.data;
145
				section.setResource(files[0]);
173
				if (files.length > 0)
174
					element.setResource(files[0]);
146
			}
175
			}
147
176
148
			updateErrorInfo();
149
		}
177
		}
150
178
151
		public void dropAccept(DropTargetEvent event) {
179
		public void dropAccept(DropTargetEvent event) {
Lines 153-209 Link Here
153
		}
181
		}
154
182
155
	}
183
	}
156
184
	
157
	private abstract class InternalSection {
185
	private abstract class ContentTypeElement {
158
186
		
159
		protected Group group;
187
		private Button radioButton;
160
		protected Text fileText;
188
		protected Button mainButton;
189
		protected Text text;
190
		private String type;
191
		protected InternalSection section;
161
		private IResource resource;
192
		private IResource resource;
162
193
		
163
		public InternalSection(Composite parent) {
194
		public ContentTypeElement(Composite parent, String type, InternalSection section) {
195
			this.type = type;
196
			this.section = section;
164
			createContents(parent);
197
			createContents(parent);
165
		}
198
		}
166
199
		
167
		private InternalSection() {
200
		private void createContents(Composite parent) {
168
			// not to instantiate
201
			createRadioButton(parent);
202
			createText(parent);
203
			createMainButton(parent);
204
		}
205
		
206
		private void createRadioButton(Composite parent) {
207
			radioButton = new Button(parent, SWT.RADIO);
208
			radioButton.setText(type);
209
		}
210
211
		protected void createText(Composite parent) {
212
			text = new Text(parent, SWT.BORDER);
213
			text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
214
			text.setEditable(false);
215
		}
216
		
217
		protected void createMainButton(Composite parent) {
218
			mainButton = new Button(parent, SWT.PUSH);
219
			mainButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
220
		}
221
		
222
		protected Button getRadioButton() {
223
			return radioButton;
224
		}
225
		
226
		protected String getText() {
227
			return text.getText();
228
		}
229
		
230
		protected void setText(String string) {
231
			text.setText(string);
232
		}
233
		
234
		protected InternalSection getSection() {
235
			return section;
236
		}
237
		
238
		protected void setEnabled(boolean enabled) {
239
			radioButton.setSelection(enabled);
240
			mainButton.setEnabled(enabled);
241
			text.setEnabled(enabled);
169
		}
242
		}
170
243
		
171
		public void createContents(Composite parent) {
244
		protected void setResource(IResource resource) {
172
			createGroup(parent);
245
			this.resource = resource;
173
			createFileLabel();
246
			section.setResource(resource);
174
			createFileCombo();
175
			initDrag();
176
			initDrop();
177
		}
247
		}
178
248
179
		public IResource getResource() {
249
		public IResource getResource() {
180
			return resource;
250
			return resource;
181
		}
251
		}
182
252
		
183
		public void setResource(IResource resource) {
253
		void clearResource() {
184
			this.resource = resource;
254
			resource = null;
185
			String txt = resource.getFullPath().toString();
255
			text.setText(""); //$NON-NLS-1$
186
			fileText.setText(txt);
187
		}
256
		}
257
		
258
	}
259
	
260
	private class WorkspaceContent extends ContentTypeElement {
261
		
262
		public WorkspaceContent(Composite parent, InternalSection section) {
263
			super(parent, CompareMessages.CompareWithOtherResourceDialog_workspaceRadioButton, section);
264
		}
265
		
266
		protected void createMainButton(Composite parent) {
267
			super.createMainButton(parent);
268
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_workspaceMainButton);
269
			// temporarily hide this button. For more information about supporting for browsing workspace see bug 243744.
270
			mainButton.setVisible(false);
271
		}
272
		
273
		protected void createText(Composite parent) {
274
			
275
			super.createText(parent);
276
			text.setEditable(true);
277
			
278
			text.addModifyListener(new ModifyListener() {
279
				public void modifyText(ModifyEvent e) {
280
					section.setResource(text.getText());
281
					updateErrorInfo();
282
				}
283
			});
188
284
189
		public void setResource(String s) {
285
			text.addSelectionListener(new SelectionListener() {
190
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
286
				public void widgetDefaultSelected(SelectionEvent e) {
191
					.findMember(s);
287
					widgetSelected(e);
192
			if (tmp instanceof IWorkspaceRoot)
288
				}
193
				resource = null;
289
				public void widgetSelected(SelectionEvent e) {
194
			else
290
					section.setResource(text.getText());
195
				resource = tmp;
291
					updateErrorInfo();
196
292
				}
293
			});
294
			
295
			initDrag();
296
			initDrop();
197
		}
297
		}
198
298
199
		protected void clearResource() {
299
		protected void setResource(IResource resource) {
200
			resource = null;
300
			super.setResource(resource);
201
			fileText.setText(""); //$NON-NLS-1$
301
			text.setText(resource.getFullPath().toOSString());
202
			updateErrorInfo();
203
		}
302
		}
204
303
205
		protected void initDrag() {
304
		protected void initDrag() {
206
			DragSource source = new DragSource(fileText, DND.DROP_MOVE
305
			DragSource source = new DragSource(text, DND.DROP_MOVE
207
					| DND.DROP_COPY | DND.DROP_DEFAULT);
306
					| DND.DROP_COPY | DND.DROP_DEFAULT);
208
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
307
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
209
					ResourceTransfer.getInstance() };
308
					ResourceTransfer.getInstance() };
Lines 212-260 Link Here
212
		}
311
		}
213
312
214
		protected void initDrop() {
313
		protected void initDrop() {
215
			DropTarget target = new DropTarget(fileText, DND.DROP_MOVE
314
			DropTarget target = new DropTarget(text, DND.DROP_MOVE
216
					| DND.DROP_COPY | DND.DROP_DEFAULT);
315
					| DND.DROP_COPY | DND.DROP_DEFAULT);
217
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
316
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
218
					ResourceTransfer.getInstance() };
317
					ResourceTransfer.getInstance() };
219
			target.setTransfer(types);
318
			target.setTransfer(types);
220
			target.addDropListener(new FileTextDropListener(this));
319
			target.addDropListener(new FileTextDropListener(this));
221
		}
320
		}
222
321
		
223
		protected void createGroup(Composite parent) {
322
	}
224
			group = new Group(parent, SWT.NONE);
323
	
225
			group.setLayout(new GridLayout(3, false));
324
	private class ExternalFileContent extends ContentTypeElement {
226
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
325
		
227
		}
326
		public ExternalFileContent(Composite parent, InternalSection section) {
228
327
			super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFileRadioButton, section);
229
		protected void createFileCombo() {
328
		}
230
			fileText = new Text(group, SWT.BORDER);
329
		
231
			fileText
330
		protected void createMainButton(Composite parent) {
232
					.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
331
			super.createMainButton(parent);
233
332
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFileMainButton);
234
			fileText.addModifyListener(new ModifyListener() {
333
			mainButton.addSelectionListener(new SelectionListener() {
235
				public void modifyText(ModifyEvent e) {
334
				public void widgetDefaultSelected(SelectionEvent e) {
236
					setResource(fileText.getText());
335
					widgetSelected(e);
237
					updateErrorInfo();
336
				}
337
				public void widgetSelected(SelectionEvent e) {
338
					IResource r = getExtenalFile();
339
					if (r == null) 
340
						return;
341
					setResource(r);
238
				}
342
				}
239
			});
343
			});
344
		}
240
345
241
			fileText.addSelectionListener(new SelectionListener() {
346
		protected void setResource(IResource resource) {
242
347
			super.setResource(resource);
348
			text.setText(resource.getLocation().toOSString());
349
		}
350
		
351
	}
352
	
353
	private class ExternalFolderContent extends ContentTypeElement {
354
		
355
		public ExternalFolderContent(Composite parent, InternalSection section) {
356
			super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFolderRadioButton, section);
357
		}
358
		
359
		protected void createMainButton(Composite parent) {
360
			super.createMainButton(parent);
361
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFolderMainButton);
362
			mainButton.addSelectionListener(new SelectionListener() {
243
				public void widgetDefaultSelected(SelectionEvent e) {
363
				public void widgetDefaultSelected(SelectionEvent e) {
244
					widgetSelected(e);
364
					widgetSelected(e);
245
				}
365
				}
246
247
				public void widgetSelected(SelectionEvent e) {
366
				public void widgetSelected(SelectionEvent e) {
248
					setResource(fileText.getText());
367
					IResource r = getExternalDirectory();
249
					updateErrorInfo();
368
					if (r == null)
369
						return;
370
					setResource(r);
250
				}
371
				}
251
252
			});
372
			});
253
		}
373
		}
254
374
255
		protected void createFileLabel() {
375
		protected void setResource(IResource resource) {
256
			final Label fileLabel = new Label(group, SWT.NONE);
376
			super.setResource(resource);
257
			fileLabel.setText(CompareMessages.CompareWithOther_fileLabel);
377
			text.setText(resource.getLocation().toOSString());
378
		}
379
		
380
	}
381
382
	private abstract class InternalSection {
383
		
384
		// there is no "enum" support in Java 1.4. Sigh...
385
		public static final int WORKSPACE = 0;
386
		public static final int EXTERNAL_FILE = 1;
387
		public static final int EXTERNAL_FOLDER = 2;
388
389
		protected Group group;
390
		private IResource resource;
391
		
392
		ExternalFileContent externalFileContent;
393
		ExternalFolderContent externalFolderContent;
394
		WorkspaceContent workspaceContent;
395
		
396
		public InternalSection(Composite parent) {
397
			createContents(parent);
398
		}
399
400
		private InternalSection() {
401
			// not to instantiate
402
		}
403
404
		protected void createContents(Composite parent) {
405
406
			group = new Group(parent, SWT.NONE);
407
			group.setLayout(new GridLayout(3, false));
408
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
409
			
410
			workspaceContent = new WorkspaceContent(group, this);
411
			externalFileContent = new ExternalFileContent(group, this);
412
			externalFolderContent = new ExternalFolderContent(group, this);
413
			
414
			addListenersToRadioButtons();
415
		}
416
		
417
		private void addListenersToRadioButtons() {
418
			final ContentTypeElement[] elements = new ContentTypeElement[] { workspaceContent, 
419
					externalFileContent, externalFolderContent };
420
			for (int i = 0; i < elements.length; i++)
421
				elements[i].getRadioButton().addListener(SWT.Selection, new Listener() {
422
					public void handleEvent(Event event) {
423
						for (int j = 0; j < elements.length; j++)
424
							if (event.widget != elements[j].getRadioButton())
425
								elements[j].setEnabled(false);
426
							else {
427
								elements[j].setEnabled(true);
428
								setResource(elements[j].getResource());
429
							}
430
					}
431
				});
432
		}
433
434
		protected IResource getResource() {
435
			return resource;
436
		}
437
438
		protected void setResource(IResource resource) {
439
			this.resource = resource;
440
			updateErrorInfo();
441
		}
442
443
		protected void setResource(String s) {
444
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
445
					.findMember(s);
446
			if (tmp instanceof IWorkspaceRoot) 
447
				resource = null;
448
			else 
449
				resource = tmp;
450
			updateErrorInfo();
451
		}
452
453
		protected void clearResource() {
454
			resource = null;
455
			workspaceContent.clearResource();
456
			externalFileContent.clearResource();
457
			externalFolderContent.clearResource();
458
			updateErrorInfo();
459
		}
460
		
461
		protected void setContentType(int type) {
462
			switch(type) {
463
			case WORKSPACE: 
464
				workspaceContent.setEnabled(true);
465
				externalFileContent.setEnabled(false);
466
				externalFolderContent.setEnabled(false);
467
				break;
468
			case EXTERNAL_FILE:
469
				workspaceContent.setEnabled(false);
470
				externalFileContent.setEnabled(true);
471
				externalFolderContent.setEnabled(false);
472
				break;
473
			case EXTERNAL_FOLDER:
474
				workspaceContent.setEnabled(false);
475
				externalFileContent.setEnabled(false);
476
				externalFolderContent.setEnabled(true);
477
			}
258
		}
478
		}
259
	}
479
	}
260
480
Lines 277-317 Link Here
277
497
278
		private ExpandableComposite expandable;
498
		private ExpandableComposite expandable;
279
		private Button clearButton;
499
		private Button clearButton;
500
		public boolean invalidAncestorResource = false;
280
501
281
		public InternalExpandable(Composite parent) {
502
		public InternalExpandable(Composite parent) {
282
			createContents(parent);
503
			createContents(parent);
283
		}
504
		}
284
505
285
		public void createContents(Composite parent) {
506
		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;
507
			final Composite p = parent;
296
			expandable = new ExpandableComposite(parent, SWT.NONE,
508
			expandable = new ExpandableComposite(parent, SWT.NONE,
297
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
509
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
298
			super.createGroup(expandable);
510
			super.createContents(expandable);
511
			createClearButton(group);
299
			expandable.setClient(group);
512
			expandable.setClient(group);
300
			expandable.addExpansionListener(new ExpansionAdapter() {
513
			expandable.addExpansionListener(new ExpansionAdapter() {
301
				public void expansionStateChanged(ExpansionEvent e) {
514
				public void expansionStateChanged(ExpansionEvent e) {
302
					p.layout();
515
					p.layout();
516
					getShell().pack();
303
				}
517
				}
304
			});
518
			});
305
		}
519
		}
306
520
307
		protected void createClearButton(Composite parent) {
521
		private void createClearButton(Composite parent) {
308
			clearButton = createButton(parent, CLEAR_RETURN_CODE,
522
			clearButton = new Button(parent, SWT.PUSH);
309
					CompareMessages.CompareWithOther_clear, false);
523
			clearButton.setText(CompareMessages.CompareWithOther_clear);
310
			clearButton.addSelectionListener(new SelectionListener() {
524
			clearButton.addSelectionListener(new SelectionListener() {
311
				public void widgetDefaultSelected(SelectionEvent e) {
525
				public void widgetDefaultSelected(SelectionEvent e) {
312
					widgetSelected(e);
526
					widgetSelected(e);
313
				}
527
				}
314
315
				public void widgetSelected(SelectionEvent e) {
528
				public void widgetSelected(SelectionEvent e) {
316
					clearResource();
529
					clearResource();
317
				}
530
				}
Lines 332-337 Link Here
332
	private InternalGroup rightPanel, leftPanel;
545
	private InternalGroup rightPanel, leftPanel;
333
	private InternalExpandable ancestorPanel;
546
	private InternalExpandable ancestorPanel;
334
	private ISelection fselection;
547
	private ISelection fselection;
548
	private int externalFilesCounter = 0;
335
549
336
	/**
550
	/**
337
	 * Creates the dialog.
551
	 * Creates the dialog.
Lines 403-432 Link Here
403
		IResource[] selectedResources = Utilities.getResources(selection);
617
		IResource[] selectedResources = Utilities.getResources(selection);
404
		switch (selectedResources.length) {
618
		switch (selectedResources.length) {
405
		case 1:
619
		case 1:
406
			leftPanel.setResource(selectedResources[0]);
620
			leftPanel.workspaceContent.setResource(selectedResources[0]);
407
			break;
621
			break;
408
		case 2:
622
		case 2:
409
			leftPanel.setResource(selectedResources[0]);
623
			leftPanel.workspaceContent.setResource(selectedResources[0]);
410
			rightPanel.setResource(selectedResources[1]);
624
			rightPanel.workspaceContent.setResource(selectedResources[1]);
411
			break;
625
			break;
412
		case 3:
626
		case 3:
413
			ancestorPanel.setResource(selectedResources[0]);
627
			ancestorPanel.workspaceContent.setResource(selectedResources[0]);
414
			ancestorPanel.expandable.setExpanded(true);
628
			ancestorPanel.expandable.setExpanded(true);
415
			leftPanel.setResource(selectedResources[1]);
629
			leftPanel.workspaceContent.setResource(selectedResources[1]);
416
			rightPanel.setResource(selectedResources[2]);
630
			rightPanel.workspaceContent.setResource(selectedResources[2]);
417
			break;
631
			break;
418
		}
632
		}
633
		setInitialContentTypes();
634
	}
635
636
	private void setInitialContentTypes() {
637
		ancestorPanel.setContentType(InternalSection.WORKSPACE);
638
		leftPanel.setContentType(InternalSection.WORKSPACE);
639
		rightPanel.setContentType(InternalSection.WORKSPACE);
419
	}
640
	}
420
641
421
	private boolean isComparePossible() {
642
	private boolean isComparePossible() {
422
		IResource[] resources;
643
		IResource[] resources;
423
		if (ancestorPanel.getResource() == null) {
644
		if (ancestorPanel.getResource() == null)
424
			resources = new IResource[] { leftPanel.getResource(),
645
			resources = new IResource[] { leftPanel.getResource(),
425
					rightPanel.getResource() };
646
					rightPanel.getResource() };
426
		} else {
647
		else
427
			resources = new IResource[] { ancestorPanel.getResource(),
648
			resources = new IResource[] { ancestorPanel.getResource(),
428
					leftPanel.getResource(), rightPanel.getResource() };
649
					leftPanel.getResource(), rightPanel.getResource() };
429
		}
430
650
431
		ResourceCompareInput r = new ResourceCompareInput(
651
		ResourceCompareInput r = new ResourceCompareInput(
432
				new CompareConfiguration());
652
				new CompareConfiguration());
Lines 440-450 Link Here
440
				setMessage(CompareMessages.CompareWithOther_error_empty,
660
				setMessage(CompareMessages.CompareWithOther_error_empty,
441
						IMessageProvider.ERROR);
661
						IMessageProvider.ERROR);
442
				okButton.setEnabled(false);
662
				okButton.setEnabled(false);
443
			} else if (ancestorPanel.getResource() == null
444
					&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$
445
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
446
						IMessageProvider.WARNING);
447
				okButton.setEnabled(true);
448
			} else if (!isComparePossible()) {
663
			} else if (!isComparePossible()) {
449
				setMessage(
664
				setMessage(
450
						CompareMessages.CompareWithOther_error_not_comparable,
665
						CompareMessages.CompareWithOther_error_not_comparable,
Lines 456-461 Link Here
456
			}
671
			}
457
		}
672
		}
458
	}
673
	}
674
	
675
	private IFile getExtenalFile() {
676
		FileDialog dialog = new FileDialog(getShell());
677
		String path = dialog.open();
678
		if (path != null)
679
			return (IFile) getResource(new Path(path), IResource.FILE);
680
		return null;
681
	}
682
683
	private IFolder getExternalDirectory() {
684
		DirectoryDialog dialog = new DirectoryDialog(getShell());
685
		String path = dialog.open();
686
		if (path != null)
687
			return (IFolder) getResource(new Path(path), IResource.FOLDER);
688
		return null;
689
	}
690
691
	private IResource getResource(IPath path, int type) {
692
		IResource r = null;
693
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
694
		IWorkspaceRoot root = workspace.getRoot();
695
		IProject project = root.getProject(TMP_PROJECT_NAME);
696
		String resourceName = path.lastSegment();
697
		try {
698
			project = createTmpProject();
699
			if (!project.isOpen())
700
				project.open(null);
701
			IFolder folderForExternal = project.getFolder(EXTERNAL_FILES_FOLDER_NAME);
702
			if (!folderForExternal.exists())
703
				folderForExternal.create(IResource.NONE, true, null);
704
			if (type == IResource.FILE) {
705
				r = folderForExternal.getFile(resourceName);
706
				if (r.exists()) { 	// add a number to file's name when there already is a file with that name in a folder
707
					String extension = path.getFileExtension();
708
					String newName = path.removeFileExtension().lastSegment(); 
709
					newName += "-" + externalFilesCounter + "." + extension; //$NON-NLS-1$ //$NON-NLS-2$
710
					r = folderForExternal.getFile(newName);
711
				}
712
				((IFile)r).createLink(path, IResource.REPLACE, null);
713
				externalFilesCounter++;
714
			}
715
			else {
716
				r = folderForExternal.getFolder(resourceName);
717
				if (r.exists()) {
718
					String newName = resourceName + "-" + externalFilesCounter; //$NON-NLS-1$
719
					r = folderForExternal.getFolder(newName);
720
				}
721
				((IFolder)r).createLink(path, IResource.REPLACE, null);
722
				externalFilesCounter++;
723
			}
724
		} catch (CoreException e) {
725
			CompareUIPlugin.log(e);
726
			MessageDialog.openError(getShell(),
727
							CompareMessages.CompareWithOther_externalFile_errorTitle,
728
							CompareMessages.CompareWithOther_externalFile_errorMessage);
729
		}
730
		return r;
731
	}
732
733
	/*
734
	 * (non-javadoc)
735
	 *
736
	 * Implementation based on org.eclipse.jdt.internal.core.ExternalFoldersManager#createExternalFoldersProject
737
	 */
738
	private IProject createTmpProject() throws CoreException {
739
		IProject tmpProject = getTmpProject();
740
		if (!tmpProject.isAccessible()) {
741
			try {
742
				if (!tmpProject.exists()) {
743
					IProjectDescription desc = tmpProject.getWorkspace()
744
							.newProjectDescription(tmpProject.getName());
745
					IPath location = CompareUI.getPlugin()
746
							.getStateLocation();
747
					desc.setLocation(location.append(TMP_PROJECT_NAME));
748
					tmpProject.create(desc, null);
749
				}
750
				try {
751
					tmpProject.open(null);
752
				} catch (CoreException e1) { // in case .project file or folder has been deleted
753
					IPath location1 = CompareUI.getPlugin()
754
							.getStateLocation();
755
					IPath projectPath1 = location1.append(TMP_PROJECT_NAME);
756
					projectPath1.toFile().mkdirs();
757
					FileOutputStream output = new FileOutputStream(
758
							projectPath1.append(".project").toOSString()); //$NON-NLS-1$
759
					try {
760
						output.write(TMP_PROJECT_FILE.getBytes());
761
					} finally {
762
						output.close();
763
					}
764
					tmpProject.open(null);
765
				}
766
			} catch (IOException ioe) {
767
				return tmpProject;
768
			} catch (CoreException ce) {
769
				throw new CoreException(ce.getStatus());
770
			}
771
		}
772
		return tmpProject;
773
	}
774
775
	/*
776
	 * (non-javadoc)
777
	 *
778
	 * Following method is analogical to org.eclipse.jdt.internal
779
	 */
780
	private IProject getTmpProject() {
781
		return ResourcesPlugin.getWorkspace().getRoot().getProject(
782
				TMP_PROJECT_NAME);
783
	}
459
784
460
	/**
785
	/**
461
	 * Returns table with selected resources. If any resource wasn't chosen in
786
	 * Returns table with selected resources. If any resource wasn't chosen in
Lines 477-480 Link Here
477
					rightResource };
802
					rightResource };
478
		return resources;
803
		return resources;
479
	}
804
	}
805
	
806
	/**
807
	 * Removes temporary files created from clipboard's content or imported to 
808
	 * workspace only for comparing.
809
	 */
810
	public static void cleanup() {
811
		try {
812
			IProject project = ResourcesPlugin.getWorkspace().getRoot()
813
					.getProject(TMP_PROJECT_NAME);
814
			project.delete(true, true, null);
815
		} catch (CoreException e) {
816
			CompareUIPlugin.log(e);
817
		}
818
	}
480
}
819
}
(-)compare/org/eclipse/compare/internal/ResourceCompareInput.java (+5 lines)
Lines 416-421 Link Here
416
	
416
	
417
	private String buildLabel(IResource r) {
417
	private String buildLabel(IResource r) {
418
		String n= r.getFullPath().toString();
418
		String n= r.getFullPath().toString();
419
		// if it is a file from outside a current workspace show its location 
420
		// rather than its workspace path
421
		if (n.startsWith(IPath.SEPARATOR + CompareWithOtherResourceDialog.TMP_PROJECT_NAME) || 
422
				n.startsWith(CompareWithOtherResourceDialog.TMP_PROJECT_NAME))
423
			return r.getLocation().toString();
419
		if (n.charAt(0) == IPath.SEPARATOR)
424
		if (n.charAt(0) == IPath.SEPARATOR)
420
			return n.substring(1);
425
			return n.substring(1);
421
		return n;
426
		return n;
(-)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 73923