|
Lines 14-19
Link Here
|
| 14 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
| 15 |
import java.util.ResourceBundle; |
15 |
import java.util.ResourceBundle; |
| 16 |
|
16 |
|
|
|
17 |
import org.eclipse.compare.contentmergeviewer.ContentMergeViewer; |
| 17 |
import org.eclipse.compare.contentmergeviewer.IFlushable; |
18 |
import org.eclipse.compare.contentmergeviewer.IFlushable; |
| 18 |
import org.eclipse.compare.internal.BinaryCompareViewer; |
19 |
import org.eclipse.compare.internal.BinaryCompareViewer; |
| 19 |
import org.eclipse.compare.internal.ChangePropertyAction; |
20 |
import org.eclipse.compare.internal.ChangePropertyAction; |
|
Lines 191-198
Link Here
|
| 191 |
private String fTitle; |
192 |
private String fTitle; |
| 192 |
private ListenerList fListenerList= new ListenerList(); |
193 |
private ListenerList fListenerList= new ListenerList(); |
| 193 |
private CompareNavigator fNavigator; |
194 |
private CompareNavigator fNavigator; |
| 194 |
private boolean fDirty= false; |
195 |
private ArrayList fLeftDirtyViewers = new ArrayList(); |
| 195 |
private ArrayList fDirtyViewers= new ArrayList(); |
196 |
private ArrayList fRightDirtyViewers = new ArrayList(); |
| 196 |
private IPropertyChangeListener fDirtyStateListener; |
197 |
private IPropertyChangeListener fDirtyStateListener; |
| 197 |
|
198 |
|
| 198 |
boolean fStructureCompareOnSingleClick= true; |
199 |
boolean fStructureCompareOnSingleClick= true; |
|
Lines 989-1006
Link Here
|
| 989 |
} |
990 |
} |
| 990 |
|
991 |
|
| 991 |
/** |
992 |
/** |
| 992 |
* Returns <code>true</code> if there are unsaved changes. |
993 |
* Returns <code>true</code> if there are unsaved changes in either left or |
| 993 |
* The value returned is the value of the <code>DIRTY_STATE</code> property of this input object. |
994 |
* right side. The value returned is the value of the |
| 994 |
|
995 |
* <code>DIRTY_STATE</code> property of this input object. |
| 995 |
* Returns <code>true</code> if this input has unsaved changes, |
996 |
* |
| 996 |
* that is if <code>setDirty(true)</code> has been called. |
997 |
* Returns <code>true</code> if left or right side has unsaved changes |
| 997 |
* Subclasses don't have to override if the functionality provided by <code>setDirty</code> |
998 |
* Subclasses don't have to override if the functionality provided by |
| 998 |
* is sufficient. |
999 |
* <code>setDirty</code> is sufficient. |
| 999 |
* |
1000 |
* |
| 1000 |
* @return <code>true</code> if there are changes that need to be saved |
1001 |
* @return <code>true</code> if there are changes that need to be saved |
| 1001 |
*/ |
1002 |
*/ |
| 1002 |
public boolean isSaveNeeded() { |
1003 |
public boolean isSaveNeeded() { |
| 1003 |
return fDirty || fDirtyViewers.size() > 0; |
1004 |
return isLeftSaveNeeded() || isRightSaveNeeded(); |
|
|
1005 |
} |
| 1006 |
|
| 1007 |
/** |
| 1008 |
* Returns <code>true</code> if there are unsaved changes for left side. |
| 1009 |
* |
| 1010 |
* @return <code>true</code> if there are changes that need to be saved |
| 1011 |
*/ |
| 1012 |
protected boolean isLeftSaveNeeded() { |
| 1013 |
return fLeftDirtyViewers.size() > 0; |
| 1014 |
} |
| 1015 |
|
| 1016 |
/** |
| 1017 |
* Returns <code>true</code> if there are unsaved changes for right side. |
| 1018 |
* |
| 1019 |
* @return <code>true</code> if there are changes that need to be saved |
| 1020 |
*/ |
| 1021 |
protected boolean isRightSaveNeeded() { |
| 1022 |
return fRightDirtyViewers.size() > 0; |
| 1004 |
} |
1023 |
} |
| 1005 |
|
1024 |
|
| 1006 |
/** |
1025 |
/** |
|
Lines 1017-1047
Link Here
|
| 1017 |
} |
1036 |
} |
| 1018 |
|
1037 |
|
| 1019 |
/** |
1038 |
/** |
| 1020 |
* Sets the dirty state of this input to the given |
1039 |
* Sets the dirty state of this input to the given value and sends out a |
| 1021 |
* value and sends out a <code>PropertyChangeEvent</code> if the new value differs from the old value. |
1040 |
* <code>PropertyChangeEvent</code> if the new value differs from the old |
| 1022 |
* |
1041 |
* value. Direct calling this method with parameter dirty equal to |
| 1023 |
* @param dirty the dirty state for this compare input |
1042 |
* <code>false</code> when there are unsaved changes in viewers, results in |
|
|
1043 |
* inconsistent state. The dirty state of compare input should be based only |
| 1044 |
* on the information if there are changes in viewers for left or right |
| 1045 |
* side. |
| 1046 |
* |
| 1047 |
* @param dirty |
| 1048 |
* the dirty state for this compare input |
| 1024 |
*/ |
1049 |
*/ |
| 1025 |
public void setDirty(boolean dirty) { |
1050 |
public void setDirty(boolean dirty) { |
| 1026 |
boolean oldDirty = fDirty || fDirtyViewers.size() > 0; |
1051 |
boolean oldDirty = isSaveNeeded(); |
| 1027 |
fDirty= dirty; |
1052 |
boolean newDirty = dirty || isSaveNeeded(); |
| 1028 |
if (!fDirty) |
1053 |
if (!newDirty) { |
| 1029 |
fDirtyViewers.clear(); |
1054 |
fLeftDirtyViewers.clear(); |
| 1030 |
if (oldDirty != dirty) |
1055 |
fRightDirtyViewers.clear(); |
| 1031 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, new Boolean(oldDirty), new Boolean(dirty)); |
1056 |
} |
|
|
1057 |
if (oldDirty != isSaveNeeded()) { |
| 1058 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(isSaveNeeded())); |
| 1059 |
} |
| 1032 |
} |
1060 |
} |
| 1033 |
|
1061 |
|
|
|
1062 |
/** |
| 1063 |
* Method adds or removes viewers that changed left or right side of this |
| 1064 |
* compare input. Any modification of any of the list of viewers may result |
| 1065 |
* in dirty state change. |
| 1066 |
* |
| 1067 |
* @param source |
| 1068 |
* the object that fired <code>PropertyChangeEvent</code> |
| 1069 |
* modifying the dirty state |
| 1070 |
* @param dirty |
| 1071 |
* value that describes if the changes were added or removed |
| 1072 |
*/ |
| 1034 |
private void setDirty(Object source, boolean dirty) { |
1073 |
private void setDirty(Object source, boolean dirty) { |
| 1035 |
Assert.isNotNull(source); |
1074 |
Assert.isNotNull(source); |
| 1036 |
boolean oldDirty= fDirty || fDirtyViewers.size() > 0; |
1075 |
boolean oldDirty = isSaveNeeded(); |
| 1037 |
if (dirty) |
1076 |
ContentMergeViewer cmv = (ContentMergeViewer) source; |
| 1038 |
fDirtyViewers.add(source); |
1077 |
if (dirty) { |
| 1039 |
else |
1078 |
if (cmv.isLeftDirty()) { |
| 1040 |
fDirtyViewers.remove(source); |
1079 |
if (!fLeftDirtyViewers.contains(source)) { |
| 1041 |
boolean newDirty= fDirty || fDirtyViewers.size() > 0; |
1080 |
fLeftDirtyViewers.add(source); |
| 1042 |
if (DEBUG) System.out.println("setDirty("+source+", "+dirty+"): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1081 |
} |
| 1043 |
if (oldDirty != newDirty) |
1082 |
} |
| 1044 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, new Boolean(oldDirty), new Boolean(newDirty)); |
1083 |
if (cmv.isRightDirty()) { |
|
|
1084 |
if (!fRightDirtyViewers.contains(source)) { |
| 1085 |
fRightDirtyViewers.add(source); |
| 1086 |
} |
| 1087 |
} |
| 1088 |
} else { |
| 1089 |
if (!cmv.isLeftDirty()) { |
| 1090 |
fLeftDirtyViewers.remove(source); |
| 1091 |
} |
| 1092 |
if (!cmv.isRightDirty()) { |
| 1093 |
fRightDirtyViewers.remove(source); |
| 1094 |
} |
| 1095 |
} |
| 1096 |
boolean newDirty = isSaveNeeded(); |
| 1097 |
if (DEBUG) { |
| 1098 |
System.out.println("setDirty(" + source + ", " + dirty + "): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 1099 |
} |
| 1100 |
if (oldDirty != newDirty) { |
| 1101 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty)); |
| 1102 |
} |
| 1045 |
} |
1103 |
} |
| 1046 |
|
1104 |
|
| 1047 |
/* (non Javadoc) |
1105 |
/* (non Javadoc) |