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

Collapse All | Expand All

(-)compare/org/eclipse/compare/internal/CompareMessages.java (-1 / +3 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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 129-134 Link Here
129
	public static String CompareWithOtherResourceDialog_externalFolderRadioButton;
129
	public static String CompareWithOtherResourceDialog_externalFolderRadioButton;
130
	public static String CompareWithOtherResourceDialog_workspaceMainButton;
130
	public static String CompareWithOtherResourceDialog_workspaceMainButton;
131
	public static String CompareWithOtherResourceDialog_workspaceRadioButton;
131
	public static String CompareWithOtherResourceDialog_workspaceRadioButton;
132
	public static String CompareContentViewerSwitchingPane_defaultViewer;
133
	public static String CompareContentViewerSwitchingPane_switchButtonTooltip;
132
134
133
	static {
135
	static {
134
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
136
		NLS.initializeMessages(BUNDLE_NAME, CompareMessages.class);
(-)compare/org/eclipse/compare/internal/ViewerDescriptor.java (-5 / +9 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 10-22 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare.internal;
11
package org.eclipse.compare.internal;
12
12
13
import org.eclipse.swt.widgets.Composite;
13
import org.eclipse.compare.CompareConfiguration;
14
14
import org.eclipse.compare.IViewerCreator;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.IConfigurationElement;
16
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.compare.*;
18
19
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.jface.viewers.Viewer;
18
import org.eclipse.swt.widgets.Composite;
20
19
21
/**
20
/**
22
 * Creates <code>Viewer</code>s from an <code>IConfigurationElement</code>.
21
 * Creates <code>Viewer</code>s from an <code>IConfigurationElement</code>.
Lines 25-30 Link Here
25
24
26
	private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
25
	private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
27
	private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
26
	private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
27
	private final static String LABEL_ATTRIBUTE = "label"; //$NON-NLS-1$
28
28
29
	private IConfigurationElement fConfiguration;
29
	private IConfigurationElement fConfiguration;
30
	private IViewerCreator fViewerCreator;
30
	private IViewerCreator fViewerCreator;
Lines 69-72 Link Here
69
	public String getExtension() {
69
	public String getExtension() {
70
		return fConfiguration.getAttribute(EXTENSIONS_ATTRIBUTE);
70
		return fConfiguration.getAttribute(EXTENSIONS_ATTRIBUTE);
71
	}
71
	}
72
73
	String getLabel() {
74
		return fConfiguration.getAttribute(LABEL_ATTRIBUTE);
75
	}
72
}
76
}
(-)compare/org/eclipse/compare/internal/CompareMessages.properties (-1 / +4 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2008 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 141-143 Link Here
141
CompareWithOtherResourceDialog_externalFolderRadioButton=External folder
141
CompareWithOtherResourceDialog_externalFolderRadioButton=External folder
142
CompareWithOtherResourceDialog_workspaceMainButton=Browse...
142
CompareWithOtherResourceDialog_workspaceMainButton=Browse...
143
CompareWithOtherResourceDialog_workspaceRadioButton=Workspace
143
CompareWithOtherResourceDialog_workspaceRadioButton=Workspace
144
145
CompareContentViewerSwitchingPane_defaultViewer=Default
146
CompareContentViewerSwitchingPane_switchButtonTooltip=Switch
(-)compare/org/eclipse/compare/internal/CompareUIPlugin.java (-109 / +131 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 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-25 Link Here
20
import java.util.HashSet;
20
import java.util.HashSet;
21
import java.util.Hashtable;
21
import java.util.Hashtable;
22
import java.util.Iterator;
22
import java.util.Iterator;
23
import java.util.LinkedHashSet;
23
import java.util.List;
24
import java.util.List;
24
import java.util.Map;
25
import java.util.Map;
25
import java.util.ResourceBundle;
26
import java.util.ResourceBundle;
Lines 92-164 Link Here
92
    
93
    
93
    static class CompareRegistry {
94
    static class CompareRegistry {
94
        
95
        
95
    		private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
96
    	private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
96
    		private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
97
    	private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
97
    		private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$
98
    	private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$
98
 
99
99
    		private HashMap fIdMap;					// maps ids to data
100
    	private HashMap fIdMap;	// maps ids to data
100
    		private HashMap fExtensionMap;			// maps extensions to data
101
    	private HashMap fExtensionMap;	// multimap: maps extensions to list of data
101
    		private HashMap fContentTypeBindings;		// maps content type bindings to data
102
    	private HashMap fContentTypeBindings; // multimap: maps content type bindings to list of data
102
        
103
103
 
104
104
	    	void register(IConfigurationElement element, Object data) {
105
    	void register(IConfigurationElement element, Object data) {
105
	    	    String id= element.getAttribute(ID_ATTRIBUTE);
106
    		String id= element.getAttribute(ID_ATTRIBUTE);
106
	    	    if (id != null) {      
107
    		if (id != null) {      
107
	    	        if (fIdMap == null)
108
    			if (fIdMap == null)
108
	    	            fIdMap= new HashMap();
109
    				fIdMap= new HashMap();
109
	    	        fIdMap.put(id, data);
110
    			fIdMap.put(id, data);
110
	    	    }
111
    		}
111
	    	    
112
112
	    	    String types= element.getAttribute(EXTENSIONS_ATTRIBUTE);
113
    		String types= element.getAttribute(EXTENSIONS_ATTRIBUTE);
113
	    	    if (types != null) {
114
    		if (types != null) {
114
	    	        if (fExtensionMap == null)
115
    			if (fExtensionMap == null)
115
	    	            fExtensionMap= new HashMap();
116
    				fExtensionMap= new HashMap();
116
		    		StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$
117
    			StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$
117
		    		while (tokenizer.hasMoreElements()) {
118
    			while (tokenizer.hasMoreElements()) {
118
		    			String extension= tokenizer.nextToken().trim();
119
    				String extension= tokenizer.nextToken().trim();
119
		    			fExtensionMap.put(normalizeCase(extension), data);
120
    				List l = (List) fExtensionMap.get(normalizeCase(extension));
120
		    		}
121
					if (l == null)
121
	    	    }
122
						fExtensionMap.put(normalizeCase(extension),	l = new ArrayList());
122
	    	}
123
					l.add(data);
123
124
    			}
124
	    	void createBinding(IConfigurationElement element, String idAttributeName) {
125
    		}
125
            String type= element.getAttribute(CONTENT_TYPE_ID_ATTRIBUTE);
126
    	}
126
            String id= element.getAttribute(idAttributeName);
127
127
            if (id == null)
128
    	void createBinding(IConfigurationElement element, String idAttributeName) {
128
                logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$
129
    		String type= element.getAttribute(CONTENT_TYPE_ID_ATTRIBUTE);
129
            if (type != null && id != null && fIdMap != null) {
130
    		String id= element.getAttribute(idAttributeName);
130
                Object o= fIdMap.get(id);
131
    		if (id == null)
131
                if (o != null) {
132
    			logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$
132
                    IContentType ct= fgContentTypeManager.getContentType(type);
133
    		if (type != null && id != null && fIdMap != null) {
133
                    if (ct != null) {
134
    			Object o= fIdMap.get(id);
134
                        if (fContentTypeBindings == null)
135
    			if (o != null) {
135
                            fContentTypeBindings= new HashMap();
136
    				IContentType ct= fgContentTypeManager.getContentType(type);
136
                        fContentTypeBindings.put(ct, o);
137
    				if (ct != null) {
137
                    } else {
138
    					if (fContentTypeBindings == null)
138
                        logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$
139
    						fContentTypeBindings= new HashMap();
139
                    }
140
    					List l = (List) fContentTypeBindings.get(ct);
140
                } else {
141
    					if (l == null)
141
                    logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetNotFound", id)); //$NON-NLS-1$
142
							fContentTypeBindings.put(ct, l = new ArrayList());
142
                }
143
    					l.add(o);
143
            }
144
    				} else {
144
	    	}
145
    					logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$
145
146
    				}
146
	    	Object search(IContentType type) {
147
    			} else {
147
	    	    if (fContentTypeBindings != null) {
148
    				logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetNotFound", id)); //$NON-NLS-1$
148
	    	    		for (; type != null; type= type.getBaseType()) {
149
    			}
149
	    	    			Object data= fContentTypeBindings.get(type);
150
    		}
150
	    	    			if (data != null)
151
    	}
151
	    	    				return data;
152
152
	    	    		}
153
		Object search(IContentType type) {
153
	    	    }
154
			List list = searchAll(type);
154
	    	    return null;
155
			return list != null ? list.get(0) : null;
155
	    	}
156
		}
156
	    	
157
	    	
157
	    	Object search(String extension) {
158
		List searchAll(IContentType type) {
158
	    	    if (fExtensionMap != null)
159
			if (fContentTypeBindings != null) {
159
	    	        return fExtensionMap.get(normalizeCase(extension));
160
				for (; type != null; type= type.getBaseType()) {
160
	    	    return null;
161
					List data= (List) fContentTypeBindings.get(type);
161
	    	}
162
					if (data != null)
163
						return data;
164
				}
165
			}
166
			return null;
167
		}
168
169
		Object search(String extension) {
170
			List list = searchAll(extension);
171
			return list != null ? list.get(0) : null;
172
		}
173
		
174
		List searchAll(String extension) {
175
			if (fExtensionMap != null)
176
				return (List) fExtensionMap.get(normalizeCase(extension));
177
			return null;
178
		}
162
    }
179
    }
163
	
180
	
164
	/** Status code describing an internal error */
181
	/** Status code describing an internal error */
Lines 171-189 Link Here
171
	private static final String BINARY_TYPE= "binary"; //$NON-NLS-1$
188
	private static final String BINARY_TYPE= "binary"; //$NON-NLS-1$
172
189
173
	private static final String STREAM_MERGER_EXTENSION_POINT= "streamMergers"; //$NON-NLS-1$
190
	private static final String STREAM_MERGER_EXTENSION_POINT= "streamMergers"; //$NON-NLS-1$
174
		private static final String STREAM_MERGER= "streamMerger"; //$NON-NLS-1$
191
	private static final String STREAM_MERGER= "streamMerger"; //$NON-NLS-1$
175
		private static final String STREAM_MERGER_ID_ATTRIBUTE= "streamMergerId"; //$NON-NLS-1$
192
	private static final String STREAM_MERGER_ID_ATTRIBUTE= "streamMergerId"; //$NON-NLS-1$
176
	private static final String STRUCTURE_CREATOR_EXTENSION_POINT= "structureCreators"; //$NON-NLS-1$
193
	private static final String STRUCTURE_CREATOR_EXTENSION_POINT= "structureCreators"; //$NON-NLS-1$
177
		private static final String STRUCTURE_CREATOR= "structureCreator"; //$NON-NLS-1$
194
	private static final String STRUCTURE_CREATOR= "structureCreator"; //$NON-NLS-1$
178
		private static final String STRUCTURE_CREATOR_ID_ATTRIBUTE= "structureCreatorId"; //$NON-NLS-1$
195
	private static final String STRUCTURE_CREATOR_ID_ATTRIBUTE= "structureCreatorId"; //$NON-NLS-1$
179
		
196
180
	private static final String VIEWER_TAG= "viewer"; //$NON-NLS-1$
197
	private static final String VIEWER_TAG= "viewer"; //$NON-NLS-1$
181
	private static final String STRUCTURE_MERGE_VIEWER_EXTENSION_POINT= "structureMergeViewers"; //$NON-NLS-1$
198
	private static final String STRUCTURE_MERGE_VIEWER_EXTENSION_POINT= "structureMergeViewers"; //$NON-NLS-1$
182
		private static final String STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE= "structureMergeViewerId"; //$NON-NLS-1$
199
	private static final String STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE= "structureMergeViewerId"; //$NON-NLS-1$
183
	private static final String CONTENT_MERGE_VIEWER_EXTENSION_POINT= "contentMergeViewers"; //$NON-NLS-1$
200
	private static final String CONTENT_MERGE_VIEWER_EXTENSION_POINT= "contentMergeViewers"; //$NON-NLS-1$
184
		private static final String CONTENT_MERGE_VIEWER_ID_ATTRIBUTE= "contentMergeViewerId"; //$NON-NLS-1$
201
	private static final String CONTENT_MERGE_VIEWER_ID_ATTRIBUTE= "contentMergeViewerId"; //$NON-NLS-1$
185
	private static final String CONTENT_VIEWER_EXTENSION_POINT= "contentViewers"; //$NON-NLS-1$
202
	private static final String CONTENT_VIEWER_EXTENSION_POINT= "contentViewers"; //$NON-NLS-1$
186
		private static final String CONTENT_VIEWER_ID_ATTRIBUTE= "contentViewerId"; //$NON-NLS-1$
203
	private static final String CONTENT_VIEWER_ID_ATTRIBUTE= "contentViewerId"; //$NON-NLS-1$
187
204
188
	private static final String CONTENT_TYPE_BINDING= "contentTypeBinding"; //$NON-NLS-1$
205
	private static final String CONTENT_TYPE_BINDING= "contentTypeBinding"; //$NON-NLS-1$
189
206
Lines 223-229 Link Here
223
	private Map fStructureViewerAliases;
240
	private Map fStructureViewerAliases;
224
	private CompareFilter fFilter;
241
	private CompareFilter fFilter;
225
	private IPropertyChangeListener fPropertyChangeListener;
242
	private IPropertyChangeListener fPropertyChangeListener;
226
	
243
227
	/**
244
	/**
228
	 * Creates the <code>CompareUIPlugin</code> object and registers all
245
	 * Creates the <code>CompareUIPlugin</code> object and registers all
229
	 * structure creators, content merge viewers, and structure merge viewers
246
	 * structure creators, content merge viewers, and structure merge viewers
Lines 807-827 Link Here
807
		return null;
824
		return null;
808
	}
825
	}
809
	
826
	
810
	/**
827
	public Set/*<ViewerDescriptor>*/ findContentViewerDescriptor(Viewer oldViewer, Object in, CompareConfiguration cc) {
811
	 * Returns a content compare viewer based on an old viewer and an input object.
828
		Set result = new LinkedHashSet();
812
	 * If the old viewer is suitable for showing the input the old viewer
813
	 * is returned. Otherwise the input's type is used to find a viewer descriptor in the registry
814
	 * which in turn is used to create a content compare viewer under the given parent composite.
815
	 * If no viewer descriptor can be found <code>null</code> is returned.
816
	 *
817
	 * @param oldViewer a new viewer is only created if this old viewer cannot show the given input
818
	 * @param in the input object for which to find a content viewer
819
	 * @param parent the SWT parent composite under which the new viewer is created
820
	 * @param cc a configuration which is passed to a newly created viewer
821
	 * @return the compare viewer which is suitable for the given input object or <code>null</code>
822
	 */
823
	public Viewer findContentViewer(Viewer oldViewer, Object in, Composite parent, CompareConfiguration cc) {
824
		
825
		if (in instanceof IStreamContentAccessor) {
829
		if (in instanceof IStreamContentAccessor) {
826
			String type= ITypedElement.TEXT_TYPE;
830
			String type= ITypedElement.TEXT_TYPE;
827
			
831
			
Lines 831-839 Link Here
831
			    IContentType ct= getContentType(tin);
835
			    IContentType ct= getContentType(tin);
832
				if (ct != null) {
836
				if (ct != null) {
833
					initializeRegistries();
837
					initializeRegistries();
834
					Viewer viewer= getViewer(fContentViewers.search(ct), oldViewer, parent, cc);
838
					List list = fContentViewers.searchAll(ct);
835
					if (viewer != null)
839
					if (list != null)
836
						return viewer;
840
						result.addAll(list);
837
				}
841
				}
838
			    
842
			    
839
				String ty= tin.getType();
843
				String ty= tin.getType();
Lines 842-859 Link Here
842
			}
846
			}
843
			
847
			
844
			initializeRegistries();
848
			initializeRegistries();
845
			Viewer viewer= getViewer(fContentViewers.search(type), oldViewer, parent, cc);
849
			List list = fContentViewers.searchAll(type);
846
			if (viewer != null)
850
			if (list != null)
847
				return viewer;
851
				result.addAll(list);
848
			// fallback
852
			// fallback
849
			return new SimpleTextViewer(parent);
853
			result.add(fContentViewers.search(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT)));
854
			return result;
850
		}
855
		}
851
856
852
		if (!(in instanceof ICompareInput))
857
		if (!(in instanceof ICompareInput))
853
			return null;
858
			return null;
854
			
855
		ICompareInput input= (ICompareInput) in;
856
859
860
		ICompareInput input= (ICompareInput) in;
857
		
861
		
858
		IContentType ctype= getCommonType(input);
862
		IContentType ctype= getCommonType(input);
859
		if (isCompareAsText(input, cc)) {
863
		if (isCompareAsText(input, cc)) {
Lines 861-869 Link Here
861
		}
865
		}
862
		if (ctype != null) {
866
		if (ctype != null) {
863
			initializeRegistries();
867
			initializeRegistries();
864
			Viewer viewer= getViewer(fContentMergeViewers.search(ctype), oldViewer, parent, cc);
868
			List list = fContentMergeViewers.searchAll(ctype);
865
			if (viewer != null)
869
			if (list != null)
866
				return viewer;
870
				result.addAll(list);
867
		}
871
		}
868
		
872
		
869
		String[] types= getTypes(input);
873
		String[] types= getTypes(input);
Lines 888-896 Link Here
888
		
892
		
889
		if (type != null) {
893
		if (type != null) {
890
			initializeRegistries();
894
			initializeRegistries();
891
			Viewer viewer= getViewer(fContentMergeViewers.search(type), oldViewer, parent, cc);
895
			List list = fContentMergeViewers.searchAll(type);
892
			if (viewer != null)
896
			if (list != null)
893
				return viewer;
897
				result.addAll(list);
894
		}
898
		}
895
899
896
		// fallback
900
		// fallback
Lines 906-918 Link Here
906
				type= BINARY_TYPE;
910
				type= BINARY_TYPE;
907
			
911
			
908
			initializeRegistries();
912
			initializeRegistries();
909
			IViewerDescriptor vd= (IViewerDescriptor) fContentMergeViewers.search(type);
913
			List list = fContentMergeViewers.searchAll(type);
910
			if (vd != null)
914
			if (list != null)
911
				return vd.createViewer(oldViewer, parent, cc);
915
				result.addAll(list);
916
			return result;
912
		}
917
		}
913
		return null;
918
		return null;
914
	}
