blob: 942432432430f86c60e0831801ea17c1ab44982a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*******************************************************************************
* Copyright (c) 2016 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.tcf.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.action.ContributionManager;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.QuickMenuCreator;
import org.eclipse.ui.menus.IMenuService;
public class DefaultContextActionsCommandHandler extends AbstractHandler {
protected static final String DEFAULT_CONTEXT_ACTIONS_URI = "org.eclipse.tcf.te.tcf.ui.DefaultContextActionsToolbarContribution"; //$NON-NLS-1$
protected Point menuLocation = null;
private final QuickMenuCreator fMenuCreator = new QuickMenuCreator() {
@SuppressWarnings("cast")
@Override
protected void fillMenu(IMenuManager menu) {
if (!(menu instanceof ContributionManager)) {
return;
}
IMenuService service = (IMenuService) PlatformUI.getWorkbench()
.getService(IMenuService.class);
menu.add(new Separator("group.connect")); //$NON-NLS-1$
menu.add(new Separator("group.launch")); //$NON-NLS-1$
menu.add(new Separator("group.launch.rundebug")); //$NON-NLS-1$
menu.add(new Separator("group.history")); //$NON-NLS-1$
menu.add(new Separator("group.additions")); //$NON-NLS-1$
service.populateContributionManager((ContributionManager) menu, "menu:" + DEFAULT_CONTEXT_ACTIONS_URI); //$NON-NLS-1$
for (IContributionItem item : menu.getItems()) {
item.update();
}
}
@Override
protected Point computeMenuLocation(Control focus) {
if (menuLocation != null) {
return menuLocation;
}
return super.computeMenuLocation(focus);
}
};
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// Get the position of the ToolItem
if (event.getTrigger() instanceof Event) {
Event eventTrigger = (Event) event.getTrigger();
if (eventTrigger.widget instanceof ToolItem) {
ToolItem toolItem = (ToolItem) eventTrigger.widget;
Rectangle bounds = toolItem.getBounds();
if ( bounds != null ) {
menuLocation = toolItem.getParent().toDisplay(bounds.x, bounds.y + bounds.height);
}
}
}
fMenuCreator.createMenu();
return null;
}
}
|