0

Problem in Drag and Drop

asked 2009-04-25 13:35:33 +0800

Kailas gravatar image Kailas
144 1 1

Hi Friends

What is the problem in zscript, why not drop the selected component

<?page id="demoDrag" title="DragDemo" contentType="text/html;charset=UTF-8" ?>
<zk>
<hbox>
<grid id="left" height="200px" width="200px" onDrop="move(event.dragged)" fixedLayout="true">
<rows>
<row draggable="true" onDrop="move(event.dragged)">
<textbox value="zdg" />
</row>

<row draggable="true" onDrop="move(event.dragged)">
<button label="sam" />
</row>
<row draggable="true" onDrop="move(event.dragged)">
<radio label="sam" />
</row>
<row draggable="true" onDrop="move(event.dragged)">
<captcha value="sam" />
</row>
</rows>
</grid>
<separator />

<window id="win3" droppable="true" title="Design" width="200px" height="200px" border="normal" sizable="true">
<panel>
<panelchildren>
<grid id="drop" height="200px" onDrop="move(event.dragged)" droppable="true">
<rows>
</rows>
</grid>
</panelchildren>
</panel>
</window>
</hbox>
<zscript>
import org.zkoss.zul.*;
import org.zkoss.zul.Grid;

Grid lb;
void move(Component dragged)
{
System.out.println(".............Data in dragged...................."+dragged.getGrid().toString());
System.out.println(".................."+dragged.getGrid().toString().length());
String s1 = dragged.getGrid().toString();
System.out.println("Sub String "+s1.substring(1, dragged.getGrid().toString().length() - 1));
String[] p = s1.substring(1, dragged.getGrid().toString().length() - 1).split(" ");
System.out.println("Size of "+p[1]);

lb = (Grid) Path.getComponent("/win3/drop");
if (self instanceof org.zkoss.zul.Row)
{
System.out.println("................................."+self);
if (dragged.getParent().getId().equals("right"))
{
self.parent.insertBefore(dragged, self);
}
else
{
self.parent.insertBefore(dragged, self);
}
}
else
{
if(p[1].equalsIgnoreCase("left"))
{
lb.renderRowApi(dragged.clone());
}
else
{
lb.renderRowApi(dragged);
}
}
lb.renderRowApi(dragged.clone());
}
</zscript>
</zk>

Plz. run this zul page.

Help me friends.

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2009-04-27 03:15:05 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-04-27 03:17:10 +0800

Hi,

It seems zk doesn't know what's self variable(but in zk demo the way works...) at runtime,
i've revised your code so that you can drap and drop an item from left panel to right one.
Please meke it on your own for reverse way.

1.Overwrite your right panel(only the onDrop event is revised)

<window id="win3" droppable="true" title="Design" width="200px"
		height="200px" border="normal" sizable="true">
	<panel>
		<panelchildren>
			<grid id="drop" height="200px"
				onDrop="move(event.getTarget(), event.dragged)" droppable="true">
			              <rows>
				      </rows>
			</grid>
		</panelchildren>
	</panel>
</window>


2.Revise your method

void move(Component dropped,Component dragged)
{
	System.out.println(".............Data in dragged...................."+dragged.getGrid().toString());
	System.out.println(".................."+dragged.getGrid().toString().length());
	String s1 = dragged.getGrid().toString();
	System.out.println("Sub String "+s1.substring(1, dragged.getGrid().toString().length() - 1));
	String[] p = s1.substring(1, dragged.getGrid().toString().length() - 1).split(" ");
	System.out.println("Size of "+p[1]);
	
	lb = (Grid) Path.getComponent("/win3/drop");
	
	if (dropped instanceof org.zkoss.zul.Row)
	{
		System.out.println("row................................."+self);
		if (dragged.getParent().getId().equals("right"))
		{
			self.parent.insertBefore(dragged, self);
		}
		else
		{
			self.parent.insertBefore(dragged, self);
		}
	}
	else
	{
		System.out.println("grid................................."+self);
		if(p[1].equalsIgnoreCase("left"))
		{
		    dropped.getChildren().get(0).appendChild(dragged);
		}
		else
		{
			dropped.getChildren().get(0).appendChild(dragged);
		}
	}
	lb.renderRowApi(dragged.clone());
}

link publish delete flag offensive edit

answered 2009-04-27 07:16:20 +0800

Kailas gravatar image Kailas
144 1 1

Thanks Hideokidd

My idea is when we drop the component in Window this component is set anywhere in window
(like in JAVA NullLayout you set a component throught X-Y position) so how to set X-Y position of component in ZK. It is possible or give any other idea.

Plz reply.

link publish delete flag offensive edit

answered 2009-04-28 01:04:01 +0800

hideokidd gravatar image hideokidd
750 1 2

Hi,

The feature is not supported yet,
please post to zk features.
http://sourceforge.net/tracker/?group_id=152762&atid=785194
Thanks.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-04-25 13:35:33 +0800

Seen: 412 times

Last updated: Apr 28 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More