private static void addFactory(UML.Extended.UMLModel model, SchemaBuilderFactory factory)
 {
     if (!instances.ContainsKey(model))
       {
       instances.Add(model, factory);
       }
 }
		/// <summary>
		/// creates a subset of the source model with only the properties and associations used in this schema
		/// </summary>
		/// <param name="destinationPackage">the package to create the subset in</param>
		public void createSubsetModel(UML.Classes.Kernel.Package destinationPackage)
		{
			//loop the elemets to create the subSetElements
			foreach (EASchemaElement schemaElement in this.elements) 
			{
				//only create subset elements for classes, not for datatypes
				if (schemaElement.sourceElement is UML.Classes.Kernel.Class)
				{
					schemaElement.createSubsetElement(destinationPackage);
					//Logger.log("after EASchema::creating single subset element");
				}
			}
			//Logger.log("after EASchema::creating subsetelements");
			// then loop them again to create the associations
			foreach (EASchemaElement schemaElement in this.elements) 
			{
				//only create subset elements for classes, not for datatypes
				if (schemaElement.sourceElement is UML.Classes.Kernel.Class)
				{
					schemaElement.createSubsetAssociations();
					//Logger.log("after EASchema::creating single subset association");
				}
				// and to resolve the attributes types to subset types if required
				schemaElement.resolveAttributetypes(this.schemaElements);
				//Logger.log("after EASchema::resolving attributes");
				//and add a dependency from the schemaElement to the type of the attributes
				schemaElement.addAttributeTypeDependencies();
				//Logger.log("after EASchema::adding attribuetypeDependencies");
			}

		}
		/// returns the singleton instance for the given model.
	    public static new EASchemaBuilderFactory getInstance(UML.UMLModel model){
	      EASchemaBuilderFactory factory = SBF.SchemaBuilderFactory.getInstance(model) as EASchemaBuilderFactory;
	      if( factory == null ) {
	      	factory = new EASchemaBuilderFactory((UTF_EA.Model)model);
	      }
	      return factory;
	    }
