Example #1
0
  /**
   * Handles an action for the given target. The handler method may just discard the action if it's
   * not suitable.
   *
   * @param action the action to be handled.
   * @param sender the sender of the action. This is most often the action container.
   * @param target the target of the action. For item containers this is the item id.
   */
  @Override
  @SuppressWarnings("unchecked")
  public void handleAction(Action action, Object sender, Object target) {
    if (target != null) {
      IntID itemId = (IntID) target;
      Item item = this.menuTree.getItem(itemId);
      MenuItemData itemData = this.menuTree.getItemData(itemId);

      if (item != null) {
        Map<Action, MenuActionProvider> actionComponentHandlerMap =
            itemData.getActionComponentHandlers();

        if (actionComponentHandlerMap != null) {
          MenuActionProvider menuActionProvider = actionComponentHandlerMap.get(action);

          if (menuActionProvider != null) {

            if (menuActionProvider instanceof ComponentHandler) {
              this.layout.setCenter(((ComponentHandler) menuActionProvider).getComponent());
              this.layout.doLayout();
            }

            if (menuActionProvider instanceof MenuActionExecutor) {
              ((MenuActionExecutor) menuActionProvider).executeMenuAction();
            }
          }
        }
      }
    }
  }
Example #2
0
  /**
   * Private handler of ValueChangedListener for MenuTree.
   *
   * @param itemId The item to handle.
   */
  private void menuTreeItemHandler(IntID itemId) {
    if (itemId != null) {
      MenuItemData itemData = this.menuTree.getItemData(itemId);
      ComponentHandler guiHandler = itemData.getSelectComponentHandler();
      if (guiHandler != null) {
        if (this.layout.getCenter() == null) {
          this.layout.setCenter(guiHandler.getComponent());
        } else {
          if (this.layout.getCenter().equals(guiHandler.getComponent())) {
            this.layout.setCenter(null);
          } else {
            this.layout.setCenter(guiHandler.getComponent());
          }
        }
      } else {
        this.layout.setCenter(null);
      }
    } else {
      this.layout.setCenter(null);
    }

    this.layout.doLayout();
  }