简体   繁体   English

在视图中显示表-Eclipse插件

[英]Show Table in a View - Eclipse Plugin

I'm trying to develop a plugin for Eclipse. 我正在尝试为Eclipse开发一个插件。 I follow tutorials online and I have done a plugin with sample perspective and a sample views. 我在线上学习了教程,并完成了一个带有示例透视图和示例视图的插件。

Now the view show this: 现在视图显示如下:

public Object[] getElements(Object parent) 
{
    return new String[] { "One", "Two", "Three" };
} 

Instead of string I need to insert a table. 我需要插入一个表而不是字符串。 I follow another tutorial to create a TreeTable, but I have no idea how to put this table Tree into my plugin's view. 我遵循另一个教程来创建TreeTable,但是我不知道如何将该表Tree放入我的插件视图中。

This is the code of TreeTable: 这是TreeTable的代码:

public class TreeTableCreation 
{
  public static void main(String[] args) 
  {
    Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Tree tree = new Tree(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    tree.setHeaderVisible(true);
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("Column 1");
    column1.setWidth(200);
    TreeColumn column2 = new TreeColumn(tree, SWT.CENTER);
    column2.setText("Column 2");
    column2.setWidth(200);
    TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
    column3.setText("Column 3");
    column3.setWidth(200);
    for (int i = 0; i < 4; i++) {
      TreeItem item = new TreeItem(tree, SWT.NONE);
      item.setText(new String[] { "item " + i, "abc", "defghi" });
      for (int j = 0; j < 4; j++) {
        TreeItem subItem = new TreeItem(item, SWT.NONE);
        subItem.setText(new String[] { "subitem " + j, "jklmnop", "qrs" });
        for (int k = 0; k < 4; k++) {
          TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
          subsubItem.setText(new String[] { "subsubitem " + k, "tuv", "wxyz" });
        }
      }
    }
    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }
}

Your view should have a createPartControl(Composite parent) method inherited from ViewPart . 您的视图应具有从ViewPart继承的createPartControl(Composite parent)方法。 Put your tree table creation code there and use the parent parameter as the tree's parent (instead of shell in your code). 将树表创建代码放在此处,并使用parent参数作为树的父级(而不是代码中的shell )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM