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 (-43 / +40 lines)
Lines 10-47 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;
15
import java.util.HashSet;
14
import java.util.ResourceBundle;
16
import java.util.ResourceBundle;
15
import com.ibm.icu.text.MessageFormat;
17
import java.util.Set;
16
18
19
import org.eclipse.compare.CompareConfiguration;
20
import org.eclipse.compare.CompareEditorInput;
21
import org.eclipse.compare.CompareUI;
22
import org.eclipse.compare.IStreamContentAccessor;
23
import org.eclipse.compare.ITypedElement;
24
import org.eclipse.compare.structuremergeviewer.ICompareInput;
25
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.swt.SWT;
26
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;
27
import org.eclipse.swt.layout.RowLayout;
22
import org.eclipse.swt.widgets.*;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Label;
23
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.PlatformUI;
24
import org.eclipse.core.runtime.CoreException;
32
25
import org.eclipse.compare.*;
33
import com.ibm.icu.text.MessageFormat;
26
import org.eclipse.compare.structuremergeviewer.ICompareInput;
27
34
28
/**
35
/**
29
 * A simple compare viewer for binary files.
36
 * A simple compare viewer for binary files.
30
 * Shows the position of the first non-matching byte.
37
 * Shows the position of the first non-matching byte.
31
 */
38
 */
32
public class BinaryCompareViewer extends AbstractViewer {
39
public class BinaryCompareViewer extends AbstractViewer {
40
	
41
	/**
42
	 * Property key for the set of test inputs (instance of Set)
43
	 */
44
	public static final String PROP_TEXT_INPUTS = "org.eclipse.compare.TextInputs"; //$NON-NLS-1$
33
45
34
	private static final String BUNDLE_NAME= "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$
46
	private static final String BUNDLE_NAME = "org.eclipse.compare.internal.BinaryCompareViewerResources"; //$NON-NLS-1$
35
47
	
36
	private static final int EOF= -1;
48
	private static final int EOF = -1;
37
	private ICompareInput fInput;
49
	private ICompareInput fInput;
38
	private ResourceBundle fBundle;
50
	private ResourceBundle fBundle;
39
	private boolean fLeftIsLocal;
51
	private boolean fLeftIsLocal;
40
52
41
	private Composite fComposite;
53
	private Composite fComposite;
42
	private Label fMessage;
54
	private Label fMessage;
43
	private Button fTextButton;
55
44
	
56
	private CompareConfiguration cc;
45
	
57
	
46
	public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) {
58
	public BinaryCompareViewer(Composite parent, final CompareConfiguration cc) {
47
		
59
		
Lines 59-94 Link Here
59
		
71
		
60
		fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$
72
		fLeftIsLocal= Utilities.getBoolean(cc, "LEFT_IS_LOCAL", false); //$NON-NLS-1$
61
		
73
		
62
		if (canShowAsText(cc)) {
74
		if (cc != null && cc.getContainer() instanceof CompareEditorInput) {
63
			fTextButton = new Button(fComposite, SWT.PUSH);
75
			this.cc = cc;
64
			fTextButton.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$
76
			Label compareAsTextLabel = new Label(fComposite, SWT.WRAP);
65
			fTextButton.addSelectionListener(new SelectionListener() {
77
			compareAsTextLabel
66
				public void widgetSelected(SelectionEvent e) {
78
					.setText(Utilities.getString(fBundle, "compareAsText")); //$NON-NLS-1$
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
		}
79
		}
79
	}
80
	}
80
81
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() {
82
	public Control getControl() {
93
		return fComposite;
83
		return fComposite;
94
	}
84
	}
Lines 97-102 Link Here
97
		if (fComposite != null && input instanceof ICompareInput) {
87
		if (fComposite != null && input instanceof ICompareInput) {
98
			fInput= (ICompareInput) input;
88
			fInput= (ICompareInput) input;
99
			
89
			
90
			if (cc != null){
91
				Set set = (Set)cc.getProperty(PROP_TEXT_INPUTS);
92
				if (set == null) {
93
					set = new HashSet();
94
					cc.setProperty(PROP_TEXT_INPUTS, set);
95
				}
96
				set.add(input);
97
			}
98
			
100
			InputStream left= null;
99
			InputStream left= null;
101
			InputStream right= null;
100
			InputStream right= null;
102
			
101
			
Lines 142-149 Link Here
142
			}
141
			}
143
			if (message != null)
142
			if (message != null)
144
				fMessage.setText(message);
143
				fMessage.setText(message);
145
			if (fTextButton != null)
146
				fTextButton.setEnabled(true);
147
			fComposite.layout();
144
			fComposite.layout();
148
		}
145
		}
149
	}
146
	}
(-)compare/org/eclipse/compare/internal/CompareUIPlugin.java (-8 / +9 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-873 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);
862
		List cTypeViewerList = null;
863
		if (isCompareAsText(input, cc)) {
863
		if (isCompareAsText(input, cc)) {
864
			ctype = Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT);
864
			ctype = Platform.getContentTypeManager().getContentType(
865
					IContentTypeManager.CT_TEXT);
865
		}
866
		}
866
		if (ctype != null) {
867
		if (ctype != null) {
867
			initializeRegistries();
868
			initializeRegistries();
868
			List list = fContentMergeViewers.searchAll(ctype);
869
			cTypeViewerList = fContentMergeViewers.searchAll(ctype);
869
			if (list != null)
870
				result.addAll(list);
871
		}
870
		}
872
		
871
		
873
		String[] types= getTypes(input);
872
		String[] types= getTypes(input);
Lines 896-902 Link Here
896
			if (list != null)
895
			if (list != null)
897
				result.addAll(list);
896
				result.addAll(list);
898
		}
897
		}
899
898
		
900
		// fallback
899
		// fallback
901
		String leftType= guessType(input.getLeft());
900
		String leftType= guessType(input.getLeft());
902
		String rightType= guessType(input.getRight());
901
		String rightType= guessType(input.getRight());
Lines 913-918 Link Here
913
			List list = fContentMergeViewers.searchAll(type);
912
			List list = fContentMergeViewers.searchAll(type);
914
			if (list != null)
913
			if (list != null)
915
				result.addAll(list);
914
				result.addAll(list);
915
			if (cTypeViewerList != null)
916
				result.addAll(cTypeViewerList);
916
			return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
917
			return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
917
		}
918
		}
918
		return null;
919
		return null;
Lines 938-944 Link Here
938
	}
939
	}
939
	
940
	
940
	private boolean isCompareAsText(ICompareInput input, CompareConfiguration cc) {
941
	private boolean isCompareAsText(ICompareInput input, CompareConfiguration cc) {
941
		Set set = (Set)cc.getProperty(ICompareAsText.PROP_TEXT_INPUTS);
942
		Set set = (Set)cc.getProperty(BinaryCompareViewer.PROP_TEXT_INPUTS);
942
		if (set == null)
943
		if (set == null)
943
			return false;
944
			return false;
944
		return set.contains(input);
945
		return set.contains(input);

Return to bug 266476