示例#1
0
        /// <summary>
        /// set the main element to navigate
        /// </summary>
        /// <param name="newElement">the element to navigate</param>
        public void setElement(UML.Extended.UMLItem newElement)
        {
            if (!treeBackgroundWorker.IsBusy)
            {
                this.startThread(newElement);
            }
            else
            {
                //backgroundworker is still busy so we add the element to the workqueue instead
                TimeSpan runtime = (DateTime.Now - lastStartTime);
                if (runtime.TotalSeconds < 5)
                {
                    this.workQueue.Insert(0, newElement);
                    //make sure the queue doesn't get too large.
                    if (this.workQueue.Count > 10)
                    {
                        this.workQueue.RemoveAt(this.workQueue.Count - 1);
                    }
                }
                else
                {
                    //for some reason sometimes the backgroundworker gets stuck.
                    //This always seems to happen shortly after a right click (and thus a call to EA_GetMenuItems) when a lot of elements have been clicked in a short period of time.
                    //when its stuck it is calling a method on the EA API that never returns (someting like EA.Element.Name)
                    //I've tried everything to abort or cancel the thread, but nothing seems to work.
                    //So the only solution that does seem to work is spawn a new thread and start using that one.
                    //In the long rung this will ofcourse cause the a memory/thread leak, but from personal experience, this only seems to happen a few times a day, and only when dealing with a large (and thus slow) model.

                    //current backgoundworker is stuck. Start a new one.
                    this.resetTreeBackgroundWorker();
                    //process the element
                    this.startThread(newElement);
                }
            }
        }
示例#2
0
 /// <summary>
 /// returns the tooltiptext for the given element
 /// </summary>
 /// <param name="element">the element</param>
 /// <returns>the tooltip text</returns>
 private string getToolTipText(UML.Extended.UMLItem element)
 {
     //Getting some strange RPC_E_WRONG_THREAD error while getting the owner ElementWrapper.
     //Disablign the tooltiptext for now to avoid the error
     //Enabled again after installing all addins together
     return(element.fqn);
 }
示例#3
0
        /// <summary>
        /// initialise based on named elements
        /// </summary>
        /// <param name="namedElements"></param>
        private void InitNamedElements(List <UML.Extended.UMLItem> namedElements)
        {
            InitializeComponent();
            this.Text            = "Select Elements";
            this.ItemHeader.Text = "Element";
            this.openButton.Text = "Select";
            //fill the diagramList
            foreach (UML.Extended.UMLItem element in namedElements)
            {
                //add the element
                ListViewItem item = new ListViewItem(element.name);
                item.Tag = element;

                string ownerName = string.Empty;

                UML.Extended.UMLItem owner = element.owner as UML.Extended.UMLItem;
                if (null != owner)
                {
                    ownerName = owner.name;
                }
                item.SubItems.Add(ownerName);
                if (ownerName == string.Empty)
                {
                    item.ForeColor = SystemColors.GrayText;
                }
                item.UseItemStyleForSubItems = true;
                this.navigateListView.Items.Add(item);
            }
        }
