Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » What is the best way to remove a MToolControl from main toolbar if part is deactivated?
What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802030] Thu, 31 January 2019 07:26 Go to next message
Thomas Fahrmeyer is currently offline Thomas FahrmeyerFriend
Messages: 30
Registered: July 2009
Location: Germany
Member
Hi,

I have a part that contributes a MToolControl to the main toolbar not the part local toolbar. The needed behavior is that this toolcontrol is removed from the toolbar if a new part gets activated. It should behave like a Command where the handler is provided by the part. If the part gets deactivated, the handler will be removed and the command is deactivated.

What is the best way to achieve the toolcontrol removal if the providing part is deactivated?

Thanks in advance.
Thomas
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802070 is a reply to message #1802030] Thu, 31 January 2019 17:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I'm sure I follow. How is a part providing an MToolControl?
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802071 is a reply to message #1802070] Thu, 31 January 2019 17:21 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Anyways - did you try a visibleWhen expression - a programtic one, and there you let the system in inject the active part and based upon that you return true/false? I also guess part activation might be a good addon for our lifecycle story?
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802079 is a reply to message #1802071] Thu, 31 January 2019 21:45 Go to previous messageGo to next message
Thomas Fahrmeyer is currently offline Thomas FahrmeyerFriend
Messages: 30
Registered: July 2009
Location: Germany
Member
Tom, thanks for the fast replay, as ever ;)

The MToolControl would be added by toolbar.getChildren().add(control). To specify a position I would need to create a toolbarcontribution, correct?

I was not aware that a toolcontrol can have a visibleWhen expression, because the model editor does not provide the possibility to define one. I need to have a look how to create such expression programmatically. Do you have a fast link to some sample code?

How can the active part be injected? The Api of MUIElement takes an instance of an MExpression, but the part injection should be done at lifetime. Ah, I could just define a setter method with @Inject. But as far as I know something like
@Inject
public void setPart(@Active MPart activePart)
 

is not supported. A hint is appreciated.

What I'm missing (is not a lack of efxclipse) is an Api to provide toolbar and maybe menu contributions context sensitiv to the providing part. It should work in the same way as a local part handler is managed. I think it is not uncommon that a part is providing some stuff to the main toolbar. If the part gets deactivated, these contributions should go away. Do I'm wrong?

Even if the VisibleWhen stuff is working, the toolcontrol is still a child of the toolbar and therefore not garbage collected. If it holds a reference to a big chunk of memory, that is really bad.

The last think: I not fully understood the hint for the addon? Can you elaborate a little bit more?

Thanks for your time and the very good work in efxclipse ;)
Thomas
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802105 is a reply to message #1802079] Fri, 01 February 2019 09:06 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
let's first clarify what you mean with "Deactivated":
* Part is closed
* Part is not the current one focused and hidden inside a stack
* Part is on top of the stack but not focused

The only way to destroy something is that you set it as toBeRendered false.
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802120 is a reply to message #1802105] Fri, 01 February 2019 14:38 Go to previous messageGo to next message
Thomas Fahrmeyer is currently offline Thomas FahrmeyerFriend
Messages: 30
Registered: July 2009
Location: Germany
Member
I mainly mean that the part is not active. The same semantic as if a command gets disabled because the registered handler is removed.

If a part contributes something relative to its IEclipseContext, I would expect that all that stuff is not active/usable anymore if this part is not active. In my opinion it is not active if anything you mentioned happens.

Let describe my use case: There is a perspective where parts are arranged side by side. One is displaying images another one a PDF file for instance. If the Image Part is active (clicked by the user) every action that is useable by the Image Viewer (like Brightness/Contrast manipulation buttons) is visible in the main toolbar. If the user activates the PDF Part, the Brightness/Contrast Toolbar item should not be visible. That could be done by the mentioned expression. There would be no memory leak because the Image Part still exists. That's fine. But if the the Image part is closed, everything needs to really be removed from the toolbar, otherwise some classes referenced from the toolbar item can not be "garbage collected".

Maybe I'm thinking to complicated, but I like the local handler registration of a part and the management of these handlers very much. I'd like to extend the concept to support toolbar contributions for the any toolbar as well.

Ok, that is not yet possible I would need to do the following:
* define a programmatic MExpression for the MToolControl provided by my part which returns false, if another part is active. That is good for switching to another part
* implement a @PreDestroy method which removes the contribution from the toolbar. The @PreDestroy method is called if part.setToBeRendered(false) is called

Tom, if you maybe can elaborate a little bit more about the lifecycle hook, that would be great.

Thanks
Thomas



Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802227 is a reply to message #1802120] Mon, 04 February 2019 17:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Let's create a ticket and discuss there - in the end I think we want something like we had in 3.x where one could push elements to the tool and menubar without worrying to provide visible when, ...
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802246 is a reply to message #1802227] Tue, 05 February 2019 07:48 Go to previous messageGo to next message
Thomas Fahrmeyer is currently offline Thomas FahrmeyerFriend
Messages: 30
Registered: July 2009
Location: Germany
Member
I could create an enhancement ticket, but in which repo? It is a e4 issue not efxclipse, isn't? Is it a good practice to references to this topic here?

Thanks for your time
Thomas
Re: What is the best way to remove a MToolControl from main toolbar if part is deactivated? [message #1802248 is a reply to message #1802246] Tue, 05 February 2019 08:14 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
efxclipse-rt is the repo and yes post a link here
Previous Topic:Error opening workspace after installing e(fx)
Next Topic:Is there an approximate release date for efxclipse 3.5?
Goto Forum:
  


Current Time: Thu Dec 12 15:26:22 GMT 2024

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

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

Back to the top