Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Misplaced drop down menu in a toolbar drop-down item when working with ActionCon
Misplaced drop down menu in a toolbar drop-down item when working with ActionCon [message #112329] Thu, 13 November 2008 09:31 Go to next message
No real name is currently offline No real nameFriend
Messages: 3
Registered: July 2009
Junior Member
Hi all,

I'd like to realize a drop down menu in a (arbitrarily positioned) toolbar
using ToolBarManager and ActionContributionItem. Unfortunately with RAP
the menu pops up at a wrong position when pressing the arrow button while
the same code is running fine under RCP.

Backtracking the effect one can find the reason for it in
ActionContributionItem.handleWidgetSelection() at

if (mc != null) {
Menu m = mc.getMenu(ti.getParent());
if (m != null) {
// position the menu below the drop down item
Point point = ti.getParent().toDisplay(new Point(e.x, e.y));
Point p = ti.getParent().toDisplay(
new Point(e.x, e.y));
m.setLocation(p.x, p.y); // waiting for SWT
// 0.42
m.setVisible(true);
return; // we don't fire the action
}
}

in the RAP version (which is slightly different to the RCP implementation
where the coordinates of the toolitem are taken directly from the OS).
Here RAP seems to take coordinates from the processed event that are
already absolute values (where the control should be positioned) but
treats them as relatives, i.e. starts an additional translation in
Control.toDisplay() which in the end leads to a misplaced control.

Debugging a little deeper one can see that these coordinates are already
set as absolute ones when instantiating the event in
DropDownToolItemDelegateLCA.readData() resp.
ToolItemLCAUtil.newSelectionEvent() - can't estimate if this is the wanted
behavior.

It would be nice if you could take a look at the effect and help me to
find out wether there's a mistake in my approach of realizing a drop down
toolitem or possibly a little bug in the RAP implementation?

You can easily reproduce it with the following code. Just replace the view
coding of the RAP project template "RAP Application with a view" by the
code below. (Your view ID will probabely be different of course.)

Thanks in advance
Rainer


public class View extends ViewPart {
public static final String ID = "DropDownBug.view";



public void createPartControl(Composite parent) {
RowLayout rowLayout = new RowLayout();
rowLayout.wrap = false;
rowLayout.pack = true;
rowLayout.justify = false;
rowLayout.type = SWT.VERTICAL;
parent.setLayout(rowLayout);


ToolBarManager tbm = new ToolBarManager();
tbm.createControl(parent);

IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
tbm.add(org.eclipse.ui.actions.ActionFactory.NEW.create(wind ow));
tbm.add(org.eclipse.ui.actions.ActionFactory.DELETE.create(w indow));

tbm.add(new DropDownAction(IAction.AS_DROP_DOWN_MENU));

tbm.update(true);


}

/**
* Passing the focus request to the viewer's control.
*/
public void setFocus() {
}

public class DropDownAction extends Action implements IMenuCreator {
private Menu fMenu;


public DropDownAction(final int style) {
super("DropDownAction", style);
setMenuCreator(this);
}


@Override
public void run() {
int i = 0;
}


public void dispose() {
if (this.fMenu != null) {
this.fMenu.dispose();
this.fMenu = null;
}
}


public Menu getMenu(final Control parent) {
if (this.fMenu != null) {
// this.fMenu.dispose();
return this.fMenu;
}

this.fMenu = new Menu(parent);
this.fMenu.addMenuListener(new MenuListener() {

public void menuHidden(final MenuEvent e) {
}


public void menuShown(final MenuEvent e) {
// DropDownAction.this.fMenu.setLocation(new Point(58, 71));
}

});

ActionContributionItem item = new ActionContributionItem(new
Action("Say hi 1") {
public void run() {
Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
MessageDialog.openInformation(shell, "Message", "Hi all ...");
}
});
item.fill(this.fMenu, -1);

new MenuItem(this.fMenu, SWT.SEPARATOR);

ActionContributionItem item2 = new ActionContributionItem(new
Action("Say hi 2") {
public void run() {
Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
MessageDialog.openInformation(shell, "Message", "Good night ...");
}
});
item2.fill(this.fMenu, -1);

return this.fMenu;

}


public Menu getMenu(final Menu parent) {
return null;
}
}
}
Re: Misplaced drop down menu in a toolbar drop-down item when working with ActionCon [message #112416 is a reply to message #112329] Fri, 14 November 2008 10:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rsternberg.innoopract.com

Hi Rainer,

thanks a lot for your analysis. I can reproduce the problem and I'm
pretty sure this is a bug in RAP because a) it works in RCP and b) you
didn't deal with positions in your code at all.

