Genii Weblog

Midas 101 - Chunk Definitions

Fri 1 Aug 2003, 11:15 AM



by Ben Langhinrichs
Since I started my articles on Rich Text 101, I have gotten requests from customers to write a matching series of articles on Midas Rich Text LSX subjects.  These may not have the same general appeal, but may be interesting to customers and those considering becoming customers.  I'll put links to both sets of tutorials on our weblog.

For those who have not used our Midas Rich Text LSX much, or have used it primarily from samples such as the Send It! sample, this topic may jelp explain some of the odd syntax and code samples.  While Midas was written to allow access to rich text constructs which were exceedingly hard to modify via LotusScript (or any other programming language), the strength of the product is not mostly the access it allows, but the engine which makes such access so simple.  

The Midas engine relies on a peculiar design methodology.  The Notes Object Model, which basically maps a class to each discrete entity, such as a document, a view, a database, an item, etc.  The Midas Object Model has very few classes, and primarily relies on a single class, the GeniiRTChunk class.  This "chunk" represents a portion of the rich text in somewhat the way a view represents a portion of the document collection of a database.  

In a view, there are selection criteria which determine which portion of the document collection to show.  Within that selection, there is an order based on sorting.  In the Midas Rich Text LSX, there is a chunk definition, which also determines which portion of the rich text to use.  This may be a single element definition, such as "Button 2", or it my be a group of elements defined by a wildcard or range, such as "Section 2-5" or "Table *", or it may even be a portion of rich text bounded by one or more elements, such as "After Graphic 3".  Finally, the portion of rich text can be narrowed down by drilling down in the definition, such as "Table *; Row 1", which is the first row of every table, or "Inside Section 3; Table 1; Row 1; Column 2-4", which is columns 2 through 4 of the first row of the first table inside the third section.  Phew!

So, we can define a chunk of rich text to act on, and we have great flexibility about defining it.  So what?

Well, here is the powerful part.  We can then use any of the methods or properties in the GeniiRTChunk class on any chunk.  Midas will "do the right thing" as one customer put it, no matter what chunk is described.  Let's see a couple of examples to see what this means.

Set rtchunk = rtitem.DefineChunk("Table *; Row 1")
rtchunk.Font = "12pt -BOLD"

Two lines.  The first defines the chunk.  The second sets the text point size and removes the bold attribute.  Very simple, but what is changed?  Well, it depends on the rich text field.  There may be ten tables, or just one, or none at all.  The text may be in Verdana or Comic Sans MS, and it may be in italics or underlined.  There may be nested tables, with graphics, all inside collapsed sections.  It doesn't make a difference, since Midas will simply find each table, and all text in the first row of that table will have its point size changed to 12 pt and its bold attribute turned off.  The other font attributes, font faces, colors, etc. will not be changed.  The graphics won't be effected.  Midas will just "do the right thing".

Another example, showing another feature:

Set rtchunk = rtitem.DefineChunk("Section 1")
rtchunk.ButtonText = "Press Me!"

Now wait, this has to be a mistake.  I defined a chunk as a section, but changed a property which has to do with buttons.  Does Midas raise an error?  No.  Does it do anything?  It depends.  What if there are buttons inside the section, perhaps inside a table inside the section?  If so, Midas will change their text to "Press Me!".  If not, it will simply do nothing.  After all, it isn't an error to say "Change the text of all buttons inside the section" if there are no buttons.  All buttons were changed, since all can be none.

But why is all this valuable?  Isn't it easier to just step through classes that represent each object and change the appropriate properties directly?  Consider these two examples, taken from real customers (with altered names).

Set rtchunk = rtitem.DefineChunk("Everything")
Call rtchunk.ReplaceText("DDSERVER_04", "HANSERVER01", "TEXT & NONTEXT")

With two lines, we change the server name whether it is hardcoded into section titles, button text, field formulas, computed text, hide-when formulas, action formulas, text, URL links or anywhere else.

Set rtchunk = rtitem.DefineChunk("After Section 2")
Call rtchunk.ChangeFont("Arial", "Verdana")

Again, two lines, one to define, one to act, but this takes a fairly hardcoded format with two collapsable sections that make up preliminary data that should not be altered, and changes anything after that.

I'll write more about Chunk Definitions, including some special features that allow named chunks, in a future tutorial.  I would encourage you to read the article on Chunk Definitions and Late Binding, which discusses late binding in chunk definitions, to clarify a common misunderstanding of how the definition is applied to the rich text.

Copyright © 2003 Genii Software Ltd.

What has been said:


31.1. kurt
(12/01/2003 06:35 AM)

test


31.2. HeonGue
(04/07/2004 01:17 AM)

test


31.3. Martin Cooke
(24/02/2006 04:52)

Excellent article and very useful table of HTML WYSIWYG editiors