### Eclipse Workspace Patch 1.0
#P org.eclipse.compare
Index: compare/org/eclipse/compare/CompareEditorInput.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java,v
retrieving revision 1.114
diff -u -r1.114 CompareEditorInput.java
--- compare/org/eclipse/compare/CompareEditorInput.java 11 Jan 2010 11:08:10 -0000 1.114
+++ compare/org/eclipse/compare/CompareEditorInput.java 18 Feb 2010 16:53:49 -0000
@@ -226,7 +226,7 @@
public boolean hasViewerFor(Object input) {
OutlineViewerCreator creator = getWrappedCreator();
- return (creator != null);
+ return creator != null;
}
public Object getInput() {
@@ -275,7 +275,7 @@
private boolean isShowStructureInOutlineView() {
Object object= getCompareConfiguration().getProperty(CompareConfiguration.USE_OUTLINE_VIEW);
- return (object instanceof Boolean && ((Boolean)object).booleanValue());
+ return object instanceof Boolean && ((Boolean)object).booleanValue();
}
/* (non Javadoc)
@@ -718,7 +718,7 @@
/* private */ boolean hasChildren(Object input) {
if (input instanceof IDiffContainer) {
IDiffContainer dn= (IDiffContainer) input;
- return (dn.hasChildren());
+ return dn.hasChildren();
}
return false;
}
Index: compare/org/eclipse/compare/internal/ContentChangeNotifier.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/ContentChangeNotifier.java,v
retrieving revision 1.3
diff -u -r1.3 ContentChangeNotifier.java
--- compare/org/eclipse/compare/internal/ContentChangeNotifier.java 7 Dec 2006 21:16:06 -0000 1.3
+++ compare/org/eclipse/compare/internal/ContentChangeNotifier.java 18 Feb 2010 16:53:49 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,7 +12,9 @@
import org.eclipse.compare.IContentChangeListener;
import org.eclipse.compare.IContentChangeNotifier;
-import org.eclipse.core.runtime.*;
+import org.eclipse.core.runtime.ISafeRunnable;
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.swt.widgets.Display;
/**
@@ -62,7 +64,7 @@
final IContentChangeListener contentChangeListener = (IContentChangeListener)listeners[i];
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
- (contentChangeListener).contentChanged(element);
+ contentChangeListener.contentChanged(element);
}
public void handleException(Throwable exception) {
// Logged by safe runner
#P org.eclipse.team.ui
Index: plugin.xml
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.team.ui/plugin.xml,v
retrieving revision 1.207
diff -u -r1.207 plugin.xml
--- plugin.xml 12 Feb 2010 15:56:10 -0000 1.207
+++ plugin.xml 18 Feb 2010 16:53:50 -0000
@@ -655,7 +655,7 @@
@@ -668,7 +668,7 @@
Index: src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java,v
retrieving revision 1.48
diff -u -r1.48 OpenInCompareAction.java
--- src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java 26 Jan 2010 12:35:05 -0000 1.48
+++ src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java 18 Feb 2010 16:53:50 -0000
@@ -107,12 +107,31 @@
if (info != null)
return openCompareEditorOnSyncInfo(configuration, info, keepFocus, reuseEditorIfPossible);
}
+ /*if (object instanceof PatchFileDiffNode) {
+ if (participant instanceof ApplyPatchModelSynchronizeParticipant) {
+ ApplyPatchModelSynchronizeParticipant apmsp = (ApplyPatchModelSynchronizeParticipant) participant;
+ ISynchronizationContext context = apmsp.getContext();
+ if (context instanceof ApplyPatchSubscriberMergeContext) {
+ ApplyPatchSubscriberMergeContext apsmc = (ApplyPatchSubscriberMergeContext) context;
+ try {
+ Subscriber subscriber = apsmc.getSubscriber();
+ SyncInfo info = subscriber.getSyncInfo(((PatchFileDiffNode)object).getResource());
+ if (info != null)
+ return openCompareEditorOnSyncInfo(configuration, info, keepFocus, reuseEditorIfPossible);
+ } catch (TeamException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }*/
if (participant instanceof ModelSynchronizeParticipant) {
ModelSynchronizeParticipant msp = (ModelSynchronizeParticipant) participant;
ICompareInput input = msp.asCompareInput(object);
IWorkbenchPage workbenchPage = getWorkbenchPage(site);
if (input != null && workbenchPage != null && isOkToOpen(site, participant, input)) {
if (configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER).equals(PatchModelProvider.ID))
+ // TODO: //now, we never get here
return openCompareEditor(workbenchPage, new ApplyPatchModelCompareEditorInput(msp, input, workbenchPage, configuration), keepFocus, site, reuseEditorIfPossible);
else
return openCompareEditor(workbenchPage, new ModelCompareEditorInput(msp, input, workbenchPage, configuration), keepFocus, site, reuseEditorIfPossible);
Index: src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java,v
retrieving revision 1.2
diff -u -r1.2 ApplyPatchModelSynchronizeParticipant.java
--- src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java 26 Jan 2010 12:35:04 -0000 1.2
+++ src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java 18 Feb 2010 16:53:50 -0000
@@ -10,12 +10,15 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.synchronize.patch;
+import org.eclipse.compare.structuremergeviewer.ICompareInput;
import org.eclipse.core.resources.mapping.ModelProvider;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.team.core.mapping.provider.SynchronizationContext;
+import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.ui.TeamUI;
+import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
import org.eclipse.team.ui.synchronize.*;
@@ -86,4 +89,14 @@
extended[extended.length - 1] = provider;
return extended;
}
+
+ public ICompareInput asCompareInput(Object object) {
+ ISynchronizationCompareAdapter adapter = Utils.getCompareAdapter(object);
+ if (adapter != null)
+ return adapter.asCompareInput(getContext(), object);
+ if (object instanceof ICompareInput) {
+ return (ICompareInput) object;
+ }
+ return null;
+ }
}
Index: src/org/eclipse/team/internal/ui/synchronize/patch/HunkDiffNode.java
===================================================================
RCS file: src/org/eclipse/team/internal/ui/synchronize/patch/HunkDiffNode.java
diff -N src/org/eclipse/team/internal/ui/synchronize/patch/HunkDiffNode.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/team/internal/ui/synchronize/patch/HunkDiffNode.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.synchronize.patch;
+
+import org.eclipse.compare.ITypedElement;
+import org.eclipse.compare.internal.core.patch.HunkResult;
+import org.eclipse.compare.internal.patch.*;
+import org.eclipse.compare.patch.PatchConfiguration;
+import org.eclipse.compare.structuremergeviewer.Differencer;
+import org.eclipse.core.resources.IResource;
+
+public class HunkDiffNode extends PatchDiffNode {
+
+ private final HunkResult result;
+
+ public static HunkDiffNode createDiffNode(PatchFileDiffNode parent, HunkResult result, boolean fullContext) {
+ return createDiffNode(parent, result, fullContext, fullContext, fullContext);
+ }
+
+ public static HunkDiffNode createDiffNode(PatchFileDiffNode parent, HunkResult result, boolean ancestorFullContext, boolean leftFullContext, boolean rightFullContext) {
+ return new HunkDiffNode(result, parent, Differencer.CHANGE, getAncestorElement(result, ancestorFullContext), getLeftElement(result, leftFullContext), getRightElement(result, rightFullContext));
+ }
+
+ private static ITypedElement getRightElement(HunkResult result, boolean fullContext) {
+ return new HunkTypedElement(result, true /* isResult */, fullContext);
+ }
+
+ private static ITypedElement getLeftElement(HunkResult result,
+ boolean fullContext) {
+ if (fullContext && !result.isOK())
+ return new UnmatchedHunkTypedElement(result);
+ return new HunkTypedElement(result, false /* before state */, fullContext);
+ }
+
+ private static ITypedElement getAncestorElement(HunkResult result, boolean fullContext) {
+ if (!fullContext && result.isOK()) {
+ return new HunkTypedElement(result, false /* before state */, fullContext);
+ }
+ if (!fullContext) {
+ // Don't provide an ancestor if the hunk didn't match or we're not doing fullContext
+ return null;
+ }
+ // Make the ancestor the same as the left so we have an incoming change
+ return new HunkTypedElement(result, false /* before state */, result.isOK());
+ }
+
+ private HunkDiffNode(HunkResult result, PatchFileDiffNode parent, int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right) {
+ super(result.getHunk(), parent, kind, ancestor, left, right);
+ this.result = result;
+ }
+
+ public HunkResult getHunkResult() {
+ return result;
+ }
+
+ protected PatchConfiguration getConfiguration() {
+ return result.getDiffResult().getConfiguration();
+ }
+
+ public boolean isManuallyMerged() {
+ Object left = getLeft();
+ if (left instanceof UnmatchedHunkTypedElement) {
+ UnmatchedHunkTypedElement element = (UnmatchedHunkTypedElement) left;
+ return element.isManuallyMerged();
+ }
+ return false;
+ }
+
+ public boolean isFuzzUsed() {
+ return result.getFuzz() > 0;
+ }
+
+ public boolean isAllContextIgnored() {
+ int fuzz = result.getFuzz();
+ if (fuzz > 0) {
+ String[] lines = result.getHunk().getLines();
+ int contextLines = 0;
+ for (int i = 0; i < lines.length; i++) {
+ String line = lines[i];
+ char c = line.charAt(0);
+ if (c == ' ') {
+ contextLines++;
+ } else {
+ if (contextLines > 0 && fuzz >= contextLines) {
+ return true;
+ }
+ contextLines = 0;
+ }
+ }
+ if (contextLines > 0 && fuzz >= contextLines) {
+ return true;
+ }
+
+ }
+ return false;
+ }
+
+ public IResource getResource() {
+ return ((PatchFileDiffNode)getParent()).getResource();
+ }
+}
Index: src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java,v
retrieving revision 1.2
diff -u -r1.2 PatchCompareAdapter.java
--- src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java 26 Jan 2010 12:35:04 -0000 1.2
+++ src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java 18 Feb 2010 16:53:52 -0000
@@ -23,6 +23,8 @@
public ICompareInput asCompareInput(ISynchronizationContext context,
Object o) {
+ if (o instanceof PatchFileDiffNode)
+ return super.asCompareInput(context, o);
if (o instanceof ICompareInput)
return (ICompareInput) o;
return super.asCompareInput(context, o);
Index: src/org/eclipse/team/internal/ui/synchronize/patch/PatchFileDiffNode.java
===================================================================
RCS file: src/org/eclipse/team/internal/ui/synchronize/patch/PatchFileDiffNode.java
diff -N src/org/eclipse/team/internal/ui/synchronize/patch/PatchFileDiffNode.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/team/internal/ui/synchronize/patch/PatchFileDiffNode.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ui.synchronize.patch;
+
+import org.eclipse.compare.*;
+import org.eclipse.compare.internal.core.patch.FileDiffResult;
+import org.eclipse.compare.internal.core.patch.FilePatch2;
+import org.eclipse.compare.internal.patch.*;
+import org.eclipse.compare.patch.PatchConfiguration;
+import org.eclipse.compare.structuremergeviewer.*;
+import org.eclipse.core.internal.runtime.AdapterManager;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
+
+public class PatchFileDiffNode extends PatchDiffNode implements IContentChangeListener, IAdaptable {
+
+ private final FileDiffResult result;
+
+ public static PatchFileDiffNode createDiffNode(DiffNode parent, FileDiffResult result) {
+ return new PatchFileDiffNode(result, parent, getKind(result), getAncestorElement(result), getLeftElement(result), getRightElement(result));
+ }
+
+ private static int getKind(FileDiffResult result) {
+ if (!result.hasMatches())
+ return Differencer.NO_CHANGE;
+ int fileDiffKind = result.getDiff().getDiffType(result.getConfiguration().isReversed());
+ int kind = convertFileDiffTypeToDifferencerType(fileDiffKind);
+ return kind | Differencer.RIGHT;
+ }
+
+ private static int convertFileDiffTypeToDifferencerType(int fileDiffKind) {
+ int kind;
+ switch (fileDiffKind) {
+ case FilePatch2.ADDITION:
+ kind = Differencer.ADDITION;
+ break;
+ case FilePatch2.DELETION:
+ kind = Differencer.DELETION;
+ break;
+ case FilePatch2.CHANGE:
+ kind = Differencer.CHANGE;
+ break;
+ default:
+ kind = Differencer.CHANGE;
+ break;
+ }
+ return kind;
+ }
+
+ private static ITypedElement getRightElement(FileDiffResult result) {
+ return new PatchFileTypedElement(result, true);
+ }
+
+ private static ITypedElement getLeftElement(FileDiffResult result) {
+ return new LocalResourceTypedElement(((WorkspaceFileDiffResult)result).getTargetFile());
+// return new PatchFileTypedElement(result, false);
+ }
+
+ private static ITypedElement getAncestorElement(FileDiffResult result) {
+ return new PatchFileTypedElement(result, false);
+ }
+
+ public PatchFileDiffNode(FileDiffResult result, IDiffContainer parent, int kind,
+ ITypedElement ancestor, ITypedElement left, ITypedElement right) {
+ super(result.getDiff(), parent, kind, ancestor, left, right);
+ this.result = result;
+ }
+
+ public FileDiffResult getDiffResult() {
+ return result;
+ }
+
+ protected PatchConfiguration getConfiguration() {
+ return result.getConfiguration();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.structuremergeviewer.DiffContainer#add(org.eclipse.compare.structuremergeviewer.IDiffElement)
+ */
+ public void add(IDiffElement diff) {
+ super.add(diff);
+ // Listen for content changes in unmatched children so we can fire an input change
+ if (diff instanceof HunkDiffNode) {
+ HunkDiffNode node = (HunkDiffNode) diff;
+ Object left = node.getLeft();
+ if (left instanceof IContentChangeNotifier) {
+ IContentChangeNotifier notifier = (IContentChangeNotifier) left;
+ notifier.addContentChangeListener(this);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.IContentChangeListener#contentChanged(org.eclipse.compare.IContentChangeNotifier)
+ */
+ public void contentChanged(IContentChangeNotifier source) {
+ fireChange();
+ }
+
+ public int getKind() {
+ int kind = super.getKind();
+ if (kind == Differencer.NO_CHANGE && getPatcher().hasCachedContents(getDiffResult().getDiff())) {
+ return Differencer.CHANGE | Differencer.RIGHT;
+ }
+ return kind;
+ }
+
+ public boolean fileExists() {
+ IResource file = getResource();
+ return file != null && file.isAccessible();
+ }
+
+ public IResource getResource() {
+ return ((WorkspaceFileDiffResult)getDiffResult()).getTargetFile();
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (adapter == IResource.class)
+ return getResource();
+ return AdapterManager.getDefault().getAdapter(this, adapter);
+ }
+}