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)
 
(5 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
* Use the template "Hello, World"
 
* Use the template "Hello, World"
 
* In the '''Dependencies''' tab add '''org.eclipse.soc2007.phpengine''' as a Required Plugin-ins
 
* In the '''Dependencies''' tab add '''org.eclipse.soc2007.phpengine''' as a Required Plugin-ins
* Create the PHP file
+
* Create a PHP file
** Create file helloWorld.php under project root.
+
** Create a file helloWorld.php under project root.
 
** Add contents "<? echo "Hello, World Eclipse from PHP"; ?>"
 
** Add contents "<? echo "Hello, World Eclipse from PHP"; ?>"
 
* Create a new interface
 
* Create a new interface
 
** Use the package '''testproject.actions'''
 
** Use the package '''testproject.actions'''
 
** Name it '''HelloWorld'''
 
** Name it '''HelloWorld'''
** Make it extend '''org.eclipse.soc2007.phpscriptengine.Scriptable'''
+
** Annotate the class with:
** Add a method '''String getHelloWorld(String rtrn);'''
+
@ScriptableClass(
 +
  fileName="testproject/actions/helloWorld.php"
 +
)
 +
** Add a method '''String getHelloWorld(String name);'''
 
** Annotate the method with:
 
** Annotate the method with:
  @ScriptableAnnotation(
+
  @ScriptableMethod(
  fileName="helloWorld.php",
+
  functionName="helloWorld"
  output="true"
+
 
  )
 
  )
* The template should have created a Java class testproject.actions.SampleAction.java
+
* The template should have created a Java file testproject/actions/SampleAction.java
** Add a private field
+
public class SampleAction implements IWorkbenchWindowActionDelegate {
 +
* Add a private field
 
  private HelloWorld helloWorld;
 
  private HelloWorld helloWorld;
* Modify the constructor
+
* Modify the constructor (Activator is testproject.Activator)
public SampleAction() {
+
helloWorld = (HelloWorld)PhpScriptableFactory.newInstance(
helloWorld = (HelloWorld)ScriptUtil.registerProxy(this, HelloWorld.class, Activator.class.getClassLoader());
+
  HelloWorld.class);
}
+
 
* Modify the '''run''' method
 
* Modify the '''run''' method
 
  public void run(IAction action) {
 
  public void run(IAction action) {
Line 36: Line 38:
 
  window.getShell(),
 
  window.getShell(),
 
  "SamplePlugin Plug-in",
 
  "SamplePlugin Plug-in",
  helloWorld.getHelloWorld(null));
+
  helloWorld.getHelloWorld("Your_Name"));
}
+
* Implement the '''getHelloWorld(String)''' method
+
public String getHelloWorld(String rtrn) {
+
return rtrn;
+
 
  }
 
  }
 
* '''Launch the Run'''
 
* '''Launch the Run'''
 
* From the top menu choose '''Sample Menu -> Sample Action'''
 
* From the top menu choose '''Sample Menu -> Sample Action'''
* Use should see the following dialog [[Image:helloFromEclipse.png]]
+
* 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.

Latest revision as of 15:33, 5 August 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
    • 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.

Back to the top