1 11 package org.eclipse.team.ui.mapping; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.ui.*; 15 16 26 public abstract class SaveableComparison extends Saveable { 27 28 31 public static final int PROP_DIRTY = IWorkbenchPartConstants.PROP_DIRTY; 32 33 private boolean dirty; 34 private ListenerList listeners = new ListenerList(ListenerList.IDENTITY); 35 36 39 public boolean isDirty() { 40 return dirty; 41 } 42 43 46 public void doSave(IProgressMonitor monitor) throws CoreException { 47 if (!isDirty()) 48 return; 49 performSave(monitor); 50 setDirty(false); 51 } 52 53 58 public void doRevert(IProgressMonitor monitor) { 59 if (!isDirty()) 60 return; 61 performRevert(monitor); 62 setDirty(false); 63 } 64 65 70 public void addPropertyListener(IPropertyListener listener) { 71 listeners.add(listener); 72 } 73 74 79 public void removePropertyListener(IPropertyListener listener) { 80 listeners.remove(listener); 81 } 82 83 88 protected void setDirty(boolean dirty) { 89 if (this.dirty == dirty) { 90 return; 91 } 92 this.dirty = dirty; 93 firePropertyChange(PROP_DIRTY); 94 } 95 96 100 protected void firePropertyChange(final int property) { 101 Object [] allListeners = listeners.getListeners(); 102 for (int i = 0; i < allListeners.length; i++) { 103 final Object object = allListeners[i]; 104 SafeRunner.run(new ISafeRunnable() { 105 public void run() throws Exception { 106 ((IPropertyListener)object).propertyChanged(SaveableComparison.this, property); 107 } 108 public void handleException(Throwable exception) { 109 } 111 }); 112 } 113 } 114 115 122 protected abstract void performSave(IProgressMonitor monitor) throws CoreException; 123 124 129 protected abstract void performRevert(IProgressMonitor monitor); 130 } 131 | Popular Tags |