View | Details | Raw Unified | Return to bug 300221
Collapse All | Expand All

(-)compare/org/eclipse/compare/CompareEditorInput.java (-3 / +3 lines)
Lines 226-232 Link Here
226
226
227
		public boolean hasViewerFor(Object input) {
227
		public boolean hasViewerFor(Object input) {
228
			OutlineViewerCreator creator = getWrappedCreator();
228
			OutlineViewerCreator creator = getWrappedCreator();
229
			return (creator != null);
229
			return creator != null;
230
		}
230
		}
231
231
232
		public Object getInput() {
232
		public Object getInput() {
Lines 275-281 Link Here
275
	
275
	
276
	private boolean isShowStructureInOutlineView() {
276
	private boolean isShowStructureInOutlineView() {
277
		Object object= getCompareConfiguration().getProperty(CompareConfiguration.USE_OUTLINE_VIEW);
277
		Object object= getCompareConfiguration().getProperty(CompareConfiguration.USE_OUTLINE_VIEW);
278
		return (object instanceof Boolean && ((Boolean)object).booleanValue());
278
		return object instanceof Boolean && ((Boolean)object).booleanValue();
279
	}
279
	}
280
		
280
		
281
	/* (non Javadoc)
281
	/* (non Javadoc)
Lines 718-724 Link Here
718
	/* private */ boolean hasChildren(Object input) {
718
	/* private */ boolean hasChildren(Object input) {
719
		if (input instanceof IDiffContainer) {
719
		if (input instanceof IDiffContainer) {
720
			IDiffContainer dn= (IDiffContainer) input;
720
			IDiffContainer dn= (IDiffContainer) input;
721
			return (dn.hasChildren());
721
			return dn.hasChildren();
722
		}
722
		}
723
		return false;
723
		return false;
724
	}
724
	}
(-)compare/org/eclipse/compare/internal/ContentChangeNotifier.java (-3 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 12-18 Link Here
12
12
13
import org.eclipse.compare.IContentChangeListener;
13
import org.eclipse.compare.IContentChangeListener;
14
import org.eclipse.compare.IContentChangeNotifier;
14
import org.eclipse.compare.IContentChangeNotifier;
15
import org.eclipse.core.runtime.*;
15
import org.eclipse.core.runtime.ISafeRunnable;
16
import org.eclipse.core.runtime.ListenerList;
17
import org.eclipse.core.runtime.SafeRunner;
16
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.swt.widgets.Display;
17
19
18
/**
20
/**
Lines 62-68 Link Here
62
					final IContentChangeListener contentChangeListener = (IContentChangeListener)listeners[i];
64
					final IContentChangeListener contentChangeListener = (IContentChangeListener)listeners[i];
63
					SafeRunner.run(new ISafeRunnable() {
65
					SafeRunner.run(new ISafeRunnable() {
64
						public void run() throws Exception {
66
						public void run() throws Exception {
65
							(contentChangeListener).contentChanged(element);
67
							contentChangeListener.contentChanged(element);
66
						}
68
						}
67
						public void handleException(Throwable exception) {
69
						public void handleException(Throwable exception) {
68
							// Logged by safe runner
70
							// Logged by safe runner
(-)plugin.xml (-2 / +2 lines)
Lines 655-661 Link Here
655
            </adapter>
655
            </adapter>
656
         </factory>
656
         </factory>
657
         <factory
657
         <factory
658
               adaptableType="org.eclipse.compare.internal.patch.PatchFileDiffNode"
658
               adaptableType="org.eclipse.team.internal.ui.synchronize.patch.PatchFileDiffNode"
659
               class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory">
659
               class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory">
660
            <adapter
660
            <adapter
661
                  type="org.eclipse.core.resources.mapping.ResourceMapping">
661
                  type="org.eclipse.core.resources.mapping.ResourceMapping">
Lines 668-674 Link Here
668
            </adapter>
668
            </adapter>
669
         </factory>
669
         </factory>
670
         <factory
670
         <factory
671
               adaptableType="org.eclipse.compare.internal.patch.HunkDiffNode"
671
               adaptableType="org.eclipse.team.internal.ui.synchronize.patch.HunkDiffNode"
672
               class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory">
672
               class="org.eclipse.team.internal.ui.synchronize.patch.AdapterFactory">
673
            <adapter
673
            <adapter
674
                  type="org.eclipse.core.resources.mapping.ResourceMapping">
674
                  type="org.eclipse.core.resources.mapping.ResourceMapping">
(-)src/org/eclipse/team/internal/ui/synchronize/actions/OpenInCompareAction.java (+19 lines)
Lines 107-118 Link Here
107
			if (info != null)
107
			if (info != null)
108
				return openCompareEditorOnSyncInfo(configuration, info, keepFocus, reuseEditorIfPossible);
108
				return openCompareEditorOnSyncInfo(configuration, info, keepFocus, reuseEditorIfPossible);
109
		}
109
		}
110
		/*if (object instanceof PatchFileDiffNode) {
111
			if (participant instanceof ApplyPatchModelSynchronizeParticipant) {
112
				ApplyPatchModelSynchronizeParticipant apmsp = (ApplyPatchModelSynchronizeParticipant) participant;
113
				ISynchronizationContext context = apmsp.getContext();
114
				if (context instanceof ApplyPatchSubscriberMergeContext) {
115
					ApplyPatchSubscriberMergeContext apsmc = (ApplyPatchSubscriberMergeContext) context;
116
					try {
117
						Subscriber subscriber = apsmc.getSubscriber();
118
						SyncInfo info = subscriber.getSyncInfo(((PatchFileDiffNode)object).getResource());
119
						if (info != null)
120
							return openCompareEditorOnSyncInfo(configuration, info, keepFocus, reuseEditorIfPossible);
121
					} catch (TeamException e) {
122
						// TODO Auto-generated catch block
123
						e.printStackTrace();
124
					}
125
				}
126
			}
127
		}*/
110
		if (participant instanceof ModelSynchronizeParticipant) {
128
		if (participant instanceof ModelSynchronizeParticipant) {
111
			ModelSynchronizeParticipant msp = (ModelSynchronizeParticipant) participant;
129
			ModelSynchronizeParticipant msp = (ModelSynchronizeParticipant) participant;
112
			ICompareInput input = msp.asCompareInput(object);
130
			ICompareInput input = msp.asCompareInput(object);
113
			IWorkbenchPage workbenchPage = getWorkbenchPage(site);
131
			IWorkbenchPage workbenchPage = getWorkbenchPage(site);
114
			if (input != null && workbenchPage != null && isOkToOpen(site, participant, input)) {
132
			if (input != null && workbenchPage != null && isOkToOpen(site, participant, input)) {
115
				if (configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER).equals(PatchModelProvider.ID))
133
				if (configuration.getProperty(ModelSynchronizeParticipant.P_VISIBLE_MODEL_PROVIDER).equals(PatchModelProvider.ID))
134
					// TODO: //now, we never get here
116
					return openCompareEditor(workbenchPage, new ApplyPatchModelCompareEditorInput(msp, input, workbenchPage, configuration), keepFocus, site, reuseEditorIfPossible);
135
					return openCompareEditor(workbenchPage, new ApplyPatchModelCompareEditorInput(msp, input, workbenchPage, configuration), keepFocus, site, reuseEditorIfPossible);
117
				else
136
				else
118
					return openCompareEditor(workbenchPage, new ModelCompareEditorInput(msp, input, workbenchPage, configuration), keepFocus, site, reuseEditorIfPossible);
137
					return openCompareEditor(workbenchPage, new ModelCompareEditorInput(msp, input, workbenchPage, configuration), keepFocus, site, reuseEditorIfPossible);
(-)src/org/eclipse/team/internal/ui/synchronize/patch/ApplyPatchModelSynchronizeParticipant.java (+13 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
12
13
import org.eclipse.compare.structuremergeviewer.ICompareInput;
13
import org.eclipse.core.resources.mapping.ModelProvider;
14
import org.eclipse.core.resources.mapping.ModelProvider;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.Action;
16
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.jface.action.IMenuManager;
17
import org.eclipse.team.core.mapping.provider.SynchronizationContext;
18
import org.eclipse.team.core.mapping.provider.SynchronizationContext;
19
import org.eclipse.team.internal.ui.Utils;
18
import org.eclipse.team.ui.TeamUI;
20
import org.eclipse.team.ui.TeamUI;
21
import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
19
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
22
import org.eclipse.team.ui.mapping.SynchronizationActionProvider;
20
import org.eclipse.team.ui.synchronize.*;
23
import org.eclipse.team.ui.synchronize.*;
21
24
Lines 86-89 Link Here
86
		extended[extended.length - 1] = provider;
89
		extended[extended.length - 1] = provider;
87
		return extended;
90
		return extended;
88
	}
91
	}
92
	
93
	public ICompareInput asCompareInput(Object object) {
94
		ISynchronizationCompareAdapter adapter = Utils.getCompareAdapter(object);
95
		if (adapter != null)
96
			return adapter.asCompareInput(getContext(), object);
97
		if (object instanceof ICompareInput) {
98
			return (ICompareInput) object;
99
		}
100
		return null;
101
	}
89
}
102
}
(-)src/org/eclipse/team/internal/ui/synchronize/patch/HunkDiffNode.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
13
import org.eclipse.compare.ITypedElement;
14
import org.eclipse.compare.internal.core.patch.HunkResult;
15
import org.eclipse.compare.internal.patch.*;
16
import org.eclipse.compare.patch.PatchConfiguration;
17
import org.eclipse.compare.structuremergeviewer.Differencer;
18
import org.eclipse.core.resources.IResource;
19
20
public class HunkDiffNode extends PatchDiffNode {
21
22
	private final HunkResult result;
23
24
	public static HunkDiffNode createDiffNode(PatchFileDiffNode parent, HunkResult result, boolean fullContext) {
25
		return createDiffNode(parent, result, fullContext, fullContext, fullContext);
26
	}
27
	
28
	public static HunkDiffNode createDiffNode(PatchFileDiffNode parent, HunkResult result, boolean ancestorFullContext, boolean leftFullContext, boolean rightFullContext) {
29
		return new HunkDiffNode(result, parent, Differencer.CHANGE, getAncestorElement(result, ancestorFullContext), getLeftElement(result, leftFullContext), getRightElement(result, rightFullContext));
30
	}
31
	
32
	private static ITypedElement getRightElement(HunkResult result, boolean fullContext) {
33
		return new HunkTypedElement(result, true /* isResult */, fullContext);
34
	}
35
36
	private static ITypedElement getLeftElement(HunkResult result,
37
			boolean fullContext) {
38
		if (fullContext && !result.isOK())
39
			return new UnmatchedHunkTypedElement(result);
40
		return new HunkTypedElement(result, false /* before state */, fullContext);
41
	}
42
43
	private static ITypedElement getAncestorElement(HunkResult result, boolean fullContext) {
44
		if (!fullContext && result.isOK()) {
45
			return new HunkTypedElement(result, false /* before state */, fullContext);
46
		}
47
		if (!fullContext) {
48
			// Don't provide an ancestor if the hunk didn't match or we're not doing fullContext
49
			return null;
50
		}
51
		// Make the ancestor the same as the left so we have an incoming change
52
		return new HunkTypedElement(result, false /* before state */, result.isOK());
53
	}
54
55
	private HunkDiffNode(HunkResult result, PatchFileDiffNode parent, int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right) {
56
		super(result.getHunk(), parent, kind, ancestor, left, right);
57
		this.result = result;
58
	}
59
60
	public HunkResult getHunkResult() {
61
		return result;
62
	}
63
64
	protected PatchConfiguration getConfiguration() {
65
		return result.getDiffResult().getConfiguration();
66
	}
67
68
	public boolean isManuallyMerged() {
69
		Object left = getLeft();
70
		if (left instanceof UnmatchedHunkTypedElement) {
71
			UnmatchedHunkTypedElement element = (UnmatchedHunkTypedElement) left;
72
			return element.isManuallyMerged();
73
		}
74
		return false;
75
	}
76
	
77
	public boolean isFuzzUsed() {
78
		return result.getFuzz() > 0;
79
	}
80
	
81
	public boolean isAllContextIgnored() {
82
		int fuzz = result.getFuzz();
83
		if (fuzz > 0) {
84
			String[] lines = result.getHunk().getLines();
85
			int contextLines = 0;
86
			for (int i = 0; i < lines.length; i++) {
87
				String line = lines[i];
88
				char c = line.charAt(0);
89
				if (c == ' ') {
90
					contextLines++;
91
				} else {
92
					if (contextLines > 0 && fuzz >= contextLines) {
93
						return true;
94
					}
95
					contextLines = 0;
96
				}
97
			}
98
			if (contextLines > 0 && fuzz >= contextLines) {
99
				return true;
100
			}
101
			
102
		}
103
		return false;
104
	}
105
106
	public IResource getResource() {
107
		return ((PatchFileDiffNode)getParent()).getResource();
108
	}
109
}
(-)src/org/eclipse/team/internal/ui/synchronize/patch/PatchCompareAdapter.java (+2 lines)
Lines 23-28 Link Here
23
23
24
	public ICompareInput asCompareInput(ISynchronizationContext context,
24
	public ICompareInput asCompareInput(ISynchronizationContext context,
25
			Object o) {
25
			Object o) {
26
		if (o instanceof PatchFileDiffNode) 
27
			return super.asCompareInput(context, o);
26
		if (o instanceof ICompareInput)
28
		if (o instanceof ICompareInput)
27
			return (ICompareInput) o;
29
			return (ICompareInput) o;
28
		return super.asCompareInput(context, o);
30
		return super.asCompareInput(context, o);
(-)src/org/eclipse/team/internal/ui/synchronize/patch/PatchFileDiffNode.java (+131 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.team.internal.ui.synchronize.patch;
12
13
import org.eclipse.compare.*;
14
import org.eclipse.compare.internal.core.patch.FileDiffResult;
15
import org.eclipse.compare.internal.core.patch.FilePatch2;
16
import org.eclipse.compare.internal.patch.*;
17
import org.eclipse.compare.patch.PatchConfiguration;
18
import org.eclipse.compare.structuremergeviewer.*;
19
import org.eclipse.core.internal.runtime.AdapterManager;
20
import org.eclipse.core.resources.IResource;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
23
24
public class PatchFileDiffNode extends PatchDiffNode implements IContentChangeListener, IAdaptable {
25
26
	private final FileDiffResult result;
27
28
	public static PatchFileDiffNode createDiffNode(DiffNode parent, FileDiffResult result) {
29
		return new PatchFileDiffNode(result, parent, getKind(result), getAncestorElement(result), getLeftElement(result), getRightElement(result));
30
	}
31
	
32
	private static int getKind(FileDiffResult result) {
33
		if (!result.hasMatches())
34
			return Differencer.NO_CHANGE;
35
		int fileDiffKind = result.getDiff().getDiffType(result.getConfiguration().isReversed());
36
		int kind = convertFileDiffTypeToDifferencerType(fileDiffKind);
37
		return kind | Differencer.RIGHT;
38
	}
39
40
	private static int convertFileDiffTypeToDifferencerType(int fileDiffKind) {
41
		int kind;
42
		switch (fileDiffKind) {
43
		case FilePatch2.ADDITION:
44
			kind = Differencer.ADDITION;
45
			break;
46
		case FilePatch2.DELETION:
47
			kind = Differencer.DELETION;
48
			break;
49
		case FilePatch2.CHANGE:
50
			kind = Differencer.CHANGE;
51
			break;
52
		default:
53
			kind = Differencer.CHANGE;
54
			break;
55
		}
56
		return kind;
57
	}
58
59
	private static ITypedElement getRightElement(FileDiffResult result) {
60
		return new PatchFileTypedElement(result, true);
61
	}
62
63
	private static ITypedElement getLeftElement(FileDiffResult result) {
64
		return new LocalResourceTypedElement(((WorkspaceFileDiffResult)result).getTargetFile());
65
//		return new PatchFileTypedElement(result, false);
66
	}
67
68
	private static ITypedElement getAncestorElement(FileDiffResult result) {
69
		return new PatchFileTypedElement(result, false);
70
	}
71
72
	public PatchFileDiffNode(FileDiffResult result, IDiffContainer parent, int kind,
73
			ITypedElement ancestor, ITypedElement left, ITypedElement right) {
74
		super(result.getDiff(), parent, kind, ancestor, left, right);
75
		this.result = result;
76
	}
77
78
	public FileDiffResult getDiffResult() {
79
		return result;
80
	}
81
	
82
	protected PatchConfiguration getConfiguration() {
83
		return result.getConfiguration();
84
	}
85
	
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.compare.structuremergeviewer.DiffContainer#add(org.eclipse.compare.structuremergeviewer.IDiffElement)
88
	 */
89
	public void add(IDiffElement diff) {
90
		super.add(diff);
91
		// Listen for content changes in unmatched children so we can fire an input change
92
		if (diff instanceof HunkDiffNode) {
93
			HunkDiffNode node = (HunkDiffNode) diff;
94
			Object left = node.getLeft();
95
			if (left instanceof IContentChangeNotifier) {
96
				IContentChangeNotifier notifier = (IContentChangeNotifier) left;
97
				notifier.addContentChangeListener(this);
98
			}
99
		}
100
	}
101
102
	/* (non-Javadoc)
103
	 * @see org.eclipse.compare.IContentChangeListener#contentChanged(org.eclipse.compare.IContentChangeNotifier)
104
	 */
105
	public void contentChanged(IContentChangeNotifier source) {
106
		fireChange();
107
	}
108
	
109
	public int getKind() {
110
		int kind = super.getKind();
111
		if (kind == Differencer.NO_CHANGE && getPatcher().hasCachedContents(getDiffResult().getDiff())) {
112
			return Differencer.CHANGE | Differencer.RIGHT;
113
		}
114
		return kind;
115
	}
116
117
	public boolean fileExists() {
118
		IResource file = getResource();
119
		return file != null && file.isAccessible();
120
	}
121
122
	public IResource getResource() {
123
		return ((WorkspaceFileDiffResult)getDiffResult()).getTargetFile();
124
	}
125
	
126
	public Object getAdapter(Class adapter) {
127
		if (adapter == IResource.class)
128
			return getResource();
129
		return AdapterManager.getDefault().getAdapter(this, adapter);
130
	}
131
}

Return to bug 300221