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/HowTo/4.0/Extended Search Setup"

< Scout‎ | HowTo‎ | 4.0
m
(Replaced content with "The Scout documentation has been moved to https://eclipsescout.github.io/.")
 
Line 1: Line 1:
{{ScoutPage|cat=HowTo 4.0}}
+
The Scout documentation has been moved to https://eclipsescout.github.io/.
 
+
For a client we were writing a wizard that would allow users to specify a year, click next, and then select a few projects from a list. We had specified the following:
+
 
+
: The user is presented with the project search dialog. By default, only international agreements with status Contract – In Force and without appendix are shown. The user selects some of these (multiselect is possible) and clicks the Next button. A new search replaces the default search criterion described below. The user cannot leave this step, if he chooses a contract without valid yearly data.
+
 
+
: '''Without appendix''': This results in the following special search criterion:
+
* Find project
+
** doesn’t have Activity with
+
*** Start date >= Jan 1, YYYY
+
*** and Start date <= Dec 31, YYYY
+
*** and Activity type is Appendix
+
 
+
The problem we faced was how to add this special search. Here's some code:
+
 
+
<pre>
+
  @Order(10.0f)
+
  public class ChooseHandler extends AbstractFormHandler{
+
 
+
    private void setUpSearch(ProjectSearchForm searchForm){
+
      ComposerField composer = searchForm.getComposerField();
+
      ContactEntity contact = composer.new ContactEntity();
+
      ITreeNode contactNode = composer.addEntityNode(
+
          composer.getTree().getRootNode(),
+
          contact,
+
          true,
+
          new HashMap<String,Object>(),
+
          "doesn't have an activity");
+
      composer.addAttributeNode(
+
          contactNode,
+
          contact.new ContactTypeAttribute(),
+
          new ComposerOp.EQ(),
+
          ContactTypeCodeType.AppendixCode.ID,
+
          TEXTS.get("Appendix"));
+
      DateFormat formatter = new SimpleDateFormat();
+
      Calendar c = Calendar.getInstance();
+
      c.set(getYear(), 0, 1, 0, 0, 0); // first second of the year
+
      composer.addAttributeNode(
+
          contactNode,
+
          contact.new StartDateAttribute(),
+
          new ComposerOp.GE(),
+
          c.getTime(),
+
          formatter.format(c.getTime()));
+
      c.set(getYear() + 1, 0, 1, 0, 0, 0); // first second of the next year
+
      composer.addAttributeNode(
+
          contactNode,
+
          contact.new StartDateAttribute(),
+
          new ComposerOp.LT(),
+
          c.getTime(),
+
          formatter.format(c.getTime()));
+
      searchForm.getProjectTypeField().setValue(new Long[]{ProjectTypeCodeType.InternationalAgreementCode.ID});
+
      searchForm.getProjectStatusField().setValue(new Long[]{ProjectStatusCodeType.ContractInActionCode.ID});
+
    }
+
 
+
    @Override
+
    public void execStore() throws ProcessingException{
+
      setProjectNr(getProjectTablePageField().getPage().getTable().getProjectNrColumn().getSelectedValues());
+
      if(getProjectNr()==null){
+
        throw new VetoException(TEXTS.get("PleaseChooseProject"));
+
      }
+
    }
+
 
+
    @Override
+
    public void execLoad() throws ProcessingException{
+
      ProjectSearchForm searchForm=(ProjectSearchForm)getProjectTablePageField().getSearchFormField().getInnerForm();
+
      setUpSearch(searchForm);
+
      searchForm.doSave();
+
    }
+
  }
+
</pre>
+

Latest revision as of 07:35, 18 March 2024

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

Back to the top