How to define a selection provider for my editor ? [message #1112942] |
Fri, 20 September 2013 07:57  |
Eclipse User |
|
|
|
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 #1114829 is a reply to message #1113017] |
Mon, 23 September 2013 05:06   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.39291 seconds