Home » Modeling » EMF » Programatically select Item in Editor in different window
|
Re: Programatically select Item in Editor in different window [message #904369 is a reply to message #904360] |
Tue, 28 August 2012 10:27 |
Ed Merks Messages: 33146 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 |
Markus G 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 #904443 is a reply to message #904435] |
Tue, 28 August 2012 12:35 |
Markus G 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 |
Ed Merks Messages: 33146 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/
|
|
| | |
Goto Forum:
Current Time: Sat May 11 08:54:55 GMT 2024
Powered by FUDForum. Page generated in 0.04902 seconds
|