From a213cf49b17f35586400359cb65d1ba00ba1c868 Mon Sep 17 00:00:00 2001 From: axelcl Date: Wed, 19 Oct 2005 16:19:23 +0000 Subject: [PATCH] Added some examples for context menu on Outline --- net.sourceforge.phpeclipse.tests/plugin.xml | 13 ++-- .../phpeclipse/example/outline/Import2Console.java | 64 +++++++++++++++++ .../phpeclipse/example/outline/Type2Console.java | 74 ++++++++++++++++++++ 3 files changed, 144 insertions(+), 7 deletions(-) create mode 100644 net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Import2Console.java create mode 100644 net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Type2Console.java diff --git a/net.sourceforge.phpeclipse.tests/plugin.xml b/net.sourceforge.phpeclipse.tests/plugin.xml index c206c99..852ac88 100644 --- a/net.sourceforge.phpeclipse.tests/plugin.xml +++ b/net.sourceforge.phpeclipse.tests/plugin.xml @@ -21,7 +21,6 @@ - @@ -87,21 +86,21 @@ diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Import2Console.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Import2Console.java new file mode 100644 index 0000000..7586ca9 --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Import2Console.java @@ -0,0 +1,64 @@ +package net.sourceforge.phpeclipse.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); + + } + +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Type2Console.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Type2Console.java new file mode 100644 index 0000000..6bbe516 --- /dev/null +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/example/outline/Type2Console.java @@ -0,0 +1,74 @@ +package net.sourceforge.phpeclipse.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.swt.widgets.*; +import org.eclipse.ui.*; + +public class Type2Console implements IObjectActionDelegate { + private IWorkbenchPartSite myPartSite = null; + + private IWorkspace myWorkspace = null; + + private IWorkbenchPart myWorkbenchPart = null; + + private IType myType = null; + + private Shell myShell = new Shell(); // TBReplaced with getShell() + + public Type2Console() { + } + + /** + * @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 = (IType) item; // this plugin only reacts to + // "org.eclipse.jdt.core.IType" objects + } + } + + private void showSourceInConsole(String actionId) throws Exception { + if (!(myType.isInterface() || myType.isClass())) { + throw new Exception("incompatible Type"); + } + + IMethod[] methods = myType.getMethods(); + + String fqname = myType.getFullyQualifiedName(); // a.b.c.d.MyClass + System.out.println(fqname + '\n'); + for (int i = 0; i < methods.length; i++) { + System.out.println("Method " + i + ":" + + methods[i].getElementName()); + } + + } + +} -- 1.7.1