Tuesday, December 15, 2009

Attaching the Accelerator Key Bindings to the RCP Application

After a tricky way I explored how to attach the Accelerator Key Bindings to the RCP Application. Following were the steps to do it:
1. An action to invoke => For eg. any of the actions like showF1HelpAction, undoAction, etc.
2. A command that invokes the action => this has to be done in plugin.xml => An example is as follows:
 <command category="com.somedomain.someproduct.commands.category" categoryId="com.somedomain.someproduct.commands.category"  
 defaultHandler="com.somedomain.someproduct.ui.handlers.UndoHandler" id="com.somedomain.someproduct.commands.undo" name="Undo">  
 </command>  
3. A handler optionally to handle the command => this has to be done in plugin.xml => An example is as follows:
 <handler class="com.somedomain.someproduct.ui.handlers.UndoHandler" commandId="com.somedomain.someproduct.commands.undo">  
 </handler>  
4. A key binding that invokes the command (that invokes the action) => this has to be done in plugin.xml => An example is as follows:
 <key commandId="com.somedomain.someproduct.commands.undo" schemeId="com.somedomain.someproduct.commands.key.binding.scheme" sequence="M1+Z">  
 </key>  
5. Your own scheme which inherits from org.eclipse.ui.defaultAcceleratorConfiguration and overwriting the defaults like Ctrl+S, Ctrl+C, Ctrl+V, etc. => this has to be done in plugin.xml => An example is as follows:
 <scheme id="com.somedomain.someproduct.commands.key.binding.scheme" name="com.somedomain.someproduct.commands.key.binding.scheme"  
 parentId="org.eclipse.ui.defaultAcceleratorConfiguration">  
 </scheme>  
6. A plug-in configuration file that enables your key bindings. => if not previously present, create a new file plugin_customization.ini and enable the key binding as follows as follows: a. Find your product extension under the org.eclipse.core.runtime.products extension point in the plugin.xml file. b. Right click your product extension and select New > property. c. In the name* field, enter preferenceCustomization. When RCP starts up your application, it will look up this property to identify the plug-in configuration file to apply. d. In the value* field, enter the name (and path, if appropriate) of your plug-in configuration file. e. In the plugin_customization.ini file add an entry to enable key bindings as: org.eclipse.ui/KEY_CONFIGURATION_ID=com.somedomain.someproduct.commands.key.binding.scheme
7. Register the actions to be invoked using key bindings for their own unique command identifiers as follows: a. Use a unique identifier string representing the command in the constructor of your action. Call the setId(), setActionDefinitionId() methods and pass this unique command identifier. b. In ApplicationActionBarAdvisor.makeActions(), register your action. When the command is invoked, RCP will look for a registered actions having the unique command identifier in action definition ID, and invoke it.

Tuesday, May 19, 2009

Invoking external program from Java

