| /** |
| * Copyright (c) 2019 CEA. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * CEA - initial API and implementation and/or initial documentation |
| */ |
| package org.eclipse.sensinact.studio.ui.common.dialog; |
| |
| import org.eclipse.core.commands.AbstractHandler; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.jface.viewers.DoubleClickEvent; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.swt.widgets.Shell; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| |
| /** |
| * @author Etienne Gandrille |
| */ |
| public abstract class SnaHandler extends AbstractHandler { |
| |
| protected Shell getShell(ExecutionEvent event) { |
| return HandlerUtil.getActiveWorkbenchWindow(event).getShell(); |
| } |
| |
| protected Object getSelectedElement(ExecutionEvent event) { |
| ISelection selection = HandlerUtil.getCurrentSelection(event); |
| if (selection != null && selection instanceof IStructuredSelection) { |
| IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
| return structuredSelection.getFirstElement(); |
| } |
| return null; |
| } |
| |
| public static Shell getShell(DoubleClickEvent event) { |
| return event.getViewer().getControl().getShell(); |
| } |
| } |