/** * Load a Profile Definition model from a MAX file. * The MAX file contains a HL7-ProfileDefinition. */ public static Base.R2ProfileDefinition LoadProfileDefinition(Base.R2Model baseModel, string maxFileName) { XmlSerializer serializer = new XmlSerializer(typeof(ModelType)); StreamReader stream = new StreamReader(maxFileName); ModelType sourceModel; using (stream) { sourceModel = (ModelType)serializer.Deserialize(stream); } ObjectType profDefObj = sourceModel.objects.Single(o => R2Const.ST_FM_PROFILEDEFINITION.Equals(o.stereotype)); R2ProfileDefinition profileDefinition = new R2ProfileDefinition(profDefObj); foreach (ObjectType objectType in sourceModel.objects) { R2ModelElement modelElement = Create(objectType); if (modelElement != null && !(modelElement is R2RootElement)) { profileDefinition.children.Add(modelElement); // find Base Element if any RelationshipType relType = sourceModel.relationships.SingleOrDefault(r => modelElement.Id.Equals(r.sourceId)); if (relType != null) { string destId = relType.destId; R2ModelElement baseModelElement = baseModel.children.SingleOrDefault(e => destId.Equals(e.Id)); modelElement.BaseElement = baseModelElement; modelElement.IsCompilerInstruction = true; } } } return(profileDefinition); }
//This event occurs when a user has double-clicked (or pressed [Enter]) //on the item in context, either in a diagram or in the Project Browser. public bool EA_OnContextItemDoubleClicked(EA.Repository repository, string GUID, EA.ObjectType ot) { if (ot == EA.ObjectType.otElement) { EA.Element element = repository.GetElementByGuid(GUID); R2ModelElement modelElement = R2ModelV2.EA_API.Factory.Create(repository, element); if (modelElement != null) { switch (modelElement.Stereotype) { case R2Const.ST_SECTION: // For Section Compiler Instruction! new SectionForm().Show((R2Section)modelElement); return(true); case R2Const.ST_HEADER: case R2Const.ST_FUNCTION: new FunctionForm().Show((R2Function)modelElement); return(true); case R2Const.ST_CRITERION: new CriterionForm().Show((R2Criterion)modelElement); return(true); } } } else if (ot == EA.ObjectType.otPackage) { EA.Element element = repository.GetPackageByGuid(GUID).Element; switch (element.Stereotype) { case R2Const.ST_FM_PROFILE: return(false); case R2Const.ST_FM_PROFILEDEFINITION: EA.Package profDefPackage = repository.GetPackageByGuid(GUID); R2ProfileDefinition profDef = (R2ProfileDefinition)R2ModelV2.EA_API.Factory.Create(repository, profDefPackage.Element); profDef.BaseModelName = EAHelper.getAssociatedBaseModelName(repository, profDefPackage); new ProfileMetadataForm().Show(profDef); return(true); case R2Const.ST_SECTION: new SectionForm().Show((R2ModelV2.Base.R2Section)R2ModelV2.EA_API.Factory.Create(repository, element)); return(true); } } return(false); }
public void Show(R2ProfileDefinition profDef) { _profDef = profDef; nameTextBox.Text = _profDef.Name; versionTextBox.Text = _profDef.Version; if (string.IsNullOrEmpty(_profDef.LastModified)) { dateTimePicker1.Value = DateTime.Now; } else { dateTimePicker1.Value = DateTime.Parse(profDef.LastModified); } typeComboBox.Text = _profDef.Type; languageComboBox.Text = _profDef.LanguageTag; rationaleTextBox.Text = _profDef.Rationale; scopeTextBox.Text = _profDef.Scope; prioDefTextBox.Text = _profDef.PrioDef; confClauseTextBox.Text = _profDef.ConfClause; baseModelTextBox.Text = _profDef.BaseModelName; ShowDialog(); }
private void LoadProfileDefinition(string maxFileName) { R2ProfileDefinition profDef = R2ModelV2.MAX.Factory.LoadProfileDefinition(baseModel, maxFileName); profDef.BaseModelName = baseModel.Name; modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].HeaderText = profDef.Name; modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag = profDef; foreach (R2ModelElement element in profDef.children) { int rowNumber = getBaseModelRowNumber(element.GetAlignId()); if (rowNumber == -1) { // Base Model doesnot have this row, add Row at end rowNumber = modelsDataGridView.Rows.Add(); } DataGridViewCell cell = modelsDataGridView.Rows[rowNumber].Cells[COLUMN_MERGED_PROFILE]; cell.Tag = element; cell.Value = element.GetExtId(); if (element is R2Criterion) { R2Criterion criterion = (R2Criterion)element; criterion.ProfileDefinition = profDef; cell.ToolTipText = criterion.Text; } else if (element is R2Function) { R2Function function = (R2Function)element; function.ProfileDefinition = profDef; cell.ToolTipText = function.Name + "\n" + function.Description; } else if (element is R2Section) { R2Section section = (R2Section)element; cell.ToolTipText = section.Name; } } }
/** * Factory method to create correct model class based on the EA.Element */ public static R2ModelElement Create(ObjectType objectType) { R2ModelElement modelElement = null; switch (objectType.stereotype) { case R2Const.ST_FM: modelElement = new R2Model(objectType); break; case R2Const.ST_FM_PROFILEDEFINITION: case R2Const.ST_FM_PROFILE: modelElement = new R2ProfileDefinition(objectType); break; case R2Const.ST_SECTION: modelElement = new R2Section(objectType); break; case R2Const.ST_HEADER: case R2Const.ST_FUNCTION: modelElement = new R2Function(objectType); break; case R2Const.ST_CRITERION: modelElement = new R2Criterion(objectType); break; case R2Const.ST_COMPILERINSTRUCTION: // TODO: baseElement comes from BaseModel, mock to Criterion for now Console.Write("!! R2ModelV2MAX.Create ST_COMPILERINSTRUCTION mocked to Criterion"); modelElement = new R2Criterion(objectType); //modelElement.IsCompilerInstruction = true; break; } return(modelElement); }
/** * Factory method to create correct model class based on the EA.Element */ public static R2ModelElement Create(EA.Repository repository, EA.Element element) { R2ModelElement modelElement = null; switch (element.Stereotype) { case R2Const.ST_FM_PROFILEDEFINITION: modelElement = new R2ProfileDefinition(element); break; case R2Const.ST_SECTION: modelElement = new R2Section(element); break; case R2Const.ST_HEADER: case R2Const.ST_FUNCTION: modelElement = new R2Function(element); break; case R2Const.ST_CRITERION: modelElement = new R2Criterion(element); break; case R2Const.ST_COMPILERINSTRUCTION: int genCount = element.Connectors.Cast <EA.Connector>().Count(c => "Generalization".Equals(c.Type)); if (genCount == 0) { // Try Dependency/Generalization in case this is a Section Compiler instruction genCount = element.Connectors.Cast <EA.Connector>().Count(c => "Dependency".Equals(c.Type) && "Generalization".Equals(c.Stereotype)); if (genCount == 0) { MessageBox.Show(string.Format("{0} is a Compiler Instruction.\nExpected one(1) Generalization to a Base Element.\nFix this manually.", element.Name), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } } else if (genCount > 1) { MessageBox.Show(string.Format("{0} is a Compiler Instruction.\nExpected one(1) Generalization, but got {1}.\nFix this manually.", element.Name, genCount), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } EA.Connector generalization = element.Connectors.Cast <EA.Connector>().SingleOrDefault(c => "Generalization".Equals(c.Type)); // Try Dependency/Generalization in case this is a Section Compiler instruction if (generalization == null) { generalization = element.Connectors.Cast <EA.Connector>().SingleOrDefault(c => "Dependency".Equals(c.Type) && "Generalization".Equals(c.Stereotype)); } EA.Element baseElement = repository.GetElementByID(generalization.SupplierID); switch (baseElement.Stereotype) { case R2Const.ST_SECTION: modelElement = new R2Section(element); modelElement.BaseElement = new R2Section(baseElement); break; case R2Const.ST_HEADER: case R2Const.ST_FUNCTION: modelElement = new R2Function(element); modelElement.BaseElement = new R2Function(baseElement); break; case R2Const.ST_CRITERION: modelElement = new R2Criterion(element); modelElement.BaseElement = new R2Criterion(baseElement); break; } modelElement.IsCompilerInstruction = true; if (repository != null) { modelElement.BaseElement.Path = GetModelElementPath(repository, baseElement); } break; } if (modelElement != null && repository != null) { modelElement.Path = GetModelElementPath(repository, element); // is element is in profile definition package this is a compiler instruction EA.Package ProfileDefinitionPackage = repository.GetPackageByID(((EA.Element)modelElement.SourceObject).PackageID); if (R2Const.ST_FM_PROFILEDEFINITION.Equals(ProfileDefinitionPackage.StereotypeEx)) { modelElement.IsCompilerInstruction = true; // The ProfileType is needed for R2FunctionCI's in the FunctionForm if (modelElement is R2Function) { R2Function function = (R2Function)modelElement; function.ProfileDefinition = (R2ProfileDefinition)Create(EAHelper.repository, ProfileDefinitionPackage.Element); } else if (modelElement is R2Criterion) { R2Criterion criterion = (R2Criterion)modelElement; criterion.ProfileDefinition = (R2ProfileDefinition)Create(EAHelper.repository, ProfileDefinitionPackage.Element); } } } return(modelElement); }
private void saveButton_Click(object sender, EventArgs e) { string fileNameOutput = FileUtil.showFileDialog("Select Profile Definition MAX XML file", "max files (*.xml, *.max)|*.xml;*.max", fileNameMerged, false); if (string.IsNullOrEmpty(fileNameOutput)) { // Save canceled return; } List <ObjectType> objects = new List <ObjectType>(); List <RelationshipType> relationships = new List <RelationshipType>(); R2ProfileDefinition profileDef = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag; string defId = profileDef.Id; ObjectType maxDefObj = (ObjectType)profileDef.SourceObject; maxDefObj.SetTagValue("MAX::ExportDate", Util.FormatLastModified(DateTime.Now)); maxDefObj.SetTagValue("MAX::ExportFile", fileNameOutput); objects.Add(maxDefObj); foreach (DataGridViewRow row in modelsDataGridView.Rows) { R2ModelElement element = (R2ModelElement)row.Cells[1].Tag; if (element != null) { element.SaveToSource(); ObjectType maxObj = (ObjectType)element.SourceObject; maxObj.id = Guid.NewGuid().ToString(); maxObj.parentId = defId; objects.Add(maxObj); // Only create Generalization Relationship if this is a Compiler Instruction if (element.BaseElement != null) { RelationshipType maxRel = new RelationshipType(); maxRel.sourceId = maxObj.id; maxRel.destId = ((ObjectType)element.BaseElement.SourceObject).id; maxRel.type = RelationshipTypeEnum.Generalization; maxRel.typeSpecified = true; relationships.Add(maxRel); } } } // Convert to MAX model ModelType model = new ModelType(); model.exportDate = Util.FormatLastModified(DateTime.Now); model.objects = objects.ToArray(); model.relationships = relationships.ToArray(); // Save Merged profile definition as MAX XML XmlSerializer serializer = new XmlSerializer(typeof(ModelType)); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.NewLineChars = "\n"; using (XmlWriter writer = XmlWriter.Create(fileNameOutput, settings)) { serializer.Serialize(writer, model); } MessageBox.Show("Created Profile Definition MAX file.", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void modelsDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { // Only popup file selection for Base Model and Profiles // There are separate buttons for MergedProfile Definition (== column 1) string defaultFileName = null; switch (e.ColumnIndex) { case COLUMN_BASE_MODEL: // Ask confirmation is Base Model already loaded if (baseModel != null) { if (MessageBox.Show("This action will lose any changes to the Merged Profile that are not saved.\nAre you sure?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } defaultFileName = fileNameBaseModel; break; case COLUMN_MERGED_PROFILE: ProfileMetadataForm form = new ProfileMetadataForm(); R2ProfileDefinition profDef = (R2ProfileDefinition)modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].Tag; if (profDef != null) { form.Show(profDef); modelsDataGridView.Columns[COLUMN_MERGED_PROFILE].HeaderText = profDef.Name; } return; case 2: if (baseModel != null) { defaultFileName = fileNameProfile1; } break; case 3: if (baseModel != null) { defaultFileName = fileNameProfile2; } break; case 4: if (baseModel != null) { defaultFileName = fileNameProfile3; } break; } if (defaultFileName != null) { string fileName = FileUtil.showFileDialog("Select input MAX XML file", "max files (*.xml, *.max)|*.xml;*.max", defaultFileName, true); if (!string.IsNullOrEmpty(fileName)) { Cursor = Cursors.WaitCursor; DataGridViewCellStyle cellStyle = new DataGridViewCellStyle { BackColor = Color.White }; switch (e.ColumnIndex) { case COLUMN_BASE_MODEL: fileNameBaseModel = fileName; ClearColumn(0); ClearColumn(1); ClearColumn(2); ClearColumn(3); ClearColumn(4); LoadBaseModelAndNewMergedProfile(); UpdateStatistics(); break; /* case COLUMN_MERGED_PROFILE: * fileNameMerged = fileName; * ClearColumn(COLUMN_MERGED_PROFILE); * LoadProfileDefinition(fileNameMerged); * break;*/ case 2: fileNameProfile1 = fileName; ClearColumn(e.ColumnIndex); LoadProfile(e.ColumnIndex, fileName, cellStyle); break; case 3: fileNameProfile2 = fileName; ClearColumn(e.ColumnIndex); LoadProfile(e.ColumnIndex, fileName, cellStyle); break; case 4: fileNameProfile3 = fileName; ClearColumn(e.ColumnIndex); LoadProfile(e.ColumnIndex, fileName, cellStyle); break; } UpdateStatistics(); Cursor = Cursors.Default; } } } else if (e.ColumnIndex != -1) { DataGridViewCell cell = modelsDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (cell.Tag is R2Section) { new SectionForm().Show((R2Section)cell.Tag); } else if (cell.Tag is R2Function) { new FunctionForm().Show((R2Function)cell.Tag); } else if (cell.Tag is R2Criterion) { new CriterionForm().Show((R2Criterion)cell.Tag); } // Update content of compare grid, content might be changed in the form updateCompareDataGridView(false, _currentRow, _currentCompareRow); } }