Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) custom propeties (Read 10456 times)
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
custom propeties
Sep 29th, 2009 at 5:03pm
Print Post  
Hi  i am using Netdiagram for flowchart in webforms.here my requirement is when i click on diagram element for example cirlcle, i want to save inforamtion behind hat element.like i need to create custom properties..can anybody suggest me regarding this..if you have any example please let me know
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #1 - Sep 29th, 2009 at 6:15pm
Print Post  
Hi,

You could assign custom objects to the Tag property of items. You will have to handle the SerializeTag and DeserializeTag events in order to preserve the Tag values between postbacks.

I hope that helps.
Stoyan
  
Back to top
 
IP Logged
 
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
Re: custom propeties
Reply #2 - Sep 29th, 2009 at 7:11pm
Print Post  
A Microsoft Office Visio drawing is more than a picture―it's also a valuable way to store data. A shape can act as a visual database field that stores data you can retrieve in a report. For example, a flowchart shape can store data about the cost, duration, and resources involved in the process step the shape represents....
do we have this fecility in Net diagram.. If yes can you send one example with code


Thanks;
Kumar
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #3 - Sep 29th, 2009 at 7:56pm
Print Post  
The custom fields in Visio are a simple hashtable, aren't they. You might store such values in a Dictionary<string, string> or Dictionary<string, Object>, and then assign that Dictionary to DiagramItem.Tag.

Stoyan
  
Back to top
 
IP Logged
 
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
Re: custom propeties
Reply #4 - Sep 29th, 2009 at 8:02pm
Print Post  
Ya  i am not sure..Can  you provide sample code or example for this task,that will be great
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #5 - Sep 30th, 2009 at 11:58am
Print Post  
For example

Code
Select All
DiagramItem item = diagram.ActiveItem;

Dictionary<string, string> customProps = new Dictionary<string, string>();
customProps["prop1"] = "value1";
customProps["prop2"] = "value2";

item.Tag = customProps; 



Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #6 - Sep 30th, 2009 at 12:14pm
Print Post  
If you are using JavaApplet mode and need to read the value on the client side, add a handler for SerializeTag and DeserializeTag like this:

diagram.SerializeTag += new SerializeTagEventHandler(diagram_SerializeTag);

and implement them like this:

Code
Select All
void diagram_SerializeTag(object sender, SerializeTagEventArgs e)
{
	Dictionary<string, string> table = (Dictionary<string, string>)e.Tag;
	string[] serialized = new string[table.Count * 2];
	int c = 0;
	foreach (KeyValuePair<string, string> p in table)
	{
		serialized[c++] = p.Key;
		serialized[c++] = p.Value;
	}
	e.Context.WriteString(String.Join(";", serialized), "hashtable", e.Representation);
}

// similar for deserialize
 



Then add JavaScript functions that implement the same logic on the client side by assigning their names to the SerializeTagScript and DeserializeTagScript properties.
  
Back to top
 
