Jump to: navigation, search

Framework to develop simple Eclipse plugin using PHP/PHPinJava

< Framework to develop simple Eclipse plugin using PHP
Revision as of 14:33, 5 August 2007 by Toomasr.gmail.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Mapping PHP functions to Java methods

This is a step by step tutorial showing the capabilities of the current release.

Goals

  • Develop a Hello, World! plugin
  • The String "Hello, World!" is generated from evaluation a PHP script

Steps to reproduce

  • Install the plugin
  • Create a new plugin project (Name it testproject)
  • Use the template "Hello, World"
  • In the Dependencies tab add org.eclipse.soc2007.phpengine as a Required Plugin-ins
  • Create a PHP file
    • Create a file helloWorld.php under project root.
    • Add contents "<? echo "Hello, World Eclipse from PHP"; ?>"
  • Create a new interface
    • Use the package testproject.actions
    • Name it HelloWorld
    • Annotate the class with:
@ScriptableClass(
 fileName="testproject/actions/helloWorld.php"
)
    • Add a method String getHelloWorld(String name);
    • Annotate the method with:
@ScriptableMethod(
 functionName="helloWorld"
)
  • The template should have created a Java file testproject/actions/SampleAction.java
public class SampleAction implements IWorkbenchWindowActionDelegate {
  • Add a private field
private HelloWorld helloWorld;
  • Modify the constructor (Activator is testproject.Activator)
helloWorld = (HelloWorld)PhpScriptableFactory.newInstance(
 HelloWorld.class);
  • Modify the run method
	public void run(IAction action) {
		MessageDialog.openInformation(
			window.getShell(),
			"SamplePlugin Plug-in",
			helloWorld.getHelloWorld("Your_Name"));
	}
  • Launch the Run
  • From the top menu choose Sample Menu -> Sample Action
  • Use should see a dialog telling you "Hello World 'YourName'"
  • Not seeing the desired output?
    • Be sure to check if the installed plugin and the fragment are in the Run plugins list.