基于 Eclipse 插件中另一个视图的渲染视图

发布于 2024-11-09 12:43:20 字数 1548 浏览 6 评论 0原文

我正在开发一个 Eclipse 插件,当前有 2 个视图。在我的第一个视图中,我在 TableViewer 中显示了一个连接列表(名称和连接状态)。在我的第二个视图中,我想加载数据库中的表(连接)。此加载将通过单击连接上的菜单项(“查看详细信息”)来完成。这些表将显示在 TreeViewer 中,因为它们也可以有子表。我尝试这样做:

我的视图类:

public class DBTreeView extends ViewPart {

private TreeViewer treeViewer;
private Connection root = null;

    public DBTreeView() {
        Activator.getDefault().setDbTreeView(this);
    }

    public void createPartControl(Composite parent) {
        treeViewer = new TreeViewer(parent);
        treeViewer.setContentProvider(new DBTreeContentProvider());
        treeViewer.setLabelProvider(new DBTreeLabelProvider());
    }

    public void setInput(Connection conn){
        root = conn;
        treeViewer.setInput(root);
        treeViewer.refresh();
    }
}

我创建了一个 setInput 方法,该方法是从连接视图中的菜单项注册的操作中调用的,并以当前选定的连接作为参数:

MViewContentsAction 类:

public void run(){
    selectedConnection =  Activator.getDefault().getConnectionsView().getSelectedConnection();  
    Activator.getDefault().getDbTreeView().setInput(selectedConnection);    
}

在我的 ContentProvider 类中:

public Object[] getChildren(Object arg0) {
    if (arg0 instanceof Connection){
        return ((Connection) arg0).getTables().toArray();
    }
    return EMPTY_ARRAY;
}

其中 EMPTY_ARRAY 是一个...空数组

我面临的问题是,在调试模式下,这段代码不会以某种方式执行:

Activator.getDefault().getDbTreeView().setInput(selectedConnection);

并且单击菜单项时树视图中也没有任何反应。有什么想法吗? 谢谢

I am developing an Eclipse plug-in that has currently 2 views. In my first view I have a list of connections displayed in a TableViewer (name and connection status).In my second view I want to load the tables in a database (the connection). This loading will be done by clicking a menu item on a connection ("view details"). These tables will be displayed in a TreeViewer because they can also have children. I have tried to do it this way:

My View class:

public class DBTreeView extends ViewPart {

private TreeViewer treeViewer;
private Connection root = null;

    public DBTreeView() {
        Activator.getDefault().setDbTreeView(this);
    }

    public void createPartControl(Composite parent) {
        treeViewer = new TreeViewer(parent);
        treeViewer.setContentProvider(new DBTreeContentProvider());
        treeViewer.setLabelProvider(new DBTreeLabelProvider());
    }

    public void setInput(Connection conn){
        root = conn;
        treeViewer.setInput(root);
        treeViewer.refresh();
    }
}

I made a setInput method that is called from the action registered with the menu item in the connections view with the currently selected connection as argument:

MViewContentsAction class:

public void run(){
    selectedConnection =  Activator.getDefault().getConnectionsView().getSelectedConnection();  
    Activator.getDefault().getDbTreeView().setInput(selectedConnection);    
}

In my ContentProvider class:

public Object[] getChildren(Object arg0) {
    if (arg0 instanceof Connection){
        return ((Connection) arg0).getTables().toArray();
    }
    return EMPTY_ARRAY;
}

where EMPTY_ARRAY is an...empty array

The problem I'm facing is that when in debug mode, this piece of code is not executed somehow:

Activator.getDefault().getDbTreeView().setInput(selectedConnection);

And also nothing happens in the tree view when clicking the menu item. Any ideas?
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪化雨蝶 2024-11-16 12:43:20

呵呵。好吧,你在这里做的事情是..不是真正正确的方法。您应该做的是将 TableViewer 注册为选择提供程序。

getSite().setSelectionProvider(tableViewer);

然后,定义一个选择侦听器并将其添加到树查看器的视图中,如下所示:

ISelectionListener listener = new ISelectionListener() {
     public void selectionChanged(IWorkbenchPart part, ISelection sel) {
        if (!(sel instanceof IStructuredSelection))
           return;
        IStructuredSelection ss = (IStructuredSelection) sel;
        // rest of your code dealing with checking whether selection is what is
        //expected and if it is, setting it as an input to             
        //your tree viewer                     
       }
    };

   public void createPartControl(Composite parent) {
     getSite().getPage().addSelectionListener(listener);
  }

现在,树查看器的输入将根据表查看器中选择的内容进行更改(顺便说一句,不要忘记调用 treeviewer.refresh()设置新输入后)。

请参阅此处的示例。

Huh. Ok, what you're doing here is.. not really the right way. What you should be doing is registering your TableViewer as a selection provider.

getSite().setSelectionProvider(tableViewer);

Then, define a selection listener and add it to the view with the tree viewer like this:

ISelectionListener listener = new ISelectionListener() {
     public void selectionChanged(IWorkbenchPart part, ISelection sel) {
        if (!(sel instanceof IStructuredSelection))
           return;
        IStructuredSelection ss = (IStructuredSelection) sel;
        // rest of your code dealing with checking whether selection is what is
        //expected and if it is, setting it as an input to             
        //your tree viewer                     
       }
    };

   public void createPartControl(Composite parent) {
     getSite().getPage().addSelectionListener(listener);
  }

Now your tree viewer's input will be changed according to what is selected in the table viewer (btw, don't forget to call treeviewer.refresh() after you set new input).

See an example here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文