Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Scout/Concepts/TreeBox"

(Added detailed descriptions on how to use TreeBox)
(Replaced content with "The Scout documentation has been moved to https://eclipsescout.github.io/.")
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{ScoutPage|cat=Component Model}}
+
The Scout documentation has been moved to https://eclipsescout.github.io/.
 
+
{{ScoutLink|Concepts|ValueField|Value field}} to propose multiple choices (hierarchical).
+
 
+
*implements: {{ScoutJavadoc|ITreeBox<T>|I}}
+
*extends: {{ScoutJavadoc|AbstractTreeBox<T>|C}}
+
 
+
== Description  ==
+
 
+
{{note|TODO|Add a description}}
+
 
+
*Value is stored in a Array: <code>T[]</code> <br>It cointains the keys, whose entries were checked by the user. If no entry was checked, the value will be null.
+
*Like a {{ScoutLink|Concepts|SmartField|Smart field}} but for multiple Values. Differ from a {{ScoutLink|Concepts|ListBox|ListBox}} because it is hierarchical.
+
*Use a {{ScoutLink|Concepts|CodeType|CodeType}} or a {{ScoutLink|Concepts|LookupCall|LookupCall}}
+
 
+
<br>
+
 
+
== Screenshot  ==
+
 
+
{|
+
|-
+
! RAP
+
! SWT
+
! Swing
+
! Swing Rayo
+
|-
+
| [[Image:Scout 3.8 TreeBox RAP.png]]
+
| [[Image:Scout 3.8 TreeBox SWT.png]]
+
| [[Image:Scout 3.8 TreeBox Swing.png]]
+
| [[Image:Scout 3.8 TreeBox Swing Rayo.png]]
+
|}
+
 
+
== Properties  ==
+
 
+
''Defined with {{ScoutLink|Concepts|GetConfigured Methods|getConfiguredXxxxxx()}} methods''.
+
 
+
See also the {{ScoutLink|Concepts|Field|Field}} and the {{ScoutLink|Concepts|ValueField|Value field}} pages for the properties that all fields have in common.
+
 
+
<br>
+
 
+
'''getConfiguredLookupCall()'''<br>
+
 
+
The fields of a TreeBox are populated through the use of a <code>LookupCall</code>:
+
 
+
@Override
+
protected Class&lt;? extends LookupCall&gt; getConfiguredLookupCall() {
+
return MyLookupCall.class;
+
}
+
 
+
That lookup call in turn uses a lookup service:
+
<pre>public class MyLookupCall extends LookupCall{
+
  private static final long serialVersionUID = 1L;
+
  @Override
+
  protected Class&lt;? extends ILookupService&gt; getConfiguredService() {
+
    return IMyLookupService.class;
+
  }
+
}
+
</pre>
+
The lookup service on the server uses an SQL query to return the content for those fields (see below).
+
 
+
<br>
+
 
+
'''getConfiguredAutoExpandAll()''' <br>
+
 
+
By default the TreeBoxField shows a collapsed tree if not all elements of the tree can be shown in the field at the current size. This can be changed to always expand the tree by setting the <code>AutoExpandAll</code> property to true
+
 
+
@Override
+
protected boolean getConfiguredAutoExpandAll() {
+
return true;
+
}
+
 
+
<br>
+
 
+
== Events  ==
+
 
+
''Defined with {{ScoutLink|Concepts|Exec_Methods|execXxxxxx()}} methods''.
+
 
+
See also the {{ScoutLink|Concepts|Field|Field}} and the {{ScoutLink|Concepts|ValueField|Value field}} pages for the events that all fields have in common.
+
 
+
<br>
+
 
+
'''execFilterLookupResult()'''<br>
+
 
+
By default the entries in the list and tree are sorted by the <code>text</code> attribute (i.e. the visible text), not the <code>key</code>. This can be changed by defining a filtering function:
+
 
+
@Override
+
protected void execFilterLookupResult(LookupCall call, List&lt;LookupRow&gt; result) throws ProcessingException {
+
java.util.Collections.sort(result, new MyLookupRowComparator());
+
}
+
 
