Converting PowerBuilder Applications to Java  –  Tip #1

Overview

I had to convert a PowerBuilder application to Java for a client recently and documented some information to help out any other PB developers who might need to do the same.  The task is not a fun one but it forced me to learn Java.

Java to PowerBuilder

Java to PowerBuilder

Java in my opinion is a 3GL (3rd Generation Language) so in many situations it will take a lot more code to accomplish the same things as in a 4GL such as PowerBuilder.  The datawindow is the most challenging thing to convert and at first I was tempted to write my own Java datawindow replacement, but the task was far too difficult for a Java beginner.  One of the most difficult and overlooked part of the conversion was printing.  Java is terrible at printing reports and something that we take for granted as PowerBuilder developers is a nightmare in Java.

I’ll post the PowerBuilder to Java tutorials in many separate posts titles similar to this one.  You can click on the PB to Java category to show all posts for that category and find all the tips I’ve posted to date.

Top Issues when converting from PowerBuilder to Java Client Server

  • UI controls don’t map easily especially datawindow controls and edit mask
  • Converting DataWindows
  • Mapping of PowerBuilder events to Java Swing
  • Datawindow Reports

Top Solutions for converting PowerBuilder to Java

  • Since the Swing library is platform independent to achieve the same look and feel the Layout Manager needs to be set to Windows look and feel. There is no native Java for Edit Mask but there are third party components available.
  • Develop helper classes that implement the base DataWindow functionality.
  • Some UI events in PowerBuilder do not have equivalent in Java Swing.  Experimentation and use of multiple events may be needed.  e.g. DataWindow ItemChanged Event -> FocusListener.focusLost
  • Use BIRT (open source) for reporting.
[adrotate banner=”16″]

Mapping of PB Objects and Variables to Java

Converting PowerBuilder Datatypes to Java Datatypes

The most obvious challenge in a conversion is to determine mapping between PowerBuilder object types and variables and Java.  There is no hard set rules when it comes to the mappings but I’ve posted suggestions based on my limited experiences.  The most challenging objects to convert are datawindows.  There was another area that caused a lot of confusion for me at first, and that is passing values by reference in function calls, or events.  You can’t pass variables by reference in Java so you need to work around that by creating classes for your variable types and using getter and setter methods.  I’ll explain in more detail in a future post.

So for now, here is a list of potential mappings of PowerBuilder to Java objects/variables.

PowerBuilder to Java Conversion

Object Mapping Suggestions

PowerBuilder Java
CheckBox javax.swing.JCheckBox
CommandButton javax.swing.JButton
GroupBox javax.swing.JPanel
HScrollBar java.awt.Scrollbar
Line java.awt.Graphics
TreeView javax.swing.JTree
MultipleLineEdit javax.swing.JTextArea
Oval java.awt.Graphics
Picture java.awt.Image
PictureButton java.awt.Image
RadioButton java.swing.JRadioButton
SingleLineEdit javax.swing.JTextField
StaticText javax.swing.JLabel
Tab javax.swing.JTabbedPane
Datawindow (Free Form) javax.swing (various components)
Datawindow (Grid, Tabular) javax.swing.JTable

Variable Mapping Suggestions

PowerBuilder Java
boolean boolean
date java.util.Date
datetime java.util.Date
dec java.math.BigDecimal
dec short
long int
real float or double
string java.lang.String

Datawindows – Converting Tips

Datawindows are by far the most complicated to convert to Java.  There are lots of different datawindow object types but in general there are List types and Free Form types.  Also, to be considered are drop down datawindows.  In PowerBuilder drop down datawindows are easy and they use a code value and display value. By default they do not use a code value in Java,  the JComboBox only uses a display value. If this is a problem then you could extend the JComboBox and write code to support the data value.  There is no support for edit mask type controls, the only suggestion is to use third-party tools such as JSuite.

List Style Datawindows

The JTable is a good option for converting tabular and grid view datawindows.   There are some aftermarket controls you might want to consider that have extended the JTable, we did not purchase any but we suffered with a pretty difficult learning curve.  The JTable is very primitive compared to the datawindow so you’ll be doing a lot more coding than you are used to.

Free Form Datawindows

Typically, we would create a Jpanel for Free Form datawindows.  Then depending on which controls you need, place them onto the Jpanel.  Use the mapping table above for determining which components to use on the Jpanel.

Printing Datawindows

