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 (+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/CompareWithOtherResourceDialog.java (-101 / +441 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
	private 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-148 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
				element.setResource(files[0]);
146
			}
174
			}
147
175
148
			updateErrorInfo();
176
			updateErrorInfo();
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
		}
270
		
271
		protected void createText(Composite parent) {
272
			
273
			super.createText(parent);
274
			text.setEditable(true);
275
			
276
			text.addModifyListener(new ModifyListener() {
277
				public void modifyText(ModifyEvent e) {
278
					section.setResource(text.getText());
279
					updateErrorInfo();
280
				}
281
			});
188
282
189
		public void setResource(String s) {
283
			text.addSelectionListener(new SelectionListener() {
190
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
284
				public void widgetDefaultSelected(SelectionEvent e) {
191
					.findMember(s);
285
					widgetSelected(e);
192
			if (tmp instanceof IWorkspaceRoot)
286
				}
193
				resource = null;
287
				public void widgetSelected(SelectionEvent e) {
194
			else
288
					section.setResource(text.getText());
195
				resource = tmp;
289
					updateErrorInfo();
196
290
				}
291
			});
292
			
293
			initDrag();
294
			initDrop();
197
		}
295
		}
198
296
199
		protected void clearResource() {
297
		protected void setResource(IResource resource) {
200
			resource = null;
298
			super.setResource(resource);
201
			fileText.setText(""); //$NON-NLS-1$
299
			text.setText(resource.getFullPath().toOSString());
202
			updateErrorInfo();
203
		}
300
		}
204
301
205
		protected void initDrag() {
302
		protected void initDrag() {
206
			DragSource source = new DragSource(fileText, DND.DROP_MOVE
303
			DragSource source = new DragSource(text, DND.DROP_MOVE
207
					| DND.DROP_COPY | DND.DROP_DEFAULT);
304
					| DND.DROP_COPY | DND.DROP_DEFAULT);
208
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
305
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
209
					ResourceTransfer.getInstance() };
306
					ResourceTransfer.getInstance() };
Lines 212-260 Link Here
212
		}
309
		}
213
310
214
		protected void initDrop() {
311
		protected void initDrop() {
215
			DropTarget target = new DropTarget(fileText, DND.DROP_MOVE
312
			DropTarget target = new DropTarget(text, DND.DROP_MOVE
216
					| DND.DROP_COPY | DND.DROP_DEFAULT);
313
					| DND.DROP_COPY | DND.DROP_DEFAULT);
217
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
314
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
218
					ResourceTransfer.getInstance() };
315
					ResourceTransfer.getInstance() };
219
			target.setTransfer(types);
316
			target.setTransfer(types);
220
			target.addDropListener(new FileTextDropListener(this));
317
			target.addDropListener(new FileTextDropListener(this));
221
		}
318
		}
222
319
		
223
		protected void createGroup(Composite parent) {
320
	}
224
			group = new Group(parent, SWT.NONE);
321
	
225
			group.setLayout(new GridLayout(3, false));
322
	private class ExternalFileContent extends ContentTypeElement {
226
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
323
		
227
		}
324
		public ExternalFileContent(Composite parent, InternalSection section) {
228
325
			super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFileRadioButton, section);
229
		protected void createFileCombo() {
326
		}
230
			fileText = new Text(group, SWT.BORDER);
327
		
231
			fileText
328
		protected void createMainButton(Composite parent) {
232
					.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
329
			super.createMainButton(parent);
233
330
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFileMainButton);
234
			fileText.addModifyListener(new ModifyListener() {
331
			mainButton.addSelectionListener(new SelectionListener() {
235
				public void modifyText(ModifyEvent e) {
332
				public void widgetDefaultSelected(SelectionEvent e) {
236
					setResource(fileText.getText());
333
					widgetSelected(e);
237
					updateErrorInfo();
334
				}
335
				public void widgetSelected(SelectionEvent e) {
336
					IResource r = getExtenalFile();
337
					if (r == null) 
338
						return;
339
					setResource(r);
238
				}
340
				}
239
			});
341
			});
342
		}
