用户可以在视图中添加新的部分吗?

时间:2011-03-30 08:40:59

标签: eclipse eclipse-rcp rcp

我正在使用eclipse 3.6并使用java 6开发RCP应用程序。 我正在使用该部分并试图让使用能够添加新的n部分。之后我需要该领域的文本。

现在用户可以看到一个部分。我需要他能够添加一个n节,然后在stopRouteStreet-field中写入文本。我想阅读这个字段中写的所有n文本。

知道如何做到这一点吗?。

这是我的代码

Section sectionStop = toolkit.createSection(form.getBody(), Section.DESCRIPTION|Section.TWISTIE|Section.TITLE_BAR);         
td = new TableWrapData(TableWrapData.FILL);
td.colspan = 2;
sectionStop.setLayoutData(td);
sectionStop.addExpansionListener(new ExpansionAdapter() {
    public void expansionStateChanged(ExpansionEvent e) {
        form.reflow(true);
    }
});

sectionStop.setText(Messages.SearchMapView_endPoint); //$NON-NLS-1$

Composite sectionClientStop = toolkit.createComposite(sectionStop);
sectionClientStop.setLayout(new GridLayout());

final Composite stopComposite = toolkit.createComposite(sectionClientStop, SWT.NONE);
final GridLayout gridLayoutStop = new GridLayout();
gridLayoutStop.numColumns = 2;
stopComposite.setLayout(gridLayoutStop);
toolkit.createLabel(stopComposite, Messages.SearchMapView_Street);
stopRouteStreet = toolkit.createText(stopComposite, "", SWT.BORDER); //$NON-NLS-1$
sectionStop.setClient(sectionClientStop);

1 个答案:

答案 0 :(得分:1)

您需要一个全局变量(HashMap会这样做),它保存每个新创建的Section和Text控件之间的映射。

// define global field

HashMap <Section, Text> dynamicControls = new HashMap <Section, Text> ();   

// after you create the text field, save the newly created Text field
....
...

dynamicControls.put(section, text);

// Later when you need to read the values in all the text fields 
for(Section s: dynamicControls.keySet()){
        Text textField = dynamicControls.get(s); 
        System.out.println(textField.getText());
}
相关问题