public void Set(PSMAttribute attribute) { //Only PIMLess attributes if (attribute.RepresentedAttribute != null) { return; } ElementHolder <Property> AttributeHolder = new ElementHolder <Property>(); NewAttributeCommand c1 = NewAttributeCommandFactory.Factory().Create(Controller) as NewAttributeCommand; c1.createdAttributeHolder = AttributeHolder; c1.Owner = attribute.Class.RepresentedClass; c1.Lower = attribute.Lower; c1.Upper = attribute.Upper; c1.Default = attribute.Default; c1.Name = NameSuggestor <Property> .SuggestUniqueName(attribute.Class.RepresentedClass.Attributes, attribute.Name ?? attribute.Alias, property => property.Name); c1.Type = new ElementHolder <DataType>(attribute.Type); Commands.Add(c1); RenameElementCommand <Property> c2 = RenameElementCommandFactory <Property> .Factory().Create(Controller) as RenameElementCommand <Property>; c2.ContainingCollection = attribute.Class.Attributes; c2.RenamedElement = attribute; c2.NewName = c1.Name; Commands.Add(c2); PropagatePIMLessCommand c3 = PropagatePIMLessCommandFactory.Factory().Create(Controller) as PropagatePIMLessCommand; c3.Set(new ElementHolder <PSMAttribute>(attribute), AttributeHolder); Commands.Add(c3); }
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); }
public void AddNewAttribute(string attributeName, string newSimpleDataType, uint?lower, UnlimitedNatural?upper, string @default) { MacroCommand <ModelController> command = MacroCommandFactory <ModelController> .Factory().Create(DiagramController.ModelController); AddSimpleTypeCommand simpleTypeCommand = (AddSimpleTypeCommand)AddSimpleTypeCommandFactory.Factory().Create(DiagramController.ModelController); ElementHolder <DataType> type = new ElementHolder <DataType>(); simpleTypeCommand.CreatedSimpleType = type; command.Commands.Add(simpleTypeCommand); NewAttributeCommand attributeCommand = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController); if (!String.IsNullOrEmpty(attributeName)) { attributeCommand.Name = attributeName; } else { attributeCommand.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name); } attributeCommand.Type = type; attributeCommand.Lower = lower; attributeCommand.Upper = upper; attributeCommand.Default = @default; attributeCommand.Owner = Class; command.Commands.Add(attributeCommand); command.Execute(); }
internal override void CommandOperation() { if (Diagram == null) { Diagram = new PIMDiagram(NameSuggestor <PIMDiagram> .SuggestUniqueName(Project.PIMDiagrams, "PIM Diagram", diagram => diagram.Caption)); } Project.AddDiagram(Diagram); }
public override bool CanExecute() { if (!NameSuggestor <Diagram> .IsNameUnique(Project.Diagrams, NewCaption, diagram => diagram.Caption)) { ErrorDescription = String.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, NewCaption); return(false); } return(RenamedDiagram != null && NewCaption != null); }
protected override DragButtonData PrepareButtonData() { className = NameSuggestor <PIMClass> .SuggestUniqueName(ActiveDiagramView.Controller.ModelController.Model.Classes, "Class", modelClass => modelClass.Name); return(new DragButtonData(NewModelClassToDiagramCommandFactory.Factory(), new PIM_Class(ActiveDiagramView) { ElementName = className })); }
public override bool CanExecute() { if (!NameSuggestor <Operation> .IsNameUnique(Owner.Operations, Name, operation => operation.Name)) { ErrorDescription = String.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, Name); return(false); } return(true); }
public string GetName(Classifier varType) { string nameBase = varType.Name.ToLower()[0].ToString(); string result = NameSuggestor <string> .SuggestUniqueName(UsedNames, nameBase, item => item, true, false); UsedNames.Add(result); return(result); }
protected override DragButtonData PrepareButtonData() { text = NameSuggestor <Comment> .SuggestUniqueName(ActiveDiagramView.Controller.ModelController.Model.Comments, "Comment", comment => comment.Body); return(new DragButtonData(NewModelCommentaryToDiagramCommandFactory.Factory(), new XCaseComment(ActiveDiagramView) { CommentText = text })); }
public override bool CanExecute() { if (Name != SimpleDataType.Name) { return(NameSuggestor <DataType> .IsNameUnique(SimpleDataType.Package.OwnedTypes, Name, item => item.Name)); } else { return(true); } }
public override bool CanExecute() { if (CreatedPackage != null && CreatedPackage.Element != null) { if (!NameSuggestor <Package> .IsNameUnique(Package.NestedPackages, CreatedPackage.Element.Name, package => package.Name)) { ErrorDescription = String.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, CreatedPackage.Element.Name); return(false); } } return(true); }
public void AddNewAttribute() { NewAttributeCommand c = NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController) as NewAttributeCommand; c.Owner = AttributeHolder as IHasAttributes; c.Name = NameSuggestor <Property> .SuggestUniqueName(((IHasAttributes)AttributeHolder).Attributes, "Attribute", property => property.Name); if (c.CanExecute()) { c.Execute(); } }
internal override void CommandOperation() { if (CreatedComment == null) { CreatedComment = new ElementHolder <Comment>(); } CreatedComment.Element = AnnotatedElement.AddComment(NameSuggestor <Comment> .SuggestUniqueName(AnnotatedElement.Comments, "Comment", comment => comment.Body));; CreatedComment.Element.Body = Text; Debug.Assert(CreatedComment.HasValue); AssociatedElements.Add(CreatedComment.Element); }
/// <summary> /// Gets a unique name for global element. Adds record to <see cref="usedRootLabels"/>. /// The name is based upon <paramref name="psmClass"/>' <see cref="PSMClass.ElementName"/>. /// </summary> /// <param name="psmClass">The class for which the name is returned.</param> /// <returns>unique global element name</returns> public string GetNameForGlobalElement(PSMClass psmClass) { string normalized = NormalizeTypeName(psmClass, r => r.ElementName); string elementName = NameSuggestor <string> .SuggestUniqueName(usedRootLabels, normalized, item => item, true, false); if (elementName != normalized) { Log.AddWarning(string.Format(LogMessages.XS_DUPLICATE_ROOT_ELEMENTS, psmClass.ElementName, elementName)); } usedRootLabels.Add(elementName); return(elementName); }
private void OnAddAttributeClick(object sender, RoutedEventArgs e) { MenuItem m = sender as MenuItem; if (m.DataContext is Class) { NewAttributeCommand newAttributeCommand = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(project.GetModelController()); newAttributeCommand.Owner = m.DataContext as Class; newAttributeCommand.Name = NameSuggestor <Property> .SuggestUniqueName((newAttributeCommand.Owner as IHasAttributes).Attributes, "Attribute", property => property.Name); newAttributeCommand.Execute(); } }
public override bool CanExecute() { if (ContainingCollection != null) { if (NewName != RenamedElement.Name && NewName != "" && !NameSuggestor <ElementType> .IsNameUnique(ContainingCollection, NewName, element => element.Name)) { ErrorDescription = String.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, NewName); return(false); } } return(true); }
public override bool CanExecute() { if (OldPackage == NewPackage) { ErrorDescription = String.Format(CommandError.CMDERR_ADDING_PRESENT, MovedClass); return(false); } if (!NameSuggestor <PIMClass> .IsNameUnique(NewPackage.Classes, MovedClass.Name, modelClass => modelClass.Name)) { ErrorDescription = String.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, MovedClass.Name); return(false); } return(true); }
protected string GetTemplateName(string name) { string returns; if (NameSuggestor <string> .IsNameUnique(templateNames, name, S => S)) { returns = name; } else { returns = NameSuggestor <string> .SuggestUniqueName(templateNames, name, S => S); } templateNames.Add(returns); return(returns); }
public void AddNewAttribute(string attributeName) { NewAttributeCommand c = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController); if (!String.IsNullOrEmpty(attributeName)) { c.Name = attributeName; } else { c.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name); } c.Owner = Class; c.Execute(); }
private void TranslateScript(XElement schSchema, OCLScript oclScript, TranslationSettings translationSettings, ref Dictionary <PSMClass, List <PatternInfo> > patterns) { OclCompilerResult compilerResult = oclScript.CompileToAst(); compilerResult.CompileExpressionsInMessages(); if (!compilerResult.Errors.HasError) { XComment comment = new XComment(string.Format("Below follow constraints from OCL script '{0}'. ", oclScript.Name)); schSchema.Add(comment); foreach (ClassifierConstraintBlock classifierConstraintBlock in compilerResult.Constraints.ClassifierConstraintBlocks) { PSMClass contextClass = (PSMClass)classifierConstraintBlock.Context.Tag; patterns.CreateSubCollectionIfNeeded(contextClass); string patternName = NameSuggestor <PatternInfo> .SuggestUniqueName(patterns[contextClass], contextClass.Name, p => p.PatternName, true, false); PatternInfo patternInfo = new PatternInfo { PatternName = patternName }; XElement patternElement = schSchema.SchematronPattern(patternInfo.PatternName); patterns[contextClass].Add(patternInfo); bool abstractPattern = !contextClass.GeneralizationsAsGeneral.IsEmpty(); if (abstractPattern) { patternElement.AddAttributeWithValue("abstract", "true"); } string context = !abstractPattern?contextClass.GetXPathFull(true).ToString() : "$" + classifierConstraintBlock.Self.Name; XElement ruleElement = patternElement.SchematronRule(context); patternInfo.ContextVariableName = classifierConstraintBlock.Self.Name; if (!abstractPattern) { ruleElement.SchematronLet(patternInfo.ContextVariableName, @"."); } TranslateInvariantsToXPath(classifierConstraintBlock, ruleElement, (PSMBridge)compilerResult.Bridge, translationSettings); } } else { XComment comment = new XComment(string.Format("OCL script '{0}' contains errors and thus can not be translated. ", oclScript.Name)); schSchema.Add(comment); } }
public override bool CanExecute() { // Error messages missing if (Package == null) { return(false); } if (CreatedClass != null && CreatedClass.Element != null) { return(NameSuggestor <PIMClass> .IsNameUnique(Package.Classes, CreatedClass.Element.Name, modelClass => modelClass.Name)); } else { return(true); } }
public void AddNewOperation(string operationName) { NewOperationCommand c = (NewOperationCommand)NewOperationCommandFactory.Factory().Create(DiagramController.ModelController); if (!String.IsNullOrEmpty(operationName)) { c.Name = operationName; } else { c.Name = NameSuggestor <Operation> .SuggestUniqueName(Class.Operations, "Operation", operation => operation.Name); } c.Owner = Class; c.Execute(); }
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); }
protected string GetTemplateName(string prefix) { string returns; XNamespace ns = GetNamespace(prefix); string id = CutID(prefix); if (NameSuggestor <string> .IsNameUnique(templateNames, Namespaces[ns] + ":" + id, S => S)) { returns = Namespaces[ns] + ":" + id; } else { returns = NameSuggestor <string> .SuggestUniqueName(templateNames, Namespaces[ns] + ":" + id, S => S); } templateNames.Add(returns); return(returns); }
public override bool CanExecute() { if (Lower != null && Upper != null) { if (Lower > Upper) { ErrorDescription = CommandError.CMDERR_MULTIPLICITY_BAD_BOUNDS; return(false); } } if (!NameSuggestor <Property> .IsNameUnique(Owner.Attributes, Name, attribute => attribute.Name)) { ErrorDescription = String.Format(CommandError.CMDERR_NAME_NOT_UNIQUE, Name); return(false); } return(true); }
internal override void CommandOperation() { PSMAttribute psmAttribute; if (RepresentedAttribute != null) { psmAttribute = PSMClass.AddAttribute(RepresentedAttribute); psmAttribute.Lower = RepresentedAttribute.Lower; psmAttribute.Upper = RepresentedAttribute.Upper; } else { psmAttribute = PSMClass.AddAttribute((Property)null); if (!String.IsNullOrEmpty(Name)) { psmAttribute.Name = Name; } else if (!String.IsNullOrEmpty(Alias)) { psmAttribute.Name = Alias; } else { psmAttribute.Name = NameSuggestor <PSMAttribute> .SuggestUniqueName(PSMClass.PSMAttributes, "Attribute", a => a.AliasOrName); } psmAttribute.Type = Type; } psmAttribute.Alias = Alias; if (customMultiplicity) { psmAttribute.Lower = Lower; psmAttribute.Upper = Upper; } psmAttribute.Default = Default; AssociatedElements.Add(PSMClass); CreatedAttribute = psmAttribute; }
private void OnAddPackageClick(object sender, RoutedEventArgs e) { MenuItem m = sender as MenuItem; if (m.DataContext == null || m.DataContext is Package) { NewModelPackageCommand newPackageCommand = (NewModelPackageCommand)NewModelPackageCommandFactory.Factory().Create(project.GetModelController()); if (m.DataContext == null) { newPackageCommand.Package = model; } else { newPackageCommand.Package = m.DataContext as Package; } newPackageCommand.PackageName = NameSuggestor <Package> .SuggestUniqueName(newPackageCommand.Package.NestedPackages, "Package", package => package.Name); newPackageCommand.Execute(); nestedPackages.DataContext = null; } }
public void AddNewAttribute(string attributeName, DataType type, uint?lower, UnlimitedNatural?upper, string @default) { NewAttributeCommand c = (NewAttributeCommand)NewAttributeCommandFactory.Factory().Create(DiagramController.ModelController); if (!String.IsNullOrEmpty(attributeName)) { c.Name = attributeName; } else { c.Name = NameSuggestor <Property> .SuggestUniqueName(Class.Attributes, "Attribute", property => property.Name); } c.Type = new ElementHolder <DataType> { Element = type }; c.Lower = lower; c.Upper = upper; c.Default = @default; c.Owner = Class; c.Execute(); }
public override void Execute(object parameter) { Element element; MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller); command.Description = CommandDescription.ADD_OPERATION; foreach (ISelectable item in ActiveDiagramView.SelectedItems) { if (item is XCaseViewBase && (element = (item as XCaseViewBase).Controller.Element) is IHasOperations) { NewOperationCommand c = NewOperationCommandFactory.Factory().Create(ActiveDiagramView.Controller.ModelController) as NewOperationCommand; c.Owner = element as IHasOperations; c.Name = NameSuggestor <Operation> .SuggestUniqueName((element as IHasOperations).Operations, "Operation", property => property.Name); command.Commands.Add(c); } } if (command.Commands.Count > 0) { command.Execute(); } }
public override void Execute(object parameter) { Element element; MacroCommand <DiagramController> command = MacroCommandFactory <DiagramController> .Factory().Create(ActiveDiagramView.Controller); command.Description = CommandDescription.ADD_PSM_ATTRIBUTE; foreach (ISelectable item in ActiveDiagramView.SelectedItems) { if (item is PSM_Class && (element = (item as PSM_Class).Controller.Element) is PSMClass) { AddPSMClassAttributeCommand c = AddPSMClassAttributeCommandFactory.Factory().Create(ActiveDiagramView.Controller) as AddPSMClassAttributeCommand; c.PSMClass = (PSMClass)element; c.Name = NameSuggestor <PSMAttribute> .SuggestUniqueName(((PSMClass)element).PSMAttributes, "FreeAttribute", property => property.AliasOrName); command.Commands.Add(c); } } if (command.Commands.Count > 0) { command.Execute(); } }