Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Cannot add an item to the toolbar programmatically
Cannot add an item to the toolbar programmatically [message #1137376] Mon, 14 October 2013 12:51 Go to next message
Pawel Zalejko is currently offline Pawel ZalejkoFriend
Messages: 14
Registered: October 2013
Junior Member
Hi,

I'm trying to create a toolbar that will be filled in programmatically. Unfortunately I cannot add a new item to the toolbar due to ClassCastException. I try to add a button to the toolbar in the following way:

String commandId = "example.command";
MToolBar toolbar = ...

MHandledToolItem element = eModelService.createModelElement(MHandledToolItem.class);
element.setElementId("my.new.item.id");
element.setLabel("New item");

ParameterizedCommand wbCommand = getCommand(commandId);
element.setWbCommand(wbCommand);

toolbar.getChildren().add(element);



The last line throws the ClassCastException exception:

java.lang.ClassCastException: org.eclipse.fx.ui.workbench.renderers.fx.DefToolItemRenderer$ToolItemImpl cannot be cast to org.eclipse.fx.ui.workbench.renderers.base.widget.WLayoutedWidget
	at org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.childRendered(BaseToolBarRenderer.java:103)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.childRendered(BaseToolBarRenderer.java:1)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:161)
	at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:251)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.engineCreateWidget(BaseRenderer.java:307)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.handleChildrenAddition(BaseToolBarRenderer.java:135)
	at org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.handleChildrenAddition(BaseToolBarRenderer.java:1)
	at org.eclipse.fx.ui.workbench.renderers.base.EventProcessor$1.handleEvent(EventProcessor.java:41)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
	at org.eclipse.fx.ui.workbench.fx.E4Application$1.syncExec(E4Application.java:156)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)



I also encountered one more issue with the toolbar. After starting my application all toolbar buttons(that I declared in the Application.e4xmi) are disabled. I checked your demo application (e4 Media Application) and toolbar is disabled as well.


Re: Cannot add an item to the toolbar programmatically [message #1137566 is a reply to message #1137376] Mon, 14 October 2013 15:31 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
On 14.10.13 17:05, Pawel Zalejko wrote:
> Hi,
>
> I'm trying to create a toolbar that will be filled in programmatically.
> Unfortunately I cannot add a new item to the toolbar due to
> ClassCastException. I try to add a button to the toolbar in the
> following way:
>
>
> String commandId = "example.command";
> MToolBar toolbar = ...
>
> MHandledToolItem element =
> eModelService.createModelElement(MHandledToolItem.class);
> element.setElementId("my.new.item.id");
> element.setLabel("New item");
>
> ParameterizedCommand wbCommand = getCommand(commandId);
> element.setWbCommand(wbCommand);
>
> toolbar.getChildren().add(element);
>
>
> The last line throws the ClassCastException exception:
> java.lang.ClassCastException:
> org.eclipse.fx.ui.workbench.renderers.fx.DefToolItemRenderer$ToolItemImpl cannot
> be cast to
> org.eclipse.fx.ui.workbench.renderers.base.widget.WLayoutedWidget
> at
> org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.childRendered(BaseToolBarRenderer.java:103)
>
> at
> org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.childRendered(BaseToolBarRenderer.java:1)
>
> at
> org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:161)
>
> at
> org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:251)
>
> at
> org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.engineCreateWidget(BaseRenderer.java:307)
>
> at
> org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.handleChildrenAddition(BaseToolBarRenderer.java:135)
>
> at
> org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.handleChildrenAddition(BaseToolBarRenderer.java:1)
>
> at
> org.eclipse.fx.ui.workbench.renderers.base.EventProcessor$1.handleEvent(EventProcessor.java:41)
>
> at
> org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
>
> at
> org.eclipse.fx.ui.workbench.fx.E4Application$1.syncExec(E4Application.java:156)
>
> at
> org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
>
> at
> org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
>
> at
> org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
>
> at
> org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
>
> at
> org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
>

Filed as https://bugs.eclipse.org/bugs/show_bug.cgi?id=419373 and fixed
in master.

>
>
> I also encountered one more issue with the toolbar. After starting my
> application all toolbar buttons(that I declared in the
> Application.e4xmi) are disabled. I checked your demo application (e4
> Media Application) and toolbar is disabled as well.
>

Filed as https://bugs.eclipse.org/bugs/show_bug.cgi?id=419375 and fixed
in master.

It looks like your Application.e4xmi is missing the
HandlerProcessingAddon. How did you bootstrap the the e4 application?

You can add it yourself next to the current addons:

<addons xmi:id="_CsUUmjTlEeOp9YyhHHv9bw"
elementId="org.eclipse.e4.ui.workbench.addons.HandlerProcessingAddon"
contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>