示例#4
0
 /// <summary>
 /// event launched just before a node is expanded
 /// </summary>
 /// <param name="sender">sender</param>
 /// <param name="e">arguments</param>
 void NavigatorTreeBeforeExpand(object sender, TreeViewCancelEventArgs e)
 {
     foreach (TreeNode subNode in e.Node.Nodes)
     {
         if (this.isOwnerNode(subNode))
         {
             UML.Extended.UMLItem owner = ((UML.Extended.UMLItem)e.Node.Tag).owner;
             if (owner != null)
             {
                 this.addElementToTree(owner, e.Node, subNode);
             }
         }
         else if (this.isTypeNode(subNode))
         {
             UML.Classes.Kernel.Property attribute = e.Node.Tag as UML.Classes.Kernel.Property;
             if (attribute != null &&
                 attribute.type != null)
             {
                 this.addElementToTree(attribute.type, e.Node, subNode);
             }
         }
     }
     if (BeforeExpand != null)
     {
         BeforeExpand(sender, e);
     }
 }
        private static Mapping getMapping(UML.Extended.UMLItem mappingItem, Element mappingTarget, MappingNode startNode, List <string> sourceMappingPath, List <string> targetMappingPath, MappingNode targetRootNode)
        {
            //do nothing if mappign target is null
            if (mappingTarget == null)
            {
                return(null);
            }
            //check if the mappingPath of the source corresponds with the path of the node
            var startNodeMappingPath = startNode.mappingPath;
            //source is OK if mapping corresponds, or no mappingPath found and it is not virtual
            var sourceOK = sourceMappingPath.SequenceEqual(startNodeMappingPath) || (!sourceMappingPath.Any() && !startNode.isVirtual);

            // if no targetMapping found then we try to build a Mapping up to the target root node source element
            if (!targetMappingPath.Any())
            {
                targetMappingPath = getMappingPath(mappingTarget, targetRootNode);
            }
            //target is OK if the first item of the targetMappignPath corresponds to the targetRootNode
            var targetOK = targetMappingPath.FirstOrDefault() == targetRootNode.source?.uniqueID;

            //if target or source is not OK then we return null
            if (!sourceOK || !targetOK)
            {
                return(null);
            }
            //first create the targetMappingNode
            var targetMappingNode = targetRootNode.createMappingNode(targetMappingPath);

            //return the actual mapping
            return(createMapping(mappingItem, startNode, targetMappingNode));
        }
示例#6
0
 void QuickSearchComboBoxSelectionChangeCommitted(object sender, EventArgs e)
 {
     if (this.quickSearchBox.SelectedIndex >= 0)
     {
         UML.Extended.UMLItem quickSearchSelectedItem = this.quickSearchBox.SelectedItem as UML.Extended.UMLItem;
         {
             if (quickSearchSelectedItem != null)
             {
                 // if this element is to be selected in the project browser is will
                 // automatically be set as the main element
                 if (settings.quickSearchSelectProjectBrowser)
                 {
                     quickSearchSelectedItem.select();
                 }
                 else
                 {
                     this.setElement(quickSearchSelectedItem);
                 }
                 // also add to diagram if needed
                 if (settings.quickSearchAddToDiagram)
                 {
                     this.addToDiagram(quickSearchSelectedItem);
                 }
             }
         }
     }
 }
示例#7
0
        /// <summary>
        /// adds an elementNode to the tree
        /// </summary>
        /// <param name="element">the source element</param>
        /// <param name="parentNode">the parentNode. If null is passed then the node will be added as root node</param>
        /// <param name="nodeToReplace">the node to replace with new data</param>
        private void addElementToTree(UML.Extended.UMLItem element, TreeNode parentNode, TreeNode nodeToReplace = null)
        {
            TreeNode elementNode = this.makeElementNode(element, parentNode, nodeToReplace);

            this.enableDisableContexMenu(element);
            // select the node
            //NavigatorTree.SelectedNode = elementNode;
        }
示例#8
0
 private void openProperties()
 {
     UML.Extended.UMLItem selectedElement = this.NavigatorTree.SelectedNode.Tag as UML.Extended.UMLItem;
     if (selectedElement != null)
     {
         selectedElement.openProperties();
     }
 }
示例#9
0
 private void addToDiagram(UML.Extended.UMLItem selectedElement)
 {
     if (selectedElement != null)
     {
         selectedElement.addToCurrentDiagram();
         selectedElement.selectInCurrentDiagram();
     }
 }
