void OnIsDefaultPropertyChanged(DependencyPropertyChangedEventArgs e) { bool isUndoRedoInProgress = this.IsUndoRedoInProgress(); if (!this.internalDefaultCaseChange && !isUndoRedoInProgress) { bool value = (bool)e.NewValue; bool oldValue = (bool)e.OldValue; if (value) { if (object.Equals(this.flowSwitchModelItem.Properties["Default"].Value, null)) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem flowNodeMI = GenericFlowSwitchHelper.GetCaseModelItem(this.flowSwitchModelItem.Properties["Cases"], this.CaseObject); GenericFlowSwitchHelper.RemoveCase(this.flowSwitchModelItem.Properties["Cases"], this.CaseObject); this.flowSwitchModelItem.Properties["Default"].SetValue(flowNodeMI); this.UpdateViewState(this.CaseName + CaseViewStateKeyAppendString, DefaultConnectorViewStateKey); this.internalChange = true; es.Complete(); } } else { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DefaultCaseExists)); } } else { if (oldValue) { using (EditingScope es = (EditingScope)this.flowSwitchModelItem.BeginEdit(SR.FlowSwitchCaseRenameEditingScopeDesc)) { ModelItem defaultCase = this.flowSwitchModelItem.Properties["Default"].Value; object uniqueCase = null; string errorMessage = string.Empty; Type typeArgument = typeof(T); if (GenericFlowSwitchHelper.CanBeGeneratedUniquely(typeArgument)) { string caseName = GenericFlowSwitchHelper.GetCaseName(this.flowSwitchModelItem.Properties["Cases"], typeArgument, out errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(errorMessage)); } uniqueCase = GenericFlowSwitchHelper.GetObject(caseName, typeArgument); } else { FlowSwitchCaseEditorDialog editor = new FlowSwitchCaseEditorDialog(this.flowSwitchModelItem, ((WorkflowViewElement)this.flowSwitchModelItem.View).Context, this.flowSwitchModelItem.View, SR.ChangeCaseValue, this.flowSwitchModelItem.ItemType.GetGenericArguments()[0]); editor.WindowSizeToContent = SizeToContent.WidthAndHeight; if (!editor.ShowOkCancel()) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; return; } uniqueCase = editor.Case; if (GenericFlowSwitchHelper.ContainsCaseKey(this.flowSwitchModelItem.Properties["Cases"], uniqueCase)) { this.internalDefaultCaseChange = true; this.IsDefaultCase = oldValue; throw FxTrace.Exception.AsError(new InvalidOperationException(SR.InvalidFlowSwitchCaseMessage)); } } this.flowSwitchModelItem.Properties["Default"].SetValue(null); this.flowSwitchModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(FlowSwitchLabelFeature.DefaultCaseDisplayNameDefaultValue); this.internalChange = true; if (typeof(string) != typeof(T)) { this.ModelItem.Properties["Case"].SetValue(uniqueCase); GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], uniqueCase, defaultCase.GetCurrentValue()); } else { this.ModelItem.Properties["Case"].SetValue(uniqueCase); GenericFlowSwitchHelper.AddCase(this.flowSwitchModelItem.Properties["Cases"], uniqueCase, defaultCase.GetCurrentValue()); } this.UpdateViewState(DefaultConnectorViewStateKey, GenericFlowSwitchHelper.GetString(uniqueCase, typeof(T)) + CaseViewStateKeyAppendString); es.Complete(); this.internalChange = false; } this.internalDefaultCaseChange = false; } } } this.internalDefaultCaseChange = false; }
void OnViewStateChanged(object sender, ViewStateChangedEventArgs e) { Fx.Assert(this.panel != null, "This code should not be hit if panel is null"); Fx.Assert(e.ParentModelItem != null, "ViewState should be associated with some modelItem"); Connector changedConnector = null; if (e.ParentModelItem == this.ModelItem) { if (string.Equals(e.Key, FlowchartSizeFeature.WidthPropertyName, StringComparison.Ordinal)) { this.FlowchartWidth = (double)TypeDescriptor.GetProperties(this.ModelItem)[FlowchartSizeFeature.WidthPropertyName].GetValue(this.ModelItem); } else if (string.Equals(e.Key, FlowchartSizeFeature.HeightPropertyName, StringComparison.Ordinal)) { this.FlowchartHeight = (double)TypeDescriptor.GetProperties(this.ModelItem)[FlowchartSizeFeature.HeightPropertyName].GetValue(this.ModelItem); } } if ((IsFlowNode(e.ParentModelItem) || this.ModelItem.Equals(e.ParentModelItem)) && !this.internalViewStateChange) { ModelItem itemOnCanvas = this.GetCorrespondingElementOnCanvas(e.ParentModelItem); if (this.modelElement.ContainsKey(itemOnCanvas)) { if (e.Key.Equals(shapeLocation)) { if (e.NewValue != null) { FreeFormPanel.SetLocation(this.modelElement[itemOnCanvas], (Point)e.NewValue); this.panel.InvalidateMeasure(); if (e.OldValue != null) { this.shapeLocations.Remove((Point)e.OldValue); } this.shapeLocations.Add((Point)e.NewValue); } } else { if (this.ModelItem.Equals(e.ParentModelItem) && e.Key.Equals(ConnectorViewStateKey)) { changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["StartNode"].Value, "StartNode"); } else if (typeof(FlowStep).IsAssignableFrom(e.ParentModelItem.ItemType) && e.Key.Equals(ConnectorViewStateKey)) { changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["Next"].Value, "Next"); } else if (typeof(FlowDecision).IsAssignableFrom(e.ParentModelItem.ItemType)) { if (e.Key.Equals(TrueConnectorViewStateKey)) { changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["True"].Value, "True"); } else if (e.Key.Equals(FalseConnectorViewStateKey)) { changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["False"].Value, "False"); } } else if (GenericFlowSwitchHelper.IsGenericFlowSwitch(e.ParentModelItem.ItemType)) { if (e.Key.Equals(FlowchartDesigner.FlowSwitchDefaultViewStateKey, StringComparison.CurrentCulture)) { changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, e.ParentModelItem.Properties["Default"].Value, e.Key); } else if (e.Key.EndsWith(CaseViewStateKeyAppendString, StringComparison.CurrentCulture)) { string switchCaseName = e.Key.Substring(0, e.Key.Length - CaseViewStateKeyAppendString.Length); object switchCase = switchCaseName; Type genericType = e.ParentModelItem.ItemType.GetGenericArguments()[0]; switchCase = GenericFlowSwitchHelper.GetObject(switchCaseName, genericType); if (GenericFlowSwitchHelper.ContainsCaseKey(e.ParentModelItem.Properties["Cases"], switchCase)) { //Prepending with GenericFlowSwitchHelper.FlowSwitchCasesKeyIdentifier to differentiate between the property Default and the key Default. changedConnector = this.GetLinkOnCanvas(e.ParentModelItem, GenericFlowSwitchHelper.GetCaseModelItem(e.ParentModelItem.Properties["Cases"], switchCase), GenericFlowSwitchHelper.FlowSwitchCasesKeyIdentifier + switchCase); } } } } } } if (changedConnector != null) { if (e.NewValue != null) { Fx.Assert(e.NewValue is PointCollection, "e.NewValue is not PointCollection"); changedConnector.Points = e.NewValue as PointCollection; this.panel.RemoveConnectorEditor(); this.panel.InvalidateMeasure(); } } }