Project

General

Profile

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

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

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

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

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