Creating user profiles for the LPEX editor in WebSphere Developer for zSeries v6.0

LPEX user profiles let you organize LPEX editor customizations for specific tasks and avoid manual customization of the LPEX editor. This article shows how to create and implement a user profile in WebSphere® Developer for zSeries v6.0.

John Casey (jocasey@us.ibm.com), Worldwide Technical Sales Support for WebSphere Developer for z/Series, IBM, Software Group

John Casey is an IBM Certified Application Development Specialist. During his 27 years at IBM, he has been involved in many application projects on both distributed and zSeries platforms. He has authored and conducted technical workshops both inside and outside of IBM. In his current role, he assists IBM customers throughout the world in understanding and using IBM development tools, such as WebSphere Developer for zSeries and WebSphere Studio Asset Analyzer, to address their Application Transformation needs. You can reach John at jcasey@us.ibm.com.



12 July 2006

Introduction

In my previous article, Extending the LPEX Editor in WebSphere Developer for zSeries v6.0, I showed how to create and deploy a new LPEX action. To use the new action, you needed to manually identify the action and its shortcut key to the LPEX editor. With user profiles, you can eliminate the manual definition of LPEX editor customizations.

Another benefit of user profiles is that they provide a way to group LPEX editor customizations. By creating more than one user profile, you can activate a set of customizations for a specific need. With the LPEX editor base profiles, you can configure the editor to adopt the keyboard and command personalities of several popular editors, such as ISPF, XEDIT, VI, and Emacs. When you select which base profile to use, the LPEX editor runs that set of definitions for the document being opened or, if manually invoked, for a document that is already opened.

You implement a user profile as a Java ™ class with a userProfile method. You then code your LPEX customizations by invoking LPEX commands and actions in the userProfile method. When the LPEX editor opens a new document, it issues the updateProfile command, which invokes the userProfile method of the class that you defined as the default user profile.

LPEX provides three contexts, or scopes, that influence which editor settings are in effect for a document being edited:

  • The install context identifies editor settings that are read from an Install.properties file in the com.ibm.lpex.core package.
  • Default editor settings reside in the LPEX editor pages of the Preferences view. They may be set by the Install.properties file, manually by the user or when a client LPEX plug-in is registered, such as this article demonstrates.
  • Finally, the current context describes the settings of a specific document view that has edit focus. Each document has its own current context settings. These settings lets the actions, key assignments, or editor parameters that are available while editing text in one document be different from those available while editing text in another document.

When you first open a document, its context is set to default. We will make use of this fact by setting the default user profile to our user profile class during registration of our plug-in, when our preload method is executed. So, when the LPEX editor opens, it runs our userProfile classname method that defines a new action, assigns a shortcut key, and sets our preferred editor style to ISPF.

In this article, I show you how to create, test, and deploy a user profile for the LPEX editor. Although you do not need to know Java or Eclipse to follow the step-by-step instructions, the article does assume that you have some familiarity with either Eclipse or one of the Eclipse-based products, such as WebSphere Developer for zSeries.

Create a user profile plug-in

In the Eclipse platform, a plug-in is the fundamental unit for packaging functions. You describe a plug-in using a plug-in manifest file, plugin.xml. Our LPEX editor user profile will be packaged as a plug-in.

Although you can use any Java IDE to build Eclipse plug-ins, the Eclipse Plug-in Development Environment (PDE) provides tools to simplify the development of plug-ins. For example, the PDE creates a project structure that supports plug-in definition and deployment, and Java coding. The PDE provides wizards to simplify the defintion of the manifest file and of supporting Java classes.

Enable the Plug-in Development Environment

  1. Start WebSphere Developer for zSeries. When prompted for the name of a workspace, create a new workspace in which to develop your plug-in.
  2. Select Windows - Preferences from the Workbench menu bar.
  3. In the Preferences view on the left-hand side, expand Workbench and select Capabilities .
  4. In the Capabilities pane, which is displayed on the right-hand side of the Preferences view, expand Eclipse Developer and check the boxes for Eclipse Plug-in Development and Eclipse Plug-in Development Examples.
  5. Click OK at the bottom of the Preferences view to save your changes and close the window.

Create a Plug-in development project

  1. From the Workbench menu bar select Window - Open Perspective - Other ....
  2. In the Select Perspective window, select Plug-in Development and click OK to open a perspective that aids the plug-in developer.
  3. Launch the New Project Wizard by selecting File - New - Plug-in Project.
  4. On the Plug-in Project page, enter com.mycompany.lpexExtensions as the project name and click Next.
  5. On the Plug-in Content page, click Finish to create the plug-in project and the necessary folders and files.

    You should see your new plug-in, com.mycompany.lpexExtensions, in the Package Explorer view on the left side, and its plugin.xml file opened in the editor area.

    Tip: The tab for the active file in the editor is blue, and if you hover the mouse over the blue area, then the full name of the file, com.mycompany.lpexExtensions/plugin.xml, will be displayed.

Complete the plug-in manifest file

