1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.ui.section;
|
5
|
|
6
|
import java.util.Arrays;
|
7
|
import java.util.EnumSet;
|
8
|
|
9
|
import org.eclipse.swt.SWT;
|
10
|
import org.eclipse.swt.widgets.Display;
|
11
|
|
12
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
13
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
14
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
15
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
16
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
17
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
18
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
|
23
|
|
24
|
/**
|
25
|
* @author n.hoffmann
|
26
|
*
|
27
|
*/
|
28
|
public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentifiableEntity> extends
|
29
|
AbstractCdmDetailElement<T> {
|
30
|
|
31
|
/**
|
32
|
*
|
33
|
*/
|
34
|
private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
|
35
|
protected ToggleableTextElement toggleable_cache;
|
36
|
protected boolean isAdvancedView ;
|
37
|
|
38
|
public AbstractIdentifiableEntityDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
|
39
|
super(formFactory, formElement);
|
40
|
updateToggleableCacheState();
|
41
|
initIsAdvancedDetailsView();
|
42
|
|
43
|
}
|
44
|
|
45
|
public void updateToggleableCacheField() {
|
46
|
if (toggleable_cache != null){
|
47
|
if (!getEntity().isProtectedTitleCache()) {
|
48
|
toggleable_cache.setText(getEntity().generateTitle());
|
49
|
}
|
50
|
}
|
51
|
}
|
52
|
|
53
|
protected void handleToggleableCacheField() {
|
54
|
boolean pushedState = toggleable_cache.getState();
|
55
|
|
56
|
getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
|
57
|
setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache }));
|
58
|
updateToggleableCacheField();
|
59
|
}
|
60
|
|
61
|
|
62
|
@Override
|
63
|
protected void updateControlStates(){
|
64
|
super.updateControlStates();
|
65
|
updateToggleableCacheState();
|
66
|
}
|
67
|
|
68
|
|
69
|
private void updateToggleableCacheState() {
|
70
|
if(toggleable_cache != null){
|
71
|
toggleable_cache.setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
|
72
|
}
|
73
|
}
|
74
|
protected void initIsAdvancedDetailsView(){
|
75
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION)){
|
76
|
isAdvancedView = false;
|
77
|
} else{
|
78
|
isAdvancedView = true;
|
79
|
}
|
80
|
}
|
81
|
|
82
|
|
83
|
}
|