示例#10
0
        /// <summary>
        /// catches the event that the backgroundworker has finished.
        /// in that case we should select the returned node
        /// </summary>
        /// <param name="sender">the backgroundworder</param>
        /// <param name="e">the parameters</param>
        private void treeBackgroundRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if ((e.Cancelled == true))
            {
                //nothing?
            }
            else if (!(e.Error == null))
            {
                //nothing?
            }
            else
            {
                //do the visual work for the new treenode
                TreeNode elementNode = (TreeNode)e.Result;

                //remove duplicate
                if (this.removeRootNode((UML.Extended.UMLItem)elementNode.Tag))
                {
                    try
                    {
                        //no parentNode, add as new root node before any others
                        //inserting a node sometimes causes an InvalidOperationException because its being called in the wrong thread
                        //doing it using the invoke should help.
                        invoker = new MethodDelegate(ThreadSaveInsertNode);
                        this.NavigatorTree.Invoke(invoker, elementNode);
                        //this.NavigatorTree.Nodes.Insert(0,elementNode);
                        //remove the excess nodes
                        this.removeExcessNodes();
                        //expand the node
                        elementNode.Expand();
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace, "An error occured"
                                        , MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    //first node is already the one we need
                    elementNode = this.NavigatorTree.Nodes[0];
                }
                this.NavigatorTree.SelectedNode = (TreeNode)e.Result;

                //check if there's still something int the queue
                if (this.workQueue.Count > 0)
                {
                    //get the last element in the queue
                    UML.Extended.UMLItem nextElement = this.workQueue[this.workQueue.Count - 1];
                    //remove it
                    this.workQueue.RemoveAt(this.workQueue.Count - 1);
                    //process it
                    this.setElement(nextElement);
                }
            }
        }
示例#11
0
 private void startThread(UML.Extended.UMLItem newElement)
 {
     if (!this.treeBackgroundWorker.IsBusy)
     {
         this.working = true;
         //start new tread here to create new element
         this.lastStartTime = DateTime.Now;
         this.treeBackgroundWorker.RunWorkerAsync(newElement);
     }
 }
示例#12
0
        private void treeBackground_DoWork(object sender, DoWorkEventArgs e)
        {
            UML.Extended.UMLItem element = e.Argument as UML.Extended.UMLItem;
            BackgroundWorker     worker  = sender as BackgroundWorker;

            if (element != null)
            {
                //pass the new node to the runworkercompleted event
                e.Result = this.makeElementNode(element, null);
            }
        }
示例#13
0
 /// <summary>
 /// copies the GUID of the selected element to the clipboard
 /// </summary>
 void copyGUID()
 {
     if (this.NavigatorTree.SelectedNode != null)
     {
         UML.Extended.UMLItem selectedElement = this.NavigatorTree.SelectedNode.Tag as UML.Extended.UMLItem;
         if (selectedElement.uniqueID != null)
         {
             Clipboard.SetText(selectedElement.uniqueID);
         }
     }
 }
 public override TSF.UmlToolingFramework.UML.Extended.UMLItem getItemFromRelativePath(List <string> relativePath)
 {
     UML.Extended.UMLItem item = null;
     if (ElementWrapper.filterName(relativePath, this.name))
     {
         if (relativePath.Count == 1)
         {
             item = this;
         }
     }
     return(this);
 }
        /// <summary>
        /// searches downward for the item with the given relative path
        /// This relative path includes the own name
        /// </summary>
        /// <param name="relativePath">list of names inlcuding the own name</param>
        /// <returns>the item matching the path</returns>
        public TSF.UmlToolingFramework.UML.Extended.UMLItem getItemFromRelativePath(List <string> relativePath)
        {
            UML.Extended.UMLItem item         = null;
            List <string>        filteredPath = new List <string>(relativePath);

            if (ElementWrapper.filterName(filteredPath, this.name))
            {
                if (filteredPath.Count == 1)
                {
                    item = this;
                }
            }
            return(item);
        }
示例#16
0
 /// <summary>
 /// createas a new navigatorList based on the given list of UML Items
 /// </summary>
 /// <param name="items">the items to show</param>
 public NavigatorList(List <UML.Extended.UMLItem> items, UML.Extended.UMLItem context) : base()
 {
     if (items.Count > 0)
     {
         this.context = context;
         if (items[0] is UML.Diagrams.Diagram)
         {
             this.InitDiagrams(items.Cast <UML.Diagrams.Diagram>().ToList());
         }
         else
         {
             this.InitNamedElements(items);
         }
     }
 }
