| /******************************************************************************* |
| * Copyright (c) 2012 SAP AG. |
| * 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: |
| * Georgi Konstantinov - initial API and implementation. |
| *******************************************************************************/ |
| package org.eclipse.wst.sse.sieditor.search.ui.actions; |
| |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.wst.sse.sieditor.model.api.IModelObject; |
| import org.eclipse.wst.sse.sieditor.search.i18n.Messages; |
| import org.eclipse.wst.sse.sieditor.ui.v2.dt.clipboard.ClipboardService; |
| import org.eclipse.wst.sse.sieditor.ui.v2.nodes.ITreeNode; |
| |
| public class CopyAction extends AbstractActiveOnSingleSelectionAction { |
| |
| public CopyAction(ISelection selection) { |
| super(selection); |
| } |
| |
| @Override |
| public void run() { |
| final Object firstElementFromSelection = getStructuredSelectionFirstElement(); |
| |
| IModelObject modelObject = ((ITreeNode) firstElementFromSelection).getModelObject(); |
| |
| ClipboardService.copyModelObjectToClipboard(modelObject); |
| } |
| |
| @Override |
| public boolean isEnabled() { |
| if (!super.isEnabled()) { |
| return false; |
| } |
| |
| Object firstElement = getStructuredSelectionFirstElement(); |
| return ClipboardService.isCopyEnabled(firstElement); |
| } |
| |
| @Override |
| public String getText() { |
| return Messages.CopyAction_Label; |
| } |
| } |