Skip to content

Commit

Permalink
Initial stab at getting associations working
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltwin committed Aug 19, 2011
1 parent dd2d7c1 commit 3ff1db4
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 57 deletions.
12 changes: 6 additions & 6 deletions MonoDevelop.ClassDesigner/ClassDiagram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void LoadType (XElement element, ProjectDom dom)
if (startfig == null)
continue;

Add (new AssociationConnectionFigure (property, ConnectionType.Association, startfig, figure));
// Add (new AssociationConnectionFigure (property, ConnectionType.Association, startfig, figure));
}
}

Expand Down Expand Up @@ -515,11 +515,11 @@ void LoadType (XElement element, ProjectDom dom)
else
startfig = CreateTypeFigure (property.ReturnType.Type);

if (startfig is System.Collections.ICollection)
Add (new AssociationConnectionFigure (property, ConnectionType.CollectionAssociation,
startfig, figure));
else
throw new ArgumentException ("The type is not a valid collection.");
// if (startfig is System.Collections.ICollection)
// Add (new AssociationConnectionFigure (property, ConnectionType.CollectionAssociation,
// startfig, figure));
// else
// throw new ArgumentException ("The type is not a valid collection.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ public override bool CanHandle (IEnumerable<IFigure> figures)
}

#region Commands
[CommandHandler (DesignerCommands.ShowAssociation)]
protected void ShowAsAssociation ()
{

}

[CommandHandler (DesignerCommands.ShowAssociationCollection)]
protected void ShowAsAssociationCollection ()
{

}
#endregion
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// MemberCommadns.cs
//
// Author:
// Graham Lyon <graham.lyon@gmail.com>
//
// Copyright (c) 2011 Graham Lyon
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

using System.Collections.Generic;
using System.Linq;

using MonoHotDraw.Figures;

using MonoDevelop.ClassDesigner.Figures;
using MonoDevelop.Components.Commands;
using MonoDevelop.Diagram.Components;
using MonoDevelop.Projects.Dom;

