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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.swt;
\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
27 * The default JFace double click event handler for {@link GraphExplorer}.
\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
37 * @author Tuukka Lehtonen
\r
39 * @see IPriorityAction
\r
41 public class DefaultMouseListener extends GraphExplorerMouseAdapter {
\r
43 public DefaultMouseListener(GraphExplorer ge) {
\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
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
60 public void exception(Throwable t) {
\r
61 ErrorLogger.defaultLogError(ChooseActionRequest.class.getName() + " failed, see exception for details.", t);
\r