YOUR FEEDBACK
Gregor Rosenauer wrote: well, not what's your take on this? Did I miss a second page of this article or...
AJAXWorld RIA Conference
Early Bird Savings Expire Friday Register Today and SAVE !..


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
POWERBUILDER LINKS YOU MUST CLICK ON


Highlighting Selected Text in PowerBuilder DataWindow
Techniques for simulating text formatting

Let's suppose that you have a search window where a user can enter a search string and get the list of text items matching this pattern. Ideally, the portions of text that meet the search criteria should be highlighted, for example, by text formatting. It could look like Figure 1.

In PowerBuilder we have a great tool for searching and displaying information - the DataWindow. But how can we do text formatting inside a DataWindow column? Unfortunately, there's no way in the DataWindow object to do that. This article describes a technique that will let you simulate this.

A Sample DataWindow
To explain, let's say that we have a tabular DataWindow with a one-string column called text. We'll only discuss selecting matching text patterns, not filtering data, so our sample DataWindow can have an external data source. The result set description for this DataWindow is very simple and is shown in the Figure 2.

Then we can either add some text data in our DataWindow through the Rows/Data menu command in the DataWindow Painter, or load data from some external source in script.

Selecting Part of the Text
Now we have a DataWindow containing the text we want to match against a string pattern. Next we want to select the portions of text in our DataWindow that meet this pattern, say, by highlighting the text in red.

If there are three rows in the DataWindow:

PowerBuilder rules the world.
It is a rule with us.
This is the rule of the game.

And the string pattern is the 'rule,' we want our rows to look like this:

PowerBuilder rules the world.
It is a rule with us.
This is the rule of the game.

We can't just highlight a portion of the DataWindow column, but we can break the column into three parts: a part before the selection, the selection, and the part after the selection. Let's add another string columnsearch to the result set of our DataWindow to store the string pattern. Instead of the original column text, add three computed fields. The expression for the first computed field is:

if( isNull(search), text,
if( pos(text, search, 1) = 0, text, left(text,
pos(text, search, 1) - 1) )
)

Let's call it "prefix". The expression for the second computed field is:

if(pos(text, search, 1) = 0, '', search)

Let's call it "matched." The expression for the third computed field is:

if( isNull(search), '',
if( pos(text, search, 1) = 0, '', mid(text,
pos(text, search, 1) + len(search) ) )
)

We call it "suffix." Put them side-by-side and size them to the width of original text column. Set the font color for the "matched" to red. Now you can delete the text column.

As a result we get the picture shown in Figure 3 in preview mode. Well done, they're red! But there are nasty gaps between our computed fields and they don't look like one DataWindow column. To properly size and place our computed fields we check on the Slide left property for the matched and suffix computed fields (click the left mouse button on a computed field, Properties, Position tab, Slide groupbox, check the left checkbox). Put your DataWindow in preview:

And here it is - text formatting inside a DataWindow column! So, we have simulated the selection of a portion of text in a DataWindow item just by adding an extra column to the DataWindow result set, creating three computed fields instead of the original column. No script at all! (see Figure 4)

Selecting Several Parts
What if we want to select several parts of the text in a DataWindow item, say two, three, or even more? Then we'll have to create more computed fields for parts of the original column. Let's go further and break ourtext column into the smallest parts - the characters. Every computed field will contain just one character of the text column: the first computed field will contain the first character, the second computed field the second character, and so on. The expression for such a computed field looks like this:

mid( text, , 1)

Then we'll be able to select any characters of the text column by setting the font color of the desired computed fields. We could get a string such as:

PowerBuilder rules the world.

To properly set the font color for our computed fields we can use a technique described by Buck Woolley in his article "Not Your Father's DataWindow" (PBDJ volume 8 issue 7). In short, the essence of this technique is packing parameters of many DataWindow objects in string columns. In our case we have one such parameter for every computed field: selected or not. In our example DataWindow the length of the text column is 50 characters so we'll have 50 computed fields.

Let's add a string column called "select" to the result set of our DataWindow where the packed parameters will be placed. It also has a length of 50.

For the colorful text mentioned above, the "select" column will contain the string:

"0101010101010010100101001010000000<...>"

and so on to the end of string.

OK, so far so good, but how can we create our computed fields? Can you imagine creating 50 (or even more) computed fields manually? This would be madness! Well, it's time for coding.

Selection Service Object
Let's make an object that does all the tedious work for us. First we have to initialize or prepare our DataWindow by creating as many computed fields as the length of the original column. To do this we have to know the DataWindow and the name of the original column. The code for the function of_init() is shown in Listing 1. All visual parameters for the created computed fields are taken from the original column. At the end of this function an instance variable is initialized with a string of 0s.

Second, we need a function that selects the given portion of the text. The arguments for this function are the number of the first selected character, the length of the selection, and the row number in the DataWindow. Let's call it of_select(). The code for this function is shown in Listing 2.

Finally, we need a function that clears a selection in a particular row. The code for this function of_clear() is shown in listing 3.

Conclusion
In PowerBuilder there are no direct ways for text formatting inside a DataWindow column. But by using the techniques described you can simulate text formatting of portions of the text in a DataWindow column. You can use any text formatting you want: change the font color, change the background color, make it bold or italic, or even change the font.

About Konstantin Goldobin
Konstantin Goldobin is a senior developer at a software company in Voronezh, Russia. He has been working with PowerBuilder since 1995 version 4.0. Visit his web site at www.vsi.ru/~kgold.

YOUR FEEDBACK
SYS-CON Australia News Desk wrote: Let's suppose that you have a search window where a user can enter a search string and get the list of text items matching this pattern. Ideally, the portions of text that meet the search criteria should be highlighted, for example, by text formatting.
SYS-CON Italy News Desk wrote: Let's suppose that you have a search window where a user can enter a search string and get the list of text items matching this pattern. Ideally, the portions of text that meet the search criteria should be highlighted, for example, by text formatting.
SYS-CON Brazil News Desk wrote: Let's suppose that you have a search window where a user can enter a search string and get the list of text items matching this pattern. Ideally, the portions of text that meet the search criteria should be highlighted, for example, by text formatting.
PBDJ LATEST STORIES . . .
Join Scott Guthrie as he discusses Microsoft’s commitment to web standards development, Rich Internet Applications and how Microsoft is contributing to help move the web forward. Join Adobe’s Kevin Lynch as he demonstrates how Flash and HTML come together to make the most engaging,...
Particularly in a means of moving PowerBuilder applications to the web. What I’m looking for doesn’t require a server license or the installation of unmanaged code to the web server, and works well across different browsers (not just Internet Explorer). The WPF DataWindow will help...
"The rise of Enterprise Architecture is proof that organizations need to manage the impact of changes in competition, technology and regulations across their enterprise," said Dan Lahl, director of Intelligent Enterprise for Sybase. "PowerDesigner 15's unique Link and Synch technology ...
With PowerBuilder 11 Sybase gave developers what we have long hoped for – the possibility of taking an application created in a client/server architecture and turning it into a Web application, almost without having to move the code; and it's better if you don't use a server applicat...
Like any standard .NET application, the PowerBuilder .NET application follows the common language runtime rules regarding the permissions needed to do the operation the application aims to do. The code access security (CAS) provided by the .NET Framework is a security mechanism that a ...
PowerBuilder 11.0 supports deploying existing PowerBuilder client/server business applications as an ASP.NET WebForm application. This greatly improves developer productivity without having to learn a new development language and preserves PowerBuilder development skills. Although the ...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING POWERBUILDER / SYBASE NEWS

Organized by TAITRA (Taiwan External Trade Development Council) and Taiwan Electric...