Esempio n. 1
0
        /// <summary>
        /// Translates the name of the type. The returned type name is unique compared to
        /// the results of previous calls of <see cref="TranslateTypeName"/>.
        /// </summary>
        /// <param name="psmClass">The PSM class for which type name should be returned.</param>
        /// <returns></returns>
        public string TranslateTypeName(PSMClass psmClass)
        {
            if (string.IsNullOrEmpty(psmClass.Name))
            {
                Log.AddError(LogMessages.XS_CLASS_NAME_EMPTY);
                return("empty");
            }
            string normalizedTypeName = NormalizeTypeName(psmClass, p => p.Name);

            if (psmClass.Diagram != this.Diagram)
            {
                PSMDiagramReference reference = Diagram.DiagramReferences.FirstOrDefault(r => r.ReferencedDiagram == psmClass.Diagram);
                if (reference != null && !string.IsNullOrEmpty(reference.NamespacePrefix))
                {
                    normalizedTypeName = String.Format("{0}:{1}", reference.NamespacePrefix, normalizedTypeName);
                }
            }

            if (!counters.ContainsKey(normalizedTypeName) || counters[normalizedTypeName] == 0)
            {
                counters[normalizedTypeName] = 1;
                return(String.Format("{0}", normalizedTypeName));
            }
            return(String.Format("{0}{1}", normalizedTypeName, ++counters[normalizedTypeName]));
        }
Esempio n. 2
0
        /// <summary>
        /// Processes selected items (from TreeView) and shows a dialog, where the user
        /// can choose whether to create a new PSMClass or
        /// create a Structural Representative and select the PSMClass to represent
        /// or connect an existing root of a PSM Diagram
        /// </summary>
        public void ResolveRepresentants()
        {
            List <StructuralRepresentativeSelectorData> List = new List <StructuralRepresentativeSelectorData>();
            StructuralRepresentativeSelectorData        D;

            //Look for PSM Classes to represent
            foreach (TreeClasses T in Selected)
            {
                D = new StructuralRepresentativeSelectorData();
                D.Representative    = false;
                D.ExistingRootClass = false;
                D.TreeClass         = T;
                List <PSMClass> possibleRepresented = T.PIMClass.DerivedPSMClasses.Where(PSMClass => PSMClass.Diagram == Controller.Diagram).ToList();

                /* also allow to reference classes from referenced diagrams */
                foreach (PSMDiagramReference diagramReference in ((PSMDiagram)Controller.Diagram).DiagramReferences)
                {
                    PSMDiagramReference reference = diagramReference;
                    possibleRepresented.AddRange(T.PIMClass.DerivedPSMClasses.Where(PSMClass => PSMClass.Diagram == reference.ReferencedDiagram));
                }

                D.PossibleRepresented = possibleRepresented;

                D.PossibleRoots = T.PIMClass.DerivedPSMClasses.Where(
                    PSMClass => PSMClass.Diagram == Controller.Diagram && (Controller.Diagram as PSMDiagram).Roots.Contains(PSMClass) && !PSMClass.SubtreeContains(SourcePSMClass)
                    ).ToList();

                D.RootsSelectionEnabled = D.PossibleRoots.Count > 0;

                if (D.PossibleRepresented.Count > 0) //Add only PSMClasses that are candidates for StructuralRepresentative
                {                                    //Their corresponding PIM classes already have a PSMClass/Representative derived in current diagram
                    D.SelectedRepresentative = D.PossibleRepresented[0];
                    if (D.RootsSelectionEnabled)     //Candidate for Root to child transition
                    {
                        D.SelectedRootClass = D.PossibleRoots[0];
                    }
                    List.Add(D);
                }
            }

            if (List.Count > 0)
            {
                SelectRepresentantDialog dialog = new SelectRepresentantDialog();
                dialog.List.ItemsSource = List;
                dialog.ShowDialog();
            }

            foreach (StructuralRepresentativeSelectorData data in List)
            {
                if (data.Representative)
                {
                    data.TreeClass.Represented = data.SelectedRepresentative;
                }
                if (data.ExistingRootClass)
                {
                    data.TreeClass.RootClass = data.SelectedRootClass;
                }
            }
        }
Esempio n. 3
0
        public DiagramReferenceDialog(PSMDiagramReference diagramReference, PSM_DiagramReferenceController psmDiagramReferenceController, ModelController controller)
        {
            InitializeComponent();
            this.psmDiagramReferenceController = psmDiagramReferenceController;
            this.modelController  = controller;
            this.diagramReference = diagramReference;

            Title = string.Format("DiagramReference: {0}", diagramReference.ReferencedDiagram);

            tbName.Text            = diagramReference.Name;
            tbNamespace.Text       = diagramReference.Namespace;
            tbNamespacePrefix.Text = diagramReference.NamespacePrefix;
            tbSchemaLocation.Text  = diagramReference.SchemaLocation;
            cbLocal.IsChecked      = diagramReference.Local;
            itemsSource            =
                new List <Object>(controller.Project.PSMDiagrams.Where(d => d != diagramReference.ReferencingDiagram));
            cbDiagram.ItemsSource = itemsSource;
            if (diagramReference.ReferencedDiagram != null)
            {
                cbDiagram.SelectedIndex = cbDiagram.Items.IndexOf(diagramReference.ReferencedDiagram);
            }
        }
Esempio n. 4
0
        internal override void CommandOperation()
        {
            if (CreatedDiagramReference == null)
            {
                CreatedDiagramReference = new ElementHolder <PSMDiagramReference>();
            }

            PSMDiagramReference reference = new PSMDiagramReference()
            {
                ReferencedDiagram  = ReferencedDiagram,
                ReferencingDiagram = (PSMDiagram)this.Diagram,
                Name           = ReferencedDiagram.Caption,
                Local          = true,
                SchemaLocation = ReferencedDiagram.Caption + ".xsd"
            };

            CreatedDiagramReference.Element = reference;

            Debug.Assert(CreatedDiagramReference.HasValue);
            Diagram.AddModelElement(reference, ViewHelper);
            AssociatedElements.Add(reference);
        }
 public PSM_DiagramReferenceController(PSMDiagramReference element, DiagramController diagramController) : base(element, diagramController)
 {
 }