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

Collapse All | Expand All

(-)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/CompareMessages.java (-1 / +11 lines)
Lines 118-125 Link Here
118
	public static String CompareWithOther_error_not_comparable;
118
	public static String CompareWithOther_error_not_comparable;
119
	public static String CompareWithOther_error_empty;
119
	public static String CompareWithOther_error_empty;
120
	public static String CompareWithOther_clear;
120
	public static String CompareWithOther_clear;
121
	public static String CompareWithOther_warning_two_way;
122
	public static String CompareWithOther_info;
121
	public static String CompareWithOther_info;
122
	public static String CompareWithOther_externalFileButton;
123
	public static String CompareWithOther_externalFile_errorTitle;
124
	public static String CompareWithOther_externalFile_errorMessage;
125
	public static String CompareWithOther_pathLabel;
126
	public static String CompareWithOther_externalFolderBUtton;
127
	public static String CompareWithOtherResourceDialog_externalFileMainButton;
128
	public static String CompareWithOtherResourceDialog_externalFileRadioButton;
129
	public static String CompareWithOtherResourceDialog_externalFolderMainButton;
130
	public static String CompareWithOtherResourceDialog_externalFolderRadioButton;
131
	public static String CompareWithOtherResourceDialog_workspaceMainButton;
132
	public static String CompareWithOtherResourceDialog_workspaceRadioButton;
