1 11 package org.eclipse.compare.internal.patch; 12 13 import org.eclipse.compare.*; 14 import org.eclipse.compare.patch.PatchConfiguration; 15 import org.eclipse.compare.structuremergeviewer.*; 16 import org.eclipse.core.resources.IFile; 17 18 public class PatchFileDiffNode extends PatchDiffNode implements IContentChangeListener { 19 20 private final FileDiffResult result; 21 22 public static PatchFileDiffNode createDiffNode(DiffNode parent, FileDiffResult result) { 23 return new PatchFileDiffNode(result, parent, getKind(result), getAncestorElement(result), getLeftElement(result), getRightElement(result)); 24 } 25 26 private static int getKind(FileDiffResult result) { 27 if (!result.hasMatches()) 28 return Differencer.NO_CHANGE; 29 return result.getDiff().getDiffType(result.getConfiguration().isReversed()) | Differencer.RIGHT; 30 } 31 32 private static ITypedElement getRightElement(FileDiffResult result) { 33 return new PatchFileTypedElement(result, true); 34 } 35 36 private static ITypedElement getLeftElement(FileDiffResult result) { 37 return new PatchFileTypedElement(result, false); 38 } 39 40 private static ITypedElement getAncestorElement(FileDiffResult result) { 41 return new PatchFileTypedElement(result, false); 42 } 43 44 public PatchFileDiffNode(FileDiffResult result, IDiffContainer parent, int kind, 45 ITypedElement ancestor, ITypedElement left, ITypedElement right) { 46 super(result.getDiff(), parent, kind, ancestor, left, right); 47 this.result = result; 48 } 49 50 public FileDiffResult getDiffResult() { 51 return result; 52 } 53 54 protected PatchConfiguration getConfiguration() { 55 return result.getConfiguration(); 56 } 57 58 61 public void add(IDiffElement diff) { 62 super.add(diff); 63 if (diff instanceof HunkDiffNode) { 65 HunkDiffNode node = (HunkDiffNode) diff; 66 Object left = node.getLeft(); 67 if (left instanceof IContentChangeNotifier) { 68 IContentChangeNotifier notifier = (IContentChangeNotifier) left; 69 notifier.addContentChangeListener(this); 70 } 71 } 72 } 73 74 77 public void contentChanged(IContentChangeNotifier source) { 78 fireChange(); 79 } 80 81 public int getKind() { 82 int kind = super.getKind(); 83 if (kind == Differencer.NO_CHANGE && getPatcher().hasCachedContents(getDiffResult().getDiff())) { 84 return Differencer.CHANGE | Differencer.RIGHT; 85 } 86 return kind; 87 } 88 89 public boolean fileExists() { 90 IFile file = ((WorkspaceFileDiffResult)getDiffResult()).getTargetFile(); 91 return file != null && file.isAccessible(); 92 } 93 94 } 95 | Popular Tags |