Exemplo n.º 1
0
        private static void onNotifyTGGOutermostPackageModified(SQLRepository sqlRepository, EA.Package pkg)
        {
            TGG tgg = new TGG(sqlRepository, sqlRepository.GetPackageByID(pkg.PackageID));

            tgg.loadTreeFromTaggedValue();
            tgg.saveTreeToEATaggedValue(true);
        }
Exemplo n.º 2
0
        private static void onCSPConstraintDoubleClicked(SQLRepository sqlRepository, EA.Element doubleClickedElement)
        {
            TGG tggPackage = new TGG(sqlRepository, EAUtil.getOutermostPackage(doubleClickedElement, sqlRepository));

            tggPackage.loadTreeFromTaggedValue();
            CSPInstanceDialog CSPConstraintDialog = new CSPInstanceDialog(sqlRepository, sqlRepository.GetElementByID(doubleClickedElement.ElementID), new TGGCSPController(tggPackage));

            CSPConstraintDialog.ShowDialog();
        }
Exemplo n.º 3
0
        public static DomainType getDomainOfEClass(SQLRepository repository, SQLElement eClass)
        {
            //Get the TGG Schema diagram
            EA.Diagram tggSchema = repository.GetCurrentDiagram();

            //Get the TGG Project
            SQLPackage tggProject    = repository.GetPackageByID(tggSchema.PackageID);
            SQLPackage parentPackage = repository.GetPackageByID(tggProject.ParentID);

            while (parentPackage.ParentID != 0)
            {
                tggProject    = parentPackage;
                parentPackage = repository.GetPackageByID(tggProject.ParentID);
            }

            TGG tgg = new TGG(repository, tggProject);

            tgg.loadTreeFromTaggedValue();

            String sourceDomainID = tgg.getDomain(DomainType.SOURCE).MetamodelGuid;
            String targetDomainID = tgg.getDomain(DomainType.TARGET).MetamodelGuid;

            SQLPackage currentPackage         = repository.GetPackageByID(eClass.PackageID);
            SQLPackage parentOfCurrentPackage = repository.GetPackageByID(currentPackage.ParentID);

            while (parentOfCurrentPackage.ParentID != 0)
            {
                currentPackage         = parentOfCurrentPackage;
                parentOfCurrentPackage = repository.GetPackageByID(parentOfCurrentPackage.ParentID);
            }

            SQLPackage modelOfTheEClass = currentPackage;

            Boolean isSource = sourceDomainID == modelOfTheEClass.PackageGUID;
            Boolean isTarget = targetDomainID == modelOfTheEClass.PackageGUID;

            if (isTarget && isSource)
            {
                return(DomainType.UNDEFINED);
            }

            else if (isTarget)
            {
                return(DomainType.TARGET);
            }

            else if (isSource)
            {
                return(DomainType.SOURCE);
            }
            else
            {
                return(DomainType.UNDEFINED);
            }
        }
        public NewTGGProjectDialog(SQLRepository repository, SQLPackage newTggProject)
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.repository    = repository;
            this.newTGGProject = newTggProject;

            this.tgg = new TGG(repository, newTggProject);
            tgg.loadTreeFromTaggedValue();

            InitializeInformation();
        }
Exemplo n.º 5
0
        private void updateMocaTreeFragments()
        {
            // For all packages (recursively!) in TGG and Ecore projects
            foreach (EA.Package p in EAUtil.findAllMoflonPackages(repository))
            {
                SQLPackage p2 = sqlRep.GetPackageByID(p.PackageID);
                if (p.Element.Stereotype == TGGModelingMain.TggSchemaPackageStereotype)
                {
                    TGG tgg = new TGG(sqlRep, p2);
                    tgg.loadTreeFromTaggedValue();
                    tgg.saveTreeToEATaggedValue(false);
                }
                else if (p.Element.Stereotype == TGGModelingMain.TggRulePackageStereotype)
                {
                    TGGRulePackage package = new TGGRulePackage(p2, sqlRep);
                    package.loadTreeFromTaggedValue();
                    package.saveTreeToEATaggedValue(false);
                }
                else
                {
                    EPackage package = new EPackage(p2, sqlRep);
                    package.loadTreeFromTaggedValue();
                    package.saveTreeToEATaggedValue(false);
                }
            }

            foreach (EA.Element eClassElement in EAUtil.findAllEClasses(repository))
            {
                EClass eClass = new EClass(sqlRep.GetElementByID(eClassElement.ElementID), sqlRep);
                eClass.saveTreeToEATaggedValue(false);
            }

            foreach (EA.Element ruleElement in EAUtil.findAllStereotypedElements(repository, TGGModelingMain.TggRuleStereotype))
            {
                TGGRule rule = new TGGRule(sqlRep, sqlRep.GetElementByID(ruleElement.ElementID));
                rule.loadTreeFromTaggedValue();
                rule.saveTreeToEATaggedValue(false);
            }

            foreach (EA.Element corrTypeElement in EAUtil.findAllStereotypedElements(repository, TGGModelingMain.TggCorrespondenceTypeStereotype))
            {
                TGGCorrespondenceType corrType = new TGGCorrespondenceType(sqlRep.GetElementByID(corrTypeElement.ElementID), sqlRep);
                corrType.loadTreeFromTaggedValue();
                corrType.saveTreeToEATaggedValue(false);
            }
        }