Tom
Re: Cannot add an item to the toolbar programmatically [message #1138497 is a reply to message #1137566] Tue, 15 October 2013 05:56 Go to previous messageGo to next message
Pawel Zalejko is currently offline Pawel ZalejkoFriend
Messages: 14
Registered: October 2013
Junior Member
Hi Tom,

I added the HandlerProcessingAddon and now the toolbar works like a charm. All buttons are enabled Smile

Thanks!
Re: Cannot add an item to the toolbar programmatically [message #1138870 is a reply to message #1137376] Tue, 15 October 2013 11:31 Go to previous messageGo to next message
Pawel Zalejko is currently offline Pawel ZalejkoFriend
Messages: 14
Registered: October 2013
Junior Member
Hi Tom,

It looks that the problem with disabled buttons is not resolved. All buttons added to the toolbar programmatically are disabled(those buttons that are declared in the Application.e4xmi work fine).

String commandId = "example.command";
MToolBar toolbar = ...

MHandledToolItem element = eModelService.createModelElement(MHandledToolItem.class);
element.setElementId("my.new.item.id");
element.setLabel("New item");

ParameterizedCommand wbCommand = getCommand(commandId);
element.setWbCommand(wbCommand);

// Set true in order to enable the button.
element.setEnabled(true);
element.setVisible(true);
element.setToBeRendered(true);

toolbar.getChildren().add(element);


Even when I set following flags on "true" the problem is present:

element.setEnabled(true);
element.setVisible(true);
element.setToBeRendered(true);
Re: Cannot add an item to the toolbar programmatically [message #1138897 is a reply to message #1138870] Tue, 15 October 2013 11:54 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
Can you please file a bug please and post the bug id to this thread.

Tom

On 15.10.13 13:31, Pawel Zalejko wrote:
> Hi Tom,
>
> It looks that the problem with disabled buttons is not resolved. All
> buttons added to the toolbar programmatically are disabled(those buttons
> that are declared in the Application.e4xmi work fine).
>
>
> String commandId = "example.command";
> MToolBar toolbar = ...
>
> MHandledToolItem element =
> eModelService.createModelElement(MHandledToolItem.class);
> element.setElementId("my.new.item.id");
> element.setLabel("New item");
>
> ParameterizedCommand wbCommand = getCommand(commandId);
> element.setWbCommand(wbCommand);
>
> // Set true in order to enable the button.
> element.setEnabled(true);
> element.setVisible(true);
> element.setToBeRendered(true);
>
> toolbar.getChildren().add(element);
>
>
> Even when I set following flags on "true" the problem is present:
>
>
> element.setEnabled(true);
> element.setVisible(true);
> element.setToBeRendered(true);
>
Re: Cannot add an item to the toolbar programmatically [message #1138913 is a reply to message #1138897] Tue, 15 October 2013 12:05 Go to previous messageGo to next message
Pawel Zalejko is currently offline Pawel ZalejkoFriend
Messages: 14
Registered: October 2013
Junior Member
Filed as https://bugs.eclipse.org/bugs/show_bug.cgi?id=419443.

Pawel

[Updated on: Tue, 15 October 2013 12:06]

Report message to a moderator

Re: Cannot add an item to the toolbar programmatically [message #1139044 is a reply to message #1137376] Tue, 15 October 2013 13:53 Go to previous messageGo to next message
Pawel Zalejko is currently offline Pawel ZalejkoFriend
Messages: 14
Registered: October 2013
Junior Member
I have also one question regarding the toolbar. Is it possible to make that toolbar's width will be the same as a window's width (set e.g. maxWidth="Infinity")?

[Updated on: Tue, 15 October 2013 13:54]

Report message to a moderator

Re: Cannot add an item to the toolbar programmatically [message #1139072 is a reply to message #1139044] Tue, 15 October 2013 14:15 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
http://wiki.eclipse.org/Efxclipse/Runtime/e4#MTrimElement

Tom

On 15.10.13 15:53, Pawel Zalejko wrote:
> I have also one question regarding the toolbar. Is it possible to make
> that toolbar's width will be the same as a window's width (set e.g.
> maxHeight="Infinity")?
Re: Cannot add an item to the toolbar programmatically [message #1139161 is a reply to message #1138913] Tue, 15 October 2013 15:28 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5487
Registered: July 2009
Senior Member
Your code is wrong you need assign an MCommand

Tom

On 15.10.13 14:05, Pawel Zalejko wrote:
> Filled as https://bugs.eclipse.org/bugs/show_bug.cgi?id=419443.
>
> Pawel
Re: Cannot add an item to the toolbar programmatically [message #1140218 is a reply to message #1137376] Wed, 16 October 2013 07:54 Go to previous message
Pawel Zalejko is currently offline Pawel ZalejkoFriend
Messages: 14
Registered: October 2013
Junior Member
Hi Tom,

You are right. It should be MCommand.

Many thanks for your efforts.

Pawel
Previous Topic:InjectionException at runtime of SWT/JavaFX product build with Maven
Next Topic:Model Processing and Rendering Window children of a Window
Goto Forum:
  


Current Time: Wed Dec 17 20:04:31 GMT 2014

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

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