Plug-ins, such as the LPEX editor, can have defined extension points that client plug-ins can use. These extension points are basically programming interfaces. The plug-in manifest captures which LPEX extension points your client plug-in will use.

  1. In the editor, click Dependencies (use either the tab at the bottom or the link in the text on the Overview page) to switch to the Dependencies page.
  2. On the Dependencies page, click the Add button.
  3. On the Plug-in Selection window, in the Select a Plug-in field enter com.ibm.lpex, which will reduce the list that is displayed below this field to three entries. Select com.ibm.lpex and click OK. This step adds these plug-ins to your plug-in project's classpath.
  4. In the editor, click Extensions (use the tab at the bottom) to switch to the Extensions page.
  5. On the Extensions page, click the Add button.
  6. On the New Extension window, select com.ibm.lpex.preload and click Finish.
  7. Right click on com.ibm.lpex.preload and click New - preload, as Figure 1 shows:
    Figure 1. Specifying the Preload class
    Specifying the Preload class
  8. Under Extension Element Details, change the generated class name to com.mycompany.lpexExtensions.Preload.
  9. Press Ctrl+S to save your changes to plugin.xml.

Create the Preload class

The Preload Java class defines a preload method. This method, which is invoked by the LPEX editor when it initializes, defines our user profile class as the default user profile.

To create the class:

  1. In the Package Explorer view, expand the src folder and right-click the com.mycompany.lpexExtensions package. In the context menu select New - Class.
  2. In the New Java Class window, verify that the Source Folder and Package fields are prefilled with com.mycompany.lpexExtensions/src and com.mycompany.lpexExtensions, respectively, which appear because you started the New Java Class wizard from the package folder.
  3. Enter Preload in the Name field.
  4. Click the Add button next to the Interfaces text box.
  5. In the Implemented Interfaces Selection window, enter lpexp in the Choose interfaces field, which shortens the list as you type.
  6. Select LpexPreload and click OK. This step adds com.ibm.lpex.alef.LpexPreload to the Interfaces box.
  7. Click Finish to create the class and open it for editing.
  8. In the editor for Preload.java, add this statement after the existing import statement:
    import com.ibm.lpex.core.LpexView;
  9. In the editor for Preload.java add this statement to the preload method:
    LpexView.doGlobalCommand("set default.updateProfile.userProfile com.mycompany.lpexExtensions.UserProfile1");
  10. Press Ctrl+S to save your changes.
  11. Verify that your code looks similar to what is shown in Listing 1. You can ignore the comments. Make sure that there are no errors.
  12. Close the editor for Preload.java.
Listing 1. Completed Preload class definition (template generated comments have been removed)
package com.mycompany.lpexExtensions;
import com.ibm.lpex.alef.LpexPreload;
import com.ibm.lpex.core.LpexView;
public class Preload implements LpexPreload {
	public void preload() {
		LpexView.doGlobalCommand(
			"set default.updateProfile.userProfile
			com.mycompany.lpexExtensions.UserProfile1" );
	}
}

Create the user profile class

You implement the LPEX editor user profile as a Java class with a userProfile method. You then code the LPEX customizations by invoking LPEX commands and actions in the userProfile method.

To create the class:

  1. In the Package Explorer view, expand the src folder and right-click Specifiy the destination directory for your plug-in the com.mycompany.lpexExtensions package. In the context menu select New - Class.
  2. In the New Java Class window, verify that the Source Folder and Package entry fields are prefilled with com.mycompany.lpexExtensions/src and com.mycompany.lpexExtensions, respectively.
  3. Enter UserProfile1 in the Name field.
  4. Click Finish to create the class and open it for editing.
  5. In the editor for UserProfile1.java, add the two import statements after the package statement, as shown in Listing 2.
  6. Add the userProfile method and all of its statements as shown in Listing 2.
  7. Press Ctrl+S to save your changes.
  8. Verify that your code looks similar to what is shown in Listing 2. You can ignore the comments. Make sure that there are no errors.
  9. Close the editor for UserProfile1.java.
Listing 2. Completed UserProfile1 class (template generated comments have been removed)
package com.mycompany.lpexExtensions;
import com.ibm.lpex.core.LpexAction;
import com.ibm.lpex.core.LpexView;
public class UserProfile1 {
    public static void userProfile(LpexView lpexView) {
      // define new action
      lpexView.defineAction("insertSemicolon2Action", new LpexAction() {
         public void doAction(LpexView view) {
             // go to the end of the line
            view.doAction(view.actionId("contextEnd"));
            // insert a semicolon and comment string
            view.doCommand("insertText ; /*  */");
            // position the cursor in the middle of the comment
            view.doAction(view.actionId("left"));
            view.doAction(view.actionId("left"));
            view.doAction(view.actionId("left"));
         }

         public boolean available(LpexView view) {
            // allow the action to run for any visible text line in a writable document
            return view.currentElement() != 0 && !view.queryOn("readonly");
         }
      });
      // Assign keys "Ctrl+5" to run insertSemicolon2Action
      lpexView.doCommand("set keyAction.c-5 insertSemicolon2Action");

      // set ispf as default editor style
      lpexView.doDefaultCommand("set default.updateProfile.baseProfile ispf");
      /* lpexView.doDefaultCommand("updateProfile"); */
   }
}

Test your user profile plug-in

Eclipse provides a runtime environment, the runtime workbench, for testing plug-ins as they are being developed. To start the runtime workbench:

