Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » problem with selection provider: domain object wanted instead of editpart
problem with selection provider: domain object wanted instead of editpart [message #240990] Sun, 27 January 2008 09:25 Go to next message
Eclipse UserFriend
Originally posted by: mail.bjoren.de

Hi!

I am facing the following problem: I have an graphical gef editor where
you model a graph. when you select an element (realized as an editpart),
the selection is given to the workbench selection service, so that other
views can react. however, i do not want the other views to know about
editparts at all and would prefer that the ISelection-Object received
after an event contains the domain model object behind the editpart, and
not the editpart itself.

thanks for any help!
Re: problem with selection provider: domain object wanted instead of editpart [message #240995 is a reply to message #240990] Sun, 27 January 2008 09:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mail.bjoren.de

me again:

i found this newsgroup article
" http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg1 3873.html".

the same question is asked, but no sufficient reply is given.
of course you can always get the model from an editpart, but why should
the a view showing domain objects know about editparts?!
Re: problem with selection provider: domain object wanted instead of editpart [message #241010 is a reply to message #240995] Sun, 27 January 2008 21:09 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.
--------------020001010603030909020500
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

I imagine your could do something like the following, as we did in EMF,
to filter another selection provider's selections and forward that
filtered result from your editor. (We use this to unwrap objects when
we register a context menu that that object actions see the underlying
objects and not the wrappers.)

|*package *org.eclipse.emf.edit.ui.provider;

*import *java.util.List;

*import *org.eclipse.emf.common.util.UniqueEList;
*import *org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
*import *org.eclipse.jface.viewers.ISelection;
*import *org.eclipse.jface.viewers.ISelectionChangedListener;
*import *org.eclipse.jface.viewers.ISelectionProvider;
*import *org.eclipse.jface.viewers.IStructuredSelection;
*import *org.eclipse.jface.viewers.SelectionChangedEvent;
*import *org.eclipse.jface.viewers.StructuredSelection;

*public class *UnwrappingSelectionProvider *implements *ISelectionProvider
{
*protected *ISelection selection;
*protected *List<ISelectionChangedListener> listeners = *new *UniqueEList.FastCompare<ISelectionChangedListener>();
*protected *ISelectionChangedListener selectionChangedListener =
*new *ISelectionChangedListener()
{
*public **void *selectionChanged(SelectionChangedEvent event)
{
setSelection(event.getSelection());
}
};

*public *UnwrappingSelectionProvider(ISelectionProvider selectionProvider)
{
selectionProvider.addSelectionChangedListener(selectionChang edListener);
setSelection(selectionProvider.getSelection());
}

*public **void *addSelectionChangedListener(ISelectionChangedListener listener)
{
listeners.add(listener);
}

*public *ISelection getSelection()
{
*return *selection;
}

*public **void *removeSelectionChangedListener(ISelectionChangedListener listener)
{
listeners.remove(listener);
}

*public **void *setSelection(ISelection selection)
{
*if *(selection *instanceof *IStructuredSelection)
{
Object [] objects = ((IStructuredSelection)selection).toArray();
*for *(*int *i = 0; i < objects.length; ++i)
{
objects[i] = unwrap(objects[i]);
}
*this*.selection = *new *StructuredSelection(objects);
}
*else*
{
*this*.selection = selection;
}
fireSelectionChanged();
}

*protected *Object unwrap(Object object)
{
*return *AdapterFactoryEditingDomain.unwrap(object);
}

*protected **void *fireSelectionChanged()
{
*for *(ISelectionChangedListener selectionChangedListener : listeners)
{
selectionChangedListener.selectionChanged(*new *SelectionChangedEvent(this, selection));
}
}
}|


bjoern wrote:
> me again:
>
> i found this newsgroup article
> " http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg1 3873.html".
>
> the same question is asked, but no sufficient reply is given.
> of course you can always get the model from an editpart, but why
> should the a view showing domain objects know about editparts?!
>


--------------020001010603030909020500
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I imagine your could do something like the following, as we did in EMF,
to filter another selection provider's selections and forward that
filtered result from your editor.
Re: problem with selection provider: domain object wanted instead of editpart [message #241060 is a reply to message #241010] Mon, 28 January 2008 14:52 Go to previous message
Eclipse UserFriend
Originally posted by: mail.bjoren.de

thanks ed, i ll try that out!
bjoern
Previous Topic:custom resizing
Next Topic:How do I make a rectangle clickable?
Goto Forum:
  


Current Time: Thu Apr 25 13:03:28 GMT 2024

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

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

Back to the top