|
Lines 11-20
Link Here
|
| 11 |
package org.eclipse.compare; |
11 |
package org.eclipse.compare; |
| 12 |
|
12 |
|
| 13 |
import java.lang.reflect.InvocationTargetException; |
13 |
import java.lang.reflect.InvocationTargetException; |
| 14 |
import java.util.ArrayList; |
|
|
| 15 |
import java.util.ResourceBundle; |
14 |
import java.util.ResourceBundle; |
| 16 |
|
15 |
|
|
|
16 |
import org.eclipse.compare.contentmergeviewer.ContentMergeViewer; |
| 17 |
import org.eclipse.compare.contentmergeviewer.IFlushable; |
17 |
import org.eclipse.compare.contentmergeviewer.IFlushable; |
|
|
18 |
import org.eclipse.compare.contentmergeviewer.IFlushable2; |
| 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; |
| 20 |
import org.eclipse.compare.internal.CompareContentViewerSwitchingPane; |
21 |
import org.eclipse.compare.internal.CompareContentViewerSwitchingPane; |
|
Lines 177-183
Link Here
|
| 177 |
* @since 3.3 |
178 |
* @since 3.3 |
| 178 |
*/ |
179 |
*/ |
| 179 |
public static final String PROP_SELECTED_EDITION= ICompareUIConstants.PROP_SELECTED_EDITION; |
180 |
public static final String PROP_SELECTED_EDITION= ICompareUIConstants.PROP_SELECTED_EDITION; |
| 180 |
|
181 |
|
|
|
182 |
public static final int LEFT_SIDE = 1; |
| 183 |
public static final int RIGHT_SIDE = 2; |
| 184 |
|
| 181 |
private static final String COMPARE_EDITOR_IMAGE_NAME= "eview16/compare_view.gif"; //$NON-NLS-1$ |
185 |
private static final String COMPARE_EDITOR_IMAGE_NAME= "eview16/compare_view.gif"; //$NON-NLS-1$ |
| 182 |
private static Image fgTitleImage; |
186 |
private static Image fgTitleImage; |
| 183 |
|
187 |
|
|
Lines 193-200
Link Here
|
| 193 |
private String fTitle; |
197 |
private String fTitle; |
| 194 |
private ListenerList fListenerList= new ListenerList(); |
198 |
private ListenerList fListenerList= new ListenerList(); |
| 195 |
private CompareNavigator fNavigator; |
199 |
private CompareNavigator fNavigator; |
| 196 |
private boolean fDirty= false; |
200 |
private ContentMergeViewer fLeftDirtyViewer = null; |
| 197 |
private ArrayList fDirtyViewers= new ArrayList(); |
201 |
private ContentMergeViewer fRightDirtyViewer = null; |
| 198 |
private IPropertyChangeListener fDirtyStateListener; |
202 |
private IPropertyChangeListener fDirtyStateListener; |
| 199 |
|
203 |
|
| 200 |
boolean fStructureCompareOnSingleClick= true; |
204 |
boolean fStructureCompareOnSingleClick= true; |
|
Lines 1016-1033
Link Here
|
| 1016 |
} |
1020 |
} |
| 1017 |
|
1021 |
|
| 1018 |
/** |
1022 |
/** |
| 1019 |
* Returns <code>true</code> if there are unsaved changes. |
1023 |
* Returns <code>true</code> if there are unsaved changes in either left or |
| 1020 |
* The value returned is the value of the <code>DIRTY_STATE</code> property of this input object. |
1024 |
* right side. The value returned is the value of the |
| 1021 |
|
1025 |
* <code>DIRTY_STATE</code> property of this input object. |
| 1022 |
* Returns <code>true</code> if this input has unsaved changes, |
1026 |
* |
| 1023 |
* that is if <code>setDirty(true)</code> has been called. |
1027 |
* Returns <code>true</code> if left or right side has unsaved changes |
| 1024 |
* Subclasses don't have to override if the functionality provided by <code>setDirty</code> |
1028 |
* Subclasses don't have to override if the functionality provided by |
| 1025 |
* is sufficient. |
1029 |
* <code>setDirty</code> is sufficient. |
| 1026 |
* |
1030 |
* |
| 1027 |
* @return <code>true</code> if there are changes that need to be saved |
1031 |
* @return <code>true</code> if there are changes that need to be saved |
| 1028 |
*/ |
1032 |
*/ |
| 1029 |
public boolean isSaveNeeded() { |
1033 |
public boolean isSaveNeeded() { |
| 1030 |
return fDirty || fDirtyViewers.size() > 0; |
1034 |
return isLeftSaveNeeded() || isRightSaveNeeded(); |
|
|
1035 |
} |
| 1036 |
|
| 1037 |
/** |
| 1038 |
* Returns <code>true</code> if there are unsaved changes for left side. |
| 1039 |
* |
| 1040 |
* @return <code>true</code> if there are changes that need to be saved |
| 1041 |
*/ |
| 1042 |
protected boolean isLeftSaveNeeded() { |
| 1043 |
return fLeftDirtyViewer != null; |
| 1044 |
} |
| 1045 |
|
| 1046 |
/** |
| 1047 |
* Returns <code>true</code> if there are unsaved changes for right side. |
| 1048 |
* |
| 1049 |
* @return <code>true</code> if there are changes that need to be saved |
| 1050 |
*/ |
| 1051 |
protected boolean isRightSaveNeeded() { |
| 1052 |
return fRightDirtyViewer != null; |
| 1031 |
} |
1053 |
} |
| 1032 |
|
1054 |
|
| 1033 |
/** |
1055 |
/** |
|
Lines 1044-1074
Link Here
|
| 1044 |
} |
1066 |
} |
| 1045 |
|
1067 |
|
| 1046 |
/** |
1068 |
/** |
| 1047 |
* Sets the dirty state of this input to the given |
1069 |
* Sets the dirty state of this input to the given value and sends out a |
| 1048 |
* value and sends out a <code>PropertyChangeEvent</code> if the new value differs from the old value. |
1070 |
* <code>PropertyChangeEvent</code> if the new value differs from the old |
| 1049 |
* |
1071 |
* value. Direct calling this method with parameter dirty equal to |
| 1050 |
* @param dirty the dirty state for this compare input |
1072 |
* <code>false</code> when there are unsaved changes in viewers, results in |
|
|
1073 |
* inconsistent state. The dirty state of compare input should be based only |
| 1074 |
* on the information if there are changes in viewers for left or right |
| 1075 |
* side. |
| 1076 |
* |
| 1077 |
* @param dirty |
| 1078 |
* the dirty state for this compare input |
| 1051 |
*/ |
1079 |
*/ |
| 1052 |
public void setDirty(boolean dirty) { |
1080 |
public void setDirty(boolean dirty) { |
| 1053 |
boolean oldDirty = fDirty || fDirtyViewers.size() > 0; |
1081 |
boolean oldDirty = isSaveNeeded(); |
| 1054 |
fDirty= dirty; |
1082 |
boolean newDirty = dirty || isSaveNeeded(); |
| 1055 |
if (!fDirty) |
1083 |
if (!newDirty) { |
| 1056 |
fDirtyViewers.clear(); |
1084 |
fLeftDirtyViewer = null; |
| 1057 |
if (oldDirty != dirty) |
1085 |
fRightDirtyViewer = null; |
| 1058 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(dirty)); |
1086 |
} |
|
|
1087 |
if (oldDirty != isSaveNeeded()) { |
| 1088 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(isSaveNeeded())); |
| 1089 |
} |
| 1059 |
} |
1090 |
} |
| 1060 |
|
1091 |
|
|
|
1092 |
/** |
| 1093 |
* Method adds or removes viewers that changed left or right side of this |
| 1094 |
* compare input. Any modification of any of the list of viewers may result |
| 1095 |
* in dirty state change. |
| 1096 |
* |
| 1097 |
* @param source |
| 1098 |
* the object that fired <code>PropertyChangeEvent</code> |
| 1099 |
* modifying the dirty state |
| 1100 |
* @param dirty |
| 1101 |
* value that describes if the changes were added or removed |
| 1102 |
*/ |
| 1061 |
private void setDirty(Object source, boolean dirty) { |
1103 |
private void setDirty(Object source, boolean dirty) { |
| 1062 |
Assert.isNotNull(source); |
1104 |
Assert.isNotNull(source); |
| 1063 |
boolean oldDirty= fDirty || fDirtyViewers.size() > 0; |
1105 |
boolean oldDirty = isSaveNeeded(); |
| 1064 |
if (dirty) |
1106 |
ContentMergeViewer cmv = (ContentMergeViewer) source; |
| 1065 |
fDirtyViewers.add(source); |
1107 |
if (dirty) { |
| 1066 |
else |
1108 |
if (cmv.isLeftDirty()) { |
| 1067 |
fDirtyViewers.remove(source); |
1109 |
if (fLeftDirtyViewer == null) { |
| 1068 |
boolean newDirty= fDirty || fDirtyViewers.size() > 0; |
1110 |
fLeftDirtyViewer = cmv; |
| 1069 |
if (DEBUG) System.out.println("setDirty("+source+", "+dirty+"): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
1111 |
} |
| 1070 |
if (oldDirty != newDirty) |
1112 |
} |
|
|
1113 |
if (cmv.isRightDirty()) { |
| 1114 |
if (fRightDirtyViewer == null) { |
| 1115 |
fRightDirtyViewer = cmv; |
| 1116 |
} |
| 1117 |
} |
| 1118 |
} else { |
| 1119 |
if (!cmv.isLeftDirty()) { |
| 1120 |
fLeftDirtyViewer = null; |
| 1121 |
} |
| 1122 |
if (!cmv.isRightDirty()) { |
| 1123 |
fRightDirtyViewer = null; |
| 1124 |
} |
| 1125 |
} |
| 1126 |
boolean newDirty = isSaveNeeded(); |
| 1127 |
if (DEBUG) { |
| 1128 |
System.out.println("setDirty(" + source + ", " + dirty + "): " + newDirty); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
| 1129 |
} |
| 1130 |
if (oldDirty != newDirty) { |
| 1071 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty)); |
1131 |
Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, Boolean.valueOf(oldDirty), Boolean.valueOf(newDirty)); |
|
|
1132 |
} |
| 1072 |
} |
1133 |
} |
| 1073 |
|
1134 |
|
| 1074 |
/* (non Javadoc) |
1135 |
/* (non Javadoc) |
|
Lines 1129-1135
Link Here
|
| 1129 |
flushViewer(fStructurePane2, monitor); |
1190 |
flushViewer(fStructurePane2, monitor); |
| 1130 |
flushViewer(fContentInputPane, monitor); |
1191 |
flushViewer(fContentInputPane, monitor); |
| 1131 |
} |
1192 |
} |
| 1132 |
|
1193 |
|
|
|
1194 |
protected void flushLeftViewers(IProgressMonitor monitor) { |
| 1195 |
// flush changes in left dirty viewer |
| 1196 |
flushViewer(fStructureInputPane, monitor, LEFT_SIDE); |
| 1197 |
flushViewer(fStructurePane1, monitor, LEFT_SIDE); |
| 1198 |
flushViewer(fStructurePane2, monitor, LEFT_SIDE); |
| 1199 |
flushViewer(fContentInputPane, monitor, LEFT_SIDE); |
| 1200 |
} |
| 1201 |
|
| 1202 |
protected void flushRightViewers(IProgressMonitor monitor) { |
| 1203 |
// flush changes in right dirty viewer |
| 1204 |
flushViewer(fStructureInputPane, monitor, RIGHT_SIDE); |
| 1205 |
flushViewer(fStructurePane1, monitor, RIGHT_SIDE); |
| 1206 |
flushViewer(fStructurePane2, monitor, RIGHT_SIDE); |
| 1207 |
flushViewer(fContentInputPane, monitor, RIGHT_SIDE); |
| 1208 |
} |
| 1209 |
|
| 1133 |
private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) { |
1210 |
private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) { |
| 1134 |
if (pane != null) { |
1211 |
if (pane != null) { |
| 1135 |
IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class); |
1212 |
IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class); |
|
Lines 1138-1143
Link Here
|
| 1138 |
} |
1215 |
} |
| 1139 |
} |
1216 |
} |
| 1140 |
|
1217 |
|
|
|
1218 |
private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm, int side) { |
| 1219 |
if (pane != null) { |
| 1220 |
IFlushable2 flushable = (IFlushable2)Utilities.getAdapter(pane, IFlushable2.class); |
| 1221 |
if (flushable != null) |
| 1222 |
flushable.flush(side, pm); |
| 1223 |
} |
| 1224 |
} |
| 1225 |
|
| 1141 |
/* (non-Javadoc) |
1226 |
/* (non-Javadoc) |
| 1142 |
* @see org.eclipse.compare.ICompareContainer#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) |
1227 |
* @see org.eclipse.compare.ICompareContainer#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) |
| 1143 |
*/ |
1228 |
*/ |