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

发布于 2024-10-27 21:52:36 字数 1190 浏览 3 评论 0原文

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

现在用户可以看到一个部分。我需要他能够添加 n 个部分,然后在 stopRouteStreet 字段中写入文本。我想阅读该字段中写入的所有 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);

I am using eclipse 3.6 and developing RCP application with java 6.
I am using the Section and trying to let the use able to add new n-sections. I need the text in the field after that.

Now the User can see a section. I need that he is able to add a n-sections and then to write text in stopRouteStreet-field. I would like to read all the n Text written in this field.

Any idea how to do this?.

Here is my code

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);

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

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

发布评论

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

评论(1

絕版丫頭 2024-11-03 21:52:36

您需要一个全局变量(HashMap 即可),用于保存每个新创建的部分和文本控件之间的映射。

// 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());
}

You need a global variable (a HashMap would do), that saves a mapping between each newly created Section and the Text control.

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