Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java465
1 files changed, 228 insertions, 237 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
index 2138a38ce..cb2754e57 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java
@@ -28,6 +28,7 @@ import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.StringTokenizer;
@@ -44,6 +45,7 @@ import org.eclipse.compare.structuremergeviewer.IStructureCreator;
import org.eclipse.compare.structuremergeviewer.StructureDiffViewer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
@@ -97,41 +99,40 @@ import org.osgi.framework.ServiceRegistration;
* which is initialized from extensions contributed to extension points
* declared by this plug-in.
* <p>
- * This class is the plug-in runtime class for the
+ * This class is the plug-in runtime class for the
* <code>"org.eclipse.compare"</code> plug-in.
* </p>
*/
public final class CompareUIPlugin extends AbstractUIPlugin {
-
- static class CompareRegistry {
-
+
+ static class CompareRegistry<T> {
private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
private final static String CONTENT_TYPE_ID_ATTRIBUTE= "contentTypeId"; //$NON-NLS-1$
- private HashMap fIdMap; // maps ids to data
- private HashMap fExtensionMap; // multimap: maps extensions to list of data
- private HashMap fContentTypeBindings; // multimap: maps content type bindings to list of data
+ private HashMap<String, T> fIdMap; // maps ids to data
+ private HashMap<String, List<T>> fExtensionMap; // multimap: maps extensions to list of data
+ private HashMap<IContentType, List<T>> fContentTypeBindings; // multimap: maps content type bindings to list of data
- void register(IConfigurationElement element, Object data) {
+ void register(IConfigurationElement element, T data) {
String id= element.getAttribute(ID_ATTRIBUTE);
- if (id != null) {
+ if (id != null) {
if (fIdMap == null)
- fIdMap= new HashMap();
+ fIdMap= new HashMap<>();
fIdMap.put(id, data);
}
String types= element.getAttribute(EXTENSIONS_ATTRIBUTE);
if (types != null) {
if (fExtensionMap == null)
- fExtensionMap= new HashMap();
+ fExtensionMap= new HashMap<>();
StringTokenizer tokenizer= new StringTokenizer(types, ","); //$NON-NLS-1$
while (tokenizer.hasMoreElements()) {
String extension= tokenizer.nextToken().trim();
- List l = (List) fExtensionMap.get(normalizeCase(extension));
+ List<T> l = fExtensionMap.get(normalizeCase(extension));
if (l == null)
- fExtensionMap.put(normalizeCase(extension), l = new ArrayList());
+ fExtensionMap.put(normalizeCase(extension), l = new ArrayList<>());
l.add(data);
}
}
@@ -143,15 +144,15 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (id == null)
logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.targetIdAttributeMissing", idAttributeName)); //$NON-NLS-1$
if (type != null && id != null && fIdMap != null) {
- Object o= fIdMap.get(id);
+ T o= fIdMap.get(id);
if (o != null) {
IContentType ct= fgContentTypeManager.getContentType(type);
if (ct != null) {
if (fContentTypeBindings == null)
- fContentTypeBindings= new HashMap();
- List l = (List) fContentTypeBindings.get(ct);
+ fContentTypeBindings= new HashMap<>();
+ List<T> l = fContentTypeBindings.get(ct);
if (l == null)
- fContentTypeBindings.put(ct, l = new ArrayList());
+ fContentTypeBindings.put(ct, l = new ArrayList<>());
l.add(o);
} else {
logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.contentTypeNotFound", type)); //$NON-NLS-1$
@@ -162,15 +163,15 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
}
- Object search(IContentType type) {
- List list = searchAll(type);
+ T search(IContentType type) {
+ List<T> list = searchAll(type);
return list != null ? list.get(0) : null;
}
-
- List searchAll(IContentType type) {
+
+ List<T> searchAll(IContentType type) {
if (fContentTypeBindings != null) {
for (; type != null; type= type.getBaseType()) {
- List data= (List) fContentTypeBindings.get(type);
+ List<T> data= fContentTypeBindings.get(type);
if (data != null)
return data;
}
@@ -178,25 +179,25 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
return null;
}
- Object search(String extension) {
- List list = searchAll(extension);
+ T search(String extension) {
+ List<T> list = searchAll(extension);
return list != null ? list.get(0) : null;
}
-
- List searchAll(String extension) {
+
+ List<T> searchAll(String extension) {
if (fExtensionMap != null)
- return (List) fExtensionMap.get(normalizeCase(extension));
+ return fExtensionMap.get(normalizeCase(extension));
return null;
}
}
-
+
/** Status code describing an internal error */
public static final int INTERNAL_ERROR= 1;
private static boolean NORMALIZE_CASE= true;
public static final String PLUGIN_ID= "org.eclipse.compare"; //$NON-NLS-1$
-
+
private static final String BINARY_TYPE= "binary"; //$NON-NLS-1$
private static final String STREAM_MERGER_EXTENSION_POINT= "streamMergers"; //$NON-NLS-1$
@@ -221,7 +222,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
private static final String COMPARE_EDITOR= PLUGIN_ID + ".CompareEditor"; //$NON-NLS-1$
-
+
private static final String STRUCTUREVIEWER_ALIASES_PREFERENCE_NAME= "StructureViewerAliases"; //$NON-NLS-1$
// content type
@@ -233,38 +234,38 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
* The plugin singleton.
*/
private static CompareUIPlugin fgComparePlugin;
-
+
/** Maps type to icons */
- private static Map fgImages= new Hashtable(10);
+ private static Map<String, Image> fgImages= new Hashtable<String, Image>(10);
/** Maps type to ImageDescriptors */
- private static Map fgImageDescriptors= new Hashtable(10);
+ private static Map<String, ImageDescriptor> fgImageDescriptors= new Hashtable<String, ImageDescriptor>(10);
/** Maps ImageDescriptors to Images */
- private static Map fgImages2= new Hashtable(10);
-
- private static List fgDisposeOnShutdownImages= new ArrayList();
-
+ private static Map<ImageDescriptor, Image> fgImages2= new Hashtable<ImageDescriptor, Image>(10);
+
+ private static List<Image> fgDisposeOnShutdownImages= new ArrayList<Image>();
+
private ResourceBundle fResourceBundle;
private boolean fRegistriesInitialized;
- private CompareRegistry fStreamMergers= new CompareRegistry();
- private CompareRegistry fStructureCreators= new CompareRegistry();
- private CompareRegistry fStructureMergeViewers= new CompareRegistry();
- private CompareRegistry fContentViewers= new CompareRegistry();
- private CompareRegistry fContentMergeViewers= new CompareRegistry();
- private CompareRegistry fCompareFilters = new CompareRegistry();
-
- private Map fStructureViewerAliases;
+ private CompareRegistry<StreamMergerDescriptor> fStreamMergers= new CompareRegistry<>();
+ private CompareRegistry<StructureCreatorDescriptor> fStructureCreators= new CompareRegistry<>();
+ private CompareRegistry<ViewerDescriptor> fStructureMergeViewers= new CompareRegistry<>();
+ private CompareRegistry<ViewerDescriptor> fContentViewers= new CompareRegistry<>();
+ private CompareRegistry<ViewerDescriptor> fContentMergeViewers= new CompareRegistry<>();
+ private CompareRegistry<CompareFilterDescriptor> fCompareFilters = new CompareRegistry<>();
+
+ private Map<String, String> fStructureViewerAliases;
private CompareResourceFilter fFilter;
private IPropertyChangeListener fPropertyChangeListener;
- private ServiceRegistration debugRegistration;
+ private ServiceRegistration<DebugOptionsListener> debugRegistration;
/**
* Creates the <code>CompareUIPlugin</code> object and registers all
* structure creators, content merge viewers, and structure merge viewers
* contributed to this plug-in's extension points.
* <p>
- * Note that instances of plug-in runtime classes are automatically created
+ * Note that instances of plug-in runtime classes are automatically created
* by the platform in the course of plug-in activation.
*/
public CompareUIPlugin() {
@@ -273,10 +274,11 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
fgComparePlugin= this;
}
+ @Override
public void start(BundleContext context) throws Exception {
super.start(context);
- Hashtable properties = new Hashtable(2);
+ Hashtable<String, String> properties = new Hashtable<>(2);
properties.put(DebugOptions.LISTENER_SYMBOLICNAME, PLUGIN_ID);
debugRegistration = context.registerService(DebugOptionsListener.class, Policy.DEBUG_OPTIONS_LISTENER,
properties);
@@ -285,34 +287,34 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
getPreferenceStore().getBoolean(
ComparePreferencePage.CAPPING_DISABLED));
}
-
+
+ @Override
public void stop(BundleContext context) throws Exception {
-
IPreferenceStore ps= getPreferenceStore();
- rememberAliases(ps);
+ rememberAliases(ps);
if (fPropertyChangeListener != null) {
ps.removePropertyChangeListener(fPropertyChangeListener);
fPropertyChangeListener= null;
}
-
+
super.stop(context);
-
+
if (fgDisposeOnShutdownImages != null) {
- Iterator i= fgDisposeOnShutdownImages.iterator();
+ Iterator<Image> i= fgDisposeOnShutdownImages.iterator();
while (i.hasNext()) {
- Image img= (Image) i.next();
+ Image img= i.next();
if (!img.isDisposed())
img.dispose();
}
fgImages= null;
}
-
+
if (debugRegistration != null) {
debugRegistration.unregister();
debugRegistration = null;
}
}
-
+
/**
* Returns the singleton instance of this plug-in runtime class.
*
@@ -321,7 +323,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
public static CompareUIPlugin getDefault() {
return fgComparePlugin;
}
-
+
/**
* Returns this plug-in's resource bundle.
*
@@ -332,7 +334,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
fResourceBundle= Platform.getResourceBundle(getBundle());
return fResourceBundle;
}
-
+
/**
* Returns this plug-in's unique identifier.
*
@@ -348,14 +350,14 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
fRegistriesInitialized= true;
}
}
-
+
/**
* Registers all stream mergers, structure creators, content merge viewers, and structure merge viewers
* that are found in the XML plugin files.
*/
private void registerExtensions() {
IExtensionRegistry registry= Platform.getExtensionRegistry();
-
+
// collect all IStreamMergers
IConfigurationElement[] elements= registry.getConfigurationElementsFor(PLUGIN_ID, STREAM_MERGER_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
@@ -368,7 +370,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (CONTENT_TYPE_BINDING.equals(element.getName()))
fStreamMergers.createBinding(element, STREAM_MERGER_ID_ATTRIBUTE);
}
-
+
// collect all IStructureCreators
elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_CREATOR_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
@@ -376,7 +378,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
String name= element.getName();
if (!CONTENT_TYPE_BINDING.equals(name)) {
if (!STRUCTURE_CREATOR.equals(name))
- logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, STRUCTURE_CREATOR)); //$NON-NLS-1$
+ logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, STRUCTURE_CREATOR)); //$NON-NLS-1$
fStructureCreators.register(element, new StructureCreatorDescriptor(element));
}
}
@@ -385,7 +387,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (CONTENT_TYPE_BINDING.equals(element.getName()))
fStructureCreators.createBinding(element, STRUCTURE_CREATOR_ID_ATTRIBUTE);
}
-
+
// collect all viewers which define the structure merge viewer extension point
elements= registry.getConfigurationElementsFor(PLUGIN_ID, STRUCTURE_MERGE_VIEWER_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
@@ -393,7 +395,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
String name= element.getName();
if (!CONTENT_TYPE_BINDING.equals(name)) {
if (!VIEWER_TAG.equals(name))
- logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$
+ logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$
fStructureMergeViewers.register(element, new ViewerDescriptor(element));
}
}
@@ -402,7 +404,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (CONTENT_TYPE_BINDING.equals(element.getName()))
fStructureMergeViewers.createBinding(element, STRUCTURE_MERGE_VIEWER_ID_ATTRIBUTE);
}
-
+
// collect all viewers which define the content merge viewer extension point
elements= registry.getConfigurationElementsFor(PLUGIN_ID, CONTENT_MERGE_VIEWER_EXTENSION_POINT);
for (int i= 0; i < elements.length; i++) {
@@ -410,7 +412,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
String name= element.getName();
if (!CONTENT_TYPE_BINDING.equals(name)) {
if (!VIEWER_TAG.equals(name))
- logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$
+ logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$
fContentMergeViewers.register(element, new ViewerDescriptor(element));
}
}
@@ -430,8 +432,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (!FILTER_TAG.equals(name))
logErrorMessage(Utilities.getFormattedString(
"CompareUIPlugin.unexpectedTag", name, FILTER_TAG)); //$NON-NLS-1$
- fCompareFilters.register(element, new CompareFilterDescriptor(
- element));
+ fCompareFilters.register(element, new CompareFilterDescriptor(element));
}
}
for (int i = 0; i < elements.length; i++) {
@@ -448,7 +449,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
String name= element.getName();
if (!CONTENT_TYPE_BINDING.equals(name)) {
if (!VIEWER_TAG.equals(name))
- logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$
+ logErrorMessage(Utilities.getFormattedString("CompareUIPlugin.unexpectedTag", name, VIEWER_TAG)); //$NON-NLS-1$
fContentViewers.register(element, new ViewerDescriptor(element));
}
}
@@ -458,21 +459,21 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
fContentViewers.createBinding(element, CONTENT_VIEWER_ID_ATTRIBUTE);
}
}
-
+
public static IWorkbench getActiveWorkbench() {
CompareUIPlugin plugin= getDefault();
if (plugin == null)
return null;
return plugin.getWorkbench();
}
-
+
public static IWorkbenchWindow getActiveWorkbenchWindow() {
IWorkbench workbench= getActiveWorkbench();
if (workbench == null)
- return null;
+ return null;
return workbench.getActiveWorkbenchWindow();
}
-
+
/**
* Returns the active workbench page or <code>null</code> if
* no active workbench page can be determined.
@@ -486,7 +487,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
return null;
return window.getActivePage();
}
-
+
/**
* Returns the SWT Shell of the active workbench window or <code>null</code> if
* no workbench window is active.
@@ -514,7 +515,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
/**
* Performs the comparison described by the given input and opens a compare
* editor on the result.
- *
+ *
* @param input
* the input on which to open the compare editor
* @param page
@@ -535,7 +536,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
IPreferenceStore ps= configuration.getPreferenceStore();
if (ps != null)
configuration.setProperty(
- CompareConfiguration.USE_OUTLINE_VIEW,
+ CompareConfiguration.USE_OUTLINE_VIEW,
Boolean.valueOf(ps.getBoolean(ComparePreferencePage.USE_OUTLINE_VIEW)));
}
if (input.canRunAsJob()) {
@@ -557,12 +558,13 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
final IWorkbenchPage wp, final IReusableEditor editor,
final boolean activate) {
Runnable runnable = new Runnable() {
+ @Override
public void run() {
if (editor != null && !editor.getSite().getShell().isDisposed()) { // reuse the given editor
editor.setInput(input);
return;
}
-
+
IWorkbenchPage page = wp;
if (page == null)
page= getActivePage();
@@ -572,7 +574,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
page.openEditor(input, COMPARE_EDITOR, activate);
} catch (PartInitException e) {
MessageDialog.openError(getShell(), Utilities.getString("CompareUIPlugin.openEditorError"), e.getMessage()); //$NON-NLS-1$
- }
+ }
} else {
MessageDialog.openError(getShell(),
Utilities.getString("CompareUIPlugin.openEditorError"), //$NON-NLS-1$
@@ -596,7 +598,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
internalOpenDialog(input);
}
}
-
+
public IStatus prepareInput(CompareEditorInput input, IProgressMonitor monitor) {
try {
input.run(monitor);
@@ -614,40 +616,38 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
return new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0, Utilities.getString("CompareUIPlugin.compareFailed"), e.getTargetException()); //$NON-NLS-1$
}
}
-
+
/*
* @return <code>true</code> if compare result is OK to show, <code>false</code> otherwise
*/
public boolean compareResultOK(CompareEditorInput input, IRunnableContext context) {
final Shell shell= getShell();
try {
-
// run operation in separate thread and make it cancelable
if (context == null)
context = PlatformUI.getWorkbench().getProgressService();
context.run(true, true, input);
-
+
String message= input.getMessage();
if (message != null) {
MessageDialog.openError(shell, Utilities.getString("CompareUIPlugin.compareFailed"), message); //$NON-NLS-1$
return false;
}
-
+
if (input.getCompareResult() == null) {
MessageDialog.openInformation(shell, Utilities.getString("CompareUIPlugin.dialogTitle"), Utilities.getString("CompareUIPlugin.noDifferences")); //$NON-NLS-2$ //$NON-NLS-1$
return false;
}
-
- return true;
+ return true;
} catch (InterruptedException x) {
- // canceled by user
+ // canceled by user
} catch (InvocationTargetException x) {
MessageDialog.openError(shell, Utilities.getString("CompareUIPlugin.compareFailed"), x.getTargetException().getMessage()); //$NON-NLS-1$
}
return false;
}
-
+
/*
* Registers an image for the given type.
*/
@@ -657,7 +657,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
fgDisposeOnShutdownImages.add(image);
}
}
-
+
/**
* Registers an image descriptor for the given type.
*
@@ -667,17 +667,17 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
public static void registerImageDescriptor(String type, ImageDescriptor descriptor) {
fgImageDescriptors.put(normalizeCase(type), descriptor);
}
-
+
public static ImageDescriptor getImageDescriptor(String relativePath) {
if (fgComparePlugin == null)
return null;
- IPath path= Utilities.getIconPath(null).append(relativePath);
+ IPath path= Utilities.getIconPath(null).append(relativePath);
URL url= FileLocator.find(fgComparePlugin.getBundle(), path, null);
if (url == null)
return null;
return ImageDescriptor.createFromURL(url);
}
-
+
/**
* Returns a shared image for the given type, or a generic image if none
* has been registered for the given type.
@@ -691,20 +691,20 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
* @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);
+ image= fgImages.get(type);
if (image == null) {
- ImageDescriptor id= (ImageDescriptor) fgImageDescriptors.get(type);
+ ImageDescriptor id= fgImageDescriptors.get(type);
if (id != null) {
image= id.createImage();
dispose= true;
}
-
+
if (image == null) {
if (fgComparePlugin != null) {
if (ITypedElement.FOLDER_TYPE.equals(type)) {
@@ -715,7 +715,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
dispose= true;
}
} else {
- id= (ImageDescriptor) fgImageDescriptors.get(normalizeCase("file")); //$NON-NLS-1$
+ id= fgImageDescriptors.get(normalizeCase("file")); //$NON-NLS-1$
image= id.createImage();
dispose= true;
}
@@ -725,7 +725,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
return image;
}
-
+
/**
* Returns a shared image for the given adaptable.
* This convenience method queries the given adaptable
@@ -742,34 +742,32 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
*/
public static Image getImage(IAdaptable adaptable) {
if (adaptable != null) {
- Object o= adaptable.getAdapter(IWorkbenchAdapter.class);
- if (o instanceof IWorkbenchAdapter) {
- ImageDescriptor id= ((IWorkbenchAdapter) o).getImageDescriptor(adaptable);
- if (id != null) {
- Image image= (Image)fgImages2.get(id);
- if (image == null) {
- image= id.createImage();
- try {
- fgImages2.put(id, image);
- } catch (NullPointerException ex) {
- // NeedWork
- }
- fgDisposeOnShutdownImages.add(image);
-
+ IWorkbenchAdapter o= Adapters.adapt(adaptable, IWorkbenchAdapter.class);
+ ImageDescriptor id= o.getImageDescriptor(adaptable);
+ if (id != null) {
+ Image image= fgImages2.get(id);
+ if (image == null) {
+ image= id.createImage();
+ try {
+ fgImages2.put(id, image);
+ } catch (NullPointerException e) {
+ // NeedWork
}
- return image;
+ fgDisposeOnShutdownImages.add(image);
+
}
+ return image;
}
}
return null;
}
-
+
private static Image createWorkbenchImage(String type) {
IEditorRegistry er= getDefault().getWorkbench().getEditorRegistry();
ImageDescriptor id= er.getImageDescriptor("foo." + type); //$NON-NLS-1$
return id.createImage();
}
-
+
/**
* Returns an structure creator descriptor for the given type.
*
@@ -779,9 +777,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
*/
public StructureCreatorDescriptor getStructureCreator(String type) {
initializeRegistries();
- return (StructureCreatorDescriptor) fStructureCreators.search(type);
+ return fStructureCreators.search(type);
}
-
+
/**
* Returns a stream merger for the given type.
*
@@ -791,12 +789,12 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
*/
public IStreamMerger createStreamMerger(String type) {
initializeRegistries();
- StreamMergerDescriptor descriptor= (StreamMergerDescriptor) fStreamMergers.search(type);
+ StreamMergerDescriptor descriptor= fStreamMergers.search(type);
if (descriptor != null)
return descriptor.createStreamMerger();
return null;
}
-
+
/**
* Returns a stream merger for the given content type.
*
@@ -806,27 +804,27 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
*/
public IStreamMerger createStreamMerger(IContentType type) {
initializeRegistries();
- StreamMergerDescriptor descriptor= (StreamMergerDescriptor) fStreamMergers.search(type);
+ StreamMergerDescriptor descriptor= fStreamMergers.search(type);
if (descriptor != null)
return descriptor.createStreamMerger();
return null;
}
-
+
public ViewerDescriptor[] findStructureViewerDescriptor(Viewer oldViewer,
ICompareInput input, CompareConfiguration configuration) {
if (input == null)
return null;
// we don't show the structure of additions or deletions
- if (input == null || input.getLeft() == null || input.getRight() == null)
+ if (input == null || input.getLeft() == null || input.getRight() == null)
return null;
- Set result = new LinkedHashSet();
-
+ Set<ViewerDescriptor> result = new LinkedHashSet<>();
+
// content type search
IContentType ctype= getCommonType(input);
if (ctype != null) {
initializeRegistries();
- List list = fStructureMergeViewers.searchAll(ctype);
+ List<ViewerDescriptor> list = fStructureMergeViewers.searchAll(ctype);
if (list != null)
result.addAll(list);
}
@@ -837,7 +835,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (isHomogenous(types)) {
type= normalizeCase(types[0]);
initializeRegistries();
- List list = fStructureMergeViewers.searchAll(type);
+ List<ViewerDescriptor> list = fStructureMergeViewers.searchAll(type);
if (list != null)
result.addAll(list);
String alias= getStructureViewerAlias(type);
@@ -848,10 +846,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
}
- return result.size() > 0 ? (ViewerDescriptor[]) result
- .toArray(new ViewerDescriptor[0]) : null;
+ return result.size() > 0 ? result.toArray(new ViewerDescriptor[0]) : null;
}
-
+
/**
* Returns a structure compare viewer based on an old viewer and an input object.
* If the old viewer is suitable for showing the input, the old viewer
@@ -879,11 +876,8 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
type= normalizeCase(types[0]);
}
- StructureCreatorDescriptor scc= null;
initializeRegistries();
- Object desc= fStructureCreators.search(ctype); // search for content type
- if (desc instanceof StructureCreatorDescriptor)
- scc= (StructureCreatorDescriptor) desc;
+ StructureCreatorDescriptor scc= fStructureCreators.search(ctype); // search for content type
if (scc == null && type != null)
scc= getStructureCreator(type); // search for old-style type scheme
if (scc != null) {
@@ -900,41 +894,38 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
public CompareFilterDescriptor[] findCompareFilters(Object in) {
- Collection contentTypes = getContentTypes(in);
+ Collection<Object> contentTypes = getContentTypes(in);
if (contentTypes == null) {
return new CompareFilterDescriptor[0];
}
- Set result = new LinkedHashSet();
- Iterator ctIterator = contentTypes.iterator();
+ Set<CompareFilterDescriptor> result = new LinkedHashSet<>();
+ Iterator<Object> ctIterator = contentTypes.iterator();
while (ctIterator.hasNext()) {
Object ct = ctIterator.next();
if (ct instanceof IContentType) {
- List list = fCompareFilters.searchAll((IContentType) ct);
+ List<CompareFilterDescriptor> list = fCompareFilters.searchAll((IContentType) ct);
if (list != null)
result.addAll(list);
} else if (ct instanceof String) {
- List list = fCompareFilters.searchAll((String) ct);
+ List<CompareFilterDescriptor> list = fCompareFilters.searchAll((String) ct);
if (list != null)
result.addAll(list);
}
}
- ArrayList list = new ArrayList(result);
- Collections.sort(list, new Comparator() {
- public int compare(Object left, Object right) {
- return ((CompareFilterDescriptor) left)
- .getFilterId()
- .compareTo(
- ((CompareFilterDescriptor) right).getFilterId());
+ ArrayList<CompareFilterDescriptor> list = new ArrayList<>(result);
+ Collections.sort(list, new Comparator<CompareFilterDescriptor>() {
+ @Override
+ public int compare(CompareFilterDescriptor left, CompareFilterDescriptor right) {
+ return left.getFilterId().compareTo(right.getFilterId());
}
});
- return (CompareFilterDescriptor[]) result
- .toArray(new CompareFilterDescriptor[result.size()]);
+ return result.toArray(new CompareFilterDescriptor[result.size()]);
}
- private Collection getContentTypes(Object in) {
- Set result = new LinkedHashSet();
+ private Collection<Object> getContentTypes(Object in) {
+ Set<Object> result = new LinkedHashSet<>();
if (in instanceof IStreamContentAccessor) {
String type = ITypedElement.TEXT_TYPE;
@@ -1002,62 +993,61 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
result.add(BINARY_TYPE);
}
result.add(ITypedElement.TEXT_TYPE);
-
}
return result;
}
public ViewerDescriptor[] findContentViewerDescriptor(Viewer oldViewer, Object in, CompareConfiguration cc) {
- Set result = new LinkedHashSet();
+ Set<ViewerDescriptor> 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);
+ List<ViewerDescriptor> 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);
+ List<ViewerDescriptor> 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]);
+ return 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);
+ List<ViewerDescriptor> 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++)
@@ -1069,18 +1059,18 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
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);
+ List<ViewerDescriptor> 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);
@@ -1089,19 +1079,19 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
initializeRegistries();
if ((rightType != null && !right_text)
|| (leftType != null && !left_text)) {
- List list = fContentMergeViewers.searchAll(BINARY_TYPE);
+ List<ViewerDescriptor> list = fContentMergeViewers.searchAll(BINARY_TYPE);
if (list != null)
result.addAll(list);
}
- List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
+ List<ViewerDescriptor> list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
if (list != null)
result.addAll(list);
- return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
+ return result.toArray(new ViewerDescriptor[0]);
}
- return result.size() > 0 ? (ViewerDescriptor[])result.toArray(new ViewerDescriptor[0]) : null;
+ return result.isEmpty() ? null : result.toArray(new ViewerDescriptor[0]);
}
-
+
/**
* Returns a content compare viewer based on an old viewer and an input object.
* If the old viewer is suitable for showing the input the old viewer
@@ -1121,18 +1111,18 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
return getViewer(descriptors != null ? descriptors[0] : null, oldViewer, parent, cc);
}
- private static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) {
+ private static Viewer getViewer(Object descriptor, Viewer oldViewer, Composite parent, CompareConfiguration cc) {
if (descriptor instanceof IViewerDescriptor)
return ((IViewerDescriptor)descriptor).createViewer(oldViewer, parent, cc);
return null;
}
-
+
private static String[] getTypes(ICompareInput input) {
ITypedElement ancestor= input.getAncestor();
ITypedElement left= input.getLeft();
ITypedElement right= input.getRight();
-
- ArrayList tmp= new ArrayList();
+
+ ArrayList<String> tmp= new ArrayList<>();
if (ancestor != null) {
String type= ancestor.getType();
if (type != null)
@@ -1148,9 +1138,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
if (type != null)
tmp.add(normalizeCase(type));
}
- return (String[]) tmp.toArray(new String[tmp.size()]);
+ return tmp.toArray(new String[tmp.size()]);
}
-
+
private static IContentType getContentType(ITypedElement element) {
if (element == null)
return null;
@@ -1193,7 +1183,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
ct= fgContentTypeManager.findContentTypeFor(name);
return ct;
}
-
+
/*
* Returns true if the given types are homogeneous.
*/
@@ -1208,37 +1198,36 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
return false;
}
-
+
/*
* Returns the most specific content type that is common to the given inputs or null.
*/
private static IContentType getCommonType(ICompareInput input) {
-
ITypedElement ancestor= input.getAncestor();
ITypedElement left= input.getLeft();
ITypedElement right= input.getRight();
-
+
int n= 0;
IContentType[] types= new IContentType[3];
IContentType type= null;
-
+
if (ancestor != null) {
type= getContentType(ancestor);
if (type != null)
types[n++]= type;
}
- type= getContentType(left);
+ type= getContentType(left);
if (type != null)
types[n++]= type;
type= getContentType(right);
if (type != null)
types[n++]= type;
-
+
IContentType result= null;
IContentType[] s0, s1, s2;
- switch (n) {
- case 0:
- return null;
+ switch (n) {
+ case 0:
+ return null;
case 1:
return types[0];
case 2:
@@ -1267,14 +1256,14 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
return null;
}
-
+
private static IContentType[] toFullPath(IContentType ct) {
- List l= new ArrayList();
+ List<IContentType> l= new ArrayList<>();
for (; ct != null; ct= ct.getBaseType())
l.add(0, ct);
- return (IContentType[]) l.toArray(new IContentType[l.size()]);
+ return l.toArray(new IContentType[l.size()]);
}
-
+
/*
* Guesses the file type of the given input.
* Returns ITypedElement.TEXT_TYPE if none of the first 10 lines is longer than 1000 bytes.
@@ -1321,26 +1310,26 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
return null;
}
-
+
private static String normalizeCase(String s) {
if (NORMALIZE_CASE && s != null)
return s.toUpperCase();
return s;
}
-
+
//---- alias management
-
+
private String getStructureViewerAlias(String type) {
- return (String) getStructureViewerAliases().get(type);
+ return getStructureViewerAliases().get(type);
}
public void addStructureViewerAlias(String type, String alias) {
getStructureViewerAliases().put(normalizeCase(alias), normalizeCase(type));
}
-
- private Map getStructureViewerAliases() {
+
+ private Map<String, String> getStructureViewerAliases() {
if (fStructureViewerAliases == null) {
- fStructureViewerAliases= new Hashtable(10);
+ fStructureViewerAliases= new Hashtable<>(10);
String aliases= getPreferenceStore().getString(STRUCTUREVIEWER_ALIASES_PREFERENCE_NAME);
if (aliases != null && aliases.length() > 0) {
StringTokenizer st= new StringTokenizer(aliases, " "); //$NON-NLS-1$
@@ -1357,19 +1346,19 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
return fStructureViewerAliases;
}
-
+
public void removeAllStructureViewerAliases(String type) {
if (fStructureViewerAliases == null)
return;
String t= normalizeCase(type);
- Set entrySet= fStructureViewerAliases.entrySet();
- for (Iterator iter= entrySet.iterator(); iter.hasNext(); ) {
- Map.Entry entry= (Map.Entry)iter.next();
+ Set<Entry<String, String>> entrySet= fStructureViewerAliases.entrySet();
+ for (Iterator<Map.Entry<String, String>> iter= entrySet.iterator(); iter.hasNext(); ) {
+ Map.Entry<String, String> entry= iter.next();
if (entry.getValue().equals(t))
iter.remove();
}
}
-
+
/*
* Converts the aliases into a single string before they are stored
* in the preference store.
@@ -1379,11 +1368,10 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
private void rememberAliases(IPreferenceStore ps) {
if (fStructureViewerAliases == null)
return;
- StringBuffer buffer= new StringBuffer();
- Iterator iter= fStructureViewerAliases.keySet().iterator();
- while (iter.hasNext()) {
- String key= (String) iter.next();
- String alias= (String) fStructureViewerAliases.get(key);
+ StringBuilder buffer= new StringBuilder();
+ for (Map.Entry<String, String> entry : fStructureViewerAliases.entrySet()) {
+ String key= entry.getKey();
+ String alias= entry.getValue();
buffer.append(key);
buffer.append('.');
buffer.append(alias);
@@ -1393,13 +1381,14 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
//---- filters
-
+
public boolean filter(String name, boolean isFolder, boolean isArchive) {
if (fFilter == null) {
fFilter= new CompareResourceFilter();
final IPreferenceStore ps= getPreferenceStore();
fFilter.setFilters(ps.getString(ComparePreferencePage.PATH_FILTER));
fPropertyChangeListener= new IPropertyChangeListener() {
+ @Override
public void propertyChange(PropertyChangeEvent event) {
if (ComparePreferencePage.PATH_FILTER.equals(event.getProperty()))
fFilter.setFilters(ps.getString(ComparePreferencePage.PATH_FILTER));
@@ -1409,9 +1398,10 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
return fFilter.filter(name, isFolder, isArchive);
}
-
+
private void internalOpenDialog(final CompareEditorInput input) {
Runnable runnable = new Runnable() {
+ @Override
public void run() {
CompareDialog dialog = new CompareDialog(PlatformUI
.getWorkbench().getModalDialogShellProvider()
@@ -1431,9 +1421,10 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
//---- more utilities
-
+
protected void handleNoDifference() {
Runnable runnable = new Runnable() {
+ @Override
public void run() {
MessageDialog.openInformation(getShell(), Utilities.getString("CompareUIPlugin.dialogTitle"), Utilities.getString("CompareUIPlugin.noDifferences")); //$NON-NLS-1$//$NON-NLS-2$
}
@@ -1442,14 +1433,14 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
/**
- * Returns an array of all editors that have an unsaved content. If the identical content is
+ * Returns an array of all editors that have an unsaved content. If the identical content is
* presented in more than one editor, only one of those editor parts is part of the result.
- *
+ *
* @return an array of all dirty editor parts.
*/
public static IEditorPart[] getDirtyEditors() {
- Set inputs= new HashSet();
- List result= new ArrayList(0);
+ Set<IEditorInput> inputs= new HashSet<IEditorInput>();
+ List<IEditorPart> result= new ArrayList<IEditorPart>(0);
IWorkbench workbench= getDefault().getWorkbench();
IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
for (int i= 0; i < windows.length; i++) {
@@ -1466,9 +1457,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
}
}
- return (IEditorPart[])result.toArray(new IEditorPart[result.size()]);
+ return result.toArray(new IEditorPart[result.size()]);
}
-
+
public static void logErrorMessage(String message) {
if (message == null)
message= ""; //$NON-NLS-1$
@@ -1476,9 +1467,9 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
}
public static void log(Throwable e) {
- log(new Status(IStatus.ERROR, getPluginId(), INTERNAL_ERROR, CompareMessages.ComparePlugin_internal_error, e));
+ log(new Status(IStatus.ERROR, getPluginId(), INTERNAL_ERROR, CompareMessages.ComparePlugin_internal_error, e));
}
-
+
public static void log(IStatus status) {
getDefault().getLog().log(status);
}
@@ -1487,20 +1478,20 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
IContentType ctype= getCommonType(input);
if (ctype != null) {
initializeRegistries();
- List list = fContentMergeViewers.searchAll(ctype);
+ List<ViewerDescriptor> 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++)
@@ -1512,10 +1503,10 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
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);
+ List<ViewerDescriptor> list = fContentMergeViewers.searchAll(type);
if (list != null)
if (list.contains(vd))
return type;
@@ -1524,7 +1515,7 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
// 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);
@@ -1533,12 +1524,12 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
initializeRegistries();
if ((rightType != null && !right_text)
|| (leftType != null && !left_text)) {
- List list = fContentMergeViewers.searchAll(BINARY_TYPE);
+ List<ViewerDescriptor> list = fContentMergeViewers.searchAll(BINARY_TYPE);
if (list != null)
if (list.contains(vd))
return type;
}
- List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
+ List<ViewerDescriptor> list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
if (list != null)
if (list.contains(vd))
return type;
@@ -1549,27 +1540,27 @@ public final class CompareUIPlugin extends AbstractUIPlugin {
String findStructureTypeNameOrType(ICompareInput input, ViewerDescriptor vd, CompareConfiguration cc) {
if (input == null)
return null;
- // we don't show the structure of additions or deletions
- if (input == null || input.getLeft() == null || input.getRight() == null)
+ // We don't show the structure of additions or deletions
+ if (input == null || input.getLeft() == null || input.getRight() == null)
return null;
- // content type search
+ // Content type search
IContentType ctype= getCommonType(input);
if (ctype != null) {
initializeRegistries();
- List list = fStructureMergeViewers.searchAll(ctype);
+ List<ViewerDescriptor> list = fStructureMergeViewers.searchAll(ctype);
if (list != null)
if (list.contains(vd))
return ctype.getName();
}
-
- // old style search
+
+ // Old style search
String[] types= getTypes(input);
String type= null;
if (isHomogenous(types)) {
type= normalizeCase(types[0]);
initializeRegistries();
- List list = fStructureMergeViewers.searchAll(type);
+ List<ViewerDescriptor> list = fStructureMergeViewers.searchAll(type);
if (list != null)
if (list.contains(vd))
return type;

Back to the top