There is no support for printing JTables in a report format.   We purchased a third-party tool for reporting in the new Java application.  Printing in Java appears to be an afterthought, if your client requires a lot of printing support be sure to allow a LOT of time to support this.

Using Layout Managers

When designing GUI’s in Java it is important to understand Layout Managers.  I have had some exposure to Layout Managers when learning Microsoft .NET in Visual Studio 2010. Using layout managers is pretty cool because your GUI is much more flexible when it comes to resizing and different screen sizes.  You can hard code component X and Y coordinates by setting layout managers to null.  The gridbaglayout is one of the best layout managers in Java, and it is the most common one that IDE’s generate when layout out GUI’s.

Layout Managers help applications adapt to different operating systems.  Also another great advantage of Layout Managers is that you will not have to code for resize events which can be tedious in PowerBuilder if you have lots of controls.

Convert PowerBuilder Units to Pixels

If you are converting some PB objects to Java and want to keep some of the same look and feel then you’ll have to convert PowerBuilder X and Y coordinates to Pixels.  PowerBuilder provides functions called XUnitsToPixels and YUnitsToPixels.

Converting Structures

Java doesn’t support structure objects so you will need to create objects and then make instance variables for each of the attributes of the structure. You’ll also need to make getter and setter methods for each of the instance variables.  The instance variables should be declared as private and access be limited to using getter and setter functions.

