/// <summary> /// Edits a value expression and provides the edited expression after user has performed his changes /// </summary> /// <param name="expression"></param> /// <returns></returns> private Expression EditExpression(Expression expression) { Expression retVal = expression; if (expression != null) { ModelElement.DontRaiseError(() => { InterpretationContext context = new InterpretationContext(Model) { UseDefaultValue = false }; IValue value = expression.GetExpressionValue(context, null); if (value != null) { StructureEditor.Window window = new StructureEditor.Window(); window.SetModel(value); window.ShowDialog(); string newExpression = value.ToExpressionWithDefault(); const bool doSemanticalAnalysis = true; const bool silent = true; retVal = new Parser().Expression(expression.Root, newExpression, AllMatches.INSTANCE, doSemanticalAnalysis, null, silent); } }); } return(retVal); }
private void openStructureEditorToolStripMenuItem_Click(object sender, EventArgs e) { bool dialogShown = false; ExplanationPart part = Instance as ExplanationPart; if (part != null) { IValue value = part.RightPart as IValue; if (value != null) { StructureEditor.Window window = new StructureEditor.Window(); window.SetModel(value); window.ShowDialog(); dialogShown = true; } Action action = part.Element as Action; if (!dialogShown && action != null) { VisitStatement(action.Statement); dialogShown = true; } Expectation expectation = part.Element as Expectation; if (!dialogShown && expectation != null) { VisitExpression(expectation.Expression); dialogShown = true; } } if (!dialogShown) { const bool doSemanticalAnalysis = true; const bool silent = true; ModelElement root = Instance as ModelElement; if (root == null) { root = EfsSystem.Instance.Dictionaries[0]; } string text = EditionTextBox.Text; Expression expression = new Parser().Expression(root, text, AllMatches.INSTANCE, doSemanticalAnalysis, null, silent); if (expression != null) { expression = VisitExpression(expression); EditionTextBox.Text = expression.ToString(); } Statement statement = new Parser().Statement(root, text, silent); if (statement != null) { statement = VisitStatement(statement); EditionTextBox.Text = statement.ToString(); } } }
/// <summary> /// Sets the string value into the right property /// </summary> /// <param name="instance"></param> /// <param name="value"></param> private void HandleTextChange(ModelElement instance, string value) { ICommentable commentable = instance as ICommentable; if (commentable != null) { commentable.Comment = value; } }
/// <summary> /// Sets the string value into the right property /// </summary> /// <param name="instance"></param> /// <param name="value"></param> private void HandleTextChange(ModelElement instance, string value) { IDefaultValueElement defaultValueElement = instance as IDefaultValueElement; if (defaultValueElement != null) { defaultValueElement.Default = value; } }
/// <summary> /// Constructor /// </summary> public MarkAsVerifiedVisitor(IModelElement element) { ModelElement modelElement = element as ModelElement; if (modelElement != null) { visit(modelElement, true); } }
/// <summary> /// Sets the string value into the right property /// </summary> /// <param name="instance"></param> /// <param name="value"></param> private void HandleTextChange(ModelElement instance, string value) { ITypedElement typedElement = instance as ITypedElement; if (typedElement != null) { typedElement.TypeName = value; } }
/// <summary> /// Constructor /// </summary> /// <param name="model"></param> /// <param name="searchString"></param> /// <param name="replaceString"></param> public SearchAndReplaceVisitor(IModelElement model, string searchString, string replaceString) { ReplaceString = replaceString; SearchString = searchString; ModelElement modelElement = model as ModelElement; if (modelElement != null) { visit(modelElement, true); } }
/// <summary> /// Ensures that the string provided is a type /// </summary> /// <param name="text"></param> /// <param name="instance"></param> /// <returns></returns> public override bool AdditionalCheck(string text, ModelElement instance) { bool retVal = base.AdditionalCheck(text, instance); if (retVal && instance != null) { Expression expression = instance.EFSSystem.Parser.Expression(instance, text, IsValue.INSTANCE, true, null, true); retVal = (expression != null && expression.Ref is EnumValue); } return retVal; }
/// <summary> /// Sets the string value into the right property /// </summary> /// <param name="instance"></param> /// <param name="value"></param> private void HandleTextChange(ModelElement instance, string value) { IVariable variable = instance as IVariable; if (variable != null && variable.Type != null) { IValue val = variable.Type.getValue(value); if (value != null) { variable.Value = val; } } }
/// <summary> /// Checks the node /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Check(object sender, EventArgs e) { MarkingHistory.PerformMark(() => { ModelElement modelElement = Model as ModelElement; if (modelElement != null) { RuleCheckerVisitor visitor = new RuleCheckerVisitor(modelElement.Dictionary); visitor.visit(modelElement, true); } }); }
/// <summary> /// Refreshed the requirements according to the DisplayedModel /// </summary> private void RefreshRequirements() { ModelElement model = DisplayedModel as ModelElement; if (model != null) { richTextBox.Text = model.RequirementDescription(); } else { richTextBox.Text = ""; } }
/// <summary> /// Ensures that the string provided is a type /// </summary> /// <param name="text"></param> /// <param name="instance"></param> /// <returns></returns> public override bool AdditionalCheck(string text, ModelElement instance) { bool retVal = base.AdditionalCheck(text, instance); if (retVal && instance != null) { Expression expression = new Parser().Expression(instance, text, IsType.INSTANCE, true, null, true); retVal = (expression != null && expression.Ref != null) && !(expression.Ref is Function); } return retVal; }
/// <summary> /// Marks the item as removed from the model. The tool will treat it as if it was deleted. /// </summary> protected void RemoveInUpdate(object sender, EventArgs args) { ModelElement model = Item as ModelElement; if (model != null && model.Updates == null) { model = FindOrCreateUpdate(); } if (model != null) { model.setIsRemoved(true); } }
/// <summary> /// Sets the more information according to the displayed model /// </summary> private void SetMoreInfo() { ModelElement.DontRaiseError(() => { moreInfoRichTextBox.Text = ""; ITextualExplain textualExplain = DisplayedModel as ITextualExplain; if (textualExplain != null) { moreInfoRichTextBox.Instance = DisplayedModel; moreInfoRichTextBox.Text = TextualExplanationUtils.GetText(textualExplain, true); } Refresh(); }); }
/// <summary> /// Provides the arrow control which corresponds to the rule /// </summary> /// <param name="referencedModel"></param> /// <returns></returns> public ArrowControl <TEnclosing, TBoxModel, TArrowModel> GetArrowControl(ModelElement referencedModel) { ArrowControl <TEnclosing, TBoxModel, TArrowModel> retVal = null; foreach (ArrowControl <TEnclosing, TBoxModel, TArrowModel> control in _arrows.Values) { if (control.TypedModel.ReferencedModel == referencedModel) { retVal = control; break; } } return(retVal); }
/// <summary> /// Provides the dictionary on which operation should be performed /// </summary> /// <returns></returns> public Dictionary GetPatchDictionary() { Dictionary retVal = null; MainWindow mainWindow = GuiUtils.MdiWindow; EfsSystem efsSystem = mainWindow.EfsSystem; if (efsSystem != null) { ModelElement modelElement = Item as ModelElement; if (modelElement != null) { int updates = 0; foreach (Dictionary dict in efsSystem.Dictionaries) { if (modelElement.Dictionary.IsUpdatedBy(dict)) { // Set retVal to the update in case it is the only one for the base dictionary retVal = dict; updates++; } } if (updates == 0) { MessageBox.Show("No updates loaded for the current dictionary."); } if (updates > 1) { // if there are 0 or 1 possible updates, it will already have the correct value // if there are more, choose the update from a list of possibilities DictionarySelector.DictionarySelector dictionarySelector = new DictionarySelector.DictionarySelector(FilterOptions.Updates, modelElement.Dictionary); dictionarySelector.ShowDictionaries(mainWindow); if (dictionarySelector.Selected != null) { retVal = dictionarySelector.Selected; } } } } return(retVal); }
/// <summary> /// Applies the effect of an element update /// </summary> /// <param name="updateElement">The updated version of the structure element</param> /// <param name="collection">The collection in the structure that will hold the updated element</param> private void ApplyElementUpdate(ModelElement updateElement, ArrayList collection) { // Remove the redefined structure element ModelElement baseElement = updateElement.Updates; if (baseElement != null) { ArrayList temp = new ArrayList(); foreach (ModelElement elem in collection) { if (elem.Name != baseElement.Name) { temp.Add(elem); } } collection = temp; } // If the element was updated and not removed, replace it in the baseStructure if (!updateElement.IsRemoved) { AddModelElement(updateElement); } }
/// <summary> /// Constructor /// </summary> /// <param name="model">The model element to be found</param> public ReferenceVisitor(ModelElement model) { Usages = new List<Usage>(); Model = model; Filter = null; }
/// <summary> /// Provides the display attributes for a model event /// </summary> /// <param name="evt"></param> /// <returns></returns> private EventDisplayAttributes GetDisplayAttributes(ModelEvent evt) { EventDisplayAttributes retVal = new EventDisplayAttributes(Color.White, new Pen(Color.Black), "<undefined>", null, null, null); ModelElement.DontRaiseError(() => { Expect expect = evt as Expect; if (expect != null) { string name = GuiUtils.AdjustForDisplay(ShortName(expect.Expectation.Name), _eventSize.Width - 4, BottomFont); switch (expect.State) { case Expect.EventState.Active: retVal = new EventDisplayAttributes(Color.Violet, new Pen(Color.Black), name, Images.Images[QuestionMarkImageIndex], NameSpaceImages.Instance.GetImage(expect.Expectation), null); break; case Expect.EventState.Fullfilled: retVal = new EventDisplayAttributes(Color.LightGreen, new Pen(Color.Green), name, Images.Images[SuccessImageIndex], NameSpaceImages.Instance.GetImage(expect.Expectation), null); break; case Expect.EventState.TimeOut: retVal = new EventDisplayAttributes(Color.Red, new Pen(Color.DarkRed), name, Images.Images[ErrorImageIndex], NameSpaceImages.Instance.GetImage(expect.Expectation), null); break; } if (expect.Expectation.getKind() == acceptor.ExpectationKind.aContinuous) { retVal.TopRightIconImage.Add(Images.Images[CircularArrowIndex]); } if (expect.Expectation.Blocking) { retVal.TopRightIconImage.Add(Images.Images[DownArrowIndex]); } } ModelInterpretationFailure modelInterpretationFailure = evt as ModelInterpretationFailure; if (modelInterpretationFailure != null) { string name = GuiUtils.AdjustForDisplay(modelInterpretationFailure.Message, _eventSize.Width - 4, BottomFont); retVal = new EventDisplayAttributes(Color.Red, new Pen(Color.DarkRed), name, Images.Images[ErrorImageIndex], NameSpaceImages.Instance.GetImage(modelInterpretationFailure.Instance as ModelElement), null); } RuleFired ruleFired = evt as RuleFired; if (ruleFired != null) { string name = GuiUtils.AdjustForDisplay(ShortName(ruleFired.RuleCondition.Name), _eventSize.Width - 4, BottomFont); retVal = new EventDisplayAttributes(Color.LightBlue, new Pen(Color.Blue), name, null, NameSpaceImages.Instance.GetImage(ruleFired.RuleCondition), Images.Images[ToolsImageIndex]); } VariableUpdate variableUpdate = evt as VariableUpdate; if (variableUpdate != null) { string name = variableUpdate.Action.ExpressionText; Image rightIcon = null; Image rightModifier = null; if (variableUpdate.Action.Statement != null) { name = variableUpdate.Action.Statement.ShortShortDescription(); rightIcon = NameSpaceImages.Instance.GetImage(variableUpdate.Action.Statement.AffectedElement()); switch (variableUpdate.Action.Statement.UsageDescription()) { case Statement.ModeEnum.Call: rightModifier = Images.Images[CallImageIndex]; break; case Statement.ModeEnum.In: rightModifier = Images.Images[InImageIndex]; break; case Statement.ModeEnum.InOut: rightModifier = Images.Images[InOutImageIndex]; break; case Statement.ModeEnum.Internal: rightModifier = Images.Images[InternalImageIndex]; break; case Statement.ModeEnum.Out: rightModifier = Images.Images[OutImageIndex]; break; } } name = GuiUtils.AdjustForDisplay(ShortName(name), _eventSize.Width - 4, BottomFont); NameSpace nameSpace = EnclosingFinder <NameSpace> .find(variableUpdate.Action); if (nameSpace == null) { retVal = new EventDisplayAttributes(Color.LightGray, new Pen(Color.Black), name, null, rightIcon, rightModifier); } else { retVal = new EventDisplayAttributes(Color.BlanchedAlmond, new Pen(Color.Black), name, null, rightIcon, rightModifier); } } SubStepActivated subStepActivated = evt as SubStepActivated; if (subStepActivated != null) { retVal = new EventDisplayAttributes(Color.LightGray, new Pen(Color.Black), "SubStep", null, null, null); } }); return(retVal); }
/// <summary> /// Provides the namespace of the element provided in this container /// </summary> /// <param name="source">The element from which the namespace should be found</param> /// <param name="container">The container which contains the namespace</param> /// <param name="allowOutsideContainer">Indicaes that namespace can be found outside of the container</param> /// <returns></returns> private static NameSpace getCorrespondingNameSpace(ModelElement source, IEnclosesNameSpaces container, bool allowOutsideContainer) { NameSpace retVal = null; IEnclosed current = source; while (current != null && retVal == null) { NameSpace nameSpace = EnclosingNameSpaceFinder.find(current); if (container == null || container.NameSpaces.Contains(nameSpace)) { retVal = nameSpace; } current = nameSpace; } // If no name space has been found in the container, take the first one if (retVal == null && allowOutsideContainer) { retVal = EnclosingNameSpaceFinder.find(source); } return retVal; }
/// <summary> /// Constructor /// </summary> /// <param name="model"></param> /// <param name="newName"></param> /// <param name="refresh"></param> public RefactorOperation(ModelElement model, string newName, bool refresh = true) { Model = model; NewName = newName; Refresh = refresh; }
/// <summary> /// Ensures that the traceability of merged elements is updated correctly /// </summary> /// <param name="source"></param> protected override void UpdateModelElementAccordingToSource(ModelElement source) { base.UpdateModelElementAccordingToSource(source); KeepTraceability(source); }
/// <summary> /// Process a regular expression. /// </summary> /// <param name="textBox"></param> /// <param name="instance"></param> /// <param name="start">The start index of the line</param> /// <param name="line">The line to be processed</param> /// <param name="colorizedLocations">The location where coloring already occured</param> public void Colorize(SyntaxRichTextBox textBox, ModelElement instance, int start, string line, List<ColorizedLocation> colorizedLocations) { Font font = new Font(textBox.Font, FontStyle); foreach (Match match in RegExp.Matches(line)) { if (CheckLocation(match, colorizedLocations)) { if (AdditionalCheck(match.Value, instance)) { colorizedLocations.Add(new ColorizedLocation { Start = match.Index, End = match.Index + match.Length }); textBox.SelectionStart = start + match.Index; textBox.SelectionLength = match.Length; textBox.SelectionColor = Color; textBox.SelectionFont = font; } } } }
/// <summary> /// Checks that the provided message part is present in the model element messages /// </summary> /// <param name="model"></param> /// <param name="messagePart"></param> protected bool HasMessagePart(ModelElement model, string messagePart) { bool retVal = false; foreach (ElementLog log in model.Messages) { if (log.Log.Contains(messagePart)) { retVal = true; break; } } return retVal; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> public ParagraphTextChangeHandler(ModelElement instance) : base(instance, "Requirement") { }
/// <summary> /// Creates an update for the reqref. Used to delete references in an update. /// </summary> /// <param name="modelUpdate"></param> /// <returns></returns> public ReqRef CreateReqRefUpdate(ModelElement modelUpdate) { ReqRef retVal = (ReqRef) Duplicate(); retVal.setUpdates(Guid); ReqRelated reqRelatedUpdate = modelUpdate as ReqRelated; if (reqRelatedUpdate != null) { reqRelatedUpdate.appendRequirements(retVal); } return retVal; }
/// <summary> /// Constructor /// </summary> /// <param name="model"></param> public RefactorAndRelocateOperation(ModelElement model) { Model = model; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> /// <param name="expression"></param> public WatchedExpression(ModelElement instance, string expression) { Instance = instance; Expression = expression; }
/// <summary> /// Provides the name of this model element when accessing it from the other model element (provided as parameter) /// </summary> /// <param name="user"></param> /// <returns></returns> public override string ReferenceName(ModelElement user) { string retVal = Name; return retVal; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> public TypeTextChangeHandler(ModelElement instance) : base(instance, "Type") { }
/// <summary> /// Accepts the drop of a base tree node on this node /// </summary> /// <param name="sourceNode"></param> public virtual void AcceptCopy(BaseTreeNode sourceNode) { try { ModelElement modelElement = sourceNode.Model as ModelElement; if (modelElement != null) { ModelElement copy = modelElement.Duplicate(); if (copy != null) { DataDictionary.Util.DontNotify(() => { // Trick : This is used to know the enclosing collection in the target Model.AddModelElement(copy); ArrayList targetCollection = copy.EnclosingCollection; copy.Delete(); // End of trick if (targetCollection != null) { int previousIndex = -1; int index = 0; while (previousIndex != index) { previousIndex = index; foreach (INamable other in targetCollection) { if (index > 0) { if (other.Name.Equals(copy.Name + "_" + index)) { index += 1; break; } } else { if (other.Name.Equals(copy.Name)) { index += 1; break; } } } } // Renaming is mandatory if (index > 0) { copy.Name = copy.Name + "_" + index; } } }); Model.AddModelElement(copy); } } } catch (Exception) { MessageBox.Show("Cannot copy element\n"); } }
/// <summary> /// Parses the statement provided /// </summary> /// <param name="root">the root element for which this statement is created</param> /// <param name="expression"></param> /// <returns></returns> public Statement ParseStatement(ModelElement root, string expression) { return new Parser().Statement(root, expression); }
/// <summary> /// Constructor /// </summary> /// <param name="reference"></param> public HistoryObject(ModelElement reference) { Reference = reference; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> /// <param name="expression"></param> public WatchedExpression(ModelElement instance, string expression) { Instance = instance; Expression = expression; }
/// <summary> /// Copy traceability information from the element provided in parameter (source) to the current one (target) /// Do the union between traceability information /// </summary> /// <param name="source"></param> protected void KeepTraceability(ModelElement source) { ReqRelated reqSource = source as ReqRelated; if (reqSource != null) { foreach (ReqRef sourceReqRef in reqSource.Requirements) { bool isPresent = false; foreach (ReqRef reqRef in Requirements) { if (sourceReqRef.Paragraph.SourceOfUpdateChain == reqRef.Paragraph.SourceOfUpdateChain) { isPresent = true; break; } } if (!isPresent) { Requirements.Add(sourceReqRef.Duplicate()); } } } }
/// <summary> /// Tokenizes a single line /// </summary> /// <param name="instance"></param> /// <param name="line"></param> /// <param name="textParts"></param> /// <param name="colorizedLocations"></param> public void TokenizeLine(ModelElement instance, string line, List<TextPart> textParts, List<ColorizedLocation> colorizedLocations) { foreach (Match match in RegExp.Matches(line)) { if (CheckLocation(match, colorizedLocations)) { if (AdditionalCheck(match.Value, instance)) { colorizedLocations.Add(new ColorizedLocation { Start = match.Index, End = match.Index + match.Length }); textParts.Add(new TextPart(match.Index, match.Length, Color, HighlightFont)); } } } }
/// <summary> /// Performs additional checks on the string provided /// </summary> /// <param name="text"></param> /// <param name="instance"></param> /// <returns></returns> public virtual bool AdditionalCheck(string text, ModelElement instance) { return true; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> /// <param name="identifyingMessage"></param> protected HandleTextChange(ModelElement instance, string identifyingMessage) { Instance = instance; IdentifyingMessage = identifyingMessage; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> /// <param name="watch"></param> /// <param name="columnName"></param> public TextChangeHandler(ModelElement instance, WatchedExpression watch, string columnName) : base(instance, "Watch") { Watch = watch; ColumnName = columnName; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> public CommentableTextChangeHandler(ModelElement instance) : base(instance, "Comment") { }
/// <summary> /// Provides an error message found in the model, or one of its sub elements, if any /// </summary> /// <param name="model"></param> protected ElementLog ErrorMessage(ModelElement model) { ErrorMessageVisitor visitor = new ErrorMessageVisitor(); visitor.visit(model, true); return visitor.ErrorMessageFound; }
/// <summary> /// Provides the list of references of a given model element /// </summary> /// <param name="model"></param> /// <returns></returns> public List<Usage> FindReferences(ModelElement model) { List<Usage> retVal; if (model != null) { // Find references ReferenceVisitor visitor = new ReferenceVisitor(model); ModelElement.DontRaiseError(() => { foreach (Dictionary dictionary in Dictionaries) { visitor.visit(dictionary, true); } visitor.Usages.Sort(); }); retVal = visitor.Usages; foreach (Usage usage in retVal) { // It has not been proven that it is something else than Read // Let's consider it is read if (usage.Mode == null) { usage.Mode = Usage.ModeEnum.Read; } } } else { retVal = new List<Usage>(); } return retVal; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> /// <param name="watch"></param> /// <param name="columnName"></param> public TextChangeHandler(ModelElement instance, WatchedExpression watch, string columnName) : base(instance, "Watch") { Watch = watch; ColumnName = columnName; }
/// <summary> /// Constructor /// </summary> /// <param name="instance"></param> public DefaultValueTextChangeHandler(ModelElement instance) : base(instance, "Default value") { }