Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorSortMenuProvider.java | ||
---|---|---|
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.Comparator; |
|
14 |
|
|
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; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
22 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
|
23 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.IdentifiableEntityComparator; |
|
24 |
import eu.etaxonomy.taxeditor.bulkeditor.input.ReferenceEditorInput; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author p.ciardelli |
|
28 |
* @created 19.08.2009 |
|
29 |
* @version 1.0 |
|
30 |
*/ |
|
31 |
public class BulkEditorSortMenuProvider implements IBulkEditorSortMenuProvider { |
|
32 |
private static final Logger logger = Logger |
|
33 |
.getLogger(BulkEditorSortMenuProvider.class); |
|
34 |
|
|
35 |
/* (non-Javadoc) |
|
36 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortMenuProvider#fillMenu(org.eclipse.ui.IEditorInput, java.awt.Menu) |
|
37 |
*/ |
|
38 |
public Menu fillMenu(IEditorInput input, Menu menu) { |
|
39 |
addMenuItem(menu, "Title cache", new IdentifiableEntityComparator(), true); |
|
40 |
|
|
41 |
if (input instanceof ReferenceEditorInput) { |
|
42 |
addMenuItem(menu, "Year", new ReferenceYearComparator(), false); |
|
43 |
} |
|
44 |
|
|
45 |
if (input instanceof ReferenceEditorInput) { |
|
46 |
addMenuItem(menu, "Reference Type", new ReferenceTypeComparator(), false); |
|
47 |
} |
|
48 |
|
|
49 |
return menu; |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* @param menu |
|
54 |
* @param string |
|
55 |
* @param identifiableEntityComparator |
|
56 |
* @return |
|
57 |
*/ |
|
58 |
private MenuItem addMenuItem(Menu menu, String text, Comparator comparator, boolean selected) { |
|
59 |
MenuItem menuItem = new MenuItem(menu, SWT.CHECK); |
|
60 |
menuItem.setText(text); |
|
61 |
menuItem.setData(comparator); |
|
62 |
menuItem.setSelection(selected); |
|
63 |
return menuItem; |
|
64 |
} |
|
65 |
|
|
66 |
class ReferenceYearComparator implements Comparator { |
|
67 |
|
|
68 |
/** |
|
69 |
* @param o1 |
|
70 |
* @return |
|
71 |
*/ |
|
72 |
private String getYearString(Object o) { |
|
73 |
TimePeriod datePublished = o == null || !(o instanceof ReferenceBase) ? |
|
74 |
null : ((ReferenceBase) o).getDatePublished(); |
|
75 |
return datePublished == null? null : datePublished.toString(); |
|
76 |
} |
|
77 |
|
|
78 |
/* (non-Javadoc) |
|
79 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
80 |
*/ |
|
81 |
public int compare(Object o1, Object o2) { |
|
82 |
String yearString1 = getYearString(o1); |
|
83 |
String yearString2 = getYearString(o2); |
|
84 |
if (yearString1 == null) { |
|
85 |
if (yearString2 == null) { |
|
86 |
return 0; |
|
87 |
} else { |
|
88 |
return -1; |
|
89 |
} |
|
90 |
} |
|
91 |
if (yearString2 == null) { |
|
92 |
return 1; |
|
93 |
} |
|
94 |
int returnVal = yearString1.compareToIgnoreCase(yearString2); |
|
95 |
if (returnVal == 0) { |
|
96 |
return new IdentifiableEntityComparator().compare(o1, 02); |
|
97 |
} else { |
|
98 |
return returnVal; |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
class ReferenceTypeComparator implements Comparator { |
|
104 |
|
|
105 |
/* (non-Javadoc) |
|
106 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
107 |
*/ |
|
108 |
public int compare(Object o1, Object o2) { |
|
109 |
String typeString1 = o1.getClass().toString(); |
|
110 |
String typeString2 = o2.getClass().toString(); |
|
111 |
if (typeString1 == null) { |
|
112 |
if (typeString2 == null) { |
|
113 |
return 0; |
|
114 |
} else { |
|
115 |
return -1; |
|
116 |
} |
|
117 |
} |
|
118 |
if (typeString2 == null) { |
|
119 |
return 1; |
|
120 |
} |
|
121 |
int returnVal = typeString1.compareToIgnoreCase(typeString2); |
|
122 |
if (returnVal == 0) { |
|
123 |
return new IdentifiableEntityComparator().compare(o1, 02); |
|
124 |
} else { |
|
125 |
return returnVal; |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
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.Comparator; |
|
14 |
|
|
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; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
22 |
import eu.etaxonomy.cdm.model.reference.ReferenceBase; |
|
23 |
import eu.etaxonomy.taxeditor.annotatedlineeditor.IdentifiableEntityComparator; |
|
24 |
import eu.etaxonomy.taxeditor.bulkeditor.input.ReferenceEditorInput; |
|
25 |
|
|
26 |
/** |
|
27 |
* <p>BulkEditorSortMenuProvider class.</p> |
|
28 |
* |
|
29 |
* @author p.ciardelli |
|
30 |
* @created 19.08.2009 |
|
31 |
* @version 1.0 |
|
32 |
*/ |
|
33 |
public class BulkEditorSortMenuProvider implements IBulkEditorSortMenuProvider { |
|
34 |
private static final Logger logger = Logger |
|
35 |
.getLogger(BulkEditorSortMenuProvider.class); |
|
36 |
|
|
37 |
/* (non-Javadoc) |
|
38 |
* @see eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorSortMenuProvider#fillMenu(org.eclipse.ui.IEditorInput, java.awt.Menu) |
|
39 |
*/ |
|
40 |
/** {@inheritDoc} */ |
|
41 |
public Menu fillMenu(IEditorInput input, Menu menu) { |
|
42 |
addMenuItem(menu, "Title cache", new IdentifiableEntityComparator(), true); |
|
43 |
|
|
44 |
if (input instanceof ReferenceEditorInput) { |
|
45 |
addMenuItem(menu, "Year", new ReferenceYearComparator(), false); |
|
46 |
} |
|
47 |
|
|
48 |
if (input instanceof ReferenceEditorInput) { |
|
49 |
addMenuItem(menu, "Reference Type", new ReferenceTypeComparator(), false); |
|
50 |
} |
|
51 |
|
|
52 |
return menu; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* @param menu |
|
57 |
* @param string |
|
58 |
* @param identifiableEntityComparator |
|
59 |
* @return |
|
60 |
*/ |
|
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); |
|
66 |
return menuItem; |
|
67 |
} |
|
68 |
|
|
69 |
class ReferenceYearComparator implements Comparator { |
|
70 |
|
|
71 |
/** |
|
72 |
* @param o1 |
|
73 |
* @return |
|
74 |
*/ |
|
75 |
private String getYearString(Object o) { |
|
76 |
TimePeriod datePublished = o == null || !(o instanceof ReferenceBase) ? |
|
77 |
null : ((ReferenceBase) o).getDatePublished(); |
|
78 |
return datePublished == null? null : datePublished.toString(); |
|
79 |
} |
|
80 |
|
|
81 |
/* (non-Javadoc) |
|
82 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
83 |
*/ |
|
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) { |
|
89 |
return 0; |
|
90 |
} else { |
|
91 |
return -1; |
|
92 |
} |
|
93 |
} |
|
94 |
if (yearString2 == null) { |
|
95 |
return 1; |
|
96 |
} |
|
97 |
int returnVal = yearString1.compareToIgnoreCase(yearString2); |
|
98 |
if (returnVal == 0) { |
|
99 |
return new IdentifiableEntityComparator().compare(o1, 02); |
|
100 |
} else { |
|
101 |
return returnVal; |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
class ReferenceTypeComparator implements Comparator { |
|
107 |
|
|
108 |
/* (non-Javadoc) |
|
109 |
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) |
|
110 |
*/ |
|
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) { |
|
116 |
return 0; |
|
117 |
} else { |
|
118 |
return -1; |
|
119 |
} |
|
120 |
} |
|
121 |
if (typeString2 == null) { |
|
122 |
return 1; |
|
123 |
} |
|
124 |
int returnVal = typeString1.compareToIgnoreCase(typeString2); |
|
125 |
if (returnVal == 0) { |
|
126 |
return new IdentifiableEntityComparator().compare(o1, 02); |
|
127 |
} else { |
|
128 |
return returnVal; |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation