1 11 package org.eclipse.compare.internal; 12 13 import org.eclipse.compare.*; 14 import org.eclipse.compare.contentmergeviewer.IMergeViewerContentProvider; 15 import org.eclipse.compare.structuremergeviewer.*; 16 import org.eclipse.jface.viewers.Viewer; 17 import org.eclipse.swt.graphics.Image; 18 19 23 public class MergeViewerContentProvider implements IMergeViewerContentProvider { 24 25 public static final char ANCESTOR_CONTRIBUTOR = 'A'; 26 public static final char RIGHT_CONTRIBUTOR = 'R'; 27 public static final char LEFT_CONTRIBUTOR = 'L'; 28 29 private CompareConfiguration fCompareConfiguration; 30 private String fAncestorError; 31 private String fLeftError; 32 private String fRightError; 33 34 public MergeViewerContentProvider(CompareConfiguration cc) { 35 fCompareConfiguration= cc; 36 } 37 38 private boolean hasError() { 39 return fAncestorError != null || fLeftError != null || fRightError != null; 40 } 41 42 public void dispose() { 43 } 45 46 public void inputChanged(Viewer v, Object o1, Object o2) { 47 } 49 50 52 public void setAncestorError(String errorMessage) { 53 fAncestorError= errorMessage; 54 } 55 56 public String getAncestorLabel(Object element) { 57 if (fAncestorError != null) 58 return fAncestorError; 59 return fCompareConfiguration.getAncestorLabel(element); 60 } 61 62 public Image getAncestorImage(Object element) { 63 if (fAncestorError != null) 64 return null; 65 return fCompareConfiguration.getAncestorImage(element); 66 } 67 68 public Object getAncestorContent(Object element) { 69 if (element instanceof ICompareInput) 70 return ((ICompareInput) element).getAncestor(); 71 return null; 72 } 73 74 public boolean showAncestor(Object element) { 75 if (element instanceof ICompareInput) 76 return true; return false; 79 } 80 81 83 public void setLeftError(String errorMessage) { 84 fLeftError= errorMessage; 85 } 86 87 public String getLeftLabel(Object element) { 88 if (fLeftError != null) 89 return fLeftError; 90 return fCompareConfiguration.getLeftLabel(element); 91 } 92 93 public Image getLeftImage(Object element) { 94 if (fLeftError != null) 95 return null; 96 return fCompareConfiguration.getLeftImage(element); 97 } 98 99 public Object getLeftContent(Object element) { 100 if (element instanceof ICompareInput) 101 return ((ICompareInput) element).getLeft(); 102 return null; 103 } 104 105 public boolean isLeftEditable(Object element) { 106 if (hasError()) 107 return false; 108 if (element instanceof ICompareInput) { 109 Object left= ((ICompareInput) element).getLeft(); 110 if (left == null && element instanceof IDiffElement) { 111 IDiffElement parent= ((IDiffElement)element).getParent(); 112 if (parent instanceof ICompareInput) 113 left= ((ICompareInput) parent).getLeft(); 114 } 115 if (left instanceof IEditableContent) 116 return ((IEditableContent)left).isEditable(); 117 } 118 return false; 119 } 120 121 public void saveLeftContent(Object element, byte[] bytes) { 122 if (element instanceof ICompareInput) { 123 ICompareInput node= (ICompareInput) element; 124 if (bytes != null) { 125 ITypedElement left= node.getLeft(); 126 if (left == null) { 128 node.copy(false); 129 left= node.getLeft(); 130 } 131 if (left instanceof IEditableContent) 132 ((IEditableContent)left).setContent(bytes); 133 if (node instanceof ResourceCompareInput.MyDiffNode) 134 ((ResourceCompareInput.MyDiffNode)node).fireChange(); 135 } else { 136 node.copy(false); 137 } 138 } 139 } 140 141 143 public void setRightError(String errorMessage) { 144 fRightError= errorMessage; 145 } 146 147 public String getRightLabel(Object element) { 148 if (fRightError != null) 149 return fRightError; 150 return fCompareConfiguration.getRightLabel(element); 151 } 152 153 public Image getRightImage(Object element) { 154 if (fRightError != null) 155 return null; 156 return fCompareConfiguration.getRightImage(element); 157 } 158 159 public Object getRightContent(Object element) { 160 if (element instanceof ICompareInput) 161 return ((ICompareInput) element).getRight(); 162 return null; 163 } 164 165 public boolean isRightEditable(Object element) { 166 if (hasError()) 167 return false; 168 if (element instanceof ICompareInput) { 169 Object right= ((ICompareInput) element).getRight(); 170 if (right == null && element instanceof IDiffElement) { 171 IDiffContainer parent= ((IDiffElement)element).getParent(); 172 if (parent instanceof ICompareInput) 173 right= ((ICompareInput) parent).getRight(); 174 } 175 if (right instanceof IEditableContent) 176 return ((IEditableContent)right).isEditable(); 177 } 178 return false; 179 } 180 181 public void saveRightContent(Object element, byte[] bytes) { 182 if (element instanceof ICompareInput) { 183 ICompareInput node= (ICompareInput) element; 184 if (bytes != null) { 185 ITypedElement right= node.getRight(); 186 if (right == null) { 188 node.copy(true); 189 right= node.getRight(); 190 } 191 if (right instanceof IEditableContent) 192 ((IEditableContent)right).setContent(bytes); 193 if (node instanceof ResourceCompareInput.MyDiffNode) 194 ((ResourceCompareInput.MyDiffNode)node).fireChange(); 195 } else { 196 node.copy(true); 197 } 198 } 199 } 200 } 201 202 | Popular Tags |