/// <summary> /// Removes all decisions from the table and diagram /// </summary> private void RemoveAllDecisionsFromDiagram() { IEARepository repository = EAMain.Repository; string diagramGuid = _controller.Model.DiagramGUID; IEADiagram diagram = repository.GetDiagramByGuid(diagramGuid); for (int i = ForcesTableContext.DecisionColumnIndex; i < _forcesTable.Columns.Count; i++) { string decisionGuid = _forcesTable.Rows[_forcesTable.Rows.Count - 1].Cells[i].Value.ToString(); IEAElement decision = EAMain.Repository.GetElementByGUID(decisionGuid); RemoveDecisionFromDiagram(decision); } _controller.SetDiagramModel(diagram); }
private void RemoveAllForcesFromDiagram() { for (int i = _forcesTable.Rows.Count - 1; i >= 0; i--) { if (_forcesTable.Rows[i].Cells[ForcesTableContext.ForceGUIDColumnIndex].Value.Equals(ForcesTableContext.EmptyCellValue)) { continue; } RemoveForceFromDiagram(i); } IEARepository repository = EAFacade.EA.Repository; _controller.SetDiagramModel(repository.GetDiagramByGuid(_controller.Model.DiagramGUID)); }
/// <summary> /// Removes a decision from the table and diagram /// </summary> /// <param name="decision">The element to be removed</param> private void RemoveDecisionFromDiagram(IEAElement decision) { IEARepository repository = EAFacade.EA.Repository; string diagramGuid = _controller.Model.DiagramGUID; IEADiagram diagram = repository.GetDiagramByGuid(diagramGuid); //Remove the TaggedValue of the decision decision.RemoveTaggedValue(EATaggedValueKeys.IsDecisionElement, diagramGuid); //Delete the element if it is not used in the diagram/table anymore if (!ElementExistsInDiagram(decision, diagramGuid)) { diagram.RemoveElement(decision); } }
/// <summary> /// Removes a force/concern from the table and diagram (if necessary). Diagram should be update afterwards /// </summary> /// <param name="rowIndex">The element to be removed</param> private void RemoveForceFromDiagram(int rowIndex) { //Get the GUIDs from the diagram, force and concern string diagramGuid = _controller.Model.DiagramGUID; string forceGuid = _forcesTable.Rows[rowIndex].Cells[ForcesTableContext.ForceGUIDColumnIndex].Value.ToString(); string concernGuid = _forcesTable.Rows[rowIndex].Cells[ForcesTableContext.ConcernGUIDColumnIndex].Value.ToString(); //Get the diagram, force and concern objects IEARepository repository = EAMain.Repository; IEADiagram diagram = repository.GetDiagramByGuid(diagramGuid); IEAElement force = repository.GetElementByGUID(forceGuid); IEAElement concern = repository.GetElementByGUID(concernGuid); foreach ( IEAConnector connector in force.FindConnectors(concern, EAConstants.RelationClassifiedBy, EAConstants.ForcesConnectorType)) { if (connector.TaggedValueExists(EATaggedValueKeys.IsForceConnector, diagramGuid)) { connector.RemoveTaggedValue(EATaggedValueKeys.IsForceConnector, diagramGuid); if (!connector.TaggedValueExists(EATaggedValueKeys.IsForceConnector)) { force.RemoveConnector(connector); concern.RemoveConnector(connector); } break; } } //Remove the TaggedValue of the force and concern force.RemoveTaggedValue(EATaggedValueKeys.IsForceElement, diagramGuid); concern.RemoveTaggedValue(EATaggedValueKeys.IsConcernElement, diagramGuid); //Delete the element if it is not used in the diagram/table anymore if (!ElementExistsInDiagram(force, diagramGuid)) { diagram.RemoveElement(force); } if (!ElementExistsInDiagram(concern, diagramGuid)) { diagram.RemoveElement(concern); } }
/// <summary> /// Defines MenuItems for a right click on a column's header /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _forcesTable_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { //Only for decisions if (e.ColumnIndex < ForcesTableContext.DecisionColumnIndex) { return; } string elementGuid = _forcesTable.Rows[_forcesTable.Rows.Count - 1].Cells[e.ColumnIndex].Value.ToString(); IEAElement decision = EAFacade.EA.Repository.GetElementByGUID(elementGuid); if (e.Button == MouseButtons.Right) { var menu = new ContextMenu(); // Menuitem for opening a decision in its diagram menu.MenuItems.Add(Messages.ForcesViewOpenDecisionInDiagrams, (o, args) => OpenDecisionInDiagrams(decision)); // Menuitem for opening the detailviewpoint of a decision menu.MenuItems.Add(Messages.ForcesViewOpenDecisionInDetailView, (sender1, e1) => OpenInDetailView(new Decision(decision))); // Menuitem for a separator menu.MenuItems.Add("-"); // Menuitem for removing a decision menu.MenuItems.Add(Messages.ForcesViewRemoveDecision, (sender1, e1) => { RemoveDecisionFromDiagram(decision); IEARepository repository = EAFacade.EA.Repository; _controller.SetDiagramModel(repository.GetDiagramByGuid(_controller.Model.DiagramGUID)); }); // Meneitem for removing all decision menu.MenuItems.Add(Messages.ForcesViewRemoveAllDecisions, (sender1, e1) => RemoveAllDecisionsFromDiagram()); Point relativeMousePosition = PointToClient(Cursor.Position); menu.Show(this, relativeMousePosition); } }
public override bool OnContextItemDoubleClicked(string guid, EANativeType type) { if (EANativeType.Diagram != type) { return(false); } IEARepository repository = EAMain.Repository; IEADiagram diagram = repository.GetDiagramByGuid(guid); if (!diagram.IsForcesView()) { return(false); } var forcesDiagramModel = new ForcesModel(diagram); if (repository.IsTabOpen(forcesDiagramModel.Name) > 0) { // naming is not optimal as tabs can have same names... need to find a solution that we can // distinguish tabs more optimal repository.ActivateTab(forcesDiagramModel.Name); return(true); } IForcesView forcesView = repository.AddTab(forcesDiagramModel.Name, "DecisionViewpoints.Forces"); IForcesController forcesController; if (!_controllers.ContainsKey(forcesDiagramModel.DiagramGUID)) { forcesController = new ForcesController(forcesView, forcesDiagramModel); _controllers.Add(forcesDiagramModel.DiagramGUID, forcesController); } else { forcesController = _controllers[forcesDiagramModel.DiagramGUID]; forcesController.View = forcesView; forcesController.Model = forcesDiagramModel; } forcesController.Update(); return(true); }
/// <summary> /// Defines MenuItems for right clicking on a row's header /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void _forcesTable_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { var menu = new ContextMenu(); // Menuitem for removing a force menu.MenuItems.Add(Messages.ForcesViewRemoveForce, (sender1, e1) => { RemoveForceFromDiagram(e.RowIndex); IEARepository repository = EAFacade.EA.Repository; _controller.SetDiagramModel(repository.GetDiagramByGuid(_controller.Model.DiagramGUID)); }); // Menuitem for removing all forces menu.MenuItems.Add(Messages.ForcesViewRemoveAllForces, (sender1, e1) => RemoveAllForcesFromDiagram()); Point relativeMousePosition = PointToClient(Cursor.Position); menu.Show(this, relativeMousePosition); } }
/// <summary> /// Adds the element(s) that is/are selected in the TreeView to the forces diagram /// </summary> public void AddAllDecisionsToDiagram() { TreeNode selectedNode = _tvDecision.SelectedNode; if (selectedNode == null) { return; //nothing selected } AddFromNode(selectedNode); //Window does not have to be closed and no update needed if (!_closeWindow) { return; } IEARepository repository = EAFacade.EA.Repository; _controller.SetDiagramModel(repository.GetDiagramByGuid(_controller.Model.DiagramGUID)); DialogResult = DialogResult.OK; }
/// <summary> /// Remove the concern from the ForcesView (Will remove the force with the concern) /// </summary> /// <param name="element"></param> public void RemoveConcern(IEAElement element) { for (int i = _forcesTable.Rows.Count - 1; i >= 0; i--) { //Skip other elements if (_forcesTable.Rows[i].Cells[ForcesTableContext.ConcernGUIDColumnIndex].Value.Equals(ForcesTableContext.EmptyCellValue)) { continue; } if ( !_forcesTable.Rows[i].Cells[ForcesTableContext.ConcernGUIDColumnIndex].Value.ToString() .Equals(element.GUID)) { continue; } RemoveForceFromDiagram(i); } IEARepository repository = EAFacade.EA.Repository; _controller.SetDiagramModel(repository.GetDiagramByGuid(_controller.Model.DiagramGUID)); }
/// <summary> /// Add deicsion to the diagram and TaggedValue to the decision if it doesn't exist already /// </summary> /// <param name="element"></param> private void AddDecisionToDiagram(IEAElement element) { IEARepository repository = EAFacade.EA.Repository; string diagramGuid = _controller.Model.DiagramGUID; IEADiagram diagram = repository.GetDiagramByGuid(diagramGuid); diagram.AddElement(element); // Only add the TaggedValue once, because the element is already a decision if (!element.TaggedValueExists(EATaggedValueKeys.IsDecisionElement, diagramGuid)) { element.AddTaggedValue(EATaggedValueKeys.IsDecisionElement, diagramGuid); _closeWindow = true; } else { MessageBox.Show(string.Format(Messages.ForcesViewDecisionExists, element.Name), "Decision already exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public override void OnNotifyContextItemModified(string guid, EANativeType type) { IEARepository repository = EAMain.Repository; IForcesController forcesController; switch (type) { // the diagram is modified when we remove an element or a connector from it case EANativeType.Diagram: IEADiagram diagram = repository.GetDiagramByGuid(guid); if (!diagram.IsForcesView()) { return; } // if the name of a diagram changed and the forces tab is open then close it to avoid conflicts if (repository.IsTabOpen(ForcesModel.CreateForcesTabName(diagram.Name)) <= 0) { if (!_controllers.ContainsKey(diagram.GUID)) { break; } forcesController = _controllers[diagram.GUID]; if (repository.IsTabOpen(forcesController.Model.Name) > 0) { repository.RemoveTab(forcesController.Model.Name); } break; } if (!_controllers.ContainsKey(diagram.GUID)) { break; } forcesController = _controllers[diagram.GUID]; forcesController.SetDiagramModel(diagram); break; case EANativeType.Element: IEAElement element = repository.GetElementByGUID(guid); foreach ( IEADiagram eaDiagram in element.GetDiagrams() .Where(eaDiagram => eaDiagram.IsForcesView()) .Where(eaDiagram => _controllers.ContainsKey(eaDiagram.GUID))) { forcesController = _controllers[eaDiagram.GUID]; // An element can be of multiple types: if (element.TaggedValueExists(EATaggedValueKeys.IsDecisionElement, eaDiagram.GUID)) { forcesController.UpdateDecision(element); } if (element.TaggedValueExists(EATaggedValueKeys.IsConcernElement, eaDiagram.GUID)) { forcesController.UpdateConcern(element); } if (element.TaggedValueExists(EATaggedValueKeys.IsForceElement, eaDiagram.GUID)) { forcesController.UpdateForce(element); } } break; } }