institution selection can be filtered now, too
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / InstitutionSelectionDialog.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.ui.dialog.selection;
11
12 import java.util.UUID;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Shell;
17 import org.eclipse.swt.widgets.Text;
18
19 import eu.etaxonomy.cdm.api.service.IAgentService;
20 import eu.etaxonomy.cdm.model.agent.AgentBase;
21 import eu.etaxonomy.cdm.model.agent.Institution;
22 import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
23 import eu.etaxonomy.taxeditor.newWizard.NewInstitutionWizard;
24 import eu.etaxonomy.taxeditor.store.CdmStore;
25
26 /**
27 * @author n.hoffmann
28 * @created Dec 15, 2010
29 * @version 1.0
30 */
31 public class InstitutionSelectionDialog extends
32 AbstractFilteredCdmResourceSelectionDialog<Institution> {
33
34 public static Institution select(Shell shell,// ConversationHolder conversation,
35 Institution institution){
36 InstitutionSelectionDialog dialog = new InstitutionSelectionDialog(shell, //conversation,
37 "Choose Institution", false, TeamSelectionDialog.class.getCanonicalName(), institution);
38 return getSelectionFromDialog(dialog);
39 }
40
41 /**
42 * @param shell
43 * @param conversation
44 * @param title
45 * @param multi
46 * @param settings
47 * @param cdmObject
48 */
49 protected InstitutionSelectionDialog(Shell shell,//ConversationHolder conversation,
50 String title, boolean multi,
51 String settings, Institution cdmObject) {
52 super(shell, //conversation,
53 title, multi, settings, cdmObject);
54 }
55
56 /* (non-Javadoc)
57 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
58 */
59 @Override
60 protected Institution getPersistentObject(UUID uuid) {
61 AgentBase agentBase = CdmStore.getService(IAgentService.class).load(uuid);
62
63 if(agentBase instanceof Institution){
64 return (Institution) agentBase;
65 }
66 return null;
67 }
68
69 /* (non-Javadoc)
70 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#search
71 */
72 @Override
73 protected void search() {
74
75 Control control =getSearchField();
76 String pattern = null;
77 if (control != null){
78 pattern = ((Text)control).getText();
79 }
80
81 if (pattern == null || pattern.equals("?")){
82 model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(Institution.class, null, null);
83 }else{
84 model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(Institution.class, limitOfInitialElements,pattern);
85 }
86 try {
87 fillContentProvider(null);
88 } catch (CoreException e) {
89 // TODO Auto-generated catch block
90 e.printStackTrace();
91 }
92 }
93
94 /* (non-Javadoc)
95 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkText()
96 */
97 @Override
98 protected String[] getNewWizardText() {
99 return new String[]{"Institution "};
100 }
101
102 /* (non-Javadoc)
103 * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewEntityWizard(java.lang.String)
104 */
105 @Override
106 protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
107 return new NewInstitutionWizard();
108 }
109
110 }