Exemplo n.º 6
0
        private void buttonImportCSP_Click(object sender, EventArgs e)
        {
            checkForFunctions();
            if (activateExportImportCSPButton)
            {
                String pathToWrite = Path.GetDirectoryName(repository.ConnectionString);

                OpenFileDialog dialog = new OpenFileDialog();
                dialog.AddExtension     = true;
                dialog.DefaultExt       = "txt";
                dialog.InitialDirectory = pathToWrite;
                dialog.Filter           = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
                dialog.FileName         = "csptemp.txt";

                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    TGG tggPackage = new TGG(repository, repository.GetTreeSelectedPackage());
                    tggPackage.loadTreeFromTaggedValue();

                    String   fileContent = File.ReadAllText(dialog.FileName);
                    MocaNode dummyParent = MocaTreeUtil.mocaNodeFromXmlString(fileContent);
                    foreach (MocaNode cspNode in dummyParent.Children)
                    {
                        CSPConstraint constraint = new CSPConstraint();
                        constraint.deserializeFromMocaTree(cspNode);
                        Boolean alreadyIn = false;
                        foreach (CSPConstraint existingCSP in tggPackage.Constraints)
                        {
                            if (existingCSP.Name == constraint.Name)
                            {
                                alreadyIn = true;
                                break;
                            }
                        }

                        if (!alreadyIn)
                        {
                            tggPackage.Constraints.Add(constraint);
                        }
                    }

                    tggPackage.saveTreeToEATaggedValue(false);
                }
            }
        }
Exemplo n.º 7
0
        private static DomainType determineDomainSimple(SQLRepository repository, TGGObjectVariable tggOv)
        {
            if (tggOv.sqlElement.Stereotype == TGGModelingMain.TggCorrespondenceStereotype)
            {
                return(DomainType.CORRESPONDENCE);
            }

            EClass classifierElement = tggOv.Classifier;

            if (classifierElement != null)
            {
                SQLElement eClass          = repository.GetElementByID(classifierElement.EaElement.ElementID);
                SQLPackage wantedDomainPkg = repository.GetPackageByID(eClass.PackageID);
                while (!wantedDomainPkg.IsModel)
                {
                    wantedDomainPkg = repository.GetPackageByID(wantedDomainPkg.ParentID);
                }

                SQLPackage tggPackage = repository.GetPackageByID(tggOv.sqlElement.PackageID);
                while (!tggPackage.IsModel)
                {
                    tggPackage = repository.GetPackageByID(tggPackage.ParentID);
                }

                TGG tgg = new TGG(repository, tggPackage);
                tgg.loadTreeFromTaggedValue();

                // source metamodel == target metamodel
                if (tgg.getDomain(DomainType.SOURCE).MetamodelGuid == tgg.getDomain(DomainType.TARGET).MetamodelGuid)
                {
                    return(determineDomainUsingPrefixConvention(tggOv, repository));
                }

                if (wantedDomainPkg.PackageGUID == tgg.getDomain(DomainType.SOURCE).MetamodelGuid)
                {
                    return(DomainType.SOURCE);
                }
                else if (wantedDomainPkg.PackageGUID == tgg.getDomain(DomainType.TARGET).MetamodelGuid)
                {
                    return(DomainType.TARGET);
                }
            }

            return(determineDomainUsingPrefixConvention(tggOv, repository));
        }
