1 /*******************************************************************************
2 * Copyright (c) 2013 Kalray
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
10 * Xavier Raynaud - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.filter
;
15 import org
.eclipse
.core
.commands
.AbstractHandler
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.ITmfFilterTreeNode
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.filter
.model
.TmfFilterNode
;
20 import org
.eclipse
.ui
.IWorkbenchPage
;
21 import org
.eclipse
.ui
.IWorkbenchPart
;
22 import org
.eclipse
.ui
.IWorkbenchWindow
;
23 import org
.eclipse
.ui
.PlatformUI
;
26 * Handler for paste command in filter view
27 * @author Xavier Raynaud <xavier.raynaud@kalray.eu>
30 public class PasteHandler
extends AbstractHandler
{
33 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
34 // Check if we are closing down
35 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
41 IWorkbenchPage page
= window
.getActivePage();
42 IWorkbenchPart part
= page
.getActivePart();
43 if (!(part
instanceof FilterView
)) {
46 FilterView v
= (FilterView
) part
;
48 ITmfFilterTreeNode objectToPaste
= FilterEditUtils
.getTransferredTreeNode();
49 objectToPaste
= objectToPaste
.clone();
50 ITmfFilterTreeNode sel
= v
.getSelection();
51 if (sel
== null || TmfFilterNode
.NODE_NAME
.equals(objectToPaste
.getNodeName())) {
52 sel
= v
.getFilterRoot();
55 sel
.addChild(objectToPaste
);
57 v
.setSelection(objectToPaste
);
62 public boolean isEnabled() {
63 // Check if we are closing down
64 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
70 IWorkbenchPage page
= window
.getActivePage();
71 IWorkbenchPart part
= page
.getActivePart();
72 if (!(part
instanceof FilterView
)) {
75 FilterView v
= (FilterView
) part
;
76 ITmfFilterTreeNode sel
= v
.getSelection();
78 sel
= v
.getFilterRoot();
80 ITmfFilterTreeNode objectToPaste
= FilterEditUtils
.getTransferredTreeNode();
81 if (objectToPaste
!= null &&
82 (sel
.getValidChildren().contains(objectToPaste
.getNodeName())
83 || TmfFilterNode
.NODE_NAME
.equals(objectToPaste
.getNodeName()))) {