/******************************************************************************* * Copyright (c) 2004, 2010 BREDEX GmbH. * 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: * BREDEX GmbH - initial API and implementation and/or initial documentation *******************************************************************************/ package org.eclipse.jubula.client.inspector.ui.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.TreeNode; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.ui.handlers.HandlerUtil; /** * Handles the Copy command within the Component Inspector View. * * @author BREDEX GmbH * @created Jun 12, 2009 */ public class InspectorCopyHandler extends AbstractHandler { /** * * {@inheritDoc} */ public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (selection instanceof IStructuredSelection) { IStructuredSelection structSel = (IStructuredSelection)selection; Object firstElement = structSel.getFirstElement(); if (firstElement instanceof TreeNode) { firstElement = ((TreeNode)firstElement).getValue(); } if (firstElement instanceof String []) { String [] element = (String [])firstElement; if (element.length > 0) { Clipboard cb = new Clipboard( HandlerUtil.getActiveShellChecked(event) .getDisplay()); cb.setContents( new String [] {element[0]}, new Transfer[] {TextTransfer.getInstance()}); cb.dispose(); } } } return null; } }