private void InitializeExistingPropertyValuesList() { var sortedNames = new List <KeyValuePair <string, string> >(); // key is the property key string, value is the property name foreach (var key in _doc.GetAllPropertyNames()) { string keyName = PropertyKeyBase.GetPropertyName(key); if (null == keyName) { keyName = key; } sortedNames.Add(new KeyValuePair <string, string>(key, keyName)); } sortedNames.Sort(((entry1, entry2) => string.Compare(entry1.Value, entry2.Value))); // sort the entries not by the key, but by the keyname _propertyList = new SelectableListNodeList(); foreach (var entry in sortedNames) { if (_doc.TryGetValue <object>(entry.Key, !_showAllProperties, out var value, out var bag, out var bagInfo)) { var node = new MyListNode(entry.Value, new Tuple <string, string, IPropertyBag>(entry.Key, entry.Value, bag)) { Text1S = value == null ? "n.a." : value.GetType().Name, Text2S = value == null ? "null" : value.ToString().Replace('\n', '_').Replace('\r', '_'), Text3S = bagInfo.Name }; _propertyList.Add(node); } } }
private void ShowPropertyValueDialog(string propertyKey, string propertyName, object propertyValue) { IMVCAController controller = null; var pk = PropertyKeyBase.GetPropertyKey(propertyKey); if (null != pk && pk.CanCreateEditingController) { controller = pk.CreateEditingController(propertyValue); } if (null == controller) { controller = (IMVCAController)Current.Gui.GetControllerAndControl(new object[] { propertyValue }, typeof(IMVCAController), UseDocument.Copy); } if (null == controller) { Current.Gui.ErrorMessageBox("Sorry! Didn't find a Gui controller to edit this property value!"); ; return; } if (Current.Gui.ShowDialog(controller, "Edit property " + propertyName, false)) { var newValue = controller.ModelObject; _doc.TopmostBag.SetValue(propertyKey, newValue); InitializeExistingPropertyValuesList(); if (null != _view) { _view.PropertyValueList = _propertyList; } } }
/// <summary> /// filter according to the key type: string, TextCode or All /// </summary> /// <param name=""></param> /// <param name=""></param> /// <returns></returns> private bool FilterOnKeyType(PropertyKeyBase propertyKeyBase, SearchPropCriterionKeyTextWork propCritKeyTextWork) { // match all key type: string and TextCode if (propCritKeyTextWork.PropKeyTextType == CritOptionPropKeyTextType.AllKeyType) { return(true); } // get the type of the prop key PropertyKeyString propKeyString = propertyKeyBase as PropertyKeyString; if (propKeyString != null) { if (propCritKeyTextWork.PropKeyTextType == CritOptionPropKeyTextType.KeyStringOnly) { return(true); } return(false); } // the prop key type is TextCode if (propCritKeyTextWork.PropKeyTextType == CritOptionPropKeyTextType.KeyTextCodeOnly) { return(true); } return(false); }
/// <summary> /// The property key text can be a string or a textCode. /// If its a textCode, go in the repository to read the textCode by the id. /// </summary> /// <param name="propCritKeyTextWork"></param> /// <param name="propertyKeyBase"></param> /// <returns></returns> private bool GetKeyText(PropertyKeyBase propertyKeyBase, out string keyText) { PropertyKeyString propKeyString = propertyKeyBase as PropertyKeyString; if (propKeyString != null) { keyText = propKeyString.Key; // ok return(true); } keyText = ""; PropertyKeyTextCode propKeyTextCode = propertyKeyBase as PropertyKeyTextCode; if (propKeyTextCode == null) { // error! return(false); } // load the textCode TextCode textCode = _reposit.Finder.FindTextCodeById(propKeyTextCode.TextCodeId); if (textCode == null) { // error! return(false); } keyText = textCode.Code; return(true); }
private string GetPropKeyText(EtagairEngine engine, PropertyKeyBase propertyKeybase) { PropertyKeyString propKeyString = propertyKeybase as PropertyKeyString; if (propKeyString != null) { return("\"" + propKeyString.Key + "\""); } PropertyKeyTextCode propKeyTextCode = propertyKeybase as PropertyKeyTextCode; string propKeyText = "\"" + "tc/" + engine.Searcher.FindTextCodeById(propKeyTextCode.TextCodeId).Code + "\""; return(propKeyText); }
/// <summary> /// Return the property key content as a string. /// can be a string or a textCodeId. /// </summary> /// <param name="propertyKeyBase"></param> /// <returns></returns> public static string GetPropertyKeyContent(PropertyKeyBase propertyKeyBase) { PropertyKeyString propKeyString = propertyKeyBase as PropertyKeyString; if (propKeyString != null) { return(propKeyString.Key); } PropertyKeyTextCode propKeyTextCode = propertyKeyBase as PropertyKeyTextCode; if (propKeyTextCode != null) { return(propKeyTextCode.TextCodeId); } return(null); }
//public IValue CreatePropValueFromTempl(IValue propTemplValue) //{ // ici(); // PropValueTemplString propValueTemplString = propTemplValue as PropValueTemplString; // if (propValueTemplString != null) // { // PropertyValueString propValueString = new PropertyValueString(); // propValueString.Value = propValueTemplString.Value; // return propValueString; // } // PropValueTemplTextCode propValueTemplTextCode = propTemplValue as PropValueTemplTextCode; // if (propValueTemplTextCode != null) // { // PropertyValueTextCode propValueTextCode = new PropertyValueTextCode(); // propValueTextCode.TextCodeId = propValueTemplTextCode.TextCodeId; // return propValueTextCode; // } // throw new Exception("property Value type not yet implemented!"); //} #region Private methods /// <summary> /// 1- Create the key by copy from the template /// 2- has no action -> exit, need action /// 3- has action /// 3.1- Create the value by provided in the action /// /// </summary> /// <param name="propTempl"></param> /// <param name="ruleValueSetOnInst"></param> /// <returns></returns> private bool ExecPropTemplRuleValueSetOnInst(PropTempl propTempl, PropertyGroup propGroupParent, PropTemplRuleValueToSet ruleValueSetOnInst, List <PropTemplRuleActionBase> listAction, List <PropTemplRuleBase> listRulesNeedActions) { Property property = new Property(); property.PropGroupParentId = propGroupParent.Id; propGroupParent.AddProperty(property); // 1- create the key by copy from the template PropertyKeyBase propKey = CreatePropKeyFromTempl(propTempl); property.SetKeyValue(propKey, null); // an action on this rule is provided? PropTemplRuleActionBase action = listAction.Find(a => a.RuleId.Equals(ruleValueSetOnInst.Id)); if (action == null) { // no action provided for this rule!, need an action on this rule listRulesNeedActions.Add(ruleValueSetOnInst); // stops return(true); } // check the type of the action, must match the rule type! PropTemplRuleActionValueToSet actionSetOnInst = action as PropTemplRuleActionValueToSet; if (actionSetOnInst == null) { // error! action type is wrong return(false); } // move the rule in the list of rules executed/done //propTempl.MoveRuleToExecuted(ruleValueSetOnInst); // execute the action: create the prop Value //PropertyValueBase propValue = CreatePropValueFromAction(actionSetOnInst, ruleValueSetOnInst); IValue value = CreatePropValueFromAction(actionSetOnInst, ruleValueSetOnInst); // set the prop value, the key is set before property.SetValue(value); return(true); }
/// <summary> /// Create a property Template (final) from the template. /// process: /// 1- has no rule -> create the key and the value by copy from the template /// 2- has rule(s), scan rules: /// 2.1- is PropValueSetOnInstance /// 2.1.1- Create the key by copy from the template /// 2.1.2- has no action -> exit, need action /// 2.1.2- has action /// 2.1.2.1- Create the value by provided in the action /// </summary> /// <param name="propTempl"></param> /// <param name="propGroupParent"></param> /// <param name="listAction"></param> /// <param name="listRulesNeedActions"></param> /// <returns></returns> private bool CreatePropFromTempl(PropTempl propTempl, PropertyGroup propGroupParent, List <PropTemplRuleActionBase> listAction, List <PropTemplRuleBase> listRulesNeedActions) { // 1- has no rule -> create the key and the value by copy from the template if (propTempl.ListRule.Count == 0) { // create the key by copy from the template PropertyKeyBase propKey = _processEntPropTemplRules.CreatePropKeyFromTempl(propTempl); // create the value by copy from the template IValue propValue = ValueToolCore.CreateValueFromTempl(propTempl.PropValueTempl); Property property = new Property(); property.PropGroupParentId = propGroupParent.Id; property.SetKeyValue(propKey, propValue); propGroupParent.AddProperty(property); return(true); } // 2- has rule(s), scan each one return(_processEntPropTemplRules.ExecRules(propTempl, propGroupParent, listAction, listRulesNeedActions)); }
/// <summary> /// create the propGroup from the template, is empty (no child). /// Childs will be created after that. /// </summary> /// <param name="propTempl"></param> /// <param name="propGroupParent"></param> /// <returns></returns> private bool CreatePropGroupFromTempl(PropGroupTempl propGroupTempl, PropertyGroup propGroupParent, List <PropTemplRuleActionBase> listAction, List <PropTemplRuleBase> listRulesNeedActions, out PropertyGroup propGroupChild) { // create the propGroup based on the template, add it under the propGroupParent propGroupChild = new PropertyGroup(); propGroupChild.PropGroupTemplId = propGroupTempl.Id; propGroupChild.PropGroupParentId = propGroupParent.Id; // create the key by copy from the template PropertyKeyBase propKey = _processEntPropTemplRules.CreatePropKeyFromTempl(propGroupTempl); propGroupChild.Key = propKey; // save it (will create id) // TODO: besoin? //_reposit.Builder.UpdateEntity(); // add it under the propGroupParent propGroupParent.AddProperty(propGroupChild); return(true); }
/// <summary> /// low-level method. /// </summary> /// <param name="entity"></param> /// <param name="propertyParent"></param> /// <param name="propKey"></param> /// <param name="value"></param> /// <returns></returns> public Property CreateProperty(Entity entity, PropertyGroup propertyParent, PropertyKeyBase propKey, IValue value) { // check the entity parent if (entity == null) { return(null); } if (propertyParent == null) { propertyParent = entity.PropertyRoot; } if (propKey == null) { return(null); } // create the property, set the key and the value Property property = new Property(); property.PropGroupParentId = propertyParent.Id; property.SetKeyValue(propKey, value); // add the property under the root properties entity.AddProperty(propertyParent, property); // save the entity modification if (!_reposit.Builder.UpdateEntity(entity)) { return(null); } return(property); }
//public void SetKeyValue(PropertyKeyBase key, PropertyValueBase value) //{ // Key = key; // Value = value; //} public void SetKeyValue(PropertyKeyBase key, IValue value) { Key = key; Value = value; }