Merge branch 'release/5.11.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / e4 / details / DetailsViewerE4.java
index cf596ab418f06bdd287c6de39e387651d6907df9..108d32789e88fe8660093661913a50524ad0214a 100755 (executable)
@@ -57,7 +57,7 @@ import eu.etaxonomy.cdm.model.term.TermTree;
 import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.cdm.model.term.TermVocabulary;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.editor.IDistributionEditor;
+import eu.etaxonomy.taxeditor.editor.IDistributionEditorPart;
 import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
 import eu.etaxonomy.taxeditor.l10n.Messages;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
@@ -146,6 +146,7 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
 
     private ISelection selection;
     private boolean detailsEnabled = true;
+    private Object activePart;
 
     public boolean isDetailsEnabled() {
                return detailsEnabled;
@@ -156,11 +157,7 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
        }
 
        public void setInput(Object input, Object activePart) {
-        if (activePart instanceof IDistributionEditor){
-            detailsEnabled = false;
-        }else{
-            detailsEnabled = true;
-        }
+           this.activePart = activePart;
         setInput(input);
 
     }
@@ -292,7 +289,7 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
             if (isUseDescription == true && input instanceof CategoricalData) {
                 createUseRecordSection(rootElement);
             } else {
-                createDescriptionElementSection(rootElement);
+                createDescriptionElementSection(rootElement, activePart);
             }
 
         } else if (input instanceof Media) {
@@ -432,17 +429,29 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
 
     private void createTaxonSections(RootElement parent) {
         NameDetailsConfigurator config = PreferencesUtil.getPreferredNameDetailsConfiguration();
+//        EnumSet<CRUD> requiredCrud;
+//        if(getInput() == null || StoreUtil.getCdmEntity(getInput()).getId() == 0) {
+//            // new entity, not yet saved
+//            requiredCrud = EnumSet.of(CRUD.CREATE);
+//        } else {
+//            requiredCrud = EnumSet.of(CRUD.UPDATE);
+//        }
+//        boolean hasPermission = CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getInput()), requiredCrud);
+       // detailsEnabled = hasPermission;
         ParsingMessagesSection parsingMessagesSection = formFactory.createParsingMessagesSection(getConversationHolder(), parent, this,
                 StoreUtil.getSectionStyle(ParsingMessagesSection.class, getInput().getClass().getCanonicalName(), true));
-        if (!config.isSimpleDetailsViewActivated()){
+        if (config == null){
             TaxonBaseDetailSection taxonBaseDetailSection = formFactory.createTaxonBaseDetailSection(getConversationHolder(), parent, this,
                     StoreUtil.getSectionStyle(TaxonBaseDetailSection.class, getInput().getClass().getCanonicalName(), true));
             formFactory.createHorizontalSeparator(parent, SWT.BORDER);
+          //  boolean hasPermission = CdmStore.currentAuthentiationHasPermission(getInput(), Operation.UPDATE);
+            taxonBaseDetailSection.setEnabled(detailsEnabled);
             addPart(taxonBaseDetailSection);
         }else{
             if (config.isTaxonSectionActivated()){
                 TaxonBaseDetailSection taxonBaseDetailSection = formFactory.createTaxonBaseDetailSection(getConversationHolder(), parent, this,
                         StoreUtil.getSectionStyle(TaxonBaseDetailSection.class, getInput().getClass().getCanonicalName(), true));
+                taxonBaseDetailSection.setEnabled(detailsEnabled);
                 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
                 addPart(taxonBaseDetailSection);
             }
@@ -451,34 +460,40 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
                 .createNonViralNameDetailSection(getConversationHolder(), parent, this, true,
                         StoreUtil.getSectionStyle(NonViralNameDetailSection.class, getInput().getClass().getCanonicalName(), true));
         formFactory.createHorizontalSeparator(parent, SWT.BORDER);
-        if (!config.isSimpleDetailsViewActivated() || (config.isSimpleDetailsViewActivated() && config.isNomenclaturalReferenceSectionActivated())){
+        nonViralNameSection.setEnabled(detailsEnabled);
+        if (config == null || config.isNomenclaturalReferenceSectionActivated()){
             NomenclaturalReferenceDetailSection referenceDetailSection = formFactory.createNomenclaturalReferenceDetailSection(getConversationHolder(), parent, this,
                     StoreUtil.getSectionStyle(NomenclaturalReferenceDetailSection.class, getInput().getClass().getCanonicalName(), true));
+            referenceDetailSection.setEnabled(detailsEnabled);
             formFactory.createHorizontalSeparator(parent, SWT.BORDER);
             addPart(referenceDetailSection);
 
         }
-        if ( !config.isSimpleDetailsViewActivated() || (config.isSimpleDetailsViewActivated() && config.isNomenclaturalStatusSectionActivated())){
+        if ( config == null || config.isNomenclaturalStatusSectionActivated()){
             NomenclaturalStatusSection nomenclaturalStatusSection = formFactory.createNomenclaturalStatusSection(getConversationHolder(), parent,
                     StoreUtil.getSectionStyle(NomenclaturalStatusSection.class, getInput().getClass().getCanonicalName(), true));
+            nomenclaturalStatusSection.setEnabled(detailsEnabled);
             formFactory.createHorizontalSeparator(parent, SWT.BORDER);
             addPart(nomenclaturalStatusSection);
         }
 
-        if ( !config.isSimpleDetailsViewActivated() || (config.isSimpleDetailsViewActivated() && config.isProtologueActivated())){
+        if ( config == null || config.isProtologueActivated()){
             ProtologueSection protologSection = formFactory.createProtologueSection(getConversationHolder(), parent, StoreUtil.getSectionStyle(ProtologueSection.class, getInput().getClass().getCanonicalName()));
+            protologSection.setEnabled(detailsEnabled);
             formFactory.createHorizontalSeparator(parent, SWT.BORDER);
             addPart(protologSection);
         }
 
-        if (!config.isSimpleDetailsViewActivated() || (config.isSimpleDetailsViewActivated() && config.isTypeDesignationSectionActivated())){
+        if (config == null || config.isTypeDesignationSectionActivated()){
             TypeDesignationSection typeDesignationSection = formFactory.createTypeDesignationSection(getConversationHolder(), parent, StoreUtil.getSectionStyle(TypeDesignationSection.class, getInput().getClass().getCanonicalName()));
+            typeDesignationSection.setEnabled(detailsEnabled);
             formFactory.createHorizontalSeparator(parent, SWT.BORDER);
             addPart(typeDesignationSection);
         }
 
-        if (!config.isSimpleDetailsViewActivated() || (config.isSimpleDetailsViewActivated() &&config.isNameRelationsSectionActivated())){
+        if (config == null || config.isNameRelationsSectionActivated()){
             NameRelationshipDetailSection nameRelationshipSection = formFactory.createNameRelationshipDetailSection(getConversationHolder(), parent, StoreUtil.getSectionStyle(NameRelationshipDetailSection.class, getInput().getClass().getCanonicalName()));
+            nameRelationshipSection.setEnabled(detailsEnabled);
             formFactory.createHorizontalSeparator(parent, SWT.BORDER);
             addPart(nameRelationshipSection);
         }
@@ -547,14 +562,24 @@ public class DetailsViewerE4 extends AbstractCdmDataViewerE4 {
     }
 
     private void createDescriptionElementSection(RootElement parent) {
+        createDescriptionElementSection(parent, null);
+    }
+
+    private void createDescriptionElementSection(RootElement parent, Object activePart) {
         DescriptionElementDetailSection descriptionElementDetailSection = formFactory.createDescriptionElementDetailSection(getConversationHolder(), parent, this, StoreUtil.getSectionStyle(DescriptionElementDetailSection.class, getInput().getClass().getCanonicalName(), true));
         descriptionElementDetailSection.setEnabled(this.detailsEnabled);
 
         //  IntextReferenceSection intextReferenceSection = formFactory.createIntextReferenceSection(getConversationHolder(), parent,  getSectionStyle(.class, getInput().getClass().getCanonicalName()));
 
         formFactory.createHorizontalSeparator(parent, SWT.BORDER);
+        DescriptionElementSourceSection descriptionElementSourceSection;
+        if (activePart != null && activePart instanceof IDistributionEditorPart){
+            Reference defaultSource =((IDistributionEditorPart)activePart).getEditor().getDefaultSource();
+            descriptionElementSourceSection = formFactory.createDescriptionElementSourceSection(getConversationHolder(), parent, defaultSource, StoreUtil.getSectionStyle(DescriptionElementSourceSection.class, getInput().getClass().getCanonicalName()));
+        }else{
+            descriptionElementSourceSection = formFactory.createDescriptionElementSourceSection(getConversationHolder(), parent, StoreUtil.getSectionStyle(DescriptionElementSourceSection.class, getInput().getClass().getCanonicalName()) );
+        }
 
-        DescriptionElementSourceSection descriptionElementSourceSection = formFactory.createDescriptionElementSourceSection(getConversationHolder(), parent, StoreUtil.getSectionStyle(DescriptionElementSourceSection.class, getInput().getClass().getCanonicalName()));
 
         formFactory.createHorizontalSeparator(parent, SWT.BORDER);