Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Programatically select Item in Editor in different window
Programatically select Item in Editor in different window [message #904360] Tue, 28 August 2012 10:10 Go to next message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi everyone,

I'm afraid I need some help again. What I want to do is the following:
I am keeping a relation URI from elements in my model to elements in a different resource. I want to add a functionality to trace down that other element, open it in another editor (might already be opened), extend the tree as far as needed to select that element in the other viewer.

I have already gotten as far that I can check if that other file is already open by checking the titles of the editor's parts against a part of my URI. I can open the resource, iterate through it and look for my item that I can also find. I can focus the editor on my other model. Now I want to select the item I have found in the editor that already opened the resource I want.

My appreach was the follwing:
List<Item> selectionList = new LinkedList<Item>();
selectionList.add(findItem(itemURI));
editor.setSelection(new StructuredSelection(selectionList));


That doesn't seem to do the trick.

I have access to the editor, the IEditorPart , the resource and the item. So to me it seems I have all the ingredients together.. Smile


Any help would be great!

Thanks, Markus
Re: Programatically select Item in Editor in different window [message #904369 is a reply to message #904360] Tue, 28 August 2012 10:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Markus,

Comments below.

On 28/08/2012 12:10 PM, Markus G wrote:
> Hi everyone,
>
> I'm afraid I need some help again. What I want to do is the following:
> I am keeping a relation URI from elements in my model to elements in a
> different resource. I want to add a functionality to trace down that
> other element, open it in another editor (might already be opened),
> extend the tree as far as needed to select that element in the other
> viewer.
>
> I have already gotten as far that I can check if that other file is
> already open by checking the titles of the editor's parts against a
> part of my URI. I can open the resource, iterate through it and look
> for my item that I can also find. I can focus the editor on my other
> model. Now I want to select the item I have found in the editor that
> already opened the resource I want.
I think you can just ask for the editor to be opened like what we do in
org.eclipse.emf.edit.ui.util.EditUIUtil.openEditor(EObject)
>
> My appreach was the follwing:
>
> List<Item> selectionList = new LinkedList<Item>();
> selectionList.add(findItem(itemURI));
> editor.setSelection(new StructuredSelection(selectionList));
>
>
> That doesn't seem to do the trick.
No, that sets what the editor normally updates itself based on
selections in the viewer.
>
> I have access to the editor, the IEditorPart , the resource and the
> item. So to me it seems I have all the ingredients together.. :)
You need to call the setSelectionToViewer method to actually update the
selection in the active view within the editor.

>
>
> Any help would be great!
> Thanks, Markus


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Programatically select Item in Editor in different window [message #904427 is a reply to message #904369] Tue, 28 August 2012 12:14 Go to previous messageGo to next message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi Ed,
thanks a lot for the reply. The EditUIUtil.openEditor() is much nicer than the way I had implemented it before.

So now opening the editor is working well. But extending the tree view and selecting my element is still now working properly.

I tried your suggestion
			
List<Element> selectionList = new LinkedList<Element>();
selectionList.add(searchedForElement);

editor.setSelectionToViewer(selectionList);	


and also, because it seemed promising:
editor.getViewer().setSelection(new StructuredSelection(searchedForElement), true);


But both don't change the viewer.

Do you have another idea how I could select that item?

[Updated on: Tue, 28 August 2012 12:15]

Report message to a moderator

Re: Programatically select Item in Editor in different window [message #904435 is a reply to message #904427] Tue, 28 August 2012 12:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Markus,

Is searchedForParam really an EObject contained in a resource contained
by that editor's resource set? Do your item providers require any
wrapping in which case you have to find the wrapper using something like
AdapterFactoryEditingDomain.getWrapper to get the object that should be
selected. Note that if you debug through that method, it better not get
to the very last return, because in that case your object isn't really
in the tree...


On 28/08/2012 2:14 PM, Markus G wrote:
> Hi Ed,
> thanks a lot for the reply. The EditUIUtil.openEditor() is much nicer
> than the way I had implemented it before.
>
> So now opening the editor is working well. But extending the tree view
> and selecting my element is still now working properly.
>
> I tried your suggestion
>
> List<AbstractParameter> selectionList = new
> LinkedList<AbstractParameter>();
> selectionList.add(searchedForElement);
>
>
> and also, because it seemed promising:
> editor.getViewer().setSelection(new
> StructuredSelection(searchedForParam), true);
>
>
> But both don't change the viewer.
>
> Do you have another idea how I could select that item?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Programatically select Item in Editor in different window [message #904443 is a reply to message #904435] Tue, 28 August 2012 12:35 Go to previous messageGo to next message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi Ed,

I'm pretty sure that searchedForElement is contained in a resource.
EditUIUtil.openEditor(searchedForElement)

also opens the editor correctly, so that should already prove that the element is present and contained in a resource contained by that editor's resource set, right?

Doesn't that also mean that it's definitly in the tree? Otherwise the openEditor call would fail, no?


I did not explicitly add anything connected to wrappers in my ItemProviders. What exactly would that mean?

Can I simply put that one element into a LinkedList and give it to the editor, though? Maybe that's the problem..?

Thanks!

[Updated on: Tue, 28 August 2012 12:37]

Report message to a moderator

Re: Programatically select Item in Editor in different window [message #904466 is a reply to message #904443] Tue, 28 August 2012 13:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Markus,

Comments below.
On 28/08/2012 2:35 PM, Markus G wrote:
> Hi Ed,
>
> I'm pretty sure that searchedForElement is contained in a resource.
Yes, a resource, but if you look at what that utility does, it
determines the URI of the containing resource and opens an editor for
that URI. That editor will have its own copy of the resource and its
contained objects object, not the same instance you started with. You
need to get the instance in that editor.

> EditUIUtil.openEditor(searchedForElement)
>
> also opens the editor correctly, so that should already proves that
> the element is present and contained in a resource contained by that
> editor's resource set, right?
No.
>
> Doesn't that also mean that it's definitly in the tree? Otherwise the
> openEditor call would fail, no?
No. Unless you did something to locate the object actually created by
the editor, you won't have the right object. EcoreUtil.getURI will
create a URI for your object. ResourceSet.getEObject can resolve that
URI in the resource set of the editor you've opened.
>
>
> I did not explicitly add anything connected to wrappers in my
> ItemProviders. What exactly would that mean?
Given you've not really provided much detail, there's no point in me
explaining complex things that might not even apply.
>
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Programatically select Item in Editor in different window [message #905347 is a reply to message #904466] Thu, 30 August 2012 08:00 Go to previous messageGo to next message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi Ed,

thanks. Yes, you're right, but the wrapping most probably isn't my problem, so you're right, there's no point in you wasting effort to explain that complex topic here.

My problem was that I didn't see that opening a new editor opens a new instance of my resource..

So, after opening the new editor, can I access my model's root element? Then I could simply use my find function again to locate the element I'm looking for and select it then.

Thanks!
Re: Programatically select Item in Editor in different window [message #905372 is a reply to message #905347] Thu, 30 August 2012 09:00 Go to previous message
Markus G is currently offline Markus GFriend
Messages: 23
Registered: June 2012
Junior Member
Hi Ed,

never mdin my last post, I figured it out myself.

Once again thanks a lot for your support!!
Previous Topic:[CDO] Finding detached objects
Next Topic:XSDEcoreBuilder, Validation
Goto Forum:
  


Current Time: Sat Apr 20 05:00:50 GMT 2024

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

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

Back to the top