public teamsInClass_Team_Widget(
        final Criteria criteria, final UserDetailsReceivedEvent userDetails) {
      this.userDetails = userDetails;

      final TeamModelMessages targetMessages =
          (TeamModelMessages) GWT.create(TeamModelMessages.class);

      BoatTypeModelMessages boatTypeMessages =
          (BoatTypeModelMessages) GWT.create(BoatTypeModelMessages.class);

      setPadding(10);
      setIsGroup(true);
      setGroupTitle(
          classMessages.richFormView_teamsInClass_coupling_with_Team(
              targetMessages.tab_name_TeamModel()));

      // all elements from the target reference, to be picked from to make a connection

      setWidth100();
      setHeight100();

      this.grid.setWidth100();
      // grid.setHeight(150); //automatically ought to use all the space
      // grid.setHeight("*");

      this.grid.setAlternateRecordStyles(false);
      this.grid.setCellHeight(32);
      this.grid.setDataSource(dataSource);
      this.grid.setAutoFetchData(false);
      this.grid.setCanEdit(true);
      this.grid.setModalEditing(true);
      this.grid.setShowFilterEditor(true);
      this.grid.setDoubleClickDelay(100);
      this.grid.setEditEvent(ListGridEditEvent.DOUBLECLICK);
      this.grid.setListEndEditAction(RowEndEditAction.DONE);
      this.grid.setCanRemoveRecords(true);
      this.grid.setAutoSaveEdits(true);
      this.grid.setCanSelectText(true);
      this.grid.setAllowFilterExpressions(true);

      this.grid.setCanDragSelectText(true);
      this.grid.setCanRemoveRecords(
          false); // we have our own delete button, with extra functionality

      /*

      */

      ListGridField idField = new ListGridField("Team_id", "Team id");

      ListGridField sailNumberField = new ListGridField("sailNumber", targetMessages.sailNumber());

      sailNumberField.setAlign(Alignment.LEFT);

      sailNumberField = TeamRichTableView.setFormatterForsailNumber(sailNumberField);

      ListGridField teamNameField = new ListGridField("teamName", targetMessages.teamName());

      teamNameField.setAlign(Alignment.LEFT);

      teamNameField = TeamRichTableView.setFormatterForteamName(teamNameField);

      ListGridField nameCaptainField =
          new ListGridField("nameCaptain", targetMessages.nameCaptain());

      nameCaptainField.setAlign(Alignment.LEFT);

      nameCaptainField = TeamRichTableView.setFormatterFornameCaptain(nameCaptainField);

      ListGridField streetField = new ListGridField("street", targetMessages.street());

      streetField.setAlign(Alignment.LEFT);

      streetField = TeamRichTableView.setFormatterForstreet(streetField);

      ListGridField zipcodeField = new ListGridField("zipcode", targetMessages.zipcode());

      zipcodeField.setAlign(Alignment.LEFT);

      zipcodeField = TeamRichTableView.setFormatterForzipcode(zipcodeField);

      ListGridField cityField = new ListGridField("city", targetMessages.city());

      cityField.setAlign(Alignment.LEFT);

      cityField = TeamRichTableView.setFormatterForcity(cityField);

      ListGridField emailField = new ListGridField("email", targetMessages.email());

      emailField.setAlign(Alignment.LEFT);

      emailField = TeamRichTableView.setFormatterForemail(emailField);

      ListGridField phoneField = new ListGridField("phone", targetMessages.phone());

      phoneField.setAlign(Alignment.LEFT);

      phoneField = TeamRichTableView.setFormatterForphone(phoneField);

      ListGridField numPersonsField = new ListGridField("numPersons", targetMessages.numPersons());

      numPersonsField.setAlign(Alignment.LEFT);

      numPersonsField = TeamRichTableView.setFormatterFornumPersons(numPersonsField);

      ListGridField toerField = new ListGridField("toer", targetMessages.toer());

      toerField = TeamRichTableView.setFormatterFortoer(toerField);

      ListGridField spinField = new ListGridField("spin", targetMessages.spin());

      spinField = TeamRichTableView.setFormatterForspin(spinField);

      ListGridField waitinglistField =
          new ListGridField("waitinglist", targetMessages.waitinglist());

      waitinglistField = TeamRichTableView.setFormatterForwaitinglist(waitinglistField);

      ListGridField femaleTeamField = new ListGridField("femaleTeam", targetMessages.femaleTeam());

      femaleTeamField = TeamRichTableView.setFormatterForfemaleTeam(femaleTeamField);

      ListGridField remark_Field = new ListGridField("remark_", targetMessages.remark_());

      remark_Field.setAlign(Alignment.LEFT);

      remark_Field = TeamRichTableView.setFormatterForremark_(remark_Field);

      ListGridField teamStartTimeField =
          new ListGridField("teamStartTime", targetMessages.teamStartTime());

      teamStartTimeField.setAlign(Alignment.LEFT);

      teamStartTimeField = TeamRichTableView.setFormatterForteamStartTime(teamStartTimeField);

      teamStartTimeField.setTimeFormatter(TimeDisplayFormat.TOSHORTPADDED24HOURTIME);

      // call to a custom field, this class should be created customly
      teamStartTimeField =
          nl.sytematic.projects.BrioRaceSystem.client.custom.TeamTeamStartTimeCustomFieldFactory
              .getCustomField(grid, teamStartTimeField, userDetails);

      ListGridField endTimeField = new ListGridField("endTime", targetMessages.endTime());

      endTimeField.setAlign(Alignment.LEFT);

      endTimeField = TeamRichTableView.setFormatterForendTime(endTimeField);

      endTimeField.setTimeFormatter(TimeDisplayFormat.TOSHORTPADDED24HOURTIME);

      ListGridField sailingTimeField =
          new ListGridField("sailingTime", targetMessages.sailingTime());

      sailingTimeField.setAlign(Alignment.LEFT);

      sailingTimeField = TeamRichTableView.setFormatterForsailingTime(sailingTimeField);

      sailingTimeField.setTimeFormatter(TimeDisplayFormat.TOSHORTPADDED24HOURTIME);

      // call to a custom field, this class should be created customly
      sailingTimeField =
          nl.sytematic.projects.BrioRaceSystem.client.custom.TeamSailingTimeCustomFieldFactory
              .getCustomField(grid, sailingTimeField, userDetails);

      ListGridField swTimeField = new ListGridField("swTime", targetMessages.swTime());

      swTimeField.setAlign(Alignment.LEFT);

      swTimeField = TeamRichTableView.setFormatterForswTime(swTimeField);

      swTimeField.setTimeFormatter(TimeDisplayFormat.TOSHORTPADDED24HOURTIME);

      // call to a custom field, this class should be created customly
      swTimeField =
          nl.sytematic.projects.BrioRaceSystem.client.custom.TeamSwTimeCustomFieldFactory
              .getCustomField(grid, swTimeField, userDetails);

      ListGridField registrationDateTimeField =
          new ListGridField("registrationDateTime", targetMessages.registrationDateTime());

      registrationDateTimeField.setAlign(Alignment.LEFT);

      registrationDateTimeField =
          TeamRichTableView.setFormatterForregistrationDateTime(registrationDateTimeField);

      //	registrationDateTimeField.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
      DateTimeItem registrationDateTimeEditor = new DateTimeItem();
      registrationDateTimeEditor.setUseTextField(true);
      registrationDateTimeEditor.setUseMask(true);
      //	registrationDateTimeEditor.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATETIME);
      registrationDateTimeField.setEditorType(registrationDateTimeEditor);
      //   registrationDateTimeField.setFilterEditorType(registrationDateTimeEditor);

      // call to a custom field, this class should be created customly
      registrationDateTimeField =
          nl.sytematic.projects.BrioRaceSystem.client.custom
              .TeamRegistrationDateTimeCustomFieldFactory.getCustomField(
              grid, registrationDateTimeField, userDetails);

      ListGridField payDateField = new ListGridField("payDate", targetMessages.payDate());

      payDateField.setAlign(Alignment.LEFT);

      payDateField = TeamRichTableView.setFormatterForpayDate(payDateField);

      //	payDateField.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
      DateItem payDateEditor = new DateItem();
      payDateEditor.setUseTextField(true);
      payDateEditor.setUseMask(true);
      //	payDateEditor.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);
      payDateField.setEditorType(payDateEditor);
      // payDateField.setFilterEditorType(payDateEditor);

      ListGridField payOrderField = new ListGridField("payOrder", targetMessages.payOrder());

      payOrderField.setAlign(Alignment.LEFT);

      payOrderField = TeamRichTableView.setFormatterForpayOrder(payOrderField);

      ListGridField payIdField = new ListGridField("payId", targetMessages.payId());

      payIdField.setAlign(Alignment.LEFT);

      payIdField = TeamRichTableView.setFormatterForpayId(payIdField);

      ListGridField acceptedField = new ListGridField("accepted", targetMessages.accepted());

      acceptedField = TeamRichTableView.setFormatterForaccepted(acceptedField);

      ListGridField payStatusField = new ListGridField("payStatus", targetMessages.payStatus());

      payStatusField.setAlign(Alignment.LEFT);

      payStatusField = TeamRichTableView.setFormatterForpayStatus(payStatusField);

      ListGridField BoatTypeField =
          new ListGridField("BoatType_id", boatTypeMessages.name_single());

      ListGridField ClassField = new ListGridField("Class_id", classMessages.name_single());

      final SelectItem BoatTypeSelectItem =
          new SelectItem("BoatType_id", boatTypeMessages.name_single());

      BoatTypeSelectItem.setOptionDataSource(DataSource.get("BoatType"));
      BoatTypeSelectItem.setValueField("BoatType_id");
      BoatTypeSelectItem.setAlign(Alignment.LEFT);

      BoatTypeSelectItem.setTextAlign(Alignment.LEFT);
      BoatTypeSelectItem.setTitleAlign(Alignment.LEFT);
      ListGrid BoatTypeListGrid = new ListGrid();
      BoatTypeListGrid.setShowFilterEditor(true);
      BoatTypeListGrid.setFilterOnKeypress(true);

      SortSpecifier BoatTypeSort = new SortSpecifier("typeName", SortDirection.ASCENDING);
      SortSpecifier[] BoatTypeSorts = new SortSpecifier[] {BoatTypeSort};
      BoatTypeListGrid.setInitialSort(BoatTypeSorts);

      BoatTypeSelectItem.setDisplayField("typeName");

      BoatTypeSelectItem.setAllowEmptyValue(true);

      BoatTypeSelectItem.setPickListWidth(800);
      BoatTypeSelectItem.setPickListFields(
          new ListGridField("typeName", boatTypeMessages.typeName()),
          new ListGridField("SW_value", boatTypeMessages.SW_value()));

      BoatTypeSelectItem.setPickListProperties(BoatTypeListGrid);

      BoatTypeField.setAlign(Alignment.LEFT);

      BoatTypeField.setEditorType(BoatTypeSelectItem);
      BoatTypeField.setOptionDataSource(DataSource.get("BoatType"));
      BoatTypeField.setDisplayField("typeName");

      BoatTypeField.setFilterEditorType(BoatTypeSelectItem); // reusing this is okay appareantly

      ButtonItem newBoatType = new ButtonItem("newBoatType", boatTypeMessages.new_window());
      newBoatType.addClickHandler(
          new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
            @Override
            public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
              BoatTypeNewEntryWindow w =
                  new BoatTypeNewEntryWindow(
                      null,
                      new DSCallback() {
                        @Override
                        public void execute(
                            DSResponse response, Object rawData, DSRequest request) {
                          RecordList rl = response.getDataAsRecordList();
                          if (rl.getLength() > 0) {
                            Record r = rl.get(0);
                            Log.debug("Record found in callback");
                            Integer id = r.getAttributeAsInt("BoatType_id");
                            Log.debug("ID is " + id);
                            BoatTypeSelectItem.setValue(id); // select the just added value
                          }
                        }
                      });

              w.show();
              w.bringToFront();
            }
          });

      final SelectItem ClassSelectItem = new SelectItem("Class_id", classMessages.name_single());

      ClassSelectItem.setOptionDataSource(DataSource.get("Class"));
      ClassSelectItem.setValueField("Class_id");
      ClassSelectItem.setAlign(Alignment.LEFT);

      ClassSelectItem.setTextAlign(Alignment.LEFT);
      ClassSelectItem.setTitleAlign(Alignment.LEFT);
      ListGrid ClassListGrid = new ListGrid();
      ClassListGrid.setShowFilterEditor(true);
      ClassListGrid.setFilterOnKeypress(true);

      SortSpecifier ClassSort = new SortSpecifier("className", SortDirection.ASCENDING);
      SortSpecifier[] ClassSorts = new SortSpecifier[] {ClassSort};
      ClassListGrid.setInitialSort(ClassSorts);

      ClassSelectItem.setDisplayField("className");

      ClassSelectItem.setAllowEmptyValue(true);

      ClassSelectItem.setPickListWidth(800);
      ClassSelectItem.setPickListFields(
          new ListGridField("className", classMessages.className()),
          new ListGridField("startTime", classMessages.startTime()));

      ClassSelectItem.setPickListProperties(ClassListGrid);

      ClassField.setAlign(Alignment.LEFT);

      ClassField.setEditorType(ClassSelectItem);
      ClassField.setOptionDataSource(DataSource.get("Class"));
      ClassField.setDisplayField("className");

      ClassField.setFilterEditorType(ClassSelectItem); // reusing this is okay appareantly

      ButtonItem newClass = new ButtonItem("newClass", classMessages.new_window());
      newClass.addClickHandler(
          new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
            @Override
            public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
              ClassNewEntryWindow w =
                  new ClassNewEntryWindow(
                      null,
                      new DSCallback() {
                        @Override
                        public void execute(
                            DSResponse response, Object rawData, DSRequest request) {
                          RecordList rl = response.getDataAsRecordList();
                          if (rl.getLength() > 0) {
                            Record r = rl.get(0);
                            Log.debug("Record found in callback");
                            Integer id = r.getAttributeAsInt("Class_id");
                            Log.debug("ID is " + id);
                            ClassSelectItem.setValue(id); // select the just added value
                          }
                        }
                      });

              w.show();
              w.bringToFront();
            }
          });

      ListGridField deleteField = new ListGridField("deleteField", "-");
      deleteField.setShouldPrint(false);
      deleteField.setCellIcon(
          GWT.getHostPageBaseURL() + "images/icons/32/woofunction/remove_32.png");
      deleteField.setType(ListGridFieldType.ICON);
      deleteField.setTitle("");
      deleteField.setWidth(32);
      deleteField.setIconSize(24);
      deleteField.setCanDragResize(false);
      deleteField.setCanSort(false);
      deleteField.setCanEdit(false);
      deleteField.setCanGroupBy(false);
      deleteField.setCanFreeze(false);
      deleteField.setCanFilter(false);
      deleteField.setCanHide(false);
      deleteField.setCanReorder(false);
      this.grid.addRecordClickHandler(
          new RecordClickHandler() {
            public void onRecordClick(RecordClickEvent event) {
              ListGridField clicked = event.getField();
              final Record r = event.getRecord();
              if ("deleteField".equals(clicked.getName())) {

                SC.confirm(
                    radosMessages.delete_confirm_coupling(),
                    new BooleanCallback() {
                      public void execute(Boolean confirmed) {
                        if (confirmed != null && confirmed) {
                          grid.removeData(r);
                        } else {
                          // Cancel
                        }
                      }
                    });
              }
            }
          });

      ArrayList<ListGridField> fields = new ArrayList<ListGridField>();

      fields.add(idField);

      fields.add(sailNumberField);

      fields.add(teamNameField);

      fields.add(nameCaptainField);

      fields.add(streetField);

      fields.add(zipcodeField);

      fields.add(cityField);

      fields.add(emailField);

      fields.add(phoneField);

      fields.add(numPersonsField);

      fields.add(toerField);

      fields.add(spinField);

      fields.add(waitinglistField);

      fields.add(femaleTeamField);

      fields.add(remark_Field);

      fields.add(teamStartTimeField);

      fields.add(endTimeField);

      fields.add(sailingTimeField);

      fields.add(swTimeField);

      fields.add(registrationDateTimeField);

      fields.add(payDateField);

      fields.add(payOrderField);

      fields.add(payIdField);

      fields.add(acceptedField);

      fields.add(payStatusField);

      fields.add(BoatTypeField);

      if (userDetails.hasAuthority("CAN_DELETE_TEAM")) {
        fields.add(deleteField);
      }

      ListGridField[] fieldsArr = fields.toArray(new ListGridField[fields.size()]);

      this.grid.setFields(fieldsArr);

      this.grid.fetchData(criteria);
      buttonPanel.setMargin(2);

      grid.hideField("Team_id");

      // newButton.setSize(32);
      newButton.setIcon(GWT.getHostPageBaseURL() + "images/icons/32/woofunction/add_32.png");
      newButton.setIconOrientation("right");
      newButton.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {

              Map<String, Object> defaultValues = new HashMap<String, Object>();
              defaultValues.put("Class_id", criteria.getAttribute("Class_id"));
              grid.startEditingNew(defaultValues);
            }
          });

      buttonPanel.addMember(newButton);

      /*IButton printButton = new IButton(radosMessages.richTableView_print_button());*/
      IButton printButton = new IButton(radosMessages.richTableView_print_button());
      printButton.setShowRollOver(false);
      printButton.setIcon(GWT.getHostPageBaseURL() + "images/icons/32/woofunction/printer_32.png");
      printButton.setIconOrientation("right");

      // Img printButton = new
      // Img(GWT.getHostPageBaseURL()+"images/icons/32/woofunction/printer_32.png");
      // printButton.setSize(32);
      // printButton.setAltText(radosMessages.richTableView_print_button());
      printButton.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {
              Canvas.showPrintPreview(grid);
            }
          });
      buttonPanel.addMember(printButton);

      EmailGridButtonWidget email = new EmailGridButtonWidget(new Canvas[] {grid});
      email.setDefaultMessage(targetMessages.name_single() + "overzicht");
      email.setDefaultSubject(targetMessages.name_single() + "overzicht");
      email.setDefaultFrom(BrioRaceSystemApplicationPanel.getUserdetails().getEmail());
      buttonPanel.addMember(email);

      ExportButtonWidget exportButton = new ExportButtonWidget(grid, dataSource);
      buttonPanel.addMember(exportButton);

      buttonPanel.setHeight(30);

      this.addMember(buttonPanel);
      this.addMember(grid);

      handleRights();
    }
  @Override
  public void init() {
    Criteria criteria = null;
    if (parentRecord != null) {
      criteria = new Criteria();
      criteria.setAttribute("Class_id", (Long) parentRecord.getAttributeAsLong("Class_id"));
    } else {

      Record rec = this.selectedRecord;
      criteria = new Criteria();
      criteria.setAttribute("Class_id", (Long) rec.getAttributeAsLong("Class_id"));
    }

    tabs.setHeight100();
    tabs.setWidth100();
    final ClassModelMessages ClassMessagesd =
        (ClassModelMessages) GWT.create(ClassModelMessages.class);

    // let First tab be the Detail page of the current row, ie. the form thing.
    Tab tab_details = new Tab(ClassMessagesd.name_single());
    tab_details.addTabDeselectedHandler(
        detailView); // has to respond with a form save, when we select a different tab
    tab_details.setPane(detailView);
    tabs.addTab(tab_details);
    tab_details.addTabSelectedHandler(
        new TabSelectedHandler() {
          @Override
          public void onTabSelected(TabSelectedEvent event) {
            getBreadcrumbs().removeAfter("Class_single");
          }
        });

    if (userDetails.hasAuthority("CAN_READ_TEAM_TAB")
        || userDetails.hasAuthority("CAN_READ_TAB_TEAM")
        || userDetails.hasAuthority("CAN_READ_CLASS_TAB_REF")) {
      Log.debug("Detected rights: CAN_READ_TEAM_TAB, showing tab");

      teamsInClass_Team_Widget teamsInClass_Team =
          new teamsInClass_Team_Widget(criteria, userDetails);
      this.refs.add(teamsInClass_Team);

      final TeamModelMessages TeamMessages =
          (TeamModelMessages) GWT.create(TeamModelMessages.class);

      Tab tab_teamsInClass_Team_Widget = new Tab(TeamMessages.tab_name_TeamModel());
      tab_teamsInClass_Team_Widget.setPane(teamsInClass_Team);
      modelToTitleMap.put("Team", TeamMessages.tab_name_TeamModel());

      tab_teamsInClass_Team_Widget.addTabSelectedHandler(
          new TabSelectedHandler() {
            @Override
            public void onTabSelected(TabSelectedEvent event) {
              // if the last element's key doesn't end with _single, pop it first
              if (!getBreadcrumbs().lastCrumbIsSingle()) {
                getBreadcrumbs().popLast();
              }

              // then add the target's normal crumb
              getBreadcrumbs().addCrumb("Team", TeamMessages.tab_name_TeamModel());
            }
          });

      tabs.addTab(tab_teamsInClass_Team_Widget);
    } else {
      Log.debug("No rights: CAN_READ_TEAM_TAB detected, not showing tab");
    }

    attachToCanvas();
  }