GWT Celltable ContextMenu in a Column

// create your column class
private class ContextMenuColumn extends Column<UserModel, String>{

  public ContextMenuColumn(Cell<String> cell) {
   super(cell);
  }

  @Override
  public String getValue(UserModel object) {
   return "/img/icons/contextual-menu.jpg";
  }
  
  @Override
  public void onBrowserEvent(Context context, Element elem, UserModel object, NativeEvent event) {
   final UserModel user = object;
   
   int left = elem.getParentElement().getAbsoluteLeft();
      int top = elem.getParentElement().getAbsoluteTop();
      
      final DialogBox dialog = new DialogBox();
      dialog.setText(constants.Actions());
      
      Anchor lnkEdit = new Anchor(constants.Edit());
      lnkEdit.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     placeController.goTo(new ControlPanelUsersEditPlace(user.getUserId()));
     dialog.hide();
    }
   });
      
      Anchor lnkUpdateState = new Anchor(user.getEnable() == false ? constants.Enable() : constants.Disable());
      lnkUpdateState.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     presenter.setEnabled(user.getUserId(), !user.getEnable());
     dialog.hide();
    }
   });
      
      Anchor lnkResetPassword = new Anchor(constants.ChangePassword());
      lnkResetPassword.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     presenter.resetPassword(user.getUserId());
     dialog.hide();
    }
   });
      
      Anchor lnkDelete = new Anchor(constants.Delete());
      lnkDelete.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
     presenter.delete(user.getUserId());
     dialog.hide();
    }
   });
      
      VerticalPanel pnl = new VerticalPanel();
      pnl.add(lnkEdit);
      pnl.add(lnkUpdateState);
      pnl.add(lnkResetPassword);
      pnl.add(lnkDelete);
      
      dialog.setWidget(pnl);
      dialog.setPopupPosition(left - 20, top + 10);
      dialog.setAutoHideEnabled(true);
      dialog.show();
  }
 }

// create your column and add it to your table
Column<UserModel, String> contextMenuColumn = new ContextMenuColumn(new MyImageCell());

table.addColumn(contextMenuColumn);

No hay comentarios: