Exemplo n.º 1
0
        private AttributeDialog(Property attribute, ModelController controller)
        {
            InitializeComponent();

            this.modelController = controller;
            this.attribute       = attribute;
            this.Title           = string.Format("Attribute: {0}.{1}", attribute.Class.Name, attribute.Name);

            tbName.Text            = attribute.Name;
            tbDefaultValue.Text    = attribute.Default;
            tbLower.Text           = attribute.Lower.ToString();
            tbUpper.Text           = attribute.Upper.ToString();
            cbDataType.Text        = (attribute.Type != null) ? attribute.Type.ToString() : string.Empty;
            oldType                = attribute.Type;
            itemsSource            = new List <Object>(attribute.Class.Package.AllTypes.Cast <object>());
            cbDataType.ItemsSource = itemsSource;
            if (attribute.Type != null)
            {
                cbDataType.SelectedIndex = cbDataType.Items.IndexOf(attribute.Type);
            }

            SimpleDataType simpleDataType = attribute.Type as SimpleDataType;

            if (simpleDataType != null)
            {
                PrimitiveTypeName    = simpleDataType.Name;
                PrimitiveTypePackage = simpleDataType.Package;
                PrimitiveTypeParent  = simpleDataType.Parent;
                PrimitiveTypeXSD     = simpleDataType.DefaultXSDImplementation;
            }
            this.psmOnly     = new UIElement[] { cvAlias };
            this.psmDisabled = new Control[] { tbName, cbDataType };
            this.psmHidden   = new UIElement[] { cvSimpleType };
        }
Exemplo n.º 2
0
 public FakeAttribute(Property p) : this()
 {
     Name            = p.Name;
     Type            = p.Type;
     Multiplicity    = p.MultiplicityString;
     Default         = p.Default;
     SourceAttribute = p;
 }
Exemplo n.º 3
0
        public void ChangeAttributeDefaultValue(Property attribute, string newDefaultValue)
        {
            ChangeAttributeDefaultValueCommand c = (ChangeAttributeDefaultValueCommand)ChangeAttributeDefaultValueCommandFactory.Factory().Create(DiagramController.ModelController);

            c.Attribute = attribute;
            c.AssociatedElements.Add(Class);
            c.NewDefault = newDefaultValue;
            c.Execute();
        }
Exemplo n.º 4
0
        public void ChangeAttributeType(Property attribute, ElementHolder <DataType> newType)
        {
            ChangeAttributeTypeCommand c = (ChangeAttributeTypeCommand)ChangeAttributeTypeCommandFactory.Factory().Create(DiagramController.ModelController);

            c.AssociatedElements.Add(Class);
            c.Attribute = attribute;
            c.NewType   = newType;
            c.Execute();
        }
Exemplo n.º 5
0
        public void RenameAttribute(Property attribute, string newName)
        {
            RenameElementCommand <Property> renameElementCommand = (RenameElementCommand <Property>) RenameElementCommandFactory <Property> .Factory().Create(DiagramController.ModelController);

            renameElementCommand.NewName = newName;
            renameElementCommand.AssociatedElements.Add(Class);
            renameElementCommand.RenamedElement       = attribute;
            renameElementCommand.ContainingCollection = Class.Attributes;
            renameElementCommand.Execute();
        }
Exemplo n.º 6
0
        public AttributeDialog(Property attribute, IControlsAttributes pimClassController, ModelController controller)
            : this(attribute, controller)
        {
            this.pimClassController = pimClassController;

            foreach (UIElement element in psmOnly)
            {
                element.Visibility = Visibility.Collapsed;
            }
            tbOnto.Text = attribute.OntologyEquivalent;
        }
Exemplo n.º 7
0
        public void RemoveAttribute(Property attribute)
        {
            RemoveAttributeMacroCommand removeAttributeCommand = (RemoveAttributeMacroCommand)RemoveAttributeMacroCommandFactory.Factory().Create(DiagramController.ModelController);

            removeAttributeCommand.Set(attribute);
            removeAttributeCommand.AssociatedElements.Add(Class);
            if (removeAttributeCommand.Commands.Count > 0)
            {
                removeAttributeCommand.Execute();
            }
        }
Exemplo n.º 8
0
 public FakePSMAttribute(Property p)
     : this()
 {
     Name                 = p.Name;
     Type                 = p.Type;
     Multiplicity         = p.MultiplicityString;
     Default              = p.Default;
     SourceAttribute      = null;
     RepresentedAttribute = p;
     Alias                = null;
     ComesFrom            = (PIMClass)p.Class;
     Checked              = false;
 }
