Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF databinding to Treeviewer
EMF databinding to Treeviewer [message #487620] Wed, 23 September 2009 18:54 Go to next message
Rencana Tarigan is currently offline Rencana TariganFriend
Messages: 56
Registered: July 2009
Location: Bandung, Indonesia
Member

Hello,
Now i want ask how to make databinding to treeviewer.
I already success to make databinding to treeviewer when i have same type between parent and children.

now i have model like this :
PersonMail have many MailBox, MailBox have many MailFolder.
i want to show tree like :

MailBoxA (MailBox)
- Inbox(MailFolder)
- subFolder1 (MailFolder)
- Outbox (MailFolder)
- subFolder2 (MailFolder)

MailBoxB (MailBox)
- Inbox(MailFolder)
- subFolder1 (MailFolder)
- Outbox (MailFolder)
- subFolder4 (MailFolder)

can someone give me advice for this problem ?
Thanks,


Re: EMF databinding to Treeviewer [message #487686 is a reply to message #487620] Thu, 24 September 2009 07:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Rencana,

The basic generated EMF editor shows tree view like this doesn't it?


Rencana Tarigan wrote:
> Hello,
> Now i want ask how to make databinding to treeviewer.
> I already success to make databinding to treeviewer when i have same
> type between parent and children.
>
> now i have model like this :
> PersonMail have many MailBox, MailBox have many MailFolder.
> i want to show tree like :
>
> MailBoxA (MailBox)
> - Inbox(MailFolder)
> - subFolder1 (MailFolder)
> - Outbox (MailFolder)
> - subFolder2 (MailFolder)
>
> MailBoxB (MailBox)
> - Inbox(MailFolder)
> - subFolder1 (MailFolder)
> - Outbox (MailFolder)
> - subFolder4 (MailFolder)
>
> can someone give me advice for this problem ?
> Thanks,


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF databinding to Treeviewer [message #487712 is a reply to message #487686] Thu, 24 September 2009 08:37 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
1. Your IObservableFactory needs switch between the object types.
Something like this:

-----------8<-----------
private IEMFListProperty mailBoxFolders =
EMFProperties.list(MAILBOX__MAILFOLDERS);

private IEMFListProperty mailFolders =
EMFProperties.list(MAILFOLDER__MAILFOLDERS);

public IObservable createObservable(final Object target) {
if (target instanceof IObservableList)
{
return (IObservable)target;
}
else if (target instanceof MailBox)
{
return mailBoxFolders.observe(target);
}
else if ( target instanceof MailFolder )
{
return mailFolders.observe(target);
}
return null;
}
-----------8<-----------

2. You need to create IObservableMap for each attribute you want to
observe (EMF-Databinding tries to find the feature on each object and
silently ignores the fact that it can't observe
MAILFOLDER__NAME e.g. MailBox)

IObservableSet set = cp.getKnownElements();
IObservableMap[] map = new IObservableMap[2];
map[0] = EMFProperties.value(MAILBOX__LABEL).observeDetail(set);
map[1] = EMFProperties.value(MAILFOLDER__LABEL).observeDetail(set);

3. You need to write your own LabelProvider IIRC because none of the
standard ones provide will work for you out of the box.

I'd suggest subclassing ColumnLabelProvider with something like this:

private class TreeLabelProviderImpl
extends ColumnLabelProvider
{
private IMapChangeListener mapChangeListener =
new IMapChangeListener()
{
public void handleMapChange(MapChangeEvent event)
{
Set<?> affectedElements =
event.diff.getChangedKeys();
if (!affectedElements.isEmpty())
{
LabelProviderChangedEvent newEvent =
new LabelProviderChangedEvent(
TreeLabelProviderImpl.this,
affectedElements.toArray()
);
fireLabelProviderChanged(newEvent);
}
}
};

public TreeLabelProviderImpl(
IObservableMap... attributeMaps)
{
for (int i = 0; i < attributeMaps.length; i++)
{
attributeMaps[i].addMapChangeListener(
mapChangeListener
);
}
}

public String getText(Object element) {
if( element instanceof MailBox) {
return "Box " + ((MailBox)element).getLabel();
} else if( element instanceof MailFolder ) {
return "Folder " + ((MailFolder)element).getLabel();
}
}

}

I guess you already checked out the code from my example project and my
blog [1] which is available from modeling-cvs.

[1] http://tomsondev.bestsolution.at/2009/06/06/galileo-improved -emf-databinding-support/

Ed Merks schrieb:
> Rencana,
>
> The basic generated EMF editor shows tree view like this doesn't it?
>
>
> Rencana Tarigan wrote:
>> Hello,
>> Now i want ask how to make databinding to treeviewer.
>> I already success to make databinding to treeviewer when i have same
>> type between parent and children.
>>
>> now i have model like this :
>> PersonMail have many MailBox, MailBox have many MailFolder.
>> i want to show tree like :
>>
>> MailBoxA (MailBox)
>> - Inbox(MailFolder)
>> - subFolder1 (MailFolder)
>> - Outbox (MailFolder)
>> - subFolder2 (MailFolder)
>>
>> MailBoxB (MailBox)
>> - Inbox(MailFolder)
>> - subFolder1 (MailFolder)
>> - Outbox (MailFolder)
>> - subFolder4 (MailFolder)
>>
>> can someone give me advice for this problem ?
>> Thanks,
Re: EMF databinding to Treeviewer [message #487775 is a reply to message #487620] Thu, 24 September 2009 11:57 Go to previous messageGo to next message
Rencana Tarigan is currently offline Rencana TariganFriend
Messages: 56
Registered: July 2009
Location: Bandung, Indonesia
Member

@Ed : Thanks Ed, but i'm newbie for Eclipse and EMF, when i generate all and then run the editor package as eclipse application and i'm only see new eclipse with Resource perspective, and then i don't know what must i do Sad
I already have EMF Book, and still not understand to use the editor and still not understand about epo file Sad maybe need more time to read and try it...

@Tom : thanks Tom for explain it one by one , will try to code it Smile

Thanks Tom, it's work, will try to understand what i write and make another simple example Smile


[Updated on: Thu, 24 September 2009 12:25]

Report message to a moderator

Re: EMF databinding to Treeviewer [message #488038 is a reply to message #487775] Fri, 25 September 2009 12:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090208010708060100080002
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Rencana,

All the introductory tutorials show the detailed steps needed:

Tutorial: Generating an EMF Model using XML Schema
< http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html>


Rencana Tarigan wrote:
> @Ed : Thanks Ed, but i'm newbie for Eclipse and EMF, when i generate
> all and then run the editor package as eclipse application and i'm
> only see new eclipse with Resource perspective, and then i don't know
> what must i do :(
> I already have EMF Book, and still not understand to use the editor
> and still not understand about epo file :( maybe need more time to
> read and try it...
>
> @Tom : thanks Tom for explain it one by one , will try to code it :)

--------------090208010708060100080002
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Rencana,<br>
<br>
All the introductory tutorials show the detailed steps needed:<br>
<blockquote><a
href=" http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.emf.doc/tutorials/xlibmod/xlibmod.html">Tutorial:
Generating an EMF Model using XML Schema</a><br>
</blockquote>
<br>
Rencana Tarigan wrote:
<blockquote cite="mid:h9fmrk$l3p$1@build.eclipse.org" type="cite">@Ed :
Thanks Ed, but i'm newbie for Eclipse and EMF, when i generate all and
then run the editor package as eclipse application and i'm only see new
eclipse with Resource perspective, and then i don't know what must i do
:(
<br>
I already have EMF Book, and still not understand to use the editor and
still not understand about epo file :( maybe need more time to read and
try it...
<br>
<br>
@Tom : thanks Tom for explain it one by one , will try to code it :)
<br>
</blockquote>
</body>
</html>

--------------090208010708060100080002--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF databinding to Treeviewer [message #489242 is a reply to message #487620] Fri, 02 October 2009 01:47 Go to previous messageGo to next message
Rencana Tarigan is currently offline Rencana TariganFriend
Messages: 56
Registered: July 2009
Location: Bandung, Indonesia
Member

hi Ed and Tom,
can you give me some learning curve t understand the whole of EMFObservable or databinding ?
I'm newbie for use Eclipse RCP and EMF, what must i learn first, step by step to be expert at eclipse rcp and emf ?

Thanks


Re: EMF databinding to Treeviewer [message #489288 is a reply to message #489242] Fri, 02 October 2009 08:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Rencana,

It's best to search the Eclipse website for articles and other
information. All EMF articles I know about are listed on our
documentation page. More general Eclipse things, like data binding in
general, or RCP, will be in other places. I'm not sure which are the
best sources and would have to search for them myself. Perhaps others
will suggest articles they thought were good...


Rencana Tarigan wrote:
> hi Ed and Tom,
> can you give me some learning curve t understand the whole of
> EMFObservable or databinding ?
> I'm newbie for use Eclipse RCP and EMF, what must i learn first, step
> by step to be expert at eclipse rcp and emf ?
>
> Thanks


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF databinding to Treeviewer [message #489293 is a reply to message #489288] Fri, 02 October 2009 09:05 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Ed Merks schrieb:
> Rencana,
>
> It's best to search the Eclipse website for articles and other
> information. All EMF articles I know about are listed on our
> documentation page. More general Eclipse things, like data binding in
> general, or RCP, will be in other places. I'm not sure which are the
> best sources and would have to search for them myself. Perhaps others
> will suggest articles they thought were good...
Hi Rencana,

Tom suggested an excellent blog series about databinding with EMF. Did
you read it?

Cheers
/Eike

----
http://thegordian.blogspot.com
http://twitter.com/eikestepper


>
>
> Rencana Tarigan wrote:
>> hi Ed and Tom,
>> can you give me some learning curve t understand the whole of
>> EMFObservable or databinding ?
>> I'm newbie for use Eclipse RCP and EMF, what must i learn first, step
>> by step to be expert at eclipse rcp and emf ?
>>
>> Thanks


Previous Topic:EcoreUtil.delete()...
Next Topic:XML Customizing using Extended MetaData
Goto Forum:
  


Current Time: Thu Apr 25 07:45:51 GMT 2024

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

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

Back to the top