/// <summary> /// Get element from Context element. Possible inputs are: Attribute, Operation, Element, Package /// </summary> /// <param name="rep"></param> /// <returns></returns> public static EA.Element GetElementFromContextObject(EA.Repository rep) { EA.Element el = null; EA.ObjectType objectType = rep.GetContextItemType(); switch (objectType) { case ObjectType.otAttribute: var a = (EA.Attribute)rep.GetContextObject(); el = rep.GetElementByID(a.ParentID); break; case ObjectType.otMethod: var m = (Method)rep.GetContextObject(); el = rep.GetElementByID(m.ParentID); break; case ObjectType.otElement: el = (EA.Element)rep.GetContextObject(); break; case ObjectType.otPackage: EA.Package pkg = rep.GetContextObject(); el = rep.GetElementByGuid(pkg.PackageGUID); break; case ObjectType.otNone: EA.Diagram dia = rep.GetCurrentDiagram(); if (dia?.SelectedObjects.Count == 1) { var objSelected = (EA.DiagramObject)dia.SelectedObjects.GetAt(0); el = rep.GetElementByID(objSelected.ElementID); } break; default: MessageBox.Show(@"No Element, Attribute, Operation, Package selected"); break; } return el; }
/// <summary> /// Selected items in the project browser are processed differently than selected elements /// in the visible diagram. This helper will grab the currently selected project browser item first. /// If it doesn't find it, it will return the currently selected diagram item. /// </summary> /// <param name="repository">The currently open EA repository</param> /// <returns>The element currently selected in either the project browser or diagram</returns> public static EA.Element GetCurrentElement(EA.Repository repository) { EA.Element result = null; EA.Collection elements = repository.GetTreeSelectedElements(); if (elements.Count > 0) { result = elements.GetAt(0); } else { EA.Diagram diagram = repository.GetCurrentDiagram(); if (diagram != null) { EA.DiagramObject s = diagram.SelectedObjects.GetAt(0); result = repository.GetElementByID(s.ElementID); } } return result; }
public void testPropertiesDialog(EA.Repository repository) { int diagramID = repository.GetCurrentDiagram().DiagramID; repository.OpenDiagramPropertyDlg(diagramID); }
// private void showProperties(EA.Repository repository) { outputTabActive(repository); repository.WriteOutput(OUTPUT_NAME, "Tags created:\n", 0); Diagram dia = repository.GetCurrentDiagram(); for (short i = 0; i < dia.DiagramLinks.Count; i++) { DiagramLink diaLink = dia.DiagramLinks.GetAt(i); Connector con = repository.GetConnectorByID(diaLink.ConnectorID); } /*foreach (Package model in repository.Models) repository.WriteOutput(OUTPUT_NAME, "\n\nName of all Elements: ", 0); foreach (Element element in package.Elements) { repository.WriteOutput(OUTPUT_NAME, element.Name, 0); } } }*/ }
//No Tested private short countExistingConnections(EA.Repository repository) { Diagram diagram = repository.GetCurrentDiagram(); return diagram.DiagramLinks.Count; }
public static void insertCDE(EA.Repository m_Repository, QueryServiceControl.QueryServiceManager.dataelement de, EAUtil.INSERT_XSD_TYPE xsdType) { try { string id = de.names.id; string name = de.names.preferred; string definition = QueryServiceControl.QueryServiceControl.getDefinition(de.definition); EA.Package package = m_Repository.GetPackageByID(m_Repository.GetCurrentDiagram().PackageID); EA.Element o = (EA.Element)package.Elements.AddNew(name.Replace(" ", "_"), "Class"); o.Notes = definition + " (ID: " + id + ")"; EAUtil.addTaggedValue("CDERef", id, o); EAUtil.addTaggedValue("preferred name", name, o); if (package.StereotypeEx == "XSDschema") { if (xsdType == EAUtil.INSERT_XSD_TYPE.TOP_LEVEL_ELEMENT) { o.Stereotype = "XSDtopLevelElement"; } else if (xsdType == EAUtil.INSERT_XSD_TYPE.TOP_LEVEL_ATTRIBUTE) { o.Stereotype = "XSDtopLevelAttribute"; } } if (de.values != null && de.values.Item is QueryServiceControl.QueryServiceManager.nonenumerated) { string dataType = (de.values.Item as QueryServiceControl.QueryServiceManager.nonenumerated).datatype; if (dataType.StartsWith("xs:"))// || dataType.StartsWith("xsd:")) { //o.Genlinks = "Parent=" + dataType.Substring(dataType.IndexOf(":") + 1) + ";"; string simpleTypeClassName = name.Replace(" ", "_") + "_Type"; EA.Element simpleTypeClass = (EA.Element)package.Elements.AddNew(simpleTypeClassName, "Class"); simpleTypeClass.Stereotype = "XSDsimpleType"; simpleTypeClass.Genlinks = "Parent=" + dataType.Substring(dataType.IndexOf(":") + 1) + ";"; simpleTypeClass.Update(); simpleTypeClass.Refresh(); EA.DiagramObject simpleTypeDiag = (EA.DiagramObject)(m_Repository.GetCurrentDiagram().DiagramObjects.AddNew("", "")); simpleTypeDiag.ElementID = simpleTypeClass.ElementID; simpleTypeDiag.Update(); EA.Connector simpleTypeConnector = (EA.Connector)o.Connectors.AddNew("", "Generalization"); simpleTypeConnector.SupplierID = simpleTypeDiag.ElementID; simpleTypeConnector.Update(); o.Connectors.Refresh(); } else { o.Genlinks = "Parent=" + dataType + ";"; } } else if (de.values != null && de.values.Item is QueryServiceControl.QueryServiceManager.enumerated) { string enumClassName = "Enum_" + name.Replace(" ", "_"); EA.Element enumClass = (EA.Element)package.Elements.AddNew(enumClassName, "Class"); enumClass.Stereotype = "enumeration"; enumClass.Genlinks = "Parent=string;"; QueryServiceControl.QueryServiceManager.enumerated en = de.values.Item as QueryServiceControl.QueryServiceManager.enumerated; foreach (QueryServiceControl.QueryServiceManager.validvalue vv in en.validvalue) { EA.Attribute at = (EA.Attribute)enumClass.Attributes.AddNew("", ""); at.Stereotype = "enum"; at.Name = vv.code; at.Notes = QueryServiceControl.QueryServiceControl.getMeaning(vv.meaning); at.Update(); } enumClass.Attributes.Refresh(); EA.DiagramObject enumDiag = (EA.DiagramObject)(m_Repository.GetCurrentDiagram().DiagramObjects.AddNew("", "")); enumDiag.ElementID = enumClass.ElementID; enumDiag.Update(); EA.Connector enumConnector = (EA.Connector)o.Connectors.AddNew("", "Generalization"); enumConnector.SupplierID = enumDiag.ElementID; enumConnector.Update(); o.Connectors.Refresh(); enumClass.Update(); enumClass.Refresh(); } //attr.Update(); //o.Attributes.Refresh(); o.Update(); o.Refresh(); EA.DiagramObject diagram = (EA.DiagramObject)(m_Repository.GetCurrentDiagram().DiagramObjects.AddNew("", "")); diagram.ElementID = o.ElementID; diagram.Update(); m_Repository.ReloadDiagram(diagram.DiagramID); //this.Close(); } catch (Exception exp) { MessageBox.Show("Please make sure you have an active diagram openned." + "\n" + exp.Message + "\n" + exp.StackTrace, "No active diagram currently selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//deprecated public static void insertCDE(EA.Repository m_Repository, XElement node, EAUtil.INSERT_XSD_TYPE xsdType) { try { string id = node.Element(rs + "names").Element(rs + "id").Value; string name = node.Element(rs + "names").Element(rs + "preferred").Value; string definition = node.Element(rs + "definition").Value; if (definition == null || definition.Length == 0) { definition = "(No definition supplied)"; } else { //Handle special caDSR format definition = definition.Trim().Replace(">", ">").Replace("<", "<").Replace("<![CDATA[", "").Replace("]]>", ""); if (definition.Contains("<def-source>")) { XElement e = XElement.Parse("<def>" + definition + "</def>"); definition = e.Element("def-definition").Value + "\n(Source: " + e.Element("def-source").Value + ")"; } } EA.Package package = m_Repository.GetPackageByID(m_Repository.GetCurrentDiagram().PackageID); EA.Element o = (EA.Element)package.Elements.AddNew(name.Replace(" ", "_"), "Class"); o.Notes = definition + " (ID: " + id + ")"; EAUtil.addTaggedValue("CDERef", id, o); EAUtil.addTaggedValue("preferred name", name, o); if (package.StereotypeEx == "XSDschema") { if (xsdType == EAUtil.INSERT_XSD_TYPE.TOP_LEVEL_ELEMENT) { o.Stereotype = "XSDtopLevelElement"; } else if (xsdType == EAUtil.INSERT_XSD_TYPE.TOP_LEVEL_ATTRIBUTE) { o.Stereotype = "XSDtopLevelAttribute"; } } if (node.Element(rs + "values").Element(rs + "non-enumerated") != null) { string dataType = node.Element(rs + "values").Element(rs + "non-enumerated").Element(rs + "data-type").Value; if (dataType.StartsWith("xs:"))// || dataType.StartsWith("xsd:")) { //o.Genlinks = "Parent=" + dataType.Substring(dataType.IndexOf(":") + 1) + ";"; string simpleTypeClassName = name.Replace(" ", "_") + "_Type"; EA.Element simpleTypeClass = (EA.Element)package.Elements.AddNew(simpleTypeClassName, "Class"); simpleTypeClass.Stereotype = "XSDsimpleType"; simpleTypeClass.Genlinks = "Parent=" + dataType.Substring(dataType.IndexOf(":") + 1) + ";"; simpleTypeClass.Update(); simpleTypeClass.Refresh(); EA.DiagramObject simpleTypeDiag = (EA.DiagramObject)(m_Repository.GetCurrentDiagram().DiagramObjects.AddNew("", "")); simpleTypeDiag.ElementID = simpleTypeClass.ElementID; simpleTypeDiag.Update(); EA.Connector simpleTypeConnector = (EA.Connector)o.Connectors.AddNew("", "Generalization"); simpleTypeConnector.SupplierID = simpleTypeDiag.ElementID; simpleTypeConnector.Update(); o.Connectors.Refresh(); } else { o.Genlinks = "Parent=" + dataType + ";"; } } else if (node.Element(rs + "values").Element(rs + "enumerated") != null) { string enumClassName = "Enum_" + name.Replace(" ", "_"); EA.Element enumClass = (EA.Element)package.Elements.AddNew(enumClassName, "Class"); enumClass.Stereotype = "enumeration"; enumClass.Genlinks = "Parent=string;"; foreach (XElement n in node.Element(rs + "values").Element(rs + "enumerated").Elements(rs + "valid-value")) { EA.Attribute at = (EA.Attribute)enumClass.Attributes.AddNew("", ""); at.Stereotype = "enum"; at.Name = n.Element(rs + "code").Value; at.Notes = n.Element(rs + "meaning").Value; at.Update(); } enumClass.Attributes.Refresh(); EA.DiagramObject enumDiag = (EA.DiagramObject)(m_Repository.GetCurrentDiagram().DiagramObjects.AddNew("", "")); enumDiag.ElementID = enumClass.ElementID; enumDiag.Update(); EA.Connector enumConnector = (EA.Connector)o.Connectors.AddNew("", "Generalization"); enumConnector.SupplierID = enumDiag.ElementID; enumConnector.Update(); o.Connectors.Refresh(); enumClass.Update(); enumClass.Refresh(); } //attr.Update(); //o.Attributes.Refresh(); o.Update(); o.Refresh(); EA.DiagramObject diagram = (EA.DiagramObject)(m_Repository.GetCurrentDiagram().DiagramObjects.AddNew("", "")); diagram.ElementID = o.ElementID; diagram.Update(); m_Repository.ReloadDiagram(diagram.DiagramID); //this.Close(); } catch (Exception exp) { MessageBox.Show("Please make sure you have an active diagram openned." + "\n" + exp.Message + "\n" + exp.StackTrace, "No active diagram currently selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }