String findContentTypeNameOrType( ICompareInput input, ViewerDescriptor vd, CompareConfiguration cc) { IContentType ctype = getCommonType(input); if (ctype != null) { initializeRegistries(); List list = fContentMergeViewers.searchAll(ctype); if (list != null) if (list.contains(vd)) return ctype.getName(); } String[] types = getTypes(input); String type = null; if (isHomogenous(types)) type = types[0]; if (ITypedElement.FOLDER_TYPE.equals(type)) return null; if (type == null) { int n = 0; for (int i = 0; i < types.length; i++) if (!ITypedElement.UNKNOWN_TYPE.equals(types[i])) { n++; if (type == null) type = types[i]; // remember the first known type } if (n > 1) // don't use the type if there were more than one type = null; } if (type != null) { initializeRegistries(); List list = fContentMergeViewers.searchAll(type); if (list != null) if (list.contains(vd)) return type; } // fallback String leftType = guessType(input.getLeft()); String rightType = guessType(input.getRight()); if (leftType != null || rightType != null) { boolean right_text = rightType != null && ITypedElement.TEXT_TYPE.equals(rightType); boolean left_text = leftType != null && ITypedElement.TEXT_TYPE.equals(leftType); initializeRegistries(); if ((rightType != null && !right_text) || (leftType != null && !left_text)) { List list = fContentMergeViewers.searchAll(BINARY_TYPE); if (list != null) if (list.contains(vd)) return type; } List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE); if (list != null) if (list.contains(vd)) return type; } return null; }
/** * Returns a shared image for the given type, or a generic image if none has been registered for * the given type. * * <p>Note: Images returned from this method will be automatically disposed of when this plug-in * shuts down. Callers must not dispose of these images themselves. * * @param type the type * @return the image */ public static Image getImage(String type) { type = normalizeCase(type); boolean dispose = false; Image image = null; if (type != null) image = (Image) fgImages.get(type); if (image == null) { ImageDescriptor id = (ImageDescriptor) fgImageDescriptors.get(type); if (id != null) { image = id.createImage(); dispose = true; } if (image == null) { if (fgComparePlugin != null) { if (ITypedElement.FOLDER_TYPE.equals(type)) { image = getDefault() .getWorkbench() .getSharedImages() .getImage(ISharedImages.IMG_OBJ_FOLDER); // image= SharedImages.getImage(ISharedImages.IMG_OBJ_FOLDER); } else { image = createWorkbenchImage(type); dispose = true; } } else { id = (ImageDescriptor) fgImageDescriptors.get(normalizeCase("file")); // $NON-NLS-1$ image = id.createImage(); dispose = true; } } if (image != null) registerImage(type, image, dispose); } return image; }
public ViewerDescriptor[] findContentViewerDescriptor( Viewer oldViewer, Object in, CompareConfiguration cc) { Set result = new LinkedHashSet(); if (in instanceof IStreamContentAccessor) { String type = ITypedElement.TEXT_TYPE; if (in instanceof ITypedElement) { ITypedElement tin = (ITypedElement) in; IContentType ct = getContentType(tin); if (ct != null) { initializeRegistries(); List list = fContentViewers.searchAll(ct); if (list != null) result.addAll(list); } String ty = tin.getType(); if (ty != null) type = ty; } initializeRegistries(); List list = fContentViewers.searchAll(type); if (list != null) result.addAll(list); // fallback result.add( fContentViewers.search( Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))); return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]); } if (!(in instanceof ICompareInput)) return null; ICompareInput input = (ICompareInput) in; IContentType ctype = getCommonType(input); if (ctype != null) { initializeRegistries(); List list = fContentMergeViewers.searchAll(ctype); if (list != null) result.addAll(list); } String[] types = getTypes(input); String type = null; if (isHomogenous(types)) type = types[0]; if (ITypedElement.FOLDER_TYPE.equals(type)) return null; if (type == null) { int n = 0; for (int i = 0; i < types.length; i++) if (!ITypedElement.UNKNOWN_TYPE.equals(types[i])) { n++; if (type == null) type = types[i]; // remember the first known type } if (n > 1) // don't use the type if there were more than one type = null; } if (type != null) { initializeRegistries(); List list = fContentMergeViewers.searchAll(type); if (list != null) result.addAll(list); } // fallback String leftType = guessType(input.getLeft()); String rightType = guessType(input.getRight()); if (leftType != null || rightType != null) { boolean right_text = rightType != null && ITypedElement.TEXT_TYPE.equals(rightType); boolean left_text = leftType != null && ITypedElement.TEXT_TYPE.equals(leftType); initializeRegistries(); if ((rightType != null && !right_text) || (leftType != null && !left_text)) { List list = fContentMergeViewers.searchAll(BINARY_TYPE); if (list != null) result.addAll(list); } List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE); if (list != null) result.addAll(list); return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]); } return null; }