private void CustomReferenceModeAddEvent(object sender, ElementAddedEventArgs e) { ModelHasReferenceMode link = e.ModelElement as ModelHasReferenceMode; CustomReferenceMode customReferenceMode = link.ReferenceMode as CustomReferenceMode; if (customReferenceMode != null && !customReferenceMode.IsDeleted && link.Model == this.myModel) { int index = myCustomReferenceModesList.BinarySearch(customReferenceMode, NamedElementComparer <CustomReferenceMode> .CurrentCulture); int insertAt = 0; insertAt = (index < 0) ? ~index : index; myCustomReferenceModesList.Insert(insertAt, customReferenceMode); if (myModify != null) { if (myIDidIt) { myIDidIt = false; myModify(this, BranchModificationEventArgs.InsertItems(this, myCustomReferenceModesList.Count - 1, 1)); if (insertAt != index) { myModify(this, BranchModificationEventArgs.MoveItem(this, myCustomReferenceModesList.Count - 1, insertAt)); } } else { myModify(this, BranchModificationEventArgs.InsertItems(this, insertAt - 1, 1)); } } } }
private void CustomReferenceModeChangeEvent(object sender, ElementPropertyChangedEventArgs e) { CustomReferenceMode customReferenceMode = e.ModelElement as CustomReferenceMode; if (customReferenceMode != null && !customReferenceMode.IsDeleted && customReferenceMode.Model == this.myModel) { if (myModify != null) { Guid attributeId = e.DomainProperty.Id; int column = -1; if (attributeId == CustomReferenceMode.CustomFormatStringDomainPropertyId) { column = (int)Columns.FormatString; } else if (attributeId == CustomReferenceMode.NameDomainPropertyId) { column = (int)Columns.Name; } // The reference mode kind column keys off the relationship between // a reference mode and its kind. The change may also fire here if the // ReferenceMode.KindDisplay is used to change it, but we ignore the // property change in favor of the backing object. if (column != -1) { int row = this.FindReferenceMode(customReferenceMode); myModify(this, BranchModificationEventArgs.DisplayDataChanged(new DisplayDataChangedData(VirtualTreeDisplayDataChanges.Text, this, row, column, 1))); } } } }
private void CustomReferenceModeRemoveEvent(object sender, ElementDeletedEventArgs e) { ModelHasReferenceMode link = e.ModelElement as ModelHasReferenceMode; CustomReferenceMode customReferenceMode = link.ReferenceMode as CustomReferenceMode; if (customReferenceMode != null && link.Model == this.myModel) { int row = this.FindReferenceMode(customReferenceMode); if (row >= 0) { myCustomReferenceModesList.RemoveAt(row); if (myModify != null) { myModify(this, BranchModificationEventArgs.DeleteItems(this, row, 1)); } } } }
/// <summary> /// An IMS event to track the shape element added to the associated /// diagram during this connect action. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ReferenceModeKindChangeEvent(object sender, ElementPropertyChangedEventArgs e) { if (myModify != null) { ReferenceModeKind referenceModeKind = e.ModelElement as ReferenceModeKind; if (referenceModeKind != null && !referenceModeKind.IsDeleted && referenceModeKind.Model == this.myModel) { foreach (ReferenceMode refMode in referenceModeKind.ReferenceModeCollection) { CustomReferenceMode custRefMode = refMode as CustomReferenceMode; if (custRefMode != null) { int row = this.FindReferenceMode(custRefMode); myModify(this, BranchModificationEventArgs.DisplayDataChanged(new DisplayDataChangedData(VirtualTreeDisplayDataChanges.Text, this, row, (int)Columns.FormatString, 1))); } } } } }
/// <summary> /// Sets the custom refernce modes. /// </summary> /// <param name="model"></param> public void SetModel(ORMModel model) { if (model != myModel) { Store newStore = (model == null) ? null : model.Store; if (myStore != null && myStore != newStore && !myStore.Disposed) { ManageStoreEvents(myStore, EventHandlerAction.Remove); } if (newStore != null && newStore != myStore) { ManageStoreEvents(newStore, EventHandlerAction.Add); } this.myModel = model; this.myStore = newStore; int count = myCustomReferenceModesList.Count; this.myCustomReferenceModesList.Clear(); if (myModify != null && count != 0) { myModify(this, BranchModificationEventArgs.DeleteItems(this, 0, count)); } if (model != null) { foreach (ReferenceMode mode in model.ReferenceModeCollection) { CustomReferenceMode customMode = mode as CustomReferenceMode; if (customMode != null) { this.myCustomReferenceModesList.Add(customMode); } } myCustomReferenceModesList.Sort(); } count = myCustomReferenceModesList.Count; if (myModify != null && count != 0) { myModify(this, BranchModificationEventArgs.InsertItems(this, -1, count)); } } }
private void ReferenceModeHasKindChangeEvent(object sender, RolePlayerChangedEventArgs e) { if (myModify != null) { ReferenceModeHasReferenceModeKind link = e.ElementLink as ReferenceModeHasReferenceModeKind; if (link != null) { ReferenceModeKind referenceModeKind = link.Kind; if (referenceModeKind.Model == this.myModel && !link.IsDeleted) { foreach (ReferenceMode refMode in referenceModeKind.ReferenceModeCollection) { CustomReferenceMode custRefMode = refMode as CustomReferenceMode; if (custRefMode != null) { int row = this.FindReferenceMode(custRefMode); myModify(this, BranchModificationEventArgs.DisplayDataChanged(new DisplayDataChangedData(VirtualTreeDisplayDataChanges.Text, this, row, -1, 1))); } } } } } }
VirtualTreeLabelEditData IBranch.BeginLabelEdit(int row, int column, VirtualTreeLabelEditActivationStyles activationStyle) { if (column == (int)Columns.ReferenceModeKind) { ModelElement element = myCustomReferenceModesList[row]; if (element.Store == null) { // Teardown scenario return(VirtualTreeLabelEditData.Invalid); } PropertyDescriptor descriptor = ReferenceModeTypeDescriptor.KindDisplayPropertyDescriptor; TypeEditorHost hostControl = OnScreenTypeEditorHost.Create(descriptor, element, TypeEditorHostEditControlStyle.TransparentEditRegion); hostControl.Flags = VirtualTreeInPlaceControlFlags.DisposeControl | VirtualTreeInPlaceControlFlags.SizeToText | VirtualTreeInPlaceControlFlags.DrawItemText | VirtualTreeInPlaceControlFlags.ForwardKeyEvents; return(new VirtualTreeLabelEditData(hostControl)); } else if (0 != (activationStyle & VirtualTreeLabelEditActivationStyles.ImmediateSelection)) { return(VirtualTreeLabelEditData.DeferActivation); } else if (row == myCustomReferenceModesList.Count) { return(new VirtualTreeLabelEditData("")); } else if (column == (int)Columns.Name) { return(VirtualTreeLabelEditData.Default); } else if (column == (int)Columns.FormatString) { CustomReferenceMode mode = myCustomReferenceModesList[row]; if (mode.Kind.ReferenceModeType != ReferenceModeType.General || mode.CustomFormatString != "{1}") { return(new VirtualTreeLabelEditData(PrettyFormatString(mode, true))); } } return(VirtualTreeLabelEditData.Invalid); }
private int FindReferenceMode(CustomReferenceMode custRefMode) { return(myCustomReferenceModesList.IndexOf(custRefMode)); }
private int FindReferenceMode(CustomReferenceMode custRefMode) { return myCustomReferenceModesList.IndexOf(custRefMode); }