/// <summary> /// If a user selects any of the outputs listed by the Add-in, this function will be invoked. /// The function receives the Schema Composer automation interface, which can be used to traverse the schema. /// </summary> /// <param name="Repository"></param> /// <param name="composer"></param> public override void EA_GenerateFromSchema(EA.Repository Repository, EA.SchemaComposer composer, string exports) { try { Schema schema = this.schemaFactory.createSchema(composer, this.settings); UML.Classes.Kernel.Package targetPackage = null; if (this.settings.generateToArtifactPackage) { targetPackage = schema.containerElement?.owningPackage; } else { var targetPackageTag = schema.containerElement?.taggedValues.FirstOrDefault(x => x.name == targetPackageTagName); if (targetPackageTag != null) { targetPackage = targetPackageTag?.tagValue as UML.Classes.Kernel.Package; } } if (targetPackage == null) { targetPackage = this.model.getUserSelectedPackage() as UML.Classes.Kernel.Package; } if (targetPackage != null) { //save target package as tagged value on schema artifact if (!this.settings.generateToArtifactPackage) { this.saveTargetPackageTag(schema, targetPackage); } Cursor.Current = Cursors.WaitCursor; bool writable = true; //check if package is writable if (this.settings.checkSecurity) { writable = targetPackage.isCompletelyWritable; if (!writable) { var lockPackageResponse = MessageBox.Show("Package is read-only" + Environment.NewLine + "Would you like to lock the package?" , "Lock target Package?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); //lock the elements immediately if (lockPackageResponse == DialogResult.Yes) { writable = this.makeCompletelyWritable(targetPackage); if (!writable) { //if not writable then inform user and stop further processing; MessageBox.Show("Target package could not be locked", "Target Read-Only", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } //only proceed if target package is writable if (writable) { //check if the already contains classes var response = DialogResult.No; response = MessageBox.Show($"Are you sure you want to generate the subset to package '{targetPackage.name}'?" , "Generate Subset?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (response == DialogResult.Yes) { if (this.EAModel.EAVersion >= 1308) { //disable ui updates to speed up process. Only for v13 or higher this.EAModel.wrappedModel.EnableUIUpdates = false; } //update the subset this.updateMessageSubset(schema, targetPackage); //refresh package to make changes visible Only for v13 or higher if (this.EAModel.EAVersion >= 1308) { targetPackage.refresh(); } //check for any errors or warnings var errorCount = EAOutputLogger.getErrors(this.EAModel, this.settings.outputName).Count(); var warningCount = EAOutputLogger.getWarnings(this.EAModel, this.settings.outputName).Count(); if (errorCount > 0 || warningCount > 0) { MessageBox.Show(this.EAModel.mainEAWindow, $"Generation resulted in {errorCount} errors and {warningCount} warnings.\nPlease check the output log" , "Errors or Warnings!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } Cursor.Current = Cursors.Default; } } catch (Exception e) { processException(e); } finally { if (this.EAModel.EAVersion >= 1308) { //re-enable gui updates. Only for V13 or higher this.EAModel.wrappedModel.EnableUIUpdates = true; } } }