/// <summary>
        /// Populates a view ItemsSource that displays lists of <c>ViewmodelTaggedValue</c>.
        /// </summary>
        /// <param name="toAddList">A list defining what type of <c>ViewmodelTaggedValue</c> should be added to the list, based on <c>PlusprofilTaggedValue.Key</c>.</param>
        /// <param name="taggedValuesList">A <c>List</c> containing the tagged values of an object.</param>
        public ObservableCollection <ObservableCollection <ViewModelTaggedValue> > AddTaggedValuesToViewmodelTaggedValues(List <PlusprofilTaggedValue> toAddList, List <dynamic> taggedValuesList)
        {
            var resultCollectionCollection = new ObservableCollection <ObservableCollection <ViewModelTaggedValue> >();

            foreach (var ptv in toAddList)
            {
                try
                {
                    var result           = RetrieveTaggedValues(taggedValuesList, ptv.Name);
                    var resultCollection = new ObservableCollection <ViewModelTaggedValue>();
                    foreach (var tv in result)
                    {
                        var vtv = new ViewModelTaggedValue(tv)
                        {
                            ResourceDictionary = ResourceDictionary,
                            Key = ptv.Key
                        };
                        vtv.Initialize();
                        resultCollection.Add(vtv);
                    }

                    resultCollectionCollection.Add(resultCollection);

                    //Add remove button to all child elements
                    for (int i = 0; i < resultCollectionCollection.Count(); i++)
                    {
                        for (int j = 0; j < resultCollectionCollection[i].Count(); j++)
                        {
                            if (j == 0)
                            {
                                resultCollectionCollection[i][j].IsChild = false;
                            }
                            else
                            {
                                resultCollectionCollection[i][j].IsChild = true;
                            }
                        }
                    }
                }
                catch (ArgumentException)
                {
                    // No tagged values with name ptv.Name is found, thus the list is not added (do nothing)
                    // TODO: Warn the user in a non-intrusive manner (i.e. do not use a MessageBox)
                }
            }
            return(resultCollectionCollection);
        }
        /// <inheritdoc />
        public override void Initialize()
        {
            SaveCommand   = new SaveCommand();
            CancelCommand = new CancelCommand();
            AddCommand    = new AddCommand();
            RemoveCommand = new RemoveCommand();

            Element      = Repository.GetContextObject();
            UMLNameValue = Element.Name;
            AliasValue   = Element.Alias;
            TaggedValues = Element.TaggedValues;

            //Finalize list of stereotype tags to add
            switch (Element.Stereotype)
            {
            case "OwlClass":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "EquivalentClass"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SubClassOf"));
                StereotypeString = (string)ResourceDictionary["OwlClassCharacteristics"];
                break;

            case "RdfsClass":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "EquivalentClass"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SubClassOf"));
                StereotypeString = (string)ResourceDictionary["RdfsClassCharacteristics"];
                break;

            case "Individual":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SameAs"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "Type"));
                StereotypeString = (string)ResourceDictionary["IndividualCharacteristics"];
                break;
            }

            //Retrieve all tagged values and store them in a list
            //Tagged values are stored in a list to avoid iterating Collections multiple times, which is very costly
            //In a future iteration of the addin, avoid iterating the collection even once, instead using Repository.SQLQuery to retrieve
            //an XML-formatted list of every Tagged Value where the owner ID is Element.ElementID
            for (short i = 0; i < TaggedValues.Count; i++)
            {
                TaggedValue tv = TaggedValues.GetAt(i);
                _taggedValuesList.Add(tv);
            }

            // Retrieve URI tagged value and save it in URIViewmodelTaggedValue
            var result = RetrieveTaggedValues(_taggedValuesList, "URI");

            URIViewmodelTaggedValue = new ViewModelTaggedValue(result.First())
            {
                ResourceDictionary = ResourceDictionary,
                Key = Definitions.Find(ptv => ptv.Key == "URI").Key
            };
            URIViewmodelTaggedValue.Initialize();
            URIValue = URIViewmodelTaggedValue.Value;

            // Add tagged values to list of ViewmodelTaggedValues
            DanishViewmodelTaggedValues     = AddTaggedValuesToViewmodelTaggedValues(_toAddDanishTaggedValues, _taggedValuesList);
            EnglishViewmodelTaggedValues    = AddTaggedValuesToViewmodelTaggedValues(_toAddEnglishTaggedValues, _taggedValuesList);
            ProvenanceViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddProvenanceTaggedValues, _taggedValuesList);
            StereotypeViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddStereotypeTaggedValues, _taggedValuesList);
        }
Example #3
0
        /// <inheritdoc />
        public override void Initialize()
        {
            ConnectorEndType  = ConnectorEnd.End == "Supplier" ? "Target" : "Source";
            UMLNameValue      = ConnectorEnd.Role;
            AliasValue        = ConnectorEnd.Alias;
            MultiplicityValue = ConnectorEnd.Cardinality;
            TaggedValues      = ConnectorEnd.TaggedValues;

            //Finalize list of stereotype tags to add
            switch (ConnectorEnd.Stereotype)
            {
            case "RdfsProperty":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "RangeConnectorEnd"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "DomainConnectorEnd"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SubPropertyOf"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "EquivalentProperty"));
                StereotypeString = (string)ResourceDictionary["RdfsPropertyCharacteristics"];
                break;

            case "ObjectProperty":
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "RangeConnectorEnd"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "DomainConnectorEnd"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SubPropertyOf"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "EquivalentProperty"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "InverseOf"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "FunctionalProperty"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "InverseFunctionalProperty"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "SymmetricProperty"));
                _toAddStereotypeTaggedValues.Add(Definitions.Find(ptv => ptv.Key == "TransitiveProperty"));
                StereotypeString = (string)ResourceDictionary["ObjectPropertyCharacteristics"];
                break;
            }

            //Retrieve all tagged values and store them in a list
            //Tagged values are stored in a list to avoid iterating Collections multiple times, which is very costly
            //In a future iteration of the addin, avoid iterating the collection even once, instead using Repository.SQLQuery to retrieve
            //an XML-formatted list of every Tagged Value where the owner ID is Element.ElementID
            for (short i = 0; i < TaggedValues.Count; i++)
            {
                RoleTag tv = TaggedValues.GetAt(i);
                _taggedValuesList.Add(tv);
            }

            // Retrieve URI tagged value and save it in URIViewmodelTaggedValue
            try
            {
                var result = RetrieveTaggedValues(_taggedValuesList, "URI");
                URIViewmodelTaggedValue = new ViewModelTaggedValue(result.First())
                {
                    ResourceDictionary = ResourceDictionary,
                    Key = Definitions.Find(ptv => ptv.Key == "URI").Key
                };
                URIViewmodelTaggedValue.Initialize();
                URIValue = URIViewmodelTaggedValue.Value;
            }
            catch (ArgumentException)
            {
                //URI does not exist: Do nothing
            }

            // Add tagged values to list of ViewmodelTaggedValues
            DanishViewmodelTaggedValues     = AddTaggedValuesToViewmodelTaggedValues(_toAddDanishTaggedValues, _taggedValuesList);
            EnglishViewmodelTaggedValues    = AddTaggedValuesToViewmodelTaggedValues(_toAddEnglishTaggedValues, _taggedValuesList);
            ProvenanceViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddProvenanceTaggedValues, _taggedValuesList);
            StereotypeViewmodelTaggedValues = AddTaggedValuesToViewmodelTaggedValues(_toAddStereotypeTaggedValues, _taggedValuesList);
        }