]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultMouseListener.java
Merge remote-tracking branch 'origin/svn' commit 'ccc1271c9d6657fb9dcf4cf3cb115fa0c8c...
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / DefaultMouseListener.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.browsing.ui.swt;\r
13 \r
14 import org.eclipse.jface.viewers.ISelection;\r
15 import org.eclipse.swt.widgets.Control;\r
16 import org.simantics.browsing.ui.GraphExplorer;\r
17 import org.simantics.browsing.ui.common.node.IDoubleClickableNode;\r
18 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;\r
19 import org.simantics.ui.SimanticsUI;\r
20 import org.simantics.ui.workbench.action.ChooseActionRequest;\r
21 import org.simantics.utils.ui.AdaptionUtils;\r
22 import org.simantics.utils.ui.ErrorLogger;\r
23 import org.simantics.utils.ui.action.IPriorityAction;\r
24 import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
25 \r
26 /**\r
27  * The default JFace double click event handler for {@link GraphExplorer}.\r
28  * \r
29  * <p>\r
30  * Consults every IDoubleClickAction in DoubleClickExtensionManager for possible\r
31  * actions for the selection resource. IDoubleClickActions can provide actions\r
32  * with priorities, see {@link IPriorityAction}. The handler selects the action\r
33  * with the highest priority and executes it. If there are multiple actions of\r
34  * the highest used priority, a dialog will be opened so that the user can\r
35  * choose the action to take.\r
36  * \r
37  * @author Tuukka Lehtonen\r
38  * \r
39  * @see IPriorityAction\r
40  */\r
41 public class DefaultMouseListener extends GraphExplorerMouseAdapter {\r
42 \r
43     public DefaultMouseListener(GraphExplorer ge) {\r
44         super(ge);\r
45     }\r
46 \r
47     @Override\r
48     protected void handleContextDoubleClick(Control tree, ISelection selection) {\r
49         // First see if node is an IDoubleClickableNode\r
50         IDoubleClickableNode doubleClickable = AdaptionUtils.adaptToSingle(selection, IDoubleClickableNode.class);\r
51         if (doubleClickable != null) {\r
52             if (doubleClickable.handleDoubleClick())\r
53                 return;\r
54         }\r
55 \r
56         // Try the doubleClick-extensions\r
57         final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();\r
58         SimanticsUI.getSession().asyncRequest(new ChooseActionRequest(tree.getShell(), ge, selection, perspectiveId), new ProcedureAdapter<Object>() {\r
59             @Override\r
60             public void exception(Throwable t) {\r
61                 ErrorLogger.defaultLogError(ChooseActionRequest.class.getName() + " failed, see exception for details.", t);\r
62             }\r
63         });\r
64     }\r
65 \r
66 }\r