如何在 DebugSession 中创建一个 TreeTable
How create a TreeTable in DebugSession
我正在寻找一种在 intellij 插件中创建 TreeTable 的方法。
我可以在 com.intellij.xdebugger.XDebugProcess#createTabLayouter 中创建 DebugSession 中的选项卡,但我不能在该 JPanel 中创建一个 TreeTable。
我的视图如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="debugger.ui.RegisterViewSessionTab">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="86eac">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8217" class="com.intellij.ui.treeStructure.treetable.TreeTable" binding="tree" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</form>
以及 (RegisterViewSessionTab) 背后的代码:
pc = new DefaultRegisterNode();
sp = new DefaultRegisterNode();
DefaultRegisterNode group = new DefaultRegisterNode();
group.setName("Core Registers");
group.setDescription("Core Registers");
group.setValue("");
DefaultMutableTreeNode root = new DefaultMutableTreeNode(group);
pc.setName("PC");
pc.setDescription("Program Counter [Core]");
pc.setValue("---");
DefaultMutableTreeNode nodePc = new DefaultMutableTreeNode(pc);
root.add(nodePc);
sp.setName("SP");
sp.setDescription("Stack Pointer [Core]");
sp.setValue("---");
DefaultMutableTreeNode node = new DefaultMutableTreeNode(sp);
root.add(node);
ColumnInfo[] columnInfos = new ColumnInfo[3];
columnInfos[0] = new ColumnInfo<DefaultMutableTreeNode, String>("Name") {
@Nullable
@Override
public String valueOf(DefaultMutableTreeNode defaultRegisterNode) {
return ((DefaultRegisterNode)defaultRegisterNode.getUserObject()).getName();
}
};
columnInfos[1] = new TableModelEditor.EditableColumnInfo<DefaultMutableTreeNode, String>("Value") {
@Nullable
@Override
public String valueOf(DefaultMutableTreeNode defaultRegisterNode) {
return ((DefaultRegisterNode)defaultRegisterNode.getUserObject()).getValue();
}
@Nullable
@Override
public TableCellEditor getEditor(DefaultMutableTreeNode defaultRegisterNode) {
return new StringTableCellEditor(project);
}
@Override
public void setValue(DefaultMutableTreeNode defaultRegisterNode, String value) {
((DefaultRegisterNode)defaultRegisterNode.getUserObject()).setValue(value);
}
};
columnInfos[2] = new ColumnInfo<DefaultMutableTreeNode, String>("Description") {
@Nullable
@Override
public String valueOf(DefaultMutableTreeNode defaultRegisterNode) {
return ((DefaultRegisterNode)defaultRegisterNode.getUserObject()).getDescription();
}
};
ListTreeTableModelOnColumns registersModel = new ListTreeTableModelOnColumns(root, columnInfos);
tree = new TreeTable(registersModel);
型号class:
public class DefaultRegisterNode {
private String name;
private String description;
private String value;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getDescription() {
return null;
}
public void setDescription(String description) {
this.description = description;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
在行动中:
http://i.imgur.com/RN2w5mT.jpg
但是没有 collapsed/expanded 按钮?如何在 TreeTable 中启用此功能?
如果您需要更多的东西,请联系我!
谢谢
对于 TreeTableView,根节点也会显示。但是错误不存在。我找到了。
ColumnInfo[] columnInfos = new ColumnInfo[] {
new TreeColumnInfo("Name"), // <-- This is important!
new ColumnInfo<Node, String>("Name S1") {
...
}
};
在上面的 ColumnInfo 中添加一个 TreeColumnInfo。这将添加 Expand/Collapse 箭头。现在您必须创建一个 TreeCellRenderer 并设置为树。
public static class Tree extends TreeTableView {
public Tree(ListTreeTableModelOnColumns treeTableModel) {
super(treeTableModel);
setTreeCellRenderer(new Renderer());
}
class Renderer extends ColoredTreeCellRenderer {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Node node = (Node)value;
NodeModel model = node.getUserObject();
append(model.Name);
}
}
}
我正在寻找一种在 intellij 插件中创建 TreeTable 的方法。 我可以在 com.intellij.xdebugger.XDebugProcess#createTabLayouter 中创建 DebugSession 中的选项卡,但我不能在该 JPanel 中创建一个 TreeTable。
我的视图如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="debugger.ui.RegisterViewSessionTab">
<grid id="27dc6" binding="content" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="86eac">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="8217" class="com.intellij.ui.treeStructure.treetable.TreeTable" binding="tree" custom-create="true">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</form>
以及 (RegisterViewSessionTab) 背后的代码:
pc = new DefaultRegisterNode();
sp = new DefaultRegisterNode();
DefaultRegisterNode group = new DefaultRegisterNode();
group.setName("Core Registers");
group.setDescription("Core Registers");
group.setValue("");
DefaultMutableTreeNode root = new DefaultMutableTreeNode(group);
pc.setName("PC");
pc.setDescription("Program Counter [Core]");
pc.setValue("---");
DefaultMutableTreeNode nodePc = new DefaultMutableTreeNode(pc);
root.add(nodePc);
sp.setName("SP");
sp.setDescription("Stack Pointer [Core]");
sp.setValue("---");
DefaultMutableTreeNode node = new DefaultMutableTreeNode(sp);
root.add(node);
ColumnInfo[] columnInfos = new ColumnInfo[3];
columnInfos[0] = new ColumnInfo<DefaultMutableTreeNode, String>("Name") {
@Nullable
@Override
public String valueOf(DefaultMutableTreeNode defaultRegisterNode) {
return ((DefaultRegisterNode)defaultRegisterNode.getUserObject()).getName();
}
};
columnInfos[1] = new TableModelEditor.EditableColumnInfo<DefaultMutableTreeNode, String>("Value") {
@Nullable
@Override
public String valueOf(DefaultMutableTreeNode defaultRegisterNode) {
return ((DefaultRegisterNode)defaultRegisterNode.getUserObject()).getValue();
}
@Nullable
@Override
public TableCellEditor getEditor(DefaultMutableTreeNode defaultRegisterNode) {
return new StringTableCellEditor(project);
}
@Override
public void setValue(DefaultMutableTreeNode defaultRegisterNode, String value) {
((DefaultRegisterNode)defaultRegisterNode.getUserObject()).setValue(value);
}
};
columnInfos[2] = new ColumnInfo<DefaultMutableTreeNode, String>("Description") {
@Nullable
@Override
public String valueOf(DefaultMutableTreeNode defaultRegisterNode) {
return ((DefaultRegisterNode)defaultRegisterNode.getUserObject()).getDescription();
}
};
ListTreeTableModelOnColumns registersModel = new ListTreeTableModelOnColumns(root, columnInfos);
tree = new TreeTable(registersModel);
型号class:
public class DefaultRegisterNode {
private String name;
private String description;
private String value;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getDescription() {
return null;
}
public void setDescription(String description) {
this.description = description;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
在行动中: http://i.imgur.com/RN2w5mT.jpg
但是没有 collapsed/expanded 按钮?如何在 TreeTable 中启用此功能?
如果您需要更多的东西,请联系我! 谢谢
对于 TreeTableView,根节点也会显示。但是错误不存在。我找到了。
ColumnInfo[] columnInfos = new ColumnInfo[] {
new TreeColumnInfo("Name"), // <-- This is important!
new ColumnInfo<Node, String>("Name S1") {
...
}
};
在上面的 ColumnInfo 中添加一个 TreeColumnInfo。这将添加 Expand/Collapse 箭头。现在您必须创建一个 TreeCellRenderer 并设置为树。
public static class Tree extends TreeTableView {
public Tree(ListTreeTableModelOnColumns treeTableModel) {
super(treeTableModel);
setTreeCellRenderer(new Renderer());
}
class Renderer extends ColoredTreeCellRenderer {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
Node node = (Node)value;
NodeModel model = node.getUserObject();
append(model.Name);
}
}
}