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) |