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
.Comparator
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.swt
.SWT
;
17 import org
.eclipse
.swt
.widgets
.Menu
;
18 import org
.eclipse
.swt
.widgets
.MenuItem
;
19 import org
.eclipse
.ui
.IEditorInput
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
23 import eu
.etaxonomy
.taxeditor
.annotatedlineeditor
.IdentifiableEntityComparator
;
24 import eu
.etaxonomy
.taxeditor
.bulkeditor
.input
.ReferenceEditorInput
;
27 * <p>BulkEditorSortMenuProvider class.</p>
33 public class BulkEditorSortMenuProvider
implements IBulkEditorSortMenuProvider
{
34 private static final Logger logger
= Logger
35 .getLogger(BulkEditorSortMenuProvider
.class);
38 * @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortMenuProvider#fillMenu(org.eclipse.ui.IEditorInput, java.awt.Menu)
41 public Menu
fillMenu(IEditorInput input
, Menu menu
) {
42 addMenuItem(menu
, "Title cache", new IdentifiableEntityComparator(), true);
44 if (input
instanceof ReferenceEditorInput
) {
45 addMenuItem(menu
, "Year", new ReferenceYearComparator(), false);
48 if (input
instanceof ReferenceEditorInput
) {
49 addMenuItem(menu
, "Reference Type", new ReferenceTypeComparator(), false);
58 * @param identifiableEntityComparator
61 private MenuItem
addMenuItem(Menu menu
, String text
, Comparator comparator
, boolean selected
) {
62 MenuItem menuItem
= new MenuItem(menu
, SWT
.CHECK
);
63 menuItem
.setText(text
);
64 menuItem
.setData(comparator
);
65 menuItem
.setSelection(selected
);
69 class ReferenceYearComparator
implements Comparator
{
75 private String
getYearString(Object o
) {
76 TimePeriod datePublished
= o
== null || !(o
instanceof Reference
) ?
77 null : ((Reference
) o
).getDatePublished();
78 return datePublished
== null?
null : datePublished
.toString();
82 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
84 public int compare(Object o1
, Object o2
) {
85 String yearString1
= getYearString(o1
);
86 String yearString2
= getYearString(o2
);
87 if (yearString1
== null) {
88 if (yearString2
== null) {
94 if (yearString2
== null) {
97 int returnVal
= yearString1
.compareToIgnoreCase(yearString2
);
99 return new IdentifiableEntityComparator().compare(o1
, 02);
106 class ReferenceTypeComparator
implements Comparator
{
109 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
111 public int compare(Object o1
, Object o2
) {
112 String typeString1
= o1
.getClass().toString();
113 String typeString2
= o2
.getClass().toString();
114 if (typeString1
== null) {
115 if (typeString2
== null) {
121 if (typeString2
== null) {
124 int returnVal
= typeString1
.compareToIgnoreCase(typeString2
);
125 if (returnVal
== 0) {
126 return new IdentifiableEntityComparator().compare(o1
, 02);