예제 #1
0
        private void bApply_Click(object sender, RoutedEventArgs e)
        {
            bApply.Focus();
            applyButtonPressed = true;
            error = false;

            controller.BeginMacro();
            //controller.CreatedMacro.Description = string.Format("PIM Classs '{0}' was updated. ", PIMClass);
            if (tbName.ValueChanged)
            {
                cmdRenameComponent renameCommand = new cmdRenameComponent(controller)
                {
                    ComponentGuid = PIMClass, NewName = tbName.Text
                };
                controller.CreatedMacro.Commands.Add(renameCommand);
                tbName.ForgetOldValue();
            }

            //if (PIMClass.IsAbstract != cbAbstract.IsChecked)
            //{
            //    PIMClassController.ChangeAbstract(cbAbstract.IsChecked == true);
            //}

            //if (PIMClass.AllowAnyAttribute != cbAnyAttribute.IsChecked)
            //{
            //    PIMClassController.ChangeAllowAnyAttributeDefinition(cbAnyAttribute.IsChecked == true);
            //}

            #region check for deleted attributes

            List <PIMAttribute>     removedAttributes = new List <PIMAttribute>();
            List <FakePIMAttribute> addedAttributes   = new List <FakePIMAttribute>();
            foreach (PIMAttribute PIMAttribute in PIMClass.PIMAttributes)
            {
                bool found = false;
                foreach (FakePIMAttribute fakeAttribute in fakeAttributes)
                {
                    if (fakeAttribute.SourceAttribute == PIMAttribute && fakeAttribute.Checked)
                    {
                        found = true;
                        break;
                    }
                    else if (fakeAttribute.SourceAttribute == PIMAttribute && !fakeAttribute.Checked)
                    {
                        fakeAttribute.SourceAttribute = null;
                    }
                }
                if (!found)
                {
                    removedAttributes.Add(PIMAttribute);
                    cmdDeletePIMAttribute deleteCommand = new cmdDeletePIMAttribute(controller);
                    deleteCommand.Set(PIMAttribute);
                    controller.CreatedMacro.Commands.Add(deleteCommand);
                }
            }

            #endregion

            #region remove dummy entries in fake collection

            List <FakePIMAttribute> toRemove = new List <FakePIMAttribute>();
            foreach (FakePIMAttribute fakeAttribute in fakeAttributes)
            {
                if (String.IsNullOrEmpty(fakeAttribute.Name))
                {
                    if (fakeAttribute.SourceAttribute != null)
                    {
                        removedAttributes.Add(fakeAttribute.SourceAttribute);
                        cmdDeletePIMAttribute deleteCommand = new cmdDeletePIMAttribute(controller);
                        deleteCommand.Set(fakeAttribute.SourceAttribute);
                        controller.CreatedMacro.Commands.Add(deleteCommand);
                    }
                    toRemove.Add(fakeAttribute);
                }
            }

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

            #endregion

            Dictionary <PIMAttribute, string> namesDict = new Dictionary <PIMAttribute, string>();
            foreach (PIMAttribute a in PIMClass.PIMAttributes)
            {
                if (!removedAttributes.Contains(a))
                {
                    namesDict.Add(a, a.Name);
                }
            }

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

            // editing exisiting attribute
            foreach (FakePIMAttribute modifiedAttribute in modified)
            {
                PIMAttribute sourceAttribute = modifiedAttribute.SourceAttribute;
                uint         lower;
                UnlimitedInt upper;
                if (
                    !IHasCardinalityExt.ParseMultiplicityString(modifiedAttribute.Multiplicity, out lower,
                                                                out upper))
                {
                    error = true;
                }
                cmdUpdatePIMAttribute updateCommand = new cmdUpdatePIMAttribute(controller);
                updateCommand.Set(sourceAttribute, modifiedAttribute.Type, modifiedAttribute.Name, lower, upper, modifiedAttribute.DefaultValue);
                controller.CreatedMacro.Commands.Add(updateCommand);
                namesDict[sourceAttribute] = modifiedAttribute.Name;
            }

            List <string> names = namesDict.Values.ToList();
            // new attribute
            foreach (FakePIMAttribute addedAttribute in added)
            {
                if (!string.IsNullOrEmpty(addedAttribute.Name) && addedAttribute.Checked)
                {
                    uint         lower = 1;
                    UnlimitedInt upper = 1;
                    if (!String.IsNullOrEmpty(addedAttribute.Multiplicity))
                    {
                        if (!IHasCardinalityExt.ParseMultiplicityString(addedAttribute.Multiplicity, out lower, out upper))
                        {
                            error = true;
                        }
                    }
                    cmdCreateNewPIMAttribute createNewPIMAttribute = new cmdCreateNewPIMAttribute(controller);
                    createNewPIMAttribute.Set(PIMClass, addedAttribute.Type, addedAttribute.Name, lower, upper, addedAttribute.DefaultValue);
                    controller.CreatedMacro.Commands.Add(createNewPIMAttribute);
                    addedAttributes.Add(addedAttribute);
                    names.Add(addedAttribute.Name);
                }
            }

            if (error)
            {
                controller.CancelMacro();
            }
            else
            {
                CommandBase tmp = (CommandBase)controller.CreatedMacro;
                controller.CommitMacro();
                if (string.IsNullOrEmpty(tmp.ErrorDescription))
                {
                    foreach (FakePIMAttribute attribute in addedAttributes)
                    {
                        attribute.SourceAttribute = PIMClass.PIMAttributes.Where
                                                        (property => property.Name == attribute.Name).SingleOrDefault();
                    }
                    addedAttributes.RemoveAll(attribute => attribute.SourceAttribute == null);
                    bApply.IsEnabled = false;
                    dialogReady      = true;
                    error            = false;
                }
                else
                {
                    error = true;
                }
            }
            Initialize(controller, PIMClass);
            applyButtonPressed = false;
        }
예제 #2
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();
        }
예제 #3
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;
            }
        }