private void OnMenuGoToCode(object sender, EventArgs e) { if (ObjectModelBrowser.SelectedNode is EFModelElementTreeNode elementNode) { switch (elementNode.RepresentedElement) { case ModelClass modelClass: if (!EFModelDocData.OpenFileFor(modelClass)) { EFModelDocData.ShowError(modelClass.Store, $"Can't open generated file for {modelClass.Name}"); } break; case ModelAttribute modelAttribute: if (!EFModelDocData.OpenFileFor(modelAttribute.ModelClass)) { EFModelDocData.ShowError(modelAttribute.Store, $"Can't open generated file for {modelAttribute.ModelClass.Name}"); } break; case ModelEnum modelEnum: if (!EFModelDocData.OpenFileFor(modelEnum)) { EFModelDocData.ShowError(modelEnum.Store, $"Can't open generated file for {modelEnum.Name}"); } break; case ModelEnumValue modelEnumValue: if (!EFModelDocData.OpenFileFor(modelEnumValue.Enum)) { EFModelDocData.ShowError(modelEnumValue.Store, $"Can't open generated file for {modelEnumValue.Enum.Name}"); } break; } } }
protected override void OnSelectionChanged(EventArgs e) { base.OnSelectionChanged(e); // select element in tree if (PrimarySelection != null) { switch (PrimarySelection) { case ModelDiagramData modelDiagramData: // user selected a diagram. Open it. EFModelDocData docData = (EFModelDocData)TreeContainer.ModelingDocData; docData.OpenView(Constants.LogicalView, new Mexedge.VisualStudio.Modeling.ViewContext(modelDiagramData.Name, typeof(EFModelDiagram), docData.RootElement)); break; case ModelClass modelClass: // user selected a class. Find it in the current diagram, center it and make it visible modelClass.LocateInDiagram(true); // then fix up the compartments since they might need it ModelElement[] classElements = { modelClass }; CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "AttributesCompartment", false); CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "AssociationsCompartment", false); CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "SourcesCompartment", false); break; case ModelEnum modelEnum: // user selected an enum. Find it in the current diagram, center it and make it visible modelEnum.LocateInDiagram(true); // then fix up the compartment since it might need it ModelElement[] enumElements = { modelEnum }; CompartmentItemAddRule.UpdateCompartments(enumElements, typeof(EnumShape), "ValuesCompartment", false); break; } } }
/// <summary>Raises the <see cref="E:System.Windows.Forms.Control.DoubleClick" /> event.</summary> /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data. </param> protected override void OnDoubleClick(EventArgs e) { base.OnDoubleClick(e); // let's make this a switch so we can more easily extend it to different element types later switch (SelectedElement) { case ModelClass modelClass: EFModelDocData.OpenFileFor(modelClass); break; case ModelAttribute modelAttribute: EFModelDocData.OpenFileFor(modelAttribute.ModelClass); break; case ModelEnum modelEnum: EFModelDocData.OpenFileFor(modelEnum); break; case ModelEnumValue modelEnumValue: EFModelDocData.OpenFileFor(modelEnumValue.Enum); break; } }
protected override void OnSelectionChanged(EventArgs e) { base.OnSelectionChanged(e); // select element in tree if (PrimarySelection != null && PrimarySelection is ModelElement element) { using (Transaction t = element.Store.TransactionManager.BeginTransaction("TreeSelectionChanged")) { Diagram diagram = element.GetActiveDiagramView()?.Diagram; switch (PrimarySelection) { case ModelDiagramData modelDiagramData: // user selected a diagram. Open it. EFModelDocData docData = (EFModelDocData)TreeContainer.ModelingDocData; docData.OpenView(Constants.LogicalView, new Mexedge.VisualStudio.Modeling.ViewContext(modelDiagramData.Name, typeof(EFModelDiagram), docData.RootElement)); break; case ModelClass modelClass: // user selected a class. If it's in the current diagram, find it, center it and make it visible ShapeElement primaryShapeElement = PresentationViewsSubject.GetPresentation(modelClass) .OfType <ShapeElement>() .FirstOrDefault(s => s.Diagram == diagram); //if (primaryShapeElement == null || !primaryShapeElement.IsVisible) // break; modelClass.LocateInDiagram(true); // then fix up the compartments since they might need it ModelElement[] classElements = { modelClass }; CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "AttributesCompartment", false); CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "AssociationsCompartment", false); CompartmentItemAddRule.UpdateCompartments(classElements, typeof(ClassShape), "SourcesCompartment", false); // any associations to visible classes on this diagram need to be visible as well foreach (NavigationProperty navigationProperty in modelClass.LocalNavigationProperties()) { ModelClass other = navigationProperty.AssociationObject.Source == modelClass ? navigationProperty.AssociationObject.Target : navigationProperty.AssociationObject.Source; // should never happen if (other == null) { continue; } ShapeElement shapeElement = PresentationViewsSubject.GetPresentation(other) .OfType <ShapeElement>() .FirstOrDefault(s => s.Diagram == diagram); if (shapeElement != null && shapeElement.IsVisible) { ShapeElement connectorElement = PresentationViewsSubject.GetPresentation(navigationProperty.AssociationObject) .OfType <AssociationConnector>() .FirstOrDefault(s => s.Diagram == diagram); connectorElement?.Show(); } } // so do generalizations, as long as both classes are available foreach (Generalization generalization in modelClass.Store.ElementDirectory.AllElements.OfType <Generalization>().Where(g => g.Superclass == modelClass || g.Subclass == modelClass)) { ModelClass other = generalization.Superclass == modelClass ? generalization.Subclass : generalization.Superclass; // should never happen if (other == null) { continue; } ShapeElement shapeElement = PresentationViewsSubject.GetPresentation(other) .OfType <ShapeElement>() .FirstOrDefault(s => s.Diagram == diagram); if (shapeElement != null && shapeElement.IsVisible) { ShapeElement connectorElement = PresentationViewsSubject.GetPresentation(generalization) .OfType <GeneralizationConnector>() .FirstOrDefault(s => s.Diagram == diagram); connectorElement?.Show(); } } FixUpAllDiagrams.FixUp(diagram, modelClass.ModelRoot, modelClass); break; case ModelEnum modelEnum: // user selected an enum. Find it in the current diagram, center it and make it visible modelEnum.LocateInDiagram(true); // then fix up the compartment since it might need it ModelElement[] enumElements = { modelEnum }; CompartmentItemAddRule.UpdateCompartments(enumElements, typeof(EnumShape), "ValuesCompartment", false); FixUpAllDiagrams.FixUp(diagram, modelEnum.ModelRoot, modelEnum); break; } t.Commit(); } } }
private void OnMenuGenerateCode(object sender, EventArgs e) { EFModelDocData.GenerateCode(); }
private void OnMenuGenerateCode(object sender, EventArgs e) { EFModelDocData.GenerateCode(); CurrentDocView.Frame.Show(); }