Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » DND from TreeViewer to GMF generated editor
DND from TreeViewer to GMF generated editor [message #240904] Wed, 23 January 2008 11:28 Go to next message
Eclipse UserFriend
Originally posted by: amsurana.in.ibm.com

This is a multipart message in MIME format.
--=_alternative 003EA7AF652573D9_=
Content-Type: text/plain; charset="US-ASCII"

Hi,
I am writing an application using EMF & GMF.
GMF in its generated code creates an editor that extends
DiagramDocumentEditor. The palette has a tool "Person Details". This tool
lets u create a Node with a Person Name.
I have a tree viewer that displays Strings of Text with UserNames.



My Doubt:

When i drag a particular Tree item (User Name) from the TreeViewer on to
the Editor, a diagram Node (person Details Node) must be created with the
Username in the Name field of that node.

Can anyone help me figure out
1. How to provide Drop support to the editor. Or should I provide Drop
support to the Container.
2. What kind of transfer takes place ? TextTransfer, FileTransfer, etc...
2. When drop is performed what statements should be written that help in
creating new Node. ( I mean what are classes to be called to create the
node)

I am using GMF v 2.0.1 on Eclipse Europa 3.3

Regards
Amit
--=_alternative 003EA7AF652573D9_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">Hi, </font>
<br><font size=2 face="sans-serif">I am writing an application using EMF
&amp; GMF. </font>
<br><font size=2 face="sans-serif">GMF in its generated code creates an
editor that extends </font><font size=2 face="Courier New">DiagramDocumentEditor</font><font size=2 face="sans-serif">.
&nbsp;The palette has a tool &quot;Person Details&quot;. This tool lets
u create a Node with a Person Name.</font>
<br><font size=2 face="sans-serif">I have a tree viewer that displays Strings
of Text with UserNames. </font>
<br>
<br>
<br>
<br><font size=2 face="sans-serif">My Doubt: </font>
<br>
<br><font size=2 face="sans-serif">When i drag a particular Tree item (User
Name) from the TreeViewer on to the Editor, a diagram Node (person Details
Node) &nbsp;must be created with the Username in the Name field of that
node.</font>
<br>
<br><font size=2 face="sans-serif">Can anyone help me figure out</font>
<br><font size=2 face="sans-serif">1. How to provide Drop support to the
editor. Or should I provide Drop support to the Container. </font>
<br><font size=2 face="sans-serif">2. What kind of transfer takes place
? TextTransfer, FileTransfer, etc... </font>
<br><font size=2 face="sans-serif">2. When drop is performed what statements
should be written that help in creating new Node. ( I mean what are classes
to be called to create the node) </font>
<br>
<br><font size=2 face="sans-serif">I am using GMF v 2.0.1 on Eclipse Europa
3.3</font>
<br>
<br><font size=2 face="sans-serif">Regards </font>
<br><font size=2 face="sans-serif">Amit </font>
--=_alternative 003EA7AF652573D9_=--
Re: DND from TreeViewer to GMF generated editor [message #240910 is a reply to message #240904] Wed, 23 January 2008 11:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------000201010601060004050209
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Amit,

It sounds like you meant to use the GMF newsgroup, which I've added to
the "to" list of this reply.


amsurana@in.ibm.com wrote:
>
> Hi,
> I am writing an application using EMF & GMF.
> GMF in its generated code creates an editor that extends
> DiagramDocumentEditor. The palette has a tool "Person Details". This
> tool lets u create a Node with a Person Name.
> I have a tree viewer that displays Strings of Text with UserNames.
>
>
>
> My Doubt:
>
> When i drag a particular Tree item (User Name) from the TreeViewer on
> to the Editor, a diagram Node (person Details Node) must be created
> with the Username in the Name field of that node.
>
> Can anyone help me figure out
> 1. How to provide Drop support to the editor. Or should I provide Drop
> support to the Container.
> 2. What kind of transfer takes place ? TextTransfer, FileTransfer, etc...
> 2. When drop is performed what statements should be written that help
> in creating new Node. ( I mean what are classes to be called to create
> the node)
>
> I am using GMF v 2.0.1 on Eclipse Europa 3.3
>
> Regards
> Amit


--------------000201010601060004050209
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Amit,<br>
<br>
It sounds like you meant to use the GMF newsgroup, which I've added to
the "to" list of this reply.<br>
<br>
<br>
<a class="moz-txt-link-abbreviated" href="mailto:amsurana@in.ibm.com">amsurana@in.ibm.com</a> wrote:
<blockquote cite="mid:fn78dj$vqp$1@build.eclipse.org" type="cite"><br>
<font face="sans-serif" size="2">Hi, </font>
<br>
<font face="sans-serif" size="2">I am writing an application using
EMF
&amp; GMF. </font>
<br>
<font face="sans-serif" size="2">GMF in its generated code creates an
editor that extends </font><font face="Courier New" size="2">DiagramDocumentEditor</font><font
face="sans-serif" size="2">.
&nbsp;The palette has a tool "Person Details". This tool lets
u create a Node with a Person Name.</font>
<br>
<font face="sans-serif" size="2">I have a tree viewer that displays
Strings
of Text with UserNames. </font>
<br>
<br>
<br>
<br>
<font face="sans-serif" size="2">My Doubt: </font>
<br>
<br>
<font face="sans-serif" size="2">When i drag a particular Tree item
(User
Name) from the TreeViewer on to the Editor, a diagram Node (person
Details
Node) &nbsp;must be created with the Username in the Name field of that
node.</font>
<br>
<br>
<font face="sans-serif" size="2">Can anyone help me figure out</font>
<br>
<font face="sans-serif" size="2">1. How to provide Drop support to
the
editor. Or should I provide Drop support to the Container. </font>
<br>
<font face="sans-serif" size="2">2. What kind of transfer takes place
? TextTransfer, FileTransfer, etc... </font>
<br>
<font face="sans-serif" size="2">2. When drop is performed what
statements
should be written that help in creating new Node. ( I mean what are
classes
to be called to create the node) </font>
<br>
<br>
<font face="sans-serif" size="2">I am using GMF v 2.0.1 on Eclipse
Europa
3.3</font>
<br>
<br>
<font face="sans-serif" size="2">Regards </font>
<br>
<font face="sans-serif" size="2">Amit </font>
</blockquote>
<br>
</body>
</html>

--------------000201010601060004050209--
Re: DND from TreeViewer to GMF generated editor [message #240920 is a reply to message #240904] Wed, 23 January 2008 18:33 Go to previous messageGo to next message
schiermike is currently offline schiermikeFriend
Messages: 3
Registered: July 2009
Junior Member
>>1&2: Subclass AbstractTransferDragSourceListener and add it to the
Viewer. You can just use a custom transfer (extend ByteArrayTransfer) to
transfer the object which is about to be dragged (when drag&drop
happens within the same application).

Example for a custom transfer:

public class CustomTransfer extends ByteArrayTransfer {
// The only instance of CustomTransfer
private static Map<Class<?>, CustomTransfer> INSTANCES = new
HashMap<Class<?>, CustomTransfer>();

private int id;
private String type;

private CustomTransfer(Class<?> clazz) {
type = clazz.toString() + System.currentTimeMillis();
id = registerType(type);
}

/**
* Returns the only CustomTransfer for given class.
*
* @param The
* class for which the Transfer object should be returned.
* @return The only instance for given class.
*/
public static CustomTransfer getInstance(Class<?> clazz) {
CustomTransfer transfer = INSTANCES.get(clazz);

// if there is no transfer type yet, create one
if (transfer == null) {
transfer = new CustomTransfer(clazz);
INSTANCES.put(clazz, transfer);
}

return transfer;
}

@Override
protected int[] getTypeIds() {
return new int[] { id };
}

@Override
protected String[] getTypeNames() {
return new String[] { type };
}

@Override
protected void javaToNative(Object object, TransferData transferData) {
try {
// convert object to byte array
ByteArrayOutputStream bytes = new ByteArrayOutputStream(1000);
ObjectOutputStream out = new ObjectOutputStream(bytes);
out.writeObject(object);

super.javaToNative(bytes.toByteArray(), transferData);
} catch (Exception e) {
e.printStackTrace();
}
}

@SuppressWarnings("unchecked")//$NON-NLS-1$
@Override
protected Object nativeToJava(TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);

if (bytes == null)
return null;

try {
// convert byte array back to object
ObjectInputStream in = new ObjectInputStream(
new ByteArrayInputStream(bytes));

return in.readObject();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

amsurana@in.ibm.com schrieb:
>
> Hi,
> I am writing an application using EMF & GMF.
> GMF in its generated code creates an editor that extends
> DiagramDocumentEditor. The palette has a tool "Person Details". This
> tool lets u create a Node with a Person Name.
> I have a tree viewer that displays Strings of Text with UserNames.
>
>
>
> My Doubt:
>
> When i drag a particular Tree item (User Name) from the TreeViewer on to
> the Editor, a diagram Node (person Details Node) must be created with
> the Username in the Name field of that node.
>
> Can anyone help me figure out
> 1. How to provide Drop support to the editor. Or should I provide Drop
> support to the Container.
> 2. What kind of transfer takes place ? TextTransfer, FileTransfer, etc...
> 2. When drop is performed what statements should be written that help in
> creating new Node. ( I mean what are classes to be called to create the
> node)
>
> I am using GMF v 2.0.1 on Eclipse Europa 3.3
>
> Regards
> Amit
Re: DND from TreeViewer to GMF generated editor [message #240923 is a reply to message #240920] Thu, 24 January 2008 05:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: amsurana.in.ibm.com

This is a multipart message in MIME format.
--=_alternative 001BF293652573DA_=
Content-Type: text/plain; charset="US-ASCII"

Can u please tell me what are the Edit Policies or Commands that should be
used to create a new diagram Programmatically as soon as the drop is
performed on editor ??

> 3. When drop is performed what statements should be written that help in

> creating new Node. ( I mean what are classes to be called to create the
> node)

I apoligize to post this query in GEF newsgroup... that was my
mistake,....

--=_alternative 001BF293652573DA_=
Content-Type: text/html; charset="US-ASCII"


<br><tt><font size=2>Can u please tell me what are the Edit Policies or
Commands that should be used to create a new diagram Programmatically as
soon as the drop is performed on editor ??</font></tt>
<br>
<br><tt><font size=2>&gt; 3. When drop is performed what statements should
be written that help in <br>
&gt; creating new Node. ( I mean what are classes to be called to create
the <br>
&gt; node)<br>
</font></tt>
<br><tt><font size=2>I apoligize to post this query in GEF newsgroup...
that was my mistake,.... </font></tt>
<br>
--=_alternative 001BF293652573DA_=--
Re: DND from TreeViewer to GMF generated editor [message #240937 is a reply to message #240923] Thu, 24 January 2008 14:21 Go to previous messageGo to next message
schiermike is currently offline schiermikeFriend
Messages: 3
Registered: July 2009
Junior Member
I think GEF newsgroup is OK, your problem only deals with GEF.

1.) You have an AbstractTransferDropTargetListener on your viewer. This
listener creates a target request (createTargetRequest()). The request
should know your item to drop (in your example the user name) and should
be of type CreateRequest with RequesetConstants.REQ_CREATE.

2.) You have to install an EditPolicy on your target edit part in your
editor, which should have the role EditPolicy.CONTAINER_ROLE.

3.) This EditPolicy should be a subclass of ContainerEditPolicy and
should return the command when calling getCreateCommand(CreateRequest
request), which then should create your node.

how to create a node? This is your task! The nodes should be graphical
representations of your underlying model. The command returned by the
policy should modify this model in such a way that the new node is
inserted. Then refresh the editor content and your new node will
hopefully appear ;-)

amsurana@in.ibm.com schrieb:
>
> Can u please tell me what are the Edit Policies or Commands that should
> be used to create a new diagram Programmatically as soon as the drop is
> performed on editor ??
>
> > 3. When drop is performed what statements should be written that help in
> > creating new Node. ( I mean what are classes to be called to create the
> > node)
>
> I apoligize to post this query in GEF newsgroup... that was my mistake,....
Re: DND from TreeViewer to GMF generated editor [message #240954 is a reply to message #240937] Fri, 25 January 2008 07:40 Go to previous message
Eclipse UserFriend
Originally posted by: amsurana.in.ibm.com

This is a multipart message in MIME format.
--=_alternative 0029C71A652573DB_=
Content-Type: text/plain; charset="US-ASCII"

From your explanation i understand that :

--- I should create my own Sub-class, say, DropTargetListener of
AbstractTransferDropTargetListener and attach this listener to Editor's
viewer using following lines
GraphicalViewer viewer = getGraphicalViewer();
viewer.addDropTargetListener(new DropTargetListener(viewer,xfer));

-- Next I shall create a DropEditPolicy sub-classing ContainerEditPolicy
and install it to my Container that will react to the drop being
performed.

Am I right ???

Later on I 'll probably figure out what should i do to create node...

Thanks for the help... :)
--=_alternative 0029C71A652573DB_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2 face="sans-serif">From your explanation i understand that
: </font>
<br>
<br><font size=2 face="sans-serif">--- I should create my own Sub-class,
say, DropTargetListener &nbsp;of </font><tt><font size=2>AbstractTransferDropTargetListener
</font></tt><font size=2 face="sans-serif">and attach this listener to
Editor's viewer using following lines</font><tt><font size=2> </font></tt>
<br><tt><font size=2>&nbsp;</font></tt><font size=2 face="Courier New">GraphicalViewer
viewer = getGraphicalViewer();</font>
<br><font size=2 face="Courier New">&nbsp;viewer.addDropTargetListener(</font><font size=2 color=#820040 face="Courier New"><b>new</b></font><font size=2 face="Courier New">
DropTargetListener(viewer,xfer));</font>
<br>
<br><font size=2 face="Courier New">-- </font><font size=2 face="sans-serif">Next
I shall create a </font><font size=2 face="Courier New">DropEditPolicy</font><font size=2 face="sans-serif">
sub-classing</font><font size=2 face="Courier New"> ContainerEditPolicy
</font><font size=2 face="sans-serif">and install it to my</font><font size=2 face="Courier New">
Container</font><font size=2 face="sans-serif"> that will react to the
drop being performed. </font>
<br>
<br><font size=2 face="sans-serif">Am I right ??? </font>
<br>
<br><font size=2 face="sans-serif">Later on I 'll probably figure out what
should i do to create node... </font>
<br>
<br><font size=2 face="sans-serif">Thanks for the help... &nbsp;:)</font>
--=_alternative 0029C71A652573DB_=--
Previous Topic:Deactiviate editor
Next Topic:Multiple layers for nodes
Goto Forum:
  


Current Time: Wed Apr 24 23:26:57 GMT 2024

Powered by FUDForum. Page generated in 0.03363 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top