example for outline context menus
authorkhartlage <khartlage>
Tue, 17 Aug 2004 12:14:00 +0000 (12:14 +0000)
committerkhartlage <khartlage>
Tue, 17 Aug 2004 12:14:00 +0000 (12:14 +0000)
net.sourceforge.phpeclipse.tests/plugin.xml
net.sourceforge.phpeclipse.tests/src/net/sourceforge/example/outline/Import2Console.java [new file with mode: 0644]
net.sourceforge.phpeclipse.tests/src/net/sourceforge/example/outline/Type2Console.java [new file with mode: 0644]

index bbf5bd0..246473a 100644 (file)
       <import plugin="org.eclipse.core.resources"/>
    </requires>
 
-
+   <extension
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            objectClass="net.sourceforge.phpdt.core.IImportDeclaration"
+            id="net.sourceforge.phpdt.import">
+         <menu
+               label="IncludeTest"
+               path="additions"
+               id="net.sourceforge.phpdt.import1">
+            <separator
+                  name="mainActionsGroup">
+            </separator>
+            <separator
+                  name="actionsGroup">
+            </separator>
+            <separator
+                  name="infoGroup">
+            </separator>
+         </menu>
+         <action
+               label="Do nothing 1"
+               class="net.sourceforge.example.outline.Import2Console"
+               menubarPath="net.sourceforge.phpdt.import1/infoGroup"
+               enablesFor="1"
+               id="net.sourceforge.phpdt.donothing1">
+         </action>
+         <action
+               label="Print source to Console"
+               class="net.sourceforge.example.outline.Import2Console"
+               menubarPath="net.sourceforge.phpdt.import1/actionsGroup"
+               enablesFor="1"
+               id="net.sourceforge.example.outline.Import2Console">
+         </action>
+         <action
+               label="Do nothing 2"
+               class="net.sourceforge.example.outline.Import2Console"
+               menubarPath="net.sourceforge.phpdt.import1/mainActionsGroup"
+               enablesFor="1"
+               id="net.sourceforge.phpdt.donothing2">
+         </action>
+      </objectContribution>
+   </extension>
+      <extension
+         point="org.eclipse.ui.popupMenus">
+      <objectContribution
+            objectClass="net.sourceforge.phpdt.core.IType"
+            id="net.sourceforge.phpdt.type">
+         <menu
+               label="TypeTest"
+               path="additions"
+               id="net.sourceforge.phpdt.type1">
+            <separator
+                  name="mainActionsGroup">
+            </separator>
+            <separator
+                  name="actionsGroup">
+            </separator>
+            <separator
+                  name="infoGroup">
+            </separator>
+         </menu>
+         <action
+               label="Do nothing 3"
+               class="net.sourceforge.example.outline.Type2Console"
+               menubarPath="net.sourceforge.phpdt.type1/infoGroup"
+               enablesFor="1"
+               id="net.sourceforge.phpdt.donothing3">
+         </action>
+         <action
+               label="Print source to Console"
+               class="net.sourceforge.example.outline.Type2Console"
+               menubarPath="net.sourceforge.phpdt.type1/actionsGroup"
+               enablesFor="1"
+               id="net.sourceforge.example.outline.Type2Console">
+         </action>
+         <action
+               label="Do nothing 4"
+               class="net.sourceforge.example.outline.Type2Console"
+               menubarPath="net.sourceforge.phpdt.type1/mainActionsGroup"
+               enablesFor="1"
+               id="net.sourceforge.phpdt.donothing4">
+         </action>
+      </objectContribution>
+   </extension>
 </plugin>
diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/example/outline/Import2Console.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/example/outline/Import2Console.java
new file mode 100644 (file)
index 0000000..5e7b39c
--- /dev/null
@@ -0,0 +1,63 @@
+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);
+    }
+
+}
\ No newline at end of file
diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/example/outline/Type2Console.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/example/outline/Type2Console.java
new file mode 100644 (file)
index 0000000..bb5f55c
--- /dev/null
@@ -0,0 +1,74 @@
+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.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());
+        }
+
+    }
+
+}
\ No newline at end of file