public override bool CanExecute()
        {
            if (PSMAttribute.RepresentedAttribute != null)
            {
                if (Name != PSMAttribute.RepresentedAttribute.Name || Type != PSMAttribute.RepresentedAttribute.Type)
                {
                    ErrorDescription = CommandError.CMDERR_REPRESENTING_ATTRIBUTES_CAN_NOT_BE_UPDATED;
                }
            }

            string name = DecideName();

            if (name == null)
            {
                ErrorDescription = CommandError.CMDERR_PIMLESS_NAME;
            }

            if (!NameSuggestor <PSMAttribute> .IsNameUnique(PSMAttribute.Class.PSMAttributes, name, attribute => attribute.AliasOrName, PSMAttribute))
            {
                ErrorDescription = string.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, name);
                return(false);
            }

            if (customMultiplicity && !MultiplicityElementController.IsMultiplicityValid(Lower, Upper))
            {
                ErrorDescription = string.Format(CommandError.CMDERR_MULTIPLICITY_BAD_BOUNDS, name);
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
 public bool SomethingChanged()
 {
     if (SourceAttribute == null)
     {
         return(true);
     }
     else
     {
         uint?            lower;
         UnlimitedNatural upper;
         MultiplicityElementController.ParseMultiplicityString(Multiplicity, out lower, out upper);
         return(SourceAttribute.Name != Name || SourceAttribute.Type != Type ||
                SourceAttribute.Default != Default || SourceAttribute.Alias != Alias ||
                SourceAttribute.Lower != lower || SourceAttribute.Upper != upper);
     }
 }
Esempio n. 3
0
        public override bool CanExecute()
        {
            if (RepresentedAttribute != null)
            {
                if (!PSMClass.RepresentedClass.MeAndAncestors.Contains(RepresentedAttribute.Class))
                {
                    ErrorDescription = CommandError.CMDERR_INCLUDED_ATTRIBUTES_INCONSISTENCE;
                    return(false);
                }

                if (Name != RepresentedAttribute.Name || Type != null)
                {
                    ErrorDescription = CommandError.CMDERR_REPRESENTING_ATTRIBUTES_CAN_NOT_BE_UPDATED;
                }
            }

            string name = DecideName();

            if (name == null)
            {
                ErrorDescription = CommandError.CMDERR_PIMLESS_NAME;
            }

            IEnumerable <string> nameCollection;

            if (UsedAliasesOrNames != null)
            {
                nameCollection = UsedAliasesOrNames;
            }
            else
            {
                nameCollection = from PSMAttribute att in PSMClass.PSMAttributes select att.AliasOrName;
            }

            if (!NameSuggestor <string> .IsNameUnique(nameCollection, name, n => n))
            {
                ErrorDescription = string.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, name);
                return(false);
            }

            if (!MultiplicityElementController.IsMultiplicityValid(Lower, Upper))
            {
                ErrorDescription = string.Format(CommandError.CMDERR_MULTIPLICITY_BAD_BOUNDS, name);
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
        public object ConvertBack(object value, Type targetType,
                                  object parameter, System.Globalization.CultureInfo culture)
        {
            if (modelController != null && selectedAssociationEnd != null && value != null)
            {
                if (((string)value).Equals(selectedAssociationEnd.Upper.ToString()))
                {
                    return(value);
                }

                string newCardinality = selectedAssociationEnd.Lower.ToString() + ".." + ((string)value);

                uint?lower;
                NUml.Uml2.UnlimitedNatural upper;
                MultiplicityElementController.ParseMultiplicityString(newCardinality, out lower, out upper);
                MultiplicityElementController.ChangeMultiplicityOfElement(
                    selectedAssociationEnd, selectedAssociationEnd.Association, lower, upper, modelController);
            }

            return(value);
        }
Esempio n. 5
0
        private void bApply_Click(object sender, RoutedEventArgs e)
        {
            bApply.Focus();

            error = false;

            diagramController.BeginMacro();
            diagramController.CreatedMacro.Description = CommandDescription.UPDATE_CLASS_MACRO;
            if (tbName.ValueChanged)
            {
                psmClassController.RenameElementWithDiagramController(tbName.Text);
                tbName.ForgetOldValue();
            }

            if (tbElementLabel.ValueChanged)
            {
                psmClassController.ChangeElementName(tbName.Text);
                tbElementLabel.ForgetOldValue();
            }

            if (psmClass.IsAbstract != cbAbstract.IsChecked)
            {
                psmClassController.ChangeAbstract(cbAbstract.IsChecked == true);
            }

            if (psmClass.AllowAnyAttribute != cbAnyAttribute.IsChecked)
            {
                psmClassController.ChangeAllowAnyAttributeDefinition(cbAnyAttribute.IsChecked == true);
            }

            #region check for deleted attributes

            List <Property>         removedAttributes = new List <Property>();
            List <FakePSMAttribute> addedAttributes   = new List <FakePSMAttribute>();
            foreach (PSMAttribute psmAttribute in psmClassController.Class.PSMAttributes)
            {
                bool found = false;
                foreach (FakePSMAttribute fakeAttribute in fakeAttributes)
                {
                    if (fakeAttribute.SourceAttribute == psmAttribute && fakeAttribute.Checked)
                    {
                        found = true;
                        break;
                    }
                    else if (fakeAttribute.SourceAttribute == psmAttribute && !fakeAttribute.Checked)
                    {
                        fakeAttribute.SourceAttribute = null;
                    }
                }
                if (!found)
                {
                    removedAttributes.Add(psmAttribute);
                    psmClassController.RemoveAttribute(psmAttribute);
                }
            }

            #endregion

            #region remove dummy entries in fake collection

            List <FakePSMAttribute> toRemove = new List <FakePSMAttribute>();
            foreach (FakePSMAttribute fakeAttribute in fakeAttributes)
            {
                if (String.IsNullOrEmpty(fakeAttribute.Name))
                {
                    if (fakeAttribute.SourceAttribute != null)
                    {
                        removedAttributes.Add(fakeAttribute.SourceAttribute);
                        psmClassController.RemoveAttribute(fakeAttribute.SourceAttribute);
                    }
                    toRemove.Add(fakeAttribute);
                }
            }

            foreach (FakePSMAttribute attribute in toRemove)
            {
                fakeAttributes.Remove(attribute);
            }

            #endregion

            Dictionary <PSMAttribute, string> namesDict = new Dictionary <PSMAttribute, string>();
            foreach (PSMAttribute a in psmClass.PSMAttributes)
            {
                if (!removedAttributes.Contains(a))
                {
                    namesDict.Add(a, a.AliasOrName);
                }
            }

            // check for changes and new attributes
            var modified = from FakePSMAttribute a in fakeAttributes
                           where a.SourceAttribute != null && !removedAttributes.Contains(a.SourceAttribute) && a.SomethingChanged()
                           select a;
            var added = from FakePSMAttribute a in fakeAttributes where a.SourceAttribute == null select a;

            // editing exisiting attribute
            foreach (FakePSMAttribute modifiedAttribute in modified)
            {
                PSMAttribute     sourceAttribute = modifiedAttribute.SourceAttribute;
                uint?            lower;
                UnlimitedNatural upper;
                if (
                    !MultiplicityElementController.ParseMultiplicityString(modifiedAttribute.Multiplicity, out lower,
                                                                           out upper))
                {
                    error = true;
                }
                psmClassController.ModifyAttribute(sourceAttribute, modifiedAttribute.Name, modifiedAttribute.Alias,
                                                   lower, upper, modifiedAttribute.Type, modifiedAttribute.Default);
                namesDict[sourceAttribute] = modifiedAttribute.AliasOrName;
            }

            List <string> names = namesDict.Values.ToList();
            // new attribute
            foreach (FakePSMAttribute addedAttribute in added)
            {
                if (!string.IsNullOrEmpty(addedAttribute.Name) && addedAttribute.Checked)
                {
                    uint?            lower = 1;
                    UnlimitedNatural upper = 1;
                    if (!String.IsNullOrEmpty(addedAttribute.Multiplicity))
                    {
                        if (!MultiplicityElementController.ParseMultiplicityString(addedAttribute.Multiplicity, out lower, out upper))
                        {
                            error = true;
                        }
                    }
                    psmClassController.AddAttribute(addedAttribute.RepresentedAttribute, addedAttribute.Name, addedAttribute.Alias, lower, upper, addedAttribute.Type, addedAttribute.Default, names.ToList());
                    addedAttributes.Add(addedAttribute);
                    names.Add(addedAttribute.AliasOrName);
                }
            }


            if (error)
            {
                diagramController.CancelMacro();
            }
            else
            {
                CommandBase tmp = (CommandBase)diagramController.CreatedMacro;
                diagramController.CommitMacro();
                if (string.IsNullOrEmpty(tmp.ErrorDescription))
                {
                    foreach (FakePSMAttribute attribute in addedAttributes)
                    {
                        if (attribute.RepresentedAttribute != null)
                        {
                            attribute.SourceAttribute = (PSMAttribute)psmClassController.Class.AllAttributes.Where
                                                            (property => ((PSMAttribute)property).RepresentedAttribute == attribute.RepresentedAttribute).SingleOrDefault();
                        }
                        else
                        {
                            attribute.SourceAttribute = psmClassController.Class.PSMAttributes.Where
                                                            (property => property.AliasOrName == attribute.AliasOrName).SingleOrDefault();
                        }
                        //else
                        //{
                        //    attribute.SourceAttribute = (PSMAttribute)psmClassController.Class.AllAttributes.Where
                        //        (property => (property.RepresentedAttribute == attribute.RepresentedAttribute).SingleOrDefault();
                        //}
                        //if (attribute.SourceAttribute.RepresentedAttribute != null)
                        //    attribute.RepresentedAttribute = attribute.SourceAttribute.RepresentedAttribute;
                    }
                    addedAttributes.RemoveAll(attribute => attribute.SourceAttribute == null);
                    bApply.IsEnabled = false;
                    dialogReady      = true;
                    error            = false;
                }
                else
                {
                    error = true;
                }
            }
            gridAttributes.Items.Refresh();
        }
Esempio n. 6
0
        private void bOk_Click(object sender, RoutedEventArgs e)
        {
            #region parse multiplicity

            uint?            lower;
            UnlimitedNatural upper;
            try
            {
                lower = MultiplicityElementController.ParseNullabelUint(tbLower.Text);
                upper = MultiplicityElementController.ParseUnlimitedNatural(tbUpper.Text);
            }
            catch (FormatException)
            {
                CommandCantExecuteDialog dialog = new CommandCantExecuteDialog();
                dialog.tbCommand.Content = "Wrong multiplicity format";
                dialog.tbExMsg.Content   = String.Format("{0}..{1} is not a correct format for multiplicity.", tbLower.Text, tbUpper.Text);
                dialog.ShowDialog();
                return;
            }

            #endregion

            modelController.BeginMacro();
            modelController.CreatedMacro.Description = CommandDescription.UPDATE_PROPERTY_MACRO;

            if (pimClassController != null)
            {
                if (tbName.ValueChanged)
                {
                    NamedElementController.RenameElement(attribute, tbName.Text, modelController, attribute.Class.Attributes);
                }
                if (tbOnto.ValueChanged)
                {
                    NamedElementController.ChangeOntologyEquivalent(attribute, tbOnto.Text, modelController);
                }

                if (tbDefaultValue.ValueChanged)
                {
                    pimClassController.ChangeAttributeDefaultValue(attribute, tbDefaultValue.Text);
                }

                if (tbLower.ValueChanged || tbUpper.ValueChanged)
                {
                    MultiplicityElementController.ChangeMultiplicityOfElement(attribute, attribute.Class, lower, upper, modelController);
                }

                #region change attribute type (create new simple type if required)

                if (cbDataType.SelectedItem != null && cbDataType.SelectedItem is DataType)
                {
                    SimpleDataType t = cbDataType.SelectedItem as SimpleDataType;
                    if (t != null && editedSimpleType)
                    {
                        modelController.AlterSimpleType(t, PrimitiveTypeName, PrimitiveTypeXSD);
                    }
                    if (!(cbDataType.SelectedItem.Equals(oldType)))
                    {
                        pimClassController.ChangeAttributeType(attribute, new ElementHolder <DataType>((DataType)cbDataType.SelectedItem));
                    }
                }
                else
                {
                    if (newSimpleType)
                    {
                        ElementHolder <DataType> type = new ElementHolder <DataType>();
                        modelController.CreateSimpleType(PrimitiveTypeName, PrimitiveTypePackage, PrimitiveTypeParent, PrimitiveTypeXSD, type);
                        pimClassController.ChangeAttributeType(attribute, type);
                    }
                    else if (oldType != null)
                    {
                        pimClassController.ChangeAttributeType(attribute, new ElementHolder <DataType>());
                    }
                }

                #endregion
            }
            if (psmClassController != null)
            {
                PSMAttribute psmAttribute = (PSMAttribute)attribute;

                if (tbName.ValueChanged)
                {
                    NamedElementController.RenameElement(psmAttribute, tbName.Text, modelController, attribute.Class.Attributes);
                }

                #region change attribute type (create new simple type if required)

                if (cbDataType.SelectedItem != null && cbDataType.SelectedItem is DataType)
                {
                    SimpleDataType t = cbDataType.SelectedItem as SimpleDataType;
                    if (t != null && editedSimpleType)
                    {
                        modelController.AlterSimpleType(t, PrimitiveTypeName, PrimitiveTypeXSD);
                    }
                    if (!(cbDataType.SelectedItem.Equals(oldType)))
                    {
                        psmClassController.ChangeAttributeType(psmAttribute, new ElementHolder <DataType>((DataType)cbDataType.SelectedItem));
                    }
                }
                else
                {
                    if (newSimpleType)
                    {
                        ElementHolder <DataType> type = new ElementHolder <DataType>();
                        modelController.CreateSimpleType(PrimitiveTypeName, PrimitiveTypePackage, PrimitiveTypeParent, PrimitiveTypeXSD, type);
                        psmClassController.ChangeAttributeType(psmAttribute, type);
                    }
                    else if (oldType != null)
                    {
                        psmClassController.ChangeAttributeType(psmAttribute, new ElementHolder <DataType>());
                    }
                }

                #endregion

                if (tbDefaultValue.ValueChanged)
                {
                    psmClassController.ChangeAttributeDefaultValue(psmAttribute, tbDefaultValue.Text);
                }

                if (tbLower.ValueChanged || tbUpper.ValueChanged)
                {
                    MultiplicityElementController.ChangeMultiplicityOfElement(psmAttribute, attribute.Class, lower, upper, modelController);
                }

                if (tbAlias.ValueChanged)
                {
                    psmClassController.ChangeAttributeAlias(psmAttribute, tbAlias.Text);
                }
            }
            modelController.CommitMacro();
            DialogResult = true;
            Close();
        }
Esempio n. 7
0
        private void bOk_Click(object sender, RoutedEventArgs e)
        {
            modelController.BeginMacro();
            modelController.CreatedMacro.Description = CommandDescription.UPDATE_ASSOCIATION_MACRO;

            if (tbName.ValueChanged)
            {
                associationController.RenameElement(tbName.Text);
            }
            if (tbOnto.ValueChanged)
            {
                NamedElementController.ChangeOntologyEquivalent(Association, tbOnto.Text, modelController);
            }

            foreach (AssociationEndEditor endEditor in endEditors)
            {
                if (endEditor.tbRole.ValueChanged)
                {
                    NamedElementController.RenameElement(endEditor.AssociationEnd, endEditor.tbRole.Text, modelController, null);
                }

                if (endEditor.tbLower.ValueChanged ||
                    endEditor.tbUpper.ValueChanged)
                {
                    uint?            lower;
                    UnlimitedNatural upper;
                    try
                    {
                        lower = MultiplicityElementController.ParseNullabelUint(endEditor.tbLower.Text);
                        upper = MultiplicityElementController.ParseUnlimitedNatural(endEditor.tbUpper.Text);
                    }
                    catch (FormatException)
                    {
                        CommandCantExecuteDialog dialog = new CommandCantExecuteDialog();
                        dialog.tbCommand.Content = "Wrong multiplicity format";
                        dialog.tbExMsg.Content   = String.Format("{0}..{1} is not a correct format for multiplicity.", endEditor.tbLower.Text, endEditor.tbUpper.Text);
                        dialog.ShowDialog();
                        return;
                    }
                    MultiplicityElementController.ChangeMultiplicityOfElement(endEditor.AssociationEnd, Association, lower, upper, modelController);
                }

                if (endEditor.cbType.SelectedIndex != endEditor.oldKindIndex)
                {
                    AggregationKind aggregationKind = AggregationKind.none;
                    switch (endEditor.cbType.SelectedIndex)
                    {
                    case 0:
                        aggregationKind = AggregationKind.none;
                        break;

                    case 1:
                        aggregationKind = AggregationKind.shared;
                        break;

                    case 2:
                        aggregationKind = AggregationKind.composite;
                        break;
                    }

                    associationController.ChangeAggregation(endEditor.AssociationEnd, aggregationKind);
                }
            }

            modelController.CommitMacro();
            DialogResult = true;
            Close();
        }
Esempio n. 8
0
        private void bApply_Click(object sender, RoutedEventArgs e)
        {
            bApply.Focus();
            if (isPSM)
            {
                throw new NotImplementedException("Method or operation is not implemented.");
            }

            modelController.BeginMacro();
            modelController.CreatedMacro.Description = CommandDescription.UPDATE_CLASS_MACRO;
            if (tbName.ValueChanged)
            {
                classController.RenameElement(tbName.Text, modelClass.Package.Classes.Cast <Class>());
                tbName.ForgetOldValue();
            }
            if (tbOnto.ValueChanged)
            {
                classController.ChangeOntologyEquivalent(tbOnto.Text);
                tbOnto.ForgetOldValue();
            }
            if (cbPackages.SelectedItem != modelClass.Package)
            {
                classController.MoveToPackage((Package)cbPackages.SelectedItem);
            }

            // check for deleted attributes
            List <Property>      removedAttributes = new List <Property>();
            List <FakeAttribute> addedAttributes   = new List <FakeAttribute>();

            foreach (Property attribute in classController.Class.Attributes)
            {
                bool found = false;
                foreach (FakeAttribute fakeAttribute in fakeAttributes)
                {
                    if (fakeAttribute.SourceAttribute == attribute)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    removedAttributes.Add(attribute);
                    classController.RemoveAttribute(attribute);
                }
            }

            List <FakeAttribute> toRemove = new List <FakeAttribute>();

            foreach (FakeAttribute fakeAttribute in fakeAttributes)
            {
                if (String.IsNullOrEmpty(fakeAttribute.Name))
                {
                    if (fakeAttribute.SourceAttribute != null)
                    {
                        removedAttributes.Add(fakeAttribute.SourceAttribute);
                        classController.RemoveAttribute(fakeAttribute.SourceAttribute);
                    }
                    toRemove.Add(fakeAttribute);
                }
            }

            foreach (FakeAttribute attribute in toRemove)
            {
                fakeAttributes.Remove(attribute);
            }

            // check for changes and new attributes
            foreach (FakeAttribute fakeAttribute in fakeAttributes)
            {
                if (fakeAttribute.SourceAttribute != null && !removedAttributes.Contains(fakeAttribute.SourceAttribute))
                {
                    // editing old attribute
                    Property sourceAttribute = fakeAttribute.SourceAttribute;
                    if (fakeAttribute.Name != sourceAttribute.Name)
                    {
                        classController.RenameAttribute(sourceAttribute, fakeAttribute.Name);
                    }
                    if (fakeAttribute.Type != sourceAttribute.Type)
                    {
                        classController.ChangeAttributeType(sourceAttribute, new ElementHolder <DataType>(fakeAttribute.Type));
                    }
                    if (fakeAttribute.Default != sourceAttribute.Default)
                    {
                        classController.ChangeAttributeDefaultValue(sourceAttribute, fakeAttribute.Default);
                    }
                    if (fakeAttribute.Multiplicity != sourceAttribute.MultiplicityString)
                    {
                        if (!String.IsNullOrEmpty(fakeAttribute.Multiplicity))
                        {
                            uint?            lower;
                            UnlimitedNatural upper;
                            if (!MultiplicityElementController.ParseMultiplicityString(fakeAttribute.Multiplicity, out lower, out upper))
                            {
                                return;
                            }
                            MultiplicityElementController.ChangeMultiplicityOfElement(sourceAttribute, classController.Class, lower, upper, classController.DiagramController.ModelController);
                        }
                        else
                        {
                            MultiplicityElementController.ChangeMultiplicityOfElement(sourceAttribute, classController.Class, null, 1, classController.DiagramController.ModelController);
                        }
                    }
                }
                else
                {
                    // new attribute
                    if (!string.IsNullOrEmpty(fakeAttribute.Name))
                    {
                        uint?            lower = 1;
                        UnlimitedNatural upper = 1;
                        if (!String.IsNullOrEmpty(fakeAttribute.Multiplicity))
                        {
                            if (!MultiplicityElementController.ParseMultiplicityString(fakeAttribute.Multiplicity, out lower, out upper))
                            {
                                return;
                            }
                        }
                        classController.AddNewAttribute(fakeAttribute.Name, fakeAttribute.Type, lower, upper, fakeAttribute.Default);
                        addedAttributes.Add(fakeAttribute);
                    }
                }
            }

            CommandBase tmp = (CommandBase)modelController.CreatedMacro;

            modelController.CommitMacro();
            if (string.IsNullOrEmpty(tmp.ErrorDescription))
            {
                foreach (FakeAttribute attribute in addedAttributes)
                {
                    attribute.SourceAttribute =
                        classController.Class.Attributes.Where(property => property.Name == attribute.Name).SingleOrDefault();
                }
                addedAttributes.RemoveAll(attribute => attribute.SourceAttribute == null);
                bApply.IsEnabled = false;
                dialogReady      = true;
                error            = false;
            }
            else
            {
                error = true;
            }
        }