Exemplo n.º 8
0
        public MocaNode processTggOutermostPackage(SQLPackage tggOutermostPackage)
        {
            backgroundWorker.ReportProgress(0, PersistencyUtil.computePackageUri(tggOutermostPackage, repository));


            this.currentNode = new MocaNode();

            SQLTaggedValue mocaTreeTag = EAEcoreAddin.Util.EAUtil.findTaggedValue(tggOutermostPackage, Main.MoflonExportTreeTaggedValueName);

            TGG tgg = new TGG(repository, tggOutermostPackage);

            tgg.loadTreeFromTaggedValue();
            XmlDocument xmlDoc = MocaTreeUtil.stringToXmlDocument(mocaTreeTag.Notes);

            MocaNode ePackageMocaNode = new MocaNode();

            ePackageMocaNode.deserializeFromXmlTree(xmlDoc.DocumentElement.FirstChild as XmlElement);

            tgg.addAttributesDuringExport(ePackageMocaNode);

            this.currentNode.appendChildNode(ePackageMocaNode);
            foreach (SQLPackage childPackage in tggOutermostPackage.Packages)
            {
                this.currentNode = ePackageMocaNode.getChildNodeWithName(EPackageHelper.PackagesChildNodeName);
                processTggPackage(childPackage);
            }
            foreach (SQLElement childClass in tggOutermostPackage.Elements)
            {
                processTGGPackageFeatures(ePackageMocaNode, childClass);
            }
            SQLTaggedValue moflonExportTag = EAEcoreAddin.Util.EAUtil.findTaggedValue(tggOutermostPackage, MetamodelHelper.MoflonExportTaggedValueName);

            if (moflonExportTag != null)
            {
                ePackageMocaNode.appendChildAttribute(MetamodelHelper.MoflonExportTaggedValueName, moflonExportTag.Value);
            }
            else
            {
                ePackageMocaNode.appendChildAttribute(MetamodelHelper.MoflonExportTaggedValueName, "false");
            }

            return(ePackageMocaNode);
        }
Exemplo n.º 9
0
        private void buttonExportCsp_Click(object sender, EventArgs e)
        {
            checkForFunctions();
            if (activateExportImportCSPButton)
            {
                String cspXmlString = "";

                String pathToWrite = Path.GetDirectoryName(repository.ConnectionString);

                SaveFileDialog dialog = new SaveFileDialog();
                dialog.AddExtension     = true;
                dialog.DefaultExt       = "txt";
                dialog.InitialDirectory = pathToWrite;
                dialog.Filter           = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
                dialog.FileName         = "csptemp.txt";



                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    TGG tggPackage = new TGG(repository, repository.GetTreeSelectedPackage());
                    tggPackage.loadTreeFromTaggedValue();
                    MocaNode dummyNode = new MocaNode();

                    foreach (CSPConstraint constraint in tggPackage.Constraints)
                    {
                        if (constraint.UserDefined)
                        {
                            dummyNode.Children.Add(constraint.serializeToMocaTree(new MocaNode("CSPConstraint")));
                        }
                    }
                    cspXmlString = MocaTreeUtil.mocaNodeToString(dummyNode);

                    pathToWrite = dialog.FileName;
                    File.WriteAllText(pathToWrite, cspXmlString);
                    MessageBox.Show("User defined CSPs are exported to path: " + pathToWrite);
                }
            }
        }
        public override List <String> doRule(SQLPackage eaPackage, SQLWrapperClasses.SQLRepository sqlRepository)
        {
            List <String> results = new List <string>();

            if (eaPackage.Element != null && eaPackage.Element.Stereotype == TGGModelingMain.TggSchemaPackageStereotype)
            {
                TGG tggSchema = new TGG(sqlRepository, eaPackage);
                tggSchema.loadTreeFromTaggedValue();
                if (tggSchema.getDomain(DomainType.SOURCE) == null || tggSchema.getDomain(DomainType.TARGET) == null)
                {
                    results.Add("TGG source/target metamodel definition is invalid");
                }

                SQLPackage sourceMm = sqlRepository.GetPackageByGuid(tggSchema.getDomain(DomainType.SOURCE).MetamodelGuid);
                SQLPackage targetMm = sqlRepository.GetPackageByGuid(tggSchema.getDomain(DomainType.TARGET).MetamodelGuid);

                if (sourceMm == null || targetMm == null)
                {
                    results.Add("TGG source/target metamodel definition is invalid");
                }
            }
            return(results);
        }
