Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » How to switch outlines with SWT
How to switch outlines with SWT [message #1003553] Mon, 21 January 2013 14:04 Go to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
The Swing client automatically provides buttons to switch between defined outlines. The SWT client does not provide these buttons. I have looked into various solutions to this and have found a few ways to do this:

  • adding a menu Outline to the Desktop and then adding a submenu for each outline; in execAction set the outline using
    setOutline(StandardOutline.class)

  • adding an OutlineButton to a form and configuring it using its getConfiguredOutline() method


Both methods sort of work (I occasionally loose the table view when switching outlines) but neither of them is as elegant as having those buttons above the outline tree view in Swing.

Is there an easy way to replicate this behaviour in an SWT client? In another thread, somebody mentioned that this is what SnapBoxes were for, but I have no idea how I would display one of those outside a form.
Re: How to switch outlines with SWT [message #1003854 is a reply to message #1003553] Tue, 22 January 2013 06:10 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 761
Registered: October 2011
Senior Member
Quote:
In another thread, somebody mentioned that this is what SnapBoxes were for


Please if you mention an other forum thread, add a link to it:
How to use SnapBox


Is your question not a duplicate of this one ?
[SWT GUI] switch between outlines attached to the desktop?


With this method, you have to programm the Coolbar directly in the SWT Plugin. You need to ensure manually that your code match with the Scout Client Model (If you add an outline for example).
Re: How to switch outlines with SWT [message #1003906 is a reply to message #1003854] Tue, 22 January 2013 08:04 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie Bresson wrote on Tue, 22 January 2013 07:10
Quote:
In another thread, somebody mentioned that this is what SnapBoxes were for


Please if you mention an other forum thread, add a link to it:
How to use SnapBox

Sorry, I was going to but then forgot to do so before posting.

Jeremie Bresson wrote on Tue, 22 January 2013 07:10
Is your question not a duplicate of this one ?
[SWT GUI] switch between outlines attached to the desktop?

It is indeed, I must have missed that post when looking through the forum, sorry.

Jeremie Bresson wrote on Tue, 22 January 2013 07:10
With this method, you have to programm the Coolbar directly in the SWT Plugin. You need to ensure manually that your code match with the Scout Client Model (If you add an outline for example).


I'll have a look at the two links in the post you quoted above to see if I manage to make it work, thanks for pointing me in the right direction.
Re: How to switch outlines with SWT [message #1003989 is a reply to message #1003906] Tue, 22 January 2013 11:25 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Ok, so I had a look at the post [SWT GUI] switch between outlines attached to the desktop which links to an RCP tutorial on how to add a MainToolbar. Unfortunately, that tutorial was way beyond me (I wouldn't have had a clue where to start adding the code in the tutorial to the Scout SWT files).

I then had a look at the subsequent post by Li Hao which mentioned a post by Andreas Hoegger on how to extend the OutlineTreeForm to include a SnapBox containing the outline buttons. I've been successful in adding the snapbox, however its look is totally different from what Beat Schwarzentrub's Screenshot looks like in this post.

Screenshot by Beat Schwartentrub:
http://www.eclipse.org/forums/index.php/fa/13018/

The way it looks in my client:
http://www.eclipse.org/forums/index.php/fa/13052/0/

How do I make a button in a SnapBox show its label as well as its icon?

Also, switching outlines using these buttons does not work correctly: I need to press an outline button twice, to change outline, I'm not sure if this is related to them being toggle buttons or how I could change them to normal behaviour (overwriting getConfiguredDisplayStyle() to return DISPLAY_STYLE_DEFAULT does not work).
Re: How to switch outlines with SWT [message #1004024 is a reply to message #1003989] Tue, 22 January 2013 13:02 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 761
Registered: October 2011
Senior Member
Urs Beeli wrote on Tue, 22 January 2013 12:25
Ok, so I had a look at the post [SWT GUI] switch between outlines attached to the desktop which links to an RCP tutorial on how to add a MainToolbar. Unfortunately, that tutorial was way beyond me (I wouldn't have had a clue where to start adding the code in the tutorial to the Scout SWT files).


I don't no if this can help, but here is the code: ApplicationActionBarAdvisor


/!\ This was written with Scout Indigo... Maybe the generated SWT classes looks different now.
Re: How to switch outlines with SWT [message #1004472 is a reply to message #1004024] Wed, 23 January 2013 10:08 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks for this pointer. I had not realised that there was an ApplicationActionBarAdvisor class already in my SWT project Smile

I have now added the code from your example (which closely matches the code in the RCP tutorial I linked above). Unfortunately, it throws an exception when I am trying to add the ToolBarContributionItem to the coolBar depending on the id string used to create the ToolBarContributionItem:
  @Override
  protected void fillCoolBar(ICoolBarManager coolBar) {
    IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    ToolBarContributionItem tbci = new ToolBarContributionItem(toolbar, "org.eclipse.ui.main.toolbar"); // using this string, causes an exception below
    //ToolBarContributionItem tbci = new ToolBarContributionItem(toolbar, "toolbar"); // using this string, no exception is thrown, but no toolbar shown either
    coolBar.add(tbci);  // this line throws an exception with the long string
    toolbar.add(standardAction);
    toolbar.add(administrationAction);
  }


If I change the id-string to just "toolbar", no exception is thrown, but no toolbar is shown, either. Any ideas on how to proceed?

The exception is:
!MESSAGE Exception occurred while rendering: org.eclipse.e4.ui.model.application.ui.basic.impl.TrimmedWindowImpl@44534453 (elementId: IDEWindow, tags: [topLevel], contributorURI: platform:/plugin/org.eclipse.platform) (widget: Shell {minicrm}, renderer: org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer@ca30ca3, toBeRendered: true, onTop: false, visible: true, containerData: null, accessibilityPhrase: null) (label: %trimmedwindow.label.eclipseSDK, iconURI: null, tooltip: null, context: TrimmedWindowImpl (IDEWindow) Context, variables: [], x: -2147483648, y: -2147483648, width: 1024, height: 768)
!STACK 0
org.eclipse.e4.core.di.InjectionException: java.lang.ClassCastException: org.eclipse.e4.ui.model.application.ui.basic.impl.TrimBarImpl incompatible with org.eclipse.e4.ui.model.application.ui.menu.MToolBar
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:63)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:859)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:111)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:81)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.inject(ContextInjectionFactory.java:72)
	at org.eclipse.ui.internal.Workbench.createWorkbenchWindow(Workbench.java:1252)
	at org.eclipse.ui.internal.Workbench.getActiveWorkbenchWindow(Workbench.java:1224)
	at org.eclipse.ui.internal.services.WorkbenchSourceProvider.updateActiveShell(WorkbenchSourceProvider.java:924)
	at org.eclipse.ui.internal.services.WorkbenchSourceProvider.getCurrentState(WorkbenchSourceProvider.java:133)
	at org.eclipse.ui.internal.services.WorkbenchSourceProvider$6.handleEvent(WorkbenchSourceProvider.java:684)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1058)
	at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1664)
	at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2145)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4525)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1627)
	at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2069)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4976)
	at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
	at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:231)
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1217)
	at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.postProcess(WBWRenderer.java:730)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:646)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:732)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:703)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:697)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:682)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:964)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.minicrm.ui.swt.application.Application.startSecure(Application.java:43)
	at org.eclipse.minicrm.ui.swt.application.Application$1.run(Application.java:35)
	at java.security.AccessController.doPrivileged(AccessController.java:284)
	at javax.security.auth.Subject.doAs(Subject.java:573)
	at org.eclipse.minicrm.ui.swt.application.Application.start(Application.java:32)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:611)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.ClassCastException: org.eclipse.e4.ui.model.application.ui.basic.impl.TrimBarImpl incompatible with org.eclipse.e4.ui.model.application.ui.menu.MToolBar
	at org.eclipse.ui.internal.CoolBarToTrimManager.add(CoolBarToTrimManager.java:130)
	at org.eclipse.ui.internal.CoolBarToTrimManager.add(CoolBarToTrimManager.java:115)
	at org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor.fillCoolBar(ApplicationActionBarAdvisor.java:59)
	at org.eclipse.ui.application.ActionBarAdvisor.fillActionBars(ActionBarAdvisor.java:154)
	at org.eclipse.ui.internal.WorkbenchWindow.fillActionBars(WorkbenchWindow.java:2058)
	at org.eclipse.ui.internal.WorkbenchWindow.setup(WorkbenchWindow.java:533)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
	at java.lang.reflect.Method.invoke(Method.java:611)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
	... 57 more

