Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Showing Properties of EObjects without Selection(Populating Properties View without explicitly selecting an EMF Object )
Showing Properties of EObjects without Selection [message #1805411] Sun, 14 April 2019 16:08 Go to next message
Muti Ur Rehman is currently offline Muti Ur RehmanFriend
Messages: 1
Registered: March 2019
Junior Member
Hello Everyone,

I am working with Nebula NatTables and EMF , and I would like to implement a Table Based Editor.
I am Displaying EMF Objects in Table but the SelectionEvent on Table Cell returns the Selected Cell instead of underlying Eobject.

However it gives a possibility to get the underlying object by a method such as:

if (event instanceof CellSelectionEvent) {
CellSelectionEvent cellEvent = (CellSelectionEvent) event;


Object input =
natTable.getDataValueByPosition(cellEvent.getColumnPosition(),
cellEvent.getRowPosition());

if (input instanceof EObject)
{
EObject selectedObject = (EObject)input;
}

At this point , I wish to trigger the properties View to display the properties of this EObject in Properties View.

Could someone please help me with how can I display this EObject in the Properties View.

Many Thanks!
Re: Showing Properties of EObjects without Selection [message #1805528 is a reply to message #1805411] Tue, 16 April 2019 18:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
The entry point for updating a property sheet page is org.eclipse.ui.views.properties.PropertySheetPage.selectionChanged(IWorkbenchPart, ISelection) so you must present a selection containing EObjects. You'll find an example in around this line:

https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.edit.ui/src/org/eclipse/emf/edit/ui/util/FindAndReplaceTarget.java#n1155

This code is used to support the find dialog and has logic for searching the contents of the property sheet page and logic for showing the property sheet page and setting the selection of that page.

In the generated editors you'll find UnwrappingSelectionProvider is used. Somehow you should ensure that the editor's selection isn't just a cell selection but something more general that the properties vie will recognize.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Showing Properties of EObjects without Selection [message #1831460 is a reply to message #1805528] Thu, 20 August 2020 09:28 Go to previous messageGo to next message
fares kallel is currently offline fares kallelFriend
Messages: 10
Registered: May 2020
Junior Member
Hi Everyone,

I also have a NatTable Editor that displays EObjects. I would like to get the Properties view to show the properties of the selected EObject in the natTable.
I was able to retrieve the selected Object as a ISelection. and I used the org.eclipse.ui.views.properties.PropertySheetPage.selectionChanged(IWorkbenchPart, ISelection) but nothing happened I still do not get the property view to trigger. this the code I used. what am I missing? what am I doing wrong ?

natTable.addLayerListener(new ILayerListener() {

@Override
public void handleLayerEvent(ILayerEvent event) {

if (event instanceof CellSelectionEvent) {

CellSelectionEvent cellEvent = (CellSelectionEvent) event;
int columnPosition = cellEvent.getColumnPosition();
int rowPosition = cellEvent.getRowPosition();
int columnIndex = natTable.getColumnIndexByPosition(columnPosition);
int rowIndex = natTable.getRowIndexByPosition(rowPosition);
Object currentselection = bodyLayerStack.getTreeLayer().
getDataValueByPosition(bodyLayerStack.getTreeLayer().
getColumnPositionByIndex(columnIndex), bodyLayerStack.getTreeLayer().
getRowPositionByIndex(rowIndex));
ISelection selection = new StructuredSelection(currentselection);

IWorkbenchPage page = getSite().getPage();
IWorkbenchPart part = page.getActivePart();
IViewPart viewPart = page.findView("org.eclipse.ui.views.PropertySheet");

PropertySheet sheet = (PropertySheet) viewPart;
IPage sheetPage = sheet.getCurrentPage();
if( sheetPage instanceof PropertySheetPage && sheetPage!= null) {
System.out.println(" works ");
PropertySheetPage activePropertysheet = (PropertySheetPage) sheetPage ;
activePropertysheet.selectionChanged(part, selection);
}}});

Thanks for the support
Re: Showing Properties of EObjects without Selection [message #1831473 is a reply to message #1831460] Thu, 20 August 2020 12:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
All I can suggest is using the debugger to trace what's happening. Is "currentselection" really an EObject?

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Showing Properties of EObjects without Selection [message #1831480 is a reply to message #1831473] Thu, 20 August 2020 13:56 Go to previous messageGo to next message
fares kallel is currently offline fares kallelFriend
Messages: 10
Registered: May 2020
Junior Member
Hi Ed,

Thanks for the quick reply.
It's an Object yes not an EObject . Could that be the reason why it's does not trigger the Properties View ? Because everything else seems fine I think.
Do you have any suggestions on what I should try otherweise ?

Thanks
Re: Showing Properties of EObjects without Selection [message #1831482 is a reply to message #1831480] Thu, 20 August 2020 14:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
I'm not sure what you've done to specialize/implement the properties view, but the default EMF generated support only works for EObject, Resource, and ResourceSet by default. Again, debugging is the best way to find answers...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Showing Properties of EObjects without Selection [message #1831591 is a reply to message #1831482] Mon, 24 August 2020 12:32 Go to previous messageGo to next message
fares kallel is currently offline fares kallelFriend
Messages: 10
Registered: May 2020
Junior Member
Hi Ed,

Thank you for your help. I was able to open the default properties View of the selected EObject in the natTable .

I have designed a sirius Properties View that is called when an element is selected in the model Explorer for example or in a Sirius Diagram. I would like that same sirius properties View to trigger when I select an Element in my NatTable Editor, not the default Properties View. I read in the Documentation that "Sirius properties view are enabled whenever the selected element is part of an opened session, i.e. any element selected inside a Sirius editor or from the Model Explorer view on an opened session." So I am wondering if this is even possible to do from a natTable editor but if it is, can you please direct me on how i would do this ? I could Open a sirius Session but I could't figure out what to do next.

Code:
IWorkbenchPage page = getSite().getPage();
IWorkbenchPart part = page.getActivePart();
IViewPart viewPart = page.findView("org.eclipse.ui.views.PropertySheet");
PropertySheet sheet = (PropertySheet) viewPart;
IPage sheetPage = sheet.getCurrentPage();
EObject eWrapper = (EObject)wrapper;
if(sheetPage instanceof PropertySheetPage && sheetPage!= null) {
PropertySheetPage activePropertysheet = (PropertySheetPage) sheetPage ;

Resource modelResource= eWrapper.eResource();
List<Resource> resourses = modelResource.getResourceSet().getResources();
Resource resource = resourses.get(0);
URI myRepFileURI = resource.getURI();
Session siriusSession = SessionManager.INSTANCE.getSession(myRepFileURI, new NullProgressMonitor());

ISelection Eselectionwrapper = new StructuredSelection(eWrapper);
activePropertysheet.selectionChanged(part, Eselectionwrapper);
}
Re: Showing Properties of EObjects without Selection [message #1831609 is a reply to message #1831591] Tue, 25 August 2020 05:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33218
Registered: July 2009
Senior Member
Normally an editor or a viewer provides its own contribution to the IPropertySheetPage by overriding org.eclipse.ui.part.WorkbenchPart.getAdapter(Class<T>). E.g.,
  @Override
  public <T> T getAdapter(Class<T> key)
  {
    if (key.equals(IPropertySheetPage.class))
    {
      return key.cast(createPropertySheetPage());
    }
    else
    {
      return super.getAdapter(key);
    }
  }
And the editor or viewer implements ISelectionProvider or uses org.eclipse.ui.IWorkbenchSite.setSelectionProvider(ISelectionProvider) on the editor/viewer site so that its selection is automatically available as input to the property sheet page contributed by that editor or viewer.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Generating edit code for referenced models
Next Topic:EMF, GWT ELIST and serialisation
Goto Forum:
  


Current Time: Thu Sep 26 06:24:10 GMT 2024

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

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

Back to the top