Merge branch 'release/5.10.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / dialog / selection / AgentSelectionDialog.java
index 748929b4d7cdbbd5ae18c128c2061fa8b07fef44..a9cc19997624da805694ab79c77623f899d41130 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
 * Copyright (C) 2007 EDIT
 * European Distributed Institute of Taxonomy
@@ -14,11 +13,8 @@ import java.util.UUID;
 
 import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
 
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.service.IAgentService;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
@@ -35,17 +31,19 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created Sep 10, 2009
  * @version 1.0
  */
-public class AgentSelectionDialog extends
-               AbstractFilteredCdmResourceSelectionDialog<AgentBase> {
+public class AgentSelectionDialog<T extends AgentBase> extends
+               AbstractFilteredCdmResourceSelectionDialog {
 
        /**
         *
         */
-       protected static final String PERSON = "Person";
+       protected static final String PERSON = "New Person";
        /**
         *
         */
-       protected static final String TEAM = "Team";
+       protected static final String TEAM = "New Team";
+
+       protected static boolean selectTeamMember;
 
        /**
         * <p>select</p>
@@ -55,10 +53,11 @@ public class AgentSelectionDialog extends
         * @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) {
-               AgentSelectionDialog dialog = new AgentSelectionDialog(shell, conversation,
-                               "Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity);
-               return getSelectionFromDialog(dialog);
+       public static AgentBase select(Shell shell, //ConversationHolder conversation,
+               AgentBase entity, boolean selectTeamMember) {
+               AgentSelectionDialog dialog = new AgentSelectionDialog(shell, //conversation,
+                               "Choose Agent", false, AgentSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
+               return (AgentBase) getSelectionFromDialog(dialog);
        }
 
        /**
@@ -71,8 +70,11 @@ public class AgentSelectionDialog extends
         * @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) {
-               super(shell, conversation, title, multi, settings, agent);
+       protected AgentSelectionDialog(Shell shell, //ConversationHolder conversation,
+               String title, boolean multi, String settings, AgentBase agent, boolean selectTeamMember) {
+               super(shell, //conversation,
+                       title, multi, settings, agent);
+               this.selectTeamMember = selectTeamMember;
        }
 
 
@@ -87,7 +89,7 @@ public class AgentSelectionDialog extends
                 */
                @Override
         public String getText(Object element) {
-                       AgentBase agent = getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
+                   AgentBase agent = (AgentBase) getCdmObjectByUuid(((UuidAndTitleCache<AgentBase>) element).getUuid());
                        if (agent instanceof INomenclaturalAuthor) {
                                return "Nomenclatural title: '" + ((INomenclaturalAuthor) agent).getNomenclaturalTitle() + "'";
                        } else {
@@ -121,30 +123,46 @@ public class AgentSelectionDialog extends
 
        /** {@inheritDoc} */
        @Override
-       protected String getNewWizardLinkText() {
-               return String.format("Create a new <a>%1s</a> or <a>%2s</a>", TEAM, PERSON);
+       protected String[] getNewWizardText() {
+           String[] result;
+               if (this.selectTeamMember){
+                   result = new String[1];
+                   result[0] = PERSON;
+
+               }else{
+                   result = new String[2];
+            result[0] = PERSON;
+            result[1] = TEAM;
+               }
+               return result;
        }
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.taxeditor.dialogs.filteredSelection.AbstractFilteredCdmResourceSelectionDialog#getNewWizardLinkSelectionListener()
         */
        @Override
-       protected SelectionListener getNewWizardLinkSelectionListener() {
-               return super.getNewWizardLinkSelectionListener();
+       protected SelectionListener getNewWizardButtonSelectionListener() {
+               return super.getNewWizardButtonSelectionListener();
        }
 
-       /** {@inheritDoc} */
-       @Override
-       protected void initModel() {
-           Control control = getPatternControl();
-        String pattern = null;
-        if (control != null){
-            pattern = ((Text)control).getText();
-        }
-
-
-               model = CdmStore.getService(IAgentService.class).getUuidAndTitleCache(limitOfInitialElements, pattern);
-       }
+//     /** {@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);
+    }
 
 
 }