Project

General

Profile

« Previous | Next » 

Revision df44f597

Added by Andreas Müller over 1 year ago

cleanup

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/term/TermComboElement.java
1 1
/**
2
 *
3
 */
2
* Copyright (C) 2017 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
*/
4 9
package eu.etaxonomy.taxeditor.ui.combo.term;
5 10

  
6 11
import java.util.ArrayList;
......
33 38
/**
34 39
 * @author n.hoffmann
35 40
 * @created Nov 5, 2009
36
 * @version 1.0
37 41
 * @param <T>
38 42
 */
39 43
public class TermComboElement<T extends DefinedTermBase>
......
57 61
	public void setTermComparator(Comparator<T> termComparator) {
58 62
		this.termComparator = termComparator;
59 63
		populateTerms();
60

  
61 64
	}
62 65

  
63 66
	private final TermType termType;
......
92 95
            int style) {
93 96
        this(formFactory, parentElement, termClass, null, null, null, labelString, selection, addEmptyElement, style, false, null);
94 97
    }
98

  
95 99
    public TermComboElement(CdmFormFactory formFactory,
96 100
            ICdmFormElement parentElement, Class<T> termClass, String labelString, T selection, boolean addEmptyElement,
97 101
            int style, boolean useAbbrevLabel) {
98 102
        this(formFactory, parentElement, termClass, null, null, null,labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
99

  
100 103
    }
101 104

  
102 105
    public TermComboElement(CdmFormFactory formFactory,
103 106
            ICdmFormElement parentElement, List<T> terms, String labelString, T selection, boolean addEmptyElement,
104 107
            int style, boolean useAbbrevLabel, Comparator<T> comparator) {
105 108
        this(formFactory, parentElement, null, null, null, terms,labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
106

  
107 109
    }
108 110

  
109 111
	private TermComboElement(CdmFormFactory formFactory,
......
123 125

  
124 126
        if(termType!=null){
125 127
            //TODO try to remove generic T and avoid classes to be used
126
        	addTerms((List<T>) getTermManager().getPreferredTerms(termType));            
128
        	addTerms((List<T>) getTermManager().getPreferredTerms(termType));
127 129
        }
128 130
        else if(termVocabulary!=null){
129 131
            addTerms((List<T>) getTermManager().getPreferredTerms(termVocabulary));
......
147 149
        }else{
148 150
        	populateTerms();
149 151
        }
150
        
152

  
151 153
        PreferencesUtil.getPreferenceStore().addPropertyChangeListener(this);
152 154

  
153 155
        if (selection != null) {
......
165 167
		}
166 168
		for (T term: preferredTerms){
167 169
			terms.add(term);
168
		}		
170
		}
169 171
	}
170 172

  
171 173
	private TermComboElement(CdmFormFactory formFactory,
......
193 195
            addTerms(getPreferredTerms());
194 196
        }else if (terms != null && !terms.isEmpty()){
195 197
            addTerms(terms);
196
            
198

  
197 199
        }
198 200
        if (termType == null){
199 201
        	this.termType = terms.get(0).getTermType();
......
250 252
				selectedIndex = terms.indexOf(selection);
251 253
			}
252 254
		}
253
		
255

  
254 256

  
255 257
		for (Listener listener : listeners) {
256
			combo.addListener(SWT.Selection, listener);			
258
			combo.addListener(SWT.Selection, listener);
257 259
		}
258 260
		combo.select(selectedIndex);
259
		
261

  
260 262
	}
261 263

  
262 264
	public void setSelectionDto(TermDto selection) {
......
292 294
		    combo.add(EMPTY_ELEMENT_LABEL);
293 295
		}
294 296
		List<T> withoutNull = new ArrayList<>(terms);
295
		
297

  
296 298
		if (termComparator != null) {
297 299
			if (addEmptyElement){
298 300
				withoutNull = terms.subList(1, terms.size());
......
328 330
		}
329 331

  
330 332
		combo.select(index);
331

  
332 333
	}
333 334

  
334 335
	protected List<T> getPreferredTerms(){
335
	    List<T> preferredTerms = new ArrayList<T>();
336
	    List<T> preferredTerms = new ArrayList<>();
336 337
		if (customPreferredTerms != null){
337 338
			return customPreferredTerms;
338 339
		}
......
384 385
		}
385 386
	}
386 387

  
387
	/**
388
	 *
389
	 *
390
	 * @param term
391
	 */
392 388
	private void createTermNotInPreferredTerms(T term, List<T> preferredTerms) {
393 389
		terms.add(term);
394 390
		populateTerms();
395 391
	}
396 392

  
397
	/** {@inheritDoc} */
398 393
	@Override
399 394
    public void widgetSelected(SelectionEvent e) {
400 395
	    if (e.getSource().equals(combo) && combo.getSelectionIndex() >= 0){
......
402 397
	        selection = terms.get(combo.getSelectionIndex());
403 398
	        firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
404 399
	    }
405

  
406 400
	}
407 401

  
408
	/** {@inheritDoc} */
409 402
	@Override
410 403
    public void propertyChange(PropertyChangeEvent event) {
411 404
		super.propertyChange(event);
......
452 445
	        }
453 446
	    }
454 447
	}
455

  
456
}
448
}

Also available in: Unified diff