public AbstractActionModelTreeLeafAction(IAction action)
			: base(action.Path.LastSegment)
		{
			Platform.CheckForNullReference(action, "action");
			Platform.CheckTrue(action.Persistent, "Action must be persistent.");

			// this allows us to keep a "clone" that is independent of the live action objects
			// that might (probably are) in use or cached in some tool or component somewhere.
			_action = AbstractAction.Create(action);

			CheckState = _action.Available ? CheckState.Checked : CheckState.Unchecked;

			IconSet iconSet;
			if (action.IconSet == null || action.ResourceResolver == null)
			{
				iconSet = new IconSet("Icons.ActionModelNullSmall.png", "Icons.ActionModelNullMedium.png", "Icons.ActionModelNullLarge.png");
				ResourceResolver = new ApplicationThemeResourceResolver(typeof(AbstractActionModelTreeLeafAction).Assembly, action.ResourceResolver);
			}
			else
			{
				iconSet = _action.IconSet;
				ResourceResolver = _action.ResourceResolver;
			}

			if (_action.Permissible)
			{
				IconSet = iconSet;
			}
			else
			{
				IconSet = new UnavailableActionIconSet(iconSet);
				Description = SR.TooltipActionNotPermitted;
				Tooltip = String.IsNullOrEmpty(CanonicalLabel) ?
					SR.TooltipActionNotPermitted : String.Format(SR.TooltipFormatActionNotPermitted, CanonicalLabel);
			}
		}
Example #2
0
        /// <summary>
        /// Builds an in-memory abstract action model from the specified XML model and the specified set of known actions.
        /// </summary>
        /// <remarks>
        /// This method functions similarly to <see cref="BuildAndSynchronize"/> except that the resulting action model
        /// consists solely of <see cref="AbstractAction"/>s which are not actually associated with any concrete actions on tools or components.
        /// </remarks>
        /// <param name="namespace">A namespace to qualify the site.</param>
        /// <param name="site">The site.</param>
        /// <param name="actions">The set of actions to include. This set should be prefiltered on <paramref name="site"/>.</param>
        /// <returns>An <see cref="ActionModelNode"/> representing the root of the action model.</returns>
        public ActionModelRoot BuildAbstractActionModel(string @namespace, string site, IActionSet actions)
        {
            // do one time initialization
            if (_actionModelXmlDoc == null)
            {
                Initialize();
            }

            string actionModelId = string.Format("{0}:{1}", @namespace, site);

            IDictionary <string, IAction> actionMap = BuildActionMap(actions);

            XmlElement xmlActionModel = FindXmlActionModel(actionModelId);

            if (xmlActionModel == null)
            {
                xmlActionModel = Synchronize(actionModelId, actionMap);
            }
            else
            {
                // clone the model because we don't want to be modifying the actual action model yet
                xmlActionModel = (XmlElement)xmlActionModel.CloneNode(true);

                //Fix all the group hints.
                UpdateGroupHints(xmlActionModel, actionMap);

                // if there are new persistent actions that aren't already in the xml, insert them now
                foreach (IAction action in actionMap.Values)
                {
                    if (action.Persistent)
                    {
                        if (AppendActionToXmlModel(_actionModelXmlDoc, xmlActionModel, action))
                        {
                            Platform.Log(LogLevel.Debug, "Inserted {0}", action.ActionID);
                        }
                    }
                }

                List <XmlElement> childNodes      = GetActionNodeList(xmlActionModel);
                List <IAction>    abstractActions = new List <IAction>(childNodes.Count);
                foreach (XmlElement childElement in childNodes)
                {
                    if (childElement.Name == "action")
                    {
                        string actionId = childElement.GetAttribute("id");
                        if (string.IsNullOrEmpty(actionId))
                        {
                            Platform.Log(LogLevel.Debug, "Invalid action model entry with null ID in /action-models/action-model[@id='{0}']", actionModelId);
                            continue;
                        }

                        try
                        {
                            if (actionMap.ContainsKey(actionId))
                            {
                                abstractActions.Add(AbstractAction.Create(actionMap[actionId]));
                            }
                        }
                        catch (Exception ex)
                        {
                            Platform.Log(LogLevel.Debug, ex, "Invalid action model entry at /action-models/action-model[@id='{0}']/action[@id='{1}']", actionModelId, actionId);
                        }
                    }
                }
                actions   = new ActionSet(abstractActions);
                actionMap = BuildActionMap(actions);
            }

            return(Build(site, xmlActionModel, actionMap));
        }