Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 167607 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java (-3 / +29 lines)
Lines 83-90 Link Here
83
	
83
	
84
	private class InternalResourceSaveableComparison extends LocalResourceSaveableComparison {
84
	private class InternalResourceSaveableComparison extends LocalResourceSaveableComparison {
85
		public InternalResourceSaveableComparison(
85
		public InternalResourceSaveableComparison(
86
				ICompareInput input, CompareEditorInput editorInput) {
86
				ICompareInput input, CompareEditorInput editorInput, boolean connected) {
87
			super(input, editorInput, SaveableCompareEditorInput.getFileElement(input, editorInput));
87
			super(input, editorInput, SaveableCompareEditorInput.getFileElement(input, editorInput), connected);
88
		}
88
		}
89
89
90
		protected void fireInputChange() {
90
		protected void fireInputChange() {
Lines 127-132 Link Here
127
			}
127
			}
128
		};
128
		};
129
		getCompareInput().addCompareInputChangeListener(compareInputChangeListener);
129
		getCompareInput().addCompareInputChangeListener(compareInputChangeListener);
130
		
131
		if (getSaveable() instanceof LocalResourceSaveableComparison) {
132
			LocalResourceSaveableComparison lrsc = (LocalResourceSaveableComparison) saveable;
133
			if (lrsc.isConnectedToSharedDocument()) {
134
				ICompareContainer container = getContainer();
135
				IWorkbenchPart part = container.getWorkbenchPart();
136
				if (part != null) {
137
					ISaveablesLifecycleListener lifecycleListener= (ISaveablesLifecycleListener) part.getSite().getService(ISaveablesLifecycleListener.class);
138
					lifecycleListener.handleLifecycleEvent(
139
							new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
140
					if (saveable instanceof LocalResourceSaveableComparison) {
141
						LocalResourceSaveableComparison rsc = (LocalResourceSaveableComparison) saveable;
142
						rsc.dispose();
143
					}
144
					saveable = createConnectedSaveable();
145
					lifecycleListener.handleLifecycleEvent(
146
							new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
147
148
				}
149
			}
150
		}
151
		
130
		if (getSaveable() instanceof SaveableComparison) {
152
		if (getSaveable() instanceof SaveableComparison) {
131
			SaveableComparison scm = (SaveableComparison) saveable;
153
			SaveableComparison scm = (SaveableComparison) saveable;
132
			propertyListener = new IPropertyListener() {
154
			propertyListener = new IPropertyListener() {
Lines 272-278 Link Here
272
	protected Saveable createSaveable() {
294
	protected Saveable createSaveable() {
273
		Object compareResult = getCompareResult();
295
		Object compareResult = getCompareResult();
274
		Assert.isNotNull(compareResult, "This method cannot be called until after prepareInput is called"); //$NON-NLS-1$
296
		Assert.isNotNull(compareResult, "This method cannot be called until after prepareInput is called"); //$NON-NLS-1$
275
		return new InternalResourceSaveableComparison((ICompareInput)compareResult, this);
297
		return new InternalResourceSaveableComparison((ICompareInput)compareResult, this, false);
298
	}
299
	
300
	private Saveable createConnectedSaveable() {
301
		return new InternalResourceSaveableComparison((ICompareInput)getCompareResult(), this, true);
276
	}
302
	}
277
303
278
	/* (non-Javadoc)
304
	/* (non-Javadoc)
(-)src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java (-12 / +84 lines)
Lines 13-27 Link Here
13
import org.eclipse.compare.*;
13
import org.eclipse.compare.*;
14
import org.eclipse.compare.internal.Utilities;
14
import org.eclipse.compare.internal.Utilities;
15
import org.eclipse.compare.structuremergeviewer.ICompareInput;
15
import org.eclipse.compare.structuremergeviewer.ICompareInput;
16
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.runtime.*;
17
import org.eclipse.core.runtime.*;
17
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.dialogs.IDialogConstants;
18
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.dialogs.MessageDialog;
19
import org.eclipse.jface.resource.ImageDescriptor;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.jface.text.IDocument;
20
import org.eclipse.jface.util.IPropertyChangeListener;
22
import org.eclipse.jface.util.IPropertyChangeListener;
21
import org.eclipse.jface.util.PropertyChangeEvent;
23
import org.eclipse.jface.util.PropertyChangeEvent;
22
import org.eclipse.swt.graphics.Image;
24
import org.eclipse.swt.graphics.Image;
23
import org.eclipse.team.internal.ui.*;
25
import org.eclipse.team.internal.ui.*;
24
import org.eclipse.team.ui.mapping.SaveableComparison;
26
import org.eclipse.team.ui.mapping.SaveableComparison;
27
import org.eclipse.ui.IEditorInput;
28
import org.eclipse.ui.Saveable;
29
import org.eclipse.ui.part.FileEditorInput;
30
import org.eclipse.ui.texteditor.IDocumentProvider;
25
31
26
/**
32
/**
27
 * A saveable that wraps a compare input in which the left side is a {@link LocalResourceTypedElement}
33
 * A saveable that wraps a compare input in which the left side is a {@link LocalResourceTypedElement}
Lines 37-42 Link Here
37
	private boolean isSaving;
43
	private boolean isSaving;
38
	private IContentChangeListener contentChangeListener;
44
	private IContentChangeListener contentChangeListener;
39
    private ITypedElement fileElement;
45
    private ITypedElement fileElement;
46
	private IDocument document;
40
	
47
	
41
	/**
48
	/**
42
	 * Create the resource-based saveable comparison.
49
	 * Create the resource-based saveable comparison.
Lines 44-50 Link Here
44
	 * @param editorInput the editor input containing the comparison
51
	 * @param editorInput the editor input containing the comparison
45
	 */
52
	 */
46
	public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput) {
53
	public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput) {
47
		this(input, editorInput, input.getLeft());
54
		this(input, editorInput, input.getLeft(), false);
48
	}
55
	}
49
	
56
	
50
	/**
57
	/**
Lines 52-65 Link Here
52
	 * @param input the compare input to be save
59
	 * @param input the compare input to be save
53
	 * @param editorInput the editor input containing the comparison
60
	 * @param editorInput the editor input containing the comparison
54
	 * @param fileElement the file element that handles the saving and change notification
61
	 * @param fileElement the file element that handles the saving and change notification
62
	 * @param connected 
55
	 */
63
	 */
56
	public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput, ITypedElement fileElement) {
64
	public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput, ITypedElement fileElement, boolean connected) {
57
		this.input = input;
65
		this.input = input;
58
		this.editorInput = editorInput;
66
		this.editorInput = editorInput;
59
		this.fileElement = fileElement;
67
		this.fileElement = fileElement;
60
		initializeContentChangeListeners();
68
		initializeContentChangeListeners();
69
		if (connected) {
70
			initializeHashing();
71
		}
61
	}
72
	}
62
	
73
	
74
	private void initializeHashing() {
75
		Object document= getAdapter(IDocument.class);
76
		if (document != null) {
77
			this.document = (IDocument)document;
78
		}
79
	}
80
63
	private void initializeContentChangeListeners() {
81
	private void initializeContentChangeListeners() {
64
		// We need to listen to saves to the input to catch the case
82
		// We need to listen to saves to the input to catch the case
65
		// where Save was picked from the context menu
83
		// where Save was picked from the context menu
Lines 252-274 Link Here
252
			setDirty(changed);
270
			setDirty(changed);
253
		}			
271
		}			
254
	}
272
	}