25 Responses

  1. I am willing to bet that as time goes on, factors of on-page and off-page SEO are going to change as we know it. I think we will see a transformation towards user factors in deciding SERP results. That included with increased personalized SERP results and we’ll be seeing a huge molding of the users experience with Bing and the other search engines. Each search result will not be made alike, just look at things like user involvement, bounce time, bounce rate, etc… Focus on a better user experience all around, and I think you’ll see better results in 2010.

    • I have plans to post a detailed tutorial on PowerBuilder to Java, and PowerBuilder to WaveMaker however it seems time goes by so quickly. Thanks for taking the time to comment.
      Sincerely,
      Rich

      • thanks for your reply.

        i can understand a detail tutorial will take a long time.

        I think we all can appreciate, If you can post an some more information on the conversion. like

        1. tools used for converting
        2. where & how to start
        3. may be simple program to convert add two values on SLE & display in a static text etc.

        i am clueless & eager to know how to convert PB to java.

        Thanks again.

        Rajesh

      • Hi Rajesh,
        Thanks again for the feedback. I am actively working on this type content. Have I mentioned WaveMaker? Or have you looked at WaveMaker? It is a good tool to ease into Java. I wouldn’t recommend any automatic conversion programs. The strategy is really dependent on the situation, are you looking to get something to Java as quickly as at the lowest cost possible? Or do you have budget/time to re-develop the application (better)? I’ll send you an email and we can take some of this offline, I’d be happy to help out.
        Regards,
        Rich

      • Hi Rich,

        I saw a post of yours at http://www.displacedguy.com/tech/powerbuilder/converting-powerbuilder-applications-to-java-tip-1/

        We have a PB 7 application that we’re porting to Java. We’re looking for a tool that can generate Java code from the PB business logic code.

        We’re using a combination of STRUTS and SPRING frameworks and the JQuey Aerowindow framework plugin for the viewer piece.

        JavaScript Aerowindow framework
        http://archive.plugins.jquery.com/project/aerowindow

        Do you know of any migration utilities that we can use to port the PowerBuilder business logic code to Java?

        Please reply directly to mhall@ltcpartners.com if possible.

        Thanks!

      • Hi Mitch,

        I just replied to a similar comment – and I apologize for the delay in replying to yours. This is basically what I posted on the subject– but if you are looking the Java way then WaveMaker might just take you to where you need to go — it hides the complexities of Struts, Spring etc., and it does a very good job. If you go that route please tell them “Rich at DisplacedGuy” referred you– I don’t get paid or anything but I do say a lot of good things about them and they treat me like a real customer unlike Sybase. I’ve talked to the CEO of WaveMaker via email — and been offered a week training course when times were rough for me — and he asked me what they could do to make WaveMaker like the next PowerBuilder– this is the type thing that a successful company does. Reminds me of a little company called PowerSoft. Anyway I digress… here is my response to the other guy. I’ve been promoting PB for years and my site refers thousands of people to Sybase sites every year, so I tried getting them to buy a banner ad on my site for something like $100 a year and they didn’t even take the time to respond to my email. This is what I hate about Sybase. This site gets tons of traffic and makes pennies in ad revenue (techies are ad blind– we are too smart and see the ads as “ads” rather than content. This site hogs my bandwidth and the only reason I keep it running is that I make a lot of connections. If this site performed like my best site it would do over $20 daily in ad revenue– this site has not done $20 in ad revenue since inception in May 2010. Oh, the content I promised…

        I hear and see examples of what you described on a regular basis. I can’t mention the name of the companies, but there are some that are literally hand-cuffed to old PowerBuilder applications and having desperate times finding developers to support them. One company I worked planned to retire a PB app within one year of my contract start, I left the contract 8 years later and the application had been enhanced, and new interfaces added to SAP or other systems making the process of moving from PB even more complex.

        I believe this happened because management at many companies made a dire mistake of looking for the next best thing rather than really evaluating what was working and why they wanted to change. Now some companies want to change because they view PB as a risk, developers are hard to find, rates are higher, and us PB developers can command just about anything we want. If you’re a PB developer and not working from home, then you aren’t negotiating strongly enough. If you are GOOD at PB you can be working at a Fortune 500 company from your living room and still pulling six figures.

        I see no solution– we see very few successful Java projects, a few successful Microsoft projects but those tend to be at mid-sized companies. The first tool that I’ve found that MIGHT have what it takes is WaveMaker– I’m currently evaluating it but I believe that I could convert many of the smaller PB applications I’ve worked on in short order, and WaveMaker generates true Java applications so that the management doesn’t need to lose sleep about going with some unheard of technology.

        It is my opinion– and strong one at that– that Java cost the business world a catastrophic amount of money. Too many managers jumped ship and got burned, now they caused PB to lose critical mass in market share further putting them in a really tough spot. Us PB die-hards as they like to call us are hard to convince otherwise because nothing comes close. I recommend keeping an eye on WaveMaker, a cautious eye, because there is NO easy solution to what you are up against.

        I wish I could share specifics — a company I am under contract with now is severely hand-cuffed to MANY PowerBuilder applications and their attempts to rewrite in Java are in year three– the users don’t like using the Java versions so the PB apps just won’t go away. The only reason for the PB demise, is putting PB into the hands of an untrained developer — okay this is purely opinion but there’s tons of anecdotal evidence that maybe PB wasn’t so bad after all.

        IF I still feel as strongly about WaveMaker in a few months I may start marketing myself to lead conversions of PB applications to WaveMaker, which will generate pure Java applications using complex frameworks that would take years to master. Stay tuned…

  2. Did you evaluate any automatic converters?

    Do you know of any? I am looking for any time savings possible in going from PB to Java for the presentation.

    Thanks. Sean.

    • I have not evaluated any automated converters, I have always been skeptical of them. If I can find a company that has one and willing to let me try it free of charge then I’d gladly write about my experiences.

      If you happen to learn of anything please let me know.

      Sincerely,
      Rich

    • I don’t believe in automatic converters to be honest. But my number one question asked is how to convert PB to Java or .NET – I wish that I had time to post details on how to do it. My real job takes so much of my time. I will try to answer questions though.

  3. Great Information. We are looking at converting our PB apps to java or .net. Are wondering what the best option is, since we no longer have a PB resource. Any info would be helpful. Thanks.

    • Hi Sue,
      I’m working on more documents for assisting those interested in doing conversions. If outsourcing is an option then please contact me directly, I may be able to offer some suggestions.
      I’ll send you an email
      Regards,
      Rich

  4. Hi, I am a Java developer. We got a new requirement for converting PB to Java application. Could you please suggest me where to get started and what are the challenges we would have. Should we go for some tools you were mentioning earlier.
    Any help is much appreciated. Expecting quick reply.

    Thanks in advance.

    • Hi Rajaneesh, There really is no easy way to convert PB to Java or any other language for that matter. The datawindow is too proprietary and it makes conversion difficult. Now code in non-visual components might be easier to convert if it doesn’t use datastores, etc.. The only advice I have is plan enough time it will take some time but it is possible. I happen to like WaveMaker a Java based tool but you’ll still need to start developing from scratch. I would love to get a PB to Java conversion (as a project) myself so if your company wants to outsource one contact me. I can do any database and offer satisfaction guaranteed. I would do development off-site. -Rich

Leave a Reply to DisplacedGuy Cancel reply

Your email address will not be published. Required fields are marked *