示例#17
0
 private void openSelectedElements()
 {
     foreach (ListViewItem item in this.navigateListView.SelectedItems)
     {
         UML.Extended.UMLItem element = item.Tag as UML.Extended.UMLItem;
         if (null != element)
         {
             element.open();
         }
         //if the element is a diagram then also select the context
         if (element is UML.Diagrams.Diagram)
         {
             ((UML.Diagrams.Diagram)element).selectItem(context);
         }
     }
 }
示例#18
0
        public static Mapping createMapping(UML.Extended.UMLItem mappingItem, MappingNode startNode, MappingNode targetNode)
        {
            var connector = mappingItem as ConnectorWrapper;

            if (connector != null)
            {
                return(new ConnectorMapping(connector, startNode, targetNode));
            }
            var taggedValue = mappingItem as TaggedValue;

            if (taggedValue != null)
            {
                return(new TaggedValueMapping(taggedValue, startNode, targetNode));
            }
            throw new ArgumentException("MappingItem should be Connector or TaggedValue");
        }
        public UML_SM.StateMachine getContainingStateMachine(UML.Extended.UMLItem umlItem)
        {
            if (umlItem != null)
            {
                if (umlItem.owner is UML_SM.StateMachine)
                {
                    return(umlItem.owner as UML_SM.StateMachine);
                }
                else
                {
                    return(getContainingStateMachine(umlItem.owner));
                }
            }

            return(null);
        }
 /// <summary>
 /// createas a new navigatorList based on the given list of UML Items
 /// </summary>
 /// <param name="items">the items to show</param>
 public NavigatorList(List<UML.Extended.UMLItem> items, UML.Extended.UMLItem context)
     : base()
 {
     if (items.Count > 0)
     {
         this.context = context;
         if (items[0] is UML.Diagrams.Diagram)
         {
             this.InitDiagrams(items.Cast<UML.Diagrams.Diagram>().ToList());
         }
         else
         {
             this.InitNamedElements(items);
         }
     }
 }
示例#21
0
        private UML.Extended.UMLItem getLinkedFeature(bool start)
        {
            string styleEx = this.wrappedConnector.StyleEx;
            string key;

            UML.Extended.UMLItem linkedFeature = null;
            //determine start or end keyword
            key = start ? "LFSP=" : "LFEP=";
            int guidStart = styleEx.IndexOf(key) + key.Length;

            if (guidStart >= key.Length)
            {
                string featureGUID = styleEx.Substring(guidStart, this.WrappedConnector.ConnectorGUID.Length);
                linkedFeature = this.model.getItemFromGUID(featureGUID);
            }
            return(linkedFeature);
        }
示例#22
0
 void NavigatorTreeNodeMouseClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e)
 {
     //set the selected node also with right mouse click
     if (e.Button == MouseButtons.Right)
     {
         this.NavigatorTree.SelectedNode = e.Node;
     }
     //show context menu
     UML.Extended.UMLItem selectedElement = this.NavigatorTree.SelectedNode.Tag as UML.Extended.UMLItem;
     if (e.Button == MouseButtons.Right &&
         selectedElement != null)
     {
         //set enabled status
         this.enableDisableContexMenu(selectedElement);
         //then actually show the menu
         this.navigatorContextMenu.Show(this.NavigatorTree, e.Location);
     }
 }
示例#23
0
        void NavigatorTreeNodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            UML.Extended.UMLItem selectedElement = e.Node.Tag as UML.Extended.UMLItem;
            if (selectedElement != null)
            {
                if (this.settings.projectBrowserDefaultAction)
                {
                    this.selectInProjectBrowser();
                }
                else
                {
                    this.openProperties();
                }
            }