+
This filter function requires a comparator class which implements <code>Comparator&lt;LookupRow&gt;</code>:
+
<pre>public class MyRowComparator implements Comparator&lt;LookupRow&gt; {
+
  @Override
+
  public int compare(LookupRow object1, LookupRow object2) {
+
    if (object1 == null) return -1;
+
    if (object2 == null) return 1;
+
    // sort on 'text' (default behaviour)
+
    //return object1.getText().compareTo(object2.getText());
+
 
+
    // sort on 'key'
+
    return ((Long) object1.getKey()).compareTo((Long) object2.getKey());
+
  }
+
}
+
</pre>
+
<br>
+
 
+
== LookupService<br>  ==
+
 
+
The [[Scout/Tutorial/3.8/Minicrm/Lookup Calls and Lookup Services|MiniCRM tutorial]] describes how to use a lookup service to populate SmartFields (e.g. dropdown boxes).<br>
+
 
+
Populating TreeBoxFields and ListBoxFields require more fields to be returned.<br>
+
 
+
The LookupService has a '''getConfiguredSqlSelect()''' method which returns a number of fields. The first two attributes (<code>key</code> and <code>text</code>) are compulsory, any of the other attributes are optional (and can be skipped by returning null or an empty string; if all remaining fields would be skipped, the query can just end early). The attributes are returned in the following order:  
+
<pre>  @Override
+
  protected String getConfiguredSqlSelect() {
+
    return "" +
+
        "SELECT " +
+
        "  C.COMPANY_NR, " +                    // key
+
        "  C.SHORT_NAME || ': ' || C.NAME, " +  // text
+
        "  C.LOGO, " +                          // iconId
+
        "  C.TOOLTIP, " +                        // tooltip
+
        "  'F0F0F0', " +                        // background
+
        "  '404040', " +                        // foreground
+
        "  '" + Font.SERIF + "', " +            // font: not yet clear how this works
+
        "  1, "+                                // enabled
+
        "  null, "+                              // parent
+
        "  1 "+                                  // active
+
        "FROM COMPANY C " +
+
        "WHERE 1=1 " +
+
        "AND (C.TYPE_UID =&nbsp;:master OR&nbsp;:master IS NULL) " +
+
        "    AND C.COMPANY_NR =&nbsp;:key  " +
+
        "    AND ((UPPER(C.NAME) LIKE '%'|| UPPER(:text)||'%') OR (UPPER(C.SHORT_NAME) LIKE '%'||UPPER(:text)||'%')) " +
+
        "      ";
+
  }</pre>
+
In principle a LookupService can be used for SmartFields, TreeBoxFields and ListBoxFields, however not all attributes are used for all fields (and behaviour between Swing and SWT differs for some of them).
+
 
+
The attributes have the following functions:
+
 
+
*<code>key</code><br>This is the value which will be returned in the array T[]<br>
+
*<code>text</code><br>This is the text being displayed<br>
+
*<code>iconId</code><br>This is an icon id that needs to be resolvable using an IconProviderService/IconLocator. With TreeBoxFields and ListBoxFields the icon will only be shown for Swing but not SWT<br>
+
*<code>tooltip</code><br>The tooltip text will be shown when hovering over the entry with the mouse.<br>
+
*<code>background</code><br>The background colour used for this entry ("RRGGBB" in hex)<br>
+
*<code>foreground</code><br>The foreground colour used for this entry ("RRGGBB" in hex)<br>
+
*<code>font</code><br>The font to be used (TODO: needs more information on how to use this)<br>
+
*<code>enabled</code><br>TODO: needs more information on the difference between enabled and active<br>
+
*<code>parent</code><br>A reference to the key attribute of another entry and is used to build the hierarchy of elements<br>
+
*<code>active</code><br>TODO: needs more information on the difference between enabled and active<br>
+
{{Note|TODO|Update description for <code>font</code>, <code>enabled</code> and <code>active</code>}}
+
<br>
+
 
+
== See Also  ==
+
 
+
*{{ScoutLink|Concepts|SmartField|Smart field}}
+
*{{ScoutLink|Concepts|ValueField|Value field}}
+
*{{ScoutLink|Concepts|Field|Field}}
+
*{{ScoutLink|Concepts|Form|Form}}
+
 
+
<br>
+

Latest revision as of 05:00, 14 March 2024

The Scout documentation has been moved to https://eclipsescout.github.io/.

Back to the top