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

Collapse All | Expand All

(-)compare/org/eclipse/compare/CompareEditorInput.java (-29 lines)
Lines 12-20 Link Here
12
12
13
import java.lang.reflect.InvocationTargetException;
13
import java.lang.reflect.InvocationTargetException;
14
import java.util.ArrayList;
14
import java.util.ArrayList;
15
import java.util.HashSet;
16
import java.util.ResourceBundle;
15
import java.util.ResourceBundle;
17
import java.util.Set;
18
16
19
import org.eclipse.compare.contentmergeviewer.IFlushable;
17
import org.eclipse.compare.contentmergeviewer.IFlushable;
20
import org.eclipse.compare.internal.BinaryCompareViewer;
18
import org.eclipse.compare.internal.BinaryCompareViewer;
Lines 24-30 Link Here
24
import org.eclipse.compare.internal.CompareMessages;
22
import org.eclipse.compare.internal.CompareMessages;
25
import org.eclipse.compare.internal.ComparePreferencePage;
23
import org.eclipse.compare.internal.ComparePreferencePage;
26
import org.eclipse.compare.internal.CompareUIPlugin;
24
import org.eclipse.compare.internal.CompareUIPlugin;
27
import org.eclipse.compare.internal.ICompareAsText;
28
import org.eclipse.compare.internal.ICompareUIConstants;
25
import org.eclipse.compare.internal.ICompareUIConstants;
29
import org.eclipse.compare.internal.OutlineViewerCreator;
26
import org.eclipse.compare.internal.OutlineViewerCreator;
30
import org.eclipse.compare.internal.Utilities;
27
import org.eclipse.compare.internal.Utilities;
Lines 204-210 Link Here
204
201
205
	private String fHelpContextId;
202
	private String fHelpContextId;
206
	private InternalOutlineViewerCreator fOutlineView;
203
	private InternalOutlineViewerCreator fOutlineView;
207
	private ICompareAsText fCompareAsText;
208
	private ViewerDescriptor vd;
204
	private ViewerDescriptor vd;
209
	
205
	
210
	private class InternalOutlineViewerCreator extends OutlineViewerCreator {
206
	private class InternalOutlineViewerCreator extends OutlineViewerCreator {
Lines 238-249 Link Here
238
			return null;
234
			return null;
239
		}
235
		}
240
	}
236
	}
241
	
242
	private class CompareAsText implements ICompareAsText {
243
		public void compareAsText(Object input) {
244
			internalCompareAsText(input);
245
		}
246
	}
247
237
248
	/**
238
	/**
249
	 * Creates a <code>CompareEditorInput</code> which is initialized with the given
239
	 * Creates a <code>CompareEditorInput</code> which is initialized with the given
Lines 276-295 Link Here
276
		fContainer = configuration.getContainer();
266
		fContainer = configuration.getContainer();
277
		configuration.setContainer(this);
267
		configuration.setContainer(this);
278
	}
268
	}
279
	
280
	/* package */ void internalCompareAsText(Object input) {
281
		Set set = (Set)getCompareConfiguration().getProperty(ICompareAsText.PROP_TEXT_INPUTS);
282
		if (set == null) {
283
			set = new HashSet();
284
			getCompareConfiguration().setProperty(ICompareAsText.PROP_TEXT_INPUTS, set);
285
		}
286
		set.add(input);
287
		if (fContentInputPane.getInput().equals(input)) {
288
			// We need to null the input and then reset it so we get the text merge viewer
289
			fContentInputPane.setInput(null);
290
			fContentInputPane.setInput(input);
291
		}
292
	}
293
269
294
	private boolean structureCompareOnSingleClick() {
270
	private boolean structureCompareOnSingleClick() {
295
		return fStructureCompareOnSingleClick;
271
		return fStructureCompareOnSingleClick;
Lines 323-333 Link Here
323
				return fOutlineView;
299
				return fOutlineView;
324
			}
300
			}
325
		}
301
		}
326
		if (adapter == ICompareAsText.class) {
327
			if (fCompareAsText == null)
328
				fCompareAsText = new CompareAsText();
329
			return fCompareAsText;
330
		}
