@Override
    public void eventRaised(Event ev, Object sender, EventArgs args) {
      if (async && getForm() == null) return;

      valueMap = new LinkedHashMap<String, String>();
      ListModel listModel = (ListModel) sender;
      Iterable items = listModel.getItems();

      if (items != null) {
        GWT.log("Select box " + selectBox.getTitle() + " items loaded: " + items);
        itemsCount = 0;
        for (Object o : items) {
          itemsCount++;
          valueMap.put(getItemId(o), getItemName(o));
        }
        if (model.getIsChangable()) {
          setShowDisabled(false);
          setDisabled(false);
        } else {
          setShowDisabled(true);
          setDisabled(!model.getIsChangable());
        }

        // Set a tool tip with a prohibition reason when the select box is non-changeable
        if (!listModel.getIsChangable() && !listModel.getChangeProhibitionReasons().isEmpty()) {
          setTooltip("<nobr>" + model.getChangeProhibitionReasons().iterator().next() + "</nobr>");
          setHoverStyle("gridToolTipStyle");
          setHoverWidth(1);
          setHoverDelay(100);
        }
      } else {
        GWT.log("Select box " + selectBox.getTitle() + " items loaded are null");
      }
      selectBox.setValueMap(valueMap);
    }
  private void setSelectItemEvents(final boolean async, final ObjectNameIdResolver resolver) {
    final ListModel model = listModel;

    model
        .getItemsChangedEvent()
        .addListener(
            new ChangedModelItemEventHandler(this, model) {
              public String getItemName(Object o) {
                return resolver.getItemName(o);
              }

              public String getItemId(Object o) {
                return resolver.getItemId(o);
              }
            });

    model
        .getSelectedItemChangedEvent()
        .addListener(
            new IEventListener() {
              @Override
              public void eventRaised(Event ev, Object sender, EventArgs args) {
                if (async && getForm() == null) return;

                GWT.log("Item changed: " + getTitle() + " Changed to: " + model.getSelectedItem());
                if (model.getSelectedItem() != null)
                  setValue(resolver.getItemId(model.getSelectedItem()));
                else if (getDisplayValue() != null)
                  setValue((String) null); // Clear the selected item
              }
            });

    addChangedHandler(
        new BoxSelectItemChanged(model) {
          String getItemId(Object o) {
            return resolver.getItemId(o);
          }
        });

    model
        .getPropertyChangedEvent()
        .addListener(
            new IEventListener() {
              @Override
              public void eventRaised(Event ev, Object sender, EventArgs args) {
                if (async && getForm() == null) return;

                String property = ((PropertyChangedEventArgs) args).PropertyName;

                if (property.equals("IsChangable")) {
                  if (!model.getIsChangable()) {
                    setShowDisabled(true);
                    setDisabled(true);
                  } else {
                    setDisabled(false);
                  }
                } else if (property.equals("IsAvailable")) {
                  if (!model.getIsAvailable()) {
                    hide();
                  } else {
                    show();
                  }
                } else if (property.equals("IsValid")) {
                  if (!listModel.getIsValid()) {
                    setTextBoxStyle("selectBoxInvalid");
                    if (listModel.getInvalidityReasons() != null
                        && listModel.getInvalidityReasons().size() > 0) {
                      setTooltip(
                          "<nobr>"
                              + listModel.getInvalidityReasons().iterator().next()
                              + "</nobr>");
                      setHoverStyle("gridToolTipStyle");
                      setHoverWidth(1);
                      setHoverDelay(100);
                    }
                  } else {
                    setTextBoxStyle("engineSelectItem");
                    setTooltip("");
                  }
                }
              }
            });

    if (!async) {
      model.getItemsChangedEvent().raise(model, EventArgs.Empty);
      model.getSelectedItemChangedEvent().raise(model, EventArgs.Empty);
    }
  }
 @Override
 public void onChanged(ChangedEvent event) {
   model.setSelectedItem(event.getValue().toString());
 }
 @Override
 public void onClose() {
   model.ExecuteCommand(new UICommand("Cancel", model));
 }
  public ItemRemoveModalPanel(
      String title,
      String itemsString,
      final ListModel model,
      ObjectNameResolver nameResolver,
      final GridController gridController) {
    super(panelWidth, panelHeight, title);

    this.model = model;

    VLayout inPanel = new VLayout();
    inPanel.setHeight100();
    inPanel.setWidth100();

    Label message = new Label("Are you sure you want to remove the following " + itemsString + "?");
    message.setStyleName("removePanelLabel");
    message.setAutoHeight();
    inPanel.addMember(message);

    for (Object item : model.getSelectedItems()) {
      Label l = new Label("- " + nameResolver.getItemName(item));
      l.setStyleName("removePanelItems");
      l.setAutoHeight();
      l.setValign(VerticalAlignment.TOP);
      inPanel.addMember(l);
    }

    model
        .getPropertyChangedEvent()
        .addListener(
            new IEventListener() {
              @Override
              public void eventRaised(Event ev, Object sender, EventArgs args) {
                String propertyName = ((PropertyChangedEventArgs) args).PropertyName;
                GWT.log("DERBA: " + propertyName);
                if (propertyName.equals("Window") || propertyName.equals("ConfirmationModel")) {
                  destroy();
                  model.getPropertyChangedEvent().removeListener(this);
                  if (gridController != null) gridController.gridChangePerformed();
                }
              }
            });

    Button okButton = new Button("OK");
    okButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            model.ExecuteCommand(new UICommand("OnRemove", model));
          }
        });

    Button cancelButton = new Button("Cancel");
    cancelButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            onClose();
          }
        });

    setFooterButtons(Alignment.RIGHT, okButton, cancelButton);

    addItem(inPanel);
  }