Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Framework to develop simple Eclipse plugin using PHP/PHPinJava"

(Steps to reproduce)
(Steps to reproduce)
Line 26: Line 26:
 
* The template should have created a Java file testproject/actions/SampleAction.java
 
* The template should have created a Java file testproject/actions/SampleAction.java
 
** Make the class implement Scriptable
 
** Make the class implement Scriptable
  public class SampleAction implements IWorkbenchWindowActionDelegate, Scriptable {
+
  public class SampleAction implements IWorkbenchWindowActionDelegate, HelloWorld {
 
** Add a private field
 
** Add a private field
 
  private HelloWorld helloWorld;
 
  private HelloWorld helloWorld;

Revision as of 02:43, 12 July 2007

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
    • Make it extend org.eclipse.soc2007.phpscriptengine.Scriptable
    • Add a method String getHelloWorld(String rtrn);
    • Annotate the method with:
@ScriptableAnnotation(
  fileName="helloWorld.php",
  output="true"
)
  • The template should have created a Java file testproject/actions/SampleAction.java
    • Make the class implement Scriptable
public class SampleAction implements IWorkbenchWindowActionDelegate, HelloWorld {
    • Add a private field
private HelloWorld helloWorld;
  • Modify the constructor (Activator is testproject.Activator)
	public SampleAction() {
		helloWorld = (HelloWorld)ScriptUtil.registerProxy(this, HelloWorld.class, Activator.class.getClassLoader());
	}
  • Modify the run method
	public void run(IAction action) {
		MessageDialog.openInformation(
			window.getShell(),
			"SamplePlugin Plug-in",
			helloWorld.getHelloWorld(null));
	}
  • Implement the getHelloWorld(String) method
	public String getHelloWorld(String rtrn) {
		return rtrn;
	}
  • Launch the Run
  • From the top menu choose Sample Menu -> Sample Action
  • Use should see the following dialog

HelloFromEclipse.png

Back to the top