namespace MonoDevelop.ClassDesigner.Commands
{
internal sealed class MemberCommands : FigureCommandHandler
{
public override bool CanHandle (IEnumerable<IFigure> figures)
{
return figures != null && figures.Count () > 0 && figures.All (f => f is MemberFigure);
}

[CommandHandler (DesignerCommands.ShowAssociation)]
protected void ShowAsAssociation ()
{
var designer = (ClassDesigner) Designer;
foreach (var m in SelectedFigures.OfType<MemberFigure> ()) {
var type = designer.Dom.GetType (m.MemberInfo.ReturnType.FullName);
var typeFigure = designer.Diagram.GetTypeFigure (type.FullName)
?? designer.Diagram.CreateTypeFigure (type);
var classFigure = designer.Diagram.GetTypeFigure (m.MemberInfo.DeclaringType.FullName);

designer.Diagram.Add (new AssociationConnectionFigure (m, ConnectionType.Association, classFigure, typeFigure));
}
}

[CommandUpdateHandler (DesignerCommands.ShowAssociation)]
protected void ShowAsAssociationUpdate (CommandInfo info)
{
if (SelectedFigures.OfType<MemberFigure> ().All (f => f.MemberInfo.MemberType == MemberType.Property)) {
info.Visible = info.Enabled = true;
} else {
info.Visible = info.Enabled = false;
}
}

[CommandHandler (DesignerCommands.ShowAssociationCollection)]
protected void ShowAsAssociationCollection ()
{

}

[CommandUpdateHandler (DesignerCommands.ShowAssociationCollection)]
protected void ShowAsAssociationCollectionUpdate (CommandInfo info)
{
info.Visible = info.Enabled = false;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,20 @@
namespace MonoDevelop.ClassDesigner.Figures
{
public sealed class AssociationConnectionFigure : AbstractConnectionFigure
{
bool manual_label_position;
bool manual_label_size;
HStackFigure member_label;
ImageFigure image;
TextFigure name;
ConnectionType type;

{
public AssociationConnectionFigure (ConnectionType connectionType)
{
ConnectionLine = new AssociationLine ();
if (connectionType == ConnectionType.Inheritance)
throw new ArgumentException ("Connection must be of type association or collection");

type = connectionType;
manual_label_size = false;
manual_label_position = false;
Type = connectionType;

Add (ConnectionLine);
SetAttribute (FigureAttribute.Selectable, true);
}

public AssociationConnectionFigure (IBaseMember memberName,
public AssociationConnectionFigure (MemberFigure member,
ConnectionType connectionType,
IFigure startFigure,
IFigure endFigure) : this (connectionType)
Expand All @@ -66,31 +58,26 @@ public AssociationConnectionFigure (IBaseMember memberName,
return;
}

var pixbuf = ImageService.GetPixbuf (memberName.StockIcon, IconSize.Menu);

image = new ImageFigure (pixbuf);
name = new TextFigure (memberName.Name);
member_label = new HStackFigure ();
member_label.Add (image);
member_label.Add (name);
Member = member;

ConnectionLine.ConnectStart (startFigure.ConnectorAt (0.0, 0.0));
ConnectionLine.ConnectEnd (endFigure.ConnectorAt (0.0, 0.0));

type = connectionType;

// FIXME: handle collection setup
//
//if (Type == ConnectionType.CollectionAssociation)
//

Add (MemberLabel);
MemberLabel.MoveTo (ConnectionLine.EndPoint.X - 5.0, ConnectionLine.EndPoint.Y + 10.0);
//FIXME: this isn't quite working yet - startFigure isn't the direct parent of Member...
startFigure.Remove (Member);
Add (Member);
Member.MoveTo (ConnectionLine.EndPoint.X - 5.0, ConnectionLine.EndPoint.Y + 10.0);
Member.SetAttribute (FigureAttribute.Draggable, true);
Member.SetAttribute (FigureAttribute.Selectable, false);
}

public ConnectionType Type {
get { return type; }
}
public ConnectionType Type { get; private set; }
public MemberFigure Member { get; private set; }

public void Show ()
{
Expand All @@ -103,10 +90,6 @@ public void Hide ()
ConnectionLine.DisconnectStart ();
ConnectionLine.DisconnectEnd ();
}

HStackFigure MemberLabel {
get { return member_label; }
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ public IEnumerable<IFigure> AssociationFigures {

public void AddAssociation (IBaseMember member, IFigure associatedFigure, bool AsCollection)
{
AssociationConnectionFigure association;

if (AsCollection)
association = new AssociationConnectionFigure (member, ConnectionType.CollectionAssociation,
this, associatedFigure);
else
association = new AssociationConnectionFigure (member, ConnectionType.Association,
this, associatedFigure);
associations.Add (association);
// AssociationConnectionFigure association;
//
// if (AsCollection)
// association = new AssociationConnectionFigure (member, ConnectionType.CollectionAssociation,
// this, associatedFigure);
// else
// association = new AssociationConnectionFigure (member, ConnectionType.Association,
// this, associatedFigure);
// associations.Add (association);
}

public void RemoveAssociation (IBaseMember member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
<FigureCommand class="MonoDevelop.ClassDesigner.Commands.AssociationCommands" id="IAssociation" />
<FigureCommand class="MonoDevelop.ClassDesigner.Commands.CollapsableCommands" id="ICollaspable" />
<FigureCommand class="MonoDevelop.ClassDesigner.Commands.ClassCommands" id="ClassFigure" />
<FigureCommand class="MonoDevelop.ClassDesigner.Commands.MemberCommands" id="ClassFigure" />
<FigureCommand class="MonoDevelop.Diagram.Commands.ZoomCommands" id="IZoomable" />
</Extension>

Expand Down
3 changes: 2 additions & 1 deletion MonoDevelop.ClassDesigner/MonoDevelop.ClassDesigner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<Compile Include="AssemblyInfo.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Extensions\ShowClassDesignerHandler.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Commands\ClassCommands.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Commands\AssociationCommands.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Figures\InheritanceLine.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Figures\InheritanceConnectionFigure.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Commands\CollapsableCommands.cs" />
Expand All @@ -118,6 +117,8 @@
<Compile Include="MonoDevelop.ClassDesigner.Figures\ISerializableFigure.cs" />
<Compile Include="DeserializationException.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Figures\FigureExtensions.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Commands\MemberCommands.cs" />
<Compile Include="MonoDevelop.ClassDesigner.Commands\AssociationCommands.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down

0 comments on commit 3ff1db4

Please sign in to comment.