2b049413385301ce029419c14c06e25c312c1a93
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / filter / FilterEditUtils.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Kalray
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Xavier Raynaud - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.views.filter;
14
15 import org.eclipse.jface.util.LocalSelectionTransfer;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.tracecompass.tmf.core.filter.model.ITmfFilterTreeNode;
19
20 /**
21 * Utilities for cut/copy/paste/dnd in filter view
22 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
23 */
24 class FilterEditUtils {
25
26 /**
27 * Gets the ITmfFilterTreeNode in LocalSelectionTransfer, if any
28 * @return a ITmfFilterTreeNode or <code>null</code>
29 */
30 public static ITmfFilterTreeNode getTransferredTreeNode() {
31 ITmfFilterTreeNode treeNodeToDrop = null;
32 ISelection sel = LocalSelectionTransfer.getTransfer().getSelection();
33 if (sel instanceof IStructuredSelection) {
34 IStructuredSelection selection = (IStructuredSelection) sel;
35 for (Object data : selection.toList()) {
36 if (!(data instanceof ITmfFilterTreeNode)) {
37 return null;
38 } else if (treeNodeToDrop != null) {
39 // should never occur, since tree has SWT.SINGLE style
40 return null;
41 } else {
42 treeNodeToDrop = (ITmfFilterTreeNode) data;
43 }
44 }
45 }
46 return treeNodeToDrop;
47 }
48 }
This page took 0.051037 seconds and 4 git commands to generate.