Exemplo n.º 11
0
        public bool EA_OnPostNewElement(SQLRepository sqlRepository, EA.Element newElement, EA.Diagram currentDiagram)
        {
            EA.Repository repository = sqlRepository.GetOriginalRepository();

            try
            {
                //a correspondence is created as an instance of CorrespondenceType
                //Therefore its stereotype is at first time "CorrespondenceType"
                //but we want to change it to "Correspondence"

                if (TGGModelingMain.TggRuleDiagramMetatype.Contains(currentDiagram.MetaType))
                {
                    sqlRepository.SuppressEADialogs = true;

                    if (newElement.Type == Main.EAObjectType)
                    {
                        TGGObjectVariable tggOv = null;

                        //drag & drop is used
                        if (newElement.ClassifierID != 0)
                        {
                            SQLElement classifier = sqlRepository.GetElementByID(newElement.ClassifierID);
                            if (classifier.Stereotype == ECOREModelingMain.EClassStereotype)
                            {
                                tggOv                     = new TGGObjectVariable(sqlRepository.GetElementByID(newElement.ElementID), sqlRepository);
                                tggOv.Name                = classifier.Name.ToLower().Substring(0, 1) + classifier.Name.Substring(1, classifier.Name.Length - 1);
                                tggOv.BindingOperator     = BindingOperator.CREATE;
                                this.ObjectVariableDialog = new OvDialog(sqlRepository, tggOv);
                                ObjectVariableDialog.ShowDialog();
                            }
                            else if (classifier.Stereotype == TGGModelingMain.TggCorrespondenceTypeStereotype)
                            {
                                tggOv                     = new TGGCorrespondence(sqlRepository.GetElementByID(newElement.ElementID), sqlRepository);
                                tggOv.Name                = classifier.Name.ToLower().Substring(0, 1) + classifier.Name.Substring(1, classifier.Name.Length - 1);
                                tggOv.BindingOperator     = BindingOperator.CREATE;
                                this.ObjectVariableDialog = new OvDialog(sqlRepository, tggOv);
                                ObjectVariableDialog.ShowDialog();
                            }
                        }
                        else
                        {
                            //toolbox is used
                            if (newElement.Stereotype == TGGModelingMain.TggObjectVariableStereotype)
                            {
                                tggOv = new TGGObjectVariable(sqlRepository.GetElementByID(newElement.ElementID), sqlRepository);
                                this.ObjectVariableDialog = new OvDialog(sqlRepository, tggOv);
                                ObjectVariableDialog.ShowDialog();
                            }
                            else if (newElement.Stereotype == TGGModelingMain.TggCorrespondenceStereotype)
                            {
                                tggOv = new TGGCorrespondence(sqlRepository.GetElementByID(newElement.ElementID), sqlRepository);
                                this.ObjectVariableDialog = new OvDialog(sqlRepository, tggOv);
                                this.ObjectVariableDialog.ShowDialog();
                            }
                            else if (newElement.Stereotype == SDMModelingMain.CSPInstanceStereotype)
                            {
                                TGG tggPackage = new TGG(sqlRepository, EAUtil.getOutermostPackage(newElement, sqlRepository));
                                tggPackage.loadTreeFromTaggedValue();

                                CSPInstanceDialog cspInstanceDialog = new CSPInstanceDialog(sqlRepository, sqlRepository.GetElementByID(newElement.ElementID), new TGGCSPController(tggPackage));
                                cspInstanceDialog.ShowDialog();
                            }
                        }
                    }
                }
                else if (TGGModelingMain.TggRulesDiagramMetatype.Contains(currentDiagram.MetaType))
                {
                    sqlRepository.SuppressEADialogs = true;
                    if (newElement.Type == Main.EAClassType && (newElement.Stereotype == TGGModelingMain.TggRuleStereotype))
                    {
                        newElement = EAUtil.sqlEAObjectToOriginalObject(sqlRepository, newElement) as EA.Element;

                        EA.Diagram ruleDiagram = newElement.Diagrams.AddNew(newElement.Name, TGGModelingMain.TggRuleDiagramMetatype[0]) as EA.Diagram;
                        ruleDiagram.Update();

                        EA_OnNotifyContextItemModified(sqlRepository.GetOriginalRepository(), newElement.ElementGUID, EA.ObjectType.otElement);
                    }
                }
                else if (TGGModelingMain.TggPatternsDiagramMetatype.Contains(currentDiagram.MetaType))
                {
                    sqlRepository.SuppressEADialogs = true;
                }
            }
            catch
            {
            }
            return(true);
        }