3 * Copyright (C) 2013 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.view
.derivateSearch
;
12 import java
.util
.Arrays
;
13 import java
.util
.LinkedHashMap
;
14 import java
.util
.List
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.commands
.NotEnabledException
;
18 import org
.eclipse
.core
.commands
.NotHandledException
;
19 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
20 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
21 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
22 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
23 import org
.eclipse
.jface
.viewers
.TableViewer
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.events
.KeyAdapter
;
26 import org
.eclipse
.swt
.events
.KeyEvent
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.ui
.handlers
.IHandlerService
;
30 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeCacheStrategy
;
31 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
32 import eu
.etaxonomy
.cdm
.api
.service
.config
.IdentifiableServiceConfiguratorImpl
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
35 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
36 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
37 import eu
.etaxonomy
.taxeditor
.ui
.mvc
.combo
.EnumTermComboController
;
40 * Controller class for the {@link DerivateSearchComposite}.<br>
41 * This controller contains the logic to search the data base for {@link SpecimenOrObservationBase}s
42 * and handles GUI events.
45 public class DerivateSearchCompositeController
{
47 private final DerivateSearchComposite derivateSearchComposite
;
48 private IIdentifiableEntityServiceConfigurator
<SpecimenOrObservationBase
<DerivedUnitFacadeCacheStrategy
>> configurator
;
49 private EnumTermComboController
<SpecimenOrObservationType
> enumTermComboController
;
54 public DerivateSearchCompositeController(Composite parent
) {
55 this.derivateSearchComposite
= new DerivateSearchComposite(parent
, SWT
.NONE
);
60 LinkedHashMap
<SpecimenOrObservationType
, String
> orderedTerms
= AbstractUtility
.orderTerms(Arrays
.asList(SpecimenOrObservationType
.values()));
61 String
[] comboItems
= new String
[orderedTerms
.size()];
63 for(String termMessage
:orderedTerms
.values()){
64 comboItems
[count
] = termMessage
;
68 // derivateSearchComposite.getComboDerivateType().setItems(comboItems);
69 enumTermComboController
= new EnumTermComboController
<SpecimenOrObservationType
>(derivateSearchComposite
.getComboDerivateType(), null, null, SpecimenOrObservationType
.class, 0);
71 derivateSearchComposite
.getSearchField().addKeyListener(new KeyAdapter() {
74 * @see org.eclipse.swt.events.KeyAdapter#keyPressed(org.eclipse.swt.events.KeyEvent)
77 public void keyPressed(KeyEvent e
) {
78 if (e
.keyCode
== SWT
.CR
) {
79 String searchString
= derivateSearchComposite
.getSearchField().getText();
80 searchDerivates(searchString
);
85 TableViewer resultViewer
= derivateSearchComposite
.getResultViewer();
86 resultViewer
.setContentProvider(new ArrayContentProvider());
87 resultViewer
.setLabelProvider(new DerivateLabelProvider());
88 resultViewer
.addDoubleClickListener(new IDoubleClickListener() {
90 public void doubleClick(DoubleClickEvent event
) {
91 String commandId
= "eu.etaxonomy.taxeditor.editor.handler.openDerivateView";
93 IHandlerService handlerService
= (IHandlerService
) AbstractUtility
.getService(IHandlerService
.class);
95 handlerService
.executeCommand(commandId
, null);
96 } catch (ExecutionException e
) {
97 AbstractUtility
.error(DerivateSearchCompositeController
.class, e
);
98 } catch (NotDefinedException e
) {
99 AbstractUtility
.error(DerivateSearchCompositeController
.class, e
);
100 } catch (NotEnabledException e
) {
101 AbstractUtility
.error(DerivateSearchCompositeController
.class, e
);
102 } catch (NotHandledException e
) {
103 AbstractUtility
.error(DerivateSearchCompositeController
.class, e
);
108 configurator
= new IdentifiableServiceConfiguratorImpl
<SpecimenOrObservationBase
<DerivedUnitFacadeCacheStrategy
>>();
112 private void searchDerivates(String searchString
){
113 configurator
.setTitleSearchString(searchString
);
114 List
<SpecimenOrObservationBase
> results
= CdmStore
.getSearchManager().findOccurrences(configurator
, true);
115 derivateSearchComposite
.getResultViewer().setInput(results
);
120 * @return the derivateSearchComposite
122 public DerivateSearchComposite
getDerivateSearchComposite() {
123 return derivateSearchComposite
;
126 private void setEnable(boolean enabled
){
127 derivateSearchComposite
.setEnabled(enabled
);
128 derivateSearchComposite
.getResultViewer().getTable().setEnabled(enabled
);
129 derivateSearchComposite
.getSearchField().setEnabled(enabled
);