public void mouseClicked(MouseEvent e) {\r
ClickEvent event = new ClickEvent(\r
Modifiers.modifierString(e.getButton(), e.isControlDown(), e.isAltDown(), e.isShiftDown()),\r
- editor.screenToDiagram(e.getPoint())\r
+ editor.screenToDiagram(e.getPoint()),\r
+ e.getLocationOnScreen()\r
);\r
event.pickedElements = dragEvent.pickedElements;\r
editor.handleEvent(event);\r
\r
// Click location in diagram coordinates\r
final public Point2D point;\r
+ final public Point2D dispPoint;\r
\r
public List<IElement> pickedElements;\r
\r
- public ClickEvent(String modifiers, Point2D point) {\r
+ public ClickEvent(String modifiers, Point2D point, Point2D dispPoint) {\r
this.modifiers = modifiers;\r
+ this.dispPoint = dispPoint;\r
this.point = point;\r
}\r
\r
\r
public static void configure(IDiagramEditor editor) {\r
editor.addEventHandler(1, "click(left)", new PickSelection());\r
- editor.addEventHandler(1, "click(ctrl+left)", new ToggleSelection()); \r
+ editor.addEventHandler(1, "click(ctrl+left)", new ToggleSelection());\r
editor.addEventHandler(1, "drag(alt+middle)", new Pan());\r
editor.addEventHandler(1, "wheel()", new Zoom());\r
editor.addEventHandler(1, "key(1)", new ZoomToFit());\r
--- /dev/null
+package org.simantics.sysdyn.ui.actions;\r
+\r
+import org.eclipse.jface.action.GroupMarker;\r
+import org.eclipse.jface.action.IMenuListener;\r
+import org.eclipse.jface.action.IMenuManager;\r
+import org.eclipse.jface.action.MenuManager;\r
+import org.eclipse.jface.action.Separator;\r
+import org.eclipse.swt.graphics.Point;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.Menu;\r
+import org.eclipse.ui.IWorkbenchActionConstants;\r
+import org.eclipse.ui.IWorkbenchPartSite;\r
+import org.simantics.h2d.editor.IDiagramEditor;\r
+import org.simantics.h2d.event.ClickEvent;\r
+import org.simantics.h2d.event.IEvent;\r
+import org.simantics.h2d.event.handler.IEventHandler;\r
+import org.simantics.ui.action.GraphMenuManager;\r
+\r
+public class OpenContextMenu implements IEventHandler {\r
+ \r
+ Control control;\r
+ IWorkbenchPartSite site;\r
+ String menuId;\r
+ \r
+ MenuManager menuManager;\r
+ \r
+ public OpenContextMenu(Control control, IWorkbenchPartSite site,\r
+ String menuId) {\r
+ super();\r
+ this.control = control;\r
+ this.site = site;\r
+ this.menuId = menuId;\r
+ menuManager = createPopupMenu();\r
+ if (menuManager != null) {\r
+ Menu menu = menuManager.createContextMenu(control);\r
+ control.setMenu(menu);\r
+ if (site != null) {\r
+ site.registerContextMenu(menuManager.getId(), menuManager, \r
+ site.getSelectionProvider());\r
+ }\r
+ }\r
+ }\r
+\r
+ @Override\r
+ public boolean handle(IDiagramEditor editor, IEvent _event) {\r
+ final ClickEvent event = (ClickEvent)_event;\r
+ control.getDisplay().asyncExec(new Runnable() {\r
+\r
+ @Override\r
+ public void run() {\r
+ if (control.isDisposed())\r
+ return;\r
+ //Point p = control.toDisplay(event.getLocation().get(int) cp.getX(), (int) cp.getY());\r
+ menuManager.getMenu().setLocation(\r
+ new Point((int)event.dispPoint.getX(), (int)event.dispPoint.getY()));\r
+ menuManager.getMenu().setVisible(true);\r
+ }\r
+ \r
+ });\r
+ return true;\r
+ }\r
+ \r
+ protected MenuManager createPopupMenu() {\r
+ final MenuManager mm = new GraphMenuManager("Diagram Popup", menuId);\r
+ mm.setRemoveAllWhenShown(true);\r
+ mm.addMenuListener(new IMenuListener() {\r
+ public void menuAboutToShow(IMenuManager manager) {\r
+ mm.add(new GroupMarker(IWorkbenchActionConstants.WB_START));\r
+ mm.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));\r
+ mm.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));\r
+ mm.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+ mm.add(new GroupMarker(IWorkbenchActionConstants.WB_END));\r
+ }\r
+ });\r
+ return mm;\r
+ }\r
+\r
+}\r
import org.simantics.objmap.MappingException;\r
import org.simantics.objmap.Mappings;\r
import org.simantics.scenegraph.INode;\r
-import org.simantics.scenegraph.utils.NodeUtil;\r
import org.simantics.sysdyn.ui.actions.ConnectDependency;\r
import org.simantics.sysdyn.ui.actions.ConnectFlow;\r
import org.simantics.sysdyn.ui.actions.CreateAuxiliary;\r
import org.simantics.sysdyn.ui.actions.CreateCloud;\r
import org.simantics.sysdyn.ui.actions.CreateStock;\r
import org.simantics.sysdyn.ui.actions.CreateValve;\r
+import org.simantics.sysdyn.ui.actions.OpenContextMenu;\r
import org.simantics.ui.SimanticsUI;\r
import org.simantics.ui.workbench.ResourceEditorPart;\r
import org.simantics.utils.ui.jface.ActiveSelectionProvider;\r
}\r
\r
@Override\r
- public void createPartControl(Composite parent) {\r
+ public void createPartControl(final Composite parent) {\r
final Composite composite = new Composite(parent, \r
SWT.NO_BACKGROUND | SWT.EMBEDDED);\r
frame = SWT_AWT.new_Frame(composite);\r
final ActiveSelectionProvider selectionProvider = new ActiveSelectionProvider();\r
getSite().setSelectionProvider(selectionProvider);\r
\r
+ final OpenContextMenu openContextMenu = new OpenContextMenu(\r
+ parent, getSite(), "#ModelingDiagramPopup");\r
+ \r
SwingUtilities.invokeLater(new Runnable() {\r
\r
@Override\r
editor.addEventHandler(1, "key(C)", new CreateCloud());\r
editor.addEventHandler(1, "drag(alt+left)", new ConnectDependency());\r
editor.addEventHandler(1, "drag(alt+right)", new ConnectFlow());\r
+ editor.addEventHandler(1, "click(right)", openContextMenu); \r
\r
canvas = new EditorCanvas(editor);\r
frame.add(canvas);\r