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

Scout/HowTo/3.7/Extended Search Setup

< Scout‎ | HowTo‎ | 3.7(Redirected from Scout/HowTo/Extended Search Setup)

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:

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

Back to the top