To invoke the external programs from Java, the simplest way is to use the capabilities of the Runtime class. Following sample program should illustrate the same:
 import java.io.*;  
 public class Main {  
   public static void main(String args[]) {  
    try {  
    Runtime rt = Runtime.getRuntime();  
    //Process pr = rt.exec("cmd /c dir");  
    Process pr = rt.exec("c:\\helloworld.exe");  
    BufferedReader input = new BufferedReader(new   
     InputStreamReader(pr.getInputStream()));  
    String line=null;  
    while((line=input.readLine()) != null) {  
     System.out.println(line);  
    }  
    int exitVal = pr.waitFor();  
    System.out.println("Exited with error code "+exitVal);  
    } catch(Exception e) {  
     System.out.println(e.toString());  
     e.printStackTrace();  
    }  
   }  
While hunting for this solution, I came across a very elaborate link regarding the same.
http://www.rgagnon.com/javadetails/java-0014.html

Tuesday, May 5, 2009

Converting the exception stracktrace to string

Method 1 (using log4j):
 logger.error(ex, ex);  
Method 2 (without log4j):
 public String stackTraceString(Exception e) {  
      StringBuffer s = new StringBuffer();  
      StackTraceElement[] frames = e.getStackTrace();  
      for (int i=0; i < frames.length; i++) s.append(frames[i].toString()+"\n");  
      return new String(s);  
 }  
Method 3 (without log4j):
 /** Converts the exception stracktrace to string. */  
 public StringBuffer getExceptionStackTrace(Exception ex) {  
 StringWriter strWriter = new StringWriter();  
      if (null != ex) {  
           PrintWriter out = new PrintWriter(strWriter);  
           ex.printStackTrace(out);  
      }  
      return strWriter.getBuffer();  
 }  
 /** May be used to set the exception as fault content. */  
 public String getExceptionAsXmlText(Exception ex) {  
      if (null != ex) {  
           String message = ex.getMessage();  
           String stackTrace = getExceptionStackTrace(ex).toString();  
           String exXmlText = "<exception>" + 
           "<message>" + message + "</message>" +  
           "<stack-trace>" + stackTrace + "</stack-trace>" +  
           "</exception>" ;  
           return exXmlText;  
      }  
      return "";  
 }  

Import / Export full Orcale data

Using 'exp' command:

To export the entire database to a single file dba.dmp in the current directory.
- Login to server
- Use following command:
exp SYSTEM/password FULL=y FILE=dba.dmp LOG=dba.log CONSISTENT=y
or
exp SYSTEM/password PARFILE=params.dat

{oracle.home}/product/10.2.0/bin/expDB/prodDB FULL=Y FILE=forITMc.dmp LOG=export.log CONSISTENT=Y COMPRESS=Y
where params.dat contains the following information:
FILE=dba.dmp
GRANTS=y
FULL=y
ROWS=y
LOG=dba.log

To dump a single schema to disk (we use the scott example schema here)
- Login to server which has an Oracle client
- Use following command:
exp / FIlE=scott.dmp OWNER=scott

To export specific tables to disk.
- Login to server which has an Oracle client
- Use following command:
exp SYSTEM/password FIlE=expdat.dmp TABLES=(scott.emp,hr.countries)
- The above command uses two users : scott and hr

exp / FILE=scott.dmp TABLES=(emp,dept)
the above is only for one user

Using 'imp' command:

To import the full database exported in the example above.
imp SYSTEM/password FULL=y FIlE=dba.dmp

To import just the dept and emp tables from the scott schema
imp SYSTEM/password FIlE=dba.dmp FROMUSER=scott TABLES=(dept,emp)

To import tables and change the owner
imp SYSTEM/password FROMUSER=someUser TOUSER=scott FILE=someUser.dmp TABLES=(unit,manager)

To import just the scott schema exported in the example above
imp / FIlE=scott.dmp

{oracle.home}/product/10.2.0/bin/impDB/pwd4NewDB FILE=forITMc.dmp

Monday, May 4, 2009

Setting and echoing the classpath information using Ant

Setting classpath is a must (although not 'required' by default) to get anything useful done with Ant's javac/java tasks. One way of setting classpath is by using the 'path' element as follows:
 <path id="application.classpath">  
      <pathelement path="${java.class.path}"/>  
      <fileset dir=".">  
           <include name="lib/*.jar"/>  
      </fileset>  
 </path>  
Then comes situations where you want to see the list of jars files contained in this classpath. Following simple Ant target will echo the content of the classpath variable ('application.classpath'):
 <target name="printClassPath">  
      <property name="appClasspath" refid="application.classpath"/>  
      <echo message="classpath= ${appClasspath}"/>  
 </target>  

Tuesday, April 7, 2009

Recursively rename files

I knew the command for finding files in recursive fashion + I knew command for renaming the files = I now know how to recursively rename the files

find . -type f -name *.txt -exec rename -v 's/.txt/.xml/' {} \;

Similarly, say for example if you need to recursively delete the (.exe) files from your USB stick, you may use following command:
find /path/to/usb/dir -name '*.exe' -print -exec rm -f {} \;

and to remove files below size 200 use command:
find . -type f -size -200 -exec rm {} \;
or somthing like
find . -name '*.exe' -exec rm {} \;

Hope this is helpful to other people too.

Wednesday, April 1, 2009

Automated GUI Testing Tools - Comparison Matrix

After spending much efforts of hunting down the best possible tool for Automated GUI Testing for RCP Application; we came up with the following extract:



Sr. No.ToolsAvailabilityProsCons
AbbotOpen SourceLibrary (Java)1. Programmatically drive UI components
2. Records user actions programatically
3. Tools build up using Abbot - Costello, Windows Tester, Rcp Robot
4. More suitable for AWTUnit / SwingUnit testing
1. No Automatic GUI Recorder
2. More Efforts on spends on writing Java Code
3. Time consuming.
CostelloOpen SourceRecorder (XML)1. Automatic GUI Recorder for AWT & SWING applications
2. Records user actions and facilitate script construction and maintenance
3. Useful for building Unit tests and Function tests
4. Records, Edits, playback XML scripts using Abbot
5. Provides a full-fledged script editor for the generated scripts
1. Currently not supported for SWT / RCP applications.
TPTPOpen SourceRecorder (XML / Java) 1. Allows Eclipse developers to automate regression tests
2. Supports Automatic GUI Recorder
3. Also supports performance and functional testing
1. User actions on native dialogs cannot be recorded because SWT events based on the actions are not reported
2. Keyboard shortcuts are not recorded when object-based recording is enabled
3. SWT does not report mouse / keyboard events when the user clicks a menu item on the menu bar or when the user clicks the native (minimize, maximize, close) buttons that appear in the right hand corner of applications in a windows environment.
SWT BOTOpen SourceLibrary (Java)1. Facility to record and playback scripts
2. Ant support for playback of test suites, reporting, and multi threaded playback
3. Test case execution is easily integrated into a continuous build system
1. Don't have ready-made automatic GUI recorder as well as script editor
2. Not sure about we can build script on top of SWT BOT to make automatic GUI recording
Windows TesterCommercial
Recorder / Library (Java)1. Test cases are based on the JUnit standard
2. Pure Java GUI test cases are easy to read
3. Test cases are customizable
4. You can re-factor GUI test cases easily
5. Provides a rich GUI Test library
6. Test case execution is easily integrated into a continuous build system
7. You can create new GUI test case support for GEF easily record and playback tests for Java GUIs using the Eclipse Graphical Editing Framework (GEF)
1. Not Open Source
RCP RobotOpen SourceLibrary (Java)1. Designed for specially for RCP applications
2. RCP Robot is an API on top of Abbot
3. They are used to write GUI tests in Java using some kind of testing framework
1. No automatic GUI recorder or script editor
2. Manual efforts needed to write the test cases using Java code
3. Difficult to changing the existing code when requirement changes


Friday, March 20, 2009

Open full screen window using Javascript

Here's a very interesting sample code that I found. I have been looking for the solution of this issue since long time...
 <HTML>  
      <HEAD>  
           <SCRIPT LANGUAGE="JavaScript">  
           function openFull(theUrl) {  
                h = screen.height;  
                w = screen.width;  
                window.open(  
                     theUrl,'','left=0,top=0,screenX=0,screenY=0,  
                     height='+(h-100)+',width='+(w-10)+',  
                     directories=no,location=no,menubar=no,  
                     resizable=no,scrollbars=yes,status=no,  
                     titlebar=yes,toolbar=no'  
                );  
           }  
           </SCRIPT>  
      </HEAD>  
 <BODY>  
      <a href="javascript:void(0);" onClick="openFull('full-screen.html');">Open Full Screen Window</a>  
 </HTML>  

Sunday, March 15, 2009

More swap with a swap file ...

There are situations when either you have a pre-installed Linux system or a new one, but forgot to set enough swap space for your needs or you recently have upgraded your hardware (like I have recently added an additional RAM on my machine :) ).