273
	
274
	/*
275
	 * @see org.eclipse.ui.Saveable#hashCode()
276
	 */
277
	public int hashCode() {
278
		if (document != null) {
279
			return document.hashCode();
280
		}
281
		return input.hashCode();
282
	}
255
283
256
	/* (non-Javadoc)
284
	/*
257
	 * @see org.eclipse.ui.Saveable#equals(java.lang.Object)
285
	 * @see org.eclipse.ui.Saveable#equals(java.lang.Object)
258
	 */
286
	 */
259
	public boolean equals(Object object) {
287
	public boolean equals(Object obj) {
260
		if (object instanceof LocalResourceSaveableComparison) {
288
		if (this == obj)
261
			LocalResourceSaveableComparison rscm = (LocalResourceSaveableComparison) object;
289
			return true;
290
		
291
		if (!(obj instanceof Saveable))
292
			return false;
293
		
294
		if (document != null) {
295
			Object otherDocument= ((Saveable)obj).getAdapter(IDocument.class);
296
			
297
			if (document == null && otherDocument == null)
298
				return false;
299
			
300
			return document != null && document.equals(otherDocument);
301
		}
302
		
303
		if (obj instanceof LocalResourceSaveableComparison) {
304
			LocalResourceSaveableComparison rscm = (LocalResourceSaveableComparison) obj;
262
			return rscm.input.equals(input);
305
			return rscm.input.equals(input);
263
		}
306
		}
264
		return false;
307
		return false;
265
	}
308
	}
266
309
	
267
	/* (non-Javadoc)
310
	public Object getAdapter(Class adapter) {
268
	 * @see org.eclipse.ui.Saveable#hashCode()
311
		if (adapter == IDocument.class) {
269
	 */
312
			if (document != null)
270
	public int hashCode() {
313
				return document;
271
		return input.hashCode();
314
			if (fileElement instanceof LocalResourceTypedElement) {
315
				LocalResourceTypedElement lrte = (LocalResourceTypedElement) fileElement;
316
				if (lrte.isConnected()) {
317
					ISharedDocumentAdapter sda = (ISharedDocumentAdapter)Utils.getAdapter(lrte, ISharedDocumentAdapter.class);
318
					if (sda != null) {
319
						IEditorInput input = sda.getDocumentKey(lrte);
320
						if (input != null) {
321
							IDocumentProvider provider = SharedDocumentAdapter.getDocumentProvider(input);
322
							if (provider != null)
323
								return provider.getDocument(input);
324
						}
325
					}
326
				}
327
			}
328
		}
329
		if (adapter == IEditorInput.class) {
330
			if (fileElement instanceof LocalResourceTypedElement) {
331
				LocalResourceTypedElement lrte = (LocalResourceTypedElement) fileElement;
332
				return new FileEditorInput((IFile)lrte.getResource());
333
			}
334
		}
335
		return super.getAdapter(adapter);
272
	}
336
	}
273
337
274
	/**
338
	/**
Lines 278-281 Link Here
278
	public ICompareInput getInput() {
342
	public ICompareInput getInput() {
279
		return input;
343
		return input;
280
	}
344
	}
345
346
	public boolean isConnectedToSharedDocument() {
347
		if (fileElement instanceof LocalResourceTypedElement) {
348
			LocalResourceTypedElement lrte = (LocalResourceTypedElement) fileElement;
349
			return lrte.isConnected();
350
		}
351
		return false;
352
	}
281
}
353
}

Return to bug 167607