/**
- *
+ *
*/
package eu.etaxonomy.taxeditor.ui.section;
import java.util.Arrays;
+import java.util.EnumSet;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
import eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement;
/**
*
*/
public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentifiableEntity> extends
- AbstractCdmDetailElement<T> {
-
- protected ToggleableTextElement toggleable_cache;
-
- public AbstractIdentifiableEntityDetailElement(CdmFormFactory formFactory,
- ICdmFormElement formElement) {
- super(formFactory, formElement);
- }
-
- public void updateToggleableCacheField(){
- if(! getEntity().isProtectedTitleCache()){
- toggleable_cache.setText(getEntity().generateTitle());
- }
- }
-
- protected void handleToggleableCacheField(){
- boolean pushedState = toggleable_cache.getState();
-
- getEntity().setTitleCache(toggleable_cache.getText(),
- pushedState);
- setIrrelevant(pushedState,
- Arrays.asList(new Object[] { toggleable_cache }));
- updateToggleableCacheField();
- }
+ AbstractCdmDetailElement<T> {
+
+ /**
+ *
+ */
+ private static final EnumSet<CRUD> UPDATE = EnumSet.of(CRUD.UPDATE);
+ protected ToggleableTextElement toggleable_cache;
+ protected boolean isAdvancedView ;
+
+ public AbstractIdentifiableEntityDetailElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
+ super(formFactory, formElement);
+ updateToggleableCacheState();
+ initIsAdvancedDetailsView();
+
+ }
+
+ public void updateToggleableCacheField() {
+ if (toggleable_cache != null){
+ if (!getEntity().isProtectedTitleCache()) {
+ toggleable_cache.setText(getEntity().generateTitle());
+ }
+ }
+ }
+
+ protected void handleToggleableCacheField() {
+ boolean pushedState = toggleable_cache.getState();
+
+ getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
+ setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache }));
+ updateToggleableCacheField();
+ }
+
+
+ @Override
+ protected void updateControlStates(){
+ super.updateControlStates();
+ updateToggleableCacheState();
+ }
+
+
+ private void updateToggleableCacheState() {
+ if(toggleable_cache != null){
+ toggleable_cache.setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission((CdmBase) getEntity(), UPDATE));
+ }
+ }
+ protected void initIsAdvancedDetailsView(){
+ if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_SIMPLE_NAME_DETAILS_SECTION)){
+ isAdvancedView = false;
+ } else{
+ isAdvancedView = true;
+ }
+ }
+
+
}