Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » howto add a new button to toolbar
howto add a new button to toolbar [message #1047666] Tue, 23 April 2013 13:54 Go to next message
Wolfgang Strunk is currently offline Wolfgang StrunkFriend
Messages: 6
Registered: July 2009
Junior Member
I would like to extend the toolbar and add some application specific icons.
index.php/fa/14482/0/

So this is not about adding a new outline.

Did someone try this before?


Thanks
Wolfgang
Re: howto add a new button to toolbar [message #1047715 is a reply to message #1047666] Tue, 23 April 2013 14:57 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 346
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Just add the proper classes to your client's Desktop class.

You can add classes that extend AbstractToolButton to add buttons to the right of the back/forward/refresh buttons (marked green in my screenshot below).
  @Order(10.0)
  public class DrawLineTool extends AbstractToolButton {

    @Override
    protected String getConfiguredIconId() {
      return Icons.DrawLine;
    }

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("DrawLine");
    }

    @Override
    protected String getConfiguredTooltipText() {
      return TEXTS.get("DrawLineTooltip");
    }

    @Override
    protected void execAction() throws ProcessingException {
      new DrawLineForm().startModify();
    }
  }


You can add classes that extend AbstractFormToolButton to add buttons to a bar on the right hand side of your window (marked blue in my screenshot below).
  @Order(40.0)
  public class GruppenFormTool extends AbstractFormToolButton {

    @Override
    protected String getConfiguredIconId() {
      return Icons.Gruppe;
    }

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("Gruppen");
    }

    @Override
    protected String getConfiguredTooltipText() {
      return TEXTS.get("GruppenTooltip");
    }

    @Override
    protected void execAction() throws ProcessingException {
      new GruppenForm().startDisplay();
    }
  }


Any class that extends AbstractOutlineViewButton will add a button to the outline toolbar (this is intended to switch outlines, but you can abuse this by overwriting the execAction method to do something else than switch outlines (though you need to create an associated outline and add it to the list of outlines to make the button shown) (marked in red in my screenshot below).
  public class DrawLineOutlineViewButton extends AbstractOutlineViewButton {
    public DrawLineOutlineViewButton() {
      // dirty nasty hack: we're attaching our button to a dummy outline (which needs to be added to the result in Desktop.getConfiguredOutlines(), otherwise our button won't be shown)
      super(Desktop.this, DummyOutline.class);
    }

    @Override
    protected String getConfiguredIconId() {
      return Icons.DrawLine;
    }

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("DrawLine");
    }

    @Override
    protected String getConfiguredTooltipText() {
      return TEXTS.get("DrawLineTooltip");
    }

    @Override
    protected void execAction() throws ProcessingException {
      // dirty nasty hack part 2: we stop AbstractOutlineViewButton.execAction (which would switch the outline) from being called and do "our thing" instead
      new DrawLineForm().startModify();
    }
  }



Note that the above works 1:1 using the Swing client without Rayo Look and Feel. Apparently Rayo does not support ToolButtons (but it does support FormToolButtons), so using the Swing client with Rayo, you'll only see the red and blue buttons, not the green ones. With the SWT client, none of these buttons will be shown out of the box and you'll need to add some code of your own to show them on the SWT Coolbar.

Buttons in Swing client without Rayo LnF:
index.php/fa/14483/0/

Buttons in Swing client with Rayo LnF:
index.php/fa/14484/0/

[Updated on: Tue, 23 April 2013 14:58]

Report message to a moderator

