Command selected state [message #993118] |
Sun, 23 December 2012 07:43  |
Eclipse User |
|
|
|
Hi
when I create a checkbox style command ("Cmd1") which shall be visible in the menu bar and the toolbar, the state is not synchronized.
What do I miss, to get the "checked" state maintained by a single state only?
// Command decl
<commands xmi:id="_2EdVYEr2EeK2l8Ho1g9J8Q" elementId="e4test2.command.0" commandName="Cmd1" description="Cmd1 Description"/>
// Handler decl
<handlers xmi:id="_bGiy4Er1EeK2l8Ho1g9J8Q" elementId="e4test2.handler.0" contributionURI="bundleclass://E4Test2/e4test2.StdHandler" command="_2EdVYEr2EeK2l8Ho1g9J8Q"/>
// main toolbar decl
<trimBars xmi:id="_VOV6ANTAEeGTY-uOtVc6Mg">
<children xsi:type="menu:ToolBar" xmi:id="toolbar:org.eclipse.ui.main.toolbar" elementId="">
<children xsi:type="menu:HandledToolItem" xmi:id="_bcx2sEr3EeK2l8Ho1g9J8Q" elementId="e4test2.handleditem.cmd1" label="cmd1lbl" iconURI="platform:/plugin/E4Test2/icons/alt_window_16.gif" type="Check" command="_2EdVYEr2EeK2l8Ho1g9J8Q"/>
// main menu decl
<mainMenu xmi:id="_ydmDwErzEeK2l8Ho1g9J8Q" elementId="e4test2.menu.0">
<children xsi:type="menu:Menu" xmi:id="_wP9uAEz1EeKq5-u9QAXssw" elementId="e4test2.menu.file" label="File" mnemonics="">
<children xsi:type="menu:HandledMenuItem" xmi:id="_3EQsUEz1EeKq5-u9QAXssw" elementId="org.eclipse.ui.file.exit" label="Exit" command="_MBOOcEz2EeKq5-u9QAXssw"/>
</children>
<children xsi:type="menu:Menu" xmi:id="_7W0uQErzEeK2l8Ho1g9J8Q" elementId="e4test2.menu.0" label="Example">
<children xsi:type="menu:HandledMenuItem" xmi:id="_809Y0Er2EeK2l8Ho1g9J8Q" elementId="e4test2.handleditem.cmd1" selected="true" type="Check" command="_2EdVYEr2EeK2l8Ho1g9J8Q"/>
</children>
</mainMenu>
thanks
Frank
|
|
|
|
|
Re: Command selected state [message #994973 is a reply to message #994964] |
Fri, 28 December 2012 14:01   |
Eclipse User |
|
|
|
Now I found a E4 solution.
I mark the HandledMenuItem and HandledToolbarItem with "MyTag" tag.
When the event occurs, I get the handledItem injected, to get the selected state. The previously ToggleState is no more needed.
Then find all UI contribs with EModelService.findElements and update them with setSelected.
@Execute
public void run( @Active MPart part, @Active MWindow window, MHandledItem handledItem ){
// handle the event ...
// find the other UI contribs and update the checked state
List<String> tags = new LinkedList<>();
tags.add("MyTag");
List<MHandledItem> elements = modelServ.findElements(window.getMainMenu(), null, MHandledItem.class, tags );
elements.addAll( modelServ.findElements(window, null, MHandledItem.class, tags ) );
for( MHandledItem hi : elements ){
System.out.println("element : "+hi.getElementId());
hi.setSelected(handledItem.isSelected());
}
}
What is not nice about this are two things:
1. the tags should not be needed. Is there a way with just refering to the command ID?
2. the findElements does not include the main menu. Is this a bug?
thanks Frank
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08019 seconds