3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.bulkeditor
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Comparator
;
15 import java
.util
.List
;
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
;
27 * @created Dec 14, 2010
30 public class BulkEditorSortCombo
{
36 private List
<IBulkEditorSortProvider
> sortProviders
;
38 private List
<Comparator
> comparators
= new ArrayList
<Comparator
>();
40 private int selectedIndex
= 0;
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");
51 combo
= new Combo(parent
, SWT
.DROP_DOWN
);
60 private void fillCombo() {
61 for(IBulkEditorSortProvider sortProvider
: sortProviders
){
62 Set
<String
> names
= sortProvider
.getComparatorNames();
63 for(String name
: names
){
65 comparators
.add(sortProvider
.getComparatorByName(name
));
69 combo
.addSelectionListener(new SelectionListener());
70 combo
.select(selectedIndex
);
73 private class SelectionListener
extends SelectionAdapter
{
75 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
78 public void widgetSelected(SelectionEvent e
) {
79 selectedIndex
= combo
.getSelectionIndex();
86 public Comparator
getSelection() {
87 return comparators
.get(selectedIndex
);