全て、
コンテキストメニューからカスタムエディターに図を追加する、パレットレスエクリプスプラグインを作成していますが、それを行う方法が見つかりません。コンテキストメニューを介してエディターに図を動的に追加する方法、つまりアクション/コマンドを追加する方法について、誰かに教えてもらえますか?
Eclipse GEFプラグインの開発では、見るべき例が非常に少ないため、他の人が役立つようにソリューションを追加しています。このコードは、ノードをエディターにレンダリングするのに役立ちます。
エディターに図をレンダリングするためのActionクラスのソースコード:
public class AddNodeAction extends EditorPartAction
{
public static final String ADD_NODE = "ADDNODE";
public AddNodeAction(IEditorPart editor) {
super(editor);
setText("Add a Node");
setId(ADD_NODE); // Important to set ID
}
public void run()
{
<ParentModelClass> parent= (<ParentModelClass>)getEditorPart().getAdapter(<ParentModelClass>.class);
if (parent== null)
return;
CommandStack command = (CommandStack)getEditorPart().getAdapter(CommandStack.class);
if (command != null)
{
CompoundCommand totalCmd = new CompoundCommand();
<ChildModelToRenderFigureCommand>cmd = new <ChildModelToRenderFigureCommand>(parent);
cmd.setParent(parent);
<ChildModelClass> newNode = new <ChildModelClass>();
cmd.setNode(newNode);
cmd.setLocation(getLocation()); // Any location you wish to set to
totalCmd.add(cmd);
command.execute(totalCmd);
}
}
@Override
protected boolean calculateEnabled()
{
return true;
}
}