Project

General

Profile

Download (2.03 KB) Statistics
| Branch: | Tag: | Revision:
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.bulkeditor;
11

    
12
import java.util.ArrayList;
13
import java.util.Comparator;
14
import java.util.List;
15
import java.util.Set;
16

    
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.SelectionAdapter;
19
import org.eclipse.swt.events.SelectionEvent;
20
import org.eclipse.swt.widgets.Combo;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Label;
23

    
24
/**
25
 * @author n.hoffmann
26
 * @created Dec 14, 2010
27
 * @version 1.0
28
 */
29
public class BulkEditorSortCombo {
30

    
31
	private Label label;
32
	
33
	private Combo combo;
34
	
35
	private List<IBulkEditorSortProvider> sortProviders;
36
		
37
	private List<Comparator> comparators = new ArrayList<Comparator>();
38
	
39
	private int selectedIndex = 0;
40
	
41
	/**
42
	 * 
43
	 */
44
	public BulkEditorSortCombo(Composite parent, List<IBulkEditorSortProvider> sortProviders) {
45
		this.sortProviders = sortProviders;
46
		if(! sortProviders.isEmpty()){
47
			label = new Label(parent, SWT.NONE);
48
			label.setText("Sort by");
49
			
50
			combo = new Combo(parent, SWT.DROP_DOWN);
51
			
52
			fillCombo();
53
		}		
54
	}
55
	
56
	/**
57
	 * 
58
	 */
59
	private void fillCombo() {
60
		for(IBulkEditorSortProvider sortProvider : sortProviders){
61
			Set<String> names = sortProvider.getComparatorNames();
62
			for(String name : names){
63
				combo.add(name);
64
				comparators.add(sortProvider.getComparatorByName(name));
65
			}
66
		}
67
		
68
		combo.addSelectionListener(new SelectionListener());
69
		combo.select(selectedIndex);
70
	}
71
	
72
	private class SelectionListener extends SelectionAdapter{
73
		/* (non-Javadoc)
74
		 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
75
		 */
76
		@Override
77
		public void widgetSelected(SelectionEvent e) {
78
			selectedIndex = combo.getSelectionIndex();
79
		}
80
	}
81
	
82
	/**
83
	 * 
84
	 */
85
	public Comparator getSelection() {
86
		return comparators.get(selectedIndex);
87
	}
88
}
(3-3/6)