*/
package eu.etaxonomy.taxeditor.ui.dialog.selection;
+import java.lang.reflect.Member;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.internal.win32.TCHITTESTINFO;
import org.eclipse.swt.widgets.Shell;
import eu.etaxonomy.cdm.api.service.IAgentService;
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
import eu.etaxonomy.cdm.model.agent.AgentBase;
import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
import eu.etaxonomy.cdm.persistence.dto.TeamOrPersonUuidAndTitleCache;
* @since Jul 1, 2021
*/
public class CollectorSelectionDialog extends AgentSelectionDialog<AgentBase<?>> {
+ Team collectorTeam = null;
/**
* @param shell
protected CollectorSelectionDialog(Shell shell, String title, boolean multi, String settings,
AgentBase<?> agent, boolean selectTeamMember) {
super(shell, title, multi, settings, agent, selectTeamMember);
+ if (selectTeamMember && agent instanceof Team){
+ this.collectorTeam = (Team)agent;
+
+ }
}
public static <S extends AgentBase> S select(Shell shell,
S entity, boolean selectTeamMember) {
+
CollectorSelectionDialog dialog = new CollectorSelectionDialog(shell,
"Choose Collector", false, CollectorSelectionDialog.class.getCanonicalName(), entity, selectTeamMember);
return (S) getSelectionFromDialog(dialog);
if (selectTeamMember){
clazz = Person.class;
}
-
+ Set<UUID> memberUuids = new HashSet<>();
+ if (collectorTeam != null && selectTeamMember){
+ List<Person> teamMembers = this.collectorTeam.getTeamMembers();
+
+ teamMembers.forEach(member -> memberUuids.add(member.getUuid()));
+ }
+
model = CdmStore.getService(IAgentService.class).getUuidAndTitleCacheWithCollectorTitleCache(clazz, limitOfInitialElements, pattern);
+ if (collectorTeam == null){
+ return;
+ }
+ //filter
+ Iterator<UuidAndTitleCache<AgentBase<?>>> modelIterator = model.iterator();
+ List<UuidAndTitleCache<AgentBase<?>>> tempModel = new ArrayList<>();
+ while(modelIterator.hasNext()){
+ UuidAndTitleCache<AgentBase<?>> person = modelIterator.next();
+ if (memberUuids.contains(person.getUuid())){
+ tempModel.add(person);
+ }
+ }
+ model.clear();
+ model.addAll(tempModel);
}
@Override
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;\r
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;\r
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;\r
+import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;\r
\r
/**\r
* @author n.hoffmann\r
}else if(clazz.equals(AgentBase.class) && (parentElement instanceof FieldUnitFacadeGeneralDetailElement || parentElement instanceof DerivedUnitGeneralDetailElement)){\r
return (T) CollectorSelectionDialog.select(shell,\r
(TeamOrPersonBase) currentSelection, false);\r
+ }else if (clazz.equals(AgentBase.class) && parentElement instanceof CollectorSelectionElement){\r
+ return (T) CollectorSelectionDialog.select(shell,\r
+ (TeamOrPersonBase) ((CollectorSelectionElement)parentElement).getCollectorTeam(), true);\r
}else if(clazz.equals(TeamOrPersonBase.class)){\r
//TODO: add TeamOrPersonBaseSelectionDialog (see ticket #4545)\r
return (T) TeamOrPersonBaseSelectionDialog.select(shell,\r
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithAbbreviatedTitle;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithIdInVocabulary;
-import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart;
adapt(element);
parentElement.addElement(element);
return element;
- }
+ }
+
+ public CollectorSelectionElement createCollectorSelectionElement(ICdmFormElement parentElement, String labelString, AgentBase team, Person member, int mode,
+ int style) {
+ CollectorSelectionElement element = new CollectorSelectionElement(this, parentElement,
+ labelString, team, member, mode, style);
+ adapt(element);
+ parentElement.addElement(element);
+ return element;
+ }
public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
int style) {
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.occurrence.Collection;
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
import eu.etaxonomy.taxeditor.ui.element.UriWithLabelElement;
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
+import eu.etaxonomy.taxeditor.ui.selection.CollectorSelectionElement;
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
/**
private PointElement element_point;
private NumberWithLabelElement number_elevation;
private TimePeriodElement element_date;
- private EntitySelectionElement<AgentBase> selection_collector;
+ private CollectorSelectionElement selection_collector;
+ private CollectorSelectionElement selection_primary_collector;
private TextWithLabelElement text_collectingNumber;
private EntitySelectionElement<Collection> selection_collection;
private TextWithLabelElement text_accessionNumber;
formElement, "Collector",
entity.getCollector(), EntitySelectionElement.ALL,
style);
+ selection_primary_collector = formFactory
+ .createCollectorSelectionElement(
+ formElement, "Primary collector",
+ entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
+ style);
+ if (!(entity.getCollector() instanceof Team)){
+ selection_primary_collector.setEnabled(false);
+ }
text_collectingNumber = formFactory.createTextWithLabelElement(formElement,
"Collecting number", entity.getFieldNumber(), style);
}
getEntity().setGatheringPeriod(element_date.getTimePeriod());
} else if (eventSource == selection_collector) {
getEntity().setCollector(selection_collector.getSelection());
- } else if (eventSource == text_collectingNumber) {
+ getEntity().setCollector(selection_collector.getSelection());
+ if (getEntity().getCollector() instanceof Team){
+ selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
+ }
+ selection_primary_collector.setEnabled(getEntity().getCollector() instanceof Team);
+ } else if (eventSource == selection_primary_collector) {
+ getEntity().setPrimaryCollector((Person)selection_primary_collector.getSelection());
+ }else if (eventSource == text_collectingNumber) {
getEntity().setFieldNumber(text_collectingNumber.getText());
}
else if (eventSource == selection_collection) {
*/
package eu.etaxonomy.taxeditor.ui.section.occurrence;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Team;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.LanguageString;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
private NumberWithLabelElement number_elevation;
private TimePeriodElement element_date;
private CollectorSelectionElement selection_collector;
+ private CollectorSelectionElement selection_primary_collector;
private TextWithLabelElement text_collectingNumber;
private GatheringEventUnitElement element_elevation;
private CheckboxElement checkIsPublish;
element_date = formFactory.createTimePeriodElement(formElement, "Date", entity.getGatheringPeriod(), style);
selection_collector = formFactory.createCollectorSelectionElement(formElement, "Collector", entity.getCollector(), EntitySelectionElement.ALL, style);
+ selection_primary_collector = formFactory
+ .createCollectorSelectionElement(
+ formElement, "Primary collector",
+ entity.getCollector(), entity.getPrimaryCollector(), EntitySelectionElement.ALL,
+ style);
+ if (!(entity.getCollector() instanceof Team)){
+ selection_primary_collector.setEnabled(false);
+ }
text_collectingNumber = formFactory.createTextWithLabelElement(formElement, "Collecting number",
entity.getFieldNumber(), style);
checkIsPublish = formFactory.createCheckbox(formElement, "Publish", entity.innerFieldUnit().isPublish(), style);
getEntity().setGatheringPeriod(element_date.getTimePeriod());
} else if (eventSource == selection_collector) {
getEntity().setCollector(selection_collector.getSelection());
+
+ if (getEntity().getCollector() instanceof Team){
+ selection_primary_collector.setCollectorTeam((Team)getEntity().getCollector());
+ }else{
+ selection_primary_collector.setEntity(null);
+ }
+ selection_primary_collector.setEnabled((getEntity().getCollector() instanceof Team));
+
+ } else if (eventSource == selection_primary_collector) {
+ getEntity().setCollector(selection_primary_collector.getSelection());
} else if (eventSource == text_collectingNumber) {
getEntity().setFieldNumber(text_collectingNumber.getText());
} else if (eventSource == combo_specorobstype) {
toggleableText_titleCache.setText(getEntity().getTitleCache());
}
+ protected void updateControlStates(){
+ if (getEntity() != null ){
+ enabled = enabled && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud);
+ }else{
+ enabled = true;
+ }
+ Set<Object> except = new HashSet<>();
+ if (!selection_primary_collector.isEnabled() && enabled){
+ except.add(selection_primary_collector);
+ }
+ setEnabled(enabled, except);
+
+ }
+
}
\ No newline at end of file
package eu.etaxonomy.taxeditor.ui.selection;
+import org.eclipse.swt.events.SelectionEvent;
+
import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.agent.Team;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
public class CollectorSelectionElement extends EntitySelectionElement<AgentBase> {
+
+ Team collectorTeam;
/**
* @param formFactory
* @param conversation
parentElement, AgentBase.class,
labelString, entity, mode, style);
}
+ public CollectorSelectionElement(CdmFormFactory formFactory,// ConversationHolder conversation,
+ ICdmFormElement parentElement, String labelString, AgentBase entity, Person primaryCollector, int mode, int style) {
+ super(formFactory, //conversation,
+ parentElement, AgentBase.class,
+ labelString, primaryCollector, mode, style);
+ if (entity instanceof Team){
+ collectorTeam = (Team)entity;
+ }
+ }
@Override
protected String getTitle() {
}
return "";
}
+ public Team getCollectorTeam() {
+ return collectorTeam;
+ }
+ public void setCollectorTeam(Team collectorTeam) {
+ this.collectorTeam = collectorTeam;
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ if (e.getSource().equals(button_selection) ){
+ AgentBase selection = null;
+ if (this.collectorTeam != null){
+ selection = SelectionDialogFactory.getSelectionFromDialog(AgentBase.class, getShell(),
+ collectorTeam, this);
+ }else{
+ selection = SelectionDialogFactory.getSelectionFromDialog(AgentBase.class, getShell(),
+ getEntity(), getParentElement());
+ }
+ setSelectionInternal(selection);
+ if(!getLayoutComposite().isDisposed()){
+ StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
+ }
+ }
+ }
}
+++ /dev/null
-/**
- * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy
- * http://www.e-taxonomy.eu
- *
- * 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.selection;
-
-import org.eclipse.swt.events.SelectionEvent;
-
-import eu.etaxonomy.cdm.model.agent.Team;
-import eu.etaxonomy.taxeditor.ui.dialog.selection.NomenclaturalAuthorTeamSelectionDialog;
-import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
-
-/**
- * <p>
- * NomenclaturalAuthorTeamSelectionElement class.
- * </p>
- *
- * @author n.hoffmann
- * @created Jun 22, 2010
- * @version 1.0
- */
-public class NomenclaturalAuthorTeamSelectionElement extends
- EntitySelectionElement<Team> {
-
- public static final int DEFAULT = EDITABLE | SELECTABLE | DELETABLE;
-
- /**
- * <p>
- * Constructor for NomenclaturalAuthorTeamSelectionElement.
- * </p>
- *
- * @param formFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param conversation
- * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
- * object.
- * @param parentElement
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param labelString
- * a {@link java.lang.String} object.
- * @param entity
- * a {@link eu.etaxonomy.cdm.model.agent.Team} object.
- * @param style
- * a int.
- */
- public NomenclaturalAuthorTeamSelectionElement(CdmFormFactory formFactory,//ConversationHolder conversation,
- ICdmFormElement parentElement,
- String labelString, Team entity, int mode, int style) {
- super(formFactory,// conversation,
- parentElement, Team.class, labelString, entity,
- mode, style);
- }
-
- /** {@inheritDoc} */
- @Override
- protected String getTitle() {
- return (entity != null) ? entity.getNomenclaturalTitleCache() : "";
- }
-
- /** {@inheritDoc} */
- @Override
- public void widgetSelected(SelectionEvent e) {
- Team newSelection = NomenclaturalAuthorTeamSelectionDialog.select(
- getShell(), //getConversationHolder(),
- entity);
- setSelectionInternal(newSelection);
- }
-}