我一直试图让这个工作好几天,我只是无法理解它...
我正在使用java swt并且我正在尝试打开一个标签,该标签将比较2个字符串并显示并排突出显示的差异。我已经看过很多例子,但似乎无法找到要实现的代码。
我已阅读https://wiki.eclipse.org/FAQ_How_do_I_create_a_compare_editor%3F但不确定如何实际实现此目的。
每当我尝试时,我都会收到错误 -
引起:org.eclipse.core.internal.runtime.AssertionFailedException:null参数:
教程说使用 -
public class CompareEditorAction implements
IWorkbenchWindowActionDelegate {
public void run(IAction action) {
CompareUI.openCompareEditor(new MyCompareInput());
}
}
但我不确定如何实际调用它。
非常感谢任何帮助。
干杯
抛出错误的代码 -
CompareEditorInput cei = new CompareEditorInput(new CompareConfiguration()) {
@Override
protected Object prepareInput(IProgressMonitor arg0)
throws InvocationTargetException, InterruptedException {
CompareItem ancestor = new CompareItem("Common", "contents");
CompareItem left = new CompareItem("Left", "new contents");
CompareItem right = new CompareItem("Right", "old contents");
getCompareConfiguration().setLeftLabel(left.getName());
getCompareConfiguration().setRightLabel(right.getName());
getCompareConfiguration().setAncestorLabel(ancestor.getName());
return new DiffNode(null,Differencer.CONFLICTING,ancestor,left,right);
}
};
CompareItem类
package kam.test;
import javax.swing.*;
import javax.swing.*;
import javax.swing.plaf.basic.BasicButtonUI;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareEditorInput;
import org.eclipse.compare.IModificationDate;
import org.eclipse.compare.IStreamContentAccessor;
import org.eclipse.compare.ITypedElement;
import org.eclipse.compare.structuremergeviewer.Differencer;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import java.awt.*;
import java.awt.event.*;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
class CompareItem implements IStreamContentAccessor, ITypedElement, IModificationDate {
private String contents, name;
CompareItem(String name, String contents) {
this.name = name;
this.contents = contents;
}
@Override
public long getModificationDate() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getType() {
// TODO Auto-generated method stub
return ITypedElement.TEXT_TYPE;
}
@Override
public InputStream getContents() throws CoreException {
// TODO Auto-generated method stub
return new ByteArrayInputStream(contents.getBytes());
}
@Override
public org.eclipse.swt.graphics.Image getImage() {
// TODO Auto-generated method stub
return null;
}
}
堆栈追踪 -
线程“main”java.lang.ExceptionInInitializerError中的异常 at java.lang.J9VMInternals.initialize(J9VMInternals.java:258) 在org.eclipse.compare.internal.ICompareUIConstants。(ICompareUIConstants.java:15) at java.lang.J9VMInternals.initializeImpl(Native Method) 在java.lang.J9VMInternals.initialize(J9VMInternals.java:236) 在org.eclipse.compare.CompareEditorInput。(CompareEditorInput.java:163) at java.lang.J9VMInternals.initializeImpl(Native Method) 在java.lang.J9VMInternals.initialize(J9VMInternals.java:236) 在java.lang.J9VMInternals.initialize(J9VMInternals.java:203) 在kam.test.NewCompareTest.main(NewCompareTest.java:76) 引起:org.eclipse.core.internal.runtime.AssertionFailedException:null参数: 在org.eclipse.core.internal.runtime.Assert.isNotNull(Assert.java:82) 在org.eclipse.core.internal.runtime.Assert.isNotNull(Assert.java:69) at org.eclipse.core.internal.content.ContentTypeManager.getInstance(ContentTypeManager.java:74) 在org.eclipse.core.internal.runtime.InternalPlatform.getContentTypeManager(InternalPlatform.java:363) 在org.eclipse.core.runtime.Platform.getContentTypeManager(Platform.java:593) 在org.eclipse.compare.internal.CompareUIPlugin。(CompareUIPlugin.java:213) at java.lang.J9VMInternals.initializeImpl(Native Method) 在java.lang.J9VMInternals.initialize(J9VMInternals.java:236) ......还有8个