Project

General

Profile

« Previous | Next » 

Revision 9ac72187

Added by Lorna Morris over 11 years ago

Fixes #2681

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/CreateConceptRelationHandler.java
46 46
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
47 47
				Page.NAME);
48 48
		
49
		Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), editor.getConversationHolder());
49
		Taxon taxonToBeFiltered = editor.getTaxon();
50
		
51
		Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), taxonToBeFiltered);
50 52
				
51 53
		if(relatedConcept == null){
52 54
			return Status.CANCEL_STATUS;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/MoveDescriptionElementsHandler.java
35 35
import eu.etaxonomy.taxeditor.store.CdmStore;
36 36
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
37 37

  
38

  
38 39
/**
39 40
 * @author n.hoffmann
40 41
 * @created Feb 8, 2011
......
66 67
				}
67 68
			}
68 69
			
69
			Taxon targetTaxon = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), EditorUtil.getActiveMultiPageTaxonEditor().getConversationHolder());
70
			Taxon targetTaxon = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), EditorUtil.getActiveMultiPageTaxonEditor().getConversationHolder(), null);
70 71
						
71 72
			TaxonDescription targetDescription = TaxonDescription.NewInstance(targetTaxon);
72 73
			targetDescription.setTitleCache(String.format("Copied from %s", EditorUtil.getActiveMultiPageTaxonEditor().getTaxon()), true);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java
67 67
	private Set<T> transientCdmObjects = new HashSet<T>();
68 68
	private String settings;	
69 69
	
70
	protected T cdmBaseToBeFiltered;
71
	
70 72
	/**
71 73
	 * <p>Constructor for AbstractFilteredCdmResourceSelectionDialog.</p>
72 74
	 *
......
217 219
	@Override
218 220
	public void refresh() {
219 221
		initModel();
222
		filterExcludedObjects();
220 223
		super.refresh();
221 224
	}
222 225
	
......
488 491
	
489 492
	/** {@inheritDoc} */
490 493
	public void update(CdmDataChangeMap changeEvents) {}
494

  
495
	/**
496
	 * Don't want to add a taxon or synonym to itself so filter the list to remove the taxon in question
497
	 * so it is not available to add as a concept relation
498
	 */
499
	private void filterExcludedObjects() {
500
		if (model != null && cdmBaseToBeFiltered != null) {
501
			
502
			UuidAndTitleCache uuidAndTitleCacheToRemove = null;
503
						
504
			for (UuidAndTitleCache uuidAndTitleCache : model){
505
				if ((cdmBaseToBeFiltered.getUuid()).equals(uuidAndTitleCache.getUuid())) {
506
					uuidAndTitleCacheToRemove = uuidAndTitleCache;
507
				}				
508
			}
509
			model.remove(uuidAndTitleCacheToRemove);
510
		}
511
	}
491 512
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/TaxonBaseSelectionDialog.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.taxeditor.ui.dialog.selection;
12

  
13
import java.util.UUID;
14

  
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Shell;
18

  
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.service.ITaxonService;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

  
27
/**
28
 * <p>FilteredTaxonBaseSelectionDialog class.</p>
29
 *
30
 * @author n.hoffmann
31
 * @created Sep 21, 2009
32
 * @version 1.0
33
 */
34
public class TaxonBaseSelectionDialog extends
35
		AbstractFilteredCdmResourceSelectionDialog<TaxonBase> {
36
		
37
	/**
38
	 * <p>select</p>
39
	 *
40
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
41
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
42
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
43
	 */
44
	public static TaxonBase selectTaxonBase(Shell shell, ConversationHolder conversation) {
45
		TaxonBaseSelectionDialog dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, conversation,
46
				"Choose a taxon", false, null);
47
		return getSelectionFromDialog(dialog);
48
	}
49
	
50
	/**
51
	 * <p>select</p>
52
	 *
53
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
54
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
55
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
56
	 */
57
	public static Taxon selectTaxon(Shell shell, ConversationHolder conversation) {
58
		TaxonBaseSelectionDialog dialog = new TaxonBaseSelectionDialog(Taxon.class, shell, conversation,
59
				"Choose a taxon", false, null);
60
		return (Taxon) getSelectionFromDialog(dialog);
61
	}
62
	
63
	/**
64
	 * <p>select</p>
65
	 *
66
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
67
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
68
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
69
	 */
70
	public static Synonym selectSynonym(Shell shell, ConversationHolder conversation) {
71
		TaxonBaseSelectionDialog dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, conversation,
72
				"Choose a taxon", false, null);
73
		return (Synonym) getSelectionFromDialog(dialog);
74
	}
75

  
76
	private final Class<? extends TaxonBase> clazz;
77
	
78
	/**
79
	 * <p>Constructor for FilteredTaxonBaseSelectionDialog.</p>
80
	 *
81
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
82
	 * @param title a {@link java.lang.String} object.
83
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
84
	 * @param multi a boolean.
85
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
86
	 */
87
	protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, ConversationHolder conversation, String title, boolean multi, TaxonBase taxon) {
88
		super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), taxon);
89
		this.clazz = clazz;
90
	}
91

  
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
94
	 */
95
	/** {@inheritDoc} */
96
	@Override
97
	protected Control createExtendedContentArea(Composite parent) {
98
		return null;
99
	}
100

  
101
	/* (non-Javadoc)
102
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
103
	 */
104
	/** {@inheritDoc} */
105
	@Override
106
	protected TaxonBase getPersistentObject(UUID uuid) {
107
		return CdmStore.getService(ITaxonService.class).load(uuid);
108
	}
109

  
110
	/* (non-Javadoc)
111
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
112
	 */
113
	/** {@inheritDoc} */
114
	@Override