331
		if (adapter == IFindReplaceTarget.class) {
302
		if (adapter == IFindReplaceTarget.class) {
332
			if (fContentInputPane != null) {
303
			if (fContentInputPane != null) {
333
				Viewer v = fContentInputPane.getViewer();
304
				Viewer v = fContentInputPane.getViewer();
(-)compare/org/eclipse/compare/internal/ICompareAsText.java (-22 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 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
public interface ICompareAsText {
14
	
15
	/**
16
	 * Property key for the set of test inputs (instance of Set)
17
	 */
18
	public static final String PROP_TEXT_INPUTS = "org.eclipse.compare.TextInputs"; //$NON-NLS-1$
19
	
20
	public void compareAsText(Object input);
21
22
}
(-)compare/org/eclipse/compare/internal/BinaryCompareViewerResources.properties (-2 / +2 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2007 IBM Corporation and others.
2
# Copyright (c) 2000, 2009 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
5
# which accompanies this distribution, and is available at
Lines 20-23 Link Here
20
addedMessage= Added Resource
20
addedMessage= Added Resource
21
deletedMessage= Removed Resource
21
deletedMessage= Removed Resource
22
errorMessage= Internal Error
22
errorMessage= Internal Error
23
compareAsText= Compare as Text
23
compareAsText= Switch to Text Compare using the drop down menu above
(-)compare/org/eclipse/compare/internal/BinaryCompareViewer.java (-44 / +22 lines)
Lines 10-29 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
11
package org.eclipse.compare.internal;
12
12
13
import java.io.*;
13
import java.io.IOException;
14
import java.io.InputStream;
14
import java.util.ResourceBundle;
15
import java.util.ResourceBundle;
15
import com.ibm.icu.text.MessageFormat;
16
16
17
import org.eclipse.compare.CompareConfiguration;
18
import org.eclipse.compare.CompareEditorInput;
19
import org.eclipse.compare.CompareUI;
20
import org.eclipse.compare.IStreamContentAccessor;
21
import org.eclipse.compare.ITypedElement;
22
import org.eclipse.compare.structuremergeviewer.ICompareInput;
23
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.BusyIndicator;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.events.SelectionListener;
21
import org.eclipse.swt.layout.RowLayout;
25
import org.eclipse.swt.layout.RowLayout;
22
import org.eclipse.swt.widgets.*;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.ui.PlatformUI;
29
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.core.runtime.CoreException;
30
25
import org.eclipse.compare.*;
31
import com.ibm.icu.text.MessageFormat;
26
import org.eclipse.compare.structuremergeviewer.ICompareInput;
27
32
28
/**
33
/**
29
 * A simple compare viewer for binary files.
34
 * A simple compare viewer for binary files.
Lines 31-47 Link Here
31
 */
36
 */
32
public class BinaryCompareViewer extends AbstractViewer {
37
public class BinaryCompareViewer extends AbstractViewer {
33
38
34
	private static final String BUNDLE_NAME= "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$
39
	private static final String BUNDLE_NAME = "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$
35
40
	
36
	private static final int EOF= -1;
41
	private static final int EOF = -1;
37
	private ICompareInput fInput;
42
	private ICompareInput fInput;
38
	private ResourceBundle fBundle;
43
	private ResourceBundle fBundle;
39
	private boolean fLeftIsLocal;
44
	private boolean fLeftIsLocal;
40
45
41
	private Composite fComposite;
46
	private Composite fComposite;
42
	private Label fMessage;
47
	private Label fMessage;
43
	private Button fTextButton;
44
	
45
	
48
	
46
	public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) {
49
	public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) {
47
		
50
		
Lines 59-94 Link Here
59
		
62
		
60
		fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$
63
		fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$
61
		
64
		
62
		if (canShowAsText(cc)) {
65
		if (cc != null && cc.getContainer() instanceof CompareEditorInput) {
63
			fTextButton = new Button(fComposite, SWT.PUSH);
66
			Label compareAsTextLabel = new Label(fComposite, SWT.WRAP);
64
			fTextButton.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$
67
			compareAsTextLabel
65
			fTextButton.addSelectionListener(new SelectionListener() {
68
					.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$
66
				public void widgetSelected(SelectionEvent e) {
67
					BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
68
						public void run() {
69
							handleShowAsText(cc);
70
						}
71
					});
72
				}
73
				public void widgetDefaultSelected(SelectionEvent e) {
74
					// Do nothing
75
				}
76
			});
77
			fTextButton.setEnabled(false);
78
		}
69
		}
79
	}
70
	}
80
71
81
	private boolean canShowAsText(CompareConfiguration cc) {
82
		if (cc == null)
83
			return false;
84
		return Utilities.getAdapter(cc.getContainer(), ICompareAsText.class) != null;
85
	}
86
87
	protected void handleShowAsText(CompareConfiguration cc) {
88
		ICompareAsText comparer = (ICompareAsText)Utilities.getAdapter(cc.getContainer(), ICompareAsText.class);
89
		comparer.compareAsText(getInput());
90
	}
91
92
	public Control getControl() {
72
	public Control getControl() {
93
		return fComposite;
73
		return fComposite;
94
	}
74
	}
Lines 96-102 Link Here
96
	public void setInput(Object input) {
76
	public void setInput(Object input) {
97
		if (fComposite != null && input instanceof ICompareInput) {
77
		if (fComposite != null && input instanceof ICompareInput) {
98
			fInput= (ICompareInput) input;
78
			fInput= (ICompareInput) input;
99
			
79
100
			InputStream left= null;
80
			InputStream left= null;
101
			InputStream right= null;
81
			InputStream right= null;
102
			
82
			
Lines 142-149 Link Here
142
			}
122
			}
143
			if (message != null)
123
			if (message != null)
144
				fMessage.setText(message);
124
				fMessage.setText(message);
145
			if (fTextButton != null)
146
				fTextButton.setEnabled(true);
147
			fComposite.layout();
125
			fComposite.layout();
148
		}
126
		}
149
	}
127
	}
(-)compare/org/eclipse/compare/internal/CompareUIPlugin.java (-32 / +24 lines)
Lines 74-80 Link Here
74
import org.eclipse.ui.plugin.AbstractUIPlugin;
74
import org.eclipse.ui.plugin.AbstractUIPlugin;
75
import org.osgi.framework.BundleContext;
75
import org.osgi.framework.BundleContext;
76
76
77
78
/**
77
/**
79
 * The Compare UI plug-in defines the entry point to initiate a configurable
78
 * The Compare UI plug-in defines the entry point to initiate a configurable
80
 * compare operation on arbitrary resources. The result of the compare
79
 * compare operation on arbitrary resources. The result of the compare
Lines 859-868 Link Here
859
858
860
		ICompareInput input= (ICompareInput) in;
859
		ICompareInput input= (ICompareInput) in;
861
		
860
		
862
		IContentType ctype= getCommonType(input);
861
		IContentType ctype = getCommonType(input);
863
		if (isCompareAsText(input, cc)) {
864
			ctype = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);
865
		}
866
		if (ctype != null) {
862
		if (ctype != null) {
867
			initializeRegistries();
863
			initializeRegistries();
868
			List list = fContentMergeViewers.searchAll(ctype);
864
			List list = fContentMergeViewers.searchAll(ctype);
Lines 896-918 Link Here
896
			if (list != null)
892
			if (list != null)
897
				result.addAll(list);
893
				result.addAll(list);
898
		}
894
		}
899
895
		
900
		// fallback
896
		// fallback
901
		String leftType= guessType(input.getLeft());
897
		String leftType= guessType(input.getLeft());
902
		String rightType= guessType(input.getRight());
898
		String rightType= guessType(input.getRight());
903
			
899
			
904
		if (leftType != null || rightType != null) {
900
		if (leftType != null || rightType != null) {
905
			boolean right_text= rightType != null && ITypedElement.TEXT_TYPE.equals(rightType);
901
			boolean right_text = rightType != null
906
			boolean left_text= leftType != null && ITypedElement.TEXT_TYPE.equals(leftType);
902
					&& ITypedElement.TEXT_TYPE.equals(rightType);
907
			if ((leftType == null && right_text) || (left_text && rightType == null) || (left_text && right_text))
903
			boolean left_text = leftType != null
908
				type= ITypedElement.TEXT_TYPE;
904
					&& ITypedElement.TEXT_TYPE.equals(leftType);
909
			else
910
				type= BINARY_TYPE;
911
			
912
			initializeRegistries();
905
			initializeRegistries();
913
			List list = fContentMergeViewers.searchAll(type);
906
			if (!right_text || !left_text) {
907
				List list = fContentMergeViewers.searchAll(BINARY_TYPE);
908
				if (list != null)
909
					result.addAll(list);
910
			}
911
			List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
914
			if (list != null)
912
			if (list != null)
915
				result.addAll(list);
913
				result.addAll(list);
914
916
			return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
915
			return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
917
		}
916
		}
918
		return null;
917
		return null;
Lines 936-948 Link Here
936
		ViewerDescriptor[] descriptors = findContentViewerDescriptor(oldViewer, in, cc);
935
		ViewerDescriptor[] descriptors = findContentViewerDescriptor(oldViewer, in, cc);
937
		return getViewer(descriptors != null ? descriptors[0] : null, oldViewer, parent, cc);
936
		return getViewer(descriptors != null ? descriptors[0] : null, oldViewer, parent, cc);
938
	}
937
	}
939
	
940
	private boolean isCompareAsText(ICompareInput input, CompareConfiguration cc) {
941
		Set set = (Set)cc.getProperty(ICompareAsText.PROP_TEXT_INPUTS);
942
		if (set == null)
943
			return false;
944
		return set.contains(input);
945
	}
946
938
947
	private static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) {    
939
	private static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) {    
948
	    if (descriptor instanceof IViewerDescriptor)
940
	    if (descriptor instanceof IViewerDescriptor)
Lines 1299-1307 Link Here
1299
1291
1300
	String findContentTypeNameOrType(ICompareInput input, ViewerDescriptor vd, CompareConfiguration cc) {
1292
	String findContentTypeNameOrType(ICompareInput input, ViewerDescriptor vd, CompareConfiguration cc) {
1301
		IContentType ctype= getCommonType(input);
1293
		IContentType ctype= getCommonType(input);
1302
		if (isCompareAsText(input, cc)) {
1303
			ctype = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);
1304
		}
1305
		if (ctype != null) {
1294
		if (ctype != null) {
1306
			initializeRegistries();
1295
			initializeRegistries();
1307
			List list = fContentMergeViewers.searchAll(ctype);
1296
			List list = fContentMergeViewers.searchAll(ctype);
Lines 1343-1357 Link Here
1343
		String rightType= guessType(input.getRight());
1332
		String rightType= guessType(input.getRight());
1344
			
1333
			
1345
		if (leftType != null || rightType != null) {
1334
		if (leftType != null || rightType != null) {
1346
			boolean right_text= rightType != null && ITypedElement.TEXT_TYPE.equals(rightType);
1335
			boolean right_text = rightType != null
1347
			boolean left_text= leftType != null && ITypedElement.TEXT_TYPE.equals(leftType);
1336
					&& ITypedElement.TEXT_TYPE.equals(rightType);
1348
			if ((leftType == null && right_text) || (left_text && rightType == null) || (left_text && right_text))
1337
			boolean left_text = leftType != null
1349
				type= ITypedElement.TEXT_TYPE;
1338
					&& ITypedElement.TEXT_TYPE.equals(leftType);
1350
			else
1351
				type= BINARY_TYPE;
1352
			
1353
			initializeRegistries();
1339
			initializeRegistries();
1354
			List list = fContentMergeViewers.searchAll(type);
1340
			if (!left_text || !right_text) {
1341
				List list = fContentMergeViewers.searchAll(BINARY_TYPE);
1342
				if (list != null)
1343
					if (list.contains(vd))
1344
						return type;
1345
			}
1346
			List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
1355
			if (list != null)
1347
			if (list != null)
1356
				if (list.contains(vd))
1348
				if (list.contains(vd))
1357
					return type;
1349
					return type;

Return to bug 266476