Пример #1
0
        private void SaveRelations(IEAElement element)
        {
            IEARepository        repository = EAMain.Repository;
            IEnumerable <string> deleted    =
                element.FindConnectors(EAConstants.RelationMetaType, EAConstants.RelationDependsOn,
                                       EAConstants.RelationExcludedBy, EAConstants.RelationCausedBy,
                                       EAConstants.RelationReplaces)
                .Select(c => c.GUID)
                .Except(RelatedDecisions.Select(a => a.RelationGUID));

            foreach (string connector in deleted)
            {
                element.RemoveConnector(repository.GetConnectorByGUID(connector));
            }

            foreach (IDecisionRelation connector in RelatedDecisions)
            {
                if ("".Equals(connector.RelationGUID) || null == connector.RelationGUID)
                {
                    IEAElement client   = repository.GetElementByGUID(connector.Decision.GUID);
                    IEAElement supplier = repository.GetElementByGUID(connector.RelatedDecision.GUID);
                    client.ConnectTo(supplier, EAConstants.RelationMetaType, connector.Type);
                }
            }
        }
Пример #2
0
        private void SaveStakeholders(IEAElement element)
        {
            IEARepository        repository = EAMain.Repository;
            IEnumerable <string> deleted    =
                element.GetConnectors().Where(connector => connector.IsAction() && connector.ClientId != element.ID)
                .Select(c => c.GUID)
                .Except(Stakeholders.Select(a => a.ConnectorGUID));

            foreach (string connector in deleted)
            {
                element.RemoveConnector(repository.GetConnectorByGUID(connector));
            }

            foreach (IStakeholderAction connector in Stakeholders)
            {
                if ("".Equals(connector.ConnectorGUID) || null == connector.ConnectorGUID && !connector.DoDelete)
                {
                    var client   = repository.GetElementByGUID(GUID);
                    var supplier = repository.GetElementByGUID(connector.Stakeholder.GUID);
                    supplier.ConnectTo(client, EAConstants.ActionMetaType, connector.Action);
                }
                else if (connector.ConnectorGUID != null && connector.DoDelete)
                {
                    var supplier = repository.GetElementByGUID(connector.Stakeholder.GUID);
                    var temp     = EAMain.Repository.GetConnectorByGUID(connector.ConnectorGUID);
                    supplier.RemoveConnector(temp);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Add a new force for each concern if the combination not exists already
        /// </summary>
        /// <param name="force"></param>
        private void AddForceConcerns(IEAElement force)
        {
            IEARepository repository  = EAFacade.EA.Repository;
            string        diagramGuid = _controller.Model.DiagramGUID;
            IEADiagram    diagram     = repository.GetDiagramByGuid(diagramGuid);

            //Add the force for each selected concern
            foreach (var item in _lbConcern.SelectedItems)
            {
                var        selectedItem = (KeyValuePair <string, string>)item;
                IEAElement concern      = repository.GetElementByGUID(selectedItem.Key);

                diagram.AddElement(concern);

                IEAConnector connector = force.ConnectTo(concern, EAConstants.ForcesConnectorType, EAConstants.RelationClassifiedBy);
                if (!connector.TaggedValueExists(EATaggedValueKeys.IsForceConnector, diagramGuid))
                {
                    // Add TaggedValue for new force and concern (having multiple TaggedValues of the same name/data is possible).
                    // The amount of TaggedValues with the same name and data is the amount of forces/concerns in the table.
                    force.AddTaggedValue(EATaggedValueKeys.IsForceElement, diagramGuid);
                    concern.AddTaggedValue(EATaggedValueKeys.IsConcernElement, diagramGuid);

                    // Add the diagramGuid as a TaggedValue (ConnectorTag) to the connector
                    connector.AddTaggedValue(EATaggedValueKeys.IsForceConnector, diagramGuid);
                    _closeWindow = true;
                }
                else //Force concern combination (connector) already exists
                {
                    MessageBox.Show(string.Format(Messages.ForcesViewForceExists, force.Name, concern.Name),
                                    "Force already exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Adds the forces and concerns that are selected in the TreeView and ListBox to the forces diagram
        /// </summary>
        public void AddForceToForcesDiagram()
        {
            TreeNode selectedNode = _tvForce.SelectedNode;

            // Cannot add force if no force or concern is selected
            if (selectedNode == null || _lbConcern.SelectedItems.Count < 1)
            {
                return;
            }

            IEARepository repository  = EAFacade.EA.Repository;
            string        diagramGuid = _controller.Model.DiagramGUID;
            IEADiagram    diagram     = repository.GetDiagramByGuid(diagramGuid);

            IEAElement force = repository.GetElementByGUID(selectedNode.ImageKey);

//            if (force.Type.Equals("Package")) return; // User cannot add packages as a force
            diagram.AddElement(force); //Will not be added if already exists

            AddForceConcerns(force);

            //Window does not have to be closed and no update needed
            if (!_closeWindow)
            {
                return;
            }

            _controller.SetDiagramModel(repository.GetDiagramByGuid(_controller.Model.DiagramGUID));
            DialogResult = DialogResult.OK;
        }
Пример #5
0
        /// <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);
            }
        }
        public bool SaveChanges()
        {
            IEARepository repository = EAMain.Repository;

            //should not happen, need to know where the evaluation result should be saved.
            if (null == _decisionGUID)
            {
                throw new Exception();
            }

            //detect if it is a new rating entry
            if ("".Equals(TaggedValueGUID))
            {
                IEAElement element = repository.GetElementByGUID(_decisionGUID);
                element.AddTaggedValue(SerializeName(), Result);
            }
            else
            {
                //only update
                IEAElement element = repository.GetElementByGUID(_decisionGUID);
                return(element.UpdateTaggedValue(TaggedValueGUID, SerializeName(), Result));
            }
            return(true);
        }
        public bool SaveChanges()
        {
            IEARepository repository = EAMain.Repository;

            //should not happen, need to know where the History Entry should be saved.
            if (null == Decision)
            {
                throw new Exception();
            }

            //detect if it is a new history entry
            if ("".Equals(TaggedValueGUID))
            {
                IEAElement element = repository.GetElementByGUID(Decision.GUID);
                element.AddTaggedValue(EATaggedValueKeys.DecisionStateChange, Serialize());
            }
            else
            {
                //only update
                IEAElement element = repository.GetElementByGUID(Decision.GUID);
                return(element.UpdateTaggedValue(TaggedValueGUID, EATaggedValueKeys.DecisionStateChange, Serialize()));
            }
            return(true);
        }
Пример #8
0
        /// <summary>
        /// Colours the header of a row according to the state of the element in the row if it is a decision
        /// </summary>
        /// <param name="i"></param>
        private void ColourForceHeader(int i)
        {
            DataGridViewRow row  = _forcesTable.Rows[i];
            string          guid = row.Cells[ForcesTableContext.ForceGUIDColumnIndex].Value.ToString();

            if (guid.Equals(ForcesTableContext.EmptyCellValue))
            {
                return;
            }
            IEARepository repository = EAFacade.EA.Repository;
            IEAElement    element    = repository.GetElementByGUID(guid);

            if (element == null || row.HeaderCell == null || !element.IsDecision())
            {
                return;
            }
            row.HeaderCell.Style.BackColor = RetrieveColorByState(element.Stereotype);
        }
Пример #9
0
        /// <summary>
        /// Colours the header of a decision column according to the state of the decision
        /// </summary>
        /// <param name="i"></param>
        private void ColourDecisionHeader(int i)
        {
            if (i < ForcesTableContext.DecisionColumnIndex)
            {
                return;
            }
            string             decisionGuid = _forcesTable.Rows[_forcesTable.Rows.Count - 1].Cells[i].Value.ToString();
            DataGridViewColumn column       = _forcesTable.Columns[i];

            if (column.HeaderCell == null)
            {
                return;
            }
            IEARepository repository = EAFacade.EA.Repository;

            column.HeaderCell.Style.BackColor =
                RetrieveColorByState(repository.GetElementByGUID(decisionGuid).Stereotype);
        }
Пример #10
0
 public void DiscardChanges()
 {
     if ("".Equals(TaggedValueGUID))
     {
         //no changes have been saved to the repository, its a fresh history entry
     }
     else
     {
         IEARepository repository = EAMain.Repository;
         //should not happen, need to know where the History Entry should be loaded from.
         if (null == Decision)
         {
             throw new Exception();
         }
         IEAElement     element     = repository.GetElementByGUID(Decision.GUID);
         IEATaggedValue taggedValue = element.GetTaggedValueByGUID(TaggedValueGUID);
         Deserialize(taggedValue.Value);
     }
 }
Пример #11
0
 /// <summary>
 /// Add all elements that do not contain children
 /// </summary>
 /// <param name="node"></param>
 private void AddFromNode(TreeNode node)
 {
     if (node.Nodes.Count > 0)
     {
         foreach (TreeNode n in node.Nodes)
         {
             AddFromNode(n);
         }
     }
     else
     {
         IEARepository repository = EAFacade.EA.Repository;
         IEAElement    element    = repository.GetElementByGUID(node.ImageKey);
         if (element.IsDecision())
         {
             AddDecisionToDiagram(element);
         }
     }
 }
Пример #12
0
        public void SaveRatings(IEnumerable <Rating> data)
        {
            IEARepository repository = EAMain.Repository;

            foreach (Rating rating in data)
            {
                IEAElement decision = repository.GetElementByGUID(rating.DecisionGUID);
                if (decision == null)
                {
                    continue;
                }
                string forcesTaggedValue = Rating.ConstructForcesTaggedValue(rating.ForceGUID, rating.ConcernGUID);
                if (decision.GetTaggedValueByName(forcesTaggedValue) != null)
                {
                    decision.UpdateTaggedValue(forcesTaggedValue, rating.Value);
                }
                else
                {
                    decision.AddTaggedValue(forcesTaggedValue, rating.Value);
                }
            }
        }
Пример #13
0
        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;
            }
        }