Merge branch 'release/4.4.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / taxon / TaxonBaseDetailElement.java
index c166c9d2a1c2f31c544b96816a715411058033d1..39cf141f29c3c9353122daee0ca9edf13aadba03 100644 (file)
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -16,20 +16,23 @@ import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.SWT;
 
 import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.SynonymType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
 /**
- * <p>
- * TaxonBaseDetailElement class.
- * </p>
- * 
  * @author n.hoffmann
  * @created Feb 26, 2010
  * @version 1.0
@@ -42,26 +45,16 @@ public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElem
 
        private EntitySelectionElement<Reference> selection_secundum;
 
+       private TextWithLabelElement text_secundum_microreference;
+
        private TextWithLabelElement text_appendedPhrase;
 
-       private CheckboxElement checkbox_excluded;
-
-       private CheckboxElement checkbox_unplaced;
-
-       /**
-        * <p>
-        * Constructor for TaxonBaseDetailElement.
-        * </p>
-        * 
-        * @param cdmFormFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
-        *            object.
-        * @param formElement
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
-        *            object.
-        * @param style
-        *            a int.
-        */
+       private CheckboxElement checkbox_published;
+
+    private TermComboElement<SynonymType> combo_relationshipType;
+    private CheckboxElement checkProParte;
+    private CheckboxElement checkPartial;
+
        public TaxonBaseDetailElement(CdmFormFactory cdmFormFactory,
                        ICdmFormElement formElement, int style) {
                super(cdmFormFactory, formElement);
@@ -69,44 +62,77 @@ public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElem
 
        /** {@inheritDoc} */
        @Override
-       protected void createControls(ICdmFormElement formElement,
-                       TaxonBase entity, int style) {
-               toggleable_cache = formFactory.createToggleableTextField(formElement,
-                               "Title Cache", entity.getTitleCache(),
-                               entity.isProtectedTitleCache(), style);
-
-               selection_secundum = formFactory
-               .createSelectionElement(Reference.class,
+       protected void createControls(ICdmFormElement formElement, TaxonBase entity, int style) {
+                       toggleable_cache = formFactory.createToggleableTextField(formElement,
+                                       "Title Cache", entity.getTitleCache(),
+                                       entity.isProtectedTitleCache(), style);
+
+               //TODO RL
+               boolean rl=true;
+               if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
+                       toggleable_cache.setVisible(false);
+               }
+               if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
+                       text_appendedPhrase = formFactory.createTextWithLabelElement(
+                                       formElement, "Appended Phrase", entity.getAppendedPhrase(),
+                                       SWT.WRAP);
+
+               }
+
+               selection_secundum = formFactory.createSelectionElement(Reference.class,
                                getConversationHolder(), formElement, "Secundum",
                                entity.getSec(), EntitySelectionElement.ALL,
                                style);
-               
-               text_appendedPhrase = formFactory.createTextWithLabelElement(
-                               formElement, "Appended Phrase", entity.getAppendedPhrase(),
-                               SWT.NULL);
-               checkbox_useNameCache = formFactory.createCheckbox(formElement,
-                               "Exclude Authorship", entity.isUseNameCache(), style);
-               
+
+               text_secundum_microreference = formFactory.createTextWithLabelElement(
+                formElement, "Detail",
+               entity.getSecMicroReference(),null,
+                SWT.WRAP);
+
+               // TODO RL
+               if (!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)) {
+                       checkbox_useNameCache = formFactory.createCheckbox(formElement,
+                                       "Exclude Authorship", entity.isUseNameCache(), style);
+                       checkbox_doubtful = formFactory.createCheckbox(formElement,
+                                       entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
+               }
+
                if (entity instanceof Taxon) {
-                       checkbox_excluded = formFactory.createCheckbox(formElement,
-                                       "Taxon is excluded", ((Taxon) entity).isExcluded(), style);
-                       checkbox_unplaced = formFactory.createCheckbox(formElement,
-                                       "Taxon is unplaced", ((Taxon) entity).isUnplaced(), style);
+                       checkbox_published = formFactory.createCheckbox(formElement,
+                                       "Taxon is published", ((Taxon) entity).isPublish(), style);
+               }
+
+               if(entity instanceof Synonym){
+                   //#6198 removed type as it is currently not handled correctly in the editor
+//                 combo_relationshipType = formFactory.createDefinedTermComboElement(TermType.SynonymType, formElement, "Synonym Type", ((Synonym) entity).getType(), style);
+               checkProParte = formFactory.createCheckbox(formElement, "Pro Parte Synonym", ((Synonym) entity).isProParte(), style);
+               checkPartial= formFactory.createCheckbox(formElement, "Partial Synonym", ((Synonym) entity).isPartial(), style);
                }
-               
-               checkbox_doubtful = formFactory.createCheckbox(formElement,
-                               entity.getClass().getSimpleName() + " is doubtful", entity.isDoubtful(), style);
        }
 
-       /** {@inheritDoc} */
+    private void updateCheckboxPublish() {
+        if(getEntity() instanceof Taxon){
+            checkbox_published.setEnabled(
+                       CdmStore.currentAuthentiationHasOneOfRoles(Role.ROLE_PUBLISH, Role.ROLE_ADMIN)
+                       );
+        }
+    }
+
+       @Override
+    protected void updateControlStates() {
+        super.updateControlStates();
+        updateCheckboxPublish();
+    }
+
+    /** {@inheritDoc} */
        @Override
        protected void updateContent() {
                super.updateContent();
                toggleable_cache.setEnabled(getEntity().isProtectedTitleCache());
                setIrrelevant(toggleable_cache.getState(),
-                               Arrays.asList(new Object[] { toggleable_cache }));
+                               Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
        }
-       
+
        @Override
        protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
                String title = getEntity().generateTitle();
@@ -117,20 +143,34 @@ public class TaxonBaseDetailElement extends AbstractIdentifiableEntityDetailElem
        /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
-               if (eventSource.equals(toggleable_cache)) {
+               if (eventSource== toggleable_cache) {
                        handleToggleableCacheField();
-               } else if (eventSource.equals(checkbox_doubtful)) {
+               } else if (eventSource == checkbox_doubtful) {
                        getEntity().setDoubtful(checkbox_doubtful.getSelection());
-               } else if (eventSource.equals(checkbox_useNameCache)) {
+               } else if (eventSource == checkbox_useNameCache) {
                        getEntity().setUseNameCache(checkbox_useNameCache.getSelection());
-               } else if (eventSource.equals(selection_secundum)) {
+               } else if (eventSource == selection_secundum) {
                        getEntity().setSec(selection_secundum.getSelection());
-               } else if (eventSource.equals(text_appendedPhrase)) {
+               } else if (eventSource == text_appendedPhrase) {
                        getEntity().setAppendedPhrase(text_appendedPhrase.getText());
-               } else if (eventSource == checkbox_excluded) {
-                       ((Taxon) getEntity()).setExcluded(checkbox_excluded.getSelection());
-               } else if (eventSource == checkbox_unplaced) {
-                       ((Taxon) getEntity()).setUnplaced(checkbox_unplaced.getSelection());
-               }
+               } else if (eventSource == text_secundum_microreference) {
+            getEntity().setSecMicroReference(text_secundum_microreference.getText());
+               } else if (eventSource == checkbox_published) {
+                   ((Taxon)getEntity()).setPublish(checkbox_published.getSelection());
+               } else if(eventSource == combo_relationshipType){
+            ((Synonym) getEntity()).setType(combo_relationshipType.getSelection());
+        } else if(eventSource == checkPartial){
+            ((Synonym) getEntity()).setPartial(checkPartial.getSelection());
+        } else if(eventSource == checkProParte){
+            ((Synonym) getEntity()).setProParte(checkProParte.getSelection());
+        }
        }
+       @Override
+       protected void handleToggleableCacheField() {
+        boolean pushedState = toggleable_cache.getState();
+
+        getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
+        setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
+        updateToggleableCacheField();
+    }
 }