BUG Community

Welcome! Log In

bballantine's Blog

JFace EditingSupport for Custom Tables

Stan Lee in Spider Man taught us that, "With great power there must also come -- great responsibility!"  I think about that quote when working on Eclipse plug-ins, only it changes in my head to read, "With great power there must also come -- great complexity!"  Eclipse provides the building blocks to do wonderfully powerful things, but to wade into plug-in development is to wade into all sorts of complexity. 

My most recent responsibility/complexity was to make a service properties chooser/editor in the BUG Application code generation wizard.  This functionality (still in development at the time of this writing), will allow BUG Application developers tighter control of the filters used by the Application's Service Tracker.

Service property values are stored as strings, but they can represent booleans, numbers, or Strings.  I wanted to create a table where each row is a service property key/value pair.  The developer can then choose the properties they want to include in the filter and modify the values for that property.  Moreover, I wanted the property value to be editable like a text field for things like numbers, but use a combo box for things like boolean values.  Here's what the table looks like:

created on: 07/21/09

It looks straight forward enough, but the implementation turned out to be rather challenging.  The custom behavior of the cells pushed me toward using JFace CellEditorS and EditingSupport.  I found some tutorials and code-snippets on-line, but nothing suited my specific needs, which were to have checkbox support and selection events on the rows, plus different CellEditorS for each of the second column's cells, depending on the type of value.  The most helpful tutorial I found is here: http://www.vogella.de/articles/EclipseJFaceTable/article.html.  It didn't solve all my problems, but it certainly gave me a start.

After some time-consuming web-slinging, pining over the above tutorial, and some old-fashion trial and error, I was able to finally make the thing work.  Here, I share my solution in the hope that it will help where other resources fall short:

First, let's start out with the class.  This particular JFace component was added to a WizardPage:

public class CodeGenerationPage extends WizardPage {

Next, define our main TableViewer as an instance variable:

// Main JFace component private CheckboxTableViewer servicePropertiesViewer;

All of the wizard page drawing is kicked off from the createControl method, which you must override.  Inside there, we create the JFace components -- a CheckboxTableViewer which is the surrounding table, and TableColumnViewerS for the columns -- and put it all together:

// table with list of properties to choose from // compServices is a Group that we're putting all of this stuff in final Table propertiesTable = new Table( compServices, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION); propertiesTable.setHeaderVisible(true); propertiesTable.setLinesVisible(true); // layout of columns in table TableLayout propTableLayout = new TableLayout(); propTableLayout.addColumnData(new ColumnWeightData(90)); propTableLayout.addColumnData(new ColumnWeightData(120)); propertiesTable.setLayout(propTableLayout); // layout of table on the page GridData pViewerData = new GridData(GridData.FILL_BOTH); pViewerData.horizontalSpan = layout.numColumns; pViewerData.heightHint = SERVICE_PROPERTIES_HEIGHT_HINT; propertiesTable.setLayoutData(pViewerData); // viewer for services list servicePropertiesViewer = new CheckboxTableViewer(propertiesTable); servicePropertiesViewer.setContentProvider(new ServicePropsContentProvider()); // Add a listener to do something when a checkbox on a row is selected servicePropertiesViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { // You can do something when a row is selected here } }); // Column 0 - checkbox and property name // col0 is taken care of by checkboxtableviewer TableViewerColumn col0viewer = new TableViewerColumn(servicePropertiesViewer, SWT.FULL_SELECTION, 0); // TableViewerColumn needs a label provider col0viewer.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { return ((ServicePropertyHelper) element).getKey(); } }); col0viewer.getColumn().setText(KEY_LABEL); // Column 1 - property value w/ celleditors // col1 has custom cell editors defined in EditingSupport below TableViewerColumn col1viewer = new TableViewerColumn(servicePropertiesViewer, SWT.FULL_SELECTION, 1); col1viewer.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { return ((ServicePropertyHelper) element).getSelectedValue(); } }); col1viewer.getColumn().setText(VALUE_LABEL); // col1viewer has editing support - // this is where the magic happens that sets a different celleditor depending col1viewer.setEditingSupport( new PropertyValueEditingSupport(col1viewer.getViewer()));

The comments in the code should help explain things, but there are two items worthy of extra attention.  First, by using a CheckboxTableViewer, we can get a selection event from the table and also access selected elements via servicePropertiesViewer.getCheckedElements().  For the second column's CellEditorS, we need to decide, per-cell, which editor to use (whether to use a TextCellEditor or a ComboBoxCellEditor) based on what the potential values are.  We do this by adding EditingSupport to the column, i.e. col1viewer.setEditingSupport().  Here is most of the EditingSupport implementation (with all the helper functions stripped out for brevity):

public class PropertyValueEditingSupport extends EditingSupport { private final String[] truefalse = new String[] {"true", "false"}; private Composite parent; private TextCellEditor text_editor; private ComboBoxCellEditor combobox_editor; public PropertyValueEditingSupport(ColumnViewer viewer) { super(viewer); parent =((TableViewer) viewer).getTable(); text_editor = new TextCellEditor(parent); combobox_editor = new ComboBoxCellEditor(parent, new String[0]); } @Override protected boolean canEdit(Object element) { return true; } @Override protected CellEditor getCellEditor(Object element) { ServicePropertyHelper propertyHelper = ((ServicePropertyHelper) element); if (usesTextEditor(propertyHelper.getValues())) { // Ints and blanks use text editor return text_editor; } else { // everything else uses a combobox if (hasBools(propertyHelper.getValues())) // boolean combos prefill w/ true and false combobox_editor.setItems(truefalse); else // other types, just do set the combobox to values combobox_editor.setItems(propertyHelper.getValuesAsArray()); return combobox_editor; } } @Override protected Object getValue(Object element) { ServicePropertyHelper propertyHelper = ((ServicePropertyHelper) element); if (usesTextEditor(propertyHelper.getValues())) { return propertyHelper.getSelectedValue(); } else { return Integer.valueOf(propertyHelper.getSelectedIndex()); } } @Override protected void setValue(Object element, Object value) { // Get the current service that's been selected ServicePropertyHelper propertyHelper = ((ServicePropertyHelper) element); if (usesTextEditor(propertyHelper.getValues())) { // if it's a text field, just set the value propertyHelper.setSelectedValue("" + value); } else if (hasBools(propertyHelper.getValues())) { // if it's a boolean, value is an index in truefalse array propertyHelper.setSelectedValue(truefalse[Integer.valueOf("" + value)]); } else { // if it's something else, value is an index in the service property values set String val = propertyHelper.getValueAt(Integer.valueOf("" + value)); if (val != null) propertyHelper.setSelectedValue(val); } getViewer().update(element, null); } }

In the constructor, we create our two CellEditorS.  We then override getCellEditor(Object element) to return the proper cell editor for the passed element.  Element is an element in the array returned from servicePropertiesViewer's ContentProvider.getElements() method (I must point out that the relationship between a TableViewer, it's ContentProvider, it's TableViewerColumnS, and a TableViewerColumn's EditingSupport is pretty confusing.  The tutorial mentioned above should help clear all that up if you're lost.  Also, if you're still in the dark about JFace viewers, label providers, content providers, and inputs, Eclipse: Building Commercial-Quality Plug-ins is a must-read).  We must also override a couple of other EditingSupport methods: canEdit(), getValue(Object element), and setValue(Object element, Object value).  The important thing to note is that the values (given and returned) for a TextCellEditor are Strings, and for a ComboBoxCellEditor, Integers.  My model object (when I set up my CheckBoxTableViewer, a list of model objects is set with the setInput() method), is called ServicePropertyHelper.  It keeps track of the possible values and the set/selected values for a property.  It also has some helper methods for setting these, which the PropertyValueEditingSupport methods call.

So, this is obviously rather complex stuff, but it's powerful as well.  Using EditingSupport and CellEditorS gives very fine-grained control over JFace TableViewerS for doing real custom Interfaces.  Lastly, the full classes can be found in our svn tree at svn://svn.buglabs.net/dragonfly/trunk/com.buglabs.dragonfly.ui/src/com/buglabs/dragonfly/ui/wizards/bugProject  and I'll be happy to answer any questions I can if you find yourself wrangling with similar problems.


Post Comments

Add Your Comment!

Log in to leave a comment or Create an account

"Aber glauben Sie ," sagte er , "das ist vielleicht Ashley hatte ihr nicht gesagt, er werde ittomorrow Louis Vuitton Nacht zu verk��nden und sie war sauer nba jerseys auf ihn nicht f��r ihr sagen , High Heels ein alter Freund , bevor er sagte ture religion sale everybodyelse ? M?dchen setzen einen gro?en Laden Christian Louboutin shoes , zu wissen, wie die Dinge zuerst. christian louboutin outlet online "
bem��hen Educational Technology Trainer : Wie true religion outlet der Name des already vermuten l ? ray ban outlet sst , this befasst Sich Rolle mit Michael Kors Outlet der Ausbildung von Erziehern in Neuen Technologien Christian Louboutin Outlet , sterben curricularen und
" Schauen true religion jeans Sie", sagte er. " Sie es nicht Michael Kors ,

new balance outlet online

h¨¹bsch, und ich wei? verdammt gut, sie haben kein Whisky,

Michael Kors Outlet Handbags

Roggen Vaters ber¨¹hren bekam . " " Ashley Wilkes sagte,

michael kors

dass sie eine Menge von Landschaft und Musik. Ashley

gucci bags

sterben Masse Kosten senken Kann unterlassen . Und VOR Allem

Michael Kors Outlet Store

Nicht KOPIEREN your TV -Star sofort nach der Show, ?h

Michael Kors Outlet

Nicht bezeichnet einen Nachahmer zu unterlassen . Kurz ges?gt, ?hm

kate spade

theslightest macht flattern und kreischen . "" Nun, man

prada outlet

kann nicht ihre Schuld . Sie haben zu schie?en Cade

Louis Vuitton Store

im Bein . "" Nun , ich wurde lickered oder

chanel outlet online

ich h?tte es nicht getan ", sagte Stuart .

Louis Vuitton Outlet

, bis wir sie aus. Alles, was sie werden wissen,




woke up to the delicious smell of baked pumpkin drifting down the hall. Even better, the Flitwick said, they, all, because he wants to Louis Vuitton Handbags see make a toad zoom Neville
to play, Quidditch to understand Louis Vuitton Outlet is simple. There are seven players on each side. It is gucci outlet 2014 called Chasers three of them." "Three Chaser, as took out a chanelfactoryoutletstore.us.com bright red ball
dry mouth, the door is open. In a michael kors outlet great leap 1, Harry, was able to slam the door to louisvuitton-lvoutlet.net grab a key to lock it. "Yes!" Flash victory of them, Louis Vuitton Bags and they began to run up the
children is through. Too newbalance-factory-outlet.com eager to fly again to to wait for the wood,

when it comes to the chairs for their restaurant
Trendy to match everyone's taste such handmade leather satchels quite wide ranging Fortunately there are cleaning machines to deal with Louis Vuitton such problems rapidly, competently and economically So for better opportunities people often move in and outside the city5 X 11 inches and 11 X 17 inches
However, without a clear message to broadcast your coach factory outlet message may fall on deaf earsRequire a SpinSome dentists offer free consultations or perhaps free cleanings to prospective patients And in all of them sports rules need to be firmly followed particularly if we Louis Vuitton talk concerning safety In the early19th century when soccer was a well liked Racket Sports have a set of rules but without any referee to execute or impose these rules Some people may not coach outlet know how to select a good dental office for routine and advanced oral care
In addition kate spade outlet

Coach Outlet Online

I said,' Dad, I'm too old for a good

Coach Outlet

bye kiss.I'm too old for any kind

Gef¨¹llt mit neuer Begeisterung durch ihren Erfolg , blieb sie auf , reden ¨¹ber die Grill undder Ball und Ashley Wilkes und Melanie Hamilton, michael kors outlet sich gegenseitig zu unterbrechen , Witze andlaughing sie an, deutete gucci bags breit f¨¹r Einladungen zum Abendessen . Einige Zeit vor vergangen christian louboutin shoes theyrealized dass Scarlett wurde mit sehr wenig zu sagen. Die gucci outlet online Atmosph?re war irgendwie ver?ndert. Justhow , haben die Zwillinge nicht, louis vuitton aber der feine Glanz war aus dem Nachmittag verschwunden. Scarlett michael kors handbags schien wenig Aufmerksamkeit auf das, was sie sagte bepaying , louis vuitton luggage obwohl sie aus den richtigen Antworten. Sensing somethingthey nicht verstehen michael kors konnte , verbl¨¹fft und es ?rgerte , k?mpfte die Zwillinge michael kors outlet online zusammen f¨¹r eine Weile,

I knewCoach Outlet Onlineall along that it would not last.Coach Factory OutletEven in April I was saying thatCoach Outletwinter would soon be here. Yet Coach Outlet Onlinesomehow it had begun to seem possibleCoach Outlet Storelately that a miracle might happen,Coach Outlet Store Onlinethat summer might drift on and onCoach Outletthrough the months -- a final Coach Factory Onlineto crown a wonderful year. TheCoach Factory Outletcelery settled that. Last nightCoach Outletwith the celery autumn came intoCoach Factory Outletits own. There is a crispness aboutCoach Outletair, the misty evenings -- but Coach Outlet Storenone of these comes home to meCoach Outlet Store Onlineso truly. There may be cool morningsCoach Outlet Onlinein July; in a year of drought the True Religion Jeansleaves may change before their time;True Religion Outletit is only with the first celeryTrue Religionthat summer celery that is of Michael Kors Outlet Onlinethe

I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon. Máy tập cơ bụng fitness

We d like to have a lot of people have such problems: poor, Jimmy Choo Sale out of a short trip, at the feast the way back home, Jimmy Choo Shoes have to take a few clothes, but form a complete set of shoes is very bad. Buy Jimmy Choo How is bad to put inside the box, fear of extrusion deformation better shoes, larger and very take a place, can only every time out to find a contradiction by wearing shoes. So first saw this shoe bag Jimmy Choo shoe case, Christian Louboutin Heels I think it must be. The shoes package shoe case is slightly a little expensive, because just a bag of shoes also with the crocodile skin material. Priced at $2295, Buy Christian Louboutin Shoes said despondently did back to look for alternatives. Or a shoe bag price is more expensive than a pile of shoes also, it is not too can accept, away from home when I don't know what is the love of shoes or love this bag .
louboutin uk

French brand Christian Louboutin Store New York will be located in the Meatpacking OuDeNan shoe store, covers an area of 1035 square feet, Discount Christian Louboutin Heels for the store design still has not yet been determined, but at least there is one thing certain, that the store will be laid on the designer's most iconic red carpet. Christian Louboutin Shoes Outlet In addition to men's shoes, also plans to introduce more men's products, such as men's bag. French brand Christian Louboutin, Louis Vuitton Bags Sale Christian Louboutin brand Alexis Mourot chief operating officer said, "although the men's shoes is only a small part in the fashion industry, Louis Vuitton Online Sale but we believe that the future it will be potential" .

Summer to should be particularly pay attention to the choice of shoes, Women Handbags Online but the stars have a favorite. Called star never far, LV bags Sale summer is a variety of banquet, cocktail party and parties "season", persisting some cool decorous grade follow sandal high, of course, is the top priority. LV Bags Online It today for you recommend a few pairs of women's favorite star Jimmy Choo sandals. When the metro-goldwyn-mayer (MGM) Jimmy Choo Heel company agreed to take comedy "Legally Blonde 2" (Legally Blonde 2), when people are in doubt, Robert this Sue mulberry Jimmy Choo Wedges Online is the target audience. But the 40 s company acquisitions and restructuring expert Jimmy Choo Pumps For Cheap who has attended with aflame mood in the UK premiere of the film

idea to ask for recommendations and check for feedback. A jersey could half money in comparison with an Michael Kors Sale authentic one cost center, but it can really last too louis vuitton purses little and fast dissolving after Louis vuitton Outlet several washings with its fit Louis Vuitton USA and shape lost.To conclusion, even if the authentic NFL jerseys are very expensive, they are really worth money. It's always a good gucci bags idea to invest money in quality and style. Indeed, gucci purses there are a plurality of online knockoff NFL shirts. Some Michael Kors Outlets white NFL jerseys are really great. Usually these NFL jerseys Louis vuitton Sale are sold are your favorite sports team jerseys with large Christian Louboutin Shoes discount prices.NFL will never go out of fashion. They are wholesale nfl jerseys designed to be fad for at

News from Henry Westwick (then pay a visit to his brother's house), Agnes was conscious of a certain relief. 'With the Atlantic between
this matter. Have you noticed while you louis vuitton purses were in Venice, that would be responsible for her husband extraordinary disappearance? On what kind of
I insisted on an apology, Miss, Michael Kors Outlet Store Online he had the audacity to say that life in the palace was boring and he did not know how else to Cheap Louis Vuitton Handbags amuse themselves! '' I
'How to get to Lord Ferrari Mont Barry?' My master used to live with his studies and his Coach Factory Online Store grief to close, 'Mrs. Rolland replied with a hard
On the morning of his departure to press his suit once more on Christian Louboutin Outlet Online Agnes, and children, as he had expected, turned out to be innocent obstacles in his
Twitching suppressed laughter.

Jimmy Choo Choo openeth brand launched a new website, Jimmy Choo Shoes Sale aims to promote the brand plans to launch the Choo openeth series shoes and accessories, etc. All Jimmy Choo's fans can upload their own street snap on the website is tie-in, Discount Jimmy Choo Online and tagging, time, places and things to do, and so on. Jimmy Choo Store may take collocation according to the street to recommend related products. Of course the most important thing is to accept many net friends. CL: we have already started to cooperate with Disney began, Shop Christian Louboutin Shoes in between you and me is the most familiar figures of Cinderella. Who else can more love than Cinderella shoes fantastic characters? Buy Christian Louboutin Heels Now I can't give the information. This is the release of a film "Cinderella" again, but may be more than that, Christian Louboutin USA there are beautiful shoes

Christian Louboutin red bottom shoes has become many contemporary of the princess and the princess of essentials. Christian Louboutin Discount Shoes Madonna is one of his fans, and stay out of Carla Bruni and putting just one example is the selection fans. Christian Louboutin Shoes Sale On May 1, the undisputed XieWang (or Manolo blahniks?) In London's design museum launched his first retrospective. You will see a lot of shoes here, Cheap Christian Louboutin a lot of shoes, flat shoes, boots, high heel, sneakers, what would you like to see what you have - and many with the designers for up to 20 years as design objects. Louis Vuitton Bags This exhibition will have another fascinating: making shoes, from the drawings Discount Louis Vuitton Bags to the factory. But Germaine Greer, may not agree, but exhibit fever probably reengineering McQueen last year Met phenomenon. In for a few days ago, Louis Vuitton For women Louboutin from the move-in period of heavy and complicated and ARTINFO chatted in Britain.

Host: actually what do you think of fashion? Jimmy Choo Heels What fashion is, how do you think of fashion? JIMMY CHOO: fashion to strive, to go and see what fashion is, how to overcome this problem. Jimmy Choo Discount As now the economic is a bit difficult, it need to individuals to take care of the problem. As has just started to do some cheap shoes. Or what shoes are you going to do now, I want some more communication, Shop Jimmy Choo do some more new information, increase is novel, attract people, business will be good, must go outside to talk to them, tell them. Louis Vuitton For men If he said that I now have no money, you can slowly back to me also . I like to wear white clothes. Why is that? I would like to wear white, Louis Vuitton Handbags I think white is pure, I don't know whether my habit. Because I think we got off the word, to do things are the white pants in white, the feeling is very pure, generally, Cheap Louis Vuitton Outlet women are like white

'I did not think Mr. Millward a fool, and he believes it all; but however little you may value the opinions of those about you - however little you may esteem them as individuals, it is not pleasant

nba jerseys

to be looked upon as a liar and a hypocrite, to be thought to practise what you abhor, and to encourage the vices you

nfl jerseys wholesale

would discountenance, to

nfl jerseys

find your good intentions frustrated, and your hands crippled by your supposed unworthiness, and to bring disgrace on the principles you profess.' 'True; and if I, by my thoughtlessness and selfish disregard to appearances, have at all assisted to expose you to these evils,

nba jerseys online sale

let me entreat you not only to pardon me, but to enable me to make reparation; authorise me to clear your name from every

nfl jerseys outlet

imputation: give me the right to identify your honour with my own, and to defend your reputation as more precious than my life!'

wholesale jerseys

» All comments
» Comments RSS

Powered by Community Engine