May I ask you to file a bug [1] and append your snippet and the pointers
you found? This ensures that the issue doesn't get lost and allows you
to keep track of it.

Thanks, Ralf

[1] http://www.eclipse.org/rap/bugs.php

Rainer wrote:
> Hi all,
>
> I'd like to realize a drop down menu in a (arbitrarily positioned)
> toolbar using ToolBarManager and ActionContributionItem. Unfortunately
> with RAP the menu pops up at a wrong position when pressing the arrow
> button while the same code is running fine under RCP.
>
> Backtracking the effect one can find the reason for it in
> ActionContributionItem.handleWidgetSelection() at
> if (mc != null) {
> Menu m = mc.getMenu(ti.getParent());
> if (m != null) {
> // position the menu below the drop down item
> Point point = ti.getParent().toDisplay(new Point(e.x, e.y));
> Point p = ti.getParent().toDisplay(
> new Point(e.x, e.y));
> m.setLocation(p.x, p.y); // waiting for SWT
> // 0.42
> m.setVisible(true);
> return; // we don't fire the action
> }
> }
>
> in the RAP version (which is slightly different to the RCP
> implementation where the coordinates of the toolitem are taken directly
> from the OS). Here RAP seems to take coordinates from the processed
> event that are already absolute values (where the control should be
> positioned) but treats them as relatives, i.e. starts an additional
> translation in Control.toDisplay() which in the end leads to a misplaced
> control.
>
> Debugging a little deeper one can see that these coordinates are already
> set as absolute ones when instantiating the event in
> DropDownToolItemDelegateLCA.readData() resp.
> ToolItemLCAUtil.newSelectionEvent() - can't estimate if this is the
> wanted behavior.
>
> It would be nice if you could take a look at the effect and help me to
> find out wether there's a mistake in my approach of realizing a drop
> down toolitem or possibly a little bug in the RAP implementation?
>
> You can easily reproduce it with the following code. Just replace the
> view coding of the RAP project template "RAP Application with a view" by
> the code below. (Your view ID will probabely be different of course.)
>
> Thanks in advance
> Rainer
>
>
> public class View extends ViewPart {
> public static final String ID = "DropDownBug.view";
>
>
>
> public void createPartControl(Composite parent) {
> RowLayout rowLayout = new RowLayout();
> rowLayout.wrap = false;
> rowLayout.pack = true;
> rowLayout.justify = false;
> rowLayout.type = SWT.VERTICAL;
> parent.setLayout(rowLayout);
>
>
> ToolBarManager tbm = new ToolBarManager();
> tbm.createControl(parent);
>
> IWorkbenchWindow window =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
> tbm.add(org.eclipse.ui.actions.ActionFactory.NEW.create(wind ow));
>
> tbm.add(org.eclipse.ui.actions.ActionFactory.DELETE.create(w indow));
>
> tbm.add(new DropDownAction(IAction.AS_DROP_DOWN_MENU));
>
> tbm.update(true);
>
>
> }
>
> /**
> * Passing the focus request to the viewer's control.
> */
> public void setFocus() {
> }
>
> public class DropDownAction extends Action implements IMenuCreator {
> private Menu fMenu;
>
>
> public DropDownAction(final int style) {
> super("DropDownAction", style);
> setMenuCreator(this);
> }
>
>
> @Override
> public void run() {
> int i = 0;
> }
>
>
> public void dispose() {
> if (this.fMenu != null) {
> this.fMenu.dispose();
> this.fMenu = null;
> }
> }
>
>
> public Menu getMenu(final Control parent) {
> if (this.fMenu != null) {
> // this.fMenu.dispose();
> return this.fMenu;
> }
>
> this.fMenu = new Menu(parent);
> this.fMenu.addMenuListener(new MenuListener() {
>
> public void menuHidden(final MenuEvent e) {
> }
>
>
> public void menuShown(final MenuEvent e) {
> // DropDownAction.this.fMenu.setLocation(new
> Point(58, 71));
> }
>
> });
>
> ActionContributionItem item = new ActionContributionItem(new
> Action("Say hi 1") {
> public void run() {
> Shell shell =
> PlatformUI.getWorkbench().getDisplay().getActiveShell();
> MessageDialog.openInformation(shell, "Message", "Hi
> all ...");
> }
> });
> item.fill(this.fMenu, -1);
>
> new MenuItem(this.fMenu, SWT.SEPARATOR);
>
> ActionContributionItem item2 = new
> ActionContributionItem(new Action("Say hi 2") {
> public void run() {
> Shell shell =
> PlatformUI.getWorkbench().getDisplay().getActiveShell();
> MessageDialog.openInformation(shell, "Message",
> "Good night ...");
> }
> });
> item2.fill(this.fMenu, -1);
>
> return this.fMenu;
>
> }
>
>
> public Menu getMenu(final Menu parent) {
> return null;
> }
> }
> }
>
Re: Misplaced drop down menu in a toolbar drop-down item when working with ActionCon [message #112443 is a reply to message #112416] Fri, 14 November 2008 18:58 Go to previous message
No real name is currently offline No real nameFriend
Messages: 3
Registered: July 2009
Junior Member
Ralf Sternberg wrote:

> Hi Rainer,

> thanks a lot for your analysis. I can reproduce the problem and I'm
> pretty sure this is a bug in RAP because a) it works in RCP and b) you
> didn't deal with positions in your code at all.

