Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes Text in SWT ToolBar using JFACE actions. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Text in SWT ToolBar using JFACE actions." Watch "Text in SWT ToolBar using JFACE actions." New topic
Author

Text in SWT ToolBar using JFACE actions.

Jeff Barnard
Greenhorn

Joined: Nov 24, 2008
Posts: 11
It's been awhile since I last asked for help here, but I'm still good at getting lost in Java ...

I want to add a text field that I can update as a status in org.eclipse.swt.widgets.ToolBar (since it's the most intuitive location- right beside the control action related to that status).

I am implementing an org.eclipse.jface.window.ApplicationWindow using the standard setup, as shown in <http://www.ibm.com/developerworks/opensource/library/os-jface1/index.html>, where I'm calling the org.eclipse.jface.action.ToolBarManager.add() method to populate actions in the ToolBar similar to the (working) example shown in <http://www.coderanch.com/t/509741/GUI/java/Images-not-showing-up-JFace#2304348>.

The problem is I can't seem to find the appropriate class to implement this text field. I seem to have difficulty using org.eclipse.jface.action.StatusLineContributionItem (only shows red missing icon indication) and trying to add org.eclipse.swt.widgets.Text to the new action class is confusing (no parent composite exists until AFTER the window is opened- and calling the setText() method causes threadId contention).

I would welcome any and all ideas for a simple solution to this problem.
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

I don't see why not just add a Status Line?

put addStatusLine() in your constructor, and then override createStatusLineManager() "protected StatusLineManager createStatusLineManager()"

in that method create a StatusLineManager object and return it, you can use its setMessage() method to add text to it. (pass that method with no value to clear the text)


~tak
irc.esper.net - tak, irc.freenode.com - tak11, irc.efnet.org - tak11
Jeff Barnard
Greenhorn

Joined: Nov 24, 2008
Posts: 11
Lance,

Thanks for replying- and I apologize for my delay on this (had to deal with some other firefights before coming back to this problem).

Question:
put addStatusLine() in your constructor

... please clarify which constructor- if you mean the ApplicationWindow, then that StatusLine is already being used for other purposes. There is a high preference for this status/text window to be in the ToolBar (right beside the control action icon related to that status). My current implementation uses the following code flow to add the tool bar and it's icons/actions:



So do I need to code a major redesign to follow your suggestion, or am I missing something?

Thanks again for any input,
Jeff
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Sorry I wasn't aware the ApplicationWindow StatusLine was being used for other purposes.

could you add a read-only text field to the toolbar and update it with the status changes?
Jeff Barnard
Greenhorn

Joined: Nov 24, 2008
Posts: 11
Lance,

Not a problem on the confusion, I'm not explaining things well enough

I previously tried adding a read-only text field- but I know (now) I was doing it incorrectly- so here's another attempt...

The problem is that constructing the org.eclipse.swt.widgets.Text requires a org.eclipse.swt.widgets.Composite- and I'm unclear as to what that "parent" Composite should be, since the shell hasn't been created yet and the getToolBarControl.getParent() hasn't been set yet:



Thanks for your continuing input
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Jeff Barnard wrote:
The problem is that constructing the org.eclipse.swt.widgets.Text requires a org.eclipse.swt.widgets.Composite- and I'm unclear as to what that "parent" Composite should be, since the shell hasn't been created yet and the getToolBarControl.getParent() hasn't been set yet:


why not override the createToolItem method?

CTRL+F for createToolItem
Jeff Barnard
Greenhorn

Joined: Nov 24, 2008
Posts: 11
Thanks for the suggestion and link... I am familiar with the SWT Gentle Intro series (very useful).

createToolItem() needs to refer to the ToolBar (true for even an overridden method), which hasn't been created at this point in the ApplicationWindow initialization (as can be seen in the modified code below).



If I'm not missing something (which is quite likely), I'm starting to surmise that I need to add the TextFieldAction to the ToolBar after the ApplicationWindow initialization has opened the Shell window.

Please let me know if I've missed something...
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Jeff Barnard wrote:
If I'm not missing something (which is quite likely), I'm starting to surmise that I need to add the TextFieldAction to the ToolBar after the ApplicationWindow initialization has opened the Shell window.

Please let me know if I've missed something...


Yes I'm fairly certain that's the way you have to do it, since you can't pass a non-existent parent to the TextField, how come you wanted to add it before the Shell has been initialised?
Jeff Barnard
Greenhorn

Joined: Nov 24, 2008
Posts: 11
First to answer the question: I was following the template that can be seen in my 1/21 code... adding actions in createToolBarManager() via toolBarManager.add(). The only difference is that all the other actions are associated with icons, while this new action is associated with a text field.

By the way, since the ApplicationWindow uses org.eclipse.jface.window.Window.open(), I have overridden this method (and org.eclipse.jface.window.Window.runEventLoop()) and calling the TextFieldAction() constructor just after calling org.eclipse.swt.widgets.Shell.open(). This finally gets the text field to appear in the toolbar (thanks for your help)- at the wrong location !

So now I can be picky... I have managed to move the field to the right end of the other toolbar icons, but would prefer to have it at a particular location in the middle of those icons. My current constructor is captured below:



So my followup request is to see if there's any way for this text field to be at a particular location in the middle of the toolbar's action icons.
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

I have limited experience with toolbars, however can you set a layout on the toolbar then set the layout data for the Text data?
Jeff Barnard
Greenhorn

Joined: Nov 24, 2008
Posts: 11
I finally figured it out:

I replaced the Text within Action class with a ControlContribution class, and the height problem is fixed.

So thanks for your help, and I'll close out this discussion.
Lance Colton
Ranch Hand

Joined: Nov 25, 2010
Posts: 64

Sorry I didn't get back to you :-) I ment to, however it slipped my mind when I started getting more busy. I'm glad you got it worked out
 
wood burning stoves
 
subject: Text in SWT ToolBar using JFACE actions.
 
Similar Threads
Need advice for converting this page to JSF
Stop seperator from showing bar
got stuck in running my first struts example. help
collection getting appended on refresh of page
adding listeners