简体   繁体   English

Eclipse插件视图-如何动态添加和处理复合材料

[英]Eclipse plugin view - How to add and dispose composites on the fly

The Use Case is simple: 用例很简单:

In a Scrolled Composite, I have a Dropdown menu and, when I select an item from it, several ChartComposites spawn in a grid layout underneath. 在“滚动复合”中,我有一个“下拉菜单”,当我从其中选择一个项目时,在下面的网格布局中会产生几个ChartComposites。

I then select the dropdown again, I click another item, all previously spawned composites are disposed and the view is populated with new ones. 然后,我再次选择该下拉列表,单击另一项,所有以前生成的复合材料都将被放置,并在视图中填充新的复合材料。

Now for more details: 现在获取更多详细信息:

Both the Dropdown and the ChartComposites are contained in a regular Composite (because I can only set one Composite to the ScrolledComposite) which has a grid layout, because I want them arranged in a certain way. Dropdown和ChartComposites都包含在具有网格布局的常规Composite(因为我只能将一个Composite设置到ScrolledComposite)中,因为我希望它们以某种方式进行排列。

The problem is I have no idea how I can call the createPartControl() after the view has been created in order to dispose of the composites I no longer want and create the new composites. 问题是我不知道如何在创建视图后如何调用createPartControl()来处理不再需要的合成并创建新的合成。

I tried using a Content Provider but I don't think it works for premade Composites, because the results were that the ChartComposites it was supposed to return got cast into Objects and were no longer...charts. 我尝试使用Content Provider,但我认为它不适用于预制的Composites,因为结果是应该返回的ChartComposites被转换为Objects,不再是图表。

I considered using a StackLayout but I really need the GridLayout I currently have so that doesn't work. 我考虑过使用StackLayout,但是我确实需要当前使用的GridLayout,所以它不起作用。

So does anyone know a quick and easy way to dispose of and add composites to an already created view through listeners (select a dropdown item, push a button etc)? 那么,有没有人知道通过侦听器处理和添加合成到已经创建的视图的快速简便的方法(选择下拉菜单项,按下按钮等)?

You can use StackLayout and GridLayout to achieve this without having to mess around with dispose . 您可以使用StackLayoutGridLayout来实现此目的,而不必搞乱dispose

It is not clear from your question exactly what the GUI design is. 从您的问题尚不清楚GUI设计是什么。 The following code stacks multiple composite children: 以下代码堆叠了多个复合子代:

Composite parent = new Composite(body, SWT.NONE);
parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
StackLayout layout = new StackLayout();
parent.setLayout(layout);

Composite child1 = new Composite(parent, SWT.NONE);
child1.setLayout(new GridLayout());
// TODO .... add controls to child1 for first 'page'

Composite child2 = new Composite(parent, SWT.NONE);
child2.setLayout(new GridLayout());
// TODO .... add controls to child2 for second 'page'

layout.topControl = child;
layout.layout();

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

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