Fixes a couple of problems with user and group selection dialogs.
authorn.hoffmann <n.hoffmann@localhost>
Tue, 7 Jun 2011 09:32:29 +0000 (09:32 +0000)
committern.hoffmann <n.hoffmann@localhost>
Tue, 7 Jun 2011 09:32:29 +0000 (09:32 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialogs/filteredSelection/AbstractFilteredCdmResourceSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialogs/filteredSelection/GroupSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialogs/filteredSelection/UserSelectionDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/group/MemberDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/EditFromSelectionWizard.java

index ac6059f555b778e04fe7358dff84ef4a5fc917b7..0525acbbd6cdb37a84a69d0d2bd0f31dce3fe086 100644 (file)
@@ -11,7 +11,6 @@
 package eu.etaxonomy.taxeditor.ui.dialogs.filteredSelection;
 
 import java.lang.reflect.Field;
-import java.security.acl.LastOwnerException;
 import java.text.Collator;
 import java.util.Comparator;
 import java.util.HashSet;
@@ -30,7 +29,6 @@ import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.window.Window;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
@@ -92,17 +90,36 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmB
                
                initModel();
                
-               if (cdmObject != null) {
-                       setInitialPattern(getTitle(cdmObject));
+               String objectTitle = getTitle(cdmObject);
+               if (objectTitle != null) {
+                       setInitialPattern(objectTitle);
                }
                
-               ILabelProvider labelProvider = new FilteredCdmResourceLabelProvider();
-               setListLabelProvider(labelProvider);
-               setDetailsLabelProvider(labelProvider);
+               setListLabelProvider(createListLabelProvider());
+               setDetailsLabelProvider(createDetailsLabelProvider());
                
                setSelectionHistory(new ResourceSelectionHistory());
        }
        
+       /**
+        * By default, we are returning the standard list label provider
+        * 
+        * Override in subclasses if you want different behavior 
+        * 
+        * @return
+        */
+       protected ILabelProvider createDetailsLabelProvider() {
+               return createListLabelProvider();
+       }
+
+       /**
+        * 
+        * @return
+        */
+       protected ILabelProvider createListLabelProvider() {
+               return new FilteredCdmResourceLabelProvider();
+       }
+
        /**
         * Override in subclasses.
         * Will run before initModel()
@@ -185,7 +202,9 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmB
                if (cdmObject instanceof IIdentifiableEntity) {
                        return ((IIdentifiableEntity) cdmObject).getTitleCache();                       
                }
-               return null;
+               throw new IllegalArgumentException("Generic method only" +
+                               " supports cdmObject of type IIdentifiableEntity." +
+                               " Please implement specific method in subclass.");
        }
        
 
@@ -266,7 +285,8 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmB
                // this also is not the nicest way to do it. 
                // I am still amazed, that FilteredSelectionDialog does not offer any methods to change its data
                // once it was opened. Am I doing it wrong?
-               ((Text) getPatternControl()).setText(getTitle(cdmObject));
+               String pattern = getTitle(cdmObject);
+               ((Text) getPatternControl()).setText(pattern);
        }
        
        /* (non-Javadoc)
index 9931c5b580eb83602ea908a3c362d80d7d557e0a..1042a648402dc8cff3a1f8339c6b7cd0e38deaab 100644 (file)
@@ -89,5 +89,10 @@ public class GroupSelectionDialog extends
        protected Group getPersistentObject(UUID uuid) {
                return CdmStore.getService(IGroupService.class).load(uuid);
        }
+       
+       @Override
+       protected String getTitle(Group group) {
+               return group != null ? group.getName() : "";
+       }
 
 }
index 331d6b3fefb338afa9f5dc87aba662da90875d2c..41dabb8e9f3cac94cc4fc51f008804df721b0c89 100644 (file)
@@ -96,4 +96,9 @@ public class UserSelectionDialog extends
                return CdmStore.getService(IUserService.class).load(uuid);
        }
 
+       @Override
+       protected String getTitle(User user) {
+               return user != null ? user.getUsername() : "";
+       }
+       
 }
index 15661f9aff57a182e6a0bd5aa8829f944e8ac272..612458e1edea6d286a3a68f1aeef15d0fec47e5c 100644 (file)
@@ -66,7 +66,7 @@ public class MemberDetailElement extends AbstractEntityCollectionElement<User> {
                selection_user = (UserSelectionElement) formFactory
                                .createSelectionElement(SelectionType.USER,
                                                getConversationHolder(), element, "Member", entity,
-                                               UserSelectionElement.DEFAULT, style);
+                                               UserSelectionElement.EDITABLE, style);
        }
 
        /*
index b470254f0e25550f5ff0dc0ce63448e360c67a85..c0f2985638ba084484f02f4bebbc4bfe4f89f221 100644 (file)
@@ -22,7 +22,8 @@ import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.Institution;
 import eu.etaxonomy.cdm.model.agent.Person;
 import eu.etaxonomy.cdm.model.agent.Team;
-import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
+import eu.etaxonomy.cdm.model.common.ICdmBase;
+import eu.etaxonomy.cdm.model.common.User;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.occurrence.Collection;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
@@ -40,6 +41,7 @@ import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralWizardPage;
 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceWizardPage;
+import eu.etaxonomy.taxeditor.ui.section.user.UserDetailWizardPage;
 
 /**
  * <p>
@@ -75,7 +77,7 @@ public class EditFromSelectionWizard extends Wizard implements
        public void addPages() {
 
                CdmFormFactory formFactory = selectionElement.getFormFactory();
-               IdentifiableEntity entity = (IdentifiableEntity) HibernateProxyHelper
+               ICdmBase entity = (ICdmBase) HibernateProxyHelper
                                .deproxy(selectionElement.getEntity());
 
                if (entity instanceof Reference) {
@@ -120,10 +122,14 @@ public class EditFromSelectionWizard extends Wizard implements
                        addPage(new InstitutionWizardPage(formFactory,
                                        selectionElement.getConversationHolder(),
                                        (Institution) entity));
+               } else if (entity instanceof User) {
+                       addPage(new UserDetailWizardPage(formFactory, 
+                                       selectionElement.getConversationHolder(), 
+                                       (User) entity));
                } else {
                        StoreUtil.warningDialog("Missing interface", this,
                                        "No detail element for current selection");
-               }
+               } 
 
        }