919
	}
915
	
920
	
921
	/**
922
	 * Returns a content compare viewer based on an old viewer and an input object.
923
	 * If the old viewer is suitable for showing the input the old viewer
924
	 * is returned. Otherwise the input's type is used to find a viewer descriptor in the registry
925
	 * which in turn is used to create a content compare viewer under the given parent composite.
926
	 * If no viewer descriptor can be found <code>null</code> is returned.
927
	 *
928
	 * @param oldViewer a new viewer is only created if this old viewer cannot show the given input
929
	 * @param in the input object for which to find a content viewer
930
	 * @param parent the SWT parent composite under which the new viewer is created
931
	 * @param cc a configuration which is passed to a newly created viewer
932
	 * @return the compare viewer which is suitable for the given input object or <code>null</code>
933
	 */
934
	public Viewer findContentViewer(Viewer oldViewer, Object in, Composite parent, CompareConfiguration cc) {
935
		return getViewer(findContentViewerDescriptor(oldViewer, in, cc).toArray()[0], oldViewer, parent, cc);
936
	}
937
	
916
	private boolean isCompareAsText(ICompareInput input, CompareConfiguration cc) {
938
	private boolean isCompareAsText(ICompareInput input, CompareConfiguration cc) {
917
		Set set = (Set)cc.getProperty(ICompareAsText.PROP_TEXT_INPUTS);
939
		Set set = (Set)cc.getProperty(ICompareAsText.PROP_TEXT_INPUTS);
918
		if (set == null)
940
		if (set == null)
(-)compare/org/eclipse/compare/CompareViewerSwitchingPane.java (-3 / +14 lines)
Lines 216-221 Link Here
216
					return true;
216
					return true;
217
		return false;
217
		return false;
218
	}
218
	}
