Example - Scripting
Introduction
These examples show how to use Javascript and HTML-based user-interface
to create extensions.
Running the example
Before invoking any of the examples, open the Script Console view by selecting
the menu item "Perspective > Show View > Other... > Scripting > Script
Console". Messages generated by the samples will be presented within
the Script Console view.
There are a number of examples within the Toolkit Scripting examples.
Following are the instructions on how to run each example.
-
Evaluate a Javascript script
The toolbar button labelled "Perform Scripted Javascript Action", when
pressed, invokes an evaluation of a Javascript script that resides in the
file excalibur.js. This script does the following:
-
Prints a "Begin" statement.
-
Prints any selected resources.
-
Presents a workbench container selection dialog, and prints the selected
container when the dialog is closed.
-
Presents a workbench file selection dialog, and prints the selected filename(s)
when the dialog is closed.
-
Presents a system folder selection dialog, and prints the selected directory
name when the dialog is closed.
-
Presents a system file selection dialog, and prints the selected filenames
when the dialog is closed.
-
Presents a message box with an OK button.
-
Presents a message box with OK and Cancel buttons, and prints which button
was pressed when the dialog is closed.
-
Prints the plugin's install location.
-
Prints a list of all the extension points that are currently registered
with the plugin registry.
-
Prints a list of all the resources (projects, folders and files) of the
current open solution.
-
Creates a project named "ScriptProject".
-
Prints an "End" statement.
-
Present a wizard with Javascript event handling
The toolbar button labelled "Perform Scripted User Interface Script
Action", when pressed, invokes the Java class org.eclipse.scripting.examples.ExcaliburScriptRenderer.
This Java class uses another class named org.eclipse.scripting. Renderer
to present a user interface that resides in file excaliburScriptRenderer.html.
The user interface is populated with data that resides in file excaliburCompany.xml.
-
Present a wizard with Java event handling
The toolbar button labelled "Perform Scripted User Interface JavaScript
Action", when pressed, presents a user interface that is defined in file
excaliburScript.html. The user interface is populated with data that
resides in file excalibur.xml.
-
Invoke an editor with Javascript event handling
-
Select an XML file in the Navigator view (if none available, create one).
-
Open the file by double-clicking on it.
-
The Scripted Resource Editor will open, containing fields for the first
and last name of a person and home, cell and fax numbers. A Save
button is also present.
-
Present a preferences page with Javascript event handling
-
Select menu item "Window / Preferences" and click on the Scripted JavaScript
Example page
-
Present a wizard with Javascript event handling
-
Select menu item "File > New > Other... > Scripted JavaScript Example"
-
Click Next
-
The contents of the wizard page is made avaiable via an extenal file in
the plugins directory
-
Present a wizard with Java event handling
-
Select menu item "File > New > Other... " then select "Scripted Handler
Example"
-
Click Next
-
The contents of the wizard page is made avaiable via an extenal file in
the plugins directory
-
Present a wizard with Javascript event handling
-
Select menu item "File > Import " then select "Scripted JavaScript Example"
-
From the menu item "File > Export " then select "Scripted JavaScript Example"
-
Click Next
-
The contents of the wizard page is made avaiable via an extenal file in
the plugins directory
Details
All files referenced in these examples (sample scripts, xml, etc.) cav
be found in the directory "/plugins/org.eclipse.scripting.examples".
User Interfaces
A common user interface is used for all of the samples except for the Resource
Editor sample. The common user interface consists of two pages.
The first page demonstrates the use of some of the scripting Toolkit
functions. These are:
Prompting for a workbench container
Prompting for workbench files
Prompting for a system directory
Prompting for a system file
Presenting a message box with an OK button
Presenting a message box with OK and Cancel
buttons
The second page demonstrates the ability to associate presentation elements
with data elements. Selecting one or more items in the Departments
list box changes the contents in the Employees list box and the contents
of the entry fields and label that reside below the list boxes. If
the content of the entry fields at the bottom of the page are modified,
the data model is automatically updated with the entered text.
Resource Editor Example
The Resource Editor example displays a data entry page. If the file
excaliburEditorScript.xml is selected, and the popup menu item "Open With
> Scripted Resource Editor Example" is selected, the following editor page
will be presented. If any other XML file is selected, the fields
will be shown empty.