/// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        public ModelContextViewModel(ViewModelStore viewModelStore, BaseModelContext baseModelContext, bool isLocked)
            : base(viewModelStore)
        {
            this.modelContext = baseModelContext;
            
            this.copyCommand = new DelegateCommand(CopyCommand_Executed, CopyCommand_CanExecute);
            this.pasteCommand = new DelegateCommand(PasteCommand_Executed, PasteCommand_CanExecute);
            this.copyAllTreeCommand = new DelegateCommand(CopyAllTreeCommand_Executed, CopyAllTreeCommand_CanExecute);
            this.copyEmbeddingTreeCommand = new DelegateCommand(CopyEmbeddingTreeCommand_Executed, CopyAllTreeCommand_CanExecute);
            this.copyReferenceTreeCommand = new DelegateCommand(CopyReferenceTreeCommand_Executed, CopyAllTreeCommand_CanExecute);
            //this.cutCommand = new DelegateCommand(CutCommand_Executed, CutCommand_CanExecute);
            this.optimizeCommand = new DelegateCommand(OptimizeCommand_Executed);

            if (baseModelContext is ModelContext)
            {
                ModelContext modelContext = baseModelContext as ModelContext;

                this.modelTreeViewModel = new ModelTreeViewModel(viewModelStore, this, modelContext.ViewContext.DomainModelTreeView);
                this.modelTreeViewModel.IsLocked = isLocked;
                this.diagramViewModel = new DiagramViewModel(viewModelStore, this, modelContext.ViewContext.DiagramView);
                this.serializationViewModel = new SerializationViewModel(viewModelStore, modelContext.SerializationModel);

                this.modelContextType = ModelContextViewType.ModelContext;
            }
            else if( baseModelContext is ExternModelContext)
            {
                ExternModelContext modelContext = baseModelContext as ExternModelContext;
                if (modelContext.ModelContext != null)
                {
                    this.AddModelContext(modelContext.ModelContext);
                }

            	this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ExternModelContextReferencesModelContext.DomainClassId),
                	true, this.modelContext.Id, new System.Action<ElementAddedEventArgs>(OnModelContextAdded));
                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ExternModelContextReferencesModelContext.DomainClassId),
                	true, this.modelContext.Id, new System.Action<ElementDeletedEventArgs>(OnModelContextRemoved));
                this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(ExternModelContextReferencesModelContext.ExternModelContextDomainRoleId),
                	new System.Action<RolePlayerChangedEventArgs>(OnModelContextChanged));
                this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(ExternModelContextReferencesModelContext.ModelContextDomainRoleId),
                	new System.Action<RolePlayerChangedEventArgs>(OnModelContextChanged));                

                this.modelContextType = ModelContextViewType.ExternModelContext;
                
            }
            else if (baseModelContext is LibraryModelContext)
            {
                LibraryModelContext modelContext = baseModelContext as LibraryModelContext;
                this.modelTreeViewModel = new ModelTreeViewModel(viewModelStore, this, modelContext.ViewContext.DomainModelTreeView);
                this.modelTreeViewModel.IsLocked = isLocked;
                this.diagramViewModel = new DiagramViewModel(viewModelStore, this, modelContext.ViewContext.DiagramView);
                this.modelContextType = ModelContextViewType.LibraryContext;
                this.serializationViewModel = new SerializationViewModel(viewModelStore, modelContext.SerializationModel);
            }

            this.selectedItem = this.ModelTreeViewModel;

            if( this.ModelContext != null )
                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(
                    this.Store.DomainDataDirectory.GetDomainProperty(BaseModelContext.NameDomainPropertyId), this.ModelContext.Id, new System.Action<ElementPropertyChangedEventArgs>(NamePropertyChanged));
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="serializedRelationship">SerializedRelationship.</param>
        /// <param name="referencedElement">Element that is referenced by the serialization element. Can be null.</param>
        protected SerializedRelationshipViewModel(ViewModelStore viewModelStore, SerializedRelationship serializedRelationship, DomainRelationship referencedElement, SerializationClassViewModel parent)
            : base(viewModelStore, serializedRelationship, referencedElement, parent)
        {
            if (this.SerializationElement != null)
            {
                // subscribe
                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.SerializationElement.Id, new Action<ElementPropertyChangedEventArgs>(OnSerializationRelationshipropertyChanged));

                if (this.SerializationElement.SerializedDomainRoles.Count > 0)
                {
                    sourceRoleVM = new SerializedDomainRoleViewModel(this.ViewModelStore, this.SerializationElement.SerializedDomainRoles[0], referencedElement, this);
                    this.AddChild(sourceRoleVM);
                }

                if (this.SerializationElement.SerializedDomainRoles.Count > 1)
                {
                    targetRoleVM = new SerializedDomainRoleViewModel(this.ViewModelStore, this.SerializationElement.SerializedDomainRoles[1], referencedElement, this);

                    if (targetRoleVM.SerializationElement.SerializationClass is SerializedDomainClass)
                        targetClassVM = new SerializedDomainClassViewModel(this.ViewModelStore, targetRoleVM.SerializationElement.SerializationClass as SerializedDomainClass, this);
                    else if (targetRoleVM.SerializationElement.SerializationClass is SerializedReferenceRelationship)
                        targetClassVM = new SerializedReferenceRelationshipViewModel(this.ViewModelStore, targetRoleVM.SerializationElement.SerializationClass as SerializedReferenceRelationship, this);

                    this.AddChild(targetRoleVM);
                }
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="modelTreeView">Diagram tree view.</param>
        public SerializationViewModel(ViewModelStore viewModelStore, SerializationModel serializationModel)
            : base(viewModelStore)
        {
            this.allVMs = new ObservableCollection<SerializedDomainModelViewModel>();
            this.serializationModel = serializationModel;
            this.selectedVMS = new Collection<object>();

            this.rootVMs = new ObservableCollection<SerializedDomainModelViewModel>();
            this.rootVMsRO = new ReadOnlyObservableCollection<SerializedDomainModelViewModel>(this.rootVMs);

            this.selectRelationshipCommand = new DelegateCommand(SelectRelationshipCommand_Executed);
            this.moveUpCommand = new DelegateCommand(MoveUpCommand_Executed, MoveUpCommand_CanExecute);
            this.moveDownCommand = new DelegateCommand(MoveDownCommand_Executed, MoveDownCommand_CanExecute);

            if (this.serializationModel.SerializedDomainModel != null)
            {
                this.rootVMs.Add(new SerializedDomainModelViewModel(this.ViewModelStore, this.serializationModel.SerializedDomainModel));
            }
            if (this.serializationModel != null)
            {
                foreach (SerializationClass c in this.serializationModel.Children)
                    if (c is SerializedDomainClass)
                        this.AddChild(c as SerializedDomainClass);

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationModelHasChildren.DomainClassId),
                    true, this.serializationModel.Id, new System.Action<ElementAddedEventArgs>(OnChildAdded));
                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationModelHasChildren.DomainClassId),
                    true, this.serializationModel.Id, new System.Action<ElementDeletedEventArgs>(OnChildRemoved));
                
            }
        }
 {        /// <summary>
     /// Constuctor.
     /// </summary>
     /// <param name="viewModelStore">The store this view model belongs to.</param>
     /// <param name="serializedRelationship">SerializedRelationship.</param>
     /// <param name="referencedElement">Element that is referenced by the serialization element. Can be null.</param>
     public SerializedReferenceRelationshipViewModel(ViewModelStore viewModelStore, SerializedReferenceRelationship serializedRelationship, SerializationClassViewModel parent)
         : base(viewModelStore, serializedRelationship, serializedRelationship.ReferenceRelationship, parent)
     {
         if( this.SerializationElement != null )
             if (this.SerializationElement.ReferenceRelationship != null)
                 this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.SerializationElement.ReferenceRelationship.Id, new Action<ElementPropertyChangedEventArgs>(OnSerializedReferenceRelationshipPropertyChanged));
     }
        /// <summary>
        /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramTreeNode">Element represented by this view model.</param>
        protected DiagramTreeNodeViewModel(ViewModelStore viewModelStore, DiagramTreeNode diagramTreeNode)
            : base(viewModelStore, diagramTreeNode.PresentationElementClass)
        {
            this.diagramTreeNode = diagramTreeNode;

            if (this.DiagramTreeNode != null)
                if (this.DiagramTreeNode.PresentationElementClass != null)
                {
                    presentationElementClassId = this.DiagramTreeNode.PresentationElementClass.Id;

                    this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ShapeClassReferencesDomainClass.DomainClassId),
                        true, this.DiagramTreeNode.PresentationElementClass.Id, new Action<ElementAddedEventArgs>(OnShapeElementAdded));

                    this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ShapeClassReferencesDomainClass.DomainClassId),
                        true, this.DiagramTreeNode.PresentationElementClass.Id, new Action<ElementDeletedEventArgs>(OnShapeElementRemoved));

                    this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(ShapeClassReferencesDomainClass.DomainClassDomainRoleId),
                        new Action<RolePlayerChangedEventArgs>(OnShapeElementChanged));

                    this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(RelationshipShapeClassReferencesReferenceRelationship.DomainClassId),
                        true, this.DiagramTreeNode.PresentationElementClass.Id, new Action<ElementAddedEventArgs>(OnRSShapeElementAdded));

                    this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(RelationshipShapeClassReferencesReferenceRelationship.DomainClassId),
                        true, this.DiagramTreeNode.PresentationElementClass.Id, new Action<ElementDeletedEventArgs>(OnRSShapeElementRemoved));

                    this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(RelationshipShapeClassReferencesReferenceRelationship.DomainRelationshipDomainRoleId),
                        new Action<RolePlayerChangedEventArgs>(OnRSShapeElementChanged));

                    if (this.DiagramTreeNode.PresentationElementClass is RelationshipShapeClass)
                        AddRSShapeElement((this.DiagramTreeNode.PresentationElementClass as RelationshipShapeClass).ReferenceRelationship);
                    else
                        AddShapeElement((this.DiagramTreeNode.PresentationElementClass as PresentationDomainClassElement).DomainClass);
                }     
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        public MainSurfaceViewModel(ViewModelStore viewModelStore)
            : base(viewModelStore)
        {
            this.rootNodeVMs = new ObservableCollection<ModelContextViewModel>();
            this.rootNodeVMsRO = new ReadOnlyObservableCollection<ModelContextViewModel>(this.rootNodeVMs);

            if (this.ModelData.MetaModel != null)
            {
                foreach (BaseModelContext mc in this.ModelData.MetaModel.ModelContexts)
                    AddModelContext(mc);

                // subscribe
                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(MetaModelHasModelContexts.DomainClassId),
                    true, this.ModelData.MetaModel.Id, new Action<ElementAddedEventArgs>(OnModelContextAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(MetaModelHasModelContexts.DomainClassId),
                    true, this.ModelData.MetaModel.Id, new Action<ElementDeletedEventArgs>(OnModelContextRemoved));

                if (this.ModelContextVMs.Count > 0)
                    this.selectedItem = this.ModelContextVMs[0];
            }


           this.EventManager.GetEvent<SelectionChangedEvent>().Subscribe(new Action<SelectionChangedEventArgs>(OnSelectionChanged));
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>

        public DataTemplateViewModel(ViewModelStore viewModelStore, string templateDisplayName, string dataTemplate)
            : base(viewModelStore)
        {
            this.DisplayName = templateDisplayName;
            this.DataTemplate = dataTemplate;
            this.SyntaxHighlighting = "C#";
        }
 /// <summary>
 /// Constuctor.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="text">Text of the menu item.</param>
 /// <param name="iconUrl">Icon of the menu item.</param>
 public MenuItemViewModel(ViewModelStore viewModelStore, string text, string iconUrl)
     : base(viewModelStore)
 {
     itemText = text;
     itemIconUrl = iconUrl;
     itemChildren = new ObservableCollection<MenuItemViewModel>();
 }
Пример #9
0
        protected override void Load(string fileName, bool isReload)
        {
            MetaModel.BaseGlobalDirectory = MetaModelLibraryBase.GetBaseDirectory(fileName);
            LoadVModell(fileName, isReload);

            MetaModel model = this.RootElement as MetaModel;
            model.IsTopMost = true;

            // set locks to imported libraries
            SetLocksToImportedLibraries(model);
            
            // create model data, store and view model
            ModelData = new ModelData(model);
            ViewModelStore = new ViewModelStore(ModelData);
            ViewModel = new MainSurfaceViewModel(ViewModelStore);

            // register known windows
            try
            {
                IUIVisualizerService popupVisualizer = ViewModel.GlobalServiceProvider.Resolve<IUIVisualizerService>();
                popupVisualizer.Register("TargetSelectorForm", typeof(TargetSelectorForm));
                popupVisualizer.Register("CategorizedSelectionPopup", typeof(CategorizedSelectionPopup));
                popupVisualizer.Register("DiagramClassTemplateSelector", typeof(DiagramClassTemplateSelector));
                popupVisualizer.Register("DataTemplatePresetsPopup", typeof(DataTemplatePresetsPopup));
                popupVisualizer.Register("OptimizationControl", typeof(OptimizationControl));
            }
            catch { }
        }
        /// <summary>
        /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="embeddingDiagramNode">Element represented by this view model.</param>
        public EmbeddingDiagramNodeViewModel(ViewModelStore viewModelStore, EmbeddingDiagramNode embeddingDiagramNode, EmbeddingDiagramNodeViewModel parent)
            : base(viewModelStore, embeddingDiagramNode)
        {
            this.parent = parent;

            this.embeddingNodeVMs = new ObservableCollection<EmbeddingDiagramNodeViewModel>();
            this.embeddingNodeVMsRO = new ReadOnlyObservableCollection<EmbeddingDiagramNodeViewModel>(this.embeddingNodeVMs);

            if (this.EmbeddingDiagramNode != null)
            {
                foreach (EmbeddingDiagramNode node in this.EmbeddingDiagramNode.EmbeddingDiagramNodes)
                    this.AddEmbeddingDiagramNode(node);

                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.EmbeddingDiagramNode.Id, new Action<ElementPropertyChangedEventArgs>(OnElementPropertyChanged));

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(EmbeddingDiagramNodeHasEmbeddingDiagramNodes.DomainClassId),
                    true, this.EmbeddingDiagramNode.Id, new Action<ElementAddedEventArgs>(OnEmbeddingDiagramNodeAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(EmbeddingDiagramNodeHasEmbeddingDiagramNodes.DomainClassId),
                    true, this.EmbeddingDiagramNode.Id, new Action<ElementDeletedEventArgs>(OnEmbeddingDiagramNodeRemoved));

                this.EventManager.GetEvent<ModelRolePlayerMovedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(EmbeddingDiagramNodeHasEmbeddingDiagramNodes.DomainClassId),
                    this.EmbeddingDiagramNode.Id, new Action<RolePlayerOrderChangedEventArgs>(OnEmbeddingDiagramNodeMoved));

                this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(EmbeddingDiagramNodeHasEmbeddingDiagramNodes.SourceEmbeddingDiagramNodeDomainRoleId),
                    new Action<RolePlayerChangedEventArgs>(OnEmbeddingDiagramNodeChanged));
            }

            expandCollapseTreeCommand = new DelegateCommand(ExpandCollapseTreeCommand_Executed);
        }
 /// <summary>
 /// Constuctor.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="ribbonViewModel">Ribbon view model to be assigned to this view.</param>
 protected BaseHostingViewModel(ViewModelStore viewModelStore)
     : base(viewModelStore)
 {
     // init commands
     //activatedCommand = new DelegateCommand(OnActivated);
     loadedCommand = new DelegateCommand(OnLoaded);
     unloadedCommand = new DelegateCommand(OnUnloaded);
 }
        /// <summary>
        /// Constructor. This view model constructed with 'bHookUpEvents=true' does react on model changes.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="element">Element represented by this view model.</param>
        public IncludedDiagramClassViewModel(ViewModelStore viewModelStore, DiagramClass element, DesignerDiagramClass diagramClass)
            : base(viewModelStore, element, true)
        {
            this.diagramClass = diagramClass;
            this.linkId = GetHostedElement().Id;

            this.IsLocked = false;
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="referenceRSNode">ReferenceRSNode.</param>
        /// <param name="parent">Parent.</param>
        public DomainRoleViewModel(ViewModelStore viewModelStore, DomainRole role, DomainRelationshipViewModel parent)
            : base(viewModelStore, role.Relationship)
        {
            this.parentVM = parent;
            this.domainRole = role;

            this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.Role.Id, new Action<ElementPropertyChangedEventArgs>(OnRolePropertyChanged));
        }
 /// <summary>
 /// Constuctor.
 /// </summary>
 /// <param name="viewModelStore">The store this view model belongs to.</param>
 /// <param name="serializedIdProperty">SerializedIdProperty.</param>
 public SerializedIdPropertyViewModel(ViewModelStore viewModelStore, SerializedIdProperty serializedIdProperty, SerializationClassViewModel parent)
     : base(viewModelStore, serializedIdProperty, null, parent)
 {
     if (this.SerializationElement != null)
     {
         // subscribe
         this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.SerializationElement.Id, new Action<ElementPropertyChangedEventArgs>(OnSerializedIdPropertyPropertyChanged));
     }
 }
 {        /// <summary>
     /// Constuctor.
     /// </summary>
     /// <param name="viewModelStore">The store this view model belongs to.</param>
     /// <param name="serializedRelationship">SerializedRelationship.</param>
     /// <param name="referencedElement">Element that is referenced by the serialization element. Can be null.</param>
     public SerializedEmbeddingRelationshipViewModel(ViewModelStore viewModelStore, SerializedEmbeddingRelationship serializedRelationship, SerializationClassViewModel parent)
         : base(viewModelStore, serializedRelationship, serializedRelationship.EmbeddingRelationship, parent)
     {
         if (this.SerializationElement.EmbeddingRelationship != null)
         {
             this.sourceRoleVM = new SerializedDomainRoleViewModel(this.ViewModelStore, this.SerializationElement.EmbeddingRelationship.Source, this.SerializationElement.EmbeddingRelationship, this);
             this.targetRoleVM = new SerializedDomainRoleViewModel(this.ViewModelStore, this.SerializationElement.EmbeddingRelationship.Target, this.SerializationElement.EmbeddingRelationship, this);
         }
     }
        public static CategorizedSelectionViewModel CreateCategorizedVM(MetaModel model, ViewModelStore store, SelectionHelperTarget target)
        {
            // categories for main meta model as well as imported ones
            List<MetaModel> handledMetaModels = new List<MetaModel>();
            List<CategorizedAdvSelectableViewModel> modelCategoryVMs = new List<CategorizedAdvSelectableViewModel>();
            CreateCategorizedVM(model, store, target, handledMetaModels, modelCategoryVMs);

            return new CategorizedSelectionViewModel(store, modelCategoryVMs);
        }
        public static CategorizedSelectionViewModel CreateCategorizedVMWithoutImported(MetaModel model, ViewModelStore store, SelectionHelperTarget target)
        {
            // categories for main meta model as well as imported ones
            List<CategorizedAdvSelectableViewModel> modelCategoryVMs = new List<CategorizedAdvSelectableViewModel>();
            CategorizedAdvSelectableViewModel modelCategoryVM = CreateCategorizedAdvSelectableVM(model, model.Name, store, target);
            modelCategoryVMs.Add(modelCategoryVM);

            return new CategorizedSelectionViewModel(store, modelCategoryVMs);
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="serializationClass">SerializationClass.</param>
        /// <param name="referencedElement">Element that is referenced by the serialization element. Can be null.</param>
        protected SerializationClassViewModel(ViewModelStore viewModelStore, SerializationClass serializationClass, ModelElement referencedElement, SerializationClassViewModel parent)
            : base(viewModelStore, serializationClass, referencedElement)
        {
            this.childrenVMs = new ObservableCollection<SerializationElementViewModel>();
            this.childrenVMsRO = new ReadOnlyObservableCollection<SerializationElementViewModel>(this.childrenVMs);

            this.attributesVMs = new ObservableCollection<SerializationAttributeElementViewModel>();
            this.attributesVMsRO = new ReadOnlyObservableCollection<SerializationAttributeElementViewModel>(attributesVMs);

            this.parent = parent;

            if (this.SerializationElement != null)
            {
                // Lazy load the child items, if necessary.
                if (this.HasLoadedChildren)
                {
                    this.LoadChildren();
                }
                else if (this.SerializationElement.Children.Count > 0)
                    this.childrenVMs.Add(DummyChild);

                this.LoadAttributes();

                /*
                // Lazy load the attribute items, if necessary.
                if (!this.HasLoadedAttributes)
                {
                    this.LoadAttributes();
                }
                else if (this.SerializationElement.Attributes.Count > 0)
                    this.attributesVMs.Add(DummyAttribute);
                */
               
                // subscribe
                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.SerializationElement.Id, new Action<ElementPropertyChangedEventArgs>(OnSerializationClassPropertyChanged));
                                
                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationClassReferencesChildren.DomainClassId),
                    true, this.SerializationElement.Id, new Action<ElementAddedEventArgs>(OnChildAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationClassReferencesChildren.DomainClassId),
                    true, this.SerializationElement.Id, new Action<ElementDeletedEventArgs>(OnChildRemoved));

                this.EventManager.GetEvent<ModelRolePlayerMovedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationClassReferencesChildren.DomainClassId),
                    this.SerializationElement.Id, new Action<RolePlayerOrderChangedEventArgs>(OnChildMoved));

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationClassReferencesAttributes.DomainClassId),
                    true, this.SerializationElement.Id, new Action<ElementAddedEventArgs>(OnAttributeAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationClassReferencesAttributes.DomainClassId),
                    true, this.SerializationElement.Id, new Action<ElementDeletedEventArgs>(OnAttributeRemoved));

                this.EventManager.GetEvent<ModelRolePlayerMovedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(SerializationClassReferencesAttributes.DomainClassId),
                    this.SerializationElement.Id, new Action<RolePlayerOrderChangedEventArgs>(OnAttributeMoved));
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="modelTreeView">Diagram tree view.</param>
        public DiagramViewModel(ViewModelStore viewModelStore, ModelContextViewModel modelContextVM, DiagramView diagramView)
            : base(viewModelStore)
        {
            this.diagramView = diagramView;
            this.modelContextVM = modelContextVM;
            this.contextMenuOperations = new Collection<MenuItemViewModel>();
            this.selectedVMS = new Collection<object>();

            this.rootNodeVMs = new ObservableCollection<DiagramClassViewModel>();
            this.rootNodeVMsRO = new ReadOnlyObservableCollection<DiagramClassViewModel>(this.rootNodeVMs);

            if (diagramView != null)
            {
                foreach (DiagramClassView view in diagramView.DiagramClassViews)
                    AddDiagramClassView(view);

                // subscribe
                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramViewHasDiagramClassViews.DomainClassId),
                    true, this.diagramView.Id, new Action<ElementAddedEventArgs>(OnDiagramClassViewAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramViewHasDiagramClassViews.DomainClassId),
                    true, this.diagramView.Id, new Action<ElementDeletedEventArgs>(OnDiagramClassViewRemoved));
            }

            addNewDiagramClassCommand = new DelegateCommand(AddNewDiagramClassCommand_Executed);
            addNewDiagramClassFromTemplateCommand = new DelegateCommand(AddNewDiagramClassFromTemplateCommand_Executed);
            addNewShapeClassCommand = new DelegateCommand(AddNewShapeClassCommand_Executed);
            addNewMappingRelationshipShapeClassCommand = new DelegateCommand(AddNewMappingRelationshipShapeClassCommand_Executed);
            addNewRelationshipShapeClassCommand = new DelegateCommand(AddNewRelationshipShapeClassCommand_Executed);
            addNewDomainPropertyCommand = new DelegateCommand(AddNewDomainPropertyCommand_Executed);

            unparentCommand = new DelegateCommand(UnparentCommand_Executed);
            reparentCommand = new DelegateCommand(ReparentCommand_Executed);

            moveUpCommand = new DelegateCommand(MoveUpCommand_Executed);
            moveDownCommand = new DelegateCommand(MoveDownCommand_Executed);

            deleteCommand = new DelegateCommand(DeleteCommand_Executed, DeleteCommand_CanExecute);

            viewPropertiesCommand = new DelegateCommand(ViewPropertiesCommand_Executed);

            addIncludedDDCCommand = new DelegateCommand(AddIncludedDDCCommand_Executed);
            addImportedDCCommand = new DelegateCommand(AddImportedDCCommand_Executed);

            showTemplateHelperCommand = new DelegateCommand(ShowTemplateHelperCommand_Executed);

            addNewDomainClassSEDCommand = new DelegateCommand(AddNewDomainClassSEDCommand_Executed);
            addNewDomainRLForRLShape = new DelegateCommand(AddNewDomainRLForRLShape_Executed);

            UpdateOperations();

            this.EventManager.GetEvent<SelectionChangedEvent>().Subscribe(new Action<SelectionChangedEventArgs>(OnSelectionChanged));
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="referenceRSNode">ReferenceRSNode.</param>
        /// <param name="parent">Parent.</param>
        public DomainRelationshipViewModel(ViewModelStore viewModelStore, DomainRelationship relationship, TreeNodeViewModel parent)
            : base(viewModelStore, relationship)
        {
            this.parentTreeNode = parent;

            if (relationship != null)
            {
                sourceRoleVM = new DomainRoleViewModel(this.ViewModelStore, relationship.Source, this);
                targetRoleVM = new DomainRoleViewModel(this.ViewModelStore, relationship.Target, this);

            }
        }
 private static CategorizedAdvSelectableViewModel CreateCategorizedAdvSelectableVM(MetaModel model, string categoryName, ViewModelStore store, SelectionHelperTarget target)
 {
     List<CategorizedSelectableViewModel> vms = new List<CategorizedSelectableViewModel>();
     foreach (BaseModelContext m in model.ModelContexts)
     {
         if (m is LibraryModelContext)
         {
             vms.Add(CreateCategorizedSelectableVM(m as LibraryModelContext, m.Name, store, target));
         }
     }
     return new CategorizedAdvSelectableViewModel(store, categoryName, vms);
 }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="store"></param>
        /// <param name="optOperations"></param>
        /// <param name="opt"></param>
        public OptimizationMainViewModel(ViewModelStore store, MetamodelProcessor optOperations, List<BaseOptimization> opt)
            : base(store)
        {
            this.optOperations = optOperations;
            this.optList = opt;

            this.prevOptimizationCommand = new DelegateCommand(PrevOptimizationCommand_Executed, PrevOptimizationCommand_CanExecute);
            this.nextOptimizationCommand = new DelegateCommand(NextOptimizationCommand_Executed, NextOptimizationCommand_CanExecute);

            this.PrevOptimizationCommand.RaiseCanExecuteChanged();
            this.NextOptimizationCommand.RaiseCanExecuteChanged();
            this.UpdateCurrentOptimization();
        }
        private static CategorizedSelectableViewModel CreateCategorizedSelectableVM(LibraryModelContext model, string categoryName, ViewModelStore store, SelectionHelperTarget target)
        {
            List<SelectableViewModel> vms = new List<SelectableViewModel>();
            if( (target & SelectionHelperTarget.DomainClass) > 0)
                foreach (DomainClass d in model.Classes)
                {
                    vms.Add(new SelectableViewModel(store, d));
                }


            if( (target & SelectionHelperTarget.EmbeddingRelationship) > 0 ||
                (target & SelectionHelperTarget.ReferenceRelationship) > 0)
                foreach (DomainRelationship r in model.Relationships)
                {
                    if( (target & SelectionHelperTarget.EmbeddingRelationship) > 0 && r is EmbeddingRelationship )
                        vms.Add(new SelectableViewModel(store, r));

                    if ((target & SelectionHelperTarget.ReferenceRelationship) > 0 && r is ReferenceRelationship)
                        vms.Add(new SelectableViewModel(store, r));
                }

            if ((target & SelectionHelperTarget.DiagramClass) > 0 ||
                (target & SelectionHelperTarget.DiagramClassWithoutDerived) > 0)
                foreach(DiagramClass d in model.DiagramClasses)
                {
                    if ((target & SelectionHelperTarget.DiagramClassWithoutDerived) > 0)
                    {
                        if (!(d is DesignerDiagramClass))
                            vms.Add(new SelectableViewModel(store, d));
                    }
                    else
                        vms.Add(new SelectableViewModel(store, d));
                }

            if ((target & SelectionHelperTarget.ShapeClass) > 0 ||
                (target & SelectionHelperTarget.RSShapeClass) > 0 ||
                (target & SelectionHelperTarget.MappingShapeClass) > 0)
                foreach (DiagramClass d in model.DiagramClasses)
                    foreach (PresentationElementClass p in d.PresentationElements)
                    {
                        if( p is ShapeClass && (target & SelectionHelperTarget.ShapeClass) > 0 )
                            vms.Add(new SelectableViewModel(store, p));
                        if (p is RelationshipShapeClass && (target & SelectionHelperTarget.RSShapeClass) > 0)
                            vms.Add(new SelectableViewModel(store, p));
                        if (p is MappingRelationshipShapeClass && (target & SelectionHelperTarget.MappingShapeClass) > 0)
                            vms.Add(new SelectableViewModel(store, p));
                    }

            vms.Sort(CompareByName);
            return new CategorizedSelectableViewModel(store, categoryName, vms);
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public DiagramClassViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView.DiagramClass)
        {
            this.diagramClassView = diagramClassView;
            this.parent = parent;

            this.rootNodeVMs = new ObservableCollection<RootDiagramNodeViewModel>();
            this.rootNodeVMsRO = new ReadOnlyObservableCollection<RootDiagramNodeViewModel>(this.rootNodeVMs);

            this.includedDCVMs = new ObservableCollection<IncludedDiagramClassViewModel>();
            this.includedDCVMsRO = new ReadOnlyObservableCollection<IncludedDiagramClassViewModel>(includedDCVMs);

            this.importedDCCVMs = new ObservableCollection<ImportedDiagramClassViewModel>();
            this.importedDCCVMsRO = new ReadOnlyObservableCollection<ImportedDiagramClassViewModel>(importedDCCVMs);

            if (this.DiagramClassView != null)
            {
                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.DiagramClassView.Id, new Action<ElementPropertyChangedEventArgs>(OnElementPropertyChanged));
                
                if (this.DiagramClassView.DiagramClass != null)
                    this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.DiagramClassView.DiagramClass.Id, new Action<ElementPropertyChangedEventArgs>(OnElementPropertyChanged));

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                    true, this.DiagramClassView.Id, new Action<ElementAddedEventArgs>(OnRootDiagramNodeAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                    true, this.DiagramClassView.Id, new Action<ElementDeletedEventArgs>(OnRootDiagramNodeRemoved));

                this.EventManager.GetEvent<ModelRolePlayerMovedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DiagramClassViewHasRootDiagramNodes.DomainClassId),
                    this.DiagramClassView.Id, new Action<RolePlayerOrderChangedEventArgs>(OnRootDiagramNodeMoved));

                this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(DiagramClassViewHasRootDiagramNodes.DiagramClassViewDomainRoleId),
                    new Action<RolePlayerChangedEventArgs>(OnRootDiagramNodeChanged));
            }

            if (this.GetHostedElement() is DesignerDiagramClass)
            {
                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesIncludedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementAddedEventArgs>(OnIncludedDDCAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesIncludedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementDeletedEventArgs>(OnIncludedDDCRemoved));

                this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesImportedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementAddedEventArgs>(OnImportedDCAdded));

                this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(DesignerDiagramClassReferencesImportedDiagramClasses.DomainClassId),
                    true, this.GetHostedElement().Id, new Action<ElementDeletedEventArgs>(OnImportedDCRemoved));
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="modelTreeView">Domain model tree view.</param>
        public ModelTreeViewModel(ViewModelStore viewModelStore, ModelContextViewModel modelContextVM, DomainModelTreeView modelTreeView)
            : base(viewModelStore)
        {
            this.rootNodeVMs = new ObservableCollection<RootNodeViewModel>();
            this.rootNodeVMsRO = new ReadOnlyObservableCollection<RootNodeViewModel>(rootNodeVMs);

            this.modelContextVM = modelContextVM;
            this.modelTreeView = modelTreeView;
            this.selectedVMS = new Collection<object>();
            this.contextMenuOperations = new Collection<MenuItemViewModel>();

            addNewDomainPropertyCommand = new DelegateCommand(AddNewDomainPropertyCommand_Executed);
            addNewDomainClassCommand = new DelegateCommand(AddNewDomainClassCommand_Executed);
            addNewEmbeddingRSCommand = new DelegateCommand(AddNewEmbeddingRSCommand_Executed);
            addNewEmbeddingRSToExistantCommand = new DelegateCommand(AddNewEmbeddingRSToExistantCommand_Executed);
            addNewReferenceRSCommand = new DelegateCommand(AddNewReferenceRSCommand_Executed);
            addNewReferenceRSToRSCommand = new DelegateCommand(AddNewReferenceRSToRSCommand_Executed);
            addNewInheritanceRSCommand = new DelegateCommand(AddNewInheritanceRSCommand_Executed);
            addNewDerivedElementCommand = new DelegateCommand(AddNewDerivedElementCommand_Executed);

            deleteCommand = new DelegateCommand(DeleteCommand_Executed, DeleteCommand_CanExecute);

            showTemplateHelperCommand = new DelegateCommand(ShowTemplateHelperCommand_Executed);
            /*
            copyCommand = new DelegateCommand(CopyCommand_Executed, CopyCommand_CanExecute);
            pasteCommand = new DelegateCommand(PasteCommand_Executed, PasteCommand_CanExecute);
            */

            bringTreeHereCommand = new DelegateCommand(BringTreeHereCommand_Executed);
            splitTreeCommand = new DelegateCommand(SplitTreeCommand_Executed);
            moveUpCommand = new DelegateCommand(MoveUpCommand_Executed);
            moveDownCommand = new DelegateCommand(MoveDownCommand_Executed);

            viewPropertiesCommand = new DelegateCommand(ViewPropertiesCommand_Executed);

            addMappingToNewRelShapeClassCommand = new DelegateCommand(AddMappingToNewRelShapeClassCommand_Executed);
            addMappingToExtRelShapeClassCommand = new DelegateCommand(AddMappingToExtRelShapeClassCommand_Executed);
            addMappingToNewShapeClassCommand = new DelegateCommand(AddMappingToNewShapeClassCommand_Executed);
            addMappingToExtShapeClassCommand = new DelegateCommand(AddMappingToExtShapeClassCommand_Executed);
            addMappingToNewMappingShapeClassCommand = new DelegateCommand(AddMappingToNewMappingShapeClassCommand_Executed);
            addMappingToExtMappingShapeClassCommand = new DelegateCommand(AddMappingToExtMappingShapeClassCommand_Executed);

            UpdateOperations();

            foreach (RootNode n in modelTreeView.RootNodes)
                this.AddRootNode(n);

            this.EventManager.GetEvent<SelectionChangedEvent>().Subscribe(new Action<SelectionChangedEventArgs>(OnSelectionChanged));
            Subscribe();
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="serializedDomainRole">SerializedDomainRole.</param>
        /// <param name="referencedElement">Element that is referenced by the serialization element. Can be null.</param>
        public SerializedDomainRoleViewModel(ViewModelStore viewModelStore, DomainRole domainRole, DomainRelationship referencedElement, SerializedRelationshipViewModel parentVM)
            : base(viewModelStore, null, referencedElement)
        {
            this.parentVM = parentVM;
            this.domainRole = domainRole;

            if (domainRole != null)
            {
                this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.domainRole.Id, new Action<ElementPropertyChangedEventArgs>(OnSerializedRolePropertyChanged));

                if (this.domainRole.RolePlayer != null)
                    this.EventManager.GetEvent<ModelElementPropertyChangedEvent>().Subscribe(this.domainRole.RolePlayer.Id, new Action<ElementPropertyChangedEventArgs>(OnSerializedRolePropertyChanged));
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="modelTreeView">Domain model tree view.</param>
        /// <param name="parent">Parent node.</param>
        protected TreeNodeViewModel(ViewModelStore viewModelStore, TreeNode treeNode, TreeNodeViewModel parent)
            : base(viewModelStore, treeNode.DomainElement)
        {
            this.treeNode = treeNode;
            this.parentTreeNode = parent;

            this.embeddingRSNodeVMs = new ObservableCollection<EmbeddingRSNodeViewModel>();
            this.embeddingRSNodeVMsRO = new ReadOnlyObservableCollection<EmbeddingRSNodeViewModel>(embeddingRSNodeVMs);

            this.inheritanceNodeVMs = new ObservableCollection<InheritanceNodeViewModel>();
            this.inheritanceNodeVMsRO = new ReadOnlyObservableCollection<InheritanceNodeViewModel>(inheritanceNodeVMs);

            this.referenceRSNodeVMs = new ObservableCollection<ReferenceRSNodeViewModel>();
            this.referenceRSNodeVMsRO = new ReadOnlyObservableCollection<ReferenceRSNodeViewModel>(referenceRSNodeVMs);

            this.shapeClassNodeVMs = new ObservableCollection<ShapeClassNodeViewModel>();
            this.shapeClassNodeVMsRO = new ReadOnlyObservableCollection<ShapeClassNodeViewModel>(shapeClassNodeVMs);

            this.collapseExpandEmbeddingCommand = new DelegateCommand(CollapseExpandEmbeddingCommand_Executed);
            this.collapseExpandReferencingCommand = new DelegateCommand(CollapseExpandReferencingCommand_Executed);
            this.collapseExpandInheritingCommand = new DelegateCommand(CollapseExpandInheritingCommand_Executed);
            this.collapseExpandClassShapeMappingCommand = new DelegateCommand(CollapseExpandClassShapeMappingCommand_Executed);

            if (this.TreeNode != null)
            {
                foreach (EmbeddingRSNode node in this.TreeNode.EmbeddingRSNodes)
                    if (node != null)
                        AddEmbeddingRSNode(node);

                foreach (ReferenceRSNode node in this.TreeNode.ReferenceRSNodes)
                    if (node != null)
                        AddReferenceRSNode(node);

                foreach (InheritanceNode node in this.TreeNode.InheritanceNodes)
                    if (node != null)
                        AddInheritanceNode(node);

                foreach (ShapeClassNode node in this.TreeNode.ShapeClassNodes)
                    if (node != null)
                        AddShapeClassNode(node);



                Subscribe();
            }
        }
        private static void CreateCategorizedVM(MetaModel model, ViewModelStore store, SelectionHelperTarget target, List<MetaModel> handledMetaModels, List<CategorizedAdvSelectableViewModel> modelCategoryVMs)
        {
            if (!handledMetaModels.Contains(model))
            {
                CategorizedAdvSelectableViewModel modelCategoryVM = CreateCategorizedAdvSelectableVM(model, model.Name, store, target);
                modelCategoryVMs.Add(modelCategoryVM);
                handledMetaModels.Add(model);

                // imported models
                foreach (MetaModelLibrary library in model.MetaModelLibraries)
                    if (library.ImportedLibrary != null)
                        if (library.ImportedLibrary is MetaModel)
                            CreateCategorizedVM(library.ImportedLibrary as MetaModel, store, target, handledMetaModels, modelCategoryVMs);
            }
            else
                return;
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="embeddingRSNode">EmbeddingRSNode.</param>
        /// <param name="parent">Parent.</param>
        public EmbeddingRSNodeViewModel(ViewModelStore viewModelStore, EmbeddingRSNode embeddingRSNode, TreeNodeViewModel parent)
            : base(viewModelStore, embeddingRSNode.Relationship, parent)
        {
            this.embeddingRSNode = embeddingRSNode;

            this.embeddingNodeVMs = new ObservableCollection<EmbeddingNodeViewModel>();
            this.embeddingNodeVMsRO = new ReadOnlyObservableCollection<EmbeddingNodeViewModel>(embeddingNodeVMs);

            if (embeddingRSNode != null)
            {
                if (embeddingRSNode.EmbeddingNode != null)
                {
                    AddEmbeddingNode(embeddingRSNode.EmbeddingNode);
                }

                Subscribe();
            }
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="diagramClass">Element to be hosted by this view model.</param>
        public ModalDiagramViewModel(ViewModelStore viewModelStore, DiagramClassView diagramClassView, DiagramViewModel parent)
            : base(viewModelStore, diagramClassView, parent)
        {
            ModalDiagram diagramClass = diagramClassView.DiagramClass as ModalDiagram;
            if (diagramClass.DomainClass != null)
            {
                this.ReferenceVM = new BaseModelElementViewModel(this.ViewModelStore, diagramClass, true);
            }

            this.EventManager.GetEvent<ModelElementLinkAddedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ModalDiagramReferencesDomainClass.DomainClassId),
                true, diagramClass.Id, new Action<ElementAddedEventArgs>(OnReferenceAdded));

            this.EventManager.GetEvent<ModelElementLinkDeletedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRelationship(ModalDiagramReferencesDomainClass.DomainClassId),
                true, diagramClass.Id, new Action<ElementDeletedEventArgs>(OnReferenceRemoved));

            this.EventManager.GetEvent<ModelRolePlayerChangedEvent>().Subscribe(this.Store.DomainDataDirectory.GetDomainRole(ModalDiagramReferencesDomainClass.DomainClassDomainRoleId),
                new Action<RolePlayerChangedEventArgs>(OnReferenceChanged));
        }