﻿// Copyright (C) 2008 Xtensive LLC.
// All rights reserved.
// For conditions of distribution and use, see license.
// Created by: Alexander Ilyin
// Created:    2008.09.10


Ext.namespace("Xtensive");

Xtensive.CommandMenuItemAdapter = function(cfg) {
  this.command = cfg.command;
  this.menuItem = cfg.menuItem;
}

Xtensive.CommandMenuItemAdapter.prototype = {
  init: function() {
    this.command.ensureInitialized();

    this.menuItem.on('click', function() {
      this.command.execute();
    }, this);
    this.command.add_availableChanged(this.refreshMenuItem.createDelegate(this));
    this.refreshMenuItem();
  },

  refreshMenuItem: function() {
    this.menuItem.setDisabled(!this.command.get_Available());
  }
}

Xtensive.CommandMenuItemAdapter.bind = function(command, menuItem) {
  var newAdapter = new Xtensive.CommandMenuItemAdapter(
    {command : command, menuItem : menuItem});
  newAdapter.init();
}
if (typeof (Sys) !== 'undefined')
  Sys.Application.notifyScriptLoaded();