Difference between revisions of "Scout/HowTo/3.7/Extended Search Setup"
(Code example) |
|||
(7 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{ScoutPage|cat=HowTo 3.7}} | ||
+ | |||
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: | 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: | ||
Latest revision as of 05:26, 4 May 2012
Scout |
Wiki Home |
Website |
Download • Git |
Community |
Forums • Blog • Twitter • G+ |
Bugzilla |
Bugzilla |
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
- doesn’t have Activity with
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(); } }