//			if (NodeDoubleClick != null)
//			{
//				NodeDoubleClick(sender,e);
//			}
        }
        private UML.Extended.UMLItem getLinkedFeature(bool isSource)
        {
            UML.Extended.UMLItem linkedFeature = null;
            //determine start or end keyword
            string key         = isSource ? "LFSP" : "LFEP";
            string featureGUID = KeyValuePairsHelper.getValueForKey(key, this.wrappedConnector.StyleEx);

            if (!string.IsNullOrEmpty(featureGUID))
            {
                if (featureGUID.EndsWith("}R") ||
                    featureGUID.EndsWith("}L"))
                {
                    //remove the last "R" or "L"
                    featureGUID = featureGUID.Substring(0, featureGUID.Length - 1);
                }
                //get the linked feature
                linkedFeature = this.model.getItemFromGUID(featureGUID);
            }
            return(linkedFeature);
        }
        /// <summary>
        /// returns the name to show as node name for this element
        /// </summary>
        /// <param name="element"></param>
        public string getNodeName(UML.Extended.UMLItem element)
        {
            string name = string.Empty;

            if (element != null)
            {
                name  = this.getStereotypeString(element);
                name += element.name;
            }
            if (element is UML.Classes.Kernel.Parameter)
            {
                UML.Classes.Kernel.Parameter parameter = (UML.Classes.Kernel.Parameter)element;
                if (parameter.direction != UML.Classes.Kernel.ParameterDirectionKind._return)
                {
                    name = parameter.name + " (" + this.getNodeName(parameter.operation) + ")";
                }
            }
            else if (element is UML.Classes.Kernel.Feature)
            {
                UML.Classes.Kernel.Feature feature = (UML.Classes.Kernel.Feature)element;
                UML.Classes.Kernel.Element owner   = feature.owner;
                if (owner != null)
                {
                    name = owner.name;
                }
                else
                {
                    name = "[owner missing]";
                }
                name += "." + this.getStereotypeString(element) + feature.name;
            }
            else if (element is UML.Profiles.TaggedValue)
            {
                UML.Profiles.TaggedValue taggedValue = (UML.Profiles.TaggedValue)element;
                if (taggedValue.owner.name.Length > 0)
                {
                    name = taggedValue.owner.name + "." + taggedValue.name;
                }
            }
            return(name);
        }
 /// <summary>
 /// removes the rootnode representig the given element
 /// unless it this node is the first rootnode.
 /// In that case it simply returns false
 /// </summary>
 /// <param name="sourceElement">the element</param>
 private bool removeRootNode(UML.Extended.UMLItem sourceElement)
 {
     for (int i = this.NavigatorTree.Nodes.Count - 1; i >= 0; i--)
     {
         TreeNode node = this.NavigatorTree.Nodes[i];
         if (node.Tag.Equals(sourceElement))
         {
             if (i > 0)
             {
                 node.Remove();
                 return(true);
             }
             else
             {
                 //if the node is the first root node then don't remove it but return false
                 return(false);
             }
         }
     }
     return(true);
 }
示例#27
0
        /// <summary>
        /// gets the item from the given relative path.
        /// </summary>
        /// <param name="relativePath">the "." separated path</param>
        /// <returns>the item with the given path</returns>
        public override UML.Extended.UMLItem getItemFromRelativePath(List <string> relativePath)
        {
            UML.Extended.UMLItem item         = null;
            List <string>        filteredPath = new List <string>(relativePath);

            if (filterName(filteredPath, this.name))
            {
                if (filteredPath.Count > 1)
                {
                    //remove first item from filteredPath
                    filteredPath.RemoveAt(0);
                    //search deeper
                    foreach (UML.Classes.Kernel.Element element in this.ownedElements)
                    {
                        item = element.getItemFromRelativePath(filteredPath);
                        if (item != null)
                        {
                            return(item);
                        }
                    }
                    //still not found, now search diagram
                    foreach (UML.Diagrams.Diagram diagram in this.ownedDiagrams)
                    {
                        item = diagram.getItemFromRelativePath(filteredPath);
                        if (item != null)
                        {
                            return(item);
                        }
                    }
                }
                else
                {
                    item = this;
                }
            }

            return(item);
        }
