Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » How to define a selection provider for my editor ?(To pass each selection to my ExtendedPropertySheetPage)
How to define a selection provider for my editor ? [message #1112942] Fri, 20 September 2013 11:57 Go to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi,

I extended the DefaultToolBehaviorProvider as follow to use the emf transaction extended property sheet page instead of tabbed properties :
	@Override
	public Object getAdapter(Class<?> type) {
		if (type == IPropertySheetPage.class)
			return getPropertySheetPage();
		return null;
	}

    public IPropertySheetPage getPropertySheetPage() {
		if (propertySheetPage == null) {
			TransactionalEditingDomain ed = TransactionalEditingDomain.Registry.INSTANCE
					.getEditingDomain(CDOTransactionalEditingDomainImpl.CDO_TED_ID);
			propertySheetPage = new ExtendedPropertySheetPage((AdapterFactoryEditingDomain) ed);
	    	ComposedAdapterFactory emfGlobalFactory = new ComposedAdapterFactory();
			emfGlobalFactory.addAdapterFactory(new RepositorystructureItemProviderAdapterFactory());
			emfGlobalFactory.addAdapterFactory(new ApplicationItemProviderAdapterFactory());
			emfGlobalFactory.addAdapterFactory(new ServiceItemProviderAdapterFactory());
			TransactionalAdapterFactoryContentProvider tafcp =
					new TransactionalAdapterFactoryContentProvider(ed, emfGlobalFactory);
			propertySheetPage.setPropertySourceProvider(tafcp);
    	}
    	return propertySheetPage;
    }


This works fine with my explorer when selecting an item in the tree viewer but nothing is displayed when I select a element from my opened diagram.

On the explorer side, the tree viewer is registered as an ISelectionProvider :
getSite().setSelectionProvider(viewer);


I guess I have to do the same on my editor side (register a listener at the right place that will return the EObject corresponding to the selected picture element).

Could somebody tell me how to achieve this ?

Kind regards.
Re: How to define a selection provider for my editor ? [message #1113017 is a reply to message #1112942] Fri, 20 September 2013 14:16 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Laurent,

you will need to subclass DiagramEditor (plus of course register that as an
ediotor for your diagram files via the Eclipse editors extension point) and
add that piece of code to the init method. The editor is by default only
registered as a selection listener but not as a provider.

Michael
Re: How to define a selection provider for my editor ? [message #1114829 is a reply to message #1113017] Mon, 23 September 2013 09:06 Go to previous messageGo to next message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi Michael,

Thanks for the tip. I tried the following :
public class GraphitiEditor extends DiagramEditor implements ISelectionProvider {
	private ListenerList listeners = new ListenerList();
	/*
	 * Extend the editor to make it also an ISelectionProvider for properties.
	 * @see org.eclipse.graphiti.ui.editor.DiagramEditor#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
	 */
	@Override
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
		super.init(site, input);
		getSite().setSelectionProvider(this);
	}
	
	@Override
	public void addSelectionChangedListener(ISelectionChangedListener listener) {
		listeners.add(listener);
	}

	@Override
	public ISelection getSelection() {
		// Pass the EObject corresponding to the first selected PE
		PictogramElement[] peArray = getSelectedPictogramElements();
		if (peArray != null && peArray.length > 0) {
			EObject element = (EObject)Graphiti.getLinkService()
					.getBusinessObjectForLinkedPictogramElement(getSelectedPictogramElements()[0]);
			if (element != null)
				return new StructuredSelection(element);
		}
		return StructuredSelection.EMPTY;
	}

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

	@Override
	public void setSelection(ISelection selection) {
		Object[] list = listeners.getListeners();  
		for (int i = 0; i < list.length; i++)
			((ISelectionChangedListener)list[i]).selectionChanged(new SelectionChangedEvent(this, selection));  
	}


But nothing is displayed in my property view...
Setting a breakpoint in addSelectionChangedListener(), it appears the method is not even called. So no listener registers to my provider. Should I "force" the registration in init() ? If so, how ?

As additionnal information, I also tried the two solutions discribed in Graphiti tutorial (setting up an adapter factory and overriding DefaultToolBehaviorProvider#getAdapter or embedding a standard table property sheet into a tabbeb one).
The emf transaction extended property sheet page gets properly displayed but I get the following exception when selecting an editable property...

java.lang.ClassCastException: org.eclipse.emf.edit.provider.ItemPropertyDescriptor$PropertyValueWrapper cannot be cast to java.lang.String


I found a few posts about this problem but no working solution.
And this problem does not show up with my explorer.
That's the reason why I now try the "ISelectionProvider approach".
But I'm stuckked and would really appreciate if anybody could tell me what to do...

Regards,

Laurent
Re: How to define a selection provider for my editor ? [message #1117744 is a reply to message #1114829] Thu, 26 September 2013 19:21 Go to previous message
Laurent Le Moux is currently offline Laurent Le MouxFriend
Messages: 184
Registered: September 2011
Senior Member
Hi again,

I finally got an answer regarding this ClassCastException in the EMF forum.
Here's the link...

http://www.eclipse.org/forums/index.php/t/530641/

Just in case, the link is not valid, the topic title is : ClassCastException when editing property sheet value

Regards,

Laurent
Previous Topic:Retrieving the business object linked to the container shape
Next Topic:Outline view not available in plugin
Goto Forum:
  


Current Time: Tue Apr 23 07:35:51 GMT 2024

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

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

Back to the top