我正在使用 Eclipse 图形编辑框架 ( GEF )构建一个 Eclipse 插件项目。可以用我在互联网上找到的示例代码编写一个用于测试的类,代码如下:
public class Test {
public static void main(String args[]){
Shell shell = new Shell();
shell.open();
Display display = shell.getDisplay();
LightweightSystem lws = new LightweightSystem(shell);
IFigure panel = new Figure();
lws.setContents(panel);
RectangleFigure node1 = new RectangleFigure();
RectangleFigure node2 = new RectangleFigure();
node1.setBackgroundColor(ColorConstants.red);
node1.setBounds(new Rectangle(30, 30, 64, 36));
node2.setBackgroundColor(ColorConstants.blue);
node2.setBounds(new Rectangle(300, 300, 64, 36));
PolylineConnection conn = new PolylineConnection();
conn.setSourceAnchor(new ChopboxAnchor(node1));
conn.setTargetAnchor(new ChopboxAnchor(node2));
conn.setTargetDecoration(new PolygonDecoration());
Label label = new Label("Midpoint");
label.setOpaque(true);
label.setBackgroundColor(ColorConstants.buttonLightest);
label.setBorder(new LineBorder());
conn.add(label, new MidpointLocator(conn, 0));
panel.add(node1);
panel.add(node2);
panel.add(conn);
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ())
display.sleep ();
}
}//main
}
有用。
但是- 当我尝试在 EditorPart ( org.eclipse.ui.IEditorPart
) 实例类中构建图形时,它变得很糟糕并给了我以下错误代码:
**org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError:** org/eclipse/draw2d/LightweightSystem
这很奇怪,因为我只是在编辑器的createPartControl
方法中写了 3 行:
Shell shell = parent.getShell();
Display display = shell.getDisplay();
LightweightSystem lws = new LightweightSystem(shell);
那么有没有身体帮助?