Exemplo n.º 9
0
        public PSMAttribute AddAttribute(Property representedAttribute, string name, string alias, uint?lower, UnlimitedNatural upper, DataType type, string @default, IEnumerable <string> names)
        {
            AddPSMClassAttributeCommand c = (AddPSMClassAttributeCommand)AddPSMClassAttributeCommandFactory.Factory().Create(DiagramController);

            c.PSMClass             = Class;
            c.Alias                = alias;
            c.Name                 = name;
            c.Lower                = lower;
            c.Upper                = upper;
            c.Type                 = type;
            c.Default              = @default;
            c.RepresentedAttribute = representedAttribute;
            c.UsedAliasesOrNames   = names;
            c.Execute();

            return(c.CreatedAttribute);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Writes type attribute
        /// </summary>
        /// <param name="property">property whose <see cref="Model.TypedElement.Type"/> attribute is being written</param>
        /// <param name="simpleTypeWriter">writer where simple type definition is written if the type was not
        /// yet used</param>
        /// <param name="useOccurs">if set to true, minOccurs and maxOccurs attributes are also written if
        /// <paramref name="property"/> multipicity is non-default</param>
        /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and
        /// use="optional" is written.</param>
        public void TypeAttribute(Property property, ref SimpleTypesWriter simpleTypeWriter, bool useOccurs, bool forceOptional)
        {
            DataType type = property.Type;

            if (type == null)
            {
                Writer.WriteAttributeString("type", "xs:string");
                Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property));
            }
            else
            {
                SimpleDataType simpleType = type as SimpleDataType;
                if (simpleType != null)
                {
                    if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation))
                    {
                        if (simpleType.Parent != null)
                        {
                            simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType);
                            Writer.WriteAttributeString("type", simpleType.Name);
                        }
                        else
                        {
                            Writer.WriteAttributeString("type", NamespacePrefix + ":" + simpleType.DefaultXSDImplementation);
                        }
                    }
                    else
                    {
                        if (type is SimpleDataType)
                        {
                            Writer.WriteAttributeString("type", NamespacePrefix + ":" + type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                        else
                        {
                            Writer.WriteAttributeString("type", type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                    }
                }
                else
                {
                    Writer.WriteAttributeString("type", type.ToString());
                }
            }
            if (!String.IsNullOrEmpty(property.Default))
            {
                Writer.WriteAttributeString("default", property.Default);
            }
            if (forceOptional)
            {
                Writer.WriteAttributeString("use", "optional");
            }
            else
            {
                if (!useOccurs)
                {
                    if (property.Lower == 0 || property.Lower == null)
                    {
                        Writer.WriteAttributeString("use", "optional");
                        if (property.Upper > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                    }
                    else
                    {
                        if (property.Upper > 1 || property.Lower > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                        if (String.IsNullOrEmpty(property.Default))
                        {
                            Writer.WriteAttributeString("use", "required");
                        }
                    }
                }
                else
                {
                    MultiplicityAttributes(property.Lower, property.Upper);
                }
            }
            IsEmpty = false;
            AfterWriteDebug();
        }
Exemplo n.º 11
0
        public void ShowAttributeDialog(Property attribute)
        {
            AttributeDialog attributeDialog = new AttributeDialog(attribute, this, DiagramController.ModelController);

            attributeDialog.ShowDialog();
        }
Exemplo n.º 12
0
        public void typeAttribute(Property property, XmlElement targetElement, bool useOccurs, bool forceOptional)
        {
            DataType type = property.Type;

            if (type == null)
            {
                targetElement.SetAttribute("type", "xs:string");
                Log.AddWarning(string.Format(LogMessages.XS_TYPE_TRANSLATED_AS_STRING, type, property.Class, property));
            }
            else
            {
                SimpleDataType simpleType = type as SimpleDataType;
                if (simpleType != null)
                {
                    if (!string.IsNullOrEmpty(simpleType.DefaultXSDImplementation))
                    {
                        if (simpleType.Parent != null)
                        {
                            //todo: simpleTypeWriter.WriteSimpleDataTypeDeclaration(simpleType);
                            targetElement.SetAttribute("type", simpleType.Name);
                        }
                        else
                        {
                            targetElement.SetAttribute("type", "xs" + ":" + simpleType.DefaultXSDImplementation);
                        }
                    }
                    else
                    {
                        if (type is SimpleDataType)
                        {
                            targetElement.SetAttribute("type", "xs" + ":" + type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                        else
                        {
                            targetElement.SetAttribute("type", type.Name);
                            Log.AddWarning(string.Format(LogMessages.XS_MISSING_TYPE_XSD, type));
                        }
                    }
                }
                else
                {
                    targetElement.SetAttribute("type", type.ToString());
                }
            }
            if (!String.IsNullOrEmpty(property.Default))
            {
                targetElement.SetAttribute("default", property.Default);
            }
            if (forceOptional)
            {
                targetElement.SetAttribute("use", "optional");
            }
            else
            {
                if (!useOccurs)
                {
                    if (property.Lower == 0 || property.Lower == null)
                    {
                        targetElement.SetAttribute("use", "optional");
                        if (property.Upper > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                    }
                    else
                    {
                        if (property.Upper > 1 || property.Lower > 1)
                        {
                            Log.AddWarning(string.Format(LogMessages.XS_ATTRIBUTE_MULTIPLICITY_LOST, property.MultiplicityString,
                                                         property.Class, property));
                        }
                        if (String.IsNullOrEmpty(property.Default))
                        {
                            targetElement.SetAttribute("use", "required");
                        }
                    }
                }
                else
                {
                    this.multiplicityAttributes(targetElement, property.Lower, property.Upper);
                }
            }
        }
Exemplo n.º 13
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;
            }
        }