--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.swt;\r
+\r
+import org.eclipse.jface.viewers.ISelection;\r
+import org.eclipse.swt.widgets.Tree;\r
+import org.simantics.browsing.ui.GraphExplorer;\r
+import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
+import org.simantics.db.common.procedure.adapter.ProcedureAdapter;\r
+import org.simantics.ui.SimanticsUI;\r
+import org.simantics.ui.workbench.action.ChooseActionRequest;\r
+import org.simantics.utils.ui.AdaptionUtils;\r
+import org.simantics.utils.ui.ErrorLogger;\r
+import org.simantics.utils.ui.action.IPriorityAction;\r
+import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
+\r
+/**\r
+ * The default JFace double click event handler for {@link GraphExplorer}.\r
+ * \r
+ * <p>\r
+ * Consults every IDoubleClickAction in DoubleClickExtensionManager for possible\r
+ * actions for the selection resource. IDoubleClickActions can provide actions\r
+ * with priorities, see {@link IPriorityAction}. The handler selects the action\r
+ * with the highest priority and executes it. If there are multiple actions of\r
+ * the highest used priority, a dialog will be opened so that the user can\r
+ * choose the action to take.\r
+ * \r
+ * @author Tuukka Lehtonen\r
+ * \r
+ * @see IPriorityAction\r
+ */\r
+public class DefaultMouseListener extends GraphExplorerMouseAdapter {\r
+\r
+ public DefaultMouseListener(GraphExplorer ge) {\r
+ super(ge);\r
+ }\r
+\r
+ @Override\r
+ protected void handleContextDoubleClick(Tree tree, ISelection selection) {\r
+ // First see if node is an IDoubleClickableNode\r
+ IDoubleClickableNode doubleClickable = AdaptionUtils.adaptToSingle(selection, IDoubleClickableNode.class);\r
+ if (doubleClickable != null) {\r
+ if (doubleClickable.handleDoubleClick())\r
+ return;\r
+ }\r
+\r
+ // Try the doubleClick-extensions\r
+ final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();\r
+ SimanticsUI.getSession().asyncRequest(new ChooseActionRequest(tree.getShell(), ge, selection, perspectiveId), new ProcedureAdapter<Object>() {\r
+ @Override\r
+ public void exception(Throwable t) {\r
+ ErrorLogger.defaultLogError(ChooseActionRequest.class.getName() + " failed, see exception for details.", t);\r
+ }\r
+ });\r
+ }\r
+\r
+}\r