blob: 0bfefcd75a2473b738ef9aa1a9f74cb1c9779cf3 [file] [log] [blame]
package org.eclipse.app4mc.emfutils.content.extractor.handlers;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.util.Iterator;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
public class CopyContentsHandler extends AbstractHandlerUtils{
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = null;
selection = HandlerUtil.getActiveMenuSelection(event);
if (selection == null) {
selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
}
StringBuffer sb=new StringBuffer();
if(selection instanceof IStructuredSelection) {
Iterator iterator = ((IStructuredSelection) selection).iterator();
while(iterator.hasNext()) {
Object next = iterator.next();
System.out.println(next);
if(next instanceof ENamedElement) {
String name = ((ENamedElement) next).getName();
sb.append(name);
sb.append(System.getProperty("line.separator"));
}
}
StringSelection selection1 = new StringSelection(sb.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection1, selection1);
}
return null;
}
}