Project

General

Profile

« Previous | Next » 

Revision 9c260783

Added by Pepe Ciardelli over 14 years ago

Updated filtered selection dialogs to 1) pass up an existing value and 2) create an object.

View differences:

taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameSelectComposite.java
22 22
import org.eclipse.swt.layout.GridLayout;
23 23
import org.eclipse.swt.widgets.Button;
24 24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Dialog;
26 25
import org.eclipse.swt.widgets.Label;
27 26
import org.eclipse.swt.widgets.Text;
28 27

  
29 28
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
30 29
import eu.etaxonomy.taxeditor.dialogs.FilteredNameSelectionDialog;
31
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
32
import eu.etaxonomy.taxeditor.model.Resources;
33 30
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
34 31

  
35 32
/**
......
67 64
		
68 65
		Label lblName = new Label(this, SWT.NONE);
69 66
		lblName.setLayoutData(new GridData());
70
		lblName.setText("Choose a name either by searching or by entering it as free text:");
67
		lblName.setText("Choose a name:");
71 68
		
72 69
		// Create 3-columned composite for name input
73 70
		Composite nameComposite = new Composite(this, SWT.NONE);
......
80 77
		
81 78
		// Create name input
82 79
		txtName = new Text(nameComposite, SWT.BORDER);
80
		txtName.setEnabled(false);
83 81
		txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
84 82
		txtName.addModifyListener(new ModifyListener() {
85 83
			public void modifyText(ModifyEvent e) {
......
111 109
				clearName();
112 110
			}
113 111
		});
114
		
115
		// Create message re: editing names
116
		Label lblNewNameFeedback = new Label(this, SWT.NONE);
117
		lblNewNameFeedback.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
118
		lblNewNameFeedback.setFont(
119
				Resources.italicizeFont(lblNewNameFeedback.getFont()));
120
		lblNewNameFeedback.setText("Existing names can not be edited.");
121 112
	}
122 113
	
123 114
	/**
......
142 133
	/**
143 134
	 * 
144 135
	 */
145
	protected void popupSearch() {
146
//		Dialog dialog = new NameSearchDialog(getShell());
147
//        Object value = ((NameSearchDialog) dialog).open();
148
//        
149
//		if (value instanceof TaxonNameBase) {
150
//			setSavedName((TaxonNameBase<?, ?>) value);
151
//		}
152
		
153
		TaxonNameBase name = FilteredNameSelectionDialog.selectName(getShell());
136
	protected void popupSearch() {		
137
		TaxonNameBase name = FilteredNameSelectionDialog.selectName(getShell(), savedName);
154 138
		if(name != null){
155 139
			setSavedName(name);
156 140
		}
......
186 170
	 * @return
187 171
	 */
188 172
	public TaxonNameBase<?, ?> getName() {
189
		TaxonNameBase<?, ?> name = null;
190
	    if (savedName != null) {
191
	    	name = savedName;
192
		} else {
193
			if (!txtName.getText().equals("")) {
194
				name = PreferencesUtil.getPreferredNomenclaturalCode().getNewTaxonNameInstance(null);
195
				name.setTitleCache(txtName.getText());
196
			}
197
		}
198
		return name;
173
		return savedName;
199 174
	}
200 175
}
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java
251 251
		if (homotypicGroupOfAcceptedTaxon != null) {
252 252
			List<Synonym> homotypicSynonyms = homotypicGroupOfAcceptedTaxon.getSynonymsInGroup(taxon.getSec());
253 253
			for (Synonym synonym : homotypicSynonyms) {
254

  
255
				// Make sure synonym belongs to the taxon
256
				// TODO why? doesn't taxon.getHomotypicGroup.getSynonymsInGroup return synonyms of the taxon only? I would think so!
257
				if (synonym.getAcceptedTaxa().contains(taxon)) {
258
					createSynonym(synonym);
259
				}
254
				createSynonym(synonym);
260 255
			}
261 256
		}
262 257
		
263 258
		// Draw heterotypic synonym groups
264 259
		List<HomotypicalGroup> heterotypicSynonymGroups = taxon.getHeterotypicSynonymyGroups();
265 260
		for (HomotypicalGroup homotypicalGroup : heterotypicSynonymGroups) {
266
			
267
			// Make sure this is not the taxon's homotypic group
268
			// TODO why? doesn't taxon.getHeterotypicSynonymyGroups return only the heterotypic synonymy groups of the taxon and not the homotypic group? I would think so!
269
			if (!homotypicalGroup.equals(homotypicGroupOfAcceptedTaxon)) {
270 261
							
271
				List<Synonym> heterotypicSynonyms = homotypicalGroup.
272
						getSynonymsInGroup(taxon.getSec());
273
				for (Synonym synonym : heterotypicSynonyms) {
274

  
275
					// Make sure synonym belongs to the taxon 
276
					// TODO why? doesn't taxon.getHeterotypicSynonymyGroups return synonyms of the taxon only? I would think so!
277
					if (synonym.getAcceptedTaxa().contains(taxon)) {
278
						createSynonym(synonym);
279
					}
280
				}
262
			List<Synonym> heterotypicSynonyms = homotypicalGroup.
263
					getSynonymsInGroup(taxon.getSec());
264
			for (Synonym synonym : heterotypicSynonyms) {
265
				 createSynonym(synonym);
281 266
			}
282 267
		}
283 268
		
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/reference/ReferenceSelectComposite.java
60 60
		
61 61
		Label lblReference = new Label(this, SWT.NONE);
62 62
		lblReference.setLayoutData(new GridData());
63
		lblReference.setText("Choose a reference either by searching or entering it as free text:");
63
		lblReference.setText("Choose a reference:");
64 64
		
65 65
		// Create 3-columned composite for reference input
66 66
		Composite refComposite = new Composite(this, SWT.NONE);
......
74 74
		// Create reference input
75 75
		txtReference = new Text(refComposite, SWT.BORDER);
76 76
		txtReference.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
77
		txtReference.setEnabled(false);
77 78
		
78 79
		// Create reference search button
79 80
		Button btnSearchReference = new Button(refComposite, SWT.NONE);
......
99 100
				clearReference();
100 101
			}
101 102
		});
102
		
103
		// Create message re: editing references
104
		Label lblNewRefFeedback = new Label(this, SWT.NONE);
105
		lblNewRefFeedback.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
106
		lblNewRefFeedback.setFont(
107
				Resources.italicizeFont(lblNewRefFeedback.getFont()));
108
		lblNewRefFeedback.setText("Existing references can only be edited in property sheet.");
109 103
				
110 104
		Label lblMicroref = new Label(this, SWT.NONE);
111 105
		lblMicroref.setText("Enter reference detail (e.g., page no.):");
......
131 125
	 * 
132 126
	 */
133 127
	protected void popupSearch() {
134
        ReferenceBase reference = FilteredReferenceSelectionDialog.selectReference(getShell());
128
        ReferenceBase reference = FilteredReferenceSelectionDialog.selectReference(getShell(), savedReference);
135 129
		if (reference != null) {
136 130
			setSavedReference(reference);
137 131
		}
......
167 161
	 * @return
168 162
	 */
169 163
	public ReferenceBase<?> getReference() {
170
		ReferenceBase<?> reference = null;
171
	    if (savedReference != null) {
172
	    	reference = savedReference;
173
		} else {
174
			if (!txtReference.getText().equals("")) {
175
				reference = Generic.NewInstance();
176
				reference.setTitleCache(txtReference.getText());
177
			}
178
		}
179
		return reference;
164
		return savedReference;
180 165
	}
181 166
	
182 167
	public String getMicroReference() {
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/ScientificNamePropertySource.java
112 112
	protected Vector<PropertyDescriptor> descriptors = new Vector<PropertyDescriptor>();
113 113
	
114 114
	protected void addDescriptor(String id) {
115
		
116
		// Reference search
117
		if (id.equals(P_ID_SEARCH)) {
118
//			descriptors.addElement(
119
//					new ReferenceSearchDescriptor(P_ID_SEARCH, P_SEARCH, getSearchType()) {
120
//						protected void saveReference(ReferenceBase reference) {
121
//							setPropertyValue(P_ID_SEARCH, reference);
122
//						}
123
//			});
124
		}
125
		
115
			
126 116
		// Editable cache
127 117
		if (id.equals(P_ID_EDITABLECACHE)) {
128 118
			descriptors.addElement(
......
137 127
		}
138 128
		
139 129
		boolean isProtectedCache = name.isProtectedTitleCache();
140
//		boolean isProtectedCache = false;
141 130
		
142 131
		// Uninomial (aka Genus)
143 132
		if (id.equals(P_ID_UNINOMIAL)) {
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/name/TaxonBasePropertySource.java
100 100
					new PropertyDescriptor(P_ID_TAXONNAME, P_TAXONNAME));
101 101
		}		
102 102
		if (id.equals(P_ID_TAXONSEC)) {
103
			descriptors.addElement(new ReferenceSearchDescriptor(P_ID_TAXONSEC, P_TAXONSEC, IReferenceSearch.BIBREF) {
103
			descriptors.addElement(new ReferenceSearchDescriptor(P_ID_TAXONSEC, P_TAXONSEC, IReferenceSearch.BIBREF, taxonBase.getSec()) {
104 104
				protected void saveReference(ReferenceBase reference) {
105 105
					setPropertyValue(P_ID_TAXONSEC, reference);
106 106
				}
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/reference/ReferencePropertySource.java
404 404
		// Reference search
405 405
		if (id.equals(P_ID_SEARCH)) {
406 406
			descriptors.addElement(
407
					new ReferenceSearchDescriptor(P_ID_SEARCH, P_SEARCH, getSearchType()) {
407
					new ReferenceSearchDescriptor(P_ID_SEARCH, P_SEARCH, getSearchType(), reference) {
408 408
						protected void saveReference(ReferenceBase reference) {
409 409
							setPropertyValue(P_ID_SEARCH, reference);
410 410
						}
......
421 421
		if (id.equals(P_ID_PROTECT_CACHE)) {
422 422
			descriptors.addElement(
423 423
					new ComboBoxPropertyDescriptor(P_ID_PROTECT_CACHE, P_PROTECT_CACHE, 
424
							new String[] {"no", "yes"}));
425
//			descriptors.addElement(
426
//					new CheckboxPropertyDescriptor(P_ID_PROTECT_CACHE, P_PROTECT_CACHE));			
424
							new String[] {"no", "yes"}));			
427 425
		}
428 426
		
429 427
		// Reference type
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/reference/ReferenceSearchDescriptor.java
26 26
abstract public class ReferenceSearchDescriptor extends PropertyDescriptor {
27 27
		
28 28
	int searchType;
29
	private ReferenceBase existingReference;
29 30
	
30
	public ReferenceSearchDescriptor(Object id, String displayName, int searchType) {
31
	public ReferenceSearchDescriptor(Object id, String displayName, int searchType, ReferenceBase existingReference) {
31 32
		super(id, displayName);
32 33
		
33 34
		this.searchType = searchType;
35
		this.existingReference = existingReference;
34 36
	}
35 37

  
36 38
    public CellEditor createPropertyEditor(Composite parent) {
......
39 41
			protected Object openDialogBox(
40 42
					Control cellEditorWindow) {			
41 43

  
42
		        ReferenceBase reference = FilteredReferenceSelectionDialog.selectReference(cellEditorWindow.getShell());
44
		        ReferenceBase reference = FilteredReferenceSelectionDialog.selectReference(cellEditorWindow.getShell(), existingReference);
43 45
				if (reference != null) {
44 46
					saveReference(reference);
45 47
					return new ReferencePropertySource(reference);
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/type/wizard/ChooseNameTypeWizardPage.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.propertysheet.type.wizard;
11 11

  
12
import java.beans.PropertyChangeEvent;
13
import java.beans.PropertyChangeListener;
14

  
12 15
import org.apache.log4j.Logger;
13 16
import org.eclipse.core.databinding.observable.list.WritableList;
14 17
import org.eclipse.core.runtime.Assert;
15 18
import org.eclipse.jface.wizard.WizardPage;
16 19
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.events.KeyAdapter;
18
import org.eclipse.swt.events.KeyEvent;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21 20
import org.eclipse.swt.layout.GridData;
22 21
import org.eclipse.swt.layout.GridLayout;
23 22
import org.eclipse.swt.widgets.Button;
24 23
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Label;
26 24
import org.eclipse.swt.widgets.Text;
27 25

  
28 26
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
29 27
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
30 28
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
31 29
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
32
import eu.etaxonomy.taxeditor.dialogs.FilteredNameSelectionDialog;
30
import eu.etaxonomy.taxeditor.editor.name.NameSelectComposite;
33 31
import eu.etaxonomy.taxeditor.editor.reference.ReferenceSelectComposite;
34
import eu.etaxonomy.taxeditor.model.NomenclaturalCodeHelper;
35
import eu.etaxonomy.taxeditor.model.Resources;
36 32
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
37 33

  
38 34
/**
......
49 45
	private TaxonNameBase<?, ?> savedName;
50 46
	
51 47
	private Text txtName;
52
	private Button btnClearName;
53 48
	private Button btnRejected;
54 49
	private Button btnConserved;
55 50
	private Button btnLecto;
......
59 54

  
60 55
	private ReferenceSelectComposite referenceComposite;
61 56

  
57
	private NameSelectComposite nameComposite;
58

  
59
	private boolean nameSelected;
60

  
62 61
	/**
63 62
	 * @param typeDesignation
64 63
	 * @param name
......
89 88
		Composite container = new Composite(parent, SWT.NULL);
90 89
		container.setLayout(new GridLayout());
91 90
		setControl(container);
92
		
93
		// Create name text
94
		final Label lblName = new Label(container, SWT.NONE);
95
		lblName.setText("Choose a name either by searching or entering it as free text:");
96
		
97
		// Create 3-columned composite for name
98
		Composite nameComposite = new Composite(container, SWT.NULL);
99
		nameComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
100
		GridLayout gridLayout = new GridLayout();
101
		gridLayout.numColumns = 3;
102
		gridLayout.marginHeight = 0;
103
		gridLayout.marginWidth = 0;
104
		nameComposite.setLayout(gridLayout);
105
		
106
		// Create name input
107
		// TODO replace w NameSelectComposite
108
		txtName = new Text(nameComposite, SWT.BORDER);
109
		txtName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
110
		txtName.addKeyListener(new KeyAdapter() {
111
			@Override
112
			public void keyReleased(KeyEvent e) {
113
				updatePage();
114
			}			
115
		});
116
		
117
		// Create name search button
118
		Button btnSearchName = new Button(nameComposite, SWT.NONE);
119
		btnSearchName.setEnabled(true);
120
		btnSearchName.setLayoutData(new GridData());
121
		btnSearchName.setText("Search ...");
122
		btnSearchName.addSelectionListener(new SelectionAdapter() {
123 91
			
124
			// Popup reference search
125
			public void widgetSelected(SelectionEvent e) {
126
				popupNameSearch();
92
		// Create name input composite
93
		nameComposite = new NameSelectComposite(container);
94
		nameComposite.addPropertyChangeListener(new PropertyChangeListener() {
95
			public void propertyChange(PropertyChangeEvent evt) {
96
				setName();
127 97
			}
128 98
		});
129

  
130
		// Create clear name button
131
		btnClearName = new Button(nameComposite, SWT.NONE);
132
		btnClearName.setEnabled(false);
133
		btnClearName.setText("Clear");
134
		btnClearName.addSelectionListener(new SelectionAdapter() {
135
			
136
			// Clear selected reference
137
			public void widgetSelected(SelectionEvent e) {
138
				clearName();
139
			}
140
		});
141

  
142
		// Set text to name text if exists, disable ability to edit name
143
		if (typeDesignation != null && typeDesignation.getTypeName() != null) {
144
			
145
			savedName = typeDesignation.getTypeName();
146
			txtName.setText(savedName.getTitleCache());
147
			txtName.setEditable(false);
148
						
149
			btnClearName.setEnabled(false);
150
			btnSearchName.setEnabled(false);
151
		}
152 99
		
153
		// Tell user when he is entering a new name
154
		Label lblNewNameFeedback = new Label(container, SWT.NONE);
155
		lblNewNameFeedback.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
156
		lblNewNameFeedback.setFont(
157
				Resources.italicizeFont(lblNewNameFeedback.getFont()));
158
		lblNewNameFeedback.setText("Existing names can not be edited.");
100
		if (typeDesignation != null) {
101
			nameComposite.setName(typeDesignation.getTypeName());
102
		}
159 103
		
160 104
		// Create 2-columned composite for name
161 105
		Composite booleansComposite = new Composite(container, SWT.NULL);
......
209 153
			}
210 154
		}
211 155
	}
212

  
156
	
213 157
	/**
214
	 * 
215 158
	 */
216
	protected void popupNameSearch() {
217
		// TODO delete this when FilteredSelectionDialog works
218
//		Dialog dialog = new NameSearchDialog(getShell());
219
//        Object value = ((NameSearchDialog) dialog).open();
220
//        
221
//		if (value instanceof TaxonNameBase) {
222
//			setSavedName((TaxonNameBase<?, ?>) value);
223
//			updatePage();
224
//		}
225
		
226
		setSavedName(FilteredNameSelectionDialog.selectName(getShell()));
159
	private void setName() {
160
		savedName = nameComposite.getName();
161
		nameSelected = (savedName != null);
227 162
		updatePage();
228 163
	}
229
	
230
	/**
231
	 * @param value
232
	 */
233
	private void setSavedName(TaxonNameBase<?, ?> savedName) {
234 164
		
235
		this.savedName = savedName;
236
		
237
		txtName.setText(savedName.getTitleCache());
238
		txtName.setEditable(false);
239
		
240
		btnClearName.setEnabled(true);
241
	}
242
	
243 165
	/**
244 166
	 * 
245 167
	 */
246 168
	protected void clearName() {
247 169
		savedName = null;
248
		
249
		txtName.setText("");
250
		txtName.setEditable(true);
251
		
252
		btnClearName.setEnabled(false);		
170
		txtName.setText("");				
253 171
	}
254 172
		
255 173
	@Override
......
258 176
	}
259 177

  
260 178
	public boolean isPageComplete() {
261
		return (txtName.getText().length() > 0);
179
		return nameComposite.getName() != null;
262 180
	}
263 181
	
264 182
	private void updatePage() {
265
		
266 183
		getWizard().getContainer().updateButtons();
267 184
	}
268 185
	

Also available in: Unified diff