/* * Copyright (C) 2006 Davy Vanherbergen * dvanherbergen@users.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package net.sourceforge.sqlexplorer.dbstructure.actions; import net.sourceforge.sqlexplorer.Messages; import net.sourceforge.sqlexplorer.util.ImageUtil; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.dnd.TextTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.widgets.Display; /** * Copy the name of the selected node. * * @author Davy Vanherbergen */ public class CopyNodeNameAction extends AbstractDBTreeContextAction { private static final ImageDescriptor _image = ImageUtil.getDescriptor("Images.CopyAlias"); /** * Custom image for copy action * * @see org.eclipse.jface.action.IAction#getImageDescriptor() */ public ImageDescriptor getImageDescriptor() { return _image; } /** * Set the text for the menu entry. * * @see org.eclipse.jface.action.IAction#getText() */ public String getText() { return Messages.getString("DatabaseStructureView.Actions.CopyNodeName"); } /** * Copy the name of the selected node to the clipboard. * * @see org.eclipse.jface.action.IAction#run() */ public void run() { Clipboard clipBoard = new Clipboard(Display.getCurrent()); TextTransfer textTransfer = TextTransfer.getInstance(); StringBuffer text = new StringBuffer(""); String sep = ""; for (int i = 0; i < _selectedNodes.length; i++) { text.append(sep); text.append(_selectedNodes[i].getQualifiedName()); sep = ", "; } clipBoard.setContents(new Object[] {text.toString()}, new Transfer[] {textTransfer}); } /** * Action is availble when a node is selected * * @see net.sourceforge.sqlexplorer.dbstructure.actions.AbstractDBTreeContextAction#isAvailable() */ public boolean isAvailable() { if (_selectedNodes.length == 0) { return false; } return true; } }