240
343
241
			fileText.addSelectionListener(new SelectionListener() {
344
		protected void setResource(IResource resource) {
242
345
			super.setResource(resource);
346
			text.setText(resource.getLocation().toOSString());
347
		}
348
		
349
	}
350
	
351
	private class ExternalFolderContent extends ContentTypeElement {
352
		
353
		public ExternalFolderContent(Composite parent, InternalSection section) {
354
			super(parent, CompareMessages.CompareWithOtherResourceDialog_externalFolderRadioButton, section);
355
		}
356
		
357
		protected void createMainButton(Composite parent) {
358
			super.createMainButton(parent);
359
			mainButton.setText(CompareMessages.CompareWithOtherResourceDialog_externalFolderMainButton);
360
			mainButton.addSelectionListener(new SelectionListener() {
243
				public void widgetDefaultSelected(SelectionEvent e) {
361
				public void widgetDefaultSelected(SelectionEvent e) {
244
					widgetSelected(e);
362
					widgetSelected(e);
245
				}
363
				}
246
247
				public void widgetSelected(SelectionEvent e) {
364
				public void widgetSelected(SelectionEvent e) {
248
					setResource(fileText.getText());
365
					IResource r = getExternalDirectory();
249
					updateErrorInfo();
366
					if (r == null)
367
						return;
368
					setResource(r);
250
				}
369
				}
251
252
			});
370
			});
253
		}
371
		}
254
372
255
		protected void createFileLabel() {
373
		protected void setResource(IResource resource) {
256
			final Label fileLabel = new Label(group, SWT.NONE);
374
			super.setResource(resource);
257
			fileLabel.setText(CompareMessages.CompareWithOther_fileLabel);
375
			text.setText(resource.getLocation().toOSString());
376
		}
377
		
378
	}
379
380
	private abstract class InternalSection {
381
		
382
		// there is no "enum" support in Java 1.4. Sigh...
383
		public static final int WORKSPACE = 0;
384
		public static final int EXTERNAL_FILE = 1;
385
		public static final int EXTERNAL_FOLDER = 2;
386
387
		protected Group group;
388
		private IResource resource;
389
		
390
		ExternalFileContent externalFileContent;
391
		ExternalFolderContent externalFolderContent;
392
		WorkspaceContent workspaceContent;
393
		
394
		public InternalSection(Composite parent) {
395
			createContents(parent);
396
		}
397
398
		private InternalSection() {
399
			// not to instantiate
400
		}
401
402
		protected void createContents(Composite parent) {
403
404
			group = new Group(parent, SWT.NONE);
405
			group.setLayout(new GridLayout(3, false));
406
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
407
			
408
			workspaceContent = new WorkspaceContent(group, this);
409
			externalFileContent = new ExternalFileContent(group, this);
410
			externalFolderContent = new ExternalFolderContent(group, this);
411
			
412
			addListenersToRadioButtons();
413
		}
414
		
415
		private void addListenersToRadioButtons() {
416
			final ContentTypeElement[] elements = new ContentTypeElement[] { workspaceContent, 
417
					externalFileContent, externalFolderContent };
418
			for (int i = 0; i < elements.length; i++)
419
				elements[i].getRadioButton().addListener(SWT.Selection, new Listener() {
420
					public void handleEvent(Event event) {
421
						for (int j = 0; j < elements.length; j++)
422
							if (event.widget != elements[j].getRadioButton())
423
								elements[j].setEnabled(false);
424
							else {
425
								elements[j].setEnabled(true);
426
								setResource(elements[j].getResource());
427
							}
428
					}
429
				});
430
		}
431
432
		protected IResource getResource() {
433
			return resource;
434
		}
435
436
		protected void setResource(IResource resource) {
437
			this.resource = resource;
438
			updateErrorInfo();
439
		}
440
441
		protected void setResource(String s) {
442
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
443
					.findMember(s);
444
			if (tmp instanceof IWorkspaceRoot) 
445
				resource = null;
446
			else 
447
				resource = tmp;
448
			updateErrorInfo();
449
		}
450
451
		protected void clearResource() {
452
			resource = null;
453
			workspaceContent.clearResource();
454
			externalFileContent.clearResource();
455
			externalFolderContent.clearResource();
456
			updateErrorInfo();
457
		}
458
		
459
		protected void setContentType(int type) {
460
			switch(type) {
461
			case WORKSPACE: 
462
				workspaceContent.setEnabled(true);
463
				externalFileContent.setEnabled(false);
464
				externalFolderContent.setEnabled(false);
465
				break;
466
			case EXTERNAL_FILE:
467
				workspaceContent.setEnabled(false);
468
				externalFileContent.setEnabled(true);
469
				externalFolderContent.setEnabled(false);
470
				break;
471
			case EXTERNAL_FOLDER:
472
				workspaceContent.setEnabled(false);
473
				externalFileContent.setEnabled(false);
474
				externalFolderContent.setEnabled(true);
475
			}
258
		}
476
		}
