Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Add association class creation to designer
Browse files Browse the repository at this point in the history
  • Loading branch information
msawczyn committed Jan 2, 2022
2 parents f5a430b + df5e2e0 commit aa53b33
Show file tree
Hide file tree
Showing 48 changed files with 3,508 additions and 565 deletions.
112 changes: 112 additions & 0 deletions src/ActivityLog.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" encoding="utf-16"/>
<xsl:template match="activity">
<head>
<title>Activity Monitor Log</title>
<style type="text/css">
body{ text-align: left; width: 100%; font-family: Verdana, sans-serif; }

table{ border: none; border-collapse: separate; width: 100%; }

tr.title td{ font-size: 24px; font-weight: bold; }

th{ background: #d0d0d0; font-weight: bold; font-size: 10pt; text-align: left; }
tr{ background: #eeeeee}
td, th{ font-size: 8pt; padding: 1px; border: none; }

tr.info td{}
tr.warning td{background-color:yellow;color:black}
tr.error td{background-color:red;color:black}

span {text-decoration:underline}
a:hover{text-transform:uppercase;color: #9090F0;}
</style>
</head>

<body>
<table>
<tr class="title">
<td colspan="7">Activity Monitor Log</td>
</tr>
<tr>
<td colspan="2">infos</td>
<td colspan="5"><xsl:value-of select="count(entry[type='Information'])"/></td>
</tr>
<tr>
<td colspan="2">warnings</td>
<td colspan="5"><xsl:value-of select="count(entry[type='Warning'])"/></td>
</tr>
<tr>
<td colspan="2">errors</td>
<td colspan="5"><xsl:value-of select="count(entry[type='Error'])"/></td>
</tr>
<tr>
<th width="20">#</th>
<th width="50">Type</th>
<th>Description</th>
<th width="280">GUID</th>
<th>Hr</th>
<th>Source</th>
<th>Time (UTC)</th>
</tr>
<xsl:apply-templates/>
</table>

</body>
</xsl:template>

<xsl:template match="entry">
<!-- example
<entry>
<record>136</record>
<time>2004/02/26 00:42:59.706</time>
<type>Error</type>
<source>Microsoft Visual Studio</source>
<description>Loading UI library</description>
<guid>{00000000-0000-0000-0000-000000000000}</guid>
<hr>800a006f</hr>
<path></path>
</entry>
-->
<xsl:choose>

<xsl:when test="type='Information'">
<tr id="info" class="info">
<td><xsl:value-of select="record"/></td>
<td></td>
<xsl:call-template name="row"/>
</tr>
</xsl:when>

<xsl:when test="type='Warning'">
<tr id="warning" class="warning">
<td><xsl:value-of select="record"/></td>
<td>Warning</td>
<xsl:call-template name="row"/>
</tr>
</xsl:when>

<xsl:when test="type='Error'">
<tr id="error" class="error">
<td><xsl:value-of select="record"/></td>
<td>ERROR</td>
<xsl:call-template name="row"/>
</tr>
</xsl:when>

</xsl:choose>

</xsl:template>

<xsl:template name="row">
<td id="description"><xsl:value-of select="description"/><xsl:if test="path"><br/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<xsl:value-of select="path"/></xsl:if></td>
<td id="guid"><xsl:value-of select="guid"/></td>
<td id="hr"><xsl:value-of select="hr"/></td>
<td><xsl:value-of select="source"/></td>
<td><xsl:value-of select="time"/></td>
</xsl:template>

</xsl:stylesheet>
103 changes: 103 additions & 0 deletions src/Dsl/CustomCode/Gestures/ClassShapeDragData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

using Microsoft.VisualStudio.Modeling.Diagrams;

using Sawczyn.EFDesigner.EFModel.Annotations;

namespace Sawczyn.EFDesigner.EFModel
{
internal class ClassShapeDragData
{
private readonly RectangleD initialBoundingBox;
private readonly double cursorXOffset;
private readonly double cursorYOffset;
private readonly List<BidirectionalConnector> priorHighlightedConnectors = new List<BidirectionalConnector>();

public ClassShape ClassShape { get; }

public ClassShapeDragData([NotNull] ClassShape classShape, PointD startingMousePosition)
{
ClassShape = classShape ?? throw new ArgumentNullException(nameof(classShape));

cursorXOffset = startingMousePosition.X - classShape.AbsoluteBoundingBox.Left;
cursorYOffset = startingMousePosition.Y - classShape.AbsoluteBoundingBox.Top;
initialBoundingBox = classShape.AbsoluteBoundingBox;
}

private RectangleD BoundingBoxWithMouseAt(PointD mousePosition)
{
double left = mousePosition.X - cursorXOffset;
double top = mousePosition.Y - cursorYOffset;
RectangleD boundingBox = new RectangleD(left, top, initialBoundingBox.Width, initialBoundingBox.Height);

return boundingBox;
}

public List<BidirectionalConnector> GetBidirectionalConnectorsUnderShape(PointD mousePosition)
{
ModelClass modelClass = (ModelClass)ClassShape?.ModelElement;

if (modelClass == null)
return new List<BidirectionalConnector>();

RectangleD boundingBox = BoundingBoxWithMouseAt(mousePosition);

List<Guid> connectionObjectsWithAssociationClass = modelClass.Store.ElementDirectory.AllElements
.OfType<ModelClass>()
.Where(x => x.IsAssociationClass)
.Select(x => x.DescribedAssociationElementId)
.ToList();

List<BidirectionalConnector> connectors = ClassShape.Store.ElementDirectory.AllElements
.OfType<BidirectionalConnector>()
.Where(c => ((BidirectionalAssociation)c.ModelElement).SourceMultiplicity == Multiplicity.ZeroMany
&& ((BidirectionalAssociation)c.ModelElement).TargetMultiplicity == Multiplicity.ZeroMany
&& !connectionObjectsWithAssociationClass.Contains(((BidirectionalAssociation)c.ModelElement).Id)
&& c.Diagram.Id == ClassShape.Diagram.Id
&& c.AbsoluteBoundingBox.IntersectsWith(boundingBox))
.ToList();

Debug.WriteLine($"{connectors.Count} potential drop target(s)");
return connectors;
}

internal void HighlightActionableClassShapes(PointD mousePosition)
{
List<BidirectionalConnector> connectors = GetBidirectionalConnectorsUnderShape(mousePosition);
HighlightedShapesCollection highlightedShapes = ClassShape.Diagram.ActiveDiagramView.DiagramClientView.HighlightedShapes;

DiagramItem classShapeItem = new DiagramItem(ClassShape);

if (highlightedShapes.Contains(classShapeItem))
{
highlightedShapes.Remove(classShapeItem);
ClassShape.Invalidate();
}

foreach (BidirectionalConnector connector in priorHighlightedConnectors)
{
highlightedShapes.Remove(new DiagramItem(connector));
connector.Invalidate();
}

priorHighlightedConnectors.Clear();

if (connectors.Any())
{
priorHighlightedConnectors.AddRange(connectors);

highlightedShapes.Add(classShapeItem);
ClassShape.Invalidate();

foreach (BidirectionalConnector connector in connectors.Where(c => !highlightedShapes.Contains(new DiagramItem(c))))
{
highlightedShapes.Add(new DiagramItem(connector));
connector.Invalidate();
}
}
}
}
}
11 changes: 6 additions & 5 deletions src/Dsl/CustomCode/Gestures/CompartmentDragMouseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ namespace Sawczyn.EFDesigner.EFModel
/// <summary>
/// Manage the mouse while dragging a compartment item.
/// </summary>
public class CompartmentDragMouseAction<T> : MouseAction where T:CompartmentShape, IMouseActionTarget
public class CompartmentDragMouseAction<T> : MouseAction where T:CompartmentShape, ICompartmentShapeMouseTarget
{
private readonly ModelElement sourceChild;
private readonly T sourceShape;
private RectangleD sourceCompartmentBounds;

// ReSharper disable once StaticMemberInGenericType
private static Cursor _moveCursor;

public CompartmentDragMouseAction(ModelElement sourceChildElement, T sourceParentShape, RectangleD bounds)
: base(sourceParentShape.Diagram)
{
Expand All @@ -22,9 +25,6 @@ public CompartmentDragMouseAction(ModelElement sourceChildElement, T sourceParen
sourceCompartmentBounds = bounds; // For cursor.
}

// ReSharper disable once StaticMemberInGenericType
private static Cursor _moveCursor;

private static Cursor MoveCursor
{
get
Expand All @@ -40,6 +40,7 @@ private static Cursor MoveCursor
return _moveCursor;
}
}

/// <summary>
/// Display an appropriate cursor while the drag is in progress:
/// Up-down arrow if we are inside the original compartment.
Expand Down Expand Up @@ -78,7 +79,7 @@ protected override void OnMouseDown(DiagramMouseEventArgs e)
protected override void OnMouseUp(DiagramMouseEventArgs e)
{
base.OnMouseUp(e);
sourceShape.DoMouseUp(sourceChild, e);
sourceShape.MoveCompartmentItem(sourceChild, e);
Cancel(e.DiagramClientView);
e.Handled = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.VisualStudio.Modeling;
using Microsoft.VisualStudio.Modeling.Diagrams;

namespace Sawczyn.EFDesigner.EFModel
{
public interface ICompartmentShapeMouseTarget
{
void MoveCompartmentItem(ModelElement dragFrom, DiagramMouseEventArgs e);
}
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/Dsl/CustomCode/Partials/Association.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void RedrawItem()

internal IEnumerable<ModelAttribute> GetFKAutoIdentityErrors()
{
if (string.IsNullOrWhiteSpace(FKPropertyName))
return new ModelAttribute[0];
if (string.IsNullOrWhiteSpace(FKPropertyName) || Dependent == null)
return Array.Empty<ModelAttribute>();

return FKPropertyName.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
.Select(name => Dependent.Attributes.FirstOrDefault(a => a.Name == name.Trim()))
Expand Down
Loading

0 comments on commit aa53b33

Please sign in to comment.