admin管理员组文章数量:1305671
The following always shows a blank / empty TextMergeViewer
:
public class SSCCE extends Dialog {
protected SSCCE(Shell parentShell) { super(parentShell); }
protected Control createDialogArea(Composite parent) {
Composite area = (Composite)super.createDialogArea(parent);
CompareConfiguration cc = new CompareConfiguration();
TextMergeViewer tmv = new TextMergeViewer(area, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL, cc);
tmv.setInput(new CompareEditorInput(cc) {
protected Object prepareInput(IProgressMonitor arg0) throws InvocationTargetException, InterruptedException {
return new DiffNode(new CompareEntry("lName", "lContent"), new CompareEntry("lName", "lContent"));
}});
GridDataFactory.fillDefaults().grab(true, true).applyTo(tmv.getControl());
return area;
}
protected boolean isResizable() { return true; }
private class CompareEntry implements IStreamContentAccessor, ITypedElement {
String contents, name;
public CompareEntry(String _contents,String _name) {
contents = _contents; name = _name;
}
public InputStream getContents() throws CoreException {
return new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8));
}
public String getType() { return ITypedElement.TEXT_TYPE; }
public Image getImage() { return null; }
public String getName() { return name; }
}
}
... if I replace tmv.setInput()
with CompareUI.openCompareDialog()
I see EXACTLY what I'm expecting to see, so I'm guessing my CompareEditorInput
stuff is OK / there's something I need to do to force the TextMergeViewer
to recognize the inputs?
The following always shows a blank / empty TextMergeViewer
:
public class SSCCE extends Dialog {
protected SSCCE(Shell parentShell) { super(parentShell); }
protected Control createDialogArea(Composite parent) {
Composite area = (Composite)super.createDialogArea(parent);
CompareConfiguration cc = new CompareConfiguration();
TextMergeViewer tmv = new TextMergeViewer(area, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL, cc);
tmv.setInput(new CompareEditorInput(cc) {
protected Object prepareInput(IProgressMonitor arg0) throws InvocationTargetException, InterruptedException {
return new DiffNode(new CompareEntry("lName", "lContent"), new CompareEntry("lName", "lContent"));
}});
GridDataFactory.fillDefaults().grab(true, true).applyTo(tmv.getControl());
return area;
}
protected boolean isResizable() { return true; }
private class CompareEntry implements IStreamContentAccessor, ITypedElement {
String contents, name;
public CompareEntry(String _contents,String _name) {
contents = _contents; name = _name;
}
public InputStream getContents() throws CoreException {
return new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8));
}
public String getType() { return ITypedElement.TEXT_TYPE; }
public Image getImage() { return null; }
public String getName() { return name; }
}
}
... if I replace tmv.setInput()
with CompareUI.openCompareDialog()
I see EXACTLY what I'm expecting to see, so I'm guessing my CompareEditorInput
stuff is OK / there's something I need to do to force the TextMergeViewer
to recognize the inputs?
1 Answer
Reset to default 0So the problem was that TextMergeViewer
wants a DiffNode
for input, not a CompareEditorInput
(which was what CompareUI.openCompareDialog()
wanted for input).
So changing the following:
tmv.setInput(new CompareEditorInput(cc) {
protected Object prepareInput(IProgressMonitor arg0)
throws InvocationTargetException, InterruptedException {
return new DiffNode(
new CompareEntry("lName", "lContent"),
new CompareEntry("lName", "lContent"));
}});
to the following:
tmv.setInput(new DiffNode(
new CompareEntry("lName", "lContent"),
new CompareEntry("lName", "lContent")));
makes everything work :-)
本文标签: javaEclipse TextMergeViewer not showing contentStack Overflow
版权声明:本文标题:java - Eclipse TextMergeViewer not showing content? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741808555a2398654.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
tmv.invalidateTextPresentation()
&tmv.refresh()
, neither of which added any value :-/ – Dave Carpeneto Commented Feb 3 at 17:03