IBM Support

How to invoke Rhapsody API effectively using Windows shortcut and Java KeyListener

Question & Answer


Question

How do you call your frequently used or your favorite operations quickly and easily in IBM Rational Rhapsody?

Cause

In Rhapsody, shortcuts are assigned to frequently used operations like GMR (Ctrl+Shift+F5) and “Locate In Browser” (Ctrl+L), but there might be other operations you might use frequently which shortcuts are not assigned, or perhaps they are buried deep in a nested area or menu, making it very difficult to access. Otherwise, you might have a favorite Rhapsody API that you want to call at a specific time, but you have to wait for one of pre-defined events to occur to which your Helper or Plug-in (see “Simple Plug-in” sample) is listening.

Many of operations you can perform on GUI can be automated using Rhapsody API. So, the ability to call this powerful mechanism whenever you think necessary is required in order to dramatically improve your work productivity.

At the successful completion of this task, you should be able to call your favorite API with less than 2 keystrokes.

*** IMPORTANT ***
This technote contains a sample (Java source codes) that demonstrates a simple way for defining shortcut keys and triggering your API freely. Download and extract the file, and follow the instructions given in this technote. Yet, remember the sample attached to this technote is provided only for educational/PoC purpose and to be used on an "AS IS" basis without warranty of any kind. So, use it at your own risk.

Answer

Overview of Sample:

This sample consists of 1 batch file, 1 text file, and 3 Java files:

  1. ShortcutListener.java - listens to a user's keystroke and invoke a corresponding API.
  2. PropertyEditor.java - allows users to edit any property through a simple window.
  3. KeyBinder.java - allows users to manage shortcuts stored in Shortcut.txt.
  4. Shortcut.txt - the definition of user's shortcuts is stored in this file.
  5. KeyListenerSampleBuild.bat – used to build and run the sample.

We're going to assign a windows' shortcut key so that ShortcutListener can be invoked with a simple keystroke like pressing F2 key. After ShortcutListener is invoked, you will see a little blue box displayed on the screen, indicating ShortcutListener is waiting for a user's shortcut command.



To create a shortcut key, double-click on the box and you will see a key-action table appear. You will either specify a property key (e.g CPP_CG::Operation::ImplementationProlog) or select an action from the pull-down (only “Add Operation(s)” and “Add Attribute(s)” are selectable in this sample).



While the little box is on the screen, enter your shortcut command as defined in the key-action table. In the example above, pressing Ctrl+N will bring up a Property Editor for CPP_CG::Operation.ImplementationProlog of the currently selected element. This way, you will be able to eliminate the tedious task of finding a desired property from the list of thousands of properties.



If you right-click on the box or click anywhere on the screen, the box will disappear until you invoke it again by pressing F2 key.

How to set up the sample:
  1. Download and unzip the sample to either Desktop or Start Menu folder (Start Menu\rhp_shortcuts). These folders are located as below:

    For Windows 7:
    C:\Users\<User-Name>\Desktop
    C:\Users\<User-Name>\AppData\Roaming\Microsoft\Windows\Start Menu
    C:\ProgramData\Microsoft\Windows\Start Menu


    For Windows XP:
    C:\Documents and Settings\<User-Name>\Desktop
    C:\Documents and Settings\<User-Name>\Start Menu
    C:\Documents and Settings\All Users\Start Menu


    Creator Note:
    If you place the sample in a folder other than listed above, Windows shortcut likely won't work.

  2. Copy hstart.exe from Rhapsody installation folder (<RhapsodyInstall>\Share\etc) and place it in the sample folder.


    Creator Note:
    hstart.exe is a handy utility to run applications and batch files silently without a console prompt.

  3. Open KeyListenerSampleBuild.bat and adjust PATH_TO_JRE and RHP_INST_PATH.

    <example>
    PATH_TO_JRE=C:\Program Files (x86)\Java\jdk1.7.0_03\bin
    RHP_INST_PATH=<RhapsodyInstall>\Share\JavaAPI


  4. Open a console and move to where the sample is located.

  5. Compile the sample by running the following command (Use JDK 1.7 or higher):

    %KeyListenerSampleBuild.bat build

    Creator Note:
    Modify line 35 in KeyBinder.java in order to compile using JDK 1.5 or JDK 1.6.

    Before:
    JComboBox<String> comboBox1 = new JComboBox<String>(items1);

    After:
    JComboBox comboBox1 = new JComboBox (items1);

  6. Create a shortcut of hstart.exe and rename it "launcher".


  7. Right-click the shortcut, and then click Properties.
    Fill relevant sections as below.



    Example:
    Target: "<Path to Sample>\hstart.exe" /NOCONSOLE ""KeyListenerSampleBuild.bat" run"
    StartIn: "<Path to Sample>"
    Shortcut key: F2


  8. Press “F2” and make sure the blue box pop up.


  9. If there is any problem, run through the steps at the verification section below for troubleshooting.


Verification:
  1. Run %KeyListenerSampleBuild.bat test

  2. Ensure the following message appears.



  3. Run %KeyListenerSampleBuild.bat run

  4. Ensure the little blue box appears at the center of screen.



Summary:

With using Rhapsody API, you can do almost everything you imagine including test automation, nightly build, programmatic model correction, applying custom design patterns and a lot more. It will take time to build up your own repositories of API but once it's done you're just 2 keystrokes away to call your favourite API at any moment. The combined use of Windows shortcut and Java KeyListener is just one way to implement the solution. You will play with the sample, think how it can be implemented better to meet your specific requirement, and make your own version of it. This sample will provide you some tips and ideas in designing your own accessibility solution.

Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


rhp_shorcuts.zip

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"General Information","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.5;7.5.0.1;7.5.1;7.5.1.1;7.5.2;7.5.2.1;7.5.3;7.5.3.1;7.5.3.2;7.6;7.6.0.1;7.6.1;7.6.1.1;7.6.1.2","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21610675