[Updated on: Wed, 23 January 2013 10:08]

Report message to a moderator

Re: How to switch outlines with SWT [message #1005229 is a reply to message #1004472] Thu, 24 January 2013 17:19 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 761
Registered: October 2011
Senior Member
I think this is because with E4 you should contribute Actions this way...

I didn't take time to investigate E4 yet. So I can not help you. A quick search point me to: Part actionbar contributor


Scout 3.8.x (the version comes with Juno) run against:
- Eclipse 3.x
OR
- Eclipse 4.x + Compatibility Layer.


My code was produced for a 3.7.x scout application running on a Eclipse 3.x runtime.

When you develop something in the SWT plugin of your Scout application, you are in a "normal" RCP application. Please refer to the RCP docs (examples, tutorials, forum posts...).
Re: How to switch outlines with SWT [message #1005665 is a reply to message #1005229] Mon, 28 January 2013 07:26 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie, thanks for your clarification. So just to make sure I undestand this correctly: We are building our application using Eclipse 3.7 (Indigo)/Scout SDK 3.8.1 but the target platform will be Eclipse 3.8.1/Scout 3.9 (currently M4, that is likely to change). Am I right that with this setup I'll need to use the E4 RCP methods?

I took a brief look at the link in your last post and it seems like I'll need to dig deeper into the RCP docs for E4 in order to understand what I need to do, this is going to take a little longer than I had hoped Smile
Re: How to switch outlines with SWT [message #1005683 is a reply to message #1005665] Mon, 28 January 2013 09:18 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 761
Registered: October 2011
Senior Member
For the Target Platform (the runtime of your application):
-> E4 corresponds to Eclipse 4.x.x (Let say Eclipse 4.2.1).


I think that my code works on Eclipse 3.8.1.

For me Stuff like "org.eclipse.e4.ui.model.application.ui.basic.impl.TrimBarImpl incompatible with org.eclipse.e4.ui.model.application.ui.menu.MToolBar" is E4 code and is part of 4.2.
Re: How to switch outlines with SWT [message #1005750 is a reply to message #1005683] Mon, 28 January 2013 14:45 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Although I am using Eclipse 4.2.1 as my IDE, I have set up a target definition file containing the following entries:
<unit id="org.eclipse.scout.rt.source.feature.group" version="3.9.0.20121218-1038"/>
<unit id="org.eclipse.scout.rt.testing.source.feature.group" version="3.9.0.20121219-1012"/>
<unit id="org.eclipse.platform.ide" version="3.8.1.M20120914-1540"/>
<unit id="org.eclipse.rcp.feature.group" version="3.8.1.v20120814-105048-92BmGJlFw3Ez0WZ9TxCqgcSVAE"/>
<unit id="org.eclipse.equinox.sdk.feature.group" version="3.8.0.v20120522-1841-7M7fA78g5_y-eQjtHxcd47Zm7mDQ"/>
<unit id="javax.servlet" version="2.5.0.v201103041518"/>

If I understand things correctly, this would force my code to be built for Eclipse 3.8.1/Scout 3.9 - which according to your post above should support the toolbar code.

So, I re-applied the target settings and added the toolbar code again. Now, I no longer get the exception, but I also do not see a toolbar.

My code looks as follows:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
  private IWorkbenchAction standardAction;
  private IWorkbenchAction administrationAction;

  public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
    super(configurer);
  }

  @Override
  protected void makeActions(IWorkbenchWindow window) {
    standardAction = ActionFactory.ABOUT.create(window);
    standardAction.setText("Standard");
    register(standardAction);

    administrationAction = ActionFactory.ABOUT.create(window);
    administrationAction.setText("Administration");
    register(administrationAction);
  }

  @Override
  protected void fillMenuBar(IMenuManager menuBar) {
    menuBar.add(new MenuManager("", IWorkbenchActionConstants.M_FILE));
  }

  @Override
  protected void fillCoolBar(ICoolBarManager coolBar) {
    IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    ToolBarContributionItem tbci = new ToolBarContributionItem(toolbar, "org.eclipse.ui.main.toolbar");
    coolBar.add(tbci);
    toolbar.add(standardAction);
    toolbar.add(administrationAction);
  }
}


Do I need to do anything in addition to the above? Or won't these "dummy" actions work?
Re: How to switch outlines with SWT [message #1005812 is a reply to message #1005750] Mon, 28 January 2013 20:11 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 761
Registered: October 2011
Senior Member
Hi,

I am really sorry... The code I mentioned is not a working version (It is probably some code I use to test stuff).

I see:
TODO JBR: change these Actions => should correspond IViewButton of the scout desktop


I am quite sure that I have a working version somewhere, but this version with the ActionFactory.ABOUT should create buttons in the coolbar that open an about windows (In my opinion you should see it). In this code there is no link with scout.


I will try to put something together or I will ask Matthias if he can tell about his approach.
Re: How to switch outlines with SWT [message #1005867 is a reply to message #1005812] Tue, 29 January 2013 06:43 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
I realise there was not yet a connection to scout, but I don't even see the buttons to open the about window and was uncertain if I missed anything obvious. Thanks for your continued help on this!
Re: How to switch outlines with SWT [message #1005883 is a reply to message #1005867] Tue, 29 January 2013 08:27 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias Villiger
Messages: 80
Registered: September 2011
Member
I think we have implemented an outline switch in SWT for the BahBah example application. This should run on Eclipse 3.8.x with Scout 3.8.x.
You can find it here: BahBah SVN

Does this work for you?

regards,
m
Re: How to switch outlines with SWT [message #1005921 is a reply to message #1005883] Tue, 29 January 2013 10:06 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Hi Matthias

I've been able to view the BahBah source code using a web browser but have failed to do a checkout from that URL either using TortoiseSVN or Eclipse.

Tortoise says: "Could not connect to server https://dev.eclipse.org". I've tried using svn:// and http:// but that didn't help.
Eclipse fails when I try to add the SNV location saying with the error message below:
index.php/fa/13138/0/

I've tried to merge the SWT based code into my code and while it compiles, it also fails to show a toolbar.

Could this be related to the bug where the dynamic menus disappear when the outline is set (because I am seeing this bug in my application, so maybe the SWT toolbar disappears for the same reason)?

If I set breakpoints in ApplicationActionBarAdvisor I can step through

  • makeActions() creating 2 empty buttons
  • fillCoolbar() which adds those two empty buttons to the toolbar
  • initViewButtons() which reads the two outline buttons from the desktop and configures the buttons created in makeActions


(I've added the OutlineViewAction class, modified ApplicationActionBarAdvisor and SwtEnvironment in my application to match the BahBah code). Am I missing more code that is needed? Looking through the SWT package of the BahBah example I didn't see anything obvious (and can't do an automated compare due to being unable to check out).
  • Attachment: svnerror.png
    (Size: 45.12KB, Downloaded 481 times)
Re: How to switch outlines with SWT [message #1006129 is a reply to message #1005921] Wed, 30 January 2013 06:34 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie Bresson
Messages: 118
Registered: November 2010
Senior Member
I could run:
svn checkout http://dev.eclipse.org/svnroot/technology/org.eclipse.scout/scout.example/branches/3.8/bahbah


Are you sure you are not behind a proxy or something like that ?
Re: How to switch outlines with SWT [message #1006135 is a reply to message #1006129] Wed, 30 January 2013 07:17 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie

I am sure that I *am* behind a proxy. However, for TortoiseSVN I have setup the proxy config a long time ago (and succesfully retrieved sources from other external svn servers in the past) and in eclipse I was expecting the general proxy settings to be used (which are regularly succesfully used when installing and updating software).

After your post, I checked the TortoiseSVN settings and it seems that the proxy port has changed since I set it up in there, so after fixing the port number I was able to retrieve the code using tortoise.
For Eclipse I have not found any setting to specify a separate proxy for SVN access and still don't know why it can't connect through the proxy server that is defined for eclipse. Anyway, I've got the code, so I'll start building the project to see if the BahBah application shows the toolbar.

Thanks for your reminder to check the proxy settings.
Re: How to switch outlines with SWT [message #1006158 is a reply to message #1006135] Wed, 30 January 2013 09:30 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Ok, I've now compiled and run the BahBah example with the same target settings as my project and there I can see the toolbar in the SWT client. So I compared the code of the two projects and found why mine didn't show the toolbar: In my ApplicationWorkbenchWindowAdvisor.preWindowOpen() method there was a line:
configurer.setShowCoolBar(false);

After changing this to true, the bar displays. I have also modified the BahBah code so the toolbar not only displays the OutlineViewButtons but the buttons added to the desktops toolbar.

As this question has been asked a few times, here is a summary with all the changes I needed to make to show the outline change buttons on the SWT toolbar:
<package-base-path>.ui.swt\SwtEnvironment.java
-> add member
  private ApplicationActionBarAdvisor m_advisor;

-> modify the addEnvironmentListener as follows:
    addEnvironmentListener(new ISwtEnvironmentListener() {
      @Override
      public void environmentChanged(SwtEnvironmentEvent e) {
        if (e.getType() == SwtEnvironmentEvent.STARTED) {
          removeEnvironmentListener(this);
          IDesktop d = getClientSession().getDesktop();
          if (d != null) {
            setWindowTitle(d.getTitle());
            d.addPropertyChangeListener(IDesktop.PROP_TITLE, new PropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent evt) {
                setWindowTitle((String) evt.getNewValue());
              }
            });
            m_advisor.initViewButtons(d); // --> add this line
          }
        }
      }
    });
  }

-> add method setAdvisor
  public void setAdvisor(ApplicationActionBarAdvisor advisor) {
    m_advisor = advisor;
  }


<package-base-path>.ui.swt.application\ApplicationWorkbenchWindowAdvisor
-> in preWindowOpen, change the line
  configurer.setShowCoolBar(true);

to
  configurer.setShowCoolBar(true);


<package-base-path>.ui.swt.application\CoolbarButton
-> create a new class
package <package-base-path>.ui.swt.application;

import org.eclipse.jface.action.Action;
import org.eclipse.minicrm.ui.swt.Activator;
import org.eclipse.scout.rt.client.ui.action.IAction;

/**
 * 
 */
public class CoolbarButton extends Action {

  private IAction m_button;

  public CoolbarButton() {
    setText(" ");
    setEnabled(false);
  }

  public void init(IAction b) {
    setText(b.getText());
    setId(b.getActionId());
    setActionDefinitionId(b.getActionId());
    setToolTipText(b.getTooltipText());
    setImageDescriptor(Activator.getDefault().getEnvironment().getImageDescriptor(b.getIconId()));
    m_button = b;
  }

  @Override
  public void run() {
    Runnable r = new Runnable() {
      @Override
      public void run() {
        m_button.setSelected(true);
        m_button.getUIFacade().fireActionFromUI();
      }
    };
    Activator.getDefault().getEnvironment().invokeScoutLater(r, 10000);
  }
}


<package-base-path>.ui.swt.application\ApplicationActionBarAdvisor
-> add members
  private static final int NUM_OUTLINE_BUTTONS = 10; // --> make this big enough to fit all your outline and toolbar buttons
  private CoolbarButton[] m_coolbarButton = new CoolbarButton[NUM_OUTLINE_BUTTONS];

-> add the following line to the constructor
  public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
    super(configurer);
    ((SwtEnvironment) Activator.getDefault().getEnvironment()).setAdvisor(this); // --> add this line
  }

-> add the following methods
  @Override
  protected void makeActions(IWorkbenchWindow window) {
    for (int i = 0; i < NUM_OUTLINE_BUTTONS; i++) {
      m_coolbarButton[i] = new CoolbarButton();
    }
  }

  public void initViewButtons(IDesktop d) {
    IViewButton[] viewButtons = d.getViewButtons();
    int start = 0;
    int end = Math.min(m_coolbarButton.length, viewButtons.length);
    for (int i = start; i < end; i++) {
      CoolbarButton b = m_coolbarButton[i];
      IViewButton v = viewButtons[i];

      b.setEnabled(v.isEnabled() && v.isEnabledGranted());
      if (v.isVisible() && v.isVisibleGranted()) {
        b.init(v);
        register(b);
      }
      else {
        b.setEnabled(false);
      }
    }

    IToolButton[] toolButtons = d.getToolButtons();
    start = end + 1;
    end = Math.min(m_coolbarButton.length, start + toolButtons.length);
    for (int i = start; i < end; i++) {
      CoolbarButton b = m_coolbarButton[i];
      IToolButton v = toolButtons[i - start];

      b.setEnabled(v.isEnabled() && v.isEnabledGranted());
      if (v.isVisible() && v.isVisibleGranted()) {
        b.init(v);
        register(b);
      }
      else {
        b.setEnabled(false);
      }
    }
  }

  @Override
  protected void fillCoolBar(ICoolBarManager coolBar) {
    IToolBarManager toolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
    coolBar.add(new ToolBarContributionItem(toolbar, "main"));
    for (Action a : m_coolbarButton) {
      toolbar.add(a);
    }
  }


Thanks to everyone who helped me get this far, I really appreciated your help!

Just out of curiosity: Is there a reason why the above code is not generated by default? I see the issue of the magic array size being dependent on the number of buttons added in the client, but that could be chosen big enough to hold quite a few as a start...
Re: How to switch outlines with SWT [message #1006167 is a reply to message #1006158] Wed, 30 January 2013 10:30 Go to previous messageGo to next message
Jeremie Bresson is currently online Jeremie Bresson
Messages: 761
Registered: October 2011
Senior Member
Thanks a lot for the time you took to investigate this.

I will update my example application with your code.


Urs Beeli wrote on Wed, 30 January 2013 10:30
Just out of curiosity: Is there a reason why the above code is not generated by default? I see the issue of the magic array size being dependent on the number of buttons added in the client, but that could be chosen big enough to hold quite a few as a start...


That a good question.

One of the big problem is (with Eclipse 3.x):
When the coolbar (Eclipse RCP) is populated, the Scout Model of the Application is not available.

With Eclipse 4.x, it should no longer be a problem (you can add and remove stuff in the E4 Application model when you want).


Second aspect to consider:
Not everybody wants the different outline represented in the RCP coolbar.
In my opinion the coolbar is really near the the button bar we have in the SWING application, so it would make sense.

But other projects use SWT Scout application embedded in Lotus Notes (as lotus notes plugin/extensions) or with additional UI Guideline.
It is possible to represent the Scout Outline as RCP Perspective or as Beat show in this thread with SnapBox.


I think it is difficult to provide something that works for everybody.

[Updated on: Wed, 30 January 2013 10:34]

Report message to a moderator

Re: How to switch outlines with SWT [message #1006215 is a reply to message #1006158] Wed, 30 January 2013 13:35 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias Villiger
Messages: 80
Registered: September 2011
Member
Urs Beeli wrote on Wed, 30 January 2013 04:30
Just out of curiosity: Is there a reason why the above code is not generated by default? I see the issue of the magic array size being dependent on the number of buttons added in the client, but that could be chosen big enough to hold quite a few as a start...


Well, actually I totally agree. The SWT code should be created so that outline buttons, tool buttons and menu entries show up as soon as these elements are added to the scout model.

Unfortunately there are several problems with that:
1. the current implementation of the Scout SWT environment needs an initialized SWT workbench. this means, scout starts *after* the workbench.
2. In a 3.x workbench some elements are hard to dynamically inject after startup
3. The coolbar is hidden by default because not everyone uses outline buttons and if you don't use them, you just waste space in your application window (the bar is actually shown even if there is no button inside).

There are now several things we could do:
- As Jérémie explained: with E4 workbench model, dynamic injecting should no longer be a problem. Therefore we could integrate an E4 workbench.
- We could try to refactor the current swt environment so that it can start without a running workbench so that the scout model could be loaded before the workbench is being created. This would allow us to directly access the scout model when initializing the workbench.

Currently we are still investigating if and what should be implemented by when.

hope this gives you some background
m
Re: How to switch outlines with SWT [message #1006370 is a reply to message #1006215] Thu, 31 January 2013 06:42 Go to previous message
Urs Beeli is currently offline Urs Beeli
Messages: 335
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Matthias and Jeremie, thanks for your answers.
Previous Topic:Load Codes Problem
Next Topic:Problems refreshing a form-on-a-page
Goto Forum:
  


Current Time: Wed Oct 22 15:33:39 GMT 2014

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

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