|
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 192-199
Link Here
|
| 192 |
private String fTitle; |
193 |
private String fTitle; |
| 193 |
private ListenerList fListenerList= new ListenerList(); |
194 |
private ListenerList fListenerList= new ListenerList(); |
| 194 |
private CompareNavigator fNavigator; |
195 |
private CompareNavigator fNavigator; |
| 195 |
private boolean fDirty= false; |
196 |
private ArrayList fLeftDirtyViewers = new ArrayList(); |
| 196 |
private ArrayList fDirtyViewers= new ArrayList(); |
197 |
private ArrayList fRightDirtyViewers = new ArrayList(); |
| 197 |
private IPropertyChangeListener fDirtyStateListener; |
198 |
private IPropertyChangeListener fDirtyStateListener; |
| 198 |
|
199 |
|
| 199 |
boolean fStructureCompareOnSingleClick= true; |
200 |
boolean fStructureCompareOnSingleClick= true; |
|
Lines 1015-1032
Link Here
|
| 1015 |
} |
1016 |
} |
| 1016 |
|
1017 |
|
| 1017 |
/** |
1018 |
/** |
| 1018 |
* Returns <code>true</code> if there are unsaved changes. |
1019 |
* Returns <code>true</code> if there are unsaved changes in either left or |
| 1019 |
* The value returned is the value of the <code>DIRTY_STATE</code> property of this input object. |
1020 |
* right side. The value returned is the value of the |
| 1020 |
|
1021 |
* <code>DIRTY_STATE</code> property of this input object. |
| 1021 |
* Returns <code>true</code> if this input has unsaved changes, |
1022 |
* |
| 1022 |
* that is if <code>setDirty(true)</code> has been called. |
1023 |
* Returns <code>true</code> if left or right side has unsaved changes |
| 1023 |
* Subclasses don't have to override if the functionality provided by <code>setDirty</code> |
1024 |
* Subclasses don't have to override if the functionality provided by |
| 1024 |
* is sufficient. |
1025 |
* <code>setDirty</code> is sufficient. |
| 1025 |
* |
1026 |
* |
| 1026 |
* @return <code>true</code> if there are changes that need to be saved |
1027 |
* @return <code>true</code> if there are changes that need to be saved |
| 1027 |
*/ |
1028 |
*/ |
| 1028 |
public boolean isSaveNeeded() { |
1029 |
public boolean isSaveNeeded() { |
| 1029 |
return fDirty || fDirtyViewers.size() > 0; |
1030 |
return isLeftSaveNeeded() || isRightSaveNeeded(); |
|
|
1031 |
} |
| 1032 |
|
| 1033 |
/** |
| 1034 |
* Returns <code>true</code> if there are unsaved changes for left side. |
| 1035 |
* |
| 1036 |
* @return <code>true</code> if there are changes that need to be saved |
| 1037 |
*/ |
| 1038 |
protected boolean isLeftSaveNeeded() { |
| 1039 |
return fLeftDirtyViewers.size() > 0; |
| 1040 |
} |
| 1041 |
|
| 1042 |
/** |
| 1043 |
* Returns <code>true</code> if there are unsaved changes for right side. |
| 1044 |
* |
| 1045 |
* @return <code>true</code> if there are changes that need to be saved |
| 1046 |
*/ |
| 1047 |
protected boolean isRightSaveNeeded() { |
| 1048 |
return fRightDirtyViewers.size() > 0; |
| 1030 |
} |
1049 |
} |
| 1031 |
|
1050 |
|
| 1032 |
/** |
1051 |
/** |
|
Lines 1043-1073
Link Here
|
| 1043 |
} |
1062 |
} |
| 1044 |
|
1063 |
|
| 1045 |
/** |
1064 |
/** |
| 1046 |
* Sets the dirty state of this input to the given |
1065 |
* Sets the dirty state of this input to the given value and sends out a |
| 1047 |
* value and sends out a <code>PropertyChangeEvent</code> if the new value differs from the old value. |
1066 |
* <code>PropertyChangeEvent</code> if the new value differs from the old |
| 1048 |
* |
1067 |
* value. Direct calling this method with parameter dirty equal to |
| 1049 |
* @param dirty the dirty state for this compare input |
1068 |
* <code>false</code> when there are unsaved changes in viewers, results in |
|
|
1069 |
* inconsistent state. The dirty state of compare input should be based only |
| 1070 |
* on the information if there are changes in viewers for left or right |
| 1071 |
* side. |
| 1072 |
* |
| 1073 |
* @param dirty |
| 1074 |
* the dirty state for this compare input |
| 1050 |
*/ |
1075 |
*/ |
| 1051 |
public void setDirty(boolean dirty) { |
1076 |
public void setDirty(boolean dirty) { |
| 1052 |
boolean oldDirty = fDirty || fDirtyViewers.size() > 0; |
1077 |
boolean oldDirty = isSaveNeeded(); |
| 1053 |
fDirty= dirty; |
1078 |
boolean newDirty = dirty || isSaveNeeded(); |
| 1054 |
if (!fDirty) |
1079 |
if (!newDirty) { |
| 1055 |
fDirtyViewers.clear(); |
1080 |
fLeftDirtyViewers.clear(); |
| 1056 |
if (oldDirty != dirty) |
1081 |
fRightDirtyViewers.clear(); |
| 1057 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(dirty)); |
1082 |
} |
|
|
1083 |
if (oldDirty != isSaveNeeded()) { |
| 1084 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(isSaveNeeded())); |
| 1085 |
} |
| 1058 |
} |
1086 |
} |
| 1059 |
|
1087 |
|
|
|
1088 |
/** |
| 1089 |
* Method adds or removes viewers that changed left or right side of this |
| 1090 |
* compare input. Any modification of any of the list of viewers may result |
| 1091 |
* in dirty state change. |
| 1092 |
* |
| 1093 |
* @param source |
| 1094 |
* the object that fired <code>PropertyChangeEvent</code> |
| 1095 |
* modifying the dirty state |
| 1096 |
* @param dirty |
| 1097 |
* value that describes if the changes were added or removed |
| 1098 |
*/ |
| 1060 |
private void setDirty(Object source, boolean dirty) { |
1099 |
private void setDirty(Object source, boolean dirty) { |
| 1061 |
Assert.isNotNull(source); |
1100 |
Assert.isNotNull(source); |
| 1062 |
boolean oldDirty= fDirty || fDirtyViewers.size() > 0; |
1101 |
boolean oldDirty = isSaveNeeded(); |
| 1063 |
if (dirty) |
1102 |
ContentMergeViewer cmv = (ContentMergeViewer) source; |
| 1064 |
fDirtyViewers.add(source); |
1103 |
if (dirty) { |
| 1065 |
else |
1104 |
if (cmv.isLeftDirty()) { |
| 1066 |
fDirtyViewers.remove(source); |
1105 |
if (!fLeftDirtyViewers.contains(source)) { |
| 1067 |
boolean newDirty= fDirty || fDirtyViewers.size() > 0; |
1106 |
fLeftDirtyViewers.add(source); |
| 1068 |
if (DEBUG) System.out.println("setDirty("+source+", "+dirty+"): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1107 |
} |
| 1069 |
if (oldDirty != newDirty) |
1108 |
} |
|
|
1109 |
if (cmv.isRightDirty()) { |
| 1110 |
if (!fRightDirtyViewers.contains(source)) { |
| 1111 |
fRightDirtyViewers.add(source); |
| 1112 |
} |
| 1113 |
} |
| 1114 |
} else { |
| 1115 |
if (!cmv.isLeftDirty()) { |
| 1116 |
fLeftDirtyViewers.remove(source); |
| 1117 |
} |
| 1118 |
if (!cmv.isRightDirty()) { |
| 1119 |
fRightDirtyViewers.remove(source); |
| 1120 |
} |
| 1121 |
} |
| 1122 |
boolean newDirty = isSaveNeeded(); |
| 1123 |
if (DEBUG) { |
| 1124 |
System.out.println("setDirty(" + source + ", " + dirty + "): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 1125 |
} |
| 1126 |
if (oldDirty != newDirty) { |
| 1070 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty)); |
1127 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty)); |
|
|
1128 |
} |
| 1071 |
} |
1129 |
} |
| 1072 |
|
1130 |
|
| 1073 |
/* (non Javadoc) |
1131 |
/* (non Javadoc) |