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.
9 package eu
.etaxonomy
.taxeditor
.propertysheet
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.ui
.views
.properties
.PropertySheetEntry
;
14 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
15 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
18 * Redraws editor / freetext area when a value in the property sheet changes.
20 * Also includes a lovely little hack to enable custom sorting:
22 * GetDisplayName is called by two methods from the PropertySheetViewer, which
24 * <li>we are not allowed to set, and</li>
25 * <li>uses a comparator which sorts alphabetically.</li>
27 * So we set display names in the PropertySourceDescriptors as "01:Uninomial",
28 * "02:Specific Epithet"; if we ascertain from the stack trace that a "compare"
29 * method is asking for the display name, we return the uncut version for
30 * sorting; when any other method requests a display name, we chop off the ":"
31 * and everything before it.
37 public class EditorPropertySheetEntry
extends PropertySheetEntry
{
38 private static final Logger logger
= Logger
39 .getLogger(EditorPropertySheetEntry
.class);
43 protected PropertySheetEntry
createChildEntry() {
44 return new EditorPropertySheetEntry(taxon
);
47 public EditorPropertySheetEntry(Taxon taxon
) {
54 * @see org.eclipse.ui.views.properties.PropertySheetEntry#getDisplayName()
56 public String
getDisplayName() {
58 String displayName
= super.getDisplayName();
60 Thread currentThread
= Thread
.currentThread();
62 // currentThread.getStackTrace()[0] = call to getStackTrace
63 // currentThread.getStackTrace()[1] = getDisplayName
64 // currentThread.getStackTrace()[2] = who is calling getDisplayName
65 StackTraceElement stackRequestingName
= currentThread
.getStackTrace()[2];
67 if (stackRequestingName
.toString().lastIndexOf("compare") != -1) {
71 return truncateDisplayName(displayName
);
75 * Display names take the form "01:xxxx" to allow sorting. This method
76 * truncates everything before the colon, and is marked <i>public</i>
77 * to allow consistent truncation of property sheet id's.
82 public static String
truncateDisplayName(String displayName
) {
83 int colon
= displayName
.lastIndexOf(':');
85 displayName
= displayName
.substring(colon
+ 1);
90 protected void valueChanged(PropertySheetEntry child
) {
92 super.valueChanged(child
);
94 // If this is the top level of the property sheet, redraw the freetext area
95 if (getParent() == null) {
96 EditorController
.redraw(taxon
);