> May I ask you to file a bug [1] and append your snippet and the pointers
> you found? This ensures that the issue doesn't get lost and allows you
> to keep track of it.

> Thanks, Ralf

> [1] http://www.eclipse.org/rap/bugs.php

> Rainer wrote:
>> Hi all,
>>
>> I'd like to realize a drop down menu in a (arbitrarily positioned)
>> toolbar using ToolBarManager and ActionContributionItem. Unfortunately
>> with RAP the menu pops up at a wrong position when pressing the arrow
>> button while the same code is running fine under RCP.
>>
>> Backtracking the effect one can find the reason for it in
>> ActionContributionItem.handleWidgetSelection() at
>> if (mc != null) {
>> Menu m = mc.getMenu(ti.getParent());
>> if (m != null) {
>> // position the menu below the drop down item
>> Point point = ti.getParent().toDisplay(new Point(e.x, e.y));
>> Point p = ti.getParent().toDisplay(
>> new Point(e.x, e.y));
>> m.setLocation(p.x, p.y); // waiting for SWT
>> // 0.42
>> m.setVisible(true);
>> return; // we don't fire the action
>> }
>> }
>>
>> in the RAP version (which is slightly different to the RCP
>> implementation where the coordinates of the toolitem are taken directly
>> from the OS). Here RAP seems to take coordinates from the processed
>> event that are already absolute values (where the control should be
>> positioned) but treats them as relatives, i.e. starts an additional
>> translation in Control.toDisplay() which in the end leads to a misplaced
>> control.
>>
>> Debugging a little deeper one can see that these coordinates are already
>> set as absolute ones when instantiating the event in
>> DropDownToolItemDelegateLCA.readData() resp.
>> ToolItemLCAUtil.newSelectionEvent() - can't estimate if this is the
>> wanted behavior.
>>
>> It would be nice if you could take a look at the effect and help me to
>> find out wether there's a mistake in my approach of realizing a drop
>> down toolitem or possibly a little bug in the RAP implementation?
>>
>> You can easily reproduce it with the following code. Just replace the
>> view coding of the RAP project template "RAP Application with a view" by
>> the code below. (Your view ID will probabely be different of course.)
>>
>> Thanks in advance
>> Rainer
>>
>>
>> public class View extends ViewPart {
>> public static final String ID = "DropDownBug.view";
>>
>>
>>
>> public void createPartControl(Composite parent) {
>> RowLayout rowLayout = new RowLayout();
>> rowLayout.wrap = false;
>> rowLayout.pack = true;
>> rowLayout.justify = false;
>> rowLayout.type = SWT.VERTICAL;
>> parent.setLayout(rowLayout);
>>
>>
>> ToolBarManager tbm = new ToolBarManager();
>> tbm.createControl(parent);
>>
>> IWorkbenchWindow window =
>> PlatformUI.getWorkbench().getActiveWorkbenchWindow();
>> tbm.add(org.eclipse.ui.actions.ActionFactory.NEW.create(wind ow));
>>
>> tbm.add(org.eclipse.ui.actions.ActionFactory.DELETE.create(w indow));
>>
>> tbm.add(new DropDownAction(IAction.AS_DROP_DOWN_MENU));
>>
>> tbm.update(true);
>>
>>
>> }
>>
>> /**
>> * Passing the focus request to the viewer's control.
>> */
>> public void setFocus() {
>> }
>>
>> public class DropDownAction extends Action implements IMenuCreator {
>> private Menu fMenu;
>>
>>
>> public DropDownAction(final int style) {
>> super("DropDownAction", style);
>> setMenuCreator(this);
>> }
>>
>>
>> @Override
>> public void run() {
>> int i = 0;
>> }
>>
>>
>> public void dispose() {
>> if (this.fMenu != null) {
>> this.fMenu.dispose();
>> this.fMenu = null;
>> }
>> }
>>
>>
>> public Menu getMenu(final Control parent) {
>> if (this.fMenu != null) {
>> // this.fMenu.dispose();
>> return this.fMenu;
>> }
>>
>> this.fMenu = new Menu(parent);
>> this.fMenu.addMenuListener(new MenuListener() {
>>
>> public void menuHidden(final MenuEvent e) {
>> }
>>
>>
>> public void menuShown(final MenuEvent e) {
>> // DropDownAction.this.fMenu.setLocation(new
>> Point(58, 71));
>> }
>>
>> });
>>
>> ActionContributionItem item = new ActionContributionItem(new
>> Action("Say hi 1") {
>> public void run() {
>> Shell shell =
>> PlatformUI.getWorkbench().getDisplay().getActiveShell();
>> MessageDialog.openInformation(shell, "Message", "Hi
>> all ...");
>> }
>> });
>> item.fill(this.fMenu, -1);
>>
>> new MenuItem(this.fMenu, SWT.SEPARATOR);
>>
>> ActionContributionItem item2 = new
>> ActionContributionItem(new Action("Say hi 2") {
>> public void run() {
>> Shell shell =
>> PlatformUI.getWorkbench().getDisplay().getActiveShell();
>> MessageDialog.openInformation(shell, "Message",
>> "Good night ...");
>> }
>> });
>> item2.fill(this.fMenu, -1);
>>
>> return this.fMenu;
>>
>> }
>>
>>
>> public Menu getMenu(final Menu parent) {
>> return null;
>> }
>> }
>> }
>>
Hi Ralf,

