Gwt 获取组件

发布于 2024-12-05 03:41:37 字数 914 浏览 2 评论 0原文

我有一个垂直面板对象,该对象包含许多单选按钮,

那么我可以通过垂直面板对象获取这些单选按钮对象吗?

也许通过迭代或?

private void initCourse() {
    coursePopupPanel.clear();
    VerticalPanel verticalPanel = new VerticalPanel();
    coursePopupPanel.setWidget(verticalPanel);
    JsArray<JCourse> jCourseArray = JCourse.getList(stringMainData);
    for (int i = 0; i < jCourseArray.length(); i++) {
        final RadioButton courseRadioButton = new RadioButton("course");
        courseRadioButton.setText(jCourseArray.get(i).getName());
        courseRadioButton.getElement().setId(jCourseArray.get(i).getView());
        verticalPanel.add(courseRadioButton);

        //handler of course radio buttons
        courseRadioButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
            }
        });
    }
}

我有对 coursePopupPanel 的引用。但我没有引用垂直面板,所以我可以获取垂直面板的元素吗?

I have a Vertiacal panel object and This object contains many radiobuttons

So can i get those radioButton objects through Vertiacal panel object.

Maybe via iteration or ?

private void initCourse() {
    coursePopupPanel.clear();
    VerticalPanel verticalPanel = new VerticalPanel();
    coursePopupPanel.setWidget(verticalPanel);
    JsArray<JCourse> jCourseArray = JCourse.getList(stringMainData);
    for (int i = 0; i < jCourseArray.length(); i++) {
        final RadioButton courseRadioButton = new RadioButton("course");
        courseRadioButton.setText(jCourseArray.get(i).getName());
        courseRadioButton.getElement().setId(jCourseArray.get(i).getView());
        verticalPanel.add(courseRadioButton);

        //handler of course radio buttons
        courseRadioButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
            }
        });
    }
}

I have a reference to coursePopupPanel. but i have not reference to vertical panel, so can i get elements of vertical panel sonce holding reference to coursePopupPanel.

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

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

发布评论

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

评论(3

花桑 2024-12-12 03:41:37

GWT VerticalPanel 是 ComplexPanel 的子类,ComplexPanel 是包含多个子窗口小部件的面板的抽象类。 ComplexPanel(因此由 VerticalPanel 继承)中有用于获取子窗口小部件的数量、通过索引获取对它们的引用等的方法。您可以构建一个类似这样的迭代器:

Iterator<Widget> vPanelWidgets = myVerticalPanel.iterator();
while (vPanelWidgets.hasNext()){
  Widget childWidget = vPanelWidgets.next();
  if (childWidget instanceof RadioButton) {
    ...do stuff
  }
}

我倾向于不查询小部件的成员。这将我与我按照您的示例做出的有关如何显示单选按钮的决定联系在一起。如果您稍后决定在 FlexTable 的单元格中显示单选按钮以控制垂直和水平排列,该怎么办?进行该更改意味着您的小部件迭代器将无法工作。 FlexTable 是一个面板,但不是一个 ComplexPanel。如果您决定用 FlexTable 替换 VerticalPanel,我上面编写的代码将不起作用。

如果采用类似的方法,我会将相关小部件的列表(如一组 RadioButton)保存在某种 Java 集合中。我将该 Collection 传递给我的演示类,并在其中编写代码来进行布局。通常这是一个 UiBinder 类,这些 RadioButton 带有“@UiField(provided = true)”。然后,演示器中的代码将我传入的 Collection 的 RadioButton 元素关联到 UiBinder 布局中 RadioButton 的 UiField 占位符。所以我所有的布局决策实际上都在 UiBinder xml 文件中。如果我决定拆掉垂直面板并用 FlexTable 替换它,假设我正确地分离了内容,我可能不需要触及一行 Java 代码。

[实际上,我可能会保留在表示层内,特别是在 XML 文件内使用 RadioButton 的决定。该演示类将在 EventBus 上触发一条消息,以指示用户已通过 RadioButton ValueChangeHandler 进行了选择,并且我不在乎是否在 VerticalPanel 中使用 RadioButtons 或在 FlexTable 中使用 ToggleButtons。]

A GWT VerticalPanel is a subclass of ComplexPanel, an abstract class for Panels that contain more than one child widget. In ComplexPanel (and so inherited by VerticalPanel) are methods for getting the number of child widgets, getting references to them by index, and so on. You could build an iterator something like this:

Iterator<Widget> vPanelWidgets = myVerticalPanel.iterator();
while (vPanelWidgets.hasNext()){
  Widget childWidget = vPanelWidgets.next();
  if (childWidget instanceof RadioButton) {
    ...do stuff
  }
}

I tend not to query a widget for its members. That ties me to the decisions I made about how to display the RadioButtons, following your example. What if you decide later to display your radio buttons in the cells of a FlexTable in order to control vertical and horizontal arrangement? To make that change means your widget iterator won't work. FlexTable is a Panel but not a ComplexPanel. The code I wrote above won't work if you decide to replace the VerticalPanel with a FlexTable.

If was to take something like this approach, I would keep my lists of related widgets (like a group of RadioButtons) in some sort of Java Collection. I pass that Collection to my presentation class, and inside there I write the code to do the layout. Usually that's a UiBinder class, with "@UiField(provided = true)" for these RadioButtons. The code in the presenter then associates the RadioButton elements of the Collection I passed in to the UiField placeholders for the RadioButtons in the UiBinder layout. So all my layout decisions are actually in the UiBinder xml file. If I decide to rip out my Vertical Panel and replace it with a FlexTable, I might not have to touch a single line of Java code, assuming I separated things out correctly.

[Actually, I would probably keep my decision to use RadioButtons inside the presentation layer, and inside the XML file in particular. That presentation class would fire a message on the EventBus to indicate the user had made a selection via a RadioButton ValueChangeHandler, and I wouldn't care if I used RadioButtons in a VerticalPanel or ToggleButtons in a FlexTable.]

远昼 2024-12-12 03:41:37

您不会具体说明,添加更多详细信息,也许还可以添加代码示例。

我将尝试猜测您在这里想说的内容:您有一个 VerticalPanel 对象。向其中添加几个 radioButton 对象。稍后您想要检索这些 radioButton 对象(也许检查它们是否被选中),对吧?有几种方法可以做到这一点。无论如何,为什么不检查 Gwt Showcase 站点上的代码示例:

http://gwt.google.com/samples/Showcase/Showcase.html?locale=en_UM#!CwRadioButton

它有大量的视觉示例,每个示例都附加了代码和CSS。

You're not being to specific, add more details and maybe a code example.

I'm gonan try to guesstimate what you're trying to say here: You have a verticalPanel object. To it you add several radioButton objects. Later you want to retrive those radioButton objects (to maybe check if they're selected or not), right? There's several ways to do this. At any rate, why don't you check the code examples at the Gwt Showcase site here:

http://gwt.google.com/samples/Showcase/Showcase.html?locale=en_UM#!CwRadioButton

it has tons of visual examples, each with the attached code and css.

香橙ぽ 2024-12-12 03:41:37

由于 PopupPanel 实现了 HasOneWidget 接口,您可以使用 coursePopupPanel.getWidget() 来获取对 VerticalPanel 的引用。并简单地使用迭代其中的小部件

for (Widget w : verticalPanel){
    //Do Stuff
} 

Since PopupPanel implements HasOneWidget interface you can coursePopupPanel.getWidget() to get a reference to your verticalPanel. And iterate widgets in it simply using

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