示例#28
0
        /// <summary>
        /// removes the rootnode representig the given element
        /// unless it this node is the first rootnode.
        /// In that case it simply returns false
        /// </summary>
        /// <param name="sourceElement">the element</param>
        private bool removeRootNode(UML.Extended.UMLItem sourceElement)
        {
            if (sourceElement != null)
            {
                for (int i = this.NavigatorTree.Nodes.Count - 1; i >= 0; i--)
                {
                    TreeNode node = this.NavigatorTree.Nodes[i];
                    if (node != null)
                    {
                        if (sourceElement.Equals(node.Tag))
                        {
                            if (i > 0)
                            {
                                try
                                {
                                    node.Remove();
                                }
                                catch (NullReferenceException)
                                {
                                    //sometimes we get a nullpointer exception here for unknown reasons.
                                    //just ignore it and return true
                                    return(true);
                                }

                                return(true);
                            }
                            else
                            {
                                //if the node is the first root node then don't remove it but return false
                                return(false);
                            }
                        }
                    }
                }
            }
            return(true);
        }
示例#29
0
 private void selectInProjectBrowser()
 {
     UML.Extended.UMLItem selectedElement = this.NavigatorTree.SelectedNode.Tag as UML.Extended.UMLItem;
     if (selectedElement != null)
     {
         //select the context before opening the element (and changing the selected node)
         UML.Extended.UMLItem context = null;
         if (selectedElement is UML.Diagrams.Diagram)
         {
             context = this.findContext(this.NavigatorTree.SelectedNode);
         }
         //actually open element
         selectedElement.open();
         if (selectedElement is UML.Classes.Kernel.Relationship)
         {
             this.setElement(selectedElement);
         }
         //select the context if the selected element was a diagram
         if (context != null)
         {
             ((UML.Diagrams.Diagram)selectedElement).selectItem(context);
         }
     }
 }
        /// <summary>
        /// returns a string represenation of the stereotypes
        /// </summary>
        /// <param name="element">the element containing the stereotype</param>
        /// <returns>a string containing the stereotype «stereo1,ste..»</returns>
        private string getStereotypeString(UML.Extended.UMLItem element)
        {
            string stereotypeString = string.Empty;
            int    maxLength        = 20;

            if (element.stereotypes.Count > 0)
            {
                stereotypeString = "«";
                foreach (UML.Profiles.Stereotype stereotype in element.stereotypes)
                {
                    if (stereotypeString.Length > 1)
                    {
                        stereotypeString += ", ";
                    }
                    stereotypeString += stereotype.name;
                    if (stereotypeString.Length > maxLength)
                    {
                        stereotypeString = stereotypeString.Substring(0, maxLength - 2) + "..";
                    }
                }
                stereotypeString += "» ";
            }
            return(stereotypeString);
        }
示例#31
0
 /// <summary>
 /// enables or disabled the context menu items based on the type of the selected element
 /// </summary>
 /// <param name="selectedElement">the selected element</param>
 private void enableDisableContexMenu(UML.Extended.UMLItem selectedElement)
 {
     //both options should be disabled for connectors,
     if (selectedElement is UML.Classes.Kernel.Relationship)
     {
         this.selectBrowserMenuItem.Enabled  = false;
         this.projectBrowserButton.Enabled   = false;
         this.openPropertiesMenuItem.Enabled = false;
         this.propertiesButton.Enabled       = false;
     }
     //or for tagged values on connectors because we can't open their properties dialog anyway.
     else if (selectedElement is UML.Profiles.TaggedValue &&
              ((UML.Profiles.TaggedValue)selectedElement).owner is UML.Classes.Kernel.Relationship)
     {
         this.selectBrowserMenuItem.Enabled  = false;
         this.projectBrowserButton.Enabled   = false;
         this.openPropertiesMenuItem.Enabled = false;
         this.propertiesButton.Enabled       = false;
     }
     else if (selectedElement == null)
     {
         this.selectBrowserMenuItem.Enabled  = false;
         this.openPropertiesMenuItem.Enabled = false;
         this.addToDiagramButton.Enabled     = false;
         this.propertiesButton.Enabled       = false;
         this.projectBrowserButton.Enabled   = false;
     }
     //standard should be enabled.
     else
     {
         this.setContextMenuItemsEnabled(true);
         this.propertiesButton.Enabled     = true;
         this.projectBrowserButton.Enabled = true;
         this.addToDiagramButton.Enabled   = true;
     }
 }