259
	}
477
	}
260
478
Lines 282-317 Link Here
282
			createContents(parent);
500
			createContents(parent);
283
		}
501
		}
284
502
285
		public void createContents(Composite parent) {
503
		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;
504
			final Composite p = parent;
296
			expandable = new ExpandableComposite(parent, SWT.NONE,
505
			expandable = new ExpandableComposite(parent, SWT.NONE,
297
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
506
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
298
			super.createGroup(expandable);
507
			super.createContents(expandable);
508
			createClearButton(group);
299
			expandable.setClient(group);
509
			expandable.setClient(group);
300
			expandable.addExpansionListener(new ExpansionAdapter() {
510
			expandable.addExpansionListener(new ExpansionAdapter() {
301
				public void expansionStateChanged(ExpansionEvent e) {
511
				public void expansionStateChanged(ExpansionEvent e) {
302
					p.layout();
512
					p.layout();
513
					getShell().pack();
303
				}
514
				}
304
			});
515
			});
305
		}
516
		}
306
517
307
		protected void createClearButton(Composite parent) {
518
		private void createClearButton(Composite parent) {
308
			clearButton = createButton(parent, CLEAR_RETURN_CODE,
519
			clearButton = new Button(parent, SWT.PUSH);
309
					CompareMessages.CompareWithOther_clear, false);
520
			clearButton.setText(CompareMessages.CompareWithOther_clear);
310
			clearButton.addSelectionListener(new SelectionListener() {
521
			clearButton.addSelectionListener(new SelectionListener() {
311
				public void widgetDefaultSelected(SelectionEvent e) {
522
				public void widgetDefaultSelected(SelectionEvent e) {
312
					widgetSelected(e);
523
					widgetSelected(e);
313
				}
524
				}
314
315
				public void widgetSelected(SelectionEvent e) {
525
				public void widgetSelected(SelectionEvent e) {
316
					clearResource();
526
					clearResource();
317
				}
527
				}
Lines 332-337 Link Here
332
	private InternalGroup rightPanel, leftPanel;
542
	private InternalGroup rightPanel, leftPanel;
333
	private InternalExpandable ancestorPanel;
543
	private InternalExpandable ancestorPanel;
334
	private ISelection fselection;
544
	private ISelection fselection;
545
	private int externalFilesCounter = 0;
335
546
336
	/**
547
	/**
337
	 * Creates the dialog.
548
	 * Creates the dialog.
Lines 403-432 Link Here
403
		IResource[] selectedResources = Utilities.getResources(selection);
614
		IResource[] selectedResources = Utilities.getResources(selection);
404
		switch (selectedResources.length) {
615
		switch (selectedResources.length) {
405
		case 1:
616
		case 1:
406
			leftPanel.setResource(selectedResources[0]);
617
			leftPanel.workspaceContent.setResource(selectedResources[0]);
407
			break;
618
			break;
408
		case 2:
619
		case 2:
409
			leftPanel.setResource(selectedResources[0]);
620
			leftPanel.workspaceContent.setResource(selectedResources[0]);
410
			rightPanel.setResource(selectedResources[1]);
621
			rightPanel.workspaceContent.setResource(selectedResources[1]);
411
			break;
622
			break;
412
		case 3:
623
		case 3:
413
			ancestorPanel.setResource(selectedResources[0]);
624
			ancestorPanel.workspaceContent.setResource(selectedResources[0]);
414
			ancestorPanel.expandable.setExpanded(true);
625
			ancestorPanel.expandable.setExpanded(true);
415
			leftPanel.setResource(selectedResources[1]);
626
			leftPanel.workspaceContent.setResource(selectedResources[1]);
416
			rightPanel.setResource(selectedResources[2]);
627
			rightPanel.workspaceContent.setResource(selectedResources[2]);
417
			break;
628
			break;
418
		}
629
		}
630
		setInitialContentTypes();
631
	}
632
633
	private void setInitialContentTypes() {
634
		ancestorPanel.setContentType(InternalSection.WORKSPACE);
635
		leftPanel.setContentType(InternalSection.WORKSPACE);
636
		rightPanel.setContentType(InternalSection.WORKSPACE);
419
	}
637
	}
420
638
421
	private boolean isComparePossible() {
639
	private boolean isComparePossible() {
422
		IResource[] resources;
640
		IResource[] resources;
423
		if (ancestorPanel.getResource() == null) {
641
		if (ancestorPanel.getResource() == null)
424
			resources = new IResource[] { leftPanel.getResource(),
642
			resources = new IResource[] { leftPanel.getResource(),
425
					rightPanel.getResource() };
643
					rightPanel.getResource() };
426
		} else {
644
		else
427
			resources = new IResource[] { ancestorPanel.getResource(),
645
			resources = new IResource[] { ancestorPanel.getResource(),
428
					leftPanel.getResource(), rightPanel.getResource() };
646
					leftPanel.getResource(), rightPanel.getResource() };
429
		}
430
647
431
		ResourceCompareInput r = new ResourceCompareInput(
648
		ResourceCompareInput r = new ResourceCompareInput(
432
				new CompareConfiguration());
649
				new CompareConfiguration());
Lines 440-447 Link Here
440
				setMessage(CompareMessages.CompareWithOther_error_empty,
657
				setMessage(CompareMessages.CompareWithOther_error_empty,
441
						IMessageProvider.ERROR);
658
						IMessageProvider.ERROR);
442
				okButton.setEnabled(false);
659
				okButton.setEnabled(false);
443
			} else if (ancestorPanel.getResource() == null
660
			} else if (ancestorPanel.getResource() == null && isComparePossible()) {
444
					&& ancestorPanel.fileText.getText() != "") { //$NON-NLS-1$
445
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
661
				setMessage(CompareMessages.CompareWithOther_warning_two_way,
446
						IMessageProvider.WARNING);
662
						IMessageProvider.WARNING);
447
				okButton.setEnabled(true);
663
				okButton.setEnabled(true);
Lines 456-461 Link Here
456
			}
672
			}
457
		}
673
		}
458
	}
674
	}
675
	
676
	private IFile getExtenalFile() {
677
		FileDialog dialog = new FileDialog(getShell());
678
		String path = dialog.open();
679
		if (path != null)
680
			return (IFile) getResource(new Path(path), IResource.FILE);
681
		return null;
682
	}
683
684
	private IFolder getExternalDirectory() {
685
		DirectoryDialog dialog = new DirectoryDialog(getShell());
686
		String path = dialog.open();
687
		if (path != null)
688
			return (IFolder) getResource(new Path(path), IResource.FOLDER);
689
		return null;
690
	}
691
692
	private IResource getResource(IPath path, int type) {
693
		IResource r = null;
694
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
695
		IWorkspaceRoot root = workspace.getRoot();
696
		IProject project = root.getProject(TMP_PROJECT_NAME);
697
		String resourceName = path.lastSegment();
698
		try {
699
			project = createTmpProject();
700
			if (!project.isOpen())
701
				project.open(null);
702
			IFolder folderForExternal = project.getFolder(EXTERNAL_FILES_FOLDER_NAME);
703
			if (!folderForExternal.exists())
704
				folderForExternal.create(IResource.NONE, true, null);
705
			if (type == IResource.FILE) {
706
				r = folderForExternal.getFile(resourceName);
707
				if (r.exists()) { 	// add a number to file's name when there already is a file with that name in a folder
708
					String extension = path.getFileExtension();
709
					String newName = path.removeFileExtension().lastSegment(); 
710
					newName += "-" + externalFilesCounter + "." + extension; //$NON-NLS-1$ //$NON-NLS-2$
711
					r = folderForExternal.getFile(newName);
712
				}
713
				((IFile)r).createLink(path, IResource.REPLACE, null);
714
				externalFilesCounter++;
715
			}
716
			else {
717
				r = folderForExternal.getFolder(resourceName);
718
				if (r.exists()) {
719
					String newName = resourceName + "-" + externalFilesCounter; //$NON-NLS-1$
720
					r = folderForExternal.getFolder(newName);
721
				}
722
				((IFolder)r).createLink(path, IResource.REPLACE, null);
723
				externalFilesCounter++;
724
			}
725
		} catch (CoreException e) {
726
			CompareUIPlugin.log(e);
727
			MessageDialog.openError(getShell(),
728
							CompareMessages.CompareWithOther_externalFile_errorTitle,
729
							CompareMessages.CompareWithOther_externalFile_errorMessage);
730
		}
731
		return r;
732
	}
733
734
	/*
735
	 * (non-javadoc)
736
	 *
737
	 * Implementation based on org.eclipse.jdt.internal.core.ExternalFoldersManager#createExternalFoldersProject
738
	 */
739
	private IProject createTmpProject() throws CoreException {
740
		IProject tmpProject = getTmpProject();
741
		if (!tmpProject.isAccessible()) {
742
			try {
743
				if (!tmpProject.exists()) {
744
					IProjectDescription desc = tmpProject.getWorkspace()
745
							.newProjectDescription(tmpProject.getName());
746
					IPath location = CompareUI.getPlugin()
747
							.getStateLocation();
748
					desc.setLocation(location.append(TMP_PROJECT_NAME));
749
					tmpProject.create(desc, null);
750
				}
751
				try {
752
					tmpProject.open(null);
753
				} catch (CoreException e1) { // in case .project file or folder has been deleted
754
					IPath location1 = CompareUI.getPlugin()
755
							.getStateLocation();
756
					IPath projectPath1 = location1.append(TMP_PROJECT_NAME);
757
					projectPath1.toFile().mkdirs();
758
					FileOutputStream output = new FileOutputStream(
759
							projectPath1.append(".project").toOSString()); //$NON-NLS-1$
760
					try {
761
						output.write(TMP_PROJECT_FILE.getBytes());
762
					} finally {
763
						output.close();
764
					}
765
					tmpProject.open(null);
766
				}
767
			} catch (IOException ioe) {
768
				return tmpProject;
769
			} catch (CoreException ce) {
770
				throw new CoreException(ce.getStatus());
771
			}
772
		}
773
		return tmpProject;
774
	}
775
776
	/*
777
	 * (non-javadoc)
778
	 *
779
	 * Following method is analogical to org.eclipse.jdt.internal
780
	 */
781
	private IProject getTmpProject() {
782
		return ResourcesPlugin.getWorkspace().getRoot().getProject(
783
				TMP_PROJECT_NAME);
784
	}
459
785
460
	/**
786
	/**
461
	 * Returns table with selected resources. If any resource wasn't chosen in
787
	 * Returns table with selected resources. If any resource wasn't chosen in
Lines 477-480 Link Here
477
					rightResource };
803
					rightResource };
478
		return resources;
804
		return resources;
479
	}
805
	}
806
	
807
	/**
808
	 * Removes temporary files created from clipboard's content or imported to 
809
	 * workspace only for comparing.
810
	 */
811
	public static void cleanup() {
812
		try {
813
			IProject project = ResourcesPlugin.getWorkspace().getRoot()
814
					.getProject(TMP_PROJECT_NAME);
815
			project.delete(true, true, null);
816
		} catch (CoreException e) {
817
			CompareUIPlugin.log(e);
818
		}
819
	}
480
}
820
}
(-)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