* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-
package eu.etaxonomy.taxeditor.ui.dialog.selection;
+import java.util.List;
import java.util.UUID;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.cdm.api.service.IAgentService;
+import eu.etaxonomy.cdm.api.service.dto.EntityDTOBase;
+import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
import eu.etaxonomy.cdm.model.agent.AgentBase;
import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache;
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
import eu.etaxonomy.taxeditor.newWizard.NewPersonWizard;
import eu.etaxonomy.taxeditor.newWizard.NewTeamWizard;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
- * <p>FilteredAgentSelectionDialog class.</p>
+ * FilteredAgentSelectionDialog class.
*
* @author n.hoffmann
* @created Sep 10, 2009
- * @version 1.0
*/
-public class AgentSelectionDialog<T extends AgentBase> extends
- AbstractFilteredCdmResourceSelectionDialog {
+public class AgentSelectionDialog<T extends AgentBase>
+ extends AbstractFilteredCdmResourceSelectionDialog<T> {
- /**
- *
- */
protected static final String PERSON = "New Person";
- /**
- *
- */
protected static final String TEAM = "New Team";
protected static boolean selectTeamMember;
/**
- * <p>select</p>
+ * select
*
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
* @param entity a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
* @return a {@link eu.etaxonomy.cdm.model.agent.AgentBase} object.
*/
- public static AgentBase select(Shell shell, //ConversationHolder conversation,
- AgentBase entity, boolean selectTeamMember) {
- AgentSelectionDialog dialog = new AgentSelectionDialog(shell, //conversation,
+ public static <S extends AgentBase> S select(Shell shell,
+ S entity, boolean selectTeamMember) {
+ AgentSelectionDialog<S> dialog = new AgentSelectionDialog<>(shell,
"Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
- return (AgentBase) getSelectionFromDialog(dialog);
+ return getSelectionFromDialog(dialog);
}
/**
* @param multi a boolean.
* @param settings a {@link java.lang.String} object.
*/
- protected AgentSelectionDialog(Shell shell, //ConversationHolder conversation,
- String title, boolean multi, String settings, AgentBase agent, boolean selectTeamMember) {
- super(shell, //conversation,
- title, multi, settings, agent);
+ protected AgentSelectionDialog(Shell shell,
+ String title, boolean multi, String settings, T agent, boolean selectTeamMember) {
+ super(shell, title, multi, settings, agent);
this.selectTeamMember = selectTeamMember;
}
-
- /**
- * @author p.ciardelli
- * @created 18.09.2009
- * @version 1.0
- */
public class DetailsLabelProvider extends LabelProvider {
- /* (non-Javadoc)
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- */
@Override
public String getText(Object element) {
- AgentBase agent = (AgentBase) getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
+ T agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
if (agent instanceof INomenclaturalAuthor) {
- return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'";
+ return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitleCache() + "'";
} else {
return "'" + agent.getTitleCache() + "' is not a nomenclatural author.";
}
}
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObect(java.util.UUID)
- */
- /** {@inheritDoc} */
+
+
@Override
- protected AgentBase getPersistentObject(UUID cdmUuid) {
- return CdmStore.getService(IAgentService.class).load(cdmUuid);
+ protected T getPersistentObject(UUID cdmUuid) {
+ return (T)CdmStore.getService(IAgentService.class).load(cdmUuid);
}
- /** {@inheritDoc} */
@Override
protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
if(TEAM.equals(parameter)){
}
}
- /** {@inheritDoc} */
@Override
protected String[] getNewWizardText() {
String[] result;
if (this.selectTeamMember){
result = new String[1];
result[0] = PERSON;
-
}else{
result = new String[2];
result[0] = PERSON;
return result;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
- */
@Override
protected SelectionListener getNewWizardButtonSelectionListener() {
return super.getNewWizardButtonSelectionListener();
}
-// /** {@inheritDoc} */
-// @Override
-// protected void search() {
-// Control control = getSearchField();
-// String pattern = null;
-// if (control != null){
-// pattern = ((Text)control).getText();
-// }
-//
-// }
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog#callService(java.lang.String)
- */
@Override
- void callService(String pattern) {
- model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
+ protected void callService(String pattern) {
+ Class<T> clazz = (Class)AgentBase.class;
+ if (selectTeamMember){
+ clazz = (Class)Person.class;
+ }
+
+ model = (List)CdmStore.getService(IAgentService.class).getTeamOrPersonUuidAndTitleCache(clazz, limitOfInitialElements, pattern);
+ }
+ @Override
+ protected ILabelProvider createListLabelProvider() {
+ return new CollectorLabelProvider();
+ }
+
+ public class CollectorLabelProvider extends LabelProvider {
+ @Override
+ public String getText(Object element) {
+ if (element == null) {
+ return null;
+ }
+ UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
+ String titleCache = uuidAndTitleCache.getTitleCache();
+ String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
+ String collectorTitleCache = null;
+ if (element instanceof TeamOrPersonUuidAndTitleCache){
+ collectorTitleCache = ((TeamOrPersonUuidAndTitleCache)element).getCollectorTitleCache();
+ }
+ if (!titleCache.equals(abbrevTitleCache)){
+ titleCache += " - " + abbrevTitleCache;
+ }
+ if (collectorTitleCache != null && !uuidAndTitleCache.getTitleCache().equals(collectorTitleCache) && !abbrevTitleCache.equals(collectorTitleCache)){
+ titleCache += " - " + collectorTitleCache;
+ }
+ if(PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSelectionDialog.getKey())){
+ titleCache += " ["+uuidAndTitleCache.getId()+"]";
+ }
+ if (element instanceof EntityDTOBase){
+ titleCache += "(" + ((IdentifiedEntityDTO)element).getIdentifier().getTypeLabel() +": " + ((IdentifiedEntityDTO)element).getIdentifier().getIdentifier() + ")";
+ }
+
+ return titleCache;
+ }
+
+
}
-}
+}
\ No newline at end of file