Now, to make the most of the hardware that you've got, you might consider to increase the swap space. What do you do now? Do you need to repartition and reinstall the system? Answer is NO! Linux offers you with fascinating swap utilities to make a real file and use it as swap space. The trick is to make a file and then tell the swapon program to use it.

Here's how to create, for example, a 64 megs swap file on your root partition (of course make sure you have at least 64 megs free):
dd if=/dev/zero of=/swapfile bs=1024 count=65536


This will make a 64 megs (about 67 millions bytes) file on your hard drive. You now need to initialize it:
mkswap /swapfile 65536

sync

And you can then add it to your swap pool:
swapon /swapfile


With that you have 64 megs of swap added. Don't forget to add the swapon command to your startup files so the command will be repeated at each reboot.

Tuesday, March 3, 2009

Adding emmuerated values to the spreadsheet column.

Most of the client interactions makes use of various spreadsheets. One of the common strategy for validating some spreadsheet column is to provide a list of allowed enumerated values to it.

For long time I wasn't aware of this myself. Thus once I came to know about it I felt like sharing how to achieve that.

Following are the steps for adding validation to a spreadsheet column:

1. For Open Office (OpenOffice SpreadSheet):

  1. Select the spreadsheet cells for validating
  2. Click the menu: Data -> Validity. A popup dialog would appear.
  3. Select "List" option from the "Allow" drop-down.
  4. Add the comma-separated or tab-separated or newline-separated enumerated entries in the "Entry" text area.
  5. Click "Ok"
2. For MS Office (MS Excel):
  1. Select the spreadsheet cells for validating
  2. Click the menu: Data -> Validation. A popup dialog would appear.
  3. Select "List" option from the "Allow" drop-down.
  4. Add the comma-separated enumerated entries in the "Source" textbox.
  5. Click "Ok"

Sunday, March 1, 2009

Creating transparent images using GIMP (GNU Image Manipulation Program) ...

INTRODUCTION:
GNU Image Manipulation Program (GIMP) is a very powerful image manipulation software available for Linux operating systems. While working on one of client project which is a Rich UI application, we felt the necessity of inventing customized icons of our own at lot of places. The key challenge was to find a tool for helping our cause. After scanning through a stack of softwares available free / commercial; we found GIMP to be the most interesting of them all.
Two of the prime requirements for creating icons are to have a control over exact icon size and the graphic transparency. Following are the steps for creating transparent images using GIMP:


STEPS:
1. Open GIMP application
2. Click File -> Open
3. Select and load the image from the disk.
4. Zoom into the image for better accuracy while making it transparent.
5. Click Layer -> Transparency -> Add Alpha Channel
6. Make sure to select the Fuzzy selection tool from the main window toolbar for GIMP
7. Selectively click the section that you want to make transparent
8. When you are sure that this section is highlighted properly, then click Edit -> Clear or simply hit 'delete' from keyboard.
9. Repeat steps 7 and 8 until all the sections are made transparent.
10. Finally save the image File -> Save.


Hope these steps will be very helpful to everyone, especially if the application demands heavy use of images and icons.

Monday, February 16, 2009