219
	
220
	/**
221
	 * @param input the input
222
	 * @return true, if the input is considered as changed
223
	 * @noreference This method is not intended to be referenced by clients.
224
	 * @nooverride This method is not intended to be re-implemented or extended
225
	 *             by clients.
226
	 */
227
	protected boolean inputChanged(Object input) {
228
		return getInput() != input;
229
	}
219
		
230
		
220
	/**
231
	/**
221
	 * Sets the input object of this pane. 
232
	 * Sets the input object of this pane. 
Lines 233-242 Link Here
233
	 */ 
244
	 */ 
234
	public void setInput(Object input) {
245
	public void setInput(Object input) {
235
246
236
		if (getInput() == input)
247
		if (!inputChanged(input))
237
			return;
248
			return;
238
			
249
239
		boolean hadFocus= hasFocus2();
250
		boolean hadFocus = hasFocus2();
240
		
251
		
241
		super.setInput(input);
252
		super.setInput(input);
242
253
(-)compare/org/eclipse/compare/CompareEditorInput.java (-10 / +31 lines)
Lines 19-24 Link Here
19
import org.eclipse.compare.contentmergeviewer.IFlushable;
19
import org.eclipse.compare.contentmergeviewer.IFlushable;
20
import org.eclipse.compare.internal.BinaryCompareViewer;
20
import org.eclipse.compare.internal.BinaryCompareViewer;
21
import org.eclipse.compare.internal.ChangePropertyAction;
21
import org.eclipse.compare.internal.ChangePropertyAction;
22
import org.eclipse.compare.internal.CompareContentViewerSwitchingPane;
22
import org.eclipse.compare.internal.CompareEditorInputNavigator;
23
import org.eclipse.compare.internal.CompareEditorInputNavigator;
23
import org.eclipse.compare.internal.CompareMessages;
24
import org.eclipse.compare.internal.CompareMessages;
24
import org.eclipse.compare.internal.ComparePreferencePage;
25
import org.eclipse.compare.internal.ComparePreferencePage;
Lines 27-32 Link Here
27
import org.eclipse.compare.internal.ICompareUIConstants;
28
import org.eclipse.compare.internal.ICompareUIConstants;
28
import org.eclipse.compare.internal.OutlineViewerCreator;
29
import org.eclipse.compare.internal.OutlineViewerCreator;
29
import org.eclipse.compare.internal.Utilities;
30
import org.eclipse.compare.internal.Utilities;
31
import org.eclipse.compare.internal.ViewerDescriptor;
30
import org.eclipse.compare.structuremergeviewer.DiffTreeViewer;
32
import org.eclipse.compare.structuremergeviewer.DiffTreeViewer;
31
import org.eclipse.compare.structuremergeviewer.ICompareInput;
33
import org.eclipse.compare.structuremergeviewer.ICompareInput;
32
import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
34
import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
Lines 144-150 Link Here
144
public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress, ICompareContainer {
146
public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress, ICompareContainer {
145
147
146
	private static final boolean DEBUG= false;
148
	private static final boolean DEBUG= false;
147
149
	
148
	/**
150
	/**
149
	 * The name of the "dirty" property (value <code>"DIRTY_STATE"</code>).
151
	 * The name of the "dirty" property (value <code>"DIRTY_STATE"</code>).
150
	 */
152
	 */
Lines 203-208 Link Here
203
	private String fHelpContextId;
205
	private String fHelpContextId;
204
	private InternalOutlineViewerCreator fOutlineView;
206
	private InternalOutlineViewerCreator fOutlineView;
205
	private ICompareAsText fCompareAsText;
207
	private ICompareAsText fCompareAsText;
208
	private ViewerDescriptor vd;
206
	
209
	
207
	private class InternalOutlineViewerCreator extends OutlineViewerCreator {
210
	private class InternalOutlineViewerCreator extends OutlineViewerCreator {
208
		private OutlineViewerCreator getWrappedCreator() {
211
		private OutlineViewerCreator getWrappedCreator() {
Lines 552-564 Link Here
552
				
555
				
553
		Control outline= createOutlineContents(fComposite, SWT.HORIZONTAL);
556
		Control outline= createOutlineContents(fComposite, SWT.HORIZONTAL);
554
					
557
					
555
		fContentInputPane= new CompareViewerSwitchingPane(fComposite, SWT.BORDER | SWT.FLAT) {
558
		fContentInputPane= new CompareContentViewerSwitchingPane(fComposite, SWT.BORDER | SWT.FLAT, this);
556
			protected Viewer getViewer(Viewer oldViewer, Object input) {
559
557
				if (input instanceof ICompareInput)
558
					return findContentViewer(oldViewer, (ICompareInput)input, this);
559
				return null;
560
			}
561
		};
562
		if (fFocusPane == null)
560
		if (fFocusPane == null)
563
			fFocusPane= fContentInputPane;
561
			fFocusPane= fContentInputPane;
564
		if (outline != null)
562
		if (outline != null)
Lines 926-933 Link Here
926
	 */
924
	 */
927
	public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
925
	public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) {
928
926
929
		Viewer newViewer= CompareUI.findContentViewer(oldViewer, input, parent, fCompareConfiguration);
927
		Viewer newViewer = vd != null ? vd.createViewer(oldViewer, parent,
930
		
928
				fCompareConfiguration) : CompareUI.findContentViewer(oldViewer,
929
				input, parent, fCompareConfiguration);
930
			
931
		boolean isNewViewer= newViewer != oldViewer;
931
		boolean isNewViewer= newViewer != oldViewer;
932
		if (DEBUG) System.out.println("CompareEditorInput.findContentViewer: " + isNewViewer); //$NON-NLS-1$
932
		if (DEBUG) System.out.println("CompareEditorInput.findContentViewer: " + isNewViewer); //$NON-NLS-1$
933
		
933
		
Lines 949-954 Link Here
949
	}
949
	}
950
	
950
	
951
	/**
951
	/**
952
	 * @param vd
953
	 *            the viewer descriptor
954
	 * @noreference This method is not intended to be referenced by clients.
955
	 * @nooverride This method is not intended to be re-implemented or extended
956
	 *             by clients.
957
	 */
958
	public void setViewerDescriptor(ViewerDescriptor vd) {
959
		this.vd = vd;
960
	}
961
962
	/**
963
	 * @return the viewer descriptor set for the input
964
	 * @noreference This method is not intended to be referenced by clients.
965
	 * @nooverride This method is not intended to be re-implemented or extended
966
	 *             by clients.
967
	 */
968
	public ViewerDescriptor getViewerDescriptor() {
969
		return this.vd;
970
	}
971
	
972
	/**
952
	 * Returns <code>true</code> if there are unsaved changes.
973
	 * Returns <code>true</code> if there are unsaved changes.
953
	 * The value returned is the value of the <code>DIRTY_STATE</code> property of this input object.
974
	 * The value returned is the value of the <code>DIRTY_STATE</code> property of this input object.
954
	 
975
	 
(-)compare/org/eclipse/compare/CompareViewerPane.java (-13 / +44 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 10-26 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.compare;
11
package org.eclipse.compare;
12
12
13
import org.eclipse.core.runtime.*;
13
import org.eclipse.core.runtime.IAdaptable;
14
import org.eclipse.core.runtime.ListenerList;
15
import org.eclipse.core.runtime.Platform;
14
import org.eclipse.jface.action.ToolBarManager;
16
import org.eclipse.jface.action.ToolBarManager;
15
import org.eclipse.jface.viewers.*;
17
import org.eclipse.jface.viewers.DoubleClickEvent;
18
import org.eclipse.jface.viewers.IDoubleClickListener;
19
import org.eclipse.jface.viewers.IOpenListener;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.ISelectionChangedListener;
22
import org.eclipse.jface.viewers.ISelectionProvider;
23
import org.eclipse.jface.viewers.OpenEvent;
24
import org.eclipse.jface.viewers.SelectionChangedEvent;
16
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.accessibility.*;
26
import org.eclipse.swt.accessibility.ACC;
27
import org.eclipse.swt.accessibility.AccessibleAdapter;
28
import org.eclipse.swt.accessibility.AccessibleEvent;
18
import org.eclipse.swt.custom.CLabel;
29
import org.eclipse.swt.custom.CLabel;
19
import org.eclipse.swt.custom.ViewForm;
30
import org.eclipse.swt.custom.ViewForm;
20
import org.eclipse.swt.events.*;
31
import org.eclipse.swt.events.DisposeEvent;
32
import org.eclipse.swt.events.DisposeListener;
33
import org.eclipse.swt.events.MouseAdapter;
34
import org.eclipse.swt.events.MouseEvent;
21
import org.eclipse.swt.graphics.Image;
35
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.graphics.Point;
36
import org.eclipse.swt.graphics.Point;
23
import org.eclipse.swt.widgets.*;
37
import org.eclipse.swt.widgets.Composite;
38
import org.eclipse.swt.widgets.Control;
39
import org.eclipse.swt.widgets.ToolBar;
40
import org.eclipse.swt.widgets.ToolItem;
24
41
25
/**
42
/**
26
 * A <code>CompareViewerPane</code> is a convenience class which installs a
43
 * A <code>CompareViewerPane</code> is a convenience class which installs a
Lines 63-74 Link Here
63
		marginWidth= 0;
80
		marginWidth= 0;
64
		marginHeight= 0;
81
		marginHeight= 0;
65
		
82
		
66
		CLabel label= new CLabel(this, SWT.NONE) {
83
		Control topLeft = createTopLeft(this);
67
			public Point computeSize(int wHint, int hHint, boolean changed) {
84
		setTopLeft(topLeft);
68
				return super.computeSize(wHint, Math.max(24, hHint), changed);
69
			}
70
		};
71
		setTopLeft(label);
72
		
85
		
73
		MouseAdapter ml= new MouseAdapter() {
86
		MouseAdapter ml= new MouseAdapter() {
74
			public void mouseDoubleClick(MouseEvent e) {
87
			public void mouseDoubleClick(MouseEvent e) {
Lines 82-88 Link Here
82
		};	
95
		};	
83
				
96
				
84
		addMouseListener(ml);
97
		addMouseListener(ml);
85
		label.addMouseListener(ml);
98
		getTopLeft().addMouseListener(ml);
86
		
99
		
87
		addDisposeListener(new DisposeListener() {
100
		addDisposeListener(new DisposeListener() {
88
			public void widgetDisposed(DisposeEvent e) {
101
			public void widgetDisposed(DisposeEvent e) {
Lines 98-103 Link Here
98
	}
111
	}
99
	
112
	
100
	/**
113
	/**
114
	 * @param parent
115
	 *            a widget which will be the parent of the control (cannot be
116
	 *            null)
117
	 * @return the control to be placed in the top left corner of the pane
118
	 * @noreference This method is not intended to be referenced by clients.
119
	 * @nooverride This method is not intended to be re-implemented or extended
120
	 *             by clients.
121
	 */
122
	protected Control createTopLeft(Composite parent) {
123
		CLabel label = new CLabel(this, SWT.NONE) {
124
			public Point computeSize(int wHint, int hHint, boolean changed) {
125
				return super.computeSize(wHint, Math.max(24, hHint), changed);
126
			}
127
		};
128
		return label;
129
	}
130
	
131
	/**
101
	 * Set the pane's title text.
132
	 * Set the pane's title text.
102
	 * The value <code>null</code> clears it.
133
	 * The value <code>null</code> clears it.
103
	 * 
134
	 * 
(-)schema/contentMergeViewers.exsd (-21 / +31 lines)
Lines 2-10 Link Here
2
<!-- Schema file written by PDE -->
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.compare" xmlns="http://www.w3.org/2001/XMLSchema">
3
<schema targetNamespace="org.eclipse.compare" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
4
<annotation>
5
      <appinfo>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.compare" id="contentMergeViewers" name="ContentMerge Viewers"/>
6
         <meta.schema plugin="org.eclipse.compare" id="contentMergeViewers" name="ContentMerge Viewers"/>
7
      </appinfo>
7
      </appInfo>
8
      <documentation>
8
      <documentation>
9
         This extension point allows a plug-in to register compare/merge 
9
         This extension point allows a plug-in to register compare/merge 
10
viewers for specific content types. The viewer is expected to 
10
viewers for specific content types. The viewer is expected to 
Lines 17-25 Link Here
17
17
18
   <element name="extension">
18
   <element name="extension">
19
      <annotation>
19
      <annotation>
20
         <appinfo>
20
         <appInfo>
21
            <meta.element />
21
            <meta.element />
22
         </appinfo>
22
         </appInfo>
23
      </annotation>
23
      </annotation>
24
      <complexType>
24
      <complexType>
25
         <sequence>
25
         <sequence>
Lines 45-53 Link Here
45
               <documentation>
45
               <documentation>
46
                  an optional name of the extension instance
46
                  an optional name of the extension instance
47
               </documentation>
47
               </documentation>
48
               <appinfo>
48
               <appInfo>
49
                  <meta.attribute translatable="true"/>
49
                  <meta.attribute translatable="true"/>
50
               </appinfo>
50
               </appInfo>
51
            </annotation>
51
            </annotation>
52
         </attribute>
52
         </attribute>
53
      </complexType>
53
      </complexType>
Lines 68-76 Link Here
68
                  a fully qualified name of a class that implements a factory for the 
68
                  a fully qualified name of a class that implements a factory for the 
69
content merge viewer and implements &lt;samp&gt;org.eclipse.compare.IViewerCreator&lt;/samp&gt;
69
content merge viewer and implements &lt;samp&gt;org.eclipse.compare.IViewerCreator&lt;/samp&gt;
70
               </documentation>
70
               </documentation>
71
               <appinfo>
71
               <appInfo>
72
                  <meta.attribute kind="java" basedOn=":org.eclipse.compare.IViewerCreator"/>
72
                  <meta.attribute kind="java" basedOn=":org.eclipse.compare.IViewerCreator"/>
73
               </appinfo>
73
               </appInfo>
74
            </annotation>
74
            </annotation>
75
         </attribute>
75
         </attribute>
76
         <attribute name="extensions" type="string">
76
         <attribute name="extensions" type="string">
Lines 80-85 Link Here
80
               </documentation>
80
               </documentation>
81
            </annotation>
81
            </annotation>
82
         </attribute>
82
         </attribute>
83
         <attribute name="label" type="string">
84
            <annotation>
85
               <documentation>
86
                  a translatable label that will be used in the UI for this viewer
87
               </documentation>
88
               <appInfo>
89
                  <meta.attribute translatable="true"/>
90
               </appInfo>
91
            </annotation>
92
         </attribute>
83
      </complexType>
93
      </complexType>
84
   </element>
94
   </element>
85
95
Lines 95-103 Link Here
95
               <documentation>
105
               <documentation>
96
                  The id of a content type defined using the &lt;code&gt;org.eclipse.core.contenttype.contentTypes&lt;/code&gt; extension point.
106
                  The id of a content type defined using the &lt;code&gt;org.eclipse.core.contenttype.contentTypes&lt;/code&gt; extension point.
97
               </documentation>
107
               </documentation>
98
               <appinfo>
108
               <appInfo>
99
                  <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/>
109
                  <meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/>
100
               </appinfo>
110
               </appInfo>
101
            </annotation>
111
            </annotation>
102
         </attribute>
112
         </attribute>
103
         <attribute name="contentMergeViewerId" type="string" use="required">
113
         <attribute name="contentMergeViewerId" type="string" use="required">
Lines 105-122 Link Here
105
               <documentation>
115
               <documentation>
106
                  The id of a merge viewer defined using the &lt;code&gt;viewer&lt;/code&gt; element of this extension point (i.e. &lt;code&gt;org.eclipse.compare.contentMergeViewers&lt;/code&gt;)
116
                  The id of a merge viewer defined using the &lt;code&gt;viewer&lt;/code&gt; element of this extension point (i.e. &lt;code&gt;org.eclipse.compare.contentMergeViewers&lt;/code&gt;)
107
               </documentation>
117
               </documentation>
108
               <appinfo>
118
               <appInfo>
109
                  <meta.attribute kind="identifier" basedOn="org.eclipse.compare.contentMergeViewers/viewer/@id"/>
119
                  <meta.attribute kind="identifier" basedOn="org.eclipse.compare.contentMergeViewers/viewer/@id"/>
110
               </appinfo>
120
               </appInfo>
111
            </annotation>
121
            </annotation>
112
         </attribute>
122
         </attribute>
113
      </complexType>
123
      </complexType>
114
   </element>
124
   </element>
115
125
116
   <annotation>
126
   <annotation>
117
      <appinfo>
127
      <appInfo>
118
         <meta.section type="examples"/>
128
         <meta.section type="examples"/>
119
      </appinfo>
129
      </appInfo>
120
      <documentation>
130
      <documentation>
121
         The following is an example of a compare/merge viewer 
131
         The following is an example of a compare/merge viewer 
122
for text files (extension &quot;txt&quot;):
132
for text files (extension &quot;txt&quot;):
Lines 135-143 Link Here
135
   </annotation>
145
   </annotation>
136
146
137
   <annotation>
147
   <annotation>
138
      <appinfo>
148
      <appInfo>
139
         <meta.section type="apiInfo"/>
149
         <meta.section type="apiInfo"/>
140
      </appinfo>
150
      </appInfo>
141
      <documentation>
151
      <documentation>
142
         The contributed class must implement &lt;code&gt;org.eclipse.compare.IViewerCreator&lt;/code&gt;
152
         The contributed class must implement &lt;code&gt;org.eclipse.compare.IViewerCreator&lt;/code&gt;
143
      </documentation>
153
      </documentation>
Lines 145-164 Link Here
145
155
146
156
147
   <annotation>
157
   <annotation>
148
      <appinfo>
158
      <appInfo>
149
         <meta.section type="implementation"/>
159
         <meta.section type="implementation"/>
150
      </appinfo>
160
      </appInfo>
151
      <documentation>
161
      <documentation>
152
         The Compare UI plugin defines content viewers for text, binary contents, and images.
162
         The Compare UI plugin defines content viewers for text, binary contents, and images.
153
      </documentation>
163
      </documentation>
154
   </annotation>
164
   </annotation>
155
165
156
   <annotation>
166
   <annotation>
157
      <appinfo>
167
      <appInfo>
158
         <meta.section type="copyright"/>
168
         <meta.section type="copyright"/>
159
      </appinfo>
169
      </appInfo>
160
      <documentation>
170
      <documentation>
161
         Copyright (c) 2000, 2008 IBM Corporation and others.&lt;br&gt;
171
         Copyright (c) 2000, 2009 IBM Corporation and others.&lt;br&gt;
162
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
172
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at &lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
163
      </documentation>
173
      </documentation>
164
   </annotation>
174
   </annotation>
(-)plugin.xml (-6 / +9 lines)
Lines 307-325 Link Here
307
   <extension
307
   <extension
308
         point="org.eclipse.compare.contentMergeViewers">
308
         point="org.eclipse.compare.contentMergeViewers">
309
      <viewer
309
      <viewer
310
            extensions="class,exe,dll,binary,zip,jar"
311
            class="org.eclipse.compare.internal.BinaryCompareViewerCreator"
310
            class="org.eclipse.compare.internal.BinaryCompareViewerCreator"
312
            id="org.eclipse.compare.BinaryCompareViewerCreator">
311
            extensions="class,exe,dll,binary,zip,jar"
312
            id="org.eclipse.compare.BinaryCompareViewerCreator"
313
            label="%BinaryCompare.label">
313
      </viewer>
314
      </viewer>
314
      <viewer
315
      <viewer
315
            extensions="txt"
316
            class="org.eclipse.compare.internal.TextMergeViewerCreator"
316
            class="org.eclipse.compare.internal.TextMergeViewerCreator"
317
            id="org.eclipse.compare.TextMergeViewerCreator">
317
            extensions="txt"
318
            id="org.eclipse.compare.TextMergeViewerCreator"
319
            label="%TextCompare.label">
318
      </viewer>
320
      </viewer>
319
      <viewer
321
      <viewer
320
            extensions="gif,jpg,jpeg,png,bmp,ico,tif,tiff"
321
            class="org.eclipse.compare.internal.ImageMergeViewerCreator"
322
            class="org.eclipse.compare.internal.ImageMergeViewerCreator"
322
            id="org.eclipse.compare.ImageMergeViewerCreator">
323
            extensions="gif,jpg,jpeg,png,bmp,ico,tif,tiff"
324
            id="org.eclipse.compare.ImageMergeViewerCreator"
325
            label="%ImageCompare.label">
323
      </viewer>
326
      </viewer>
324
      <contentTypeBinding
327
      <contentTypeBinding
325
			contentTypeId="org.eclipse.core.runtime.text"
328
			contentTypeId="org.eclipse.core.runtime.text"
(-)plugin.properties (-1 / +5 lines)
Lines 1-5 Link Here
1
###############################################################################
1
###############################################################################
2
# Copyright (c) 2000, 2008 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 224-226 Link Here
224
224
225
context.description = Comparing in an Editor
225
context.description = Comparing in an Editor
226
context.name = Comparing in an Editor
226
context.name = Comparing in an Editor
227
228
BinaryCompare.label=Binary Compare
229
TextCompare.label=Text Compare
230
ImageCompare.label=Image Compare
(-)compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java (+226 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 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 java.util.Set;
14
15
import org.eclipse.compare.CompareConfiguration;
16
import org.eclipse.compare.CompareEditorInput;
17
import org.eclipse.compare.CompareViewerSwitchingPane;
18
import org.eclipse.compare.Splitter;
19
import org.eclipse.compare.structuremergeviewer.ICompareInput;
20
import org.eclipse.jface.viewers.Viewer;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.custom.CLabel;
23
import org.eclipse.swt.events.MouseListener;
24
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.SelectionListener;
27
import org.eclipse.swt.graphics.Image;
28
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.graphics.Rectangle;
30
import org.eclipse.swt.layout.RowLayout;
31
import org.eclipse.swt.widgets.Composite;
32
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Menu;
34
import org.eclipse.swt.widgets.MenuItem;
35
import org.eclipse.swt.widgets.ToolBar;
36
import org.eclipse.swt.widgets.ToolItem;
37
import org.eclipse.ui.PlatformUI;
38
39
public class CompareContentViewerSwitchingPane extends
40
		CompareViewerSwitchingPane {
41
42
	private CompareEditorInput fCompareEditorInput;
43
44
	private ViewerDescriptor fSelectedViewerDescriptor;
45
46
	private ToolBar toolBar;
47
48
	private Menu menu;
49
50
	public CompareContentViewerSwitchingPane(Splitter parent, int style,
51
			CompareEditorInput cei) {
52
		super(parent, style);
53
		fCompareEditorInput = cei;
54
	}
55
56
	private CompareConfiguration getCompareConfiguration() {
57
		return fCompareEditorInput.getCompareConfiguration();
58
	}
59
60
	protected Viewer getViewer(Viewer oldViewer, Object input) {
61
		if (fSelectedViewerDescriptor != null) {
62
			Set viewers = CompareUIPlugin.getDefault().findContentViewerDescriptor(
63
					oldViewer, input, getCompareConfiguration());
64
			if (viewers.contains(fSelectedViewerDescriptor)) {
65
				// use selected viewer only when appropriate for the new input
66
				fCompareEditorInput
67
						.setViewerDescriptor(fSelectedViewerDescriptor);
68
				Viewer viewer = fCompareEditorInput.findContentViewer(
69
						oldViewer, (ICompareInput) input, this);
70
				return viewer;
71
			}
72
		}
73
		if (input instanceof ICompareInput) {
74
			fCompareEditorInput.setViewerDescriptor(null);
75
			Viewer viewer = fCompareEditorInput.findContentViewer(oldViewer,
76
					(ICompareInput) input, this);
77
			fCompareEditorInput.setViewerDescriptor(fSelectedViewerDescriptor);
78
			return viewer;
79
		}
80
		return null;
81
	}
82
83
	protected Control createTopLeft(Composite p) {
84
		final Composite composite = new Composite(p, SWT.NONE) {
85
			public Point computeSize(int wHint, int hHint, boolean changed) {
86
				return super.computeSize(wHint, Math.max(24, hHint), changed);
87
			}
88
		};
89
90
		RowLayout layout = new RowLayout();
91
		layout.marginTop = 0;
92
		composite.setLayout(layout);
93
94
		CLabel cl = new CLabel(composite, SWT.NONE);
95
		cl.setText(null);
96
97
		toolBar = new ToolBar(composite, SWT.FLAT);
98
		toolBar.setVisible(false); // hide by default
99
		final ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH, 0);
100
		toolItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(
101
				/* IWorkbenchGraphicConstants */"IMG_LCL_VIEW_MENU")); //$NON-NLS-1$
102
		toolItem
103
				.setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_switchButtonTooltip);
104
		toolItem.addSelectionListener(new SelectionAdapter() {
105
			public void widgetSelected(SelectionEvent e) {
106
				Rectangle bounds = toolItem.getBounds();
107
				Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
108
				topLeft = toolBar.toDisplay(topLeft);
109
				menu.setLocation(topLeft.x, topLeft.y);
110
				menu.setVisible(true);
111
			}
112
		});
113
		return composite;
114
	}
115
	
116
	protected boolean inputChanged(Object input) {
117
		return getInput() != input
118
				|| fCompareEditorInput.getViewerDescriptor() != fSelectedViewerDescriptor;
119
	}
120
121
	public void setInput(Object input) {
122
		super.setInput(input);
123
		Set/* <ViewerDescriptor> */data = CompareUIPlugin.getDefault()
124
				.findContentViewerDescriptor(getViewer(), input,
125
						getCompareConfiguration());
126
		updateMenu(data);
127
	}
128
129
	private void updateMenu(Set data) {
130
		if (data != null && data.size() > 1) {
131
			ViewerDescriptor[] fViewerDescriptors = (ViewerDescriptor[]) data
132
					.toArray(new ViewerDescriptor[0]);
133
134
			// dispose the old menu, if exists
135
			if (menu != null)
136
				menu.dispose();
137
138
			menu = new Menu(getShell(), SWT.POP_UP);
139
140
			// add default
141
			String label = fViewerDescriptors[0].getLabel();
142
			if (label == null || label.equals("")) { //$NON-NLS-1$
143
				label = CompareMessages.CompareContentViewerSwitchingPane_defaultViewer;
144
			}
145
			MenuItem defaultItem = new MenuItem(menu, SWT.RADIO);
146
			defaultItem.setText(label);
147
			defaultItem
148
					.addSelectionListener(createSelectionListener(fViewerDescriptors[0]));
149
			menu.setDefaultItem(defaultItem);
150
			defaultItem.setSelection(fViewerDescriptors[0] == fSelectedViewerDescriptor);
151
152
			// add others
153
			for (int j = 1; j < fViewerDescriptors.length; j++) {
154
				final ViewerDescriptor vdi = fViewerDescriptors[j];
155
				label = vdi.getLabel();
156
				if (label != null && !label.equals("")) { //$NON-NLS-1$
157
					MenuItem item = new MenuItem(menu, SWT.RADIO);
158
					item.setText(label);
159
					item.addSelectionListener(createSelectionListener(vdi));
160
					item
161
							.setSelection(fViewerDescriptors[j] == fSelectedViewerDescriptor);
162
				}
163
			}
164
			toolBar.setVisible(true);
165
		} else {
166
			toolBar.setVisible(false);
167
		}
168
	}
169
170
	private SelectionListener createSelectionListener(final ViewerDescriptor vd) {
171
		return new SelectionListener() {
172
			public void widgetSelected(SelectionEvent e) {
173
				MenuItem mi = (MenuItem) e.widget;
174
				if (mi.getSelection()) {
175
					Viewer oldViewer = getViewer();
176
					fSelectedViewerDescriptor = vd;
177
					CompareContentViewerSwitchingPane.this.setInput(oldViewer
178
							.getInput());
179
				}
180
			}
181
182
			public void widgetDefaultSelected(SelectionEvent e) {
183
				// nothing to do
184
			}
185
		};
186
	}
187
188
	public void setText(String label) {
189
		Composite c = (Composite) getTopLeft();
190
		Control[] children = c.getChildren();
191
		for (int i = 0; i < children.length; i++) {
192
			if (children[i] instanceof CLabel) {
193
				CLabel cl = (CLabel) children[i];
194
				if (cl != null && !cl.isDisposed()) {
195
					cl.setText(label);
196
					c.layout();
197
				}
198
				return;
199
			}
200
		}
201
	}
202
203
	public void setImage(Image image) {
204
		Composite c = (Composite) getTopLeft();
205
		Control[] children = c.getChildren();
206
		for (int i = 0; i < children.length; i++) {
207
			if (children[i] instanceof CLabel) {
208
				CLabel cl = (CLabel) children[i];
209
				if (cl != null && !cl.isDisposed())
210
					cl.setImage(image);
211
				return;
212
			}
213
		}
214
	}
215
	
216
	public void addMouseListener(MouseListener listener) {
217
		Composite c = (Composite) getTopLeft();
218
		Control[] children = c.getChildren();
219
		for (int i = 0; i < children.length; i++) {
220
			if (children[i] instanceof CLabel) {
221
				CLabel cl = (CLabel) children[i];
222
				cl.addMouseListener(listener);
223
			}
224
		}
225
	}
226
}

Return to bug 201116