Re: howto add a new button to toolbar [message #1047816 is a reply to message #1047715] Tue, 23 April 2013 17:36 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 817
Registered: October 2011
Senior Member
Urs, this is a brillant answer!

It should be added to the wiki:
http://wiki.eclipse.org/Scout/Concepts/ToolButton
http://wiki.eclipse.org/Scout/Concepts/ViewButton

I will try to start, you can review/extend/modify.


Since Kepler M6 there is a better support for those buttons in the SDK. See Bug 364320.


Maybe Rayo should support ToolButtons...


In SWT you can also display ToolButtons (but you need to implement it in the SWT plugin of your application. On this forum there are discussions about "how to represent View Buttons in the RCP Coolbar").

[Updated on: Tue, 23 April 2013 17:44]

Report message to a moderator

Re: howto add a new button to toolbar [message #1047845 is a reply to message #1047715] Tue, 23 April 2013 18:31 Go to previous messageGo to next message
Wolfgang Strunk is currently offline Wolfgang StrunkFriend
Messages: 6
Registered: July 2009
Junior Member
Hi Urs,
that's an excellent answer and I totally agree with Jeremie: your examples should be added to the wiki and included into the book. Actually I intended to write about it, once I would have some hints and a working soluton but there is not much to add to your text. Cool

I still have some questions
- I am happy to see that the team is working on better support of Toolbars, but I wonder what the rationale behind missing support in Rayo is.
- is there any proposal what to use the AbstractFormToolButton for? I did not it used in any example.
- why is the AbstractToolButton not mapped to an SWT Coolbar by default?
Re: howto add a new button to toolbar [message #1048151 is a reply to message #1047845] Wed, 24 April 2013 05:27 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 817
Registered: October 2011
Senior Member
Wolfgang Strunk wrote on Tue, 23 April 2013 20:31
Hi Urs,
that's an excellent answer and I totally agree with Jeremie: your examples should be added to the wiki and included into the book.


For wiki: yes, the wiki is open (it is a wiki). We have no limitations, and our vision is that everybody should write in the wiki. More information here: wiki contributions.

For the book: Matthias is responsible for the content of the book (which is already defined). The space is limited (current version is already ~200 pages without all content). Contributions are more than welcome, but you should check with Matthias first if this is material for the book or not. (see also: book contributions).

Wolfgang Strunk wrote on Tue, 23 April 2013 20:31

I still have some questions
- I am happy to see that the team is working on better support of Toolbars, but I wonder what the rationale behind missing support in Rayo is.

Beat provided a good answer in an other topic from Urs, where he pointed discrepancies when using Rayo. Only the requested items were ported to rayo. I think additions like Toolbuttons could be added (there is space for a toolbar on top of the Rayo main window). As long as is does not break the choices made until now, it should be possible (Rayo is the widely used).

If you have interest let us know.

Wolfgang Strunk wrote on Tue, 23 April 2013 20:31

- is there any proposal what to use the AbstractFormToolButton for? I did not it used in any example.


In the project I am working on, we use the form tool button to open "side forms" on the right of the table (search forms, list of bookmarks, list of tasks...).

I think there is a demo of such behavior in the Scout widgets demo application.

Wolfgang Strunk wrote on Tue, 23 April 2013 20:31

- why is the AbstractToolButton not mapped to an SWT Coolbar by default?

In the SWT use cases I know sometimes the whole Scout application is represented in one perspective (using a SnapBox to switch between the outlines), sometimes each scout outline is a RCP-Perspective.
We discussed it in this thread: How to switch outlines with SWT

It might as changed in Kepler: see bug 383580 (I need to verify what changed exactly).

We are open for discussions.
Re: howto add a new button to toolbar [message #1048234 is a reply to message #1047845] Wed, 24 April 2013 07:44 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 346
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Wolfgang Strunk wrote on Tue, 23 April 2013 20:31
Hi Urs,
that's an excellent answer

I'm glad it helped you.

Wolfgang Strunk wrote on Tue, 23 April 2013 20:31
- why is the AbstractToolButton not mapped to an SWT Coolbar by default?


Jeremie provided you with a link to the thread I had started about changing outlines in SWT. Towards the end of that thread I asked the exact same question Smile Here is a link to the answer I received back then: http://www.eclipse.org/forums/index.php/mv/msg/450909/1006167/#msg_1006167

In any case, if you are interested in seeing those buttons in your SWT client, have a look at the HowTo I wrote on changing outlines in the SWT client, there is a chapter on how to do it using a toolbar: http://wiki.eclipse.org/Scout/HowTo/3.8/Changing_outlines_with_the_SWT_client#Adding_a_toolbar_to_the_SWT_application
Re: howto add a new button to toolbar [message #1053084 is a reply to message #1047715] Thu, 02 May 2013 11:22 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 817
Registered: October 2011
Senior Member
Hi Urs,

I took time to analyse your example for view button.

I do not really understand why you are missusing OutlineViewButton if you want a view button that has nothing to do with an outline.

The class hierarchy is:
\---+ AbstractAction
    \---+ AbstractViewButton
        \---+ AbstractOutlineViewButton


If you do not want the properties of AbstractOutlineViewButton you can use AbstractViewButton.

Here my example:
  @Order(30.0)
  public class MyViewButton extends AbstractViewButton {

    @Override
    protected String getConfiguredIconId() {
      return Icons.Gears;
    }

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("AboutScout");
    }

    @Override
    protected void execAction() throws ProcessingException {
      MessageBox.showOkMessage(TEXTS.get("AboutScoutTitle"), TEXTS.get("AboutScoutInfo"), null);
      setSelected(false);
    }
  }


index.php/fa/14616/0/

I am missing a point?
Re: howto add a new button to toolbar [message #1053136 is a reply to message #1053084] Thu, 02 May 2013 15:39 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 346
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie Bresson wrote on Thu, 02 May 2013 13:22
Hi Urs,

I took time to analyse your example for view button.

I do not really understand why you are missusing OutlineViewButton if you want a view button that has nothing to do with an outline.

I am missing a point?


Jeremie

I'll have to look at your example but most likely it was me that was missing a point, not you Smile I simply didn't realise I could place a button together with the "outline" buttons using AbstractViewButton, so I abused the AbstractOutlineViewButton.

Thanks for pointing this out.
Re: howto add a new button to toolbar [message #1053165 is a reply to message #1053136] Thu, 02 May 2013 19:22 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 817
Registered: October 2011
Senior Member
Hi Urs,

Not a big deal at all... I really appreciate your answer and I prefer reading this rather than nothing.

I added all your element to the 2 pages (execept for the DrawLineViewButton that I changed as discussed here):

* http://wiki.eclipse.org/Scout/Concepts/ToolButton
* http://wiki.eclipse.org/Scout/Concepts/ViewButton

Feel free to review and improve.

Because I hope it will help you and other people, I mentioned "AbstractOutlineViewButton vs AbstractViewButton" in this discussion.
Re: howto add a new button to toolbar [message #1053470 is a reply to message #1053165] Mon, 06 May 2013 07:43 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 346
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie

Thanks for those additions to the Concept pages, I think they cover the topic clearly.
Previous Topic:Casting query results
Next Topic:SVG Field in Swing and in SWT
Goto Forum:
  


Current Time: Thu Dec 18 08:34:49 GMT 2014

Powered by FUDForum. Page generated in 0.18815 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software