3 * Copyright (C) 2016 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
.ui
.dialog
.selection
;
14 import org
.eclipse
.core
.runtime
.Assert
;
15 import org
.eclipse
.core
.runtime
.ListenerList
;
16 import org
.eclipse
.jface
.viewers
.IColorProvider
;
17 import org
.eclipse
.jface
.viewers
.IFontProvider
;
18 import org
.eclipse
.jface
.viewers
.ILabelDecorator
;
19 import org
.eclipse
.jface
.viewers
.ILabelProvider
;
20 import org
.eclipse
.jface
.viewers
.ILabelProviderListener
;
21 import org
.eclipse
.jface
.viewers
.LabelProvider
;
22 import org
.eclipse
.jface
.viewers
.LabelProviderChangedEvent
;
23 import org
.eclipse
.jface
.viewers
.StyledCellLabelProvider
;
24 import org
.eclipse
.jface
.viewers
.StyledString
;
25 import org
.eclipse
.jface
.viewers
.ViewerCell
;
26 import org
.eclipse
.jface
.viewers
.DelegatingStyledCellLabelProvider
.IStyledLabelProvider
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.graphics
.Color
;
29 import org
.eclipse
.swt
.graphics
.Font
;
30 import org
.eclipse
.swt
.graphics
.GC
;
31 import org
.eclipse
.swt
.graphics
.Image
;
32 import org
.eclipse
.swt
.graphics
.Rectangle
;
33 import org
.eclipse
.swt
.widgets
.Control
;
34 import org
.eclipse
.swt
.widgets
.Display
;
35 import org
.eclipse
.swt
.widgets
.Shell
;
36 import org
.eclipse
.swt
.widgets
.Text
;
37 import org
.eclipse
.ui
.internal
.IWorkbenchGraphicConstants
;
38 import org
.eclipse
.ui
.internal
.WorkbenchImages
;
40 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
41 import eu
.etaxonomy
.cdm
.api
.service
.IAgentService
;
42 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
43 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
44 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
45 import eu
.etaxonomy
.taxeditor
.newWizard
.AbstractNewEntityWizard
;
46 import eu
.etaxonomy
.taxeditor
.newWizard
.NewPersonWizard
;
47 import eu
.etaxonomy
.taxeditor
.newWizard
.NewTeamWizard
;
48 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
49 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
50 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
51 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.AbstractFilteredCdmResourceSelectionDialog
.FilteredCdmResourceLabelProvider
;
52 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.CdmFilteredItemsSelectionDialog
.ItemsListSeparator
;
59 public class NomenclaturalAuthorSelectionDialog
extends AgentSelectionDialog
{
70 protected NomenclaturalAuthorSelectionDialog(Shell shell
, ConversationHolder conversation
, String title
,
71 boolean multi
, String settings
, AgentBase agent
, boolean teamMemberSelection
) {
72 super(shell
, conversation
, title
, multi
, settings
, agent
, teamMemberSelection
);
73 // TODO Auto-generated constructor stub
77 protected void initModel() {
78 Control control
= getPatternControl();
79 String pattern
= null;
81 pattern
= ((Text
)control
).getText();
84 model
= CdmStore
.getService(IAgentService
.class).getUuidAndAbbrevTitleCache(limitOfInitialElements
, pattern
, null);
89 protected AbstractNewEntityWizard
getNewEntityWizard(String parameter
) {
90 if(TEAM
.equals(parameter
)){
91 return new NewTeamWizard(true);
93 else if(PERSON
.equals(parameter
)){
94 return new NewPersonWizard();
97 throw new IllegalArgumentException("Could not determine the desired wizard.");
105 protected ILabelProvider
createListLabelProvider() {
106 return new FilteredCdmResourceAbbrevLabelProvider();
112 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
113 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
114 * @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
115 * @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
117 public static AgentBase
select(Shell shell
, ConversationHolder conversation
, AgentBase entity
, boolean teamMemberSelection
) {
118 NomenclaturalAuthorSelectionDialog dialog
= new NomenclaturalAuthorSelectionDialog(shell
, conversation
,
119 "Choose Agent", false, NomenclaturalAuthorSelectionDialog
.class.getCanonicalName(), entity
, teamMemberSelection
);
120 return getSelectionFromDialog(dialog
);
126 * @param cdmObject a T object.
127 * @return a {@link java.lang.String} object.
130 protected String
getTitle(AgentBase cdmObject
) {
131 if(cdmObject
== null){
135 if (cdmObject
instanceof TeamOrPersonBase
) {
136 return ((TeamOrPersonBase
) cdmObject
).getNomenclaturalTitle();
137 } else if (cdmObject
instanceof AgentBase
){
138 return ((TeamOrPersonBase
) cdmObject
).getTitleCache();
141 throw new IllegalArgumentException("Generic method only" +
142 " supports cdmObject of type IIdentifiableEntity." +
143 " Please implement specific method in subclass.");
148 public class FilteredCdmResourceAbbrevLabelProvider
extends LabelProvider
{
150 public String
getText(Object element
) {
151 if (element
== null) {
154 UuidAndTitleCache uuidAndTitleCache
= (UuidAndTitleCache
) element
;
155 String titleCache
= uuidAndTitleCache
.getTitleCache();
156 String abbrevTitleCache
= uuidAndTitleCache
.getAbbrevTitleCache();
157 abbrevTitleCache
+= " - " + titleCache
;
158 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG
)){
159 abbrevTitleCache
+= " ["+uuidAndTitleCache
.getId()+"]";
161 return abbrevTitleCache
;