gt:                                 new ContactEvent.GotoEdit(this, contact));
context: /**
   * This file is part of mycollab-mobile.
   *
   * mycollab-mobile is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * mycollab-mobile is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with mycollab-mobile.  If not, see <http://www.gnu.org/licenses/>.
   */
  /**
   * This file is part of mycollab-mobile.
   *
   * mycollab-mobile is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * mycollab-mobile is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with mycollab-mobile.  If not, see <http://www.gnu.org/licenses/>.
   *
   * This file is part of mycollab-web.
   *
   * mycollab-web is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * mycollab-web is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with mycollab-web.  If not, see <http://www.gnu.org/licenses/>.
   *
   * This file is part of mycollab-web.
   *
   * mycollab-web is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * mycollab-web is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with mycollab-web.  If not, see <http://www.gnu.org/licenses/>.
   */
  /**
   * This file is part of mycollab-web.
   *
   * mycollab-web is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * mycollab-web is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with mycollab-web.  If not, see <http://www.gnu.org/licenses/>.
   */
  package com.esofthead.mycollab.mobile.module.crm.view.account;
  
  import com.esofthead.mycollab.common.i18n.GenericI18Enum;
  import com.esofthead.mycollab.core.arguments.NumberSearchField;
  import com.esofthead.mycollab.eventmanager.EventBusFactory;
  import com.esofthead.mycollab.mobile.module.crm.events.*;
  import com.esofthead.mycollab.mobile.shell.events.ShellEvent;
  import com.esofthead.mycollab.mobile.ui.AbstractMobilePresenter;
  import com.esofthead.mycollab.mobile.ui.ConfirmDialog;
  import com.esofthead.mycollab.module.crm.CrmLinkGenerator;
  import com.esofthead.mycollab.module.crm.CrmTypeConstants;
  import com.esofthead.mycollab.module.crm.domain.*;
  import com.esofthead.mycollab.module.crm.domain.criteria.AccountSearchCriteria;
  import com.esofthead.mycollab.module.crm.service.AccountService;
  import com.esofthead.mycollab.module.crm.service.ContactService;
  import com.esofthead.mycollab.security.RolePermissionCollections;
  import com.esofthead.mycollab.spring.ApplicationContextUtil;
  import com.esofthead.mycollab.vaadin.AppContext;
  import com.esofthead.mycollab.vaadin.events.DefaultPreviewFormHandler;
  import com.esofthead.mycollab.vaadin.mvp.ScreenData;
  import com.esofthead.mycollab.vaadin.ui.NotificationUtil;
  import com.esofthead.mycollab.vaadin.ui.RelatedListHandler;
  import com.vaadin.ui.ComponentContainer;
  import com.vaadin.ui.UI;
  
  import java.util.ArrayList;
  import java.util.GregorianCalendar;
  import java.util.List;
  import java.util.Set;
  
  /**
   *
   * @author MyCollab Ltd.
   * @since 1.0
   *
   */
  public class AccountReadPresenter extends AbstractMobilePresenter<AccountReadView> {
      private static final long serialVersionUID = 1L;
  
      public AccountReadPresenter() {
          super(AccountReadView.class);
      }
  
      @Override
      protected void postInitView() {
          view.getPreviewFormHandlers().addFormHandler(new DefaultPreviewFormHandler<SimpleAccount>() {
              @Override
              public void onEdit(SimpleAccount data) {
                  EventBusFactory.getInstance().post(new AccountEvent.GotoEdit(this, data));
              }
  
              @Override
              public void onDelete(final SimpleAccount data) {
                  ConfirmDialog.show(UI.getCurrent(),
                          AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_SINGLE_ITEM_MESSAGE),
                          AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                          AppContext.getMessage(GenericI18Enum.BUTTON_NO),
                          new ConfirmDialog.CloseListener() {
                              private static final long serialVersionUID = 1L;
  
                              @Override
                              public void onClose(ConfirmDialog dialog) {
                                  if (dialog.isConfirmed()) {
                                      AccountService accountService = ApplicationContextUtil.getSpringBean(AccountService.class);
                                      accountService.removeWithSession(data,
                                              AppContext.getUsername(), AppContext.getAccountId());
                                      EventBusFactory.getInstance().post(new AccountEvent.GotoList(this, null));
                                  }
                              }
                          });
  
              }
  
              @Override
              public void onClone(SimpleAccount data) {
                  Account cloneData = (Account) data.copy();
                  cloneData.setId(null);
                  EventBusFactory.getInstance().post(new AccountEvent.GotoEdit(this, cloneData));
              }
  
              @Override
              public void onCancel() {
                  EventBusFactory.getInstance().post(new AccountEvent.GotoList(this, null));
              }
  
              @Override
              public void gotoNext(SimpleAccount data) {
                  AccountService accountService = ApplicationContextUtil.getSpringBean(AccountService.class);
                  AccountSearchCriteria criteria = new AccountSearchCriteria();
                  criteria.setSaccountid(new NumberSearchField(AppContext.getAccountId()));
                  criteria.setId(new NumberSearchField(data.getId(), NumberSearchField.GREATER));
                  Integer nextId = accountService.getNextItemKey(criteria);
                  if (nextId != null) {
                      EventBusFactory.getInstance().post(new AccountEvent.GotoRead(this, nextId));
                  } else {
                      NotificationUtil.showGotoLastRecordNotification();
                  }
  
              }
  
              @Override
              public void gotoPrevious(SimpleAccount data) {
                  AccountService accountService = ApplicationContextUtil.getSpringBean(AccountService.class);
                  AccountSearchCriteria criteria = new AccountSearchCriteria();
                  criteria.setSaccountid(new NumberSearchField(AppContext.getAccountId()));
                  criteria.setId(new NumberSearchField(data.getId(), NumberSearchField.LESSTHAN));
                  Integer nextId = accountService.getPreviousItemKey(criteria);
                  if (nextId != null) {
                      EventBusFactory.getInstance().post(new AccountEvent.GotoRead(this, nextId));
                  } else {
                      NotificationUtil.showGotoFirstRecordNotification();
                  }
              }
          });
  
          view.getRelatedCaseHandlers().addRelatedListHandler(
                  new RelatedListHandler<SimpleCase>() {
  
                      @Override
                      public void selectAssociateItems(Set<SimpleCase> items) {
                          // TODO Auto-generated method stub
                      }
  
                      @Override
                      public void createNewRelatedItem(String itemId) {
                          SimpleCase cases = new SimpleCase();
                          cases.setAccountid(view.getItem().getId());
                          EventBusFactory.getInstance().post(
                                  new CaseEvent.GotoEdit(this, cases));
                      }
                  });
          view.getRelatedContactHandlers().addRelatedListHandler(
                  new RelatedListHandler<SimpleContact>() {
  
                      @Override
                      public void createNewRelatedItem(String itemId) {
                          SimpleContact contact = new SimpleContact();
                          contact.setAccountid(view.getItem().getId());
                          EventBusFactory.getInstance().post(
  