Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Outline refresh question
Outline refresh question [message #555738] Sat, 28 August 2010 01:07 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The root node of my outline is the resulting model's root, and I compute
the label for this node as follows:

String text(BeeModel ele) {
String s = ele.eResource().getURI().lastSegment();
return Strings.isEmpty(s)
? "resource"
: s;
}

When a user invokes "save as", the resource will change name, and the
label needs to be updated.

Grateful for a hint how to best trigger a refresh of the outline node in
this case.

Regards
- henrik
Re: Outline refresh question [message #555759 is a reply to message #555738] Sat, 28 August 2010 11:07 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

a brute force way might be to invoke a dummy modify unit of work (doing
nothing to the model) before the save-as. I think this should also
trigger the update of the outline.
For a more subtle way, one would have to check what usually triggers the
update.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Outline refresh question [message #555781 is a reply to message #555759] Sat, 28 August 2010 15:54 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
A dummy modify(UOW..) that does nothing has no effect. It seems to be
smart enough to figure out that nothing has changed (state.isModified()
return false).

It is difficult to perform a dummy change as this is taking place in
generic code.

Any other hints?

- henrik

On 8/28/10 1:07 PM, Alexander Nittka wrote:
> Hi,
>
> a brute force way might be to invoke a dummy modify unit of work (doing
> nothing to the model) before the save-as. I think this should also
> trigger the update of the outline.
> For a more subtle way, one would have to check what usually triggers the
> update.
>
> Alex
Re: Outline refresh question [message #555789 is a reply to message #555781] Sat, 28 August 2010 18:50 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
... again without too much digging, so no guarantee. How about binding your own XtextContentOutlinePage implementation (making an "externalRefresh" visible).

In your XtextEditor you should be able to retrieve it via the getAdapter method (see XtextEditor implementation) and invoke that externalRefresh after saveAs has been performed.

Alex
Re: Outline refresh question [message #555797 is a reply to message #555781] Sat, 28 August 2010 21:05 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

you could try to make
org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage. refresh()
public and obtain the outline-page from the editor via
editor#getAdapter(IContentOutlinePage.class).

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 28.08.10 17:54, schrieb Henrik Lindberg:
> A dummy modify(UOW..) that does nothing has no effect. It seems to be
> smart enough to figure out that nothing has changed (state.isModified()
> return false).
>
> It is difficult to perform a dummy change as this is taking place in
> generic code.
>
> Any other hints?
>
> - henrik
>
> On 8/28/10 1:07 PM, Alexander Nittka wrote:
>> Hi,
>>
>> a brute force way might be to invoke a dummy modify unit of work (doing
>> nothing to the model) before the save-as. I think this should also
>> trigger the update of the outline.
>> For a more subtle way, one would have to check what usually triggers the
>> update.
>>
>> Alex
>
Re: Outline refresh question [message #555798 is a reply to message #555797] Sat, 28 August 2010 21:07 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Lesson learned: Refresh the newsreader before answering a question.
Alex proposed basically the same.

Am 28.08.10 23:05, schrieb Sebastian Zarnekow:
> Hi Henrik,
>
> you could try to make
> org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage. refresh()
> public and obtain the outline-page from the editor via
> editor#getAdapter(IContentOutlinePage.class).
>
> Regards,
> Sebastian
Re: Outline refresh question [message #555855 is a reply to message #555789] Sun, 29 August 2010 16:29 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Thanks guys - overriding the outline page and refreshing it worked fine.
Below is the solution
Regards
- henrik

Override in editor :

@Override
public void doSaveAs() {
super.doSaveAs();
// force refresh of content outline
IContentOutlinePage outlinePage = (IContentOutlinePage)
getAdapter(IContentOutlinePage.class);
if(outlinePage instanceof RefreshableXtextContentOutlinePage)
((RefreshableXtextContentOutlinePage) outlinePage).externalRefresh();
}

The refreshable outline page class:
public class RefreshableXtextContentOutlinePage extends
XtextContentOutlinePage {
public void externalRefresh() {
super.refresh();
}
}

And the binding:

@Override
public Class<? extends IContentOutlinePage> bindIContentOutlinePage() {
return RefreshableXtextContentOutlinePage.class;
}

On 8/28/10 8:50 PM, Alexander Nittka wrote:
> ... again without too much digging, so no guarantee. How about binding
> your own XtextContentOutlinePage implementation (making an
> "externalRefresh" visible).
>
> In your XtextEditor you should be able to retrieve it via the getAdapter
> method (see XtextEditor implementation) and invoke that externalRefresh
> after saveAs has been performed.
>
> Alex
Re: Outline refresh question [message #631056 is a reply to message #555797] Wed, 06 October 2010 01:04 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 8/28/10 11:05 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> you could try to make
> org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage. refresh()
> public and obtain the outline-page from the editor via
> editor#getAdapter(IContentOutlinePage.class).

I got that working fine for the root node change. I later discovered
that the outline page stops refreshing after a "save as" because the
outline page continues to listen to "the old model".

Hacking around this was not easy because it was not possible to just
create an alternative implementation and bind with guice as the toolbar
configurer used expects an instance of XtextContentOutlinePage - I was
not sure if I should just replace that as well, but it seemed quicker to
just hack up a solution (as I by that time understood what was going on
in the outline page).

I ended up with a class derived from XtextContentOutlinePage that
overrides everything (just to make it work as an equivalent
replacement), and then adding:

/**
* Special method that should be called from performSavedAs
*/
public void externalRefresh() {
// Must drop old listener (should ideally get rid of the listener, but
since the document changed already (??)
// it will probably not unregister for the correct document.
modelListener = null;
// Install a model listener for the current document
installModelListener();
refresh();
}

This was the only way I could figure out to reset the (private)
modelListener.

At first I thought I would need to hang on to the xtextDocument (so I
could unregister using the correct instance, but that is probably bad as
it then holds on to that object. My hack seems to work - but may have
some other surprises in store...

Since the outline management things are changing, I don't know how to go
from here - log an issue? Attatch my hacked class? or just describe the
issue.

Regards
- henrik
Re: Outline refresh question [message #631220 is a reply to message #631056] Wed, 06 October 2010 15:07 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Any input ?
Should I just go ahead and log an issue?

- henrik
On 10/6/10 3:04 AM, Henrik Lindberg wrote:
> On 8/28/10 11:05 PM, Sebastian Zarnekow wrote:
>> Hi Henrik,
>>
>> you could try to make
>> org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage. refresh()
>> public and obtain the outline-page from the editor via
>> editor#getAdapter(IContentOutlinePage.class).
>
> I got that working fine for the root node change. I later discovered
> that the outline page stops refreshing after a "save as" because the
> outline page continues to listen to "the old model".
>
> Hacking around this was not easy because it was not possible to just
> create an alternative implementation and bind with guice as the toolbar
> configurer used expects an instance of XtextContentOutlinePage - I was
> not sure if I should just replace that as well, but it seemed quicker to
> just hack up a solution (as I by that time understood what was going on
> in the outline page).
>
> I ended up with a class derived from XtextContentOutlinePage that
> overrides everything (just to make it work as an equivalent
> replacement), and then adding:
>
> /**
> * Special method that should be called from performSavedAs
> */
> public void externalRefresh() {
> // Must drop old listener (should ideally get rid of the listener, but
> since the document changed already (??)
> // it will probably not unregister for the correct document.
> modelListener = null;
> // Install a model listener for the current document
> installModelListener();
> refresh();
> }
>
> This was the only way I could figure out to reset the (private)
> modelListener.
>
> At first I thought I would need to hang on to the xtextDocument (so I
> could unregister using the correct instance, but that is probably bad as
> it then holds on to that object. My hack seems to work - but may have
> some other surprises in store...
>
> Since the outline management things are changing, I don't know how to go
> from here - log an issue? Attatch my hacked class? or just describe the
> issue.
>
> Regards
> - henrik
Re: Outline refresh question [message #631243 is a reply to message #631220] Wed, 06 October 2010 16:16 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

yes that would be very helpful (with you hack attached). Please log
other issues that you had with the Save As impl as well.

Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 06.10.10 17:07, schrieb Henrik Lindberg:
> Any input ?
> Should I just go ahead and log an issue?
>
> - henrik
> On 10/6/10 3:04 AM, Henrik Lindberg wrote:
>> On 8/28/10 11:05 PM, Sebastian Zarnekow wrote:
>>> Hi Henrik,
>>>
>>> you could try to make
>>> org.eclipse.xtext.ui.editor.outline.XtextContentOutlinePage. refresh()
>>> public and obtain the outline-page from the editor via
>>> editor#getAdapter(IContentOutlinePage.class).
>>
>> I got that working fine for the root node change. I later discovered
>> that the outline page stops refreshing after a "save as" because the
>> outline page continues to listen to "the old model".
>>
>> Hacking around this was not easy because it was not possible to just
>> create an alternative implementation and bind with guice as the toolbar
>> configurer used expects an instance of XtextContentOutlinePage - I was
>> not sure if I should just replace that as well, but it seemed quicker to
>> just hack up a solution (as I by that time understood what was going on
>> in the outline page).
>>
>> I ended up with a class derived from XtextContentOutlinePage that
>> overrides everything (just to make it work as an equivalent
>> replacement), and then adding:
>>
>> /**
>> * Special method that should be called from performSavedAs
>> */
>> public void externalRefresh() {
>> // Must drop old listener (should ideally get rid of the listener, but
>> since the document changed already (??)
>> // it will probably not unregister for the correct document.
>> modelListener = null;
>> // Install a model listener for the current document
>> installModelListener();
>> refresh();
>> }
>>
>> This was the only way I could figure out to reset the (private)
>> modelListener.
>>
>> At first I thought I would need to hang on to the xtextDocument (so I
>> could unregister using the correct instance, but that is probably bad as
>> it then holds on to that object. My hack seems to work - but may have
>> some other surprises in store...
>>
>> Since the outline management things are changing, I don't know how to go
>> from here - log an issue? Attatch my hacked class? or just describe the
>> issue.
>>
>> Regards
>> - henrik
>
Re: Outline refresh question [message #631309 is a reply to message #631243] Thu, 07 October 2010 00:32 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Logged: https://bugs.eclipse.org/bugs/show_bug.cgi?id=327168
- henrik

On 10/6/10 6:16 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> yes that would be very helpful (with you hack attached). Please log
> other issues that you had with the Save As impl as well.
>
> Thanks,
> Sebastian
Re: Outline refresh question [message #631310 is a reply to message #631243] Thu, 07 October 2010 00:43 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 10/6/10 6:16 PM, Sebastian Zarnekow wrote:
> Hi Henrik,
>
> Please log
> other issues that you had with the Save As impl as well.
>
I have an implementation that turns open of external files to an open on
a linked file, and treats save and saveAs of such linked files as
external saves (as well as handling untitled external files).

The main use of this in our case is to support an RCP packaging without
a visible workspace.

This implementation works ok although there is an issue with not being
able to have the special "links" project hidden, which in our case only
matters when the solution is used inside the IDE (users see the special
"links" project).

The implementation is found in the b3 svn.

There were no real issues in implementing this except the difficulty in
making the ExtLinkedXtextEditor correctly interpret the situation when
an external file was being opened (and make this implementation work in
both an IDE, and in a RCP packaging).

In the RCP packaging we have a special actions for Open, etc. that links
the external file upfront, but when opening an external file in the IDE,
it is more difficult to manage the change to a link.

What of all of this would you like me to capture in bugzillas?
"Add support for external open/save/saveAs" with links to code in SVN?

Regards
- henrik
Re: Outline refresh question [message #631794 is a reply to message #631310] Fri, 08 October 2010 18:51 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Henrik,

> "Add support for external open/save/saveAs" with links to code in SVN?

Yes, that would be helpful.

Thanks,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Outline refresh question [message #631843 is a reply to message #631794] Sat, 09 October 2010 02:21 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 10/8/10 8:51 PM, Sebastian Zarnekow wrote:
> Add support for external open/save/saveAs

Logged :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=327374

Regards
- henrik
Previous Topic:Detecting if semantic model changed at build
Next Topic:Question about MWE2 and generating Code
Goto Forum:
  


Current Time: Thu Apr 25 06:53:57 GMT 2024

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

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

Back to the top