IP Logged
 
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
Re: custom propeties
Reply #7 - Sep 30th, 2009 at 1:41pm
Print Post  
Hi
Thank you for your reply.But i am not getting required output.i am getting some erros.my requirement is when client rightclick on a shape client need to get a tag like CustomProperties.After clicking on Custom Properties it will allow client to enter values of cost and status.he need to save those values  and retrive those values when ever he wants.so can you plaese help me in this  here i am attching my code,thank you so much for your time
Code
Select All
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using MindFusion.Diagramming;
using MindFusion.Diagramming.WebForms;
using System.Collections.Generic;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
	  if (!IsPostBack)
	  {
		Diagram diagram = diagramView.Diagram;
		diagram.SelectAfterCreate = false;

		ShapeNode start = diagram.Factory.CreateShapeNode(10, 10, 20, 15);
		start.Shape = Shapes.Start;
		start.Text = "Start";



		//DiagramItem item = diagram.ActiveItem;

		//Dictionary<string, string> customProps = new Dictionary<string, string>();
		//customProps["prop1"] = "Example";
		//customProps["prop2"] = "Example1";

		start.Tag = "Example";
	  }
    }

    protected override void OnPreRender(EventArgs e)
    {
	  base.OnPreRender(e);

	  // display the files available for loading
	  listFileNames.Items.Clear();
	  string localDir = MapPath(@"Files\");
	  DirectoryInfo dir = new DirectoryInfo(localDir);
	  foreach (FileInfo fileInfo in dir.GetFiles())
		listFileNames.Items.Add(fileInfo.Name);
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
	  if (!String.IsNullOrEmpty(tbFileName.Text))
	  {
		string localDir = MapPath(@"Files\");
		diagramView.Diagram.SaveToFile(localDir + tbFileName.Text);
	  }
    }

    protected void btnLoad_Click(object sender, EventArgs e)
    {
	  if (!String.IsNullOrEmpty(listFileNames.SelectedValue))
	  {
		string localDir = MapPath(@"Files\");
		diagramView.Diagram.LoadFromFile(localDir + listFileNames.SelectedValue);
	  }
    }
}
diagram.SerializeTag += new SerializeTagEventHandler(diagram_SerializeTag);
void diagram_SerializeTag(object sender, SerializeTagEventArgs e)
{
Dictionary<string, string> table = (Dictionary<string, string>)e.Tag;
string[] serialized = new string[table.Count * 2];
int c = 0;
foreach (KeyValuePair<string, string> p in table)
{
serialized[c++] = p.Key;
serialized[c++] = p.Value;
}
e.Context.WriteString(String.Join(";", serialized), "hashtable", e.Representation);
}




 




i dont know how to add a tag to shape and how can i get my required ..if you have can you send me complete code
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #8 - Sep 30th, 2009 at 2:59pm
Print Post  
What ClientSideMode are you using?
  
Back to top
 
IP Logged
 
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
Re: custom propeties
Reply #9 - Sep 30th, 2009 at 3:34pm
Print Post  
Thanks for your reply.

My clinetside mode is javaapplet

sorry to bother you
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #10 - Sep 30th, 2009 at 7:29pm
Print Post  
First set the NodeClickedScript property to the name of the JS function that will handle the click event, and in that function check if the right mouse button has been clicked:

Code
Select All
function onNodeClicked(sender, args)
{
	if (args.getMouseButton() == 3)
		showContextMenu(args.getNode(), args.getMousePosition());
}
 



You will have to use a third-party context menu control, or if you know Java you could use a Swing menu. It's also possible to implement a context menu by showing a TableNode at the mouse location, and handling its CellClicked event.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #11 - Sep 30th, 2009 at 7:40pm
Print Post  
E.g. you can implement a context menu using a table like this:

Code
Select All
var menu = null;
var currentNode;
function showContextMenu(node, mousePos)
{
	var applet = <%= diagramView.AppletElement %>;
	var scriptHelper = applet.getScriptHelper();
	var diagView = applet.getDiagramView();
	var diagram = diagView.getDiagram();

	currentNode = node;
	if (!menu)
	{
		menu = diagram.getFactory().createTableNode(mousePos.getX(), mousePos.getY(), 20, 20);
		menu.setRowCount(2);
		menu.setColumnCount(1);
		menu.getCell(0, 0).setText("Delete");
		menu.getCell(0, 1).setText("Properties");
		menu.setCaptionHeight(0);
		menu.setCaption("");
		menu.resizeToFitText(true);
		menu.setCellFrameStyle(1);
		menu.setBrush(scriptHelper.createSolidBrush(255, 255, 255));
	}
	else
	{
		menu.setVisible(true);
		menu.moveTo(mousePos.getX(), mousePos.getY());
	}
} 

  
Back to top
 
IP Logged
 
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
Re: custom propeties
Reply #12 - Oct 1st, 2009 at 7:08am
Print Post  

     Thank You For Your Reply. Iam getting the properties with text but i want the links for the context menu and After clicking on Custom Properties link it will allow client to enter values of cost and status in a window.he need to save those values  and retrive those values when ever he wants.
     
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: custom propeties
Reply #13 - Oct 1st, 2009 at 8:28am
Print Post  
Next, add a CellClickedScript function that looks like this:

Code
Select All
function onCellClicked(sender, args)
{
	menu.setVisible(false);
	if (args.getCell().getText() == "Properties")
	{
		// todo: display the currentNode properties in the UI
		alert("clicked");
	}
}
 



It is up to you to display the properties in some kind of grid. You might use a TableNode for this too.

On the client side the custom properties could be stored in a JavaScript array, and you must serialize and deserialize them in a similar manner as the server side Dictionary through SerializeTagScript and DeserializeTagScript handlers.
  
Back to top
 
IP Logged
 
kumarsrmt
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 23
Joined: Sep 29th, 2009
Re: custom propeties
Reply #14 - Oct 1st, 2009 at 10:12am
Print Post  
On the client side the custom properties could be stored in a JavaScript array, and you must serialize and deserialize them in a similar manner as the server side Dictionary through SerializeTagScript and DeserializeTagScript handlers.

Can u Please provice some code for above onne i.e Serilalize and deserilalize using Javascript array
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint