Skip to main content
Jump to: navigation, search

Difference between revisions of "Scout/HowTo/3.8/Changing outlines with the SWT client"

< Scout‎ | HowTo‎ | 3.8
(Added link to "Adding toolbars to views with the SWT client")
(Adding a toolbar to the SWT application)
 
(2 intermediate revisions by 2 users not shown)
Line 7: Line 7:
 
This method is the most straigth forward. Just add a menu entry for each Outline you want to switch to. Overwriting the '''getConfiguredIconId()''', '''getConfiguredText()''' and '''execAction()''' methods are sufficient for this:  
 
This method is the most straigth forward. Just add a menu entry for each Outline you want to switch to. Overwriting the '''getConfiguredIconId()''', '''getConfiguredText()''' and '''execAction()''' methods are sufficient for this:  
  
    @Order(10.0)
+
<source lang="java">
public class AdministrationOutlineMenu extends AbstractMenu {
+
@Order(10.0)
+
public class AdministrationOutlineMenu extends AbstractMenu {
  @Override
+
 
  protected String getConfiguredIconId() {
+
  @Override
    return org.eclipse.minicrm.shared.Icons.Administration;
+
  protected String getConfiguredIconId() {
  }
+
    return org.eclipse.minicrm.shared.Icons.Administration;
+
  }
  @Override
+
 
  protected String getConfiguredText() {
+
  @Override
    return TEXTS.get("AdministrationOutline");
+
  protected String getConfiguredText() {
  }
+
    return TEXTS.get("AdministrationOutline");
+
  }
  @Override
+
 
  protected void execAction() throws ProcessingException {
+
  @Override
    setOutline(AdministrationOutline.class);
+
  protected void execAction() throws ProcessingException {
  }
+
    setOutline(AdministrationOutline.class);
}
+
  }
 +
}
 +
</source>
  
 
= Using OutlineButtons on a form  =
 
= Using OutlineButtons on a form  =
Line 30: Line 32:
 
Another option is to place an instance of an '''AbstractOutlineButton''' on a form. After adding the Button, it needs to be configured:  
 
Another option is to place an instance of an '''AbstractOutlineButton''' on a form. After adding the Button, it needs to be configured:  
  
      @Order(20.0)
+
<source lang="java">
  public class AdministrationButton extends AbstractOutlineButton {
+
@Order(20.0)
    @Override
+
public class AdministrationButton extends AbstractOutlineButton {
    protected String getConfiguredLabel() {
+
  @Override
      return TEXTS.get("AdministrationOutline");
+
  protected String getConfiguredLabel() {
    }
+
    return TEXTS.get("AdministrationOutline");
+
  }
    @Override
+
 
    @ConfigProperty("OUTLINE")
+
  @Override
    @ConfigPropertyValue("null")
+
  protected Class&lt;? extends IOutline&gt; getConfiguredOutline() {
    protected Class&lt;? extends IOutline&gt; getConfiguredOutline() {
+
    return AdministrationOutline.class;
      return AdministrationOutline.class;
+
  }
    }
+
}
  }
+
</source>
  
 
= Using a SnapBox above the TreeView  =
 
= Using a SnapBox above the TreeView  =
Line 51: Line 53:
 
Modify the class org.eclipse.minicrm.client.ui.desktop.'''Desktop''' as follows:  
 
Modify the class org.eclipse.minicrm.client.ui.desktop.'''Desktop''' as follows:  
  
  @Override
+
<source lang="java">
protected void execOpened() throws ProcessingException {
+
@Override
// outline tree
+
protected void execOpened() throws ProcessingException {
if (org.eclipse.scout.rt.shared.ui.UserAgentUtility.isSwtUi()) {
+
// outline tree
  // swt
+
if (org.eclipse.scout.rt.shared.ui.UserAgentUtility.isSwtUi()) {
  ExtendedOutlineTreeForm treeForm = new ExtendedOutlineTreeForm();
+
  // swt
  treeForm.setIconId(Icons.EclipseScout);
+
  ExtendedOutlineTreeForm treeForm = new ExtendedOutlineTreeForm();
  treeForm.startView();
+
  treeForm.setIconId(Icons.EclipseScout);
}
+
  treeForm.startView();
else {
+
}
  // swing
+
else {
  DefaultOutlineTreeForm treeForm = new DefaultOutlineTreeForm();
+
  // swing
  treeForm.setIconId(Icons.EclipseScout);
+
  DefaultOutlineTreeForm treeForm = new DefaultOutlineTreeForm();
  treeForm.startView();
+
  treeForm.setIconId(Icons.EclipseScout);
}
+
  treeForm.startView();
+
}
// leave rest of method unchanged
+
 
// ...
+
// leave rest of method unchanged
}
+
// ...
 +
}
 +
</source>
  
 
Open the source code of '''DefaultOutlineTreeForm''' and save it as org.eclipse.minicrm.client.ui.desktop.'''ExtendedOutlineTreeForm'''. Scroll down to the following part of the code:  
 
Open the source code of '''DefaultOutlineTreeForm''' and save it as org.eclipse.minicrm.client.ui.desktop.'''ExtendedOutlineTreeForm'''. Scroll down to the following part of the code:  
  
    @Order(10.0f)
+
<source lang="java">
public class OutlineTreeField extends AbstractTreeField {
+
@Order(10.0f)
 
+
public class OutlineTreeField extends AbstractTreeField {
 +
</source>
 
and change its order to 20:  
 
and change its order to 20:  
 
+
<source lang="java">
    @Order(20.0)
+
@Order(20.0)
public class OutlineTreeField extends AbstractTreeField {
+
public class OutlineTreeField extends AbstractTreeField {
 
+
</source>
 
then add the following code before the OutlineTreeField:  
 
then add the following code before the OutlineTreeField:  
 +
<source lang="java">
 +
@Order(10.0)
 +
public class OutlineSelectorField extends AbstractSnapBox {
  
    @Order(10.0)
+
  @Override
public class OutlineSelectorField extends AbstractSnapBox {
+
  public int getConfiguredGridH() {
 +
    return 1;
 +
  }
 +
 
