1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import org.eclipse.compare.ITypedElement; 14 import org.eclipse.compare.structuremergeviewer.ICompareInput; 15 import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener; 16 import org.eclipse.core.runtime.*; 17 import org.eclipse.swt.graphics.Image; 18 19 23 public abstract class AbstractCompareInput implements ICompareInput { 24 25 private ITypedElement ancestor; 26 private ITypedElement left; 27 private ITypedElement right; 28 private int kind; 29 private final ListenerList listeners = new ListenerList(ListenerList.IDENTITY); 30 31 public AbstractCompareInput(int kind, 32 ITypedElement ancestor, 33 ITypedElement left, 34 ITypedElement right) { 35 this.kind = kind; 36 this.ancestor = ancestor; 37 this.left = left; 38 this.right = right; 39 } 40 41 44 public void addCompareInputChangeListener( 45 ICompareInputChangeListener listener) { 46 if (!containsListener(listener)) { 47 listeners.add(listener); 48 getChangeNotifier().connect(this); 49 } 50 } 51 52 55 public void removeCompareInputChangeListener( 56 ICompareInputChangeListener listener) { 57 if (containsListener(listener)) { 58 listeners.remove(listener); 59 getChangeNotifier().disconnect(this); 60 } 61 } 62 63 67 protected void fireChange() { 68 if (!listeners.isEmpty()) { 69 Object [] allListeners = listeners.getListeners(); 70 for (int i = 0; i < allListeners.length; i++) { 71 final ICompareInputChangeListener listener = (ICompareInputChangeListener)allListeners[i]; 72 SafeRunner.run(new ISafeRunnable() { 73 public void run() throws Exception { 74 listener.compareInputChanged(AbstractCompareInput.this); 75 } 76 public void handleException(Throwable exception) { 77 } 79 }); 80 } 81 } 82 } 83 84 private boolean containsListener(ICompareInputChangeListener listener) { 85 if (listeners.isEmpty()) 86 return false; 87 Object [] allListeners = listeners.getListeners(); 88 for (int i = 0; i < allListeners.length; i++) { 89 Object object = allListeners[i]; 90 if (object == listener) 91 return true; 92 } 93 return false; 94 } 95 96 99 public void copy(boolean leftToRight) { 100 Assert.isTrue(false, "Copy is not support by this type of compare input"); } 102 103 106 public ITypedElement getAncestor() { 107 return ancestor; 108 } 109 110 113 public Image getImage() { 114 return getMainElement().getImage(); 115 } 116 117 125 private ITypedElement getMainElement() { 126 if (left != null) 127 return left; 128 if (right != null) 129 return right; 130 return ancestor; 131 } 132 133 136 public int getKind() { 137 return kind; 138 } 139 140 144 public void setKind(int kind) { 145 this.kind = kind; 146 } 147 148 151 public ITypedElement getLeft() { 152 return left; 153 } 154 155 158 public String getName() { 159 return getMainElement().getName(); 160 } 161 162 165 public ITypedElement getRight() { 166 return right; 167 } 168 169 174 protected abstract CompareInputChangeNotifier getChangeNotifier(); 175 176 180 public void setAncestor(ITypedElement ancestor) { 181 this.ancestor = ancestor; 182 } 183 184 188 public void setLeft(ITypedElement left) { 189 this.left = left; 190 } 191 192 196 public void setRight(ITypedElement right) { 197 this.right = right; 198 } 199 200 203 public abstract void update(); 204 205 209 public abstract boolean needsUpdate(); 210 211 212 } 213 | Popular Tags |