Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2016-10-02 17:04:30 -0400
committerSergey Prigogin2016-10-03 15:42:18 -0400
commit16bb9ed654149328b54869c05526a5fdb9562b01 (patch)
tree0b9bab4099f6ccb3ae02a6957b8e00963abc754e
parent113da94aad098175fcc200a664fd8cd2ed18a51c (diff)
downloadeclipse.platform.team-16bb9ed654149328b54869c05526a5fdb9562b01.tar.gz
eclipse.platform.team-16bb9ed654149328b54869c05526a5fdb9562b01.tar.xz
eclipse.platform.team-16bb9ed654149328b54869c05526a5fdb9562b01.zip
Use Adapters.adapt method instead of homegrown equivalents.
Also fixed compilation warnings. Change-Id: Ibde2211f8793c36861140adb034174e18f3e03bd
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java128
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareNavigator.java52
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java57
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java44
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/SharedDocumentAdapter.java24
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java24
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java137
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java241
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareOutlinePage.java51
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java465
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java7
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java337
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java8
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Utilities.java16
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java8
15 files changed, 739 insertions, 860 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index c47431c0d..e04a83047 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -33,6 +33,7 @@ import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.compare.structuremergeviewer.IDiffContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -192,7 +193,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private String fMessage;
private Object fInput;
private String fTitle;
- private ListenerList fListenerList= new ListenerList();
+ private ListenerList<IPropertyChangeListener> fListenerList= new ListenerList<>();
private CompareNavigator fNavigator;
private boolean fLeftDirty = false;
private boolean fRightDirty = false;
@@ -212,11 +213,13 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
if (fContentInputPane != null) {
Viewer v = fContentInputPane.getViewer();
if (v != null) {
- return (OutlineViewerCreator)Utilities.getAdapter(v, OutlineViewerCreator.class);
+ return Adapters.adapt(v, OutlineViewerCreator.class);
}
}
return null;
}
+
+ @Override
public Viewer findStructureViewer(Viewer oldViewer,
ICompareInput input, Composite parent,
CompareConfiguration configuration) {
@@ -226,11 +229,13 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
return null;
}
+ @Override
public boolean hasViewerFor(Object input) {
OutlineViewerCreator creator = getWrappedCreator();
return creator != null;
}
+ @Override
public Object getInput() {
OutlineViewerCreator creator = getWrappedCreator();
if (creator != null)
@@ -251,6 +256,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
Assert.isNotNull(configuration);
fDirtyStateListener= new IPropertyChangeListener() {
+ @Override
public void propertyChange(PropertyChangeEvent e) {
String propertyName= e.getProperty();
if (CompareEditorInput.DIRTY_STATE.equals(propertyName)) {
@@ -280,17 +286,17 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
return object instanceof Boolean && ((Boolean)object).booleanValue();
}
- /* (non Javadoc)
- * see IAdaptable.getAdapter
- */
- public Object getAdapter(Class adapter) {
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getAdapter(Class<T> adapter) {
if (ICompareNavigator.class.equals(adapter) || CompareNavigator.class.equals(adapter)) {
- return getNavigator();
+ return (T) getNavigator();
}
if (adapter == IShowInSource.class) {
- final IFile file = (IFile)Utilities.getAdapter(this, IFile.class);
+ final IFile file = Adapters.adapt(this, IFile.class);
if (file != null)
- return new IShowInSource() {
+ return (T) new IShowInSource() {
+ @Override
public ShowInContext getShowInContext() {
return new ShowInContext(new FileEditorInput(file), StructuredSelection.EMPTY);
}
@@ -300,14 +306,14 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
synchronized (this) {
if (fOutlineView == null)
fOutlineView = new InternalOutlineViewerCreator();
- return fOutlineView;
+ return (T) fOutlineView;
}
}
if (adapter == IFindReplaceTarget.class) {
if (fContentInputPane != null) {
Viewer v = fContentInputPane.getViewer();
if (v != null) {
- return Utilities.getAdapter(v, IFindReplaceTarget.class);
+ return (T) Adapters.adapt(v, IFindReplaceTarget.class);
}
}
}
@@ -315,7 +321,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
if (fContentInputPane != null) {
Viewer v = fContentInputPane.getViewer();
if (v != null) {
- return Utilities.getAdapter(v, IEditorInput.class);
+ return (T) Adapters.adapt(v, IEditorInput.class);
}
}
}
@@ -324,7 +330,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
if (fContentInputPane != null) {
Viewer v = fContentInputPane.getViewer();
if (v != null) {
- return Utilities.getAdapter(v, ITextEditorExtension3.class);
+ return (T) Adapters.adapt(v, ITextEditorExtension3.class);
}
}
}
@@ -332,6 +338,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
return super.getAdapter(adapter);
}
+ @Override
public synchronized ICompareNavigator getNavigator() {
if (fNavigator == null)
fNavigator= new CompareEditorInputNavigator(
@@ -345,23 +352,17 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
return fNavigator;
}
- /* (non Javadoc)
- * see IEditorInput.getImageDescriptor
- */
+ @Override
public ImageDescriptor getImageDescriptor() {
return null;
}
- /* (non Javadoc)
- * see IEditorInput.getToolTipText
- */
+ @Override
public String getToolTipText() {
return getTitle();
}
- /* (non Javadoc)
- * see IEditorInput.getName
- */
+ @Override
public String getName() {
return getTitle();
}
@@ -371,6 +372,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
*
* @return <code>null</code> because this editor cannot be persisted
*/
+ @Override
public IPersistableElement getPersistable() {
return null;
}
@@ -381,6 +383,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
*
* @return <code>false</code>
*/
+ @Override
public boolean exists() {
return false;
}
@@ -472,14 +475,15 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
* Runs the compare operation and stores the compare result.
*
* @param monitor the progress monitor to use to display progress and receive
- * requests for cancelation
- * @exception InvocationTargetException if the <code>prepareInput</code> method must propagate a checked exception,
- * it should wrap it inside an <code>InvocationTargetException</code>; runtime exceptions are automatically
- * wrapped in an <code>InvocationTargetException</code> by the calling context
- * @exception InterruptedException if the operation detects a request to cancel,
- * using <code>IProgressMonitor.isCanceled()</code>, it should exit by throwing
- * <code>InterruptedException</code>
- */
+ * requests for cancellation
+ * @throws InvocationTargetException if the <code>prepareInput</code> method must propagate a checked exception,
+ * it should wrap it inside an <code>InvocationTargetException</code>; runtime exceptions are automatically
+ * wrapped in an <code>InvocationTargetException</code> by the calling context
+ * @throws InterruptedException if the operation detects a request to cancel,
+ * using <code>IProgressMonitor.isCanceled()</code>, it should exit by throwing
+ * <code>InterruptedException</code>
+ */
+ @Override
public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
fInput= prepareInput(monitor);
}
@@ -496,7 +500,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
* </p>
*
* @param monitor the progress monitor to use to display progress and receive
- * requests for cancelation
+ * requests for cancellation
* @return the result of the compare operation, or <code>null</code> if there are no differences
* @exception InvocationTargetException if the <code>prepareInput</code> method must propagate a checked exception,
* it should wrap it inside an <code>InvocationTargetException</code>; runtime exceptions are automatically
@@ -533,7 +537,6 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
* @return the SWT control hierarchy for the compare editor
*/
public Control createContents(Composite parent) {
-
fComposite= new Splitter(parent, SWT.VERTICAL);
fComposite.setData(this);
@@ -555,6 +558,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
feedInput();
fComposite.addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
/*
* When the UI associated with this compare editor input is
@@ -568,12 +572,14 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
Control control = composite;
while (composite.getChildren().length > 0) {
control = composite.getChildren()[composite.getChildren().length - 1];
- if (control instanceof Composite)
+ if (control instanceof Composite) {
composite = (Composite) control;
- else
+ } else {
break;
+ }
}
control.addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent ev) {
handleDispose();
}
@@ -654,6 +660,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
// setup the wiring for top left pane
fStructureInputPane.addOpenListener(
new IOpenListener() {
+ @Override
public void open(OpenEvent oe) {
feed1(oe.getSelection());
}
@@ -661,6 +668,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
);
fStructureInputPane.addSelectionChangedListener(
new ISelectionChangedListener() {
+ @Override
public void selectionChanged(SelectionChangedEvent e) {
ISelection s= e.getSelection();
if (s == null || s.isEmpty())
@@ -672,6 +680,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
);
fStructureInputPane.addDoubleClickListener(
new IDoubleClickListener() {
+ @Override
public void doubleClick(DoubleClickEvent event) {
feedDefault1(event.getSelection());
}
@@ -680,6 +689,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
fStructurePane1.addSelectionChangedListener(
new ISelectionChangedListener() {
+ @Override
public void selectionChanged(SelectionChangedEvent e) {
feed2(e.getSelection());
}
@@ -688,6 +698,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
fStructurePane2.addSelectionChangedListener(
new ISelectionChangedListener() {
+ @Override
public void selectionChanged(SelectionChangedEvent e) {
feed3(e.getSelection());
}
@@ -705,9 +716,9 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
* @return the structure input pane
* @since 3.3
*/
- protected CompareViewerPane createStructureInputPane(
- final Composite parent) {
+ protected CompareViewerPane createStructureInputPane(final Composite parent) {
return new CompareStructureViewerSwitchingPane(parent, SWT.BORDER | SWT.FLAT, true, this) {
+ @Override
protected Viewer getViewer(Viewer oldViewer, Object input) {
if (CompareEditorInput.this.hasChildren(input)) {
return createDiffViewer(this);
@@ -717,7 +728,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
};
}
- /* private */ boolean hasChildren(Object input) {
+ boolean hasChildren(Object input) {
if (input instanceof IDiffContainer) {
IDiffContainer dn= (IDiffContainer) input;
return dn.hasChildren();
@@ -755,7 +766,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private boolean hasOutlineViewer(Object input) {
if (!isShowStructureInOutlineView())
return false;
- OutlineViewerCreator creator = (OutlineViewerCreator)getAdapter(OutlineViewerCreator.class);
+ OutlineViewerCreator creator = getAdapter(OutlineViewerCreator.class);
if (creator != null)
return creator.hasViewerFor(input);
return false;
@@ -772,6 +783,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private void feed1(final ISelection selection) {
BusyIndicator.showWhile(fComposite.getDisplay(),
new Runnable() {
+ @Override
public void run() {
if (selection == null || selection.isEmpty()) {
Object input= fStructureInputPane.getInput();
@@ -800,6 +812,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private void feedDefault1(final ISelection selection) {
BusyIndicator.showWhile(fComposite.getDisplay(),
new Runnable() {
+ @Override
public void run() {
if (!selection.isEmpty())
fStructurePane1.setInput(getElement(selection));
@@ -811,6 +824,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private void feed2(final ISelection selection) {
BusyIndicator.showWhile(fComposite.getDisplay(),
new Runnable() {
+ @Override
public void run() {
if (selection.isEmpty()) {
Object input= fStructurePane1.getInput();
@@ -829,6 +843,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private void feed3(final ISelection selection) {
BusyIndicator.showWhile(fComposite.getDisplay(),
new Runnable() {
+ @Override
public void run() {
if (selection.isEmpty())
internalSetContentPaneInput(fStructurePane2.getInput());
@@ -873,6 +888,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
*
* @deprecated Please use {@link #setFocus2()} instead.
*/
+ @Deprecated
public void setFocus() {
setFocus2();
}
@@ -964,6 +980,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
Control c= newViewer.getControl();
c.addDisposeListener(
new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
dsp.removePropertyChangeListener(fDirtyStateListener);
}
@@ -1176,17 +1193,13 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
}
}
- /* (non Javadoc)
- * see IPropertyChangeNotifier.addListener
- */
+ @Override
public void addPropertyChangeListener(IPropertyChangeListener listener) {
if (listener != null)
fListenerList.add(listener);
}
- /* (non Javadoc)
- * see IPropertyChangeNotifier.removeListener
- */
+ @Override
public void removePropertyChangeListener(IPropertyChangeListener listener) {
if (fListenerList != null) {
fListenerList.remove(listener);
@@ -1201,6 +1214,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
* @param pm an <code>IProgressMonitor</code> that the implementation of save may use to show progress
* @deprecated Override method saveChanges instead.
*/
+ @Deprecated
public void save(IProgressMonitor pm) {
// empty default implementation
}
@@ -1216,7 +1230,6 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
* @since 2.0
*/
public void saveChanges(IProgressMonitor monitor) throws CoreException {
-
flushViewers(monitor);
save(monitor);
@@ -1261,7 +1274,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) {
if (pane != null) {
- IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class);
+ IFlushable flushable = Adapters.adapt(pane, IFlushable.class);
if (flushable != null)
flushable.flush(pm);
}
@@ -1269,7 +1282,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private static void flushLeftViewer(CompareViewerPane pane, IProgressMonitor pm) {
if (pane != null) {
- IFlushable2 flushable = (IFlushable2)Utilities.getAdapter(pane, IFlushable2.class);
+ IFlushable2 flushable = Adapters.adapt(pane, IFlushable2.class);
if (flushable != null)
flushable.flushLeft(pm);
}
@@ -1277,15 +1290,13 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private static void flushRightViewer(CompareViewerPane pane, IProgressMonitor pm) {
if (pane != null) {
- IFlushable2 flushable = (IFlushable2)Utilities.getAdapter(pane, IFlushable2.class);
+ IFlushable2 flushable = Adapters.adapt(pane, IFlushable2.class);
if (flushable != null)
flushable.flushRight(pm);
}
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareContainer#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
- */
+ @Override
public void addCompareInputChangeListener(ICompareInput input,
ICompareInputChangeListener listener) {
if (fContainer == null) {
@@ -1298,6 +1309,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
/* (non-Javadoc)
* @see org.eclipse.compare.ICompareContainer#removeCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener)
*/
+ @Override
public void removeCompareInputChangeListener(ICompareInput input,
ICompareInputChangeListener listener) {
if (fContainer == null) {
@@ -1310,14 +1322,13 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
/* (non-Javadoc)
* @see org.eclipse.compare.ICompareContainer#registerContextMenu(org.eclipse.jface.action.MenuManager, org.eclipse.jface.viewers.ISelectionProvider)
*/
+ @Override
public void registerContextMenu(MenuManager menu, ISelectionProvider selectionProvider) {
if (fContainer != null)
fContainer.registerContextMenu(menu, selectionProvider);
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareContainer#setStatusMessage(java.lang.String)
- */
+ @Override
public void setStatusMessage(String message) {
if (!fContainerProvided) {
// Try the action bars directly
@@ -1333,9 +1344,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
}
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareContainer#getActionBars()
- */
+ @Override
public IActionBars getActionBars() {
if (fContainer != null) {
IActionBars actionBars = fContainer.getActionBars();
@@ -1351,6 +1360,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
/* (non-Javadoc)
* @see org.eclipse.compare.ICompareContainer#getServiceLocator()
*/
+ @Override
public IServiceLocator getServiceLocator() {
IServiceLocator serviceLocator = fContainer.getServiceLocator();
if (serviceLocator == null && !fContainerProvided) {
@@ -1363,6 +1373,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
/* (non-Javadoc)
* @see org.eclipse.compare.ICompareContainer#getWorkbenchPart()
*/
+ @Override
public IWorkbenchPart getWorkbenchPart() {
if (fContainer != null)
return fContainer.getWorkbenchPart();
@@ -1372,6 +1383,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
/* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
*/
+ @Override
public void run(boolean fork, boolean cancelable,
IRunnableWithProgress runnable) throws InvocationTargetException,
InterruptedException {
@@ -1379,6 +1391,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
fContainer.run(fork, cancelable, runnable);
}
+ @Override
public void runAsynchronously(IRunnableWithProgress runnable) {
if (fContainer != null)
fContainer.runAsynchronously(runnable);
@@ -1522,6 +1535,7 @@ public abstract class CompareEditorInput extends PlatformObject implements IEdit
private boolean saveChanges() {
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
+ @Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
saveChanges(monitor);
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareNavigator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareNavigator.java
index 53f2ae025..bc7411f2d 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareNavigator.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareNavigator.java
@@ -10,8 +10,7 @@
*******************************************************************************/
package org.eclipse.compare;
-import org.eclipse.compare.internal.Utilities;
-import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Adapters;
/**
* Supports cross-pane navigation through the differences of a compare container.
@@ -22,14 +21,11 @@ import org.eclipse.core.runtime.IAdaptable;
* @since 3.3
*/
public abstract class CompareNavigator implements ICompareNavigator {
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareNavigator#selectChange(boolean)
- */
+ @Override
public boolean selectChange(boolean next) {
// find most down stream CompareViewerPane
INavigatable[] navigators= getNavigatables();
- Object downStreamInput = null;
+ Object downStreamInput = null;
for (int i = navigators.length - 1; i >=0; i--) {
INavigatable navigatable = navigators[i];
if (navigatable.getInput() == downStreamInput) {
@@ -42,49 +38,47 @@ public abstract class CompareNavigator implements ICompareNavigator {
continue;
}
// not at end
- if (i + 1 < navigators.length && navigators[i+1] != null && navigators[i+1].getInput() != downStreamInput) {
+ if (i + 1 < navigators.length && navigators[i + 1] != null
+ && navigators[i + 1].getInput() != downStreamInput) {
// The navigation has invoked a change in a downstream pane.
// Set the selected change depending on the direction we are navigating
navigators[i+1].selectChange(next ? INavigatable.FIRST_CHANGE : INavigatable.LAST_CHANGE);
}
return false;
}
-
+
return true;
}
-
+
protected abstract INavigatable[] getNavigatables();
-
+
/**
- * Return the {@link INavigatable} for the given object.
- * If the object implements {@link INavigatable}, then
- * the object is returned. Otherwise, if the object
- * implements {@link IAdaptable}, the object is
- * adapted to {@link INavigatable}.
+ * Returns the {@link INavigatable} for the given object if the object
+ * adapts to {@link INavigatable}.
+ *
* @param object the object
- * @return the {@link INavigatable} for the given object or <code>null</code>
+ * @return the {@link INavigatable} for the given object or {@code null}
*/
protected final INavigatable getNavigator(Object object) {
if (object == null)
return null;
- Object data= Utilities.getAdapter(object, INavigatable.class);
- if (data instanceof INavigatable)
- return (INavigatable) data;
- return null;
+ return Adapters.adapt(object, INavigatable.class);
}
/**
- * Return whether a call to {@link ICompareNavigator#selectChange(boolean)} with the same parameter
- * would succeed.
- * @param next if <code>true</code> the next change is selected, otherwise the previous change
- * @return whether a call to {@link ICompareNavigator#selectChange(boolean)} with the same parameter
- * would succeed.
+ * Returns whether a call to {@link ICompareNavigator#selectChange(boolean)}
+ * with the same parameter would succeed.
+ *
+ * @param next if <code>true</code> the next change is selected, otherwise
+ * the previous change
+ * @return whether a call to {@link ICompareNavigator#selectChange(boolean)}
+ * with the same parameter would succeed.
* @since 3.3
*/
public boolean hasChange(boolean next) {
INavigatable[] navigators= getNavigatables();
- Object downStreamInput = null;
- for (int i = navigators.length - 1; i >=0; i--) {
+ Object downStreamInput = null;
+ for (int i = navigators.length; --i >= 0;) {
INavigatable navigatable = navigators[i];
if (navigatable.getInput() == downStreamInput) {
// Skip to up stream pane if it has the same input
@@ -97,5 +91,5 @@ public abstract class CompareNavigator implements ICompareNavigator {
downStreamInput = navigatable.getInput();
}
return false;
- }
+ }
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java
index 715eef4bc..7b362a4dc 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerPane.java
@@ -53,12 +53,11 @@ import org.eclipse.swt.widgets.ToolItem;
*/
public class CompareViewerPane extends ViewForm implements ISelectionProvider,
IDoubleClickListener, ISelectionChangedListener, IOpenListener, IAdaptable {
-
private ToolBarManager fToolBarManager;
private Object fInput;
- private ListenerList fSelectionListeners= new ListenerList();
- private ListenerList fDoubleClickListener= new ListenerList();
- private ListenerList fOpenListener= new ListenerList();
+ private ListenerList<ISelectionChangedListener> fSelectionListeners= new ListenerList<>();
+ private ListenerList<IDoubleClickListener> fDoubleClickListener= new ListenerList<>();
+ private ListenerList<IOpenListener> fOpenListener= new ListenerList<>();
/**
* Constructs a new instance of this class given its parent
@@ -84,6 +83,7 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider,
setTopLeft(topLeft);
MouseAdapter ml= new MouseAdapter() {
+ @Override
public void mouseDoubleClick(MouseEvent e) {
Control content= getContent();
if (content != null && content.getBounds().contains(e.x, e.y))
@@ -98,6 +98,7 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider,
getTopLeft().addMouseListener(ml);
addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
if (fToolBarManager != null) {
fToolBarManager.removeAll();
@@ -121,6 +122,7 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider,
*/
protected Control createTopLeft(Composite parent) {
CLabel label = new CLabel(this, SWT.NONE) {
+ @Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(wHint, Math.max(24, hHint), changed);
}
@@ -190,6 +192,7 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider,
setTopCenter(tb);
fToolBarManager = new ToolBarManager(tb);
tb.getAccessible().addAccessibleListener(new AccessibleAdapter() {
+ @Override
public void getName(AccessibleEvent e) {
if (e.childID != ACC.CHILDID_SELF) {
ToolItem item = tb.getItem(e.childID);
@@ -228,50 +231,38 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider,
fInput= input;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- */
+ @Override
public void addSelectionChangedListener(ISelectionChangedListener l) {
fSelectionListeners.add(l);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- */
+ @Override
public void removeSelectionChangedListener(ISelectionChangedListener l) {
fSelectionListeners.remove(l);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
- */
+ @Override
public ISelection getSelection() {
return null;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
- */
+ @Override
public void setSelection(ISelection s) {
// Default is to do nothing
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
- */
+ @Override
public void selectionChanged(SelectionChangedEvent ev) {
- Object[] listeners= fSelectionListeners.getListeners();
- for (int i= 0; i < listeners.length; i++)
- ((ISelectionChangedListener) listeners[i]).selectionChanged(ev);
+ for (ISelectionChangedListener listener : fSelectionListeners) {
+ listener.selectionChanged(ev);
+ }
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent)
- */
+ @Override
public void doubleClick(DoubleClickEvent event) {
- Object[] listeners= fDoubleClickListener.getListeners();
- for (int i= 0; i < listeners.length; i++)
- ((IDoubleClickListener) listeners[i]).doubleClick(event);
+ for (IDoubleClickListener listener : fDoubleClickListener) {
+ listener.doubleClick(event);
+ }
}
/**
@@ -316,19 +307,15 @@ public class CompareViewerPane extends ViewForm implements ISelectionProvider,
fOpenListener.remove(listener);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.IOpenListener#open(org.eclipse.jface.viewers.OpenEvent)
- */
+ @Override
public void open(OpenEvent event) {
Object[] listeners= fOpenListener.getListeners();
for (int i= 0; i < listeners.length; i++)
((IOpenListener) listeners[i]).open(event);
}
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter(Class adapter) {
+ @Override
+ public <T> T getAdapter(Class<T> adapter) {
return Platform.getAdapterManager().getAdapter(this, adapter);
}
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
index ff983b0db..eea4162c9 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareViewerSwitchingPane.java
@@ -16,6 +16,7 @@ import org.eclipse.compare.internal.IFlushable2;
import org.eclipse.compare.internal.NullViewer;
import org.eclipse.compare.internal.Utilities;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
@@ -28,7 +29,6 @@ import org.eclipse.swt.widgets.Display;
import com.ibm.icu.text.MessageFormat;
-
/**
* A custom <code>CompareViewerPane</code> that supports dynamic viewer switching.
*
@@ -43,9 +43,8 @@ import com.ibm.icu.text.MessageFormat;
* @since 2.0
*/
public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
-
private Viewer fViewer;
- private boolean fControlVisibility= false;
+ private boolean fControlVisibility;
private String fTitle;
private String fTitleArgument;
@@ -91,6 +90,7 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
addDisposeListener(
new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
if (fViewer != null)
fViewer.removeSelectionChangedListener(CompareViewerSwitchingPane.this);
@@ -115,14 +115,12 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
}
private void setViewer(Viewer newViewer) {
-
if (newViewer == fViewer)
return;
boolean oldEmpty= isEmpty();
if (fViewer != null) {
-
fViewer.removeSelectionChangedListener(this);
if (fViewer instanceof StructuredViewer) {
@@ -138,7 +136,6 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
if (content != null && !content.isDisposed())
content.dispose();
-
} else {
oldEmpty= false;
}
@@ -199,18 +196,14 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
return fViewer == null || fViewer instanceof NullViewer;
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareViewerPane#getSelection()
- */
+ @Override
public ISelection getSelection() {
if (fViewer != null)
return fViewer.getSelection();
return super.getSelection();
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.CompareViewerPane#setSelection(org.eclipse.jface.viewers.ISelection)
- */
+ @Override
public void setSelection(ISelection s) {
if (fViewer != null)
fViewer.setSelection(s);
@@ -251,8 +244,8 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
*
* @param input the new input object or <code>null</code>
*/
+ @Override
public void setInput(Object input) {
-
if (!inputChanged(input))
return;
@@ -327,13 +320,10 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
setText(""); //$NON-NLS-1$
}
}
-
- /**
- * {@inheritDoc}
- * @since 3.3
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter(Class adapter) {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getAdapter(Class<T> adapter) {
if (adapter == INavigatable.class) {
if (isEmpty())
return null;
@@ -345,30 +335,28 @@ public abstract class CompareViewerSwitchingPane extends CompareViewerPane {
return null;
Object data= control.getData(INavigatable.NAVIGATOR_PROPERTY);
if (data instanceof INavigatable)
- return data;
+ return (T) data;
}
if (adapter == IFlushable.class) {
Viewer v= getViewer();
if (v != null) {
- IFlushable flushable = (IFlushable)Utilities.getAdapter(v, IFlushable.class);
+ IFlushable flushable = Adapters.adapt(v, IFlushable.class);
if (flushable != null)
- return flushable;
+ return (T) flushable;
}
}
if (adapter == IFlushable2.class) {
Viewer v= getViewer();
if (v != null) {
- IFlushable2 flushable = (IFlushable2)Utilities.getAdapter(v, IFlushable2.class);
+ IFlushable2 flushable = Adapters.adapt(v, IFlushable2.class);
if (flushable != null)
- return flushable;
+ return (T) flushable;
}
}
return super.getAdapter(adapter);
}
- /* (non-Javadoc)
- * @see org.eclipse.swt.widgets.Composite#setFocus()
- */
+ @Override
public boolean setFocus() {
Viewer v= getViewer();
if (v != null) {
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/SharedDocumentAdapter.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/SharedDocumentAdapter.java
index 1a0063495..9dade75ab 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/SharedDocumentAdapter.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/SharedDocumentAdapter.java
@@ -10,9 +10,9 @@
*******************************************************************************/
package org.eclipse.compare;
-import org.eclipse.compare.internal.Utilities;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.IDocument;
@@ -30,9 +30,9 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
* @since 3.3
*/
public abstract class SharedDocumentAdapter implements ISharedDocumentAdapter {
-
/**
- * Return the document provider for the given editor input.
+ * Returns the document provider for the given editor input.
+ *
* @param input the editor input
* @return the document provider for the given editor input
*/
@@ -40,17 +40,13 @@ public abstract class SharedDocumentAdapter implements ISharedDocumentAdapter {
return DocumentProviderRegistry.getDefault().getDocumentProvider(input);
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ISharedDocumentAdapter#connect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput)
- */
+ @Override
public void connect(IDocumentProvider provider, IEditorInput documentKey)
throws CoreException {
provider.connect(documentKey);
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ISharedDocumentAdapter#disconnect(org.eclipse.ui.texteditor.IDocumentProvider, org.eclipse.ui.IEditorInput)
- */
+ @Override
public void disconnect(IDocumentProvider provider, IEditorInput documentKey) {
provider.disconnect(documentKey);
}
@@ -60,6 +56,7 @@ public abstract class SharedDocumentAdapter implements ISharedDocumentAdapter {
* {@link FileEditorInput} for the element if the element adapts to {@link IFile}.
* @see org.eclipse.compare.ISharedDocumentAdapter#getDocumentKey(java.lang.Object)
*/
+ @Override
public IEditorInput getDocumentKey(Object element) {
IFile file = getFile(element);
if (file != null && file.exists()) {
@@ -76,11 +73,11 @@ public abstract class SharedDocumentAdapter implements ISharedDocumentAdapter {
return (IFile) resource;
}
}
- IFile file = (IFile)Utilities.getAdapter(element, IFile.class);
+ IFile file = Adapters.adapt(element, IFile.class);
if (file != null) {
return file;
}
- IResource resource = (IResource)Utilities.getAdapter(element, IResource.class);
+ IResource resource = Adapters.adapt(element, IResource.class);
if (resource instanceof IFile) {
return (IFile) resource;
}
@@ -109,9 +106,7 @@ public abstract class SharedDocumentAdapter implements ISharedDocumentAdapter {
}
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ISharedDocumentAdapter#disconnect(java.lang.Object)
- */
+ @Override
public void disconnect(Object element) {
IEditorInput input = getDocumentKey(element);
if (input == null)
@@ -121,5 +116,4 @@ public abstract class SharedDocumentAdapter implements ISharedDocumentAdapter {
return;
disconnect(provider, input);
}
-
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 21b5faf7d..9b4db1530 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -77,6 +77,7 @@ import org.eclipse.core.commands.operations.IUndoableOperation;
import org.eclipse.core.commands.operations.OperationHistoryEvent;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
@@ -208,8 +209,8 @@ import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
import com.ibm.icu.text.MessageFormat;
/**
- * A text merge viewer uses the <code>RangeDifferencer</code> to perform a
- * textual, line-by-line comparison of two (or three) input documents.
+ * A text merge viewer uses the <code>RangeDifferencer</code> to perform
+ * a textual, line-by-line comparison of two (or three) input documents.
* It is based on the <code>ContentMergeViewer</code> and uses <code>TextViewer</code>s
* to implement the ancestor, left, and right content areas.
* <p>
@@ -864,7 +865,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
private void connect(IDocumentProvider documentProvider, IEditorInput input) throws CoreException {
- final ISharedDocumentAdapter sda = (ISharedDocumentAdapter) Utilities.getAdapter(fElement, ISharedDocumentAdapter.class);
+ final ISharedDocumentAdapter sda = Adapters.adapt(fElement, ISharedDocumentAdapter.class);
if (sda != null) {
sda.connect(documentProvider, input);
} else {
@@ -873,7 +874,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
private void disconnect(IDocumentProvider provider, IEditorInput input) {
- final ISharedDocumentAdapter sda = (ISharedDocumentAdapter) Utilities.getAdapter(fElement, ISharedDocumentAdapter.class);
+ final ISharedDocumentAdapter sda = Adapters.adapt(fElement, ISharedDocumentAdapter.class);
if (sda != null) {
sda.disconnect(provider, input);
} else {
@@ -948,7 +949,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
if (fDocumentKey != null)
return fDocumentKey;
if (isUsingDefaultContentProvider() && fElement != null && canHaveSharedDocument()) {
- ISharedDocumentAdapter sda = (ISharedDocumentAdapter)Utilities.getAdapter(fElement, ISharedDocumentAdapter.class, true);
+ ISharedDocumentAdapter sda = Adapters.adapt(fElement, ISharedDocumentAdapter.class);
if (sda != null) {
return sda.getDocumentKey(fElement);
}
@@ -988,7 +989,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
IEditorInput input = getDocumentKey();
IDocument document = fDocumentProvider.getDocument(input);
if (document != null) {
- final ISharedDocumentAdapter sda = (ISharedDocumentAdapter) Utilities.getAdapter(fElement, ISharedDocumentAdapter.class);
+ final ISharedDocumentAdapter sda = Adapters.adapt(fElement, ISharedDocumentAdapter.class);
if (sda != null) {
sda.flushDocument(fDocumentProvider, input, document, false);
return true;
@@ -1124,7 +1125,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
return !ext.isReadOnly(fDocumentKey);
}
- IEditableContentExtension ext = (IEditableContentExtension)Utilities.getAdapter(fElement, IEditableContentExtension.class);
+ IEditableContentExtension ext = Adapters.adapt(fElement, IEditableContentExtension.class);
if (ext != null) {
if (ext.isReadOnly()) {
IStatus status = ext.validateEdit(getControl().getShell());
@@ -1543,7 +1544,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
@Override
public boolean isHunkOnLeft() {
ITypedElement left = ((ICompareInput)getInput()).getRight();
- return left != null && Utilities.getAdapter(left, IHunk.class) != null;
+ return left != null && Adapters.adapt(left, IHunk.class) != null;
}
@Override
public boolean isIgnoreAncestor() {
@@ -3053,7 +3054,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
}
} else {
if (isPatchHunk()) {
- if (right != null && Utilities.getAdapter(right, IHunk.class) != null)
+ if (right != null && Adapters.adapt(right, IHunk.class) != null)
fLeft.getSourceViewer().setTopIndex(getHunkStart());
else
fRight.getSourceViewer().setTopIndex(getHunkStart());
@@ -5435,13 +5436,13 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
if (input != null && input instanceof DiffNode){
ITypedElement right = ((DiffNode) input).getRight();
if (right != null) {
- Object element = Utilities.getAdapter(right, IHunk.class);
+ Object element = Adapters.adapt(right, IHunk.class);
if (element instanceof IHunk)
return ((IHunk)element).getStartPosition();
}
ITypedElement left = ((DiffNode) input).getLeft();
if (left != null) {
- Object element = Utilities.getAdapter(left, IHunk.class);
+ Object element = Adapters.adapt(left, IHunk.class);
if (element instanceof IHunk)
return ((IHunk)element).getStartPosition();
}
@@ -5603,6 +5604,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
return null;
}
@Override
+ @Deprecated
public IKeyBindingService getKeyBindingService() {
return null;
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java
index f1b6a24c1..eb43148a4 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContentViewerSwitchingPane.java
@@ -14,8 +14,15 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareEditorInput;
+import org.eclipse.compare.CompareViewerSwitchingPane;
+import org.eclipse.compare.Splitter;
+import org.eclipse.compare.internal.core.ComparePlugin;
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osgi.util.NLS;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.DisposeEvent;
@@ -39,22 +46,9 @@ import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.viewers.Viewer;
-
import org.eclipse.ui.PlatformUI;
-import org.eclipse.compare.CompareConfiguration;
-import org.eclipse.compare.CompareEditorInput;
-import org.eclipse.compare.CompareViewerSwitchingPane;
-import org.eclipse.compare.Splitter;
-import org.eclipse.compare.internal.core.ComparePlugin;
-import org.eclipse.compare.structuremergeviewer.ICompareInput;
-
-public class CompareContentViewerSwitchingPane extends
- CompareViewerSwitchingPane {
-
+public class CompareContentViewerSwitchingPane extends CompareViewerSwitchingPane {
private static final String OPTIMIZED_INFO_IMAGE_NAME = "obj16/message_info.png"; //$NON-NLS-1$
public static final String OPTIMIZED_ALGORITHM_USED = "OPTIMIZED_ALGORITHM_USED"; //$NON-NLS-1$
public static final String DISABLE_CAPPING_TEMPORARILY = "DISABLE_CAPPING_TEMPORARILY"; //$NON-NLS-1$
@@ -64,27 +58,27 @@ public class CompareContentViewerSwitchingPane extends
private ViewerDescriptor fSelectedViewerDescriptor;
private ToolBar toolBar;
- private CLabel clOptimized;
+ private CLabel labelOptimized;
private Link recomputeLink;
private boolean menuShowing;
public CompareContentViewerSwitchingPane(Splitter parent, int style,
- CompareEditorInput cei) {
+ CompareEditorInput editorInput) {
super(parent, style);
- fCompareEditorInput = cei;
+ fCompareEditorInput = editorInput;
}
private CompareConfiguration getCompareConfiguration() {
return fCompareEditorInput.getCompareConfiguration();
}
+ @Override
protected Viewer getViewer(Viewer oldViewer, Object input) {
if (fSelectedViewerDescriptor != null) {
ViewerDescriptor[] array = CompareUIPlugin.getDefault().findContentViewerDescriptor(
oldViewer, input, getCompareConfiguration());
- List list = array != null ? Arrays.asList(array)
- : Collections.EMPTY_LIST;
+ List<ViewerDescriptor> list = array != null ? Arrays.asList(array) : Collections.emptyList();
if (list.contains(fSelectedViewerDescriptor)) {
// use selected viewer only when appropriate for the new input
fCompareEditorInput
@@ -93,21 +87,23 @@ public class CompareContentViewerSwitchingPane extends
oldViewer, (ICompareInput) input, this);
return viewer;
}
- // fallback to default otherwise
+ // Fallback to default otherwise
fSelectedViewerDescriptor = null;
}
if (input instanceof ICompareInput) {
fCompareEditorInput.setContentViewerDescriptor(null);
- Viewer viewer = fCompareEditorInput.findContentViewer(oldViewer,
- (ICompareInput) input, this);
+ Viewer viewer =
+ fCompareEditorInput.findContentViewer(oldViewer, (ICompareInput) input, this);
fCompareEditorInput.setContentViewerDescriptor(fSelectedViewerDescriptor);
return viewer;
}
return null;
}
+ @Override
protected Control createTopLeft(Composite p) {
final Composite composite = new Composite(p, SWT.NONE) {
+ @Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(wHint, Math.max(24, hHint), changed);
}
@@ -127,27 +123,29 @@ public class CompareContentViewerSwitchingPane extends
final ToolItem toolItem = new ToolItem(toolBar, SWT.PUSH, 0);
toolItem.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(
/* IWorkbenchGraphicConstants */"IMG_LCL_VIEW_MENU")); //$NON-NLS-1$
- toolItem
- .setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_switchButtonTooltip);
+ toolItem.setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_switchButtonTooltip);
toolItem.addSelectionListener(new SelectionAdapter() {
+ @Override
public void widgetSelected(SelectionEvent e) {
showMenu();
}
});
toolBar.addMouseListener(new MouseAdapter() {
+ @Override
public void mouseDown(MouseEvent e) {
showMenu();
}
});
- clOptimized = new CLabel(composite, SWT.NONE);
- clOptimized.setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_optimizedTooltip);
- clOptimized.setImage(CompareUIPlugin.getImageDescriptor(
+ labelOptimized = new CLabel(composite, SWT.NONE);
+ labelOptimized.setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_optimizedTooltip);
+ labelOptimized.setImage(CompareUIPlugin.getImageDescriptor(
OPTIMIZED_INFO_IMAGE_NAME).createImage());
- clOptimized.setVisible(false); // hide by default
- clOptimized.addDisposeListener(new DisposeListener() {
+ labelOptimized.setVisible(false); // hide by default
+ labelOptimized.addDisposeListener(new DisposeListener() {
+ @Override
public void widgetDisposed(DisposeEvent e) {
- Image img = clOptimized.getImage();
+ Image img = labelOptimized.getImage();
if ((img != null) && (!img.isDisposed())) {
img.dispose();
}
@@ -158,6 +156,7 @@ public class CompareContentViewerSwitchingPane extends
recomputeLink.setText(CompareMessages.CompareContentViewerSwitchingPane_optimizedLinkLabel);
recomputeLink.setToolTipText(CompareMessages.CompareContentViewerSwitchingPane_optimizedTooltip);
recomputeLink.addSelectionListener(new SelectionAdapter() {
+ @Override
public void widgetSelected(SelectionEvent e) {
/*
* Disable capping temporarily, refresh, restore global state.
@@ -182,23 +181,24 @@ public class CompareContentViewerSwitchingPane extends
return composite;
}
+ @Override
protected boolean inputChanged(Object input) {
return getInput() != input
|| fCompareEditorInput.getContentViewerDescriptor() != fSelectedViewerDescriptor;
}
+ @Override
public void setInput(Object input) {
super.setInput(input);
if (getViewer() == null || !Utilities.okToUse(getViewer().getControl()))
return;
ViewerDescriptor[] vd = CompareUIPlugin.getDefault()
- .findContentViewerDescriptor(getViewer(), getInput(),
- getCompareConfiguration());
+ .findContentViewerDescriptor(getViewer(), getInput(), getCompareConfiguration());
toolBar.setVisible(vd != null && vd.length > 1);
CompareConfiguration cc = getCompareConfiguration();
Boolean isOptimized = (Boolean) cc.getProperty(OPTIMIZED_ALGORITHM_USED);
boolean optimizedVisible = isOptimized != null && isOptimized.booleanValue();
- clOptimized.setVisible(optimizedVisible);
+ labelOptimized.setVisible(optimizedVisible);
recomputeLink.setVisible(optimizedVisible);
}
@@ -208,13 +208,12 @@ public class CompareContentViewerSwitchingPane extends
menuShowing= true;
ViewerDescriptor[] vd = CompareUIPlugin.getDefault()
- .findContentViewerDescriptor(getViewer(), getInput(),
- getCompareConfiguration());
+ .findContentViewerDescriptor(getViewer(), getInput(),getCompareConfiguration());
- // 1. create
+ // 1. Create
final Menu menu = new Menu(getShell(), SWT.POP_UP);
- // add default
+ // Add default
String label = CompareMessages.CompareContentViewerSwitchingPane_defaultViewer;
MenuItem defaultItem = new MenuItem(menu, SWT.RADIO);
defaultItem.setText(label);
@@ -223,16 +222,16 @@ public class CompareContentViewerSwitchingPane extends
new MenuItem(menu, SWT.SEPARATOR);
- // add others
+ // Add others
for (int i = 0; i < vd.length; i++) {
final ViewerDescriptor vdi = vd[i];
label = vdi.getLabel();
- if (label == null || label.equals("")) { //$NON-NLS-1$
- String l = CompareUIPlugin.getDefault().findContentTypeNameOrType((ICompareInput) getInput(), vdi, getCompareConfiguration());
+ if (label == null || label.isEmpty()) {
+ String l = CompareUIPlugin.getDefault().findContentTypeNameOrType((ICompareInput) getInput(),
+ vdi, getCompareConfiguration());
if (l == null)
- // couldn't figure out the label, skip the viewer
- continue;
- label = NLS.bind(CompareMessages.CompareContentViewerSwitchingPane_discoveredLabel, new Object[] {l});
+ continue; // Couldn't figure out the label, skip the viewer
+ label = NLS.bind(CompareMessages.CompareContentViewerSwitchingPane_discoveredLabel, l);
}
MenuItem item = new MenuItem(menu, SWT.RADIO);
item.setText(label);
@@ -240,18 +239,20 @@ public class CompareContentViewerSwitchingPane extends
item.setSelection(vdi == fSelectedViewerDescriptor);
}
- // 2. show
+ // 2. Show
Rectangle bounds = toolBar.getItem(0).getBounds();
Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
topLeft = toolBar.toDisplay(topLeft);
menu.setLocation(topLeft.x, topLeft.y);
menu.setVisible(true);
- // 3. dispose on close
+ // 3. Dispose on close
menu.addMenuListener(new MenuAdapter() {
+ @Override
public void menuHidden(MenuEvent e) {
menuShowing= false;
e.display.asyncExec(new Runnable() {
+ @Override
public void run() {
menu.dispose();
}
@@ -262,30 +263,31 @@ public class CompareContentViewerSwitchingPane extends
private SelectionListener createSelectionListener(final ViewerDescriptor vd) {
return new SelectionListener() {
+ @Override
public void widgetSelected(SelectionEvent e) {
MenuItem mi = (MenuItem) e.widget;
if (mi.getSelection()) {
Viewer oldViewer = getViewer();
fSelectedViewerDescriptor = vd;
- CompareContentViewerSwitchingPane.this.setInput(oldViewer
- .getInput());
+ CompareContentViewerSwitchingPane.this.setInput(oldViewer.getInput());
}
}
+ @Override
public void widgetDefaultSelected(SelectionEvent e) {
- // nothing to do
+ // Nothing to do
}
};
}
- public void setText(String label) {
+ @Override
+ public void setText(String text) {
Composite c = (Composite) getTopLeft();
- Control[] children = c.getChildren();
- for (int i = 0; i < children.length; i++) {
- if (children[i] instanceof CLabel) {
- CLabel cl = (CLabel) children[i];
- if (cl != null && !cl.isDisposed()) {
- cl.setText(label);
+ for (Control child : c.getChildren()) {
+ if (child instanceof CLabel) {
+ CLabel label = (CLabel) child;
+ if (label != null && !label.isDisposed()) {
+ label.setText(text);
c.layout();
}
return;
@@ -293,28 +295,27 @@ public class CompareContentViewerSwitchingPane extends
}
}
+ @Override
public void setImage(Image image) {
Composite c = (Composite) getTopLeft();
- Control[] children = c.getChildren();
- for (int i = 0; i < children.length; i++) {
- if (children[i] instanceof CLabel) {
- CLabel cl = (CLabel) children[i];
- if (cl != null && !cl.isDisposed())
- cl.setImage(image);
+ for (Control child : c.getChildren()) {
+ if (child instanceof CLabel) {
+ CLabel label = (CLabel) child;
+ if (label != null && !label.isDisposed())
+ label.setImage(image);
return;
}
}
}
+ @Override
public void addMouseListener(MouseListener listener) {
Composite c = (Composite) getTopLeft();
- Control[] children = c.getChildren();
- for (int i = 0; i < children.length; i++) {
- if (children[i] instanceof CLabel) {
- CLabel cl = (CLabel) children[i];
- cl.addMouseListener(listener);
+ for (Control child : c.getChildren()) {
+ if (child instanceof CLabel) {
+ CLabel label = (CLabel) child;
+ label.addMouseListener(listener);
}
}
}
-
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
index efbe3f056..f8ea37b3c 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
@@ -12,11 +12,13 @@ package org.eclipse.compare.internal;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.IPropertyChangeNotifier;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -71,8 +73,9 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
* A CompareEditor takes a ICompareEditorInput as input.
* Most functionality is delegated to the ICompareEditorInput.
*/
-public class CompareEditor extends EditorPart implements IReusableEditor, ISaveablesSource, IPropertyChangeListener, ISaveablesLifecycleListener {
-
+public class CompareEditor extends EditorPart
+ implements IReusableEditor, ISaveablesSource, IPropertyChangeListener,
+ ISaveablesLifecycleListener {
public final static String CONFIRM_SAVE_PROPERTY= "org.eclipse.compare.internal.CONFIRM_SAVE_PROPERTY"; //$NON-NLS-1$
private static final int UNINITIALIZED = 0;
@@ -84,11 +87,11 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
private static final int STILL_INITIALIZING = 6;
private static final int CREATING_CONTROL = 7;
private static final int DONE = 8;
-
+
private IActionBars fActionBars;
-
+
private PageBook fPageBook;
-
+
/** the SWT control from the compare editor input*/
private Control fControl;
/** the outline page */
@@ -98,17 +101,14 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
private Control initializingPage;
private Control emptyPage;
-
+
private int state = UNINITIALIZED;
- private HashSet knownSaveables;
+ private HashSet<Saveable> knownSaveables;
private final EditorCompareContainer fContainer = new EditorCompareContainer();
private class EditorCompareContainer extends CompareContainer {
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareContainer#registerContextMenu(org.eclipse.jface.action.MenuManager, org.eclipse.jface.viewers.ISelectionProvider)
- */
+ @Override
public void registerContextMenu(MenuManager menu, ISelectionProvider provider) {
if (getSite() instanceof IEditorSite) {
IEditorSite es = (IEditorSite) getSite();
@@ -116,9 +116,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareContainer#setStatusMessage(java.lang.String)
- */
+ @Override
public void setStatusMessage(String message) {
if (fActionBars != null) {
IStatusLineManager slm= fActionBars.getStatusLineManager();
@@ -127,19 +125,16 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.ICompareContainer#getServiceLocator()
- */
+
+ @Override
public IServiceLocator getServiceLocator() {
return getSite();
}
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.internal.CompareContainer#createWorkerJob()
- */
+
+ @Override
protected WorkerJob createWorkerJob() {
WorkerJob workerJob = new WorkerJob(getWorkerJobName()) {
+ @Override
public boolean belongsTo(Object family) {
if (family == CompareEditor.this)
return true;
@@ -148,41 +143,33 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
};
return workerJob;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.internal.CompareContainer#getWorkerJobName()
- */
+
+ @Override
protected String getWorkerJobName() {
return NLS.bind(CompareMessages.CompareEditor_2, getTitle());
}
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.internal.CompareContainer#getWorkbenchPart()
- */
+
+ @Override
public IWorkbenchPart getWorkbenchPart() {
return CompareEditor.this;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.compare.internal.CompareContainer#getActionBars()
- */
+
+ @Override
public IActionBars getActionBars() {
return CompareEditor.this.getActionBars();
}
}
-
+
/**
* No-argument constructor required for extension points.
*/
public CompareEditor() {
// empty default implementation
}
-
- /* (non-Javadoc)
- * Method declared on IAdaptable
- */
- public Object getAdapter(Class key) {
-
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getAdapter(Class<T> key) {
if (key.equals(IContentOutlinePage.class)) {
Object object= getCompareConfiguration().getProperty(CompareConfiguration.USE_OUTLINE_VIEW);
if (object instanceof Boolean && ((Boolean)object).booleanValue()) {
@@ -190,59 +177,54 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
if (fOutlinePage.getControl() != null && fOutlinePage.getControl().isDisposed()) {
fOutlinePage = null;
} else {
- return fOutlinePage;
+ return (T) fOutlinePage;
}
}
fOutlinePage= new CompareOutlinePage(this);
- return fOutlinePage;
+ return (T) fOutlinePage;
}
}
-
+
if (key == IShowInSource.class
|| key == OutlineViewerCreator.class
|| key == IFindReplaceTarget.class) {
Object input = getEditorInput();
if (input != null) {
- return Utilities.getAdapter(input, key);
+ return Adapters.adapt(input, key);
}
}
-
+
if (key == IEditorInput.class) {
- return getEditorInput().getAdapter(IEditorInput.class);
+ return (T) Adapters.adapt(getEditorInput(), IEditorInput.class);
}
-
+
if (key == ITextEditorExtension3.class) {
- return getEditorInput().getAdapter(ITextEditorExtension3.class);
+ return (T) Adapters.adapt(getEditorInput(), ITextEditorExtension3.class);
}
return super.getAdapter(key);
}
-
+
/*
* Helper method used by ComapreEditorConfiguration to get at the compare configuration of the editor
*/
- /* package */ CompareConfiguration getCompareConfiguration() {
+ CompareConfiguration getCompareConfiguration() {
IEditorInput input= getEditorInput();
if (input instanceof CompareEditorInput)
return ((CompareEditorInput)input).getCompareConfiguration();
return null;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
- */
+
+ @Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
-
if (!(input instanceof CompareEditorInput))
throw new PartInitException(Utilities.getString("CompareEditor.invalidInput")); //$NON-NLS-1$
-
+
setSite(site);
setInput(input);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
- */
+
+ @Override
public void setInput(IEditorInput input) {
if (!(input instanceof CompareEditorInput)) {
IStatus s= new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, Utilities.getString("CompareEditor.invalidInput"), null); //$NON-NLS-1$
@@ -266,7 +248,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
}
-
+
private void doSetInput(IEditorInput input) {
IEditorInput oldInput= getEditorInput();
disconnectFromInput(oldInput);
@@ -284,34 +266,34 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
fControl = null;
}
}
-
+
super.setInput(input);
-
+
if (fOutlinePage != null)
fOutlinePage.reset();
-
+
final CompareEditorInput cei= (CompareEditorInput) input;
cei.setContainer(fContainer);
setTitleImage(cei.getTitleImage());
setPartName(cei.getTitle());
setTitleToolTip(cei.getToolTipText());
-
+
if (input instanceof IPropertyChangeNotifier)
((IPropertyChangeNotifier)input).addPropertyChangeListener(this);
-
+
setState(cei.getCompareResult() == null ? INITIALIZING : INITIALIZED);
if (fPageBook != null)
createCompareControl();
if (fControl != null && oldSize != null)
fControl.setSize(oldSize);
-
+
boolean hasResult = cei.getCompareResult() != null;
if (!hasResult) {
initializeInBackground(cei, hadPreviousInput);
}
-
+
firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
-
+
// We only need to notify of new Saveables if we are changing inputs
if (hadPreviousInput && hasResult) {
registerSaveable();
@@ -326,23 +308,23 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
private void disconnectFromInput(IEditorInput oldInput) {
if (oldInput != null) {
-
if (oldInput instanceof IPropertyChangeNotifier)
((IPropertyChangeNotifier)oldInput).removePropertyChangeListener(this);
-
+
// Let the workbench know that the old input's saveables are no longer needed
if (knownSaveables != null && !knownSaveables.isEmpty()) {
ISaveablesLifecycleListener lifecycleListener= getSite().getService(ISaveablesLifecycleListener.class);
lifecycleListener.handleLifecycleEvent(
- new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, (Saveable[]) knownSaveables.toArray(new Saveable[knownSaveables.size()]), false));
+ new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, knownSaveables.toArray(new Saveable[knownSaveables.size()]), false));
knownSaveables.clear();
}
}
}
-
+
protected void initializeInBackground(final CompareEditorInput cei, final boolean hadPreviousInput) {
// Need to cancel any running jobs associated with the oldInput
Job job = new Job(NLS.bind(CompareMessages.CompareEditor_0, cei.getTitle())) {
+ @Override
protected IStatus run(final IProgressMonitor monitor) {
final int[] newState = new int[] { ERROR };
try {
@@ -365,6 +347,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
if (monitor.isCanceled())
newState[0] = CANCELED;
Display.getDefault().syncExec(new Runnable() {
+ @Override
public void run() {
if (fPageBook.isDisposed())
return;
@@ -381,6 +364,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
monitor.done();
}
}
+ @Override
public boolean belongsTo(Object family) {
if (family == CompareEditor.this || family == cei)
return true;
@@ -397,17 +381,15 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
public IActionBars getActionBars() {
return fActionBars;
}
-
- /*
- * Set the action bars so the Utilities class can access it.
+
+ /**
+ * Sets the action bars so the Utilities class can access it.
*/
- /* package */ void setActionBars(IActionBars actionBars) {
+ void setActionBars(IActionBars actionBars) {
fActionBars= actionBars;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
- */
+
+ @Override
public void createPartControl(Composite parent) {
parent.setData(this);
fPageBook = new PageBook(parent, SWT.NONE);
@@ -476,13 +458,14 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
}
-
+
private boolean isActive() {
return getSite().getPage().getActivePart() == this;
}
private void setPageLater() {
Display.getCurrent().timerExec(1000, new Runnable() {
+ @Override
public void run() {
synchronized(CompareEditor.this) {
if (getState() == INITIALIZING) {
@@ -494,49 +477,42 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
});
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.WorkbenchPart#dispose()
- */
+ @Override
public void dispose() {
IEditorInput input= getEditorInput();
if (input instanceof IPropertyChangeNotifier)
((IPropertyChangeNotifier)input).removePropertyChangeListener(this);
super.dispose();
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
- */
+
+ @Override
public void setFocus() {
IEditorInput input= getEditorInput();
if (input instanceof CompareEditorInput)
if (!((CompareEditorInput)input).setFocus2())
fPageBook.setFocus();
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.EditorPart#isSaveAsAllowed()
- */
+
+ @Override
public boolean isSaveAsAllowed() {
return false;
}
-
+
/* (non-Javadoc)
* Always throws an AssertionFailedException.
* @see org.eclipse.ui.part.EditorPart#doSaveAs()
*/
+ @Override
public void doSaveAs() {
Assert.isTrue(false); // Save As not supported for CompareEditor
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
- */
+
+ @Override
public void doSave(IProgressMonitor progressMonitor) {
-
final IEditorInput input= getEditorInput();
-
+
WorkspaceModifyOperation operation= new WorkspaceModifyOperation() {
+ @Override
public void execute(IProgressMonitor pm) throws CoreException {
if (input instanceof CompareEditorInput)
((CompareEditorInput)input).saveChanges(pm);
@@ -544,13 +520,10 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
};
Shell shell= getSite().getShell();
-
+
try {
-
operation.run(progressMonitor);
-
firePropertyChange(PROP_DIRTY);
-
} catch (InterruptedException x) {
// NeedWork
} catch (OperationCanceledException x) {
@@ -561,20 +534,16 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
MessageDialog.openError(shell, title, Utilities.getFormattedString("CompareEditor.cantSaveError", reason)); //$NON-NLS-1$
}
}
-
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.EditorPart#isDirty()
- */
+
+ @Override
public boolean isDirty() {
IEditorInput input= getEditorInput();
if (input instanceof CompareEditorInput)
return ((CompareEditorInput)input).isDirty();
return false;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
- */
+
+ @Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(CompareEditorInput.DIRTY_STATE)) {
Object old_value= event.getOldValue();
@@ -589,9 +558,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.ISaveablesSource#getModels()
- */
+ @Override
public Saveable[] getSaveables() {
return internalGetSaveables(knownSaveables == null);
}
@@ -617,7 +584,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
return sourceSaveables;
}
-
+
private boolean isAllSaveablesKnown() {
IEditorInput input= getEditorInput();
Saveable[] sourceSaveables = getSaveables(input);
@@ -638,11 +605,8 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
private void recordSaveables(Saveable[] sourceSaveables) {
if (knownSaveables == null)
- knownSaveables = new HashSet();
- for (int i = 0; i < sourceSaveables.length; i++) {
- Saveable saveable = sourceSaveables[i];
- knownSaveables.add(saveable);
- }
+ knownSaveables = new HashSet<>();
+ Collections.addAll(knownSaveables, sourceSaveables);
}
private Saveable[] getSaveables(IEditorInput input) {
@@ -660,9 +624,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
return fSaveable;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.ISaveablesSource#getActiveModels()
- */
+ @Override
public Saveable[] getActiveSaveables() {
IEditorInput input= getEditorInput();
if (input instanceof ISaveablesSource) {
@@ -671,53 +633,60 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
}
return new Saveable[] { getSaveable() };
}
-
+
private class CompareSaveable extends Saveable {
+ @Override
public String getName() {
return CompareEditor.this.getPartName();
}
+ @Override
public String getToolTipText() {
return CompareEditor.this.getTitleToolTip();
}
+ @Override
public ImageDescriptor getImageDescriptor() {
return ImageDescriptor.createFromImage(CompareEditor.this.getTitleImage());
}
+ @Override
public void doSave(IProgressMonitor monitor) throws CoreException {
CompareEditor.this.doSave(monitor);
}
+ @Override
public boolean isDirty() {
return CompareEditor.this.isDirty();
}
+ @Override
public boolean equals(Object object) {
return object == this;
}
+ @Override
public int hashCode() {
return CompareEditor.this.hashCode();
}
}
-
+
private Composite getInitializingMessagePane(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setBackground(getBackgroundColor(parent));
GridLayout layout = new GridLayout();
layout.numColumns = 3;
composite.setLayout(layout);
-
+
createDescriptionLabel(composite, CompareMessages.CompareEditor_1);
return composite;
}
-
+
private Color getBackgroundColor(Composite parent) {
return parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
}
-
+
private Label createDescriptionLabel(Composite parent, String text) {
Label description = new Label(parent, SWT.WRAP);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
@@ -727,7 +696,7 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
description.setBackground(getBackgroundColor(parent));
return description;
}
-
+
private void closeEditor() {
getSite().getPage().closeEditor(CompareEditor.this, false);
}
@@ -740,14 +709,16 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
return state;
}
+ @Override
public void handleLifecycleEvent(SaveablesLifecycleEvent event) {
- ISaveablesLifecycleListener lifecycleListener= getSite().getService(ISaveablesLifecycleListener.class);
+ ISaveablesLifecycleListener lifecycleListener=
+ getSite().getService(ISaveablesLifecycleListener.class);
if (event.getEventType() == SaveablesLifecycleEvent.POST_CLOSE) {
// We may get a post close for a saveable that is not known to the workbench.
// Only pass on the event for known saveables
if (knownSaveables == null || knownSaveables.isEmpty())
return;
- java.util.List result = new ArrayList();
+ java.util.List<Saveable> result = new ArrayList<>();
Saveable[] all = event.getSaveables();
for (int i = 0; i < all.length; i++) {
Saveable saveable = all[i];
@@ -759,13 +730,11 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
return;
event = new SaveablesLifecycleEvent(this,
SaveablesLifecycleEvent.POST_CLOSE,
- (Saveable[]) result.toArray(new Saveable[result.size()]),
+ result.toArray(new Saveable[result.size()]),
false);
} else if (event.getEventType() == SaveablesLifecycleEvent.POST_OPEN) {
recordSaveables(event.getSaveables());
}
lifecycleListener.handleLifecycleEvent(event);
}
-
}
-
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareOutlinePage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareOutlinePage.java
index 8ff6bf53d..dafaef4f3 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareOutlinePage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareOutlinePage.java
@@ -10,11 +10,17 @@
*******************************************************************************/
package org.eclipse.compare.internal;
-import org.eclipse.compare.*;
+import org.eclipse.compare.CompareConfiguration;
+import org.eclipse.compare.CompareViewerSwitchingPane;
+import org.eclipse.compare.Splitter;
import org.eclipse.compare.structuremergeviewer.ICompareInput;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
-import org.eclipse.jface.viewers.*;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -22,10 +28,7 @@ import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.part.Page;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-/**
- */
public class CompareOutlinePage extends Page implements IContentOutlinePage, IPropertyChangeListener {
-
private CompareEditor fCompareEditor;
private Control fControl;
private CompareViewerSwitchingPane fStructurePane;
@@ -35,12 +38,11 @@ public class CompareOutlinePage extends Page implements IContentOutlinePage, IPr
fCompareEditor= editor;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
- */
+ @Override
public void createControl(Composite parent) {
final Splitter h= new Splitter(parent, SWT.HORIZONTAL);
fStructurePane= new CompareViewerSwitchingPane(h, SWT.BORDER | SWT.FLAT, true) {
+ @Override
protected Viewer getViewer(Viewer oldViewer, Object input) {
if (input instanceof ICompareInput)
return findStructureViewer(oldViewer, (ICompareInput)input, this);
@@ -66,49 +68,37 @@ public class CompareOutlinePage extends Page implements IContentOutlinePage, IPr
return fCompareEditor.getCompareConfiguration();
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.IPage#getControl()
- */
+ @Override
public Control getControl() {
return fControl;
}
- /* (non-Javadoc)
- * @see org.eclipse.ui.part.IPage#setFocus()
- */
+ @Override
public void setFocus() {
if (fStructurePane != null)
fStructurePane.setFocus();
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- */
+ @Override
public void addSelectionChangedListener(ISelectionChangedListener listener) {
if (fStructurePane != null)
fStructurePane.addSelectionChangedListener(listener);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
- */
+ @Override
public ISelection getSelection() {
if (fStructurePane != null)
return fStructurePane.getSelection();
return StructuredSelection.EMPTY;
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- */
+ @Override
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
if (fStructurePane != null)
fStructurePane.removeSelectionChangedListener(listener);
}
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
- */
+ @Override
public void setSelection(ISelection selection) {
if (fStructurePane != null)
fStructurePane.setSelection(selection);
@@ -123,13 +113,14 @@ public class CompareOutlinePage extends Page implements IContentOutlinePage, IPr
public OutlineViewerCreator getCreator() {
if (fCreator == null) {
- fCreator = (OutlineViewerCreator)Utilities.getAdapter(fCompareEditor, OutlineViewerCreator.class);
+ fCreator = Adapters.adapt(fCompareEditor, OutlineViewerCreator.class);
if (fCreator != null)
fCreator.addPropertyChangeListener(this);
}
return fCreator;
}
+ @Override
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(OutlineViewerCreator.PROP_INPUT)) {
fStructurePane.setInput(event.getNewValue());
@@ -137,6 +128,7 @@ public class CompareOutlinePage extends Page implements IContentOutlinePage, IPr
}
}
+ @Override
public void dispose() {
super.dispose();
if (fCreator != null)
@@ -149,9 +141,10 @@ public class CompareOutlinePage extends Page implements IContentOutlinePage, IPr
fCreator.removePropertyChangeListener(this);
fCreator = null;
OutlineViewerCreator creator = getCreator();
- if (creator != null)
+ if (creator != null) {
setInput(creator.getInput());
- else
+ } else {
setInput(null);
+ }
}
}
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;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java
index 8bfd5412d..4b6eca613 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/StreamMergerDescriptor.java
@@ -18,11 +18,10 @@ import org.eclipse.core.runtime.IConfigurationElement;
* A factory proxy for creating a StructureCreator.
*/
class StreamMergerDescriptor {
-
private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
-
+
private IConfigurationElement fElement;
-
+
/*
* Creates a new sorter node with the given configuration element.
*/
@@ -35,7 +34,7 @@ class StreamMergerDescriptor {
*/
public IStreamMerger createStreamMerger() {
try {
- return (IStreamMerger)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
+ return (IStreamMerger) fElement.createExecutableExtension(CLASS_ATTRIBUTE);
} catch (CoreException ex) {
//ExceptionHandler.handle(ex, SearchMessages.getString("Search.Error.createSorter.title"), SearchMessages.getString("Search.Error.createSorter.message")); //$NON-NLS-2$ //$NON-NLS-1$
return null;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
index 5565336e5..73a8e9bc7 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/Utilities.java
@@ -18,12 +18,10 @@ import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.MissingResourceException;
@@ -51,17 +49,16 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
@@ -98,14 +95,13 @@ import com.ibm.icu.text.MessageFormat;
* Convenience and utility methods.
*/
public class Utilities {
-
private static final IPath ICONS_PATH= new Path("$nl$/icons/full/"); //$NON-NLS-1$
-
+
public static IWorkbenchPartSite findSite(Control c) {
while (c != null && !c.isDisposed()) {
Object data= c.getData();
if (data instanceof IWorkbenchPart)
- return ((IWorkbenchPart)data).getSite();
+ return ((IWorkbenchPart) data).getSite();
c= c.getParent();
}
return null;
@@ -115,13 +111,13 @@ public class Utilities {
while (c != null && !c.isDisposed()) {
Object data= c.getData();
if (data instanceof CompareEditor)
- return ((CompareEditor)data).getActionBars();
-
+ return ((CompareEditor) data).getActionBars();
+
// PR 1GDVZV7: ITPVCM:WIN98 - CTRL + C does not work in Java source compare
if (data instanceof IViewPart)
- return ((IViewPart)data).getViewSite().getActionBars();
+ return ((IViewPart) data).getViewSite().getActionBars();
// end PR 1GDVZV7
-
+
c= c.getParent();
}
return null;
@@ -141,48 +137,39 @@ public class Utilities {
}
return dflt;
}
-
+
/**
* Returns the active compare filters for the compare configuration
- *
+ *
* @param cc
* @return the active compare filters
*/
public static ICompareFilter[] getCompareFilters(CompareConfiguration cc) {
if (cc != null) {
- Object value = cc
- .getProperty(ChangeCompareFilterPropertyAction.COMPARE_FILTERS);
+ Object value = cc.getProperty(ChangeCompareFilterPropertyAction.COMPARE_FILTERS);
if (value instanceof Map) {
- Map filtersMap = (Map) value;
- return (ICompareFilter[]) filtersMap.values().toArray(
- new ICompareFilter[filtersMap.size()]);
+ @SuppressWarnings("unchecked")
+ Map<String, ICompareFilter[]> filtersMap = (Map<String, ICompareFilter[]>) value;
+ return filtersMap.values().toArray(new ICompareFilter[filtersMap.size()]);
}
}
return new ICompareFilter[0];
}
- public static void firePropertyChange(ListenerList listenerList, Object source, String property, Object old, Object newValue) {
+ public static void firePropertyChange(ListenerList<IPropertyChangeListener> listenerList, Object source, String property, Object old, Object newValue) {
PropertyChangeEvent event= new PropertyChangeEvent(source, property, old, newValue);
firePropertyChange(listenerList, event);
}
-
- public static void firePropertyChange(final ListenerList listenerList, final PropertyChangeEvent event) {
+
+ public static void firePropertyChange(final ListenerList<IPropertyChangeListener> listenerList, final PropertyChangeEvent event) {
if (listenerList == null || listenerList.isEmpty())
return;
// Legacy listeners may expect to get notified in the UI thread
Runnable runnable = new Runnable() {
+ @Override
public void run() {
- Object[] listeners= listenerList.getListeners();
- for (int i= 0; i < listeners.length; i++) {
- final IPropertyChangeListener listener= (IPropertyChangeListener) listeners[i];
- SafeRunner.run(new ISafeRunnable() {
- public void run() throws Exception {
- listener.propertyChange(event);
- }
- public void handleException(Throwable exception) {
- // Logged by SafeRunner
- }
- });
+ for (IPropertyChangeListener listener : listenerList) {
+ SafeRunner.run(() -> listener.propertyChange(event));
}
}
};
@@ -196,18 +183,17 @@ public class Utilities {
public static boolean okToUse(Widget widget) {
return widget != null && !widget.isDisposed();
}
-
- private static ArrayList internalGetResources(ISelection selection, Class type) {
- ArrayList tmp= new ArrayList();
+
+ private static ArrayList<IResource> internalGetResources(ISelection selection, Class<? extends IResource> type) {
+ ArrayList<IResource> tmp= new ArrayList<>();
if (selection instanceof IStructuredSelection) {
- Object[] s= ((IStructuredSelection)selection).toArray();
-
+ Object[] s= ((IStructuredSelection) selection).toArray();
+
for (int i= 0; i < s.length; i++) {
IResource resource= null;
Object o= s[i];
if (type.isInstance(o)) {
resource= (IResource) o;
-
} else if (o instanceof ResourceMapping) {
try {
ResourceTraversal[] travs= ((ResourceMapping)o).getTraversals(ResourceMappingContext.LOCAL_CONTEXT, null);
@@ -229,7 +215,7 @@ public class Utilities {
if (type.isInstance(adapter))
resource= (IResource) adapter;
}
-
+
if (resource != null && resource.isAccessible())
tmp.add(resource);
}
@@ -237,38 +223,37 @@ public class Utilities {
return tmp;
}
-
/*
* Convenience method: extract all accessible <code>IResources</code> from given selection.
* Never returns null.
*/
public static IResource[] getResources(ISelection selection) {
- ArrayList tmp= internalGetResources(selection, IResource.class);
- return (IResource[]) tmp.toArray(new IResource[tmp.size()]);
+ ArrayList<IResource> tmp= internalGetResources(selection, IResource.class);
+ return tmp.toArray(new IResource[tmp.size()]);
}
-
+
/*
* Convenience method: extract all accessible <code>IFiles</code> from given selection.
* Never returns null.
*/
public static IFile[] getFiles(ISelection selection) {
- ArrayList tmp= internalGetResources(selection, IFile.class);
- return (IFile[]) tmp.toArray(new IFile[tmp.size()]);
+ ArrayList<IResource> tmp= internalGetResources(selection, IFile.class);
+ return tmp.toArray(new IFile[tmp.size()]);
}
public static byte[] readBytes(InputStream in) {
ByteArrayOutputStream bos= new ByteArrayOutputStream();
- try {
+ try {
while (true) {
int c= in.read();
if (c == -1)
break;
bos.write(c);
}
-
+
} catch (IOException ex) {
return null;
-
+
} finally {
Utilities.close(in);
try {
@@ -277,41 +262,39 @@ public class Utilities {
// silently ignored
}
}
-
+
return bos.toByteArray();
}
public static IPath getIconPath(Display display) {
return ICONS_PATH;
}
-
+
/*
- * Initialize the given Action from a ResourceBundle.
+ * Initializes the given Action from a ResourceBundle.
*/
public static void initAction(IAction a, ResourceBundle bundle, String prefix) {
-
String labelKey= "label"; //$NON-NLS-1$
String tooltipKey= "tooltip"; //$NON-NLS-1$
String imageKey= "image"; //$NON-NLS-1$
String descriptionKey= "description"; //$NON-NLS-1$
-
+
if (prefix != null && prefix.length() > 0) {
labelKey= prefix + labelKey;
tooltipKey= prefix + tooltipKey;
imageKey= prefix + imageKey;
descriptionKey= prefix + descriptionKey;
}
-
+
a.setText(getString(bundle, labelKey, labelKey));
a.setToolTipText(getString(bundle, tooltipKey, null));
a.setDescription(getString(bundle, descriptionKey, null));
-
+
String relPath= getString(bundle, imageKey, null);
if (relPath != null && relPath.trim().length() > 0) {
-
String dPath;
String ePath;
-
+
if (relPath.indexOf("/") >= 0) { //$NON-NLS-1$
String path= relPath.substring(1);
dPath= 'd' + path;
@@ -320,7 +303,7 @@ public class Utilities {
dPath= "dlcl16/" + relPath; //$NON-NLS-1$
ePath= "elcl16/" + relPath; //$NON-NLS-1$
}
-
+
ImageDescriptor id= CompareUIPlugin.getImageDescriptor(dPath); // we set the disabled image first (see PR 1GDDE87)
if (id != null)
a.setDisabledImageDescriptor(id);
@@ -331,35 +314,34 @@ public class Utilities {
}
}
}
-
- public static void initToggleAction(IAction a, ResourceBundle bundle, String prefix, boolean checked) {
+ public static void initToggleAction(IAction a, ResourceBundle bundle, String prefix, boolean checked) {
String tooltip= null;
- if (checked)
+ if (checked) {
tooltip= getString(bundle, prefix + "tooltip.checked", null); //$NON-NLS-1$
- else
+ } else {
tooltip= getString(bundle, prefix + "tooltip.unchecked", null); //$NON-NLS-1$
+ }
if (tooltip == null)
tooltip= getString(bundle, prefix + "tooltip", null); //$NON-NLS-1$
-
+
if (tooltip != null)
a.setToolTipText(tooltip);
-
+
String description= null;
- if (checked)
+ if (checked) {
description= getString(bundle, prefix + "description.checked", null); //$NON-NLS-1$
- else
+ } else {
description= getString(bundle, prefix + "description.unchecked", null); //$NON-NLS-1$
+ }
if (description == null)
description= getString(bundle, prefix + "description", null); //$NON-NLS-1$
-
+
if (description != null)
a.setDescription(description);
-
}
public static String getString(ResourceBundle bundle, String key, String dfltValue) {
-
if (bundle != null) {
try {
return bundle.getString(key);
@@ -369,9 +351,8 @@ public class Utilities {
}
return dfltValue;
}
-
+
public static String getFormattedString(ResourceBundle bundle, String key, String arg) {
-
if (bundle != null) {
try {
return MessageFormat.format(bundle.getString(key), arg);
@@ -381,7 +362,7 @@ public class Utilities {
}
return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
}
-
+
public static String getString(String key) {
try {
return CompareUI.getResourceBundle().getString(key);
@@ -389,13 +370,13 @@ public class Utilities {
return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
}
}
-
+
public static String getFormattedString(String key, String arg) {
try {
return MessageFormat.format(CompareUI.getResourceBundle().getString(key), arg);
} catch (MissingResourceException e) {
return "!" + key + "!"; //$NON-NLS-2$ //$NON-NLS-1$
- }
+ }
}
public static String getFormattedString(String key, String arg0, String arg1) {
@@ -403,15 +384,14 @@ public class Utilities {
return MessageFormat.format(CompareUI.getResourceBundle().getString(key), arg0, arg1);
} catch (MissingResourceException e) {
return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
+ }
}
public static String getString(ResourceBundle bundle, String key) {
return getString(bundle, key, key);
}
-
+
public static int getInteger(ResourceBundle bundle, String key, int dfltValue) {
-
if (bundle != null) {
try {
String s= bundle.getString(key);
@@ -420,7 +400,7 @@ public class Utilities {
} catch (NumberFormatException x) {
CompareUIPlugin.log(x);
} catch (MissingResourceException x) {
- // silently ignore Exception
+ // Silently ignore Exception
}
}
return dfltValue;
@@ -428,7 +408,7 @@ public class Utilities {
/**
* Answers <code>true</code> if the given selection contains resources that don't
- * have overlapping paths and <code>false</code> otherwise.
+ * have overlapping paths and <code>false</code> otherwise.
*/
/*
public static boolean isSelectionNonOverlapping() throws TeamException {
@@ -438,25 +418,25 @@ public class Utilities {
List validPaths = new ArrayList(2);
for (int i = 0; i < resources.length; i++) {
IResource resource = resources[i];
-
+
// only allow cvs resources to be selected
if(RepositoryProvider.getProvider(resource.getProject(), CVSProviderPlugin.getTypeId()) == null) {
return false;
}
-
- // check if this resource overlaps other selections
+
+ // check if this resource overlaps other selections
IPath resourceFullPath = resource.getFullPath();
if(!validPaths.isEmpty()) {
for (Iterator it = validPaths.iterator(); it.hasNext();) {
IPath path = (IPath) it.next();
- if(path.isPrefixOf(resourceFullPath) ||
+ if(path.isPrefixOf(resourceFullPath) ||
resourceFullPath.isPrefixOf(path)) {
return false;
}
}
}
validPaths.add(resourceFullPath);
-
+
// ensure that resources are managed
ICVSResource cvsResource = CVSWorkspaceRoot.getCVSResourceFor(resource);
if(cvsResource.isFolder()) {
@@ -470,15 +450,15 @@ public class Utilities {
return false;
}
*/
-
+
/* validate edit utilities */
-
+
/**
* Status constant indicating that an validateEdit call has changed the
* content of a file on disk.
*/
private static final int VALIDATE_EDIT_PROBLEM= 10004;
-
+
/**
* Constant used to indicate that tests are being run.
*/
@@ -488,89 +468,89 @@ public class Utilities {
* Constant used while testing the indicate that changes should be flushed
* when the compare input changes and a viewer is dirty.
*/
- public static boolean TESTING_FLUSH_ON_COMPARE_INPUT_CHANGE = false;
-
+ public static boolean TESTING_FLUSH_ON_COMPARE_INPUT_CHANGE = false;
+
/*
* Makes the given resources committable. Committable means that all
* resources are writeable and that the content of the resources hasn't
* changed by calling <code>validateEdit</code> for a given file on
* <tt>IWorkspace</tt>.
- *
+ *
* @param resources the resources to be checked
* @param shell the Shell passed to <code>validateEdit</code> as a context
* @return returns <code>true</code> if all resources are committable, <code>false</code> otherwise
- *
+ *
* @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
*/
public static boolean validateResource(IResource resource, Shell shell, String title) {
return validateResources(new IResource[] { resource }, shell, title);
}
-
+
/*
* Makes the given resources committable. Committable means that all
* resources are writeable and that the content of the resources hasn't
* changed by calling <code>validateEdit</code> for a given file on
* <tt>IWorkspace</tt>.
- *
+ *
* @param resources the resources to be checked
* @param shell the Shell passed to <code>validateEdit</code> as a context
* @return returns <code>true</code> if all resources are committable, <code>false</code> otherwise
- *
+ *
* @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
*/
- public static boolean validateResources(List resources, Shell shell, String title) {
- IResource r[]= (IResource[]) resources.toArray(new IResource[resources.size()]);
+ public static boolean validateResources(List<IResource> resources, Shell shell, String title) {
+ IResource r[]= resources.toArray(new IResource[resources.size()]);
return validateResources(r, shell, title);
}
-
+
/*
* Makes the given resources committable. Committable means that all
* resources are writeable and that the content of the resources hasn't
* changed by calling <code>validateEdit</code> for a given file on
* <tt>IWorkspace</tt>.
- *
+ *
* @param resources the resources to be checked
* @param shell the Shell passed to <code>validateEdit</code> as a context
* @return returns <code>true</code> if all resources are committable, <code>false</code> otherwise
- *
+ *
* @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object)
*/
public static boolean validateResources(IResource[] resources, Shell shell, String title) {
-
// get all readonly files
- List readOnlyFiles= getReadonlyFiles(resources);
+ List<IResource> readOnlyFiles= getReadonlyFiles(resources);
if (readOnlyFiles.size() == 0)
return true;
-
+
// get timestamps of readonly files before validateEdit
- Map oldTimeStamps= createModificationStampMap(readOnlyFiles);
-
- IFile[] files= (IFile[]) readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]);
+ Map<IFile, Long> oldTimeStamps= createModificationStampMap(readOnlyFiles);
+
+ IFile[] files= readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]);
IStatus status= ResourcesPlugin.getWorkspace().validateEdit(files, shell);
- if (! status.isOK()) {
+ if (!status.isOK()) {
String message= getString("ValidateEdit.error.unable_to_perform"); //$NON-NLS-1$
displayError(shell, title, status, message);
return false;
}
-
+
IStatus modified= null;
- Map newTimeStamps= createModificationStampMap(readOnlyFiles);
- for (Iterator iter= oldTimeStamps.keySet().iterator(); iter.hasNext();) {
- IFile file= (IFile) iter.next();
+ Map<IFile, Long> newTimeStamps= createModificationStampMap(readOnlyFiles);
+ for (Map.Entry<IFile, Long> entry : newTimeStamps.entrySet()) {
+ IFile file = entry.getKey();
+ Long newTimeStamp = entry.getValue();
if (file.isReadOnly()) {
- IStatus entry= new Status(IStatus.ERROR,
+ IStatus error = new Status(IStatus.ERROR,
CompareUIPlugin.getPluginId(),
VALIDATE_EDIT_PROBLEM,
getFormattedString("ValidateEdit.error.stillReadonly", file.getFullPath().toString()), //$NON-NLS-1$
null);
- modified= addStatus(modified, entry);
- } else if (! oldTimeStamps.get(file).equals(newTimeStamps.get(file))) {
- IStatus entry= new Status(IStatus.ERROR,
+ modified= addStatus(modified, error);
+ } else if (!oldTimeStamps.get(file).equals(newTimeStamp)) {
+ IStatus error = new Status(IStatus.ERROR,
CompareUIPlugin.getPluginId(),
VALIDATE_EDIT_PROBLEM,
getFormattedString("ValidateEdit.error.fileModified", file.getFullPath().toString()), //$NON-NLS-1$
null);
- modified= addStatus(modified, entry);
+ modified= addStatus(modified, error);
}
}
if (modified != null) {
@@ -582,57 +562,55 @@ public class Utilities {
}
private static void displayError(final Shell shell, final String title, final IStatus status, final String message) {
- if (Display.getCurrent() != null)
+ if (Display.getCurrent() != null) {
ErrorDialog.openError(shell, title, message, status);
- else {
+ } else {
Display.getDefault().syncExec(new Runnable() {
+ @Override
public void run() {
ErrorDialog.openError(shell, title, message, status);
}
});
}
}
-
- private static List getReadonlyFiles(IResource[] resources) {
- List readOnlyFiles= new ArrayList();
- for (int i= 0; i < resources.length; i++) {
- IResource resource= resources[i];
+
+ private static List<IResource> getReadonlyFiles(IResource[] resources) {
+ List<IResource> readOnlyFiles= new ArrayList<>();
+ for (IResource resource : resources) {
ResourceAttributes resourceAttributes= resource.getResourceAttributes();
- if (resource.getType() == IResource.FILE && resourceAttributes != null && resourceAttributes.isReadOnly())
+ if (resource.getType() == IResource.FILE && resourceAttributes != null && resourceAttributes.isReadOnly())
readOnlyFiles.add(resource);
}
return readOnlyFiles;
}
- private static Map createModificationStampMap(List files) {
- Map map= new HashMap();
- for (Iterator iter= files.iterator(); iter.hasNext(); ) {
- IFile file= (IFile)iter.next();
- map.put(file, new Long(file.getModificationStamp()));
+ private static Map<IFile, Long> createModificationStampMap(List<IResource> files) {
+ Map<IFile, Long> map= new HashMap<IFile, Long>();
+ for (IResource file : files) {
+ map.put((IFile) file, file.getModificationStamp());
}
return map;
}
-
+
private static IStatus addStatus(IStatus status, IStatus entry) {
-
if (status == null)
return entry;
-
+
if (status.isMultiStatus()) {
((MultiStatus)status).add(entry);
return status;
}
MultiStatus result= new MultiStatus(CompareUIPlugin.getPluginId(),
- VALIDATE_EDIT_PROBLEM,
- getString("ValidateEdit.error.unable_to_perform"), null); //$NON-NLS-1$
+ VALIDATE_EDIT_PROBLEM,
+ getString("ValidateEdit.error.unable_to_perform"), null); //$NON-NLS-1$
result.add(status);
result.add(entry);
return result;
}
-
+
// encoding
-
+
public static String readString(IStreamContentAccessor sca, String encoding) throws CoreException {
String s = null;
try {
@@ -648,7 +626,7 @@ public class Utilities {
}
return s;
}
-
+
/*
* Returns null if an error occurred.
*/
@@ -685,7 +663,7 @@ public class Utilities {
}
}
}
-
+
public static String getCharset(Object resource) {
if (resource instanceof IEncodedStorage) {
try {
@@ -696,7 +674,7 @@ public class Utilities {
}
return ResourcesPlugin.getEncoding();
}
-
+
public static byte[] getBytes(String s, String encoding) {
byte[] bytes= null;
if (s != null) {
@@ -734,31 +712,7 @@ public class Utilities {
return resources[0];
return null;
}
-
- public static Object getAdapter(Object element, Class adapterType, boolean load) {
- if (adapterType.isInstance(element))
- return element;
- if (element instanceof IAdaptable) {
- Object adapted = ((IAdaptable) element).getAdapter(adapterType);
- if (adapterType.isInstance(adapted))
- return adapted;
- }
- if (load) {
- Object adapted = Platform.getAdapterManager().loadAdapter(element, adapterType.getName());
- if (adapterType.isInstance(adapted))
- return adapted;
- } else {
- Object adapted = Platform.getAdapterManager().getAdapter(element, adapterType);
- if (adapterType.isInstance(adapted))
- return adapted;
- }
- return null;
- }
-
- public static Object getAdapter(Object element, Class adapterType) {
- return getAdapter(element, adapterType, false);
- }
-
+
public static ITypedElement getLeg(char type, Object input) {
if (input instanceof ICompareInput) {
switch (type) {
@@ -768,11 +722,13 @@ public class Utilities {
return ((ICompareInput)input).getLeft();
case MergeViewerContentProvider.RIGHT_CONTRIBUTOR:
return ((ICompareInput)input).getRight();
+ default:
+ break;
}
}
return null;
}
-
+
public static IDocument getDocument(char type, Object element, boolean isUsingDefaultContentProvider, boolean canHaveSharedDocument) {
ITypedElement te= getLeg(type, element);
if (te == null)
@@ -783,7 +739,7 @@ public class Utilities {
return ((IDocumentRange) te).getDocument();
if (isUsingDefaultContentProvider && canHaveSharedDocument) {
- ISharedDocumentAdapter sda = (ISharedDocumentAdapter)Utilities.getAdapter(te, ISharedDocumentAdapter.class, true);
+ ISharedDocumentAdapter sda = Adapters.adapt(te, ISharedDocumentAdapter.class);
if (sda != null) {
IEditorInput input= sda.getDocumentKey(te);
if (input != null) {
@@ -799,7 +755,7 @@ public class Utilities {
return null;
}
-
+
/**
* Return whether either the left or right sides of the given input
* represents a hunk. A hunk is a portion of a file.
@@ -810,39 +766,39 @@ public class Utilities {
if (input != null && input instanceof DiffNode){
ITypedElement right = ((DiffNode) input).getRight();
if (right != null) {
- Object element = Utilities.getAdapter(right, IHunk.class);
+ Object element = Adapters.adapt(right, IHunk.class);
if (element instanceof IHunk)
return true;
}
ITypedElement left = ((DiffNode) input).getLeft();
if (left != null) {
- Object element = Utilities.getAdapter(left, IHunk.class);
+ Object element = Adapters.adapt(left, IHunk.class);
if (element instanceof IHunk)
return true;
}
}
- return false;
+ return false;
}
-
+
public static boolean isHunkOk(Object input) {
if (input != null && input instanceof DiffNode){
ITypedElement right = ((DiffNode) input).getRight();
if (right != null) {
- Object element = Utilities.getAdapter(right, HunkResult.class);
+ Object element = Adapters.adapt(right, HunkResult.class);
if (element instanceof HunkResult) {
return ((HunkResult)element).isOK();
}
}
ITypedElement left = ((DiffNode) input).getLeft();
if (left != null) {
- Object element = Utilities.getAdapter(left, HunkResult.class);
+ Object element = Adapters.adapt(left, HunkResult.class);
if (element instanceof HunkResult)
return ((HunkResult)element).isOK();
}
}
- return false;
+ return false;
}
-
+
public static void schedule(Job job, IWorkbenchSite site) {
if (site != null) {
IWorkbenchSiteProgressService siteProgress = site.getAdapter(IWorkbenchSiteProgressService.class);
@@ -859,6 +815,7 @@ public class Utilities {
BusyIndicator.showWhile(Display.getCurrent(), runnable);
} else {
Display.getDefault().syncExec(new Runnable() {
+ @Override
public void run() {
BusyIndicator.showWhile(Display.getCurrent(), runnable);
}
@@ -874,22 +831,22 @@ public class Utilities {
public static boolean setReadTimeout(URLConnection connection, int timeout) {
Method[] methods = connection.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
- if (methods[i].getName().equals("setReadTimeout")) //$NON-NLS-1$
+ if (methods[i].getName().equals("setReadTimeout")) { //$NON-NLS-1$
try {
methods[i].invoke(connection, new Object[] {new Integer(timeout)});
return true;
- } catch (IllegalArgumentException e) { // ignore
- } catch (IllegalAccessException e) { // ignore
- } catch (InvocationTargetException e) { // ignore
+ } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
+ // ignore
}
+ }
}
return false;
}
/**
- * Load content of file under <code>url</code> displaying progress on given
+ * Loads content of file under <code>url</code> displaying progress on given
* context.
- *
+ *
* @param url
* @param context
* @return the content of file under given URL, or <code>null</code> if URL
@@ -904,6 +861,7 @@ public class Utilities {
InterruptedException {
final String[] result = new String[1];
context.run(true, true, new IRunnableWithProgress() {
+ @Override
public void run(IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException {
SubMonitor progress = SubMonitor.convert(monitor,
@@ -922,12 +880,8 @@ public class Utilities {
connection.getInputStream(), enc,
connection.getContentLength(),
progress.newChild(90));
- } catch (SocketTimeoutException e) {
- throw new InvocationTargetException(e);
} catch (IOException e) {
throw new InvocationTargetException(e);
- } finally {
- monitor.done();
}
}
});
@@ -937,7 +891,7 @@ public class Utilities {
/**
* Applies the compare filters to the lines of text taken from the specified
* contributors
- *
+ *
* @param thisLine
* @param thisContributor
* @param otherLine
@@ -952,13 +906,11 @@ public class Utilities {
ICompareFilter[] filters) {
IRegion[][] ignoredRegions = new IRegion[filters.length][];
- HashMap input = new HashMap(4);
+ HashMap<String, Comparable<?>> input = new HashMap<>(4);
input.put(ICompareFilter.THIS_LINE, thisLine);
- input.put(ICompareFilter.THIS_CONTRIBUTOR, new Character(
- thisContributor));
+ input.put(ICompareFilter.THIS_CONTRIBUTOR, thisContributor);
input.put(ICompareFilter.OTHER_LINE, otherLine);
- input.put(ICompareFilter.OTHER_CONTRIBUTOR, new Character(
- otherContributor));
+ input.put(ICompareFilter.OTHER_CONTRIBUTOR, otherContributor);
for (int i = 0; i < filters.length; i++) {
ignoredRegions[i] = filters[i].getFilteredRegions(input);
}
@@ -967,14 +919,15 @@ public class Utilities {
for (int j = 0; j < ignoredRegions.length; j++) {
if (ignoredRegions[j] != null) {
for (int k = 0; k < ignoredRegions[j].length; k++) {
- if (ignoredRegions[j][k] != null)
+ if (ignoredRegions[j][k] != null) {
for (int l = 0; l < ignoredRegions[j][k].getLength(); l++) {
ignored[ignoredRegions[j][k].getOffset() + l] = true;
}
+ }
}
}
}
- StringBuffer buffer = new StringBuffer(thisLine.length());
+ StringBuilder buffer = new StringBuilder(thisLine.length());
for (int i = 0; i < ignored.length; i++) {
if (!ignored[i]) {
buffer.append(thisLine.charAt(i));
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
index 311bb98e2..5145ef68d 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ViewerDescriptor.java
@@ -12,6 +12,7 @@ package org.eclipse.compare.internal;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.IViewerCreator;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.jface.viewers.Viewer;
@@ -21,21 +22,20 @@ import org.eclipse.swt.widgets.Composite;
* Creates <code>Viewer</code>s from an <code>IConfigurationElement</code>.
*/
public class ViewerDescriptor implements IViewerDescriptor {
-
private final static String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$
private final static String EXTENSIONS_ATTRIBUTE= "extensions"; //$NON-NLS-1$
private final static String LABEL_ATTRIBUTE = "label"; //$NON-NLS-1$
private IConfigurationElement fConfiguration;
private IViewerCreator fViewerCreator;
- private Class fViewerClass;
+ private Class<? extends Viewer> fViewerClass;
public ViewerDescriptor(IConfigurationElement config) {
fConfiguration= config;
}
+ @Override
public Viewer createViewer(Viewer currentViewer, Composite parent, CompareConfiguration mp) {
-
if (currentViewer != null && currentViewer.getClass() == fViewerClass) {
//System.out.println("reused viewer: " + currentViewer.getClass().getName());
return currentViewer;
@@ -53,7 +53,7 @@ public class ViewerDescriptor implements IViewerDescriptor {
// If we are going to return a new viewer, we want to preemptively deregister
// any handlers to avoid the logging of conflict warnings
if (currentViewer != null) {
- CompareHandlerService[] compareHandlerService = (CompareHandlerService[]) Utilities.getAdapter(currentViewer, CompareHandlerService[].class);
+ CompareHandlerService[] compareHandlerService = Adapters.adapt(currentViewer, CompareHandlerService[].class);
if (compareHandlerService != null) {
for (int i = 0; i < compareHandlerService.length; i++) {
compareHandlerService[i].dispose();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Utilities.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Utilities.java
index e1dcc32cc..8b59b1309 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Utilities.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Utilities.java
@@ -44,25 +44,20 @@ public class Utilities {
}
public static IProject getProject(DiffProject diffProject) {
- return ResourcesPlugin.getWorkspace().getRoot().getProject(
- diffProject.getName());
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(diffProject.getName());
}
public static ReaderCreator getReaderCreator(final IStorage storage) {
return new ReaderCreator() {
+ @Override
public Reader createReader() throws CoreException {
return Utilities.createReader(storage);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.compare.patch.ReaderCreator#canCreateReader()
- */
+ @Override
public boolean canCreateReader() {
if (storage == null
- || (storage != null && storage instanceof IFile && !((IFile) storage)
- .isAccessible())) {
+ || (storage instanceof IFile && !((IFile) storage).isAccessible())) {
return false;
}
return true;
@@ -73,8 +68,7 @@ public class Utilities {
public static BufferedReader createReader(IStorage storage)
throws CoreException {
if (storage == null
- || (storage != null && storage instanceof IFile && !((IFile) storage)
- .isAccessible())) {
+ || (storage instanceof IFile && !((IFile) storage).isAccessible())) {
throw new CoreException(new Status(IStatus.WARNING,
CompareUIPlugin.PLUGIN_ID,
CompareMessages.ReaderCreator_fileIsNotAccessible));
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java
index c240a4533..f5e322302 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/SharedDocumentAdapterWrapper.java
@@ -12,7 +12,7 @@ package org.eclipse.compare.structuremergeviewer;
import org.eclipse.compare.ISharedDocumentAdapter;
import org.eclipse.compare.SharedDocumentAdapter;
-import org.eclipse.compare.internal.Utilities;
+import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.ui.IEditorInput;
@@ -37,11 +37,11 @@ public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter {
* or <code>null</code>
*/
public static ISharedDocumentAdapter getAdapter(Object element) {
- return (ISharedDocumentAdapter)Utilities.getAdapter(element, ISharedDocumentAdapter.class, true);
+ return Adapters.adapt(element, ISharedDocumentAdapter.class);
}
/**
- * Create a shared document adapter that wraps the given adapter.
+ * Creates a shared document adapter that wraps the given adapter.
* @param wrappedAdapter the wrapped adapter
*/
public SharedDocumentAdapterWrapper(ISharedDocumentAdapter wrappedAdapter) {
@@ -72,7 +72,7 @@ public class SharedDocumentAdapterWrapper implements ISharedDocumentAdapter {
}
/**
- * Return the wrapped adapter.
+ * Returns the wrapped adapter.
* @return the wrapped adapter
*/
public final ISharedDocumentAdapter getWrappedAdapter() {

Back to the top