Subversion Repositories DevTools

Rev

Rev 2094 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;


namespace EA_DocGen
{
        /// <summary>
        /// Summary description for EA_RelationshipMatrix.
        /// </summary>
        public class EA_RelationshipMatrix
        {
      private EA_Utilities EA_Utils = null;

      // declare option variables
      public string fromIntroText = null;     // This one is optional 
      public string fromPackageGUID = null;
      public string fromToTableTitle = null;  // This one is optional
      public string fromColumnTitle = null;
      public ArrayList fromElementTypes = null;
      public bool fromPackageRecursion = true;
      public EA.Package fromPackage = null;

      public string toIntroText = null;       // This one is optional
      public string toPackageGUID = null;
      public string toFromTableTitle = null;  // This one is optional
      public string toColumnTitle = null;
      public ArrayList toElementTypes = null;
      public bool toPackageRecursion = true;
      public EA.Package toPackage = null;

      private string [] options_string = null;



                public EA_RelationshipMatrix(EA_Utilities EA_UtilsRef)
                {
         EA_Utils = EA_UtilsRef;
         fromElementTypes = new ArrayList();
         toElementTypes = new ArrayList();
                }

      public void reset()
      {
         fromIntroText = null;
         fromPackageGUID = null;
         fromToTableTitle = null;
         fromColumnTitle = null;
         fromElementTypes.Clear();
         fromPackageRecursion = true;
         fromPackage = null;
         toIntroText = null;
         toPackageGUID = null;
         toFromTableTitle = null;
         toColumnTitle = null;
         toElementTypes.Clear();
         toPackageRecursion = true;
         toPackage = null;
      }


      public bool processRelationshipMatrixOptions(EA.Element theElement)
      {
         reset();

         // Extract the control options from the notes of the element
         
         string delimStr = "\n";
         char [] delim = delimStr.ToCharArray();
         options_string = theElement.Notes.ToString().Split(delim,100);
         int i = 0;
         foreach(string s in options_string)
         {
            options_string[i] = s.Trim();
            i++;
         }

         // scan the options string and assign values into the options variables as required
         foreach(string s in options_string)
         {
            if (s.Length > 0 && s != "\n" && s != "\r" && s[0] != '\\')
            {
               // FROM items
               if (s.StartsWith("fromIntroText"))
               {
                  fromIntroText = EA_Utils.options.getOptionValue(s, null);
               }
               else if (s.StartsWith("fromToTableTitle")) 
               {
                  fromToTableTitle = EA_Utils.options.getOptionValue(s, null);
               }
               else if (s.StartsWith("fromColumnTitle")) 
               {
                  fromColumnTitle = EA_Utils.options.getOptionValue(s, fromColumnTitle);
               }
               else if (s.StartsWith("fromPackageRecursion")) 
               {
                  fromPackageRecursion = EA_Utils.options.getOptionValue(s, fromPackageRecursion);
               }
               else if (s.StartsWith("fromPackage")) 
               {
                  fromPackageGUID = EA_Utils.options.getOptionValue(s, fromPackageGUID);
               }
               else if (s.StartsWith("fromElementType")) 
               {
                  string et = EA_Utils.options.getOptionValue(s,null);
                  if (et != null) 
                  {
                     fromElementTypes.Add( et );
                  }
               }


                  // TO items
               else if (s.StartsWith("toIntroText"))
               {
                  toIntroText = EA_Utils.options.getOptionValue(s, null);
               }
               else if (s.StartsWith("toFromTableTitle")) 
               {
                  toFromTableTitle = EA_Utils.options.getOptionValue(s, null);
               }
               else if (s.StartsWith("toColumnTitle")) 
               {
                  toColumnTitle = EA_Utils.options.getOptionValue(s, toColumnTitle);
               }
               else if (s.StartsWith("toPackageRecursion")) 
               {
                  toPackageRecursion = EA_Utils.options.getOptionValue(s, toPackageRecursion);
               }
               else if (s.StartsWith("toPackage")) 
               {
                  toPackageGUID = EA_Utils.options.getOptionValue(s, toPackageGUID);
               }
               else if (s.StartsWith("toElementType")) 
               {
                  string et = EA_Utils.options.getOptionValue(s,null);
                  if (et != null) 
                  {
                     toElementTypes.Add( et );
                  }
               }
            }
         }

         // Verify that we have all the necessary compulsory options
         if (fromToTableTitle == null && toFromTableTitle == null)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option: Must specify at least one table title");
            return false;
         }

         // FROM items
         if (fromColumnTitle == null)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option: fromColumnTitle");
            return false;
         }
         if (fromPackageGUID == null)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option: fromPackageGUID");
            return false;
         }
         if (fromElementTypes.Count == 0)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option(s): fromElementTypes");
            return false;
         }      

         // TO items
         if (toColumnTitle == null)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option: toColumnTitle");
            return false;
         }
         if (toPackageGUID == null)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option: toPackageGUID");
            return false;
         }
         if (toElementTypes.Count == 0)
         {
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
               "Missing option(s): toElementTypes");
            return false;
         }   

         // Find GUID linked packages in the repository
         fromPackage = EA_Utils.EA_Finder.findPackageInRepositoryByGUID( fromPackageGUID );
         if (fromPackage == null)
         {
            MessageBox.Show("Error processing EA_DocGenRelationshipMatrix\n\n" +
               "could not locate fromPackage in Repository");
            return false;
         }

         toPackage = EA_Utils.EA_Finder.findPackageInRepositoryByGUID( toPackageGUID );
         if (toPackage == null)
         {
            MessageBox.Show("Error processing EA_DocGenRelationshipMatrix\n\n" +
               "could not locate toPackage in Repository");
            return false;
         }

         return true;
      }


      public string optionTemplateForRelationshipMatrix()
      {
         return
           "fromToTableTitle=\r\n"
         + "fromIntroText=\r\n"
         + "fromColumnTitle=\r\n"
         + "fromPackage=\r\n"
         + "fromElementType=\r\n"
         + "fromElementType=\r\n"
         + "fromPackageRecursion=true\r\n"
         + "toFromTableTitle=\r\n"
         + "toIntroText=\r\n"
         + "toColumnTitle=\r\n"
         + "toPackage=\r\n"
         + "toElementType=\r\n"
         + "toPackageRecursion=true\r\n";
      }


        }
}