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.navigation.navigator;
|
12
|
|
13
|
import org.eclipse.jface.viewers.ColumnLabelProvider;
|
14
|
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
|
15
|
import org.eclipse.jface.viewers.ILabelProvider;
|
16
|
import org.eclipse.jface.viewers.StyledString;
|
17
|
import org.eclipse.jface.viewers.StyledString.Styler;
|
18
|
import org.eclipse.swt.graphics.Image;
|
19
|
import org.eclipse.swt.graphics.TextStyle;
|
20
|
import org.eclipse.ui.navigator.IDescriptionProvider;
|
21
|
import org.hibernate.LazyInitializationException;
|
22
|
|
23
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
24
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
25
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
28
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
29
|
import eu.etaxonomy.taxeditor.preference.Resources;
|
30
|
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
33
|
|
34
|
/**
|
35
|
* <p>TaxonNodeLabelProvider class.</p>
|
36
|
*
|
37
|
* @author p.ciardelli
|
38
|
* @created 04.06.2009
|
39
|
*/
|
40
|
public class TaxonNodeLabelProvider extends ColumnLabelProvider
|
41
|
implements ILabelProvider, IDescriptionProvider, IStyledLabelProvider {
|
42
|
|
43
|
|
44
|
private Styler notGrantedStyler = null;
|
45
|
|
46
|
/** {@inheritDoc} */
|
47
|
@Override
|
48
|
public Image getImage(Object element) {
|
49
|
return null;
|
50
|
}
|
51
|
|
52
|
/** {@inheritDoc} */
|
53
|
@Override
|
54
|
public String getText(Object element) {
|
55
|
if (element instanceof TaxonNode){
|
56
|
TaxonNode taxonNode = (TaxonNode) HibernateProxyHelper.deproxy(element);
|
57
|
|
58
|
try{
|
59
|
Taxon taxon = (Taxon) HibernateProxyHelper.deproxy(taxonNode.getTaxon());
|
60
|
if(taxon == null){
|
61
|
MessagingUtils.error(getClass(), "The taxon node does not have a taxon attached to it. Please check your import. TaxonNode: " + element, null);
|
62
|
// throw new RuntimeException("The data your are trying to view is corrupt. Please check your import.");
|
63
|
}else{
|
64
|
try{
|
65
|
return taxon.getName() != null ? ((IIdentifiableEntity) HibernateProxyHelper.deproxy(taxon.getName())).getTitleCache() : new String();
|
66
|
}catch(Exception e){
|
67
|
MessagingUtils.error(getClass(), e);
|
68
|
}
|
69
|
}
|
70
|
}catch (LazyInitializationException e){
|
71
|
MessagingUtils.error(getClass(), e);
|
72
|
}
|
73
|
|
74
|
}
|
75
|
return new String();
|
76
|
}
|
77
|
|
78
|
/** {@inheritDoc} */
|
79
|
@Override
|
80
|
public String getDescription(Object anElement) {
|
81
|
if (anElement instanceof TaxonNode) {
|
82
|
Taxon data = ((TaxonNode) anElement).getTaxon();
|
83
|
return "Taxon: " + (data != null ? data.getTitleCache() : ">NO TAXON<");
|
84
|
}
|
85
|
return null;
|
86
|
}
|
87
|
|
88
|
/** {@inheritDoc} */
|
89
|
@Override
|
90
|
public StyledString getStyledText(Object element) {
|
91
|
// determine style base on user grants
|
92
|
Styler styler = null;
|
93
|
if(!CdmStore.currentAuthentiationHasPermission((CdmBase) element, RequiredPermissions.TAXONNODE_EDIT)){
|
94
|
styler = getNotGrantedStyler();
|
95
|
}
|
96
|
return new StyledString(getText(element), styler);
|
97
|
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* @return
|
102
|
*/
|
103
|
private Styler getNotGrantedStyler() {
|
104
|
if (notGrantedStyler == null) {
|
105
|
notGrantedStyler = new Styler() {
|
106
|
@Override
|
107
|
public void applyStyles(TextStyle textStyle) {
|
108
|
textStyle.underline = false;
|
109
|
textStyle.foreground = StoreUtil.getColor(Resources.COLOR_TEXT_DISABLED);
|
110
|
}
|
111
|
};
|
112
|
}
|
113
|
return notGrantedStyler;
|
114
|
}
|
115
|
}
|