Around Table Header buttons

Hi
1.How I can show icons/buttons over Table when mouse goes over its header
2.How I can change each NodeItem’s background color?

Regards

You don’t just want to “show” buttons, you want to be able to use them to create a new node with a link to the current node, right? (if so, connected to which port? this sort of UI works better for nodes that have a single port.)



You can set the color of an item by setting the Shape.BrushColor. But this is already being used for Selection highlight (see the code in AddSelectionHandles) so be careful here.

Hi Jake
Thanks for your reply.Yes we want to be able to create new nodes.A new item(column/attribute) will be created/added to the current table and its output(right) port will be connected to the newly created node(node type will depend on selected button).Would you please provide a sample code in this regard?

Regards

Give me some time to think about how to approach this.

OK… I’ve done a basic Tool here. It basically is a MouseDown tool for the buttons that create a node and link and then put the new node in Drag mode so you can position. (the tool is an extension of GoToolDragging.)



This goes hand in hand with a “GoImage” class (AutoNodeImage) that knows how to create a node and link when asked.



So, you can derive a bunch of AutoNodeImage classes that each create one “to” node and link, or you can make this one AutoNodeImage smart enough to create different node types, based on a property that you would add.



I’ll leave it up to you to create a palette of these buttons on hover (actually, I think on selection would work better). You can use a Horizontal GoListGroup to easily position all the buttons. My sample here only uses one button (with a butterfly image). (and I just create the AutoNodeImage, I’m not using a selection or hover event here)



here is the initialization code:



ToolDraggingAutoNode tool = new ToolDraggingAutoNode(view);

view.MouseDownTools.Add(tool);





GoBasicNode autonode = new GoBasicNode();

autonode.Shape = new GoDrawing(GoFigure.CreateRequest);

autonode.Shape.Size = new SizeF(30, 30);

autonode.Location = new PointF(300, 500);

autonode.Text = “autonode”;

autonode.LabelSpot = GoObject.MiddleBottom;

doc.Add(autonode);



AutoNodeImage ani = new AutoNodeImage();

ani.Name = “butterfly.png”;

ani.Size = new SizeF(24, 24);

ani.AutoNodeFor = autonode;

ani.SetSpotLocation(GoObject.MiddleBottom, autonode, GoObject.MiddleTop);

doc.Add(ani);



----- and here is the code for the Tool and AutoNodeImage.





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;



using System.Drawing;

using Northwoods.Go;



namespace QuickGoDiagramForm {

class ToolDraggingAutoNode : GoToolDragging {



public ToolDraggingAutoNode(GoView v) : base(v) { }



public override bool CanStart() {

if (!this.View.CanMoveObjects() && !this.View.CanCopyObjects() && !this.View.AllowDragOut)

return false;

if (this.LastInput.IsContextButton)

return false;



// note that we are including not-selectable objects here.

GoObject obj = this.View.PickObject(true, false, this.FirstInput.DocPoint, false);

if (obj == null)

return false;



return (obj is AutoNodeImage);

}



public override void Start() {

// note that we are including not-selectable objects here.

this.CurrentObject = this.View.PickObject(true, false, this.FirstInput.DocPoint, false);

if (this.CurrentObject == null)

return;



AutoNodeImage autoNode = this.CurrentObject as AutoNodeImage;

if (autoNode == null) return;



// remember the offset within the current object

this.MoveOffset = SubtractPoints(this.FirstInput.DocPoint, this.CurrentObject.Position);

StartTransaction();



GoObject node = autoNode.CreateNode(this.View);

this.CurrentObject = node;

this.Selection.Select(this.CurrentObject);



if (!this.View.DragRoutesRealtime && this.View.DragsRealtime) {

this.View.Document.SuspendsRouting = true;

}



// hide all the selection handles, so we don’t have to drag them along

this.Selection.RemoveAllSelectionHandles();

}



public override void Stop() {

this.Selection.AddAllSelectionHandles();

base.Stop();

}





}









class AutoNodeImage : GoImage {



public AutoNodeImage() {

this.Selectable = false;

this.Movable = false;

}



// Create a “to” node and link that connects the AutoNodeFor and the newly created node.

// add them both to the Document before returning

public virtual GoObject CreateNode(GoView view) {

GoBasicNode node = new GoBasicNode();

node.Shape = new GoRoundedRectangle();

node.Shape.Size = new SizeF(40, 40);

node.Text = “new node”;



view.Document.Add(node);



// for sample purposes, we’re going to assume the AutoNodeFor is also a GoBasicNode.

GoBasicNode nodeFrom = AutoNodeFor as GoBasicNode;



if (nodeFrom != null) {

GoLink link = new GoLink();

link.FromPort = nodeFrom.Port;

link.ToPort = node.Port;

view.Document.Add(link);

}



return node;

}





// when an AutoNodeImage is created, it has to be told what node it is be to considered the “from” node.

public GoNode AutoNodeFor {

get { return myAutoNodeFor; }

set { myAutoNodeFor = value; }

}



private GoNode myAutoNodeFor = null;



}

}

Here is the code above in download form:



20110107_132401_ToolDraggingAut.txt



Here’s a screenshot of my sample usage, after 2 nodes have been created by mousing down on the butterfly.



Hi Jake
Thank you for your code.There is one problem, When I move autonode node, its butterfly icon doesn’t move automatically.They become separated,But they should move with each other.

Regards

no… my code here is just to show the mechanism of the UI interaction on the click/drag… I can envision people using this with a lot of different UI hooks (hover, selection, etc) and with a variety of nodes… so I left that part to the reader.