Project

General

Profile

« Previous | Next » 

Revision 4faee5bc

Added by Katja Luther 4 months ago

ref #9894: add field primary collector and handle as described in ticket

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/CollectorSelectionDialog.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.ui.dialog.selection;
10 10

  
11
import java.lang.reflect.Member;
12
import java.util.ArrayList;
13
import java.util.HashSet;
14
import java.util.Iterator;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.UUID;
18

  
11 19
import org.eclipse.jface.viewers.ILabelProvider;
12 20
import org.eclipse.jface.viewers.LabelProvider;
21
import org.eclipse.swt.internal.win32.TCHITTESTINFO;
13 22
import org.eclipse.swt.widgets.Shell;
14 23

  
15 24
import eu.etaxonomy.cdm.api.service.IAgentService;
......
17 26
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
18 27
import eu.etaxonomy.cdm.model.agent.AgentBase;
19 28
import eu.etaxonomy.cdm.model.agent.Person;
29
import eu.etaxonomy.cdm.model.agent.Team;
20 30
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
21 31
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
22 32
import eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache;
......
29 39
 * @since Jul 1, 2021
30 40
 */
31 41
public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>> {
42
	Team collectorTeam = null;
32 43

  
33 44
    /**
34 45
     * @param shell
......
41 52
    protected CollectorSelectionDialog(Shell shell, String title, boolean multi, String settings,
42 53
            AgentBase<?> agent, boolean selectTeamMember) {
43 54
        super(shell, title, multi, settings, agent, selectTeamMember);
55
        if (selectTeamMember && agent instanceof Team){
56
    		this.collectorTeam = (Team)agent;
57
    		
58
    	}
44 59

  
45 60
    }
46 61
    public static <S extends AgentBase> S select(Shell shell,
47 62
            S entity, boolean selectTeamMember) {
63
    	
48 64
        CollectorSelectionDialog dialog = new CollectorSelectionDialog(shell,
49 65
                "Choose Collector", false, CollectorSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
50 66
        return  (S) getSelectionFromDialog(dialog);
......
93 109
        if (selectTeamMember){
94 110
            clazz = Person.class;
95 111
        }
96

  
112
        Set<UUID> memberUuids = new HashSet<>();
113
        if (collectorTeam != null && selectTeamMember){
114
        	List<Person> teamMembers = this.collectorTeam.getTeamMembers();
115
        	
116
            teamMembers.forEach(member -> memberUuids.add(member.getUuid()));
117
        }
118
        
97 119
        model = CdmStore.getService(IAgentService.class).getUuidAndTitleCacheWithCollectorTitleCache(clazz, limitOfInitialElements, pattern);
120
        if (collectorTeam == null){
121
        	return;
122
        }
123
        //filter
124
        Iterator<UuidAndTitleCache<AgentBase<?>>> modelIterator = model.iterator();
125
        List<UuidAndTitleCache<AgentBase<?>>> tempModel = new ArrayList<>();
126
        while(modelIterator.hasNext()){
127
        	UuidAndTitleCache<AgentBase<?>> person = modelIterator.next();
128
        	if (memberUuids.contains(person.getUuid())){
129
        		tempModel.add(person);
130
        	}
131
        }
132
        model.clear();
133
        model.addAll(tempModel);
98 134
    }
99 135

  
100 136
    @Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/SelectionDialogFactory.java
61 61
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
62 62
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
63 63
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
64
import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;
64 65

  
65 66
/**
66 67
 * @author n.hoffmann
......
122 123
        }else if(clazz.equals(AgentBase.class) && (parentElement instanceof FieldUnitFacadeGeneralDetailElement || parentElement instanceof DerivedUnitGeneralDetailElement)){
123 124
		    return (T) CollectorSelectionDialog.select(shell,
124 125
		            (TeamOrPersonBase) currentSelection, false);
126
		}else if (clazz.equals(AgentBase.class) && parentElement instanceof CollectorSelectionElement){
127
			return (T) CollectorSelectionDialog.select(shell,
128
		            (TeamOrPersonBase) ((CollectorSelectionElement)parentElement).getCollectorTeam(), true);
125 129
		}else if(clazz.equals(TeamOrPersonBase.class)){
126 130
            //TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)
127 131
            return (T) TeamOrPersonBaseSelectionDialog.select(shell,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
415 415
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
416 416
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithAbbreviatedTitle;
417 417
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithIdInVocabulary;
418
import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
419 418
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
420 419
import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart;
421 420

  
......
3300 3299
      adapt(element);
3301 3300
      parentElement.addElement(element);
3302 3301
      return element;
3303
  }
3302
    }
3303
    
3304
    public CollectorSelectionElement createCollectorSelectionElement(ICdmFormElement parentElement, String labelString, AgentBase team, Person member, int mode,
3305
            int style) {
3306
      	CollectorSelectionElement element = new CollectorSelectionElement(this, parentElement, 
3307
                labelString, team, member, mode, style);
3308
        adapt(element);
3309
        parentElement.addElement(element);
3310
        return element;
3311
      }
3304 3312

  
3305 3313
    public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
3306 3314
          int style) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/DerivedUnitGeneralDetailElement.java
11 11

  
12 12
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
13 13
import eu.etaxonomy.cdm.model.agent.AgentBase;
14
import eu.etaxonomy.cdm.model.agent.Person;
15
import eu.etaxonomy.cdm.model.agent.Team;
14 16
import eu.etaxonomy.cdm.model.common.LanguageString;
15 17
import eu.etaxonomy.cdm.model.location.NamedArea;
16 18
import eu.etaxonomy.cdm.model.occurrence.Collection;
......
32 34
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
33 35
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
34 36
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
37
import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;
35 38
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
36 39

  
37 40
/**
......
54 57
	private PointElement element_point;
55 58
	private NumberWithLabelElement number_elevation;
56 59
	private TimePeriodElement element_date;
57
	private EntitySelectionElement<AgentBase> selection_collector;
60
	private CollectorSelectionElement selection_collector;
61
	private CollectorSelectionElement selection_primary_collector;
58 62
	private TextWithLabelElement text_collectingNumber;
59 63
	private EntitySelectionElement<Collection> selection_collection;
60 64
	private TextWithLabelElement text_accessionNumber;
......
103 107
		                    formElement, "Collector",
104 108
		                    entity.getCollector(), EntitySelectionElement.ALL,
105 109
		                    style);
110
		    selection_primary_collector = formFactory
111
		            .createCollectorSelectionElement(
112
		                    formElement, "Primary collector",
113
		                    entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
114
		                    style);
115
	        if (!(entity.getCollector() instanceof Team)){
116
		    	selection_primary_collector.setEnabled(false);
117
		    }
106 118
		    text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
107 119
		            "Collecting number", entity.getFieldNumber(), style);
108 120
		}
......
138 150
			getEntity().setGatheringPeriod(element_date.getTimePeriod());
139 151
		} else if (eventSource == selection_collector) {
140 152
			getEntity().setCollector(selection_collector.getSelection());
141
		} else if (eventSource == text_collectingNumber) {
153
			 getEntity().setCollector(selection_collector.getSelection());
154
	         if (getEntity().getCollector() instanceof Team){
155
	        	 selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
156
	         }
157
			selection_primary_collector.setEnabled(getEntity().getCollector() instanceof Team);
158
		} else if (eventSource == selection_primary_collector) {
159
			getEntity().setPrimaryCollector((Person)selection_primary_collector.getSelection());
160
		}else if (eventSource == text_collectingNumber) {
142 161
			getEntity().setFieldNumber(text_collectingNumber.getText());
143 162
		}
144 163
		  else if (eventSource == selection_collection) {
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/FieldUnitFacadeGeneralDetailElement.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.ui.section.occurrence;
10 10

  
11
import java.util.Collection;
12
import java.util.HashSet;
13
import java.util.Set;
14

  
11 15
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
12 16
import eu.etaxonomy.cdm.model.agent.AgentBase;
17
import eu.etaxonomy.cdm.model.agent.Team;
18
import eu.etaxonomy.cdm.model.common.CdmBase;
13 19
import eu.etaxonomy.cdm.model.common.LanguageString;
14 20
import eu.etaxonomy.cdm.model.location.NamedArea;
15 21
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
16 22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
17 24
import eu.etaxonomy.taxeditor.store.StoreUtil;
18 25
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
19 26
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
......
47 54
    private NumberWithLabelElement number_elevation;
48 55
    private TimePeriodElement element_date;
49 56
    private CollectorSelectionElement selection_collector;
57
    private CollectorSelectionElement selection_primary_collector;
50 58
    private TextWithLabelElement text_collectingNumber;
51 59
    private GatheringEventUnitElement element_elevation;
52 60
    private CheckboxElement checkIsPublish;
......
81 89

  
82 90
        element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
83 91
        selection_collector = formFactory.createCollectorSelectionElement(formElement, "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
92
        selection_primary_collector = formFactory
93
	            .createCollectorSelectionElement(
94
	                    formElement, "Primary collector",
95
	                    entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
96
	                    style);
97
        if (!(entity.getCollector() instanceof Team)){
98
	    	selection_primary_collector.setEnabled(false);
99
	    }
84 100
        text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
85 101
                entity.getFieldNumber(), style);
86 102
        checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.innerFieldUnit().isPublish(), style);
......
104 120
            getEntity().setGatheringPeriod(element_date.getTimePeriod());
105 121
        } else if (eventSource == selection_collector) {
106 122
            getEntity().setCollector(selection_collector.getSelection());
123
            
124
            if (getEntity().getCollector() instanceof Team){
125
            	selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
126
            }else{
127
            	selection_primary_collector.setEntity(null);
128
            }
129
            selection_primary_collector.setEnabled((getEntity().getCollector() instanceof Team));
130
            
131
        } else if (eventSource == selection_primary_collector) {
132
            getEntity().setCollector(selection_primary_collector.getSelection());
107 133
        } else if (eventSource == text_collectingNumber) {
108 134
            getEntity().setFieldNumber(text_collectingNumber.getText());
109 135
        } else if (eventSource == combo_specorobstype) {
......
115 141
        toggleableText_titleCache.setText(getEntity().getTitleCache());
116 142

  
117 143
    }
144
    protected void updateControlStates(){
145
        if (getEntity() != null ){
146
            enabled = enabled && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
147
        }else{
148
            enabled = true;
149
        }
150
        Set<Object> except = new HashSet<>(); 
151
        if (!selection_primary_collector.isEnabled() && enabled){
152
        	except.add(selection_primary_collector);
153
        }
154
        setEnabled(enabled, except);
155
        
156
    }
157

  
118 158
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/CollectorSelectionElement.java
1 1
package eu.etaxonomy.taxeditor.ui.selection;
2 2

  
3
import org.eclipse.swt.events.SelectionEvent;
4

  
3 5
import eu.etaxonomy.cdm.model.agent.AgentBase;
6
import eu.etaxonomy.cdm.model.agent.Person;
7
import eu.etaxonomy.cdm.model.agent.Team;
4 8
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
5 9
import eu.etaxonomy.cdm.model.common.CdmBase;
6 10
import eu.etaxonomy.cdm.model.reference.Reference;
11
import eu.etaxonomy.taxeditor.store.StoreUtil;
12
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
7 13
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
8 14
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
9 15

  
10 16
public class CollectorSelectionElement extends EntitySelectionElement<AgentBase> {
17
	
18
	Team collectorTeam;
11 19
	/**
12 20
     * @param formFactory
13 21
     * @param conversation
......
24 32
        parentElement, AgentBase.class,
25 33
        labelString, entity, mode, style);
26 34
    }
35
    public CollectorSelectionElement(CdmFormFactory formFactory,// ConversationHolder conversation,
36
            ICdmFormElement parentElement, String labelString, AgentBase entity, Person primaryCollector, int mode, int style) {
37
    	super(formFactory, //conversation,
38
        parentElement, AgentBase.class,
39
        labelString, primaryCollector, mode, style);
40
    	if (entity instanceof Team){
41
    		collectorTeam = (Team)entity;
42
    	}
43
    }
27 44

  
28 45
    @Override
29 46
    protected String getTitle() {
......
36 53
		}
37 54
		return "";
38 55
	}
56
	public Team getCollectorTeam() {
57
		return collectorTeam;
58
	}
59
	public void setCollectorTeam(Team collectorTeam) {
60
		this.collectorTeam = collectorTeam;
61
	}
62
	
63
	public void widgetSelected(SelectionEvent e) {
64
	    if (e.getSource().equals(button_selection) ){
65
	    	AgentBase selection = null;
66
	    	if (this.collectorTeam != null){
67
	    		selection = SelectionDialogFactory.getSelectionFromDialog(AgentBase.class, getShell(),
68
		                collectorTeam, this);
69
	    	}else{	    	
70
	    		selection = SelectionDialogFactory.getSelectionFromDialog(AgentBase.class, getShell(),
71
	                getEntity(), getParentElement());
72
	    	}
73
            setSelectionInternal(selection);
74
            if(!getLayoutComposite().isDisposed()){
75
                StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
76
            }
77
	    }
78
	}
39 79
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/NomenclaturalAuthorTeamSelectionElement.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.selection;
11

  
12
import org.eclipse.swt.events.SelectionEvent;
13

  
14
import eu.etaxonomy.cdm.model.agent.Team;
15
import eu.etaxonomy.taxeditor.ui.dialog.selection.NomenclaturalAuthorTeamSelectionDialog;
16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
17
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
18

  
19
/**
20
 * <p>
21
 * NomenclaturalAuthorTeamSelectionElement class.
22
 * </p>
23
 *
24
 * @author n.hoffmann
25
 * @created Jun 22, 2010
26
 * @version 1.0
27
 */
28
public class NomenclaturalAuthorTeamSelectionElement extends
29
		EntitySelectionElement<Team> {
30

  
31
	public static final int DEFAULT = EDITABLE | SELECTABLE | DELETABLE;
32

  
33
	/**
34
	 * <p>
35
	 * Constructor for NomenclaturalAuthorTeamSelectionElement.
36
	 * </p>
37
	 *
38
	 * @param formFactory
39
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
40
	 *            object.
41
	 * @param conversation
42
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
43
	 *            object.
44
	 * @param parentElement
45
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
46
	 *            object.
47
	 * @param labelString
48
	 *            a {@link java.lang.String} object.
49
	 * @param entity
50
	 *            a {@link eu.etaxonomy.cdm.model.agent.Team} object.
51
	 * @param style
52
	 *            a int.
53
	 */
54
	public NomenclaturalAuthorTeamSelectionElement(CdmFormFactory formFactory,//ConversationHolder conversation,
55
	        ICdmFormElement parentElement,
56
			String labelString, Team entity, int mode, int style) {
57
		super(formFactory,// conversation,
58
		        parentElement, Team.class, labelString, entity,
59
				mode, style);
60
	}
61

  
62
	/** {@inheritDoc} */
63
	@Override
64
	protected String getTitle() {
65
		return (entity != null) ? entity.getNomenclaturalTitleCache() : "";
66
	}
67

  
68
	/** {@inheritDoc} */
69
	@Override
70
	public void widgetSelected(SelectionEvent e) {
71
		Team newSelection = NomenclaturalAuthorTeamSelectionDialog.select(
72
				getShell(), //getConversationHolder(),
73
				entity);
74
		setSelectionInternal(newSelection);
75
	}
76
}

Also available in: Unified diff