1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.browsing.ui.swt;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.swt.widgets.Control;
16 import org.simantics.Simantics;
17 import org.simantics.browsing.ui.GraphExplorer;
18 import org.simantics.browsing.ui.common.node.IDoubleClickableNode;
19 import org.simantics.db.common.procedure.adapter.ProcedureAdapter;
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;
27 * The default JFace double click event handler for {@link GraphExplorer}.
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.
37 * @author Tuukka Lehtonen
39 * @see IPriorityAction
41 public class DefaultMouseListener extends GraphExplorerMouseAdapter {
43 public DefaultMouseListener(GraphExplorer ge) {
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())
56 // Try the doubleClick-extensions
57 final String perspectiveId = WorkbenchUtils.getCurrentPerspectiveId();
58 Simantics.getSession().asyncRequest(new ChooseActionRequest(tree.getShell(), ge, selection, perspectiveId), new ProcedureAdapter<Object>() {
60 public void exception(Throwable t) {
61 ErrorLogger.defaultLogError(ChooseActionRequest.class.getName() + " failed, see exception for details.", t);