 +
  @Override
 +
  protected int getConfiguredGridW() {
 +
    return 1;
 +
  }
 
   
 
   
  @Override
+
  @Override
  public int getConfiguredGridH() {
+
  protected boolean getConfiguredGridUseUiHeight() {
    return 1;
+
    return true;
  }
+
  }
 
   
 
   
  @Override
+
  @Order(10.0)
  protected int getConfiguredGridW() {
+
  public class StandardOutlineButton extends AbstractButton {
    return 1;
+
    @Override
  }
+
    protected String getConfiguredIconId() {
+
      return org.eclipse.minicrm.shared.Icons.Standard;
  @Override
+
    }
  protected boolean getConfiguredGridUseUiHeight() {
+
 
    return true;
+
    @Override
  }
+
    protected String getConfiguredLabel() {
+
      return TEXTS.get("StandardOutline");
  @Order(10.0)
+
    }
  public class StandardOutlineButton extends AbstractButton {
+
 
    @Override
+
    @Override
    protected String getConfiguredIconId() {
+
    protected void execClickAction() throws ProcessingException {
      return org.eclipse.minicrm.shared.Icons.Standard;
+
      changeOutline();
    }
+
    }
+
    @Override
+
    protected String getConfiguredLabel() {
+
      return TEXTS.get("StandardOutline");
+
    }
+
+
    @Override
+
    protected void execClickAction() throws ProcessingException {
+
      changeOutline();
+
    }
+
+
    @Override
+
    protected void execToggleAction(boolean selected) throws ProcessingException {
+
      changeOutline();
+
    }
+
 
   
 
   
    protected void changeOutline() {
+
    @Override
      getDesktop().setOutline(StandardOutline.class);
+
    protected void execToggleAction(boolean selected) throws ProcessingException {
      StandardOutline outline = (StandardOutline) getDesktop().getOutline();
+
      changeOutline();
      CompanyTablePage page = outline.findPage(CompanyTablePage.class);
+
    }
      outline.selectNode(page);
+
 
    }
+
    protected void changeOutline() {
  }
+
      getDesktop().setOutline(StandardOutline.class);
+
      StandardOutline outline = (StandardOutline) getDesktop().getOutline();
  @Order(20.0)
+
      CompanyTablePage page = outline.findPage(CompanyTablePage.class);
  public class AdministrationOutlineButton extends AbstractButton {
+
      outline.selectNode(page);
    @Override
+
    }
    protected String getConfiguredIconId() {
+
  }
      return org.eclipse.minicrm.shared.Icons.Administration;
+
 
    }
+
  @Order(20.0)
    @Override
+
  public class AdministrationOutlineButton extends AbstractButton {
    protected String getConfiguredLabel() {
+
    @Override
      return TEXTS.get("AdministrationOutline");
+
    protected String getConfiguredIconId() {
    }
+
      return org.eclipse.minicrm.shared.Icons.Administration;
+
    }
    @Override
+
    @Override
    protected void execClickAction() throws ProcessingException {
+
    protected String getConfiguredLabel() {
      changeOutline();
+
      return TEXTS.get("AdministrationOutline");
    }
+
    }
+
 
    @Override
+
    @Override
    protected void execToggleAction(boolean selected) throws ProcessingException {
+
    protected void execClickAction() throws ProcessingException {
      changeOutline();
+
      changeOutline();
    }
+
    }
+
 
    protected void changeOutline() {
+
    @Override
      getDesktop().setOutline(AdministrationOutline.class);
+
    protected void execToggleAction(boolean selected) throws ProcessingException {
      AdministrationOutline outline = (AdministrationOutline) getDesktop().getOutline();
+
      changeOutline();
      RoleTablePage page = outline.findPage(RoleTablePage.class);
+
    }
      outline.selectNode(page);
+
 
    }
+
    protected void changeOutline() {
  }
+
      getDesktop().setOutline(AdministrationOutline.class);
}
+
      AdministrationOutline outline = (AdministrationOutline) getDesktop().getOutline();
 +
      RoleTablePage page = outline.findPage(RoleTablePage.class);
 +
      outline.selectNode(page);
 +
    }
 +
  }
 +
}
 +
</source>
  
 
The reason that AbstractButtons are used instead of AbstractOutlineButtons is that the OutlineButtons in the SnapBox don't properly toggle and need clicking on twice to change outlines. Using the normal button and overwriting both the execClickAction as well as the execToggleAction solves this problem.  
 
The reason that AbstractButtons are used instead of AbstractOutlineButtons is that the OutlineButtons in the SnapBox don't properly toggle and need clicking on twice to change outlines. Using the normal button and overwriting both the execClickAction as well as the execToggleAction solves this problem.  
Line 171: Line 177:
 
This is the approach that most closely mirrors the Swing buttons. It, too, requires changes outside the Scout SDK. The following classes need to be modified or added:  
 
This is the approach that most closely mirrors the Swing buttons. It, too, requires changes outside the Scout SDK. The following classes need to be modified or added:  
  
*org.eclipse.minicrm.ui.swt.SwtEnvironment  
+
* org.eclipse.minicrm.ui.swt.SwtEnvironment  
*org.eclipse.minicrm.ui.swt.application.ApplicationWorkbenchWindowAdvisor  
+
* org.eclipse.minicrm.ui.swt.application.ApplicationWorkbenchWindowAdvisor  
*org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor  
+
* org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor  
*org.eclipse.minicrm.ui.swt.application.CoolbarButton
+
* org.eclipse.minicrm.ui.swt.application.CoolbarButton
  
 
The following changes need to be made to each of these classes:  
 
The following changes need to be made to each of these classes:  
Line 183: Line 189:
  
 
Add the following private member:  
 
Add the following private member:  
<pre>public class SwtEnvironment extends AbstractSwtEnvironment {
+
<source lang="java">
  private ApplicationActionBarAdvisor m_advisor;
+
public class SwtEnvironment extends AbstractSwtEnvironment {
</pre>  
+
private ApplicationActionBarAdvisor m_advisor;
 +
</source>  
 
In the constructor add the following line to the second environment listener:  
 
In the constructor add the following line to the second environment listener:  
 
+
<source lang="java">
            m_advisor.initViewButtons(d);
+
m_advisor.initViewButtons(d);
 
+
</source>
 
so that it looks as follows:  
 
so that it looks as follows:  
  
    addEnvironmentListener(new ISwtEnvironmentListener() {
+
<source lang="java">
  @Override
+
addEnvironmentListener(new ISwtEnvironmentListener() {
  public void environmentChanged(SwtEnvironmentEvent e) {
+
  @Override
    if (e.getType() == SwtEnvironmentEvent.STARTED) {
+
  public void environmentChanged(SwtEnvironmentEvent e) {
      removeEnvironmentListener(this);
+
    if (e.getType() == SwtEnvironmentEvent.STARTED) {
      IDesktop d = getClientSession().getDesktop();
+
      removeEnvironmentListener(this);
      if (d&nbsp;!= null) {
+
      IDesktop d = getClientSession().getDesktop();
        setWindowTitle(d.getTitle());
+
      if (d&nbsp;!= null) {
        d.addPropertyChangeListener(IDesktop.PROP_TITLE, new PropertyChangeListener() {
+
        setWindowTitle(d.getTitle());
          @Override
+
        d.addPropertyChangeListener(IDesktop.PROP_TITLE, new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent evt) {
+
          @Override
            setWindowTitle((String) evt.getNewValue());
+
          public void propertyChange(PropertyChangeEvent evt) {
          }
+
            setWindowTitle((String) evt.getNewValue());
        });
+
          }
        m_advisor.initViewButtons(d);
+
        });
      }
+
        m_advisor.initViewButtons(d);
    }
+
      }
  }
+
    }
});
+
  }
 +
});
 +
</source>
  
Add the following method to the class:  
+
Add the following method to the class:
  
  public void setAdvisor(ApplicationActionBarAdvisor advisor) {
+
<source lang="java">
m_advisor = advisor;
+
public void setAdvisor(ApplicationActionBarAdvisor advisor) {
}
+
  m_advisor = advisor;
 +
}
 +
</source>
  
 
<br>  
 
<br>  
Line 223: Line 234:
  
 
Change the following line in '''preWindowOpen()'''  
 
Change the following line in '''preWindowOpen()'''  
<pre> configurer.setShowCoolBar(false);
+
<source lang="java">
</pre>  
+
  configurer.setShowCoolBar(false);
 +
</source>  
 
to  
 
to  
<pre> configurer.setShowCoolBar(true);
+
<source lang="java">
</pre>  
+
  configurer.setShowCoolBar(true);
 +
</source>  
 
<br> '''org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor'''  
 
<br> '''org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor'''  
  
 
Add the following private members:  
 
Add the following private members:  
 
+
<source lang="java">
 
   private static final int NUM_OUTLINE_BUTTONS = 10;
 
   private static final int NUM_OUTLINE_BUTTONS = 10;
private CoolbarButton[] m_coolbarButton = new CoolbarButton[NUM_OUTLINE_BUTTONS];
+
  private CoolbarButton[] m_coolbarButton = new CoolbarButton[NUM_OUTLINE_BUTTONS];
 
+
  private IActionBarConfigurer m_configurer;
 +
</source>
 
The value of '''NUM_OUTLINE_BUTTONS''' must be large enough to contain all Outlines and any ToolButton defined on the desktop as well.  
 
The value of '''NUM_OUTLINE_BUTTONS''' must be large enough to contain all Outlines and any ToolButton defined on the desktop as well.  
  
 
Mofiy the constructor so it looks like this:  
 
Mofiy the constructor so it looks like this:  
 
+
<source lang="java">
 
   public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
 
   public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
super(configurer);
+
  super(configurer);
((SwtEnvironment) Activator.getDefault().getEnvironment()).setAdvisor(this);
+
  this.m_configurer = configurer;
}
+
  ((SwtEnvironment) Activator.getDefault().getEnvironment()).setAdvisor(this);
 +
}
 +
</source>
  
 
Add the following methods:  
 
Add the following methods:  
 +
<source lang="java">
 +
@Override
 +
protected void makeActions(IWorkbenchWindow window) {
 +
  for (int i = 0; i &lt; NUM_OUTLINE_BUTTONS; i++) {
 +
    m_coolbarButton[i] = new CoolbarButton();
 +
  }
 +
}
  
  @Override
+
public void initViewButtons(IDesktop d) {
protected void makeActions(IWorkbenchWindow window) {
+
  IViewButton[] viewButtons = d.getViewButtons();
for (int i = 0; i &lt; NUM_OUTLINE_BUTTONS; i++) {
+
  int start = 0;
  m_coolbarButton[i] = new CoolbarButton();
+
  int end = Math.min(m_coolbarButton.length, viewButtons.length);
}
+
  for (int i = start; i &lt; end; i++) {
}
+
    CoolbarButton b = m_coolbarButton[i];
+
    IViewButton v = viewButtons[i];
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 &lt; end; i++) {
+
  CoolbarButton b = m_coolbarButton[i];
+
  IViewButton v = viewButtons[i];
+
+
  b.setEnabled(v.isEnabled() &amp;&amp; v.isEnabledGranted());
+
  if (v.isVisible() &amp;&amp; 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 &lt; end; i++) {
+
  CoolbarButton b = m_coolbarButton[i];
+
  IToolButton v = toolButtons[i - start];
+
+
  b.setEnabled(v.isEnabled() &amp;&amp; v.isEnabledGranted());
+
  if (v.isVisible() &amp;&amp; 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&nbsp;: m_coolbarButton) {
+
  toolbar.add(a);
+
}
+
}
+
  
 +
    b.setEnabled(v.isEnabled() &amp;&amp; v.isEnabledGranted());
 +
    if (v.isVisible() &amp;&amp; v.isVisibleGranted()) {
 +
      b.init(v);
 +
      register(b);
 +
    }
 +
    else {
 +
      b.setEnabled(false);
 +
    }
 +
 +
    m_configurer.getCoolBarManager().update(true);
 +
  }
 +
 +
  IToolButton[] toolButtons = d.getToolButtons();
 +
  start = end + 1;
 +
  end = Math.min(m_coolbarButton.length, start + toolButtons.length);
 +
  for (int i = start; i &lt; end; i++) {
 +
    CoolbarButton b = m_coolbarButton[i];
 +
    IToolButton v = toolButtons[i - start];
 +
 +
    b.setEnabled(v.isEnabled() &amp;&amp; v.isEnabledGranted());
 +
    if (v.isVisible() &amp;&amp; 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&nbsp;: m_coolbarButton) {
 +
    toolbar.add(a);
 +
  }
 +
}
 +
</source>
 
<br>  
 
<br>  
  
Line 303: Line 321:
  
 
Add this class with the following content:  
 
Add this class with the following content:  
<pre>public class CoolbarButton extends Action {
+
<source lang="java">
 +
public class CoolbarButton extends Action {
 
   private IAction m_button;
 
   private IAction m_button;
  
Line 332: Line 351:
 
   }
 
   }
 
}
 
}
</pre>  
+
</source>  
 
<br>  
 
<br>  
  
Line 341: Line 360:
 
The following configuration with two outlines and one tool button would look as follows in the SWT client:  
 
The following configuration with two outlines and one tool button would look as follows in the SWT client:  
  
[[Image:ToolbarResult.png]]<br>  
+
[[Image:ToolbarResult.png]]<br>
  
 
= Using view specific toolbars  =
 
= Using view specific toolbars  =

Latest revision as of 00:39, 8 November 2013


Scout
Wiki Home
Website
DownloadGit
Community
ForumsBlogTwitterG+
Bugzilla
Bugzilla


While Swing clients automatically show buttons at the top to switch between outlines if theses were added using the Scout SDK, the SWT client lacks this feature. This how-to describes various ways to change outlines in SWT.

Using menus

This method is the most straigth forward. Just add a menu entry for each Outline you want to switch to. Overwriting the getConfiguredIconId(), getConfiguredText() and execAction() methods are sufficient for this:

@Order(10.0)
public class AdministrationOutlineMenu extends AbstractMenu {
 
  @Override
  protected String getConfiguredIconId() {
    return org.eclipse.minicrm.shared.Icons.Administration;
  }
 
  @Override
  protected String getConfiguredText() {
    return TEXTS.get("AdministrationOutline");
  }
 
  @Override
  protected void execAction() throws ProcessingException {
    setOutline(AdministrationOutline.class);
  }
}

Using OutlineButtons on a form

Another option is to place an instance of an AbstractOutlineButton on a form. After adding the Button, it needs to be configured:

@Order(20.0)
public class AdministrationButton extends AbstractOutlineButton {
  @Override
  protected String getConfiguredLabel() {
    return TEXTS.get("AdministrationOutline");
  }
 
  @Override
  protected Class&lt;? extends IOutline&gt; getConfiguredOutline() {
    return AdministrationOutline.class;
  }
}

Using a SnapBox above the TreeView

This method is a little more elaborate and requries code changes beyond the Scout SDK.

Modify the class org.eclipse.minicrm.client.ui.desktop.Desktop as follows:

@Override
protected void execOpened() throws ProcessingException {
// outline tree
if (org.eclipse.scout.rt.shared.ui.UserAgentUtility.isSwtUi()) {
  // swt
  ExtendedOutlineTreeForm treeForm = new ExtendedOutlineTreeForm();
  treeForm.setIconId(Icons.EclipseScout);
  treeForm.startView();
}
else {
  // swing
  DefaultOutlineTreeForm treeForm = new DefaultOutlineTreeForm();
  treeForm.setIconId(Icons.EclipseScout);
  treeForm.startView();
}
 
// leave rest of method unchanged
// ...
}

Open the source code of DefaultOutlineTreeForm and save it as org.eclipse.minicrm.client.ui.desktop.ExtendedOutlineTreeForm. Scroll down to the following part of the code:

@Order(10.0f)
public class OutlineTreeField extends AbstractTreeField {

and change its order to 20:

@Order(20.0)
public class OutlineTreeField extends AbstractTreeField {

then add the following code before the OutlineTreeField:

@Order(10.0)
public class OutlineSelectorField extends AbstractSnapBox {
 
  @Override
  public int getConfiguredGridH() {
    return 1;
  }
 
  @Override
  protected int getConfiguredGridW() {
    return 1;
  }
 
  @Override
  protected boolean getConfiguredGridUseUiHeight() {
    return true;
  }
 
  @Order(10.0)
  public class StandardOutlineButton extends AbstractButton {
    @Override
    protected String getConfiguredIconId() {
      return org.eclipse.minicrm.shared.Icons.Standard;
    }
 
    @Override
    protected String getConfiguredLabel() {
      return TEXTS.get("StandardOutline");
    }
 
    @Override
    protected void execClickAction() throws ProcessingException {
      changeOutline();
    }
 
    @Override
    protected void execToggleAction(boolean selected) throws ProcessingException {
      changeOutline();
    }
 
    protected void changeOutline() {
      getDesktop().setOutline(StandardOutline.class);
      StandardOutline outline = (StandardOutline) getDesktop().getOutline();
      CompanyTablePage page = outline.findPage(CompanyTablePage.class);
      outline.selectNode(page);
    }
  }
 
  @Order(20.0)
  public class AdministrationOutlineButton extends AbstractButton {
    @Override
    protected String getConfiguredIconId() {
      return org.eclipse.minicrm.shared.Icons.Administration;
    }
    @Override
    protected String getConfiguredLabel() {
      return TEXTS.get("AdministrationOutline");
    }
 
    @Override
    protected void execClickAction() throws ProcessingException {
      changeOutline();
    }
 
    @Override
    protected void execToggleAction(boolean selected) throws ProcessingException {
      changeOutline();
    }
 
    protected void changeOutline() {
      getDesktop().setOutline(AdministrationOutline.class);
      AdministrationOutline outline = (AdministrationOutline) getDesktop().getOutline();
      RoleTablePage page = outline.findPage(RoleTablePage.class);
      outline.selectNode(page);
    }
  }
}

The reason that AbstractButtons are used instead of AbstractOutlineButtons is that the OutlineButtons in the SnapBox don't properly toggle and need clicking on twice to change outlines. Using the normal button and overwriting both the execClickAction as well as the execToggleAction solves this problem.

One caveat of this solution is, that buttons in the SnapBox only show an icon, the text is only shown as tooltip.

SnapBoxOutlineButtons.png

Adding a toolbar to the SWT application

This is the approach that most closely mirrors the Swing buttons. It, too, requires changes outside the Scout SDK. The following classes need to be modified or added:

