package net.sourceforge.example.outline; import org.eclipse.core.resources.*; import net.sourceforge.phpdt.core.*; import org.eclipse.jface.action.*; import org.eclipse.jface.viewers.*; import org.eclipse.ui.*; public class Import2Console implements IObjectActionDelegate { private IWorkbenchPartSite myPartSite = null; private IWorkspace myWorkspace = null; private IWorkbenchPart myWorkbenchPart = null; private IImportDeclaration myType = null; public Import2Console() { // this(new PackageSelector()); } // public CreateMock(IPackageSelector aPackageSelector) { // myPackageSelector = aPackageSelector; // } /** * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) */ public void setActivePart(IAction action, IWorkbenchPart targetPart) { myWorkspace = ResourcesPlugin.getWorkspace(); myWorkbenchPart = targetPart; } /** * @see IActionDelegate#run(IAction) */ public void run(IAction action) { try { String actionId = action.getId(); showSourceInConsole(actionId); } catch (Exception e) { e.printStackTrace(); } } /** * @see IActionDelegate#selectionChanged(IAction, ISelection) */ public void selectionChanged(IAction action, ISelection selection) { if (selection instanceof IStructuredSelection) { Object item = ((IStructuredSelection) selection).getFirstElement(); myType = (IImportDeclaration) item; // this plugin only reacts to IImportDeclaration's } } private void showSourceInConsole(String actionId) throws Exception { String src = myType.getSource(); System.out.println("Source :"+src); } }