| /** |
| * <copyright> |
| * |
| * Copyright (c) 2009-2010 Thales Corporate Services S.A.S. |
| * This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-v2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Thales Corporate Services S.A.S - initial API and implementation |
| * |
| * </copyright> |
| */ |
| |
| package org.eclipse.egf.model.editor.contributions; |
| |
| import org.eclipse.egf.core.ui.contributor.EditorListenerContributor; |
| import org.eclipse.egf.model.fcore.InvocationContract; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.jface.action.Action; |
| import org.eclipse.jface.viewers.DoubleClickEvent; |
| import org.eclipse.jface.viewers.IDoubleClickListener; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.jface.viewers.StructuredViewer; |
| import org.eclipse.ui.IWorkbenchPage; |
| |
| /** |
| * @author Thomas Guiu |
| * |
| */ |
| public class OpenInvocationContractListenerContributor extends EditorListenerContributor { |
| |
| @Override |
| public void addListener(final IWorkbenchPage page, StructuredViewer viewer) { |
| if (page == null || viewer == null) { |
| return; |
| } |
| IDoubleClickListener listener = new IDoubleClickListener() { |
| |
| public void doubleClick(DoubleClickEvent event) { |
| if (event.getSelection().isEmpty()) { |
| return; |
| } |
| final Object object = ((IStructuredSelection) event.getSelection()).getFirstElement(); |
| if (object instanceof InvocationContract) { |
| OpenInvocationContractMenuContributor menu = new OpenInvocationContractMenuContributor(); |
| Action openAction = menu.new InvocationContractOpenAction() { |
| |
| @Override |
| protected EObject getEObject() { |
| return ((InvocationContract) object).getInvokedContract(); |
| } |
| |
| }; |
| openAction.run(); |
| } |
| } |
| }; |
| viewer.addDoubleClickListener(listener); |
| _listeners.put(viewer, listener); |
| } |
| |
| } |