123
133
124
	static {
134
	static {
125
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
135
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java (-105 / +443 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 282-317 Link Here
282
			createContents(parent);
502
			createContents(parent);
283
		}
503
		}
284
504
285
		public void createContents(Composite parent) {
505
		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;
506
			final Composite p = parent;
296
			expandable = new ExpandableComposite(parent, SWT.NONE,
507
			expandable = new ExpandableComposite(parent, SWT.NONE,
297
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
508
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
298
			super.createGroup(expandable);
509
			super.createContents(expandable);
510
			createClearButton(group);
299
			expandable.setClient(group);
511
			expandable.setClient(group);
300
			expandable.addExpansionListener(new ExpansionAdapter() {
512
			expandable.addExpansionListener(new ExpansionAdapter() {
301
				public void expansionStateChanged(ExpansionEvent e) {
513
				public void expansionStateChanged(ExpansionEvent e) {
302
					p.layout();
514
					p.layout();
515
					getShell().pack();
303
				}
516
				}
304
			});
517
			});
305
		}
518
		}
306
519
307
		protected void createClearButton(Composite parent) {
520
		private void createClearButton(Composite parent) {
308
			clearButton = createButton(parent, CLEAR_RETURN_CODE,
521
			clearButton = new Button(parent, SWT.PUSH);
309
					CompareMessages.CompareWithOther_clear, false);
522
			clearButton.setText(CompareMessages.CompareWithOther_clear);
310
			clearButton.addSelectionListener(new SelectionListener() {
523
			clearButton.addSelectionListener(new SelectionListener() {
311
				public void widgetDefaultSelected(SelectionEvent e) {
524
				public void widgetDefaultSelected(SelectionEvent e) {
312
					widgetSelected(e);
525
					widgetSelected(e);
313
				}
526
				}
314
315
				public void widgetSelected(SelectionEvent e) {
527
				public void widgetSelected(SelectionEvent e) {
316
					clearResource();
528
					clearResource();
317
				}
529
				}
Lines 332-337 Link Here
332
	private InternalGroup rightPanel, leftPanel;
544
	private InternalGroup rightPanel, leftPanel;
333
	private InternalExpandable ancestorPanel;
545
	private InternalExpandable ancestorPanel;
334
	private ISelection fselection;
546
	private ISelection fselection;
547
	private int externalFilesCounter = 0;
335
548
336
	/**
549
	/**
337
	 * Creates the dialog.
550
	 * Creates the dialog.
Lines 403-432 Link Here
403
		IResource[] selectedResources = Utilities.getResources(selection);
616
		IResource[] selectedResources = Utilities.getResources(selection);
404
		switch (selectedResources.length) {
617
		switch (selectedResources.length) {
405
		case 1:
618
		case 1:
406
			leftPanel.setResource(selectedResources[0]);
619
			leftPanel.workspaceContent.setResource(selectedResources[0]);
407
			break;
620
			break;
408
		case 2:
621
		case 2:
409
			leftPanel.setResource(selectedResources[0]);
622
			leftPanel.workspaceContent.setResource(selectedResources[0]);
410
			rightPanel.setResource(selectedResources[1]);
623
			rightPanel.workspaceContent.setResource(selectedResources[1]);
411
			break;
624
			break;
412
		case 3:
625
		case 3:
413
			ancestorPanel.setResource(selectedResources[0]);
626
			ancestorPanel.workspaceContent.setResource(selectedResources[0]);
414
			ancestorPanel.expandable.setExpanded(true);
627
			ancestorPanel.expandable.setExpanded(true);
415
			leftPanel.setResource(selectedResources[1]);
628
			leftPanel.workspaceContent.setResource(selectedResources[1]);
416
			rightPanel.setResource(selectedResources[2]);
629
			rightPanel.workspaceContent.setResource(selectedResources[2]);
417
			break;
630
			break;
418
		}
631
		}
632
		setInitialContentTypes();
633
	}
634
635
	private void setInitialContentTypes() {
636
		ancestorPanel.setContentType(InternalSection.WORKSPACE);
637
		leftPanel.setContentType(InternalSection.WORKSPACE);
638
		rightPanel.setContentType(InternalSection.WORKSPACE);
419
	}
639
	}
420
640
421
	private boolean isComparePossible() {
641
	private boolean isComparePossible() {
422
		IResource[] resources;
642
		IResource[] resources;
423
		if (ancestorPanel.getResource() == null) {
643
		if (ancestorPanel.getResource() == null)
424
			resources = new IResource[] { leftPanel.getResource(),
644
			resources = new IResource[] { leftPanel.getResource(),
425
					rightPanel.getResource() };
645
					rightPanel.getResource() };
426
		} else {
646
		else
427
			resources = new IResource[] { ancestorPanel.getResource(),
647
			resources = new IResource[] { ancestorPanel.getResource(),
428
					leftPanel.getResource(), rightPanel.getResource() };
648
					leftPanel.getResource(), rightPanel.getResource() };
429
		}
430
649
431
		ResourceCompareInput r = new ResourceCompareInput(
650
		ResourceCompareInput r = new ResourceCompareInput(
432
				new CompareConfiguration());
651
				new CompareConfiguration());
Lines 440-450 Link Here
440
				setMessage(CompareMessages.CompareWithOther_error_empty,
659
				setMessage(CompareMessages.CompareWithOther_error_empty,
441
						IMessageProvider.ERROR);
660
						IMessageProvider.ERROR);
442
				okButton.setEnabled(false);
661
				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()) {
662
			} else if (!isComparePossible()) {
449
				setMessage(
663
				setMessage(
450
						CompareMessages.CompareWithOther_error_not_comparable,
664
						CompareMessages.CompareWithOther_error_not_comparable,
Lines 456-461 Link Here
456
			}
670
			}
457
		}
671
		}
458
	}
672
	}
673
	
674
	private IFile getExtenalFile() {
675
		FileDialog dialog = new FileDialog(getShell());
676
		String path = dialog.open();
677
		if (path != null)
678
			return (IFile) getResource(new Path(path), IResource.FILE);
679
		return null;
680
	}
681
682
	private IFolder getExternalDirectory() {
683
		DirectoryDialog dialog = new DirectoryDialog(getShell());
684
		String path = dialog.open();
685
		if (path != null)
686
			return (IFolder) getResource(new Path(path), IResource.FOLDER);
687
		return null;
688
	}
689
690
	private IResource getResource(IPath path, int type) {
691
		IResource r = null;
692
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
693
		IWorkspaceRoot root = workspace.getRoot();
694
		IProject project = root.getProject(TMP_PROJECT_NAME);
695
		String resourceName = path.lastSegment();
696
		try {
697
			project = createTmpProject();
698
			if (!project.isOpen())
699
				project.open(null);
700
			IFolder folderForExternal = project.getFolder(EXTERNAL_FILES_FOLDER_NAME);
701
			if (!folderForExternal.exists())
702
				folderForExternal.create(IResource.NONE, true, null);
703
			if (type == IResource.FILE) {
704
				r = folderForExternal.getFile(resourceName);
705
				if (r.exists()) { 	// add a number to file's name when there already is a file with that name in a folder
706
					String extension = path.getFileExtension();
707
					String newName = path.removeFileExtension().lastSegment(); 
708
					newName += "-" + externalFilesCounter + "." + extension; //$NON-NLS-1$ //$NON-NLS-2$
709
					r = folderForExternal.getFile(newName);
710
				}
711
				((IFile)r).createLink(path, IResource.REPLACE, null);
712
				externalFilesCounter++;
713
			}
714
			else {
715
				r = folderForExternal.getFolder(resourceName);
716
				if (r.exists()) {
717
					String newName = resourceName + "-" + externalFilesCounter; //$NON-NLS-1$
718
					r = folderForExternal.getFolder(newName);
719
				}
720
				((IFolder)r).createLink(path, IResource.REPLACE, null);
721
				externalFilesCounter++;
722
			}
723
		} catch (CoreException e) {
724
			CompareUIPlugin.log(e);
725
			MessageDialog.openError(getShell(),
726
							CompareMessages.CompareWithOther_externalFile_errorTitle,
727
							CompareMessages.CompareWithOther_externalFile_errorMessage);
728
		}
729
		return r;
730
	}
731
732
	/*
733
	 * (non-javadoc)
734
	 *
735
	 * Implementation based on org.eclipse.jdt.internal.core.ExternalFoldersManager#createExternalFoldersProject
736
	 */
737
	private IProject createTmpProject() throws CoreException {
738
		IProject tmpProject = getTmpProject();
739
		if (!tmpProject.isAccessible()) {
740
			try {
741
				if (!tmpProject.exists()) {
742
					IProjectDescription desc = tmpProject.getWorkspace()
743
							.newProjectDescription(tmpProject.getName());
744
					IPath location = CompareUI.getPlugin()
745
							.getStateLocation();
746
					desc.setLocation(location.append(TMP_PROJECT_NAME));
747
					tmpProject.create(desc, null);
748
				}
749
				try {
750
					tmpProject.open(null);
751
				} catch (CoreException e1) { // in case .project file or folder has been deleted
752
					IPath location1 = CompareUI.getPlugin()
753
							.getStateLocation();
754
					IPath projectPath1 = location1.append(TMP_PROJECT_NAME);
755
					projectPath1.toFile().mkdirs();
756
					FileOutputStream output = new FileOutputStream(
757
							projectPath1.append(".project").toOSString()); //$NON-NLS-1$
758
					try {
759
						output.write(TMP_PROJECT_FILE.getBytes());
760
					} finally {
761
						output.close();
762
					}
763
					tmpProject.open(null);
764
				}
765
			} catch (IOException ioe) {
766
				return tmpProject;
767
			} catch (CoreException ce) {
768
				throw new CoreException(ce.getStatus());
769
			}
770
		}
771
		return tmpProject;
772
	}
773
774
	/*
775
	 * (non-javadoc)
776
	 *
777
	 * Following method is analogical to org.eclipse.jdt.internal
778
	 */
779
	private IProject getTmpProject() {
780
		return ResourcesPlugin.getWorkspace().getRoot().getProject(
781
				TMP_PROJECT_NAME);
782
	}
459
783
460
	/**
784
	/**
461
	 * Returns table with selected resources. If any resource wasn't chosen in
785
	 * Returns table with selected resources. If any resource wasn't chosen in
Lines 477-480 Link Here
477
					rightResource };
801
					rightResource };
478
		return resources;
802
		return resources;
479
	}
803
	}
804
	
805
	/**
806
	 * Removes temporary files created from clipboard's content or imported to 
807
	 * workspace only for comparing.
808
	 */
809
	public static void cleanup() {
810
		try {
811
			IProject project = ResourcesPlugin.getWorkspace().getRoot()
812
					.getProject(TMP_PROJECT_NAME);
813
			project.delete(true, true, null);
814
		} catch (CoreException e) {
815
			CompareUIPlugin.log(e);
816
		}
817
	}
480
}
818
}
(-)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 (-1 / +11 lines)
Lines 129-134 Link Here
129
CompareWithOther_dialogMessage=Select resources to compare
129
CompareWithOther_dialogMessage=Select resources to compare
130
CompareWithOther_error_not_comparable=Selected resources are not comparable.
130
CompareWithOther_error_not_comparable=Selected resources are not comparable.
131
CompareWithOther_error_empty=Both left and right panel must contain a valid path.
131
CompareWithOther_error_empty=Both left and right panel must contain a valid path.
132
CompareWithOther_warning_two_way=Ancestor is not a valid resource. Two-way compare will be performed.
133
CompareWithOther_clear=Clear
132
CompareWithOther_clear=Clear
134
CompareWithOther_info=Drag files from a view or between dialog's fields.
133
CompareWithOther_info=Drag files from a view or between dialog's fields.
134
CompareWithOther_externalFileButton=External file...
135
CompareWithOther_externalFolderBUtton=External folder...
136
CompareWithOther_externalFile_errorTitle=Compare With Other Resource Error
137
CompareWithOther_externalFile_errorMessage=Cannot create a link to an external file.
138
CompareWithOther_pathLabel=Path:
139
CompareWithOtherResourceDialog_externalFileMainButton=Browse...
140
CompareWithOtherResourceDialog_externalFileRadioButton=External file
141
CompareWithOtherResourceDialog_externalFolderMainButton=Browse...
142
CompareWithOtherResourceDialog_externalFolderRadioButton=External folder
143
CompareWithOtherResourceDialog_workspaceMainButton=Browse...
144
CompareWithOtherResourceDialog_workspaceRadioButton=Workspace

Return to bug 73923