Lines 15-27
Link Here
|
15 |
|
15 |
|
16 |
import java.io.File; |
16 |
import java.io.File; |
17 |
import java.io.IOException; |
17 |
import java.io.IOException; |
|
|
18 |
import java.io.InputStream; |
18 |
import java.net.MalformedURLException; |
19 |
import java.net.MalformedURLException; |
19 |
import java.net.URL; |
20 |
import java.net.URL; |
20 |
import java.util.ArrayList; |
21 |
import java.util.ArrayList; |
21 |
import java.util.Iterator; |
22 |
import java.util.Iterator; |
22 |
import java.util.List; |
23 |
import java.util.List; |
23 |
|
24 |
|
|
|
25 |
import org.eclipse.compare.CompareConfiguration; |
26 |
import org.eclipse.compare.CompareEditorInput; |
27 |
import org.eclipse.compare.ITypedElement; |
28 |
import org.eclipse.compare.ResourceNode; |
29 |
import org.eclipse.compare.contentmergeviewer.ITokenComparator; |
30 |
import org.eclipse.compare.contentmergeviewer.TokenComparator; |
31 |
import org.eclipse.compare.internal.ResourceCompareInput.FilteredBufferedResourceNode; |
24 |
import org.eclipse.compare.internal.merge.DocumentMerger; |
32 |
import org.eclipse.compare.internal.merge.DocumentMerger; |
|
|
33 |
import org.eclipse.compare.internal.merge.DocumentMerger.IDocumentMergerInput; |
34 |
import org.eclipse.compare.structuremergeviewer.DiffNode; |
35 |
import org.eclipse.compare.structuremergeviewer.Differencer; |
36 |
import org.eclipse.compare.structuremergeviewer.ICompareInput; |
37 |
import org.eclipse.compare.structuremergeviewer.IDiffElement; |
25 |
import org.eclipse.core.resources.IContainer; |
38 |
import org.eclipse.core.resources.IContainer; |
26 |
import org.eclipse.core.resources.IFile; |
39 |
import org.eclipse.core.resources.IFile; |
27 |
import org.eclipse.core.resources.IProject; |
40 |
import org.eclipse.core.resources.IProject; |
Lines 35-44
Link Here
|
35 |
import org.eclipse.jface.dialogs.Dialog; |
48 |
import org.eclipse.jface.dialogs.Dialog; |
36 |
import org.eclipse.jface.dialogs.IDialogConstants; |
49 |
import org.eclipse.jface.dialogs.IDialogConstants; |
37 |
import org.eclipse.jface.dialogs.IDialogSettings; |
50 |
import org.eclipse.jface.dialogs.IDialogSettings; |
|
|
51 |
import org.eclipse.jface.dialogs.IPageChangingListener; |
38 |
import org.eclipse.jface.dialogs.MessageDialog; |
52 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
|
53 |
import org.eclipse.jface.dialogs.PageChangingEvent; |
39 |
import org.eclipse.jface.dialogs.TitleAreaDialog; |
54 |
import org.eclipse.jface.dialogs.TitleAreaDialog; |
40 |
import org.eclipse.jface.resource.ImageDescriptor; |
55 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
56 |
import org.eclipse.jface.text.Document; |
41 |
import org.eclipse.jface.text.IDocument; |
57 |
import org.eclipse.jface.text.IDocument; |
|
|
58 |
import org.eclipse.jface.text.Position; |
42 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
59 |
import org.eclipse.jface.viewers.DoubleClickEvent; |
43 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
60 |
import org.eclipse.jface.viewers.IDoubleClickListener; |
44 |
import org.eclipse.jface.viewers.ISelection; |
61 |
import org.eclipse.jface.viewers.ISelection; |
Lines 69-74
Link Here
|
69 |
import org.eclipse.swt.widgets.Listener; |
86 |
import org.eclipse.swt.widgets.Listener; |
70 |
import org.eclipse.swt.widgets.Shell; |
87 |
import org.eclipse.swt.widgets.Shell; |
71 |
import org.eclipse.swt.widgets.Text; |
88 |
import org.eclipse.swt.widgets.Text; |
|
|
89 |
import org.eclipse.ui.IWorkbenchPart; |
72 |
import org.eclipse.ui.model.BaseWorkbenchContentProvider; |
90 |
import org.eclipse.ui.model.BaseWorkbenchContentProvider; |
73 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
91 |
import org.eclipse.ui.model.WorkbenchLabelProvider; |
74 |
import org.eclipse.ui.views.navigator.ResourceComparator; |
92 |
import org.eclipse.ui.views.navigator.ResourceComparator; |
Lines 88-97
Link Here
|
88 |
final GenerateDiffFileWizard wizard = new GenerateDiffFileWizard(merger, rightToLeft); |
106 |
final GenerateDiffFileWizard wizard = new GenerateDiffFileWizard(merger, rightToLeft); |
89 |
wizard.setWindowTitle(title); |
107 |
wizard.setWindowTitle(title); |
90 |
WizardDialog dialog = new WizardDialog(shell, wizard); |
108 |
WizardDialog dialog = new WizardDialog(shell, wizard); |
|
|
109 |
|
110 |
dialog.addPageChangingListener(new IPageChangingListener() { |
111 |
|
112 |
public void handlePageChanging(PageChangingEvent event) { |
113 |
if(event.getTargetPage() instanceof LocationPage) { |
114 |
LocationPage page = (LocationPage) event.getTargetPage(); |
115 |
page.updateAssociatedResources(); |
116 |
} |
117 |
} |
118 |
|
119 |
}); |
120 |
|
91 |
dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT); |
121 |
dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT); |
92 |
dialog.open(); |
122 |
dialog.open(); |
93 |
} |
123 |
} |
|
|
124 |
public static void run(IResource[] input, Shell shell) { |
125 |
final String title = CompareMessages.GenerateLocalDiff_title; |
126 |
final GenerateDiffFileWizard wizard = new GenerateDiffFileWizard(input); |
127 |
wizard.setWindowTitle(title); |
128 |
WizardDialog dialog = new WizardDialog(shell, wizard); |
129 |
|
130 |
dialog.addPageChangingListener(new IPageChangingListener() { |
94 |
|
131 |
|
|
|
132 |
public void handlePageChanging(PageChangingEvent event) { |
133 |
if(event.getTargetPage() instanceof LocationPage) { |
134 |
LocationPage page = (LocationPage) event.getTargetPage(); |
135 |
page.updateAssociatedResources(); |
136 |
} |
137 |
} |
138 |
|
139 |
}); |
140 |
|
141 |
dialog.setMinimumPageSize(INITIAL_WIDTH, INITIAL_HEIGHT); |
142 |
dialog.open(); |
143 |
|
144 |
} |
145 |
|
95 |
protected class DirectionSelectionPage extends WizardPage { |
146 |
protected class DirectionSelectionPage extends WizardPage { |
96 |
|
147 |
|
97 |
public final static int LEFT_OPTION = 1; |
148 |
public final static int LEFT_OPTION = 1; |
Lines 214-220
Link Here
|
214 |
*/ |
265 |
*/ |
215 |
private final DefaultValuesStore store; |
266 |
private final DefaultValuesStore store; |
216 |
|
267 |
|
217 |
|
|
|
218 |
class LocationPageContentProvider extends BaseWorkbenchContentProvider { |
268 |
class LocationPageContentProvider extends BaseWorkbenchContentProvider { |
219 |
//Never show closed projects |
269 |
//Never show closed projects |
220 |
boolean showClosedProjects=false; |
270 |
boolean showClosedProjects=false; |
Lines 448-453
Link Here
|
448 |
this.store= store; |
498 |
this.store= store; |
449 |
} |
499 |
} |
450 |
|
500 |
|
|
|
501 |
public void updateAssociatedResources() { |
502 |
Differencer dif = new Differencer(); |
503 |
if(directionSelectionPage.isRightToLeft()) |
504 |
startNode = (DiffNode) dif.findDifferences(false, null, null, null, |
505 |
new FilteredBufferedResourceNode(rightResource), |
506 |
new FilteredBufferedResourceNode(leftResource)); |
507 |
else if(!directionSelectionPage.isRightToLeft()) |
508 |
startNode = (DiffNode) dif.findDifferences(false, null, null, null, |
509 |
new FilteredBufferedResourceNode(leftResource), |
510 |
new FilteredBufferedResourceNode(rightResource)); |
511 |
associatedResources = buildMap(startNode); |
512 |
} |
513 |
|
451 |
/** |
514 |
/** |
452 |
* Allow the user to finish if a valid file has been entered. |
515 |
* Allow the user to finish if a valid file has been entered. |
453 |
*/ |
516 |
*/ |
Lines 463-469
Link Here
|
463 |
pageValid= true; |
526 |
pageValid= true; |
464 |
break; |
527 |
break; |
465 |
} |
528 |
} |
466 |
|
529 |
|
467 |
/** |
530 |
/** |
468 |
* Avoid draw flicker by clearing error message |
531 |
* Avoid draw flicker by clearing error message |
469 |
* if all is valid. |
532 |
* if all is valid. |
Lines 623-629
Link Here
|
623 |
public void createControl(Composite parent) { |
686 |
public void createControl(Composite parent) { |
624 |
|
687 |
|
625 |
final Composite composite= new Composite(parent, SWT.NULL); |
688 |
final Composite composite= new Composite(parent, SWT.NULL); |
626 |
composite.setLayout(new GridLayout()); |
689 |
GridLayout lay = new GridLayout(); |
|
|
690 |
lay.verticalSpacing = 15; |
691 |
composite.setLayout(lay); |
627 |
setControl(composite); |
692 |
setControl(composite); |
628 |
initializeDialogUnits(composite); |
693 |
initializeDialogUnits(composite); |
629 |
|
694 |
|
Lines 632-640
Link Here
|
632 |
|
697 |
|
633 |
//Create a location group |
698 |
//Create a location group |
634 |
setupLocationControls(composite); |
699 |
setupLocationControls(composite); |
635 |
|
700 |
|
636 |
initializeDefaultValues(); |
701 |
initializeDefaultValues(); |
637 |
|
702 |
|
638 |
Dialog.applyDialogFont(parent); |
703 |
Dialog.applyDialogFont(parent); |
639 |
|
704 |
|
640 |
validatePage(); |
705 |
validatePage(); |
Lines 643-648
Link Here
|
643 |
setupListeners(); |
708 |
setupListeners(); |
644 |
} |
709 |
} |
645 |
|
710 |
|
|
|
711 |
|
646 |
/** |
712 |
/** |
647 |
* Setup the controls for the location. |
713 |
* Setup the controls for the location. |
648 |
*/ |
714 |
*/ |
Lines 815-821
Link Here
|
815 |
}); |
881 |
}); |
816 |
|
882 |
|
817 |
} |
883 |
} |
818 |
|
884 |
|
819 |
/** |
885 |
/** |
820 |
* Enable and disable controls based on the selected radio button. |
886 |
* Enable and disable controls based on the selected radio button. |
821 |
*/ |
887 |
*/ |
Lines 1158-1164
Link Here
|
1158 |
|
1224 |
|
1159 |
private final DefaultValuesStore defaultValuesStore; |
1225 |
private final DefaultValuesStore defaultValuesStore; |
1160 |
|
1226 |
|
1161 |
private DocumentMerger merger; |
|
|
1162 |
private IDocument leftDoc; |
1227 |
private IDocument leftDoc; |
1163 |
private IDocument rightDoc; |
1228 |
private IDocument rightDoc; |
1164 |
private String leftPath; |
1229 |
private String leftPath; |
Lines 1170-1192
Link Here
|
1170 |
private Text unified_customRelativeText; |
1235 |
private Text unified_customRelativeText; |
1171 |
private Button unified_customRelativeOption; |
1236 |
private Button unified_customRelativeOption; |
1172 |
|
1237 |
|
|
|
1238 |
private IResource rightResource; |
1239 |
private IResource leftResource; |
1240 |
|
1241 |
private ArrayList associatedResources; |
1242 |
|
1173 |
public GenerateDiffFileWizard() { |
1243 |
public GenerateDiffFileWizard() { |
1174 |
super(); |
1244 |
super(); |
1175 |
setWindowTitle(CompareMessages.GenerateLocalDiff_title); |
1245 |
setWindowTitle(CompareMessages.GenerateLocalDiff_title); |
1176 |
initializeDefaultPageImageDescriptor(); |
1246 |
initializeDefaultPageImageDescriptor(); |
1177 |
defaultValuesStore = new DefaultValuesStore(); |
1247 |
defaultValuesStore = new DefaultValuesStore(); |
|
|
1248 |
associatedResources = new ArrayList(); |
1178 |
} |
1249 |
} |
1179 |
|
1250 |
|
|
|
1251 |
private DiffNode startNode; |
1252 |
|
1253 |
public GenerateDiffFileWizard(IResource[] input) { |
1254 |
this(); |
1255 |
|
1256 |
this.leftDoc = new Document(); |
1257 |
this.rightDoc = new Document(); |
1258 |
|
1259 |
leftResource = input[0]; |
1260 |
rightResource = input[1]; |
1261 |
|
1262 |
leftPath = leftResource.getFullPath().toString(); |
1263 |
rightPath = rightResource.getFullPath().toString(); |
1264 |
|
1265 |
Differencer dif = new Differencer(); |
1266 |
startNode = (DiffNode) dif.findDifferences(false, null, null, null, |
1267 |
new FilteredBufferedResourceNode(leftResource), |
1268 |
new FilteredBufferedResourceNode(rightResource)); |
1269 |
associatedResources = buildMap(startNode); |
1270 |
|
1271 |
} |
1272 |
|
1180 |
public GenerateDiffFileWizard(DocumentMerger merger, boolean rightToLeft) { |
1273 |
public GenerateDiffFileWizard(DocumentMerger merger, boolean rightToLeft) { |
1181 |
this(); |
1274 |
this(); |
1182 |
this.merger = merger; |
|
|
1183 |
this.leftDoc = merger.getDocument(MergeViewerContentProvider.LEFT_CONTRIBUTOR); |
1275 |
this.leftDoc = merger.getDocument(MergeViewerContentProvider.LEFT_CONTRIBUTOR); |
1184 |
this.rightDoc = merger.getDocument(MergeViewerContentProvider.RIGHT_CONTRIBUTOR); |
1276 |
this.rightDoc = merger.getDocument(MergeViewerContentProvider.RIGHT_CONTRIBUTOR); |
1185 |
this.leftPath = merger.getCompareConfiguration().getLeftLabel(leftDoc); |
1277 |
this.leftPath = merger.getCompareConfiguration().getLeftLabel(leftDoc); |
1186 |
this.rightPath = merger.getCompareConfiguration().getRightLabel(rightDoc); |
1278 |
this.rightPath = merger.getCompareConfiguration().getRightLabel(rightDoc); |
1187 |
this.rightToLeft = rightToLeft; |
1279 |
this.rightToLeft = rightToLeft; |
|
|
1280 |
IWorkbenchPart workbenchPart = merger.getCompareConfiguration().getContainer().getWorkbenchPart(); |
1281 |
|
1282 |
if(workbenchPart instanceof CompareEditor) { |
1283 |
|
1284 |
CompareEditor editor = (CompareEditor)workbenchPart; |
1285 |
|
1286 |
CompareEditorInput input = (CompareEditorInput)editor.getEditorInput(); |
1287 |
input.getCompareResult(); |
1288 |
if(input.getCompareResult() instanceof ICompareInput) { |
1289 |
ICompareInput node = (ICompareInput)input.getCompareResult(); |
1290 |
|
1291 |
leftResource = ((ResourceNode)node.getLeft()).getResource(); |
1292 |
rightResource = ((ResourceNode)node.getRight()).getResource(); |
1293 |
Differencer dif = new Differencer(); |
1294 |
startNode = (DiffNode) dif.findDifferences(false, null, null, null, |
1295 |
new FilteredBufferedResourceNode(leftResource), |
1296 |
new FilteredBufferedResourceNode(rightResource)); |
1297 |
|
1298 |
if(leftResource instanceof IFile && rightResource instanceof IFile) |
1299 |
associatedResources.add(new Object[] {leftResource, rightResource}); |
1300 |
|
1301 |
} |
1302 |
|
1303 |
} |
1188 |
} |
1304 |
} |
|
|
1305 |
|
1306 |
private ArrayList buildMap(DiffNode diff) { |
1307 |
ArrayList res = new ArrayList(); |
1308 |
IResource lresource = null; |
1309 |
IResource rresource = null; |
1310 |
IDiffElement[] children = diff.getChildren(); |
1311 |
if (children != null) { |
1312 |
for (int i = 0; i < children.length; i++) { |
1313 |
if (children[i] instanceof DiffNode) { |
1314 |
DiffNode o = (DiffNode) children[i]; |
1315 |
if (o != null && o.getKind() != Differencer.NO_CHANGE) { |
1316 |
DiffNode node = o; |
1189 |
|
1317 |
|
|
|
1318 |
ITypedElement left = node.getLeft(); |
1319 |
if (left instanceof BufferedResourceNode) { |
1320 |
BufferedResourceNode bn = (BufferedResourceNode) left; |
1321 |
IResource resource = bn.getResource(); |
1322 |
if (resource instanceof IFile) { |
1323 |
lresource = resource; |
1324 |
} |
1325 |
|
1326 |
} |
1327 |
|
1328 |
ITypedElement right = node.getRight(); |
1329 |
if (right instanceof BufferedResourceNode) { |
1330 |
BufferedResourceNode bn = (BufferedResourceNode) right; |
1331 |
IResource resource = bn.getResource(); |
1332 |
if (resource instanceof IFile) { |
1333 |
rresource = resource; |
1334 |
} |
1335 |
} |
1336 |
|
1337 |
if(rresource != null || lresource != null) |
1338 |
res.add(new Object[] {lresource, rresource}); |
1339 |
lresource = null; |
1340 |
rresource = null; |
1341 |
} |
1342 |
|
1343 |
res.addAll(buildMap((DiffNode) children[i])); |
1344 |
} |
1345 |
} |
1346 |
return res; |
1347 |
} |
1348 |
return res; |
1349 |
} |
1350 |
|
1351 |
|
1190 |
public void addPages() { |
1352 |
public void addPages() { |
1191 |
String pageTitle = CompareMessages.GenerateLocalDiff_pageTitle; |
1353 |
String pageTitle = CompareMessages.GenerateLocalDiff_pageTitle; |
1192 |
String pageDescription = CompareMessages.GenerateLocalDiff_Specify_the_file_which_contributes_the_changes; |
1354 |
String pageDescription = CompareMessages.GenerateLocalDiff_Specify_the_file_which_contributes_the_changes; |
Lines 1286-1292
Link Here
|
1286 |
public boolean needsProgressMonitor() { |
1448 |
public boolean needsProgressMonitor() { |
1287 |
return true; |
1449 |
return true; |
1288 |
} |
1450 |
} |
1289 |
|
1451 |
|
1290 |
/** |
1452 |
/** |
1291 |
* Completes processing of the wizard. If this method returns <code> |
1453 |
* Completes processing of the wizard. If this method returns <code> |
1292 |
* true</code>, the wizard will close; otherwise, it will stay active. |
1454 |
* true</code>, the wizard will close; otherwise, it will stay active. |
Lines 1301-1324
Link Here
|
1301 |
} |
1463 |
} |
1302 |
|
1464 |
|
1303 |
//Validation of patch root |
1465 |
//Validation of patch root |
1304 |
if(optionsPage.getRootSelection() == OptionsPage.ROOT_CUSTOM) { |
1466 |
// if(optionsPage.getRootSelection() == OptionsPage.ROOT_CUSTOM) { |
1305 |
String path = optionsPage.getPath(); |
1467 |
// String path = optionsPage.getPath(); |
1306 |
IFile file2; |
1468 |
// IFile file2; |
1307 |
try { |
1469 |
// try { |
1308 |
file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); |
1470 |
// file2 = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); |
1309 |
} catch(IllegalArgumentException e) { |
1471 |
// } catch(IllegalArgumentException e) { |
1310 |
final String title = CompareMessages.GenerateLocalDiff_3; |
1472 |
// final String title = CompareMessages.GenerateLocalDiff_3; |
1311 |
final String msg = CompareMessages.GenerateLocalDiff_4; |
1473 |
// final String msg = CompareMessages.GenerateLocalDiff_4; |
1312 |
final MessageDialog dialog = new MessageDialog(getShell(), title, |
1474 |
// final MessageDialog dialog = new MessageDialog(getShell(), title, |
1313 |
null, msg, MessageDialog.ERROR, |
1475 |
// null, msg, MessageDialog.ERROR, |
1314 |
new String[] { IDialogConstants.OK_LABEL }, 0); |
1476 |
// new String[] { IDialogConstants.OK_LABEL }, 0); |
1315 |
dialog.open(); |
1477 |
// dialog.open(); |
1316 |
return false; |
1478 |
// return false; |
1317 |
} |
1479 |
// } |
1318 |
if(!validateFile2(file2)) { |
1480 |
// if(!validateFile2(file2)) { |
1319 |
return false; |
1481 |
// return false; |
1320 |
} |
1482 |
// } |
1321 |
} |
1483 |
// } |
1322 |
|
1484 |
|
1323 |
// Create the patch |
1485 |
// Create the patch |
1324 |
generateDiffFile(file); |
1486 |
generateDiffFile(file); |
Lines 1385-1397
Link Here
|
1385 |
} else { |
1547 |
} else { |
1386 |
oldPath = this.rightPath; |
1548 |
oldPath = this.rightPath; |
1387 |
} |
1549 |
} |
1388 |
|
1550 |
|
1389 |
UnifiedDiffFormatter formatter = new UnifiedDiffFormatter(merger |
1551 |
//TODO extend formatter to use list of mergers. |
1390 |
.getAllDiffs(), leftDoc, rightDoc, oldPath, toPath, |
1552 |
UnifiedDiffFormatter formatter = new UnifiedDiffFormatter(createFormatterInput()); |
1391 |
directionSelectionPage.isRightToLeft()); |
|
|
1392 |
try { |
1553 |
try { |
1393 |
if (file == null) { |
1554 |
if (file == null) { |
1394 |
formatter.generateDiffToClipboard(); |
1555 |
formatter.generateDiff(); |
1395 |
} else { |
1556 |
} else { |
1396 |
formatter.generateDiff(file); |
1557 |
formatter.generateDiff(file); |
1397 |
} |
1558 |
} |
Lines 1399-1404
Link Here
|
1399 |
throw new RuntimeException(e); |
1560 |
throw new RuntimeException(e); |
1400 |
} |
1561 |
} |
1401 |
} |
1562 |
} |
|
|
1563 |
|
1564 |
private Object[][] createFormatterInput() { |
1565 |
Object[] resArr = associatedResources.toArray(); |
1566 |
int size = resArr.length; |
1567 |
Object[][] result = new Object[size][3]; |
1568 |
DocumentMerger merg = null; |
1569 |
for (int j = 0; j < size; j++) { |
1570 |
IFile sourceRes = (IFile) ((Object[])resArr[j])[0]; |
1571 |
IFile targetRes = (IFile) ((Object[])resArr[j])[1]; |
1572 |
merg = createDocumentMerger(sourceRes, targetRes); |
1573 |
result[j][0] = merg; |
1574 |
result[j][1] = targetRes ; |
1575 |
result[j][2] = sourceRes ; |
1576 |
} |
1577 |
return result; |
1578 |
} |
1579 |
|
1580 |
private DocumentMerger createDocumentMerger(IFile leftFile, IFile rightFile){ |
1581 |
IDocument leftDoc = convertFileToDocument(leftFile); |
1582 |
IDocument rightDoc = convertFileToDocument(rightFile); |
1583 |
if (leftDoc == null) { |
1584 |
leftDoc = new Document(); |
1585 |
} |
1586 |
if (rightDoc == null) { |
1587 |
rightDoc = new Document(); |
1588 |
} |
1589 |
DocumentMerger docMerger; |
1590 |
docMerger = new DocumentMerger(new LocalDiffMergerInput(leftDoc, rightDoc)); |
1591 |
try { |
1592 |
docMerger.doDiff(); |
1593 |
} catch (Exception e) { |
1594 |
throw new RuntimeException(e); |
1595 |
} |
1596 |
return docMerger; |
1597 |
} |
1598 |
|
1599 |
private IDocument convertFileToDocument(IFile file) { |
1600 |
if(file == null) |
1601 |
return null; |
1602 |
StringBuffer str = new StringBuffer(); |
1603 |
int c; |
1604 |
try{ |
1605 |
InputStream inputStream = file.getContents(); |
1606 |
while ((c = inputStream.read())!=-1){ |
1607 |
str.append((char)c); |
1608 |
} |
1609 |
inputStream.close(); |
1610 |
return new Document(str.toString()); |
1611 |
}catch(Exception ex){ |
1612 |
CompareUIPlugin.log(ex); |
1613 |
} |
1614 |
|
1615 |
return null; |
1616 |
} |
1617 |
|
1618 |
private class LocalDiffMergerInput implements IDocumentMergerInput { |
1619 |
|
1620 |
private IDocument leftDoc; |
1621 |
private IDocument rightDoc; |
1622 |
|
1623 |
public LocalDiffMergerInput(IDocument leftDoc, IDocument rightDoc) { |
1624 |
this.leftDoc = leftDoc ; |
1625 |
this.rightDoc= rightDoc; |
1626 |
} |
1627 |
|
1628 |
public ITokenComparator createTokenComparator(String line) { |
1629 |
return new TokenComparator(line); |
1630 |
} |
1631 |
public CompareConfiguration getCompareConfiguration() { |
1632 |
return new CompareConfiguration(); |
1633 |
} |
1634 |
public IDocument getDocument(char contributor) { |
1635 |
switch (contributor) { |
1636 |
case MergeViewerContentProvider.LEFT_CONTRIBUTOR: |
1637 |
return leftDoc; |
1638 |
case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: |
1639 |
return rightDoc; |
1640 |
case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: |
1641 |
return null; |
1642 |
} |
1643 |
return null; |
1644 |
} |
1645 |
public int getHunkStart() { |
1646 |
return 0; |
1647 |
} |
1648 |
public Position getRegion(char contributor) { |
1649 |
switch (contributor) { |
1650 |
case MergeViewerContentProvider.LEFT_CONTRIBUTOR: |
1651 |
return new Position(0, leftDoc.getLength()); |
1652 |
case MergeViewerContentProvider.RIGHT_CONTRIBUTOR: |
1653 |
return new Position(0, rightDoc.getLength()); |
1654 |
case MergeViewerContentProvider.ANCESTOR_CONTRIBUTOR: |
1655 |
return new Position(0, 0); |
1656 |
} |
1657 |
return null; |
1658 |
} |
1659 |
public boolean isHunkOnLeft() { |
1660 |
return false; |
1661 |
} |
1662 |
public boolean isIgnoreAncestor() { |
1663 |
return true; |
1664 |
} |
1665 |
public boolean isPatchHunk() { |
1666 |
return false; |
1667 |
} |
1668 |
|
1669 |
public boolean isShowPseudoConflicts() { |
1670 |
return false; |
1671 |
} |
1672 |
public boolean isThreeWay() { |
1673 |
return false; |
1674 |
} |
1675 |
public boolean isPatchHunkOk() { |
1676 |
return false; |
1677 |
} |
1678 |
|
1679 |
} |
1402 |
|
1680 |
|
1403 |
public boolean validateFile(File file) { |
1681 |
public boolean validateFile(File file) { |
1404 |
|
1682 |
|