okay, it's done. I've used the default for the assignment, I hope it's
okay.

As closing comment: one can bypass the problem by registering a
SelectionListener with the ToolItem corresponding to the drop-down action,
finding out the "attached" menu and sending an event to it charged with
the right coordinates. In the menuShown() event handler of the menu one
can correct the location.

For example

final ToolItem item = toolBarManager.getControl().getItem(xyz);
item.addListener(SWT.Selection, new Listener() {
public void handleEvent(final Event event) {
Point point = new Point(event.x, event.y);

ActionContributionItem contribution = (ActionContributionItem)
item.getData();
NewItemMenuCreator creator = (NewItemMenuCreator)
contribution.getAction().getMenuCreator();
Menu menu = creator.getMenu(toolBarManager.getControl());

MenuEvent myEvent = new MenuEvent(menu, MenuEvent.MENU_SHOWN);
myEvent.data = point;
myEvent.processEvent();
}

and

this.fMenu.addMenuListener(new MenuListener() {

...

public void menuShown(final MenuEvent e) {
Point location = (Point) e.data;
if (location != null) {
DropDownAction.this.fMenu.setLocation(location);
}
}

Still waiting for side effects ;-)) and without it would be better of
course! But for the moment ...

Best regards
Rainer
Previous Topic:ParameterizedCommand.generateCommand
Next Topic:JAAS authorization problem in RAP application
Goto Forum:
  


Current Time: Fri Apr 26 13:44:41 GMT 2024

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

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

Back to the top