/// <summary> /// Edit element executed. /// </summary> protected virtual void EditElementCommand_Executed() { // update the default values list first. this.UpdateDefaultValuesList(); using (SelectElementViewModel vm = new SelectElementViewModel(this.ViewModelStore, this.DefaultValues)) { vm.Title = "Select a role player"; //if (this.Elements.Count == 1) // vm.Title += " of type " + this.ViewModelStore.ElementTypeProvider.GetTypeDisplayName(this.Elements[0] as ModelElement); bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("SelectElementPopup", vm); if (result == true) { try { using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Update role value - " + this.PropertyName)) { PropertyGridEditorViewModel.SetPropertyValues(this.Elements, this.PropertyName, vm.SelectedElement); transaction.Commit(); } } catch (Exception ex) { System.Windows.MessageBox.Show("Error while adding: " + ex.Message); } } } GC.Collect(); }
/// <summary> /// Delete element executed. /// </summary> protected virtual void AddElementCommand_Executed() { WaitCursor cursor = new WaitCursor(); try { // update the default values list first. this.UpdateDefaultValuesList(); using (SelectElementViewModel vm = new SelectElementViewModel(this.ViewModelStore, this.DefaultValues)) { vm.Title = "Select a role player"; if (this.Elements.Count == 1) if (this.Elements[0] is IDomainModelOwnable) vm.Title += " of type " + (this.Elements[0] as IDomainModelOwnable).DomainElementTypeDisplayName; //vm.Title += " of type " + this.ViewModelStore.GetDomainModelServices(this.Elements[0] as ModelElement).ElementTypeProvider.GetTypeDisplayName( // this.Elements[0] as ModelElement); cursor.Dispose(); cursor = null; bool? result = this.GlobalServiceProvider.Resolve<IUIVisualizerService>().ShowDialog("SelectElementPopup", vm); if (result == true && vm.SelectedElement is ModelElement) { try { using (Transaction transaction = this.Store.TransactionManager.BeginTransaction("Add new relationship")) { RoleAssignment[] roleAssignments = new RoleAssignment[2]; roleAssignments[0] = new RoleAssignment(this.SourceRoleId, this.Elements[0] as ModelElement); roleAssignments[1] = new RoleAssignment(this.TargetRoleId, vm.SelectedElement as ModelElement); this.Store.ElementFactory.CreateElementLink(this.RelationshipDomainClassId, roleAssignments); transaction.Commit(); } } catch (Exception ex) { System.Windows.MessageBox.Show("Error while adding: " + ex.Message); } } } } finally { if( cursor != null ) cursor.Dispose(); } GC.Collect(); }