Esempio n. 1
0
        /// <summary>
        /// Method calls <see cref="ICommand.CanExecute"/> on <paramref name="command"/>
        /// and displays the info box when the return value is false.
        /// </summary>
        /// <param name="command">command</param>
        /// <returns>value returned by <paramref name="command"/>.<see cref="ICommand.CanExecute"/></returns>
        public static bool CheckCanExecute(CommandBase command)
        {
            if (!command.CanExecute())
            {
                CommandCantExecuteDialog dialog = new CommandCantExecuteDialog();
                if (!String.IsNullOrEmpty(command.Description))
                {
                    dialog.tbCommand.Content = command.Description;
                }
                else
                {
                    dialog.tbCommand.Content = command.ToString();
                }

                dialog.tbExMsg.Content = String.Empty;
                dialog.tbExMsg.Content = command.ErrorDescription;

                dialog.ShowDialog();
                return(false);
            }
            return(true);
        }
Esempio n. 2
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. 3
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();
        }