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

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/CompareMessages.java (+3 lines)
Lines 118-123 Link Here
118
	public static String CompareWithOther_error_empty;
118
	public static String CompareWithOther_error_empty;
119
	public static String CompareWithOther_clearAll;
119
	public static String CompareWithOther_clearAll;
120
	public static String CompareWithOther_clear;
120
	public static String CompareWithOther_clear;
121
	public static String CompareWithOther_clipboard;
122
	public static String CompareWithOther_tmp_file_path;
123
	public static String CompareWithOther_clipboard_files;
121
124
122
	static {
125
	static {
123
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
126
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
(-)compare/org/eclipse/compare/internal/CompareMessages.properties (-1 / +4 lines)
Lines 127-132 Link Here
127
CompareWithOther_dialogTitle=Compare with Other Resource...
127
CompareWithOther_dialogTitle=Compare with Other Resource...
128
CompareWithOther_dialogMessage=Select resources to compare
128
CompareWithOther_dialogMessage=Select resources to compare
129
CompareWithOther_error_not_comparable=Selected resources are not comparable.
129
CompareWithOther_error_not_comparable=Selected resources are not comparable.
130
CompareWithOther_error_empty=Both left and right panel must not be empty.
130
CompareWithOther_error_empty=Both left and right panel must contain a valid path to resource from workspace. 
131
CompareWithOther_clearAll=Clear All
131
CompareWithOther_clearAll=Clear All
132
CompareWithOther_clear=Clear
132
CompareWithOther_clear=Clear
133
CompareWithOther_clipboard=From clipboard
134
CompareWithOther_tmp_file_path=clipboard
135
CompareWithOther_clipboard_files=ClipboardTmpFiles
(-)compare/org/eclipse/compare/internal/CompareAction.java (-31 / +6 lines)
Lines 19-25 Link Here
19
import org.eclipse.ui.IWorkbenchPart;
19
import org.eclipse.ui.IWorkbenchPart;
20
import org.eclipse.compare.CompareConfiguration;
20
import org.eclipse.compare.CompareConfiguration;
21
import org.eclipse.compare.CompareUI;
21
import org.eclipse.compare.CompareUI;
22
import org.eclipse.core.resources.IResource;
23
22
24
23
25
/*
24
/*
Lines 27-57 Link Here
27
 */
26
 */
28
public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
27
public class CompareAction extends BaseCompareAction implements IObjectActionDelegate {
29
28
30
	private static ResourceCompareInput fInput;
29
	private ResourceCompareInput fInput;
31
	private static IWorkbenchPage fWorkbenchPage;
30
	private IWorkbenchPage fWorkbenchPage;
31
32
32
33
	public void run(ISelection selection) {
33
	public void run(ISelection selection) {
34
		if (fInput != null) {
34
		if (fInput != null) {
35
			// Pass the shell so setSelection can prompt the user for which
35
			// Pass the shell so setSelection can prompt the user for which
36
			// resource should be the ancestor
36
			// resource should be the ancestor
37
			boolean ok = fInput.setSelection(selection, fWorkbenchPage
37
			boolean ok = fInput.setSelection(selection,
38
					.getWorkbenchWindow().getShell());
38
				fWorkbenchPage.getWorkbenchWindow().getShell());
39
			if (!ok)
39
			if (!ok) return;
40
				return;
41
			fInput.initializeCompareConfiguration();
42
			CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
43
			fInput = null; // don't reuse this input!
44
		}
45
	}
46
47
	public static void run(IResource[] resources) {
48
		fWorkbenchPage = CompareUIPlugin.getActiveWorkbench()
49
				.getActiveWorkbenchWindow().getActivePage();
50
		if (fInput != null) {
51
			boolean ok = fInput.setSelection(resources, fWorkbenchPage
52
					.getWorkbenchWindow().getShell());
53
			if (!ok)
54
				return;
55
			fInput.initializeCompareConfiguration();
40
			fInput.initializeCompareConfiguration();
56
			CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
41
			CompareUI.openCompareEditorOnPage(fInput, fWorkbenchPage);
57
			fInput= null;	// don't reuse this input!
42
			fInput= null;	// don't reuse this input!
Lines 73-88 Link Here
73
		return fInput.isEnabled(selection);
58
		return fInput.isEnabled(selection);
74
	}
59
	}
75
60
76
	public static boolean isEnabled(IResource[] resources) {
77
		if (fInput == null) {
78
			CompareConfiguration cc = new CompareConfiguration();
79
			cc.setProperty(CompareEditor.CONFIRM_SAVE_PROPERTY, new Boolean(
80
					false));
81
			fInput = new ResourceCompareInput(cc);
82
		}
83
		return fInput.isEnabled(resources);
84
	}
85
86
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
61
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
87
		fWorkbenchPage= targetPart.getSite().getPage();
62
		fWorkbenchPage= targetPart.getSite().getPage();
88
	}
63
	}
(-)compare/org/eclipse/compare/internal/Messages.java (-33 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
12
13
import com.ibm.icu.text.MessageFormat;
14
15
/**
16
 * Helper class to format message strings.
17
 * 
18
 * @since 3.1
19
 */
20
public class Messages {
21
22
	public static String format(String message, Object object) {
23
		return MessageFormat.format(message, new Object[] { object});
24
	}
25
26
	public static String format(String message, Object[] objects) {
27
		return MessageFormat.format(message, objects);
28
	}
29
30
	private Messages() {
31
		// Not for instantiation
32
	}
33
}
(-)compare/org/eclipse/compare/internal/ResourceCompareInput.java (-22 / +14 lines)
Lines 201-214 Link Here
201
	// to use as the ancestor.  Returns false if the user cancels the prompt,
201
	// to use as the ancestor.  Returns false if the user cancels the prompt,
202
	// true otherwise.
202
	// true otherwise.
203
	boolean setSelection(ISelection s, Shell shell) {
203
	boolean setSelection(ISelection s, Shell shell) {
204
		IResource[] selection = Utilities.getResources(s);
204
		
205
		return setSelection(selection, shell);
205
		IResource[] selection= Utilities.getResources(s);
206
	}
207
208
	boolean setSelection(IResource[] selection, Shell shell) {
209
210
		fThreeWay = selection.length == 3;
211
206
207
		fThreeWay= selection.length == 3;
208
		
212
		if (fThreeWay) {
209
		if (fThreeWay) {
213
			SelectAncestorDialog dialog =
210
			SelectAncestorDialog dialog =
214
				new SelectAncestorDialog(shell, selection);
211
				new SelectAncestorDialog(shell, selection);
Lines 236-261 Link Here
236
	 * Returns true if compare can be executed for the given selection.
233
	 * Returns true if compare can be executed for the given selection.
237
	 */
234
	 */
238
	public boolean isEnabled(ISelection s) {
235
	public boolean isEnabled(ISelection s) {
239
236
		
240
		IResource[] selection = Utilities.getResources(s);
237
		IResource[] selection= Utilities.getResources(s);
241
		return isEnabled(selection);
238
		if (selection.length < 2 || selection.length > 3)
242
	}
243
244
	public boolean isEnabled(IResource[] resources) {
245
		if (resources.length < 2 || resources.length > 3)
246
			return false;
239
			return false;
247
240
248
		boolean threeWay= resources.length == 3;
241
		boolean threeWay= selection.length == 3;
249
		
242
		
250
		if (threeWay) {
243
		if (threeWay)
251
			// It only makes sense if they're all mutually comparable.
244
			// It only makes sense if they're all mutually comparable.
252
			// If not, the user should compare two of them.
245
			// If not, the user should compare two of them.
253
			return comparable(resources[0], resources[1])
246
			return comparable(selection[0], selection[1])
254
					&& comparable(resources[0], resources[2])
247
				&& comparable(selection[0], selection[2])
255
					&& comparable(resources[1], resources[2]);
248
				&& comparable(selection[1], selection[2]);
256
		}
249
		
257
250
		return comparable(selection[0], selection[1]);
258
		return comparable(resources[0], resources[1]);
259
	}
251
	}
260
	
252
	
261
	/**
253
	/**
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceAction.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Aleksandra Wozniak and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
12
13
import org.eclipse.core.resources.IResource;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.dialogs.IDialogConstants;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.swt.widgets.Shell;
19
import org.eclipse.ui.IObjectActionDelegate;
20
import org.eclipse.ui.IWorkbenchPart;
21
import org.eclipse.ui.PlatformUI;
22
23
/**
24
 * The "Compare with other resource" action
25
 * 
26
 * @since 3.4
27
 */
28
public class CompareWithOtherResourceAction implements IObjectActionDelegate {
29
30
	Shell shell;
31
	CompareWithOtherResourceDialog dialog;
32
	private ISelection fselection;
33
	private IWorkbenchPart fWorkbenchPart;
34
35
	public CompareWithOtherResourceAction() {
36
		shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
37
	}
38
39
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
40
		fWorkbenchPart = targetPart;
41
	}
42
43
	public void run(IAction action) {
44
		dialog = new CompareWithOtherResourceDialog(shell, fselection);
45
		int returnCode = dialog.open();
46
		
47
		if (returnCode == IDialogConstants.OK_ID) {
48
			IResource[] resources = dialog.getResult();
49
			StructuredSelection ss = new StructuredSelection(resources);
50
			CompareAction ca = new CompareAction();
51
			ca.setActivePart(null, fWorkbenchPart);
52
			if (ca.isEnabled(ss))
53
				ca.run(ss);
54
		}
55
	}
56
57
	public void selectionChanged(IAction action, ISelection selection) {
58
		fselection = selection;
59
	}
60
61
}
(-)compare/org/eclipse/compare/internal/CompareWithOtherResourceDialog.java (+483 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Aleksandra Wozniak and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Aleksandra Wozniak (aleksandra.k.wozniak@gmail.com) - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
12
13
import org.eclipse.compare.CompareConfiguration;
14
import org.eclipse.core.resources.IResource;
15
import org.eclipse.core.resources.IWorkspaceRoot;
16
import org.eclipse.core.resources.ResourcesPlugin;
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.dialogs.IMessageProvider;
19
import org.eclipse.jface.dialogs.TitleAreaDialog;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.dnd.DND;
24
import org.eclipse.swt.dnd.DragSource;
25
import org.eclipse.swt.dnd.DragSourceEvent;
26
import org.eclipse.swt.dnd.DragSourceListener;
27
import org.eclipse.swt.dnd.DropTarget;
28
import org.eclipse.swt.dnd.DropTargetEvent;
29
import org.eclipse.swt.dnd.DropTargetListener;
30
import org.eclipse.swt.dnd.TextTransfer;
31
import org.eclipse.swt.dnd.Transfer;
32
import org.eclipse.swt.events.ModifyEvent;
33
import org.eclipse.swt.events.ModifyListener;
34
import org.eclipse.swt.events.SelectionEvent;
35
import org.eclipse.swt.events.SelectionListener;
36
import org.eclipse.swt.layout.GridData;
37
import org.eclipse.swt.layout.GridLayout;
38
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Control;
42
import org.eclipse.swt.widgets.Group;
43
import org.eclipse.swt.widgets.Label;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.ui.forms.events.ExpansionAdapter;
46
import org.eclipse.ui.forms.events.ExpansionEvent;
47
import org.eclipse.ui.forms.widgets.ExpandableComposite;
48
import org.eclipse.ui.part.ResourceTransfer;
49
50
/**
51
 * This is a dialog that can invoke the compare editor on chosen files.
52
 * <p>
53
 * This class can be used as is or can be subclassed.
54
 * 
55
 * @since 3.4
56
 */
57
public class CompareWithOtherResourceDialog extends TitleAreaDialog {
58
59
	private int CLEAR_RETURN_CODE = 150; // any number != 0
60
61
	private class FileTextDragListener implements DragSourceListener {
62
63
		private InternalSection section;
64
65
		public FileTextDragListener(InternalSection section) {
66
			this.section = section;
67
		}
68
69
		public void dragFinished(DragSourceEvent event) {
70
			section.fileCombo.setText(""); //$NON-NLS-1$
71
		}
72
73
		public void dragSetData(DragSourceEvent event) {
74
			if (TextTransfer.getInstance().isSupportedType(event.dataType))
75
				event.data = section.fileCombo.getText();
76
		}
77
78
		public void dragStart(DragSourceEvent event) {
79
			if (section.fileCombo.getText() == null)
80
				event.doit = false;
81
		}
82
	}
83
84
	private class FileTextDropListener implements DropTargetListener {
85
86
		private InternalSection section;
87
		private ResourceTransfer resourceTransfer;
88
		private TextTransfer textTransfer;
89
90
		public FileTextDropListener(InternalSection section) {
91
			this.section = section;
92
			resourceTransfer = ResourceTransfer.getInstance();
93
			textTransfer = TextTransfer.getInstance();
94
		}
95
96
		public void dragEnter(DropTargetEvent event) {
97
98
			if (event.detail == DND.DROP_DEFAULT) {
99
				if ((event.operations & DND.DROP_COPY) != 0)
100
					event.detail = DND.DROP_COPY;
101
				else
102
					event.detail = DND.DROP_NONE;
103
			}
104
105
			for (int i = 0; i < event.dataTypes.length; i++) {
106
				if (resourceTransfer.isSupportedType(event.dataTypes[i])) {
107
					event.currentDataType = event.dataTypes[i];
108
					if (event.detail != DND.DROP_COPY)
109
						event.detail = DND.DROP_NONE;
110
					break;
111
				}
112
			}
113
		}
114
115
		public void dragLeave(DropTargetEvent event) {
116
			// intentionally empty
117
		}
118
119
		public void dragOperationChanged(DropTargetEvent event) {
120
121
			if (event.detail == DND.DROP_DEFAULT) {
122
				if ((event.operations & DND.DROP_COPY) != 0)
123
					event.detail = DND.DROP_COPY;
124
				else
125
					event.detail = DND.DROP_NONE;
126
			} else if (resourceTransfer.isSupportedType(event.currentDataType)) {
127
				if (event.detail != DND.DROP_COPY)
128
					event.detail = DND.DROP_NONE;
129
			}
130
		}
131
132
		public void dragOver(DropTargetEvent event) {
133
			// intentionally empty
134
		}
135
136
		public void drop(DropTargetEvent event) {
137
138
			if (textTransfer.isSupportedType(event.currentDataType)) {
139
				String txt = (String) event.data;
140
				section.setResource(ResourcesPlugin.getWorkspace().getRoot()
141
						.findMember(txt));
142
			} else if (resourceTransfer.isSupportedType(event.currentDataType)) {
143
				IResource[] files = (IResource[]) event.data;
144
				section.setResource(files[0]);
145
			}
146
147
			updateErrorInfo();
148
		}
149
150
		public void dropAccept(DropTargetEvent event) {
151
			// intentionally empty
152
		}
153
154
	}
155
156
	private abstract class InternalSection {
157
158
		protected Group group;
159
		private Combo fileCombo;
160
		private IResource resource;
161
		private Button clearButton;
162
163
		public InternalSection(Composite parent) {
164
			createContents(parent);
165
		}
166
167
		public InternalSection() {
168
			// not to instantiate
169
		}
170
171
		public void createContents(Composite parent) {
172
			createGroup(parent);
173
			createFileLabel();
174
			createFileCombo();
175
			createClearButton(group);
176
			initDrag();
177
			initDrop();
178
		}
179
180
		public IResource getResource() {
181
			return resource;
182
		}
183
184
		public void setResource(IResource resource) {
185
			this.resource = resource;
186
			String txt = resource.getFullPath().toString();
187
			fileCombo.add(txt);
188
			fileCombo.setText(txt);
189
		}
190
191
		public void setResource(String s) {
192
			IResource tmp = ResourcesPlugin.getWorkspace().getRoot()
193
					.findMember(s);
194
			if (tmp instanceof IWorkspaceRoot)
195
				resource = null;
196
			else
197
				resource = tmp;
198
199
		}
200
201
		protected void clearResource() {
202
			resource = null;
203
			fileCombo.setText(""); //$NON-NLS-1$
204
			updateErrorInfo();
205
		}
206
207
		protected void initDrag() {
208
			DragSource source = new DragSource(fileCombo, DND.DROP_MOVE
209
					| DND.DROP_COPY);
210
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
211
					ResourceTransfer.getInstance() };
212
			source.setTransfer(types);
213
			source.addDragListener(new FileTextDragListener(this));
214
		}
215
216
		protected void initDrop() {
217
			DropTarget target = new DropTarget(fileCombo, DND.DROP_MOVE
218
					| DND.DROP_COPY | DND.DROP_DEFAULT);
219
			Transfer[] types = new Transfer[] { TextTransfer.getInstance(),
220
					ResourceTransfer.getInstance() };
221
			target.setTransfer(types);
222
			target.addDropListener(new FileTextDropListener(this));
223
		}
224
225
		protected void createGroup(Composite parent) {
226
			group = new Group(parent, SWT.NONE);
227
			group.setLayout(new GridLayout(3, false));
228
			group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
229
		}
230
231
		protected void createFileCombo() {
232
			fileCombo = new Combo(group, SWT.NONE);
233
			fileCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
234
					false));
235
			fileCombo.setItems(new String[] { "" }); //$NON-NLS-1$
236
			fileCombo.setText(fileCombo.getItem(0));
237
238
			fileCombo.addModifyListener(new ModifyListener() {
239
				public void modifyText(ModifyEvent e) {
240
					setResource(fileCombo.getText());
241
					updateErrorInfo();
242
				}
243
			});
244
245
			fileCombo.addSelectionListener(new SelectionListener() {
246
247
				public void widgetDefaultSelected(SelectionEvent e) {
248
					widgetSelected(e);
249
				}
250
251
				public void widgetSelected(SelectionEvent e) {
252
					setResource(fileCombo.getText());
253
					updateErrorInfo();
254
				}
255
256
			});
257
		}
258
259
		protected void createFileLabel() {
260
			final Label fileLabel = new Label(group, SWT.NONE);
261
			fileLabel.setText(CompareMessages.CompareWithOther_fileLabel);
262
		}
263
264
		protected void createClearButton(Composite parent) {
265
			clearButton = createButton(parent, CLEAR_RETURN_CODE,
266
					CompareMessages.CompareWithOther_clear, false);
267
			clearButton.addSelectionListener(new SelectionListener() {
268
				public void widgetDefaultSelected(SelectionEvent e) {
269
					widgetSelected(e);
270
				}
271
272
				public void widgetSelected(SelectionEvent e) {
273
					clearResource();
274
				}
275
			});
276
		}
277
	}
278
279
	private class InternalGroup extends InternalSection {
280
281
		public InternalGroup(Composite parent) {
282
			createContents(parent);
283
		}
284
285
		public void setText(String text) {
286
			group.setText(text);
287
		}
288
289
		public void setLayoutData(GridData layoutData) {
290
			group.setLayoutData(layoutData);
291
		}
292
	}
293
294
	private class InternalExpandable extends InternalSection {
295
296
		private ExpandableComposite expandable;
297
298
		public InternalExpandable(Composite parent) {
299
			createContents(parent);
300
		}
301
302
		public void createGroup(Composite parent) {
303
			final Composite p = parent;
304
			expandable = new ExpandableComposite(parent, SWT.NONE,
305
					ExpandableComposite.TREE_NODE | ExpandableComposite.TWISTIE);
306
			super.createGroup(expandable);
307
			expandable.setClient(group);
308
			expandable.addExpansionListener(new ExpansionAdapter() {
309
				public void expansionStateChanged(ExpansionEvent e) {
310
					p.getShell().pack();
311
				}
312
			});
313
		}
314
315
		public void setText(String text) {
316
			expandable.setText(text);
317
			group.setText(text);
318
		}
319
320
		public void setLayoutData(GridData layoutData) {
321
			expandable.setLayoutData(layoutData);
322
		}
323
	}
324
325
	private Button okButton, clearAllButton;
326
	private InternalGroup rightPanel, leftPanel;
327
	private InternalExpandable ancestorPanel;
328
	private ISelection fselection;
329
330
	/**
331
	 * Creates the dialog.
332
	 * 
333
	 * @param shell
334
	 *            a shell
335
	 * @param selection
336
	 *            if the selection is not null, it will be set as initial files
337
	 *            for comparison
338
	 * @since 3.4
339
	 */
340
	protected CompareWithOtherResourceDialog(Shell shell, ISelection selection) {
341
		super(shell);
342
		setShellStyle(SWT.MODELESS | SWT.RESIZE | SWT.MAX);
343
		fselection = selection;
344
	}
345
346
	/*
347
	 * (non-Javadoc)
348
	 * 
349
	 * @see
350
	 * org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets
351
	 * .Composite)
352
	 */
353
	protected Control createDialogArea(Composite parent) {
354
355
		Composite mainPanel = new Composite(parent, SWT.NULL);
356
		mainPanel.setLayout(new GridLayout(2, true));
357
		mainPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
358
359
		ancestorPanel = new InternalExpandable(mainPanel);
360
		ancestorPanel.setText(CompareMessages.CompareWithOther_ancestor);
361
		GridData ancestorGD = new GridData(SWT.FILL, SWT.FILL, true, true);
362
		ancestorGD.horizontalSpan = 2;
363
		ancestorPanel.setLayoutData(ancestorGD);
364
365
		rightPanel = new InternalGroup(mainPanel);
366
		rightPanel.setText(CompareMessages.CompareWithOther_rightPanel);
367
		rightPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
368
369
		leftPanel = new InternalGroup(mainPanel);
370
		leftPanel.setText(CompareMessages.CompareWithOther_leftPanel);
371
		leftPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
372
373
		setSelection(fselection);
374
		getShell().setText(CompareMessages.CompareWithOther_dialogTitle);
375
		setTitle(CompareMessages.CompareWithOther_dialogMessage);
376
377
		return mainPanel;
378
	}
379
380
	/*
381
	 * (non-Javadoc)
382
	 * 
383
	 * @see
384
	 * org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse
385
	 * .swt.widgets.Composite)
386
	 */
387
	protected void createButtonsForButtonBar(Composite parent) {
388
389
		super.createButtonsForButtonBar(parent);
390
		okButton = getButton(IDialogConstants.OK_ID);
391
392
		clearAllButton = createButton(parent, CLEAR_RETURN_CODE,
393
				CompareMessages.CompareWithOther_clearAll, false);
394
		clearAllButton.addSelectionListener(new SelectionListener() {
395
			public void widgetDefaultSelected(SelectionEvent e) {
396
				widgetSelected(e);
397
			}
398
399
			public void widgetSelected(SelectionEvent e) {
400
				leftPanel.clearResource();
401
				rightPanel.clearResource();
402
				ancestorPanel.clearResource();
403
			}
404
		});
405
406
		updateErrorInfo();
407
	}
408
409
	private void setSelection(ISelection selection) {
410
		IResource[] selectedResources = Utilities.getResources(selection);
411
		switch (selectedResources.length) {
412
		case 0:
413
			break;
414
		case 1:
415
			leftPanel.setResource(selectedResources[0]);
416
			break;
417
		case 2:
418
			leftPanel.setResource(selectedResources[0]);
419
			rightPanel.setResource(selectedResources[1]);
420
			break;
421
		case 3:
422
			ancestorPanel.setResource(selectedResources[0]);
423
			ancestorPanel.expandable.setExpanded(true);
424
			leftPanel.setResource(selectedResources[1]);
425
			rightPanel.setResource(selectedResources[2]);
426
			break;
427
		}
428
	}
429
430
	private boolean comparePossible() {
431
		IResource[] resources;
432
		if (ancestorPanel.getResource() == null)
433
			resources = new IResource[] { leftPanel.getResource(),
434
					rightPanel.getResource() };
435
		else
436
			resources = new IResource[] { ancestorPanel.getResource(),
437
					leftPanel.getResource(), rightPanel.getResource() };
438
439
		ResourceCompareInput r = new ResourceCompareInput(
440
				new CompareConfiguration());
441
		return r.isEnabled(new StructuredSelection(resources));
442
	}
443
444
	private void updateErrorInfo() {
445
		if (okButton != null) {
446
			if (leftPanel.getResource() == null
447
					|| rightPanel.getResource() == null) {
448
				setMessage(CompareMessages.CompareWithOther_error_empty,
449
						IMessageProvider.ERROR);
450
				okButton.setEnabled(false);
451
			} else if (!comparePossible()) {
452
				setMessage(
453
						CompareMessages.CompareWithOther_error_not_comparable,
454
						IMessageProvider.ERROR);
455
				okButton.setEnabled(false);
456
			} else {
457
				setMessage(null);
458
				okButton.setEnabled(true);
459
			}
460
		}
461
	}
462
463
	/**
464
	 * Returns table with selected resources. If any resource wasn't chosen in
465
	 * the ancestor panel, table has only two elements -- resources chosen in
466
	 * left and right panel. In the other case table contains all three
467
	 * resources.
468
	 * 
469
	 * @return table with selected resources
470
	 */
471
	public IResource[] getResult() {
472
		IResource[] resources;
473
		IResource rightResource = rightPanel.getResource();
474
		IResource leftResource = leftPanel.getResource();
475
		IResource ancestorResource = ancestorPanel.getResource();
476
		if (ancestorResource == null)
477
			resources = new IResource[] { leftResource, rightResource };
478
		else
479
			resources = new IResource[] { ancestorResource, leftResource,
480
					rightResource };
481
		return resources;
482
	}
483
}

Return to bug 240298