115
	protected void initModel() {
116
		if(clazz == TaxonBase.class){
117
			model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache();
118
		}
119
		else if(clazz == Taxon.class){
120
			model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheTaxon();
121
		}
122
		else if(clazz == Synonym.class){
123
			model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheSynonym();
124
		}
125
	}
126

  
127
	/** {@inheritDoc} */
128
	@Override
129
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
130
		return null;
131
	}
132

  
133
	/** {@inheritDoc} */
134
	@Override
135
	protected String getNewWizardLinkText() {
136
		return null;
137
	}
138
}
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.taxeditor.ui.dialog.selection;
12

  
13
import java.util.UUID;
14

  
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Control;
17
import org.eclipse.swt.widgets.Shell;
18

  
19
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
20
import eu.etaxonomy.cdm.api.service.ITaxonService;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24
import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard;
25
import eu.etaxonomy.taxeditor.store.CdmStore;
26

  
27
/**
28
 * <p>FilteredTaxonBaseSelectionDialog class.</p>
29
 *
30
 * @author n.hoffmann
31
 * @created Sep 21, 2009
32
 * @version 1.0
33
 */
34
public class TaxonBaseSelectionDialog extends
35
		AbstractFilteredCdmResourceSelectionDialog<TaxonBase> {
36
	
37
		
38
	/**
39
	 * <p>select</p>
40
	 *
41
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
42
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
43
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
44
	 */
45
	public static TaxonBase selectTaxonBase(Shell shell, ConversationHolder conversation) {
46
		AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(TaxonBase.class, shell, conversation,
47
				"Choose a taxon", false, null, null);
48
		return getSelectionFromDialog(dialog);
49
	}
50
	
51
	/**
52
	 * <p>select</p>
53
	 *
54
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
55
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
56
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
57
	 */
58
	public static Taxon selectTaxon(Shell shell, ConversationHolder conversation, Taxon taxonToBeFiltered) {
59
		
60

  
61
		AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Taxon.class, shell, conversation,
62
				"Choose a taxon", false, null, taxonToBeFiltered);
63
		return (Taxon) getSelectionFromDialog(dialog);
64
	}
65
	
66
	/**
67
	 * <p>select</p>
68
	 *
69
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
70
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
71
	 * @return a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
72
	 */
73
	public static Synonym selectSynonym(Shell shell, ConversationHolder conversation) {
74
		AbstractFilteredCdmResourceSelectionDialog<TaxonBase> dialog = new TaxonBaseSelectionDialog(Synonym.class, shell, conversation,
75
				"Choose a taxon", false, null, null);
76
		return (Synonym) getSelectionFromDialog(dialog);
77
	}
78

  
79
	private final Class<? extends TaxonBase> clazz;
80
	
81
	/**
82
	 * <p>Constructor for FilteredTaxonBaseSelectionDialog.</p>
83
	 *
84
	 * @param shell a {@link org.eclipse.swt.widgets.Shell} object.
85
	 * @param title a {@link java.lang.String} object.
86
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
87
	 * @param multi a boolean.
88
	 * @param taxon a {@link eu.etaxonomy.cdm.model.taxon.TaxonBase} object.
89
	 */
90
	protected TaxonBaseSelectionDialog(Class<? extends TaxonBase> clazz, Shell shell, ConversationHolder conversation, String title, boolean multi, TaxonBase taxon, TaxonBase taxonToBeFiltered) {
91
		super(shell, conversation, title, multi, ReferenceSelectionDialog.class.getCanonicalName(), taxon);
92
		this.cdmBaseToBeFiltered = taxonToBeFiltered;
93

  
94
		
95
		
96
		this.clazz = clazz;
97
	}
98

  
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createExtendedContentArea(org.eclipse.swt.widgets.Composite)
101
	 */
102
	/** {@inheritDoc} */
103
	@Override
104
	protected Control createExtendedContentArea(Composite parent) {
105
		return null;
106
	}
107

  
108
	/* (non-Javadoc)
109
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#getPersistentObject(java.util.UUID)
110
	 */
111
	/** {@inheritDoc} */
112
	@Override
113
	protected TaxonBase getPersistentObject(UUID uuid) {
114
		return CdmStore.getService(ITaxonService.class).load(uuid);
115
	}
116

  
117
	/* (non-Javadoc)
118
	 * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
119
	 */
120
	/** {@inheritDoc} */
121
	@Override
122
	protected void initModel() {
123
		if(clazz == TaxonBase.class){
124
			model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCache();
125
		}
126
		else if(clazz == Taxon.class){
127
						
128
			model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheTaxon();
129
			
130
		}
131
		else if(clazz == Synonym.class){
132
			model = CdmStore.getService(ITaxonService.class).getUuidAndTitleCacheSynonym();
133
		}
134
	}
135

  
136
	/** {@inheritDoc} */
137
	@Override
138
	protected AbstractNewEntityWizard getNewEntityWizard(String parameter) {
139
		return null;
140
	}
141

  
142
	/** {@inheritDoc} */
143
	@Override
144
	protected String getNewWizardLinkText() {
145
		return null;
146
	}
147
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/key/TaxonomicScopeSection.java
62 62
	@Override
63 63
	public Taxon createNewElement() {
64 64
		Taxon selection = TaxonBaseSelectionDialog.selectTaxon(getShell(),
65
				getConversationHolder());
65
				getConversationHolder(), null);
66 66

  
67 67
		return selection;
68 68
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/selection/TaxonSelectionElement.java
54 54
	@Override
55 55
	public void widgetSelected(SelectionEvent e) {
56 56
		Taxon newSelection = TaxonBaseSelectionDialog.selectTaxon(getShell(),
57
				getConversationHolder());
57
				getConversationHolder(), null);
58 58
		setSelectionInternal(newSelection);
59 59
	}
60 60

  

Also available in: Unified diff