|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006, 2007 IBM Corporation and others. |
2 |
* Copyright (c) 2006, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 12-29
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.io.UnsupportedEncodingException; |
13 |
import java.io.UnsupportedEncodingException; |
| 14 |
|
14 |
|
| 15 |
import org.eclipse.compare.*; |
|
|
| 16 |
import org.eclipse.compare.contentmergeviewer.IDocumentRange; |
| 17 |
import org.eclipse.compare.internal.CompareUIPlugin; |
| 18 |
import org.eclipse.compare.internal.Utilities; |
| 19 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 20 |
import org.eclipse.core.runtime.CoreException; |
15 |
import org.eclipse.core.runtime.CoreException; |
| 21 |
import org.eclipse.core.runtime.IProgressMonitor; |
16 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 22 |
import org.eclipse.jface.text.*; |
17 |
import org.eclipse.core.runtime.OperationCanceledException; |
|
|
18 |
|
| 19 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 20 |
|
| 21 |
import org.eclipse.jface.text.Document; |
| 22 |
import org.eclipse.jface.text.IDocument; |
| 23 |
import org.eclipse.jface.text.IDocumentExtension3; |
| 24 |
import org.eclipse.jface.text.IDocumentPartitioner; |
| 25 |
|
| 23 |
import org.eclipse.ui.IEditorInput; |
26 |
import org.eclipse.ui.IEditorInput; |
| 24 |
import org.eclipse.ui.services.IDisposable; |
27 |
import org.eclipse.ui.services.IDisposable; |
|
|
28 |
|
| 25 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
29 |
import org.eclipse.ui.texteditor.IDocumentProvider; |
| 26 |
|
30 |
|
|
|
31 |
import org.eclipse.compare.CompareUI; |
| 32 |
import org.eclipse.compare.IEditableContent; |
| 33 |
import org.eclipse.compare.IEncodedStreamContentAccessor; |
| 34 |
import org.eclipse.compare.ISharedDocumentAdapter; |
| 35 |
import org.eclipse.compare.IStreamContentAccessor; |
| 36 |
import org.eclipse.compare.ITypedElement; |
| 37 |
import org.eclipse.compare.SharedDocumentAdapter; |
| 38 |
import org.eclipse.compare.contentmergeviewer.IDocumentRange; |
| 39 |
import org.eclipse.compare.internal.CompareUIPlugin; |
| 40 |
import org.eclipse.compare.internal.Utilities; |
| 41 |
|
| 27 |
/** |
42 |
/** |
| 28 |
* An {@link IStructureCreator2} that attempts to use an {@link IDocumentProvider} |
43 |
* An {@link IStructureCreator2} that attempts to use an {@link IDocumentProvider} |
| 29 |
* to obtain a shared document for an {@link ITypedElement}. |
44 |
* to obtain a shared document for an {@link ITypedElement}. |
|
Lines 43-56
Link Here
|
| 43 |
IDocument doc= CompareUI.getDocument(input); |
58 |
IDocument doc= CompareUI.getDocument(input); |
| 44 |
if (doc == null) { |
59 |
if (doc == null) { |
| 45 |
if (input instanceof IStreamContentAccessor) { |
60 |
if (input instanceof IStreamContentAccessor) { |
| 46 |
IStreamContentAccessor sca= (IStreamContentAccessor) input; |
61 |
IStreamContentAccessor sca= (IStreamContentAccessor) input; |
| 47 |
try { |
62 |
try { |
| 48 |
contents= Utilities.readString(sca); |
63 |
contents= Utilities.readString(sca); |
| 49 |
} catch (CoreException e) { |
64 |
} catch (CoreException e) { |
| 50 |
// return null indicates the error. |
65 |
// return null indicates the error. |
| 51 |
CompareUIPlugin.log(e); |
66 |
CompareUIPlugin.log(e); |
| 52 |
return null; |
67 |
return null; |
| 53 |
} |
68 |
} |
| 54 |
} |
69 |
} |
| 55 |
|
70 |
|
| 56 |
if (contents == null) { |
71 |
if (contents == null) { |
|
Lines 59-65
Link Here
|
| 59 |
} |
74 |
} |
| 60 |
|
75 |
|
| 61 |
doc= new Document(contents); |
76 |
doc= new Document(contents); |
| 62 |
setupDocument(doc); |
77 |
setupDocument(doc); |
| 63 |
} |
78 |
} |
| 64 |
|
79 |
|
| 65 |
try { |
80 |
try { |
|
Lines 77-83
Link Here
|
| 77 |
final IStructureComparator[] result = new IStructureComparator[] { null }; |
92 |
final IStructureComparator[] result = new IStructureComparator[] { null }; |
| 78 |
Runnable runnable = new Runnable() { |
93 |
Runnable runnable = new Runnable() { |
| 79 |
public void run() { |
94 |
public void run() { |
| 80 |
result[0] = internalCreateStructure(element, monitor); |
95 |
try { |
|
|
96 |
result[0]= internalCreateStructure(element, monitor); |
| 97 |
} catch (OperationCanceledException ex) { |
| 98 |
return; |
| 99 |
} |
| 81 |
} |
100 |
} |
| 82 |
}; |
101 |
}; |
| 83 |
Utilities.runInUIThread(runnable); |
102 |
Utilities.runInUIThread(runnable); |
|
Lines 194-200
Link Here
|
| 194 |
} |
213 |
} |
| 195 |
|
214 |
|
| 196 |
/** |
215 |
/** |
| 197 |
* Default implementation of save that extracts the contents from |
216 |
* Default implementation of save that extracts the contents from |
| 198 |
* the document of an {@link IDocumentRange} and sets it on the |
217 |
* the document of an {@link IDocumentRange} and sets it on the |
| 199 |
* input. If the input is an {@link IEncodedStreamContentAccessor}, |
218 |
* input. If the input is an {@link IEncodedStreamContentAccessor}, |
| 200 |
* the charset of the input is used to extract the contents from the |
219 |
* the charset of the input is used to extract the contents from the |
|
Lines 234-244
Link Here
|
| 234 |
} |
253 |
} |
| 235 |
if (encoding == null) |
254 |
if (encoding == null) |
| 236 |
encoding= ResourcesPlugin.getEncoding(); |
255 |
encoding= ResourcesPlugin.getEncoding(); |
| 237 |
byte[] bytes; |
256 |
byte[] bytes; |
| 238 |
try { |
257 |
try { |
| 239 |
bytes= contents.getBytes(encoding); |
258 |
bytes= contents.getBytes(encoding); |
| 240 |
} catch (UnsupportedEncodingException e) { |
259 |
} catch (UnsupportedEncodingException e) { |
| 241 |
bytes= contents.getBytes(); |
260 |
bytes= contents.getBytes(); |
| 242 |
} |
261 |
} |
| 243 |
bca.setContent(bytes); |
262 |
bca.setContent(bytes); |
| 244 |
} |
263 |
} |
|
Lines 257-263
Link Here
|
| 257 |
|
276 |
|
| 258 |
/** |
277 |
/** |
| 259 |
* Create an {@link ISharedDocumentAdapter} that will provide the document key for the given input |
278 |
* Create an {@link ISharedDocumentAdapter} that will provide the document key for the given input |
| 260 |
* object for any {@link DocumentRangeNode} instances whose document is the same as the |
279 |
* object for any {@link DocumentRangeNode} instances whose document is the same as the |
| 261 |
* provided document. |
280 |
* provided document. |
| 262 |
* @param input the input element |
281 |
* @param input the input element |
| 263 |
* @param document the document associated with the input element |
282 |
* @param document the document associated with the input element |
|
Lines 308-314
Link Here
|
| 308 |
|
327 |
|
| 309 |
// Build the structure |
328 |
// Build the structure |
| 310 |
IStructureComparator structure= createStructure(input, monitor); |
329 |
IStructureComparator structure= createStructure(input, monitor); |
| 311 |
if (structure == null) // we couldn't parse the structure |
330 |
if (structure == null) // we couldn't parse the structure |
| 312 |
return null; // so we can't find anything |
331 |
return null; // so we can't find anything |
| 313 |
|
332 |
|
| 314 |
// find the path in the tree |
333 |
// find the path in the tree |
|
Lines 331-337
Link Here
|
| 331 |
return null; |
350 |
return null; |
| 332 |
// Build the structure |
351 |
// Build the structure |
| 333 |
IStructureComparator structure= getStructure(input); |
352 |
IStructureComparator structure= getStructure(input); |
| 334 |
if (structure == null) // we couldn't parse the structure |
353 |
if (structure == null) // we couldn't parse the structure |
| 335 |
return null; // so we can't find anything |
354 |
return null; // so we can't find anything |
| 336 |
|
355 |
|
| 337 |
// find the path in the tree |
356 |
// find the path in the tree |
|
Lines 373-379
Link Here
|
| 373 |
IStructureComparator result= find(child, path, index+1); |
392 |
IStructureComparator result= find(child, path, index+1); |
| 374 |
if (result != null) |
393 |
if (result != null) |
| 375 |
return result; |
394 |
return result; |
| 376 |
} |
395 |
} |
| 377 |
} |
396 |
} |
| 378 |
} |
397 |
} |
| 379 |
} |
398 |
} |
|
Lines 408-414
Link Here
|
| 408 |
|
427 |
|
| 409 |
private IDisposable getDisposable(Object object) { |
428 |
private IDisposable getDisposable(Object object) { |
| 410 |
if (object instanceof IDisposable) { |
429 |
if (object instanceof IDisposable) { |
| 411 |
return (IDisposable) object; |
430 |
return (IDisposable) object; |
| 412 |
} |
431 |
} |
| 413 |
if (object instanceof DocumentRangeNode) { |
432 |
if (object instanceof DocumentRangeNode) { |
| 414 |
DocumentRangeNode node = (DocumentRangeNode) object; |
433 |
DocumentRangeNode node = (DocumentRangeNode) object; |