Example #4
0
 getVisibility(UML.Classes.Kernel.VisibilityKind visibility) {
   switch( visibility ) {
     case UML.Classes.Kernel.VisibilityKind._private:   return "private";
     case UML.Classes.Kernel.VisibilityKind._protected: return "protected";
     case UML.Classes.Kernel.VisibilityKind._package:   return "package";
     case UML.Classes.Kernel.VisibilityKind._public:    return "public";
     default:                                           return "public";
   }
 }
 public static int getEAAggregationKind
   (UML.Classes.Kernel.AggregationKind aggregation)
 {
   switch(aggregation) {
     case UML.Classes.Kernel.AggregationKind.none:      return 0;
     case UML.Classes.Kernel.AggregationKind.shared:    return 1;
     case UML.Classes.Kernel.AggregationKind.composite: return 2;
     default:                                           return 0;
   }
 }
 /// translates the UML VisibilityKind to the string used in EA
 internal static String getEAVisibility
   (UML.Classes.Kernel.VisibilityKind visibility)
 {
   switch (visibility) {
     case UML.Classes.Kernel.VisibilityKind._private:   return "Private";
     case UML.Classes.Kernel.VisibilityKind._public:    return "Public";
     case UML.Classes.Kernel.VisibilityKind._protected: return "Protected";
     case UML.Classes.Kernel.VisibilityKind._package:   return "Package";
     default:                                           return "";
   }
 }
 /// translates the EA visibilityString to the UML VisibilityKind.
 /// If the proper translation cannot be found the defaultVisibility will 
 /// be returned
 internal static UML.Classes.Kernel.VisibilityKind getUMLVisibilityKind
   (String visibility, UML.Classes.Kernel.VisibilityKind defaultVisibility)
 {
   switch (visibility) {
     case "Private":   return UML.Classes.Kernel.VisibilityKind._private;
     case "Public":    return UML.Classes.Kernel.VisibilityKind._public;
     case "Protected": return UML.Classes.Kernel.VisibilityKind._protected;
     case "Package":   return UML.Classes.Kernel.VisibilityKind._package;
     default:          return defaultVisibility;
   }
 }
 internal static string getEAParameterDirectionKind
   ( UML.Classes.Kernel.ParameterDirectionKind UMLdirection )
 {
   switch (UMLdirection) {
   case UML.Classes.Kernel.ParameterDirectionKind._in:     return "in";
   case UML.Classes.Kernel.ParameterDirectionKind._out:    return "out";
   case UML.Classes.Kernel.ParameterDirectionKind._inout:  return "inout";
   case UML.Classes.Kernel.ParameterDirectionKind._return: return "return";
   default:                                                return "in";
   }
 }
		/// <summary>
		/// returns the SchemaElement that corresponds with the given UML element
		/// </summary>
		/// <param name="umlElement">the source UMLElement</param>
		/// <returns></returns>
		internal EASchemaElement getSchemaElementForUMLElement(UML.Classes.Kernel.Element umlElement)
		{
			EASchemaElement result = null;
			foreach (EASchemaElement schemaElement in this.elements) 
			{
				if (schemaElement.sourceElement.Equals(umlElement))
				{
					result = schemaElement;
				}
			}
			return result;
		}
 	/// <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.UMLItem> items, UML.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);
 			}
 		}
 			
     }
 /// <summary>
 /// returns all tagged values that reference the given item
 /// </summary>
 /// <param name="parentItem"></param>
 /// <returns></returns>
 private List<UML.Extended.UMLItem>getDependentTaggedValues(UML.Extended.UMLItem parentItem)
 {
     List<UML.Extended.UMLItem> elementsToNavigate = new List<UML.Extended.UMLItem>();
     UML.Classes.Kernel.Element parentElement = parentItem as UML.Classes.Kernel.Element;
     if (parentElement != null)
     {
     foreach (UML.Profiles.TaggedValue taggedValue in parentElement.getReferencingTaggedValues())
     {
         //not for the "system" tagged values
         if (taggedValue.name != eaGUIDTagname
            && taggedValue.name != eaOperationGUIDTagName)
         {
             elementsToNavigate.Add(taggedValue);
         }
     }
     }
     return elementsToNavigate;
 }
   /// <summary>
   /// selects the implementation of the operation in the project browser, and opens all owned diagrams of the implementation.
   /// </summary>
   private List<UML.UMLItem> getImplementation(UML.UMLItem parentElement)
   {
   	List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
   	UML.Classes.Kernel.Operation selectedOperation = this.getSelectedOperation(parentElement);
   	if (selectedOperation != null )
   	{
   		foreach ( UML.CommonBehaviors.BasicBehaviors.Behavior implementation in selectedOperation.methods)
   		{
   			//select the behavior in the project browser
	   		elementsToNavigate.AddRange(implementation.ownedDiagrams);
   		}
   	}
   	return elementsToNavigate;
   }
 /// <summary>
 /// Opens the type of the attribute
 /// </summary>
 private List<UML.UMLItem> getClassifier(UML.UMLItem parentElement)
 {
 		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
 		UML.Classes.Kernel.Property selectedAttribute = parentElement as UML.Classes.Kernel.Property;
 		if (null != selectedAttribute)
 		{
 			elementsToNavigate.Add(selectedAttribute.type);
 		}
 		return elementsToNavigate;
 }
   /// <summary>
   /// Opens the parameters that use the selected element as type
   /// </summary>
   private List<UML.UMLItem> getParameters(UML.UMLItem parentElement)
   {
	   	List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
	   	UML.Classes.Kernel.Type selectedType = parentElement as UML.Classes.Kernel.Type;
	   	// get the parameters that use the selected classifier as type
	   	elementsToNavigate.AddRange(selectedType.getDependentTypedElements<UML.Classes.Kernel.Parameter>());
	   	return elementsToNavigate;
   }
   /// <summary>
   /// opens the CallOperationActions that call te selected operation
   /// </summary>
   private List<UML.UMLItem> getActions(UML.UMLItem parentElement)
   {
   	List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
   	UML.Classes.Kernel.Operation selectedOperation = this.getSelectedOperation( parentElement);
   	if( selectedOperation != null)
   	{
		elementsToNavigate.AddRange(selectedOperation.getDependentCallOperationActions());
    }
	return elementsToNavigate;
   }
   /// <summary>
   /// Opens the types of the parameters of the selected operation
   /// </summary>
   private List<UML.UMLItem> getParameterTypes(UML.UMLItem parentElement)
   {
   		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
	   	UML.Classes.Kernel.Operation selectedOperation = this.getSelectedOperation(parentElement);
        if (selectedOperation != null)
        {
            HashSet<UML.Classes.Kernel.Parameter> parameters = selectedOperation.ownedParameters;
            foreach (UML.Classes.Kernel.Parameter parameter in parameters)
            {
                elementsToNavigate.Add(parameter.type);
            }
        }
	   	return elementsToNavigate;
   }
   /// <summary>
   /// Opens the attributes of that use the selected element as type
   /// </summary>
   private List<UML.UMLItem> getAttributes(UML.UMLItem parentElement)
   {
	   	List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
	   	UML.Classes.Kernel.Type selectedType = parentElement as UML.Classes.Kernel.Type;
	   	// get the attributes that use the selected Type as type
	   	elementsToNavigate.AddRange( selectedType.getDependentTypedElements<UML.Classes.Kernel.Property>());
	   	return elementsToNavigate;
   }
 /// <summary>
 /// get all using diagrams for the given element 
 /// currently only used for operations
 /// </summary>
 /// <param name="parentElement">the element</param>
 /// <returns>the diagrams using the given element</returns>
 private List<UML.UMLItem> getDiagrams(UML.UMLItem parentElement)
 {
     List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
 	UML.Classes.Kernel.Operation selectedOperation = this.getSelectedOperation(parentElement);
     
     if (selectedOperation != null)
     {
     	elementsToNavigate.AddRange( selectedOperation.getUsingDiagrams<UML.Diagrams.Diagram>());
     }
     return elementsToNavigate;
 }
   /// <summary>
   /// gets the operation for the parent element which can be
   /// - an operation itself
   /// - a message calling the operation
   /// - a parameter for an operation
   /// - a CallOperationAction
   /// </summary>
   /// <param name="parentElement">the element to get the operation from</param>
   /// <returns>the operation for this parent element</returns>
   private List<UML.UMLItem> getOperation(UML.UMLItem parentElement)
   {
   	   List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
   	   UML.Classes.Kernel.Operation calledOperation = null;
   	   if (parentElement is UML.Classes.Kernel.Parameter)
   	   {
   	   		calledOperation = ((UML.Classes.Kernel.Parameter)parentElement).operation;
   	   }
   	   else if (parentElement is UML.Actions.BasicActions.CallOperationAction)
   	   {
   	   		calledOperation = ((UML.Actions.BasicActions.CallOperationAction)parentElement).operation;
   	   }
   	   else
   	   {
   	   		calledOperation = this.getSelectedOperation(parentElement);
   	   }
	   if (null != calledOperation)
	   {
	   		elementsToNavigate.Add(calledOperation);
	   }
	   return elementsToNavigate;
   }
	private List<UML.UMLItem> getCompositeDiagram(UML.UMLItem parentElement)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
   		UML.Classes.Kernel.Element selectedElement = parentElement as UML.Classes.Kernel.Element;
   		if (selectedElement != null)
   		{
   			UML.Diagrams.Diagram compositediagram = selectedElement.compositeDiagram;
   			if (compositediagram != null)
   			{
   				elementsToNavigate.Add(compositediagram);
   			}
   		}
   		return elementsToNavigate;
	}
 /// <summary>
 /// creates a list of menuoptions based on the names of tagged values that reference another UML item
 /// </summary>
 /// <param name="ownerElement">the owner of the tagged values</param>
 /// <returns>menuoptions for tagged values</returns>
 private static List<string> getTaggedValueMenuItems(UML.Classes.Kernel.Element ownerElement)
 {
 	List<string> menuItems = new List<string>();
 	foreach (UML.Profiles.TaggedValue taggedValue in ownerElement.taggedValues) 
 	{
 		if (taggedValue.tagValue is UML.UMLItem)
 		{
 			string menuName = taggedValueMenuName(taggedValue.name);
 			//we don't want the "system" tagged values ea_guid and operation_guid to show up in the navigator
 			if(menuName != taggedValueMenuName(eaGUIDTagname)
 			   && menuName != taggedValueMenuName(eaOperationGUIDTagName)
 			   && !menuItems.Contains(menuName))
 			{
 				menuItems.Add(menuName);
 			}
 		}
 	}
 	return menuItems;
 }
   /// <summary>
   /// Gets the selected operation from the model, either directly or through the selected message
   /// </summary>
   /// <returns>the selected operation, or the operation called by the selected message</returns>
   private UML.Classes.Kernel.Operation getSelectedOperation(UML.UMLItem parentElement)
   {
   	   // try if the the users selected an operation
   	   UML.Classes.Kernel.Operation selectedOperation = parentElement as UML.Classes.Kernel.Operation;
   	   //selected element is not an operation, try to get he operation from the selected message
   	   if (null == selectedOperation)
   	   {
           UML.Interactions.BasicInteractions.Message selectedMessage = parentElement as UML.Interactions.BasicInteractions.Message;
	       
	       if (null != selectedMessage)
	       {
		        selectedOperation = selectedMessage.calledOperation;
	       
		       if (selectedOperation == null)
		       {
		       	System.Windows.Forms.MessageBox.Show("Could not find operation!\nMake sure you either select:\n-An Operation in the project browser \n-A message in a sequence diagram that calls an existing Operation"
		        	                                     ,"Missing Operation!",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);
		       }
	       }
   	   }
       return selectedOperation;
   }
		/// <summary>
	/// returns all elements linked via the "link to element feature" 
	/// </summary>
	/// <param name="parentItem">the connected element</param>
	/// <returns>attribute, operations and classes that are linked usign the "link to element feature" functionality</returns>
	private List<UML.UMLItem>getLinkedToElementFeatures(UML.UMLItem parentItem)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		//either the parent is a property, or it is a element
		if (parentItem is UML.Classes.Kernel.Feature)
		{
			UML.Classes.Kernel.Feature parentFeature = (UML.Classes.Kernel.Feature)parentItem;
			
			foreach (UML.Classes.Kernel.Relationship relation in parentFeature.relationships)
			{
				foreach (UML.UMLItem item in relation.relatedElements) 
				{
					if (!item.Equals(parentItem))
					{
						elementsToNavigate.Add(item);
					}
				}
			}
		}
		else if (parentItem is UML.Classes.Kernel.Element)
		{
			UML.Classes.Kernel.Element parentElement = (UML.Classes.Kernel.Element)parentItem;
			foreach (UML.Classes.Kernel.Relationship relation in parentElement.relationships)
			{
				foreach (UML.UMLItem item in relation.relatedElements) 
				{
					if (item is UML.Classes.Kernel.Feature)
					{
						elementsToNavigate.Add(item);
					}
				}
			}
		}
		return elementsToNavigate;
	}		
	/// <summary>
	/// returns the owner of the parentElement
	/// </summary>
	/// <param name="parentElement">the selected element</param>
	/// <returns>the owner of the element</returns>
	private List<UML.UMLItem> getOwner(UML.UMLItem parentElement)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		UML.UMLItem owner = parentElement.owner;
		if (owner != null)
		{
			elementsToNavigate.Add(owner);
		}
		return elementsToNavigate;
	}
	private void navigate(UML.UMLItem item)
	{
		if (fullyLoaded)
        {
            if (this.navigatorControl == null)
            {
                this.navigatorControl = this.model.addWindow("Navigate", "TSF.UmlToolingFramework.EANavigator.NavigatorControl") as NavigatorControl;
                this.navigatorControl.BeforeExpand += new TreeViewCancelEventHandler(this.NavigatorTreeBeforeExpand);
                this.navigatorControl.NodeDoubleClick += new TreeNodeMouseClickEventHandler(this.NavigatorTreeNodeDoubleClick);
                this.navigatorControl.fqnButtonClick += new EventHandler(this.FqnButtonClick);
                this.navigatorControl.guidButtonClick += new EventHandler(this.GuidButtonClick);
                this.navigatorControl.quickSearchTextChanged += new EventHandler(this.quickSearchTextChanged);
                this.navigatorControl.settings = this.settings;
            }
            if (this.navigatorControl != null && this.model != null)
            {
                if (item != null)
                {
                    this.navigatorControl.setElement(item);
                }
            }
        }
	}
	/// <summary>
	/// returns the items to navigate based on the given element and chosen option.
	/// </summary>
	/// <param name="menuChoice">the chosen option</param>
	/// <param name="parentElement">the elememnt</param>
	/// <returns>list of items to navigate</returns>
	public List<UML.UMLItem> getElementsToNavigate(string menuChoice,UML.UMLItem parentElement )
	{
		
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		 switch(menuChoice) 
		 {
	        case menuOperation   : 
		 		elementsToNavigate = this.getOperation(parentElement);
	            break;
	        case menuDiagrams : 
	            elementsToNavigate = this.getDiagrams(parentElement);
	            break;
	        case menuParameterTypes:
	            elementsToNavigate = this.getParameterTypes(parentElement);
	            break;
	        case menuActions:
	            elementsToNavigate = this.getActions(parentElement);
	            break;
	        case menuAttributes:
	            elementsToNavigate = this.getAttributes(parentElement);
	        	break;
	        case menuParameters:
	        	elementsToNavigate = this.getParameters(parentElement);
	        	break;
	        case menuImplementation:
	        	elementsToNavigate = this.getImplementation(parentElement);
	        	break;
	        case menuDiagramOperations:
	        	elementsToNavigate = this.getDiagramOperations(parentElement);
				break;
		    case menuImplementedOperations:
	        	elementsToNavigate = this.getImplementedOperation(parentElement);
				break;
			case menuDependentTaggedValues:
	        	elementsToNavigate = this.getDependentTaggedValues(parentElement);
				break;
			case menuLinkedToElementFeature:
	        	elementsToNavigate = this.getLinkedToElementFeatures(parentElement);
				break;
			case menuCompositeDiagram:
				elementsToNavigate = this.getCompositeDiagram(parentElement);
				break;
			case menuCompositeElement:
				elementsToNavigate = this.getCompositeElements(parentElement);
				break;
			default:
				if(menuChoice.StartsWith(taggedValueMenuPrefix) 
				   && menuChoice.EndsWith(taggedValueMenuSuffix))
				{
					elementsToNavigate = this.getElementsViaTaggedValues(parentElement,menuChoice);
				}
				else if (menuChoice == getOwnerMenuName(parentElement))
				{
					elementsToNavigate = this.getOwner(parentElement);
				}
				else if (menuChoice == getTypeMenuName(parentElement))
				{
					elementsToNavigate = this.getClassifier(parentElement);
				}
				break;
		}
		 return elementsToNavigate;
		 
	}
   	private List<UML.UMLItem> getCompositeElements(UML.UMLItem parentElement)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		UML.Diagrams.Diagram compositeDiagram = parentElement as UML.Diagrams.Diagram;
		if (compositeDiagram != null)
		{
			elementsToNavigate = compositeDiagram.compositeElements.Cast<UML.UMLItem>().ToList();
		}
		return elementsToNavigate;
	}
	/// <summary>
	/// returns all elements referenced by the tagged values of the parent element
	/// </summary>
	/// <param name="parentElement">any UML.Classes.Kernel.Element</param>
	/// <returns>all elements referenced by the tagged values of the parent element</returns>
	private List<UML.UMLItem> getElementsViaTaggedValues(UML.UMLItem parentElement, string menuOption)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		UML.Classes.Kernel.Element taggedValueOwner = parentElement as UML.Classes.Kernel.Element;
		if (taggedValueOwner != null)
		{
			
			foreach ( UML.Profiles.TaggedValue taggedValue in taggedValueOwner.taggedValues) 
			{
				if ( menuOption.Equals(taggedValueMenuName(taggedValue.name)))
				{
					UML.UMLItem elementToNavigate = taggedValue.tagValue as UML.UMLItem;
					if (elementToNavigate != null)
					{
						elementsToNavigate.Add(elementToNavigate);
					}
				}
			}
		}
		return elementsToNavigate;
	}
	/// <summary>
	/// returns the operation implemented by the given parentElement, 
	/// or in case the parentElement is a diagram, by the owner of the parentElement
	/// </summary>
	/// <param name="parentElement">either a behavior, or a diagram owned by a behavior</param>
	/// <returns>the implmented operation (specification)</returns>
	private List<UML.UMLItem> getImplementedOperation(UML.UMLItem parentElement)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		UML.CommonBehaviors.BasicBehaviors.Behavior behavior = parentElement as UML.CommonBehaviors.BasicBehaviors.Behavior;
		//if the parent element is not a behavior it might be a diagram owned by a behavior
		if (behavior == null
		   && parentElement is UML.Diagrams.Diagram)
		{
			behavior = ((UML.Diagrams.Diagram)parentElement).owner as UML.CommonBehaviors.BasicBehaviors.Behavior;
		}
		if (behavior != null)
		{
			elementsToNavigate.Add(behavior.specification as UML.Classes.Kernel.Operation);	
		}
		return elementsToNavigate;
	}
	/// <summary>
	/// returns all operations called on the given diagram
	/// </summary>
	/// <param name="parentElement">the sequence diagram</param>
	/// <returns>all operations called on the given diagram</returns>
	private List<UML.UMLItem> getDiagramOperations(UML.UMLItem parentElement)
	{
		List<UML.UMLItem> elementsToNavigate = new List<UML.UMLItem>();
		
		if (parentElement is UML.Diagrams.SequenceDiagram)
		{
			UML.Diagrams.SequenceDiagram diagram = (UML.Diagrams.SequenceDiagram)parentElement;
			elementsToNavigate.AddRange(diagram.getCalledOperations());
		}
		else if (parentElement is UML.Diagrams.CommunicationDiagram)
		{
			UML.Diagrams.CommunicationDiagram diagram = (UML.Diagrams.CommunicationDiagram)parentElement;
			elementsToNavigate.AddRange(diagram.getCalledOperations());
		}
		return elementsToNavigate;
	}