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