private ProjectMemberRoleSelector(
      final int x, final int y, int width, int height, final RoleSelectionListener rsl) {

    VerticalPanel vp = new VerticalPanel();
    vp.setBorderRadius(3);
    vp.setBoxShadow(1, 1, 5, 5, "rgba(0,0,0,0.2)");
    vp.fitToParent();

    HorizontalPanel header = new HorizontalPanel();
    header.setWidth100();
    header.setHeight(20);
    header.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    header.setBackgroundImage(
        new LinearGradient(LinearGradient.Orientation.TOP_TO_BOTTOM, "#cdcdcd", "#979797"));

    Label headerLabel = new Label("Select project role and data-use ...");
    headerLabel.setFontSize(10);
    headerLabel.setFontWeight(FontWeight.BOLD);
    headerLabel.setHeight100();
    header.add(headerLabel);

    vp.add(header);

    final Form form =
        new Form() {

          @Override
          public Validity valid() {

            Validity v = super.valid();
            if (!v.valid()) {
              return v;
            }
            if ((_role.equals(ProjectRole.MEMBER) || _role.equals(ProjectRole.GUEST))
                && _dataUse == null) {
              return new Validity() {
                @Override
                public boolean valid() {

                  return false;
                }

                @Override
                public String reasonForIssue() {

                  return "data-use is not set for " + _role;
                }
              };
            }
            return v;
          }
        };
    form.fitToParent();
    Field<ProjectRole> roleField =
        new Field<ProjectRole>(
            new FieldDefinition(
                "Role", ProjectRole.asEnumerationType(), "Project role", null, 1, 1));
    roleField.addListener(
        new FormItemListener<ProjectRole>() {

          @Override
          public void itemValueChanged(FormItem<ProjectRole> f) {

            _role = f.value();
            if (form.valid().valid()) {
              _okButton.enable();
            } else {
              _okButton.disable();
            }
          }

          @Override
          public void itemPropertyChanged(FormItem<ProjectRole> f, Property property) {}
        });
    form.add(roleField);
    Field<DataUse> dataUseField =
        new Field<DataUse>(
            new FieldDefinition(
                "Data Use", DataUse.asEnumerationType(), "Project data use", null, 0, 1));
    dataUseField.addListener(
        new FormItemListener<DataUse>() {

          @Override
          public void itemValueChanged(FormItem<DataUse> f) {

            _dataUse = f.value();
            if (form.valid().valid()) {
              _okButton.enable();
            } else {
              _okButton.disable();
            }
          }

          @Override
          public void itemPropertyChanged(FormItem<DataUse> f, Property property) {}
        });
    form.add(dataUseField);
    form.render();
    vp.add(form);

    ButtonBar bb = new ButtonBar(ButtonBar.Position.BOTTOM, ButtonBar.Alignment.RIGHT);
    bb.setHeight(26);
    _okButton = new Button("OK");
    _okButton.disable();
    _okButton.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {

            _succeeded = true;
            _pp.hide();
          }
        });
    bb.add(_okButton);
    Button cancelButton = new Button("Cancel");
    cancelButton.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {

            _succeeded = false;
            _pp.hide();
          }
        });
    bb.add(cancelButton);
    bb.setMarginRight(5);
    vp.add(bb);

    _pp = new PopupPanel();
    _pp.setAutoHideEnabled(true);
    _pp.setWidth(width > MIN_WIDTH ? width : MIN_WIDTH);
    _pp.setHeight(height > MIN_HEIGHT ? height : MIN_HEIGHT);
    _pp.setBackgroundColour("#f0f0f0");
    _pp.setBorder(1, "#a0a080");
    _pp.setContent(vp);
    _pp.addCloseHander(
        new PopupCloseHandler() {

          @Override
          public void closed(PopupPanel p) {

            if (_succeeded) {
              rsl.roleSelected(_role, _dataUse);
            } else {
              rsl.roleSelected(null, null);
            }
          }
        });
    _pp.setPopupPositionAndShow(
        new PositionCallback() {

          @Override
          public void setPosition(int offsetWidth, int offsetHeight) {

            _pp.setPopupPosition(x - offsetWidth / 2, y - offsetHeight / 2);
          }
        });
  }
  public ShoppingCartForm(ShoppingCart cart, FormEditMode mode, boolean showHeader) {

    _mode = mode;

    _vp = new VerticalPanel();
    _vp.fitToParent();

    /*
     * header
     */
    if (showHeader) {
      CenteringPanel headerSP = new CenteringPanel();
      headerSP.setWidth100();
      headerSP.setHeight(20);
      headerSP.setBackgroundImage(
          new LinearGradient(
              LinearGradient.Orientation.TOP_TO_BOTTOM,
              ListGridHeader.HEADER_COLOUR_LIGHT,
              ListGridHeader.HEADER_COLOUR_DARK));
      _header = new HTML();
      _header.fitToParent();
      _header.setFontSize(11);
      _header.setFontWeight(FontWeight.BOLD);
      headerSP.setContent(_header);
      _vp.add(headerSP);
    }

    /*
     * tabs
     */
    _tp =
        new TabPanel() {
          protected void activated(int id) {
            _activeTabId = id;
            if (_activeTabId == _contentsTabId) {
              contentsTabActivated();
            }
            if (_activeTabId == _settingsTabId) {
              settingsTabActivated();
            }
          }
        };
    _tp.fitToParent();
    _tp.setBodyBorder(1, BorderStyle.SOLID, new RGB(0x97, 0x97, 0x97));

    /*
     * content tab
     */
    _contentsForm = new ShoppingCartContentsForm(null, _mode);
    _contentsTabId = _tp.addTab(TAB_NAME_CONTENTS, null, _contentsForm.gui());
    addMustBeValid(_contentsForm);

    /*
     * settings tab
     */
    _settingsForm = new ShoppingCartSettingsForm(null, _mode);
    _settingsTabId = _tp.addTab(TAB_NAME_SETTINGS, null, _settingsForm.gui());
    addMustBeValid(_settingsForm);

    _tp.setActiveTabById(_contentsTabId);
    _vp.add(_tp);

    setCart(cart);
  }