2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.bulkeditor
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Comparator
;
14 import java
.util
.List
;
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
;
26 * @created Dec 14, 2010
29 public class BulkEditorSortCombo
{
35 private List
<IBulkEditorSortProvider
> sortProviders
;
37 private List
<Comparator
> comparators
= new ArrayList
<Comparator
>();
39 private int selectedIndex
= 0;
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");
50 combo
= new Combo(parent
, SWT
.DROP_DOWN
);
59 private void fillCombo() {
60 for(IBulkEditorSortProvider sortProvider
: sortProviders
){
61 Set
<String
> names
= sortProvider
.getComparatorNames();
62 for(String name
: names
){
64 comparators
.add(sortProvider
.getComparatorByName(name
));
68 combo
.addSelectionListener(new SelectionListener());
69 combo
.select(selectedIndex
);
72 private class SelectionListener
extends SelectionAdapter
{
74 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
77 public void widgetSelected(SelectionEvent e
) {
78 selectedIndex
= combo
.getSelectionIndex();
85 public Comparator
getSelection() {
86 return comparators
.get(selectedIndex
);