  • org.eclipse.minicrm.ui.swt.SwtEnvironment
  • org.eclipse.minicrm.ui.swt.application.ApplicationWorkbenchWindowAdvisor
  • org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor
  • org.eclipse.minicrm.ui.swt.application.CoolbarButton

The following changes need to be made to each of these classes:


org.eclipse.minicrm.ui.swt.SwtEnvironment

Add the following private member:

public class SwtEnvironment extends AbstractSwtEnvironment {
private ApplicationActionBarAdvisor m_advisor;

In the constructor add the following line to the second environment listener:

m_advisor.initViewButtons(d);

so that it looks as follows:

addEnvironmentListener(new ISwtEnvironmentListener() {
  @Override
  public void environmentChanged(SwtEnvironmentEvent e) {
    if (e.getType() == SwtEnvironmentEvent.STARTED) {
      removeEnvironmentListener(this);
      IDesktop d = getClientSession().getDesktop();
      if (d&nbsp;!= 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 the following method to the class:

public void setAdvisor(ApplicationActionBarAdvisor advisor) {
  m_advisor = advisor;
}


org.eclipse.minicrm.ui.swt.application.ApplicationWorkbenchWindowAdvisor

Change the following line in preWindowOpen()

  configurer.setShowCoolBar(false);

to

  configurer.setShowCoolBar(true);


org.eclipse.minicrm.ui.swt.application.ApplicationActionBarAdvisor

Add the following private members:

  private static final int NUM_OUTLINE_BUTTONS = 10;
  private CoolbarButton[] m_coolbarButton = new CoolbarButton[NUM_OUTLINE_BUTTONS];
  private IActionBarConfigurer m_configurer;

The value of NUM_OUTLINE_BUTTONS must be large enough to contain all Outlines and any ToolButton defined on the desktop as well.

Mofiy the constructor so it looks like this:

  public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
  super(configurer);
  this.m_configurer = configurer;
  ((SwtEnvironment) Activator.getDefault().getEnvironment()).setAdvisor(this);
}

Add the following methods:

@Override
protected void makeActions(IWorkbenchWindow window) {
  for (int i = 0; i &lt; 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 &lt; end; i++) {
    CoolbarButton b = m_coolbarButton[i];
    IViewButton v = viewButtons[i];
 
    b.setEnabled(v.isEnabled() &amp;&amp; v.isEnabledGranted());
    if (v.isVisible() &amp;&amp; v.isVisibleGranted()) {
      b.init(v);
      register(b);
    }
    else {
      b.setEnabled(false);
    }
 
    m_configurer.getCoolBarManager().update(true);
  }
 
  IToolButton[] toolButtons = d.getToolButtons();
  start = end + 1;
  end = Math.min(m_coolbarButton.length, start + toolButtons.length);
  for (int i = start; i &lt; end; i++) {
    CoolbarButton b = m_coolbarButton[i];
    IToolButton v = toolButtons[i - start];
 
    b.setEnabled(v.isEnabled() &amp;&amp; v.isEnabledGranted());
    if (v.isVisible() &amp;&amp; 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&nbsp;: m_coolbarButton) {
    toolbar.add(a);
  }
}


org.eclipse.minicrm.ui.swt.application.CoolbarButton

Add this class with the following content:

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);
  }
}



The advantage of this method is not only that the buttons show both the configured icon and text of the outlines but that it also supports tool buttons added to the desktop by right clicking on the Tools item below the desktop and choosing "New Tool item..."

ToolbarNewTool.png

The following configuration with two outlines and one tool button would look as follows in the SWT client:

ToolbarResult.png

Using view specific toolbars

Have a look at Adding toolbars to views to see how expand and collapse buttons can be added to a toolbar of the OutlineView.

ViewToolbar.png

Back to the top