  1. Go to the Overview page in the editor for plugin.xml (click the Overview tab).
  2. On the Overview page, click Launch a runtime workbench, which starts another instance of WebSphere Developer for zSeries that can access your plug-in code.

Observe the effect of the Preload class

  1. Open the Preferences page by selecting Window - Preferences from the menu bar.
  2. In the Preferences window, expand LPEX Editor (on the left), and select User Profiles. Because the Preload method was invoked during the initialization of the workspace, Class name has been set to com.mycompany.lpexExtensions.UserProfile1 as shown in Figure 2. This is the default user profile.
    Figure 2. Default user profile set by Preload class
    Default user profile set by Preload class
  3. Click Cancel to close the Preferences window.

Test the user profile

To test your new action, you need to open a file in the z/OS LPEX editor. An easy way to do this is to create a new project using sample code shipped with WebSphere Developer for zSeries. Since our user action supports the PL/I syntax of ending a command with a semicolon, we will use a PL/I example.

To test your action:

  1. From the menu bar, select File - New - Example
  2. In the New Example window, expand Examples, expand Workstation PL/I, select PLI Sample 1, and click Next.
  3. On the z/OS Local Project page, enter PLITest in the Project name field and click Finish.
  4. If the Confirm Perspective Switch dialog box appears, click Yes.
  5. In the z/OS Projects View, expand the project PLITest, expand the folder pli, and double-click on HelloApp.pli to edit it.
  6. Position your cursor at the beginning of a line with text, and then press Ctrl+5. Your new action is executed, placing a semicolon at the end of the line and inserting a new line below.
  7. Your action can also be run from the command line using the action command. Position your cursor at the beginning of a line with text, and then press Esc, which will place the cursor in the command line. Enter action insertSemicolon2Action in the command line area and press Enter. Your new action is executed.
  8. When you are finished testing your new action, close the editor for HelloApp.pli. You do not need to save the changes.
  9. In the test workbench window, select File - Exit from the menu bar to close the workbench window.

Deploy the plug-in to WebSphere Developer for zSeries

To deploy the plug-in, you first need to export it from the PDE, and then copy it to your WebSphere Developer for zSeries installation directory.

Export the plug-in from the PDE

During development, plug-ins in your workspace are used as-is so that you can quickly test and debug them. When you are satisfied with the operation of your new plug-in, you will want to publish this plug-in so that others may use it. The easiest way to publish your plug-in is using the Export Plug-ins and Fragments Wizard:

  1. In the Package Explorer view, right click on com.mycompany.lpexExtensions and select Export... from the context menu
  2. On the Export window, select Deployable plug-ins and fragments in the list box and click Next.
  3. In the Export Plug-ins and Fragments window, check the box for com.mycompany.lpexExtensions, which is listed in the Available Plug-ins and Fragmentstextbox.
  4. In the Export Options field, select a directory structure from the list. You can deploy plug-ins in one of three formats:
    • A single ZIP file whose content can be unzipped into any Eclipse-based product.
    • A directory structure, so that the plug-in can be placed directly in an Eclipse installation, such as the plug-in directory for WebSphere Developer for zSeries.
    • Individual JAR archives for an update site. This option creates one JAR per plug-in, and places the JARs in a /plugins/ subdirectory of the chosen destination.
  5. For the Directory field, use its Browse button to navigate to the \wdz\eclipse folder in the WebSphere Developer for zSeries installation directory. The Directory field should look like Figure 3 if you used the default installation directory of C:\Program Files\IBM\Rational\SDP\6.0.
    Figure 3. Specifiy the destination directory for your plug-in
    Specifiy the destination directory for your plug-in
  6. Click Finish to start the build process, which displays a message dialog that the build is in progress. You do not need to press any of the buttons. When the build is finished, the dialog box will close.

Verify that the plug-in works

  1. Stop WebSphere Developer for zSeries and restart it.
  2. Verify that the user profile has been added to the the LPEX editor User Profile page in the Preferences view.
  3. Open a PL/I file in the LPEX editor and verify that insertSemicolon2Action works.

Conclusion

User profiles ease the customization of the LPEX editor. They eliminate manual definition and provide a way to organize editor settings for special tasks. In this article, I showed how to extend the LPEX editor in WebSphere Developer for z/Series to automatically load a user profile when the editor opens. By following the steps in this article, you have a model by which you can create your own user profiles for the LPEX editor.

Resources

Learn

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into WebSphere on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Rational
ArticleID=145621
ArticleTitle=Creating user profiles for the LPEX editor in WebSphere Developer for zSeries v6.0
publish-date=07122006