private void initAdvancedModeFromLocalStorage(UnitVmModel model) {
    if (model.getIsAdvancedModeLocalStorageKey() == null) {
      return;
    }

    boolean isAdvancedMode =
        Boolean.parseBoolean(clientStorage.getLocalItem(model.getIsAdvancedModeLocalStorageKey()));
    model.getAdvancedMode().setEntity(isAdvancedMode);
  }
  private void storeAdvancedModeToLocalStorage(UnitVmModel model) {
    if (model.getIsAdvancedModeLocalStorageKey() == null) {
      return;
    }

    clientStorage.setLocalItem(
        model.getIsAdvancedModeLocalStorageKey(),
        Boolean.toString(model.getAdvancedMode().getEntity()));
  }
  private void switchToAdvancedIfNeeded(final UnitVmModel model) {
    if (model.getAdvancedMode().getEntity() || model.getValid().getEntity()) {
      return;
    }

    List<HasValidation> invalidWidgets = getView().getInvalidWidgets();

    if (invalidWidgets.size() == 0) {
      return;
    }

    for (HasValidation invalidWidget : invalidWidgets) {
      boolean isVisible =
          invalidWidget instanceof HasVisibility && ((HasVisibility) invalidWidget).isVisible();
      boolean isAttached =
          invalidWidget instanceof HasAttachHandlers
              && ((HasAttachHandlers) invalidWidget).isAttached();
      if (!isVisible || !isAttached) {
        model.getAdvancedMode().setEntity(true);
        break;
      }
    }
  }
  private void initListeners(final UnitVmModel model) {
    model
        .getAdvancedMode()
        .getPropertyChangedEvent()
        .addListener(
            new IEventListener<EventArgs>() {

              @Override
              public void eventRaised(
                  Event<? extends EventArgs> ev, Object sender, EventArgs args) {
                storeAdvancedModeToLocalStorage(model);
                swithAccordingToMode(model);
              }
            });

    model
        .getAttachedToInstanceType()
        .getPropertyChangedEvent()
        .addListener(
            new IEventListener<EventArgs>() {
              @Override
              public void eventRaised(
                  Event<? extends EventArgs> ev, Object sender, EventArgs args) {
                swithAttachToInstanceType(model);
              }
            });

    model
        .getValid()
        .getPropertyChangedEvent()
        .addListener(
            new IEventListener<EventArgs>() {
              @Override
              public void eventRaised(
                  Event<? extends EventArgs> ev, Object sender, EventArgs args) {
                switchToAdvancedIfNeeded(model);
              }
            });

    registerHandler(
        getView()
            .getNumaSupportButton()
            .addClickHandler(
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    getView().getNumaSupportButton().getCommand().execute();
                  }
                }));
  }
 private void swithAccordingToMode(final UnitVmModel model) {
   getView().switchMode(model.getAdvancedMode().getEntity());
 }