AbstractCell ning CellTable-dan "klik" qilish uchun ota-vidjetda hodisalarni boshqarish

Men GWT noob emasman va men bu borada to'g'ri yo'nalishda dag'alliklarni qadrlayman.

GWT 2.4 yordamida

Tarmoq jadvalini qo'shadigan EntryPoint sinfida qanday voqeani tinglash mumkinligini bilish qiyin emas. CellTable-dagi maxsus AbstractCell bor, u ko'prik bilan String yaratadi. Hujayra bir marta bosish hodisasini boshqaradi.

Qanday qilib mening EntryPoint sinfi voqeni qanday bajarishi mumkinligini (masalan, CellTable-ni yashirish va boshqa ba'zi vidjetlarni ko'rsatish) mumkin?

Men Cell va CellTable-dagi voqea bilan muvaffaqiyatli ishlay olaman, lekin ota-ona vidjetini (uni boshqarish uchun EntryPoint klassini) qanday qilib olishni tushunolmayman.

EntryPoint sinfi:

public class Tags_GWT implements EntryPoint {

private final TagGwtServiceAsync tagService = GWT.create(TagGwtService.class);
final TagCellTable tagCellTable = new TagCellTable();

public void onModuleLoad() {

    RootPanel.get("tagCellTable").add(tagCellTable);

   //load the table with data
    tagService.getTagsAsList(new AsyncCallback>() {
        public void onFailure(Throwable caught) {
            GWT.log("Error loading data");
        }
        public void onSuccess(List tags) {
            tagCellTable.setInput(tags);
        }
    });

CellTable sinf:

public class TagCellTable extends CellTable{

code removed for simplicity

// Add a field updater to be notified when the user enters a new name.
nameColumn.setFieldUpdater(new FieldUpdater() {
  @Override
  public void update(int index, TagDto object, String value) {
   //Inform the user of the change.
    Window.alert("TagCellTable.update is executing for: '" + value + "'");
  }
});

AbstractCell klassi:

public class LinkCell extends AbstractCell{

code omitted for simplicity

@Override
public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater valueUpdater) {

  super.onBrowserEvent(context, parent, value, event, valueUpdater);

  if ("click".equals(event.getType())) {
   //Ignore clicks that occur outside of the outermost element.
    EventTarget eventTarget = event.getEventTarget();
    if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) {
      doAction(value, valueUpdater);
    }
  }
}


@Override
protected void onEnterKeyDown(Context context, Element parent, String value, NativeEvent event, ValueUpdater valueUpdater) {
  doAction(value, valueUpdater);
}


private void doAction(String value, ValueUpdater valueUpdater) {

  Window.alert("LinkCell.doAction is executing for: ' " + value + "'");

  if (valueUpdater != null) {
      valueUpdater.update(value);
  }
}
1

1 javoblar

EventBus obyektiga havola qilish uchun LinkCell ni berishingiz kerak. Keyin, doAction EventBus saytida ba'zi voqea kodini yoqishingiz mumkin. Kirish nuqtasi moduli tegishli voqealar uchun bir xil EventBus ni tinglashi mumkin va u erdan javob berishi mumkin.

CellTable aslida vidjetlardan tayyorlanmaganligi sababli, o'rnatilgan ichki tashqi koddan hujayra ichiga kirishning yaxshi usuli yo'q. Oddiy widget hodisasi hiirarxiyasi hech qachon faollashtirilmaydi, shuning uchun tinglovchilarni qo'shish uchun hech narsa yo'q - o'zingizning EventBusni yaratishingiz kerak.

1
qo'shib qo'ydi
Yep! Bundan ham aniqroq qayta qo'ng'iroq obyektini ishlatishingiz mumkin.
qo'shib qo'ydi muallif Riley Lark, manba
Buning uchun dasturning global voqea avtobusidan foydalanishni taklif qilmayman, ammo sizning Cell-ga faqat Cell uchun bo'lgan juda muhim voqea avtobusi berishi mumkin, va keyin boshqa vidjetlar o'sha voqea avtobusini tinglashi mumkin.
qo'shib qo'ydi muallif Riley Lark, manba
Javobingiz uchun tashakkur. SimpleEventBus dan qanday foydalanishni tushuntiruvchi ushbu yozuvni topdim. Buni sizga nimani taklif qilayotgan deb hisoblayman?
qo'shib qo'ydi muallif Justin, manba