| /******************************************************************************* |
| * Copyright (c) 2000, 2007 IBM Corporation and others. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| |
| *******************************************************************************/ |
| package org.eclipse.dltk.internal.ui.util; |
| |
| import java.util.List; |
| |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| |
| public class SelectionUtil { |
| |
| public static List toList(ISelection selection) { |
| if (selection instanceof IStructuredSelection) |
| return ((IStructuredSelection)selection).toList(); |
| return null; |
| } |
| |
| /** |
| * Returns the selected element if the selection |
| * consists of a single element only. |
| * |
| * @param s the selection |
| * @return the selected first element or null |
| * |
| */ |
| public static Object getSingleElement(ISelection s) { |
| if (!(s instanceof IStructuredSelection)) |
| return null; |
| IStructuredSelection selection= (IStructuredSelection)s; |
| if (selection.size() != 1) |
| return null; |
| |
| return selection.getFirstElement(); |
| } |
| } |