Add flag for displaying choose action in name details view #5260
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / NonViralNameDetailSection.java
index 4f4c09e06ef72de7927395d69682a0d90195c6d6..9a02d8f98d514b01315b30a4767b272ca9265ea9 100644 (file)
@@ -44,6 +44,7 @@ public class NonViralNameDetailSection extends AbstractCdmDetailSection<NonViral
                implements ITaxonBaseDetailSection {
 
        private TaxonBase taxonBase;
+       boolean nameChoosable = false;
 
        /**
         * <p>Constructor for NonViralNameDetailSection.</p>
@@ -52,41 +53,45 @@ public class NonViralNameDetailSection extends AbstractCdmDetailSection<NonViral
         * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
         * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
         * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
+        * @param nameChoosable if <code>true</code> adds a button to choose the displayed name
         * @param style a int.
         */
        public NonViralNameDetailSection(CdmFormFactory formFactory, ConversationHolder conversation,
-                       ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
+                       ICdmFormElement parentElement, ISelectionProvider selectionProvider, boolean nameChoosable, int style) {
                super(formFactory, conversation, parentElement, selectionProvider, style);
+               this.nameChoosable = nameChoosable;
        }
 
        @Override
        protected Control createToolbar() {
-               ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
-               //choose name
-               Action chooseNameAction = new Action("Choose Name", IAction.AS_PUSH_BUTTON){
-                   @Override
-                   public void run() {
-                       TaxonNameBase taxonName = NameSelectionDialog.select(getShell(), getConversationHolder(), null);
-                       if(taxonName!=null){
-                           if(taxonName.isInstanceOf(NonViralName.class)){
-                               CdmStore.getService(ITaxonNodeService.class).list(TaxonNode.class, null, null, null, null);
-                               NonViralName nonViralName = HibernateProxyHelper.deproxy(taxonName, NonViralName.class);
-                               taxonBase.setName(nonViralName);
-                               //                                      taxonBase.getTitleCache();
-                               setEntity(nonViralName);
-                               firePropertyChangeEvent(NonViralNameDetailSection.this);
-                           }
-                           else{
-                               MessagingUtils.warningDialog("Invalid name", this, "The selected name can not be used for this taxon.");
-                           }
-                       }
-                   }
-               };
-               chooseNameAction.setToolTipText("Choose name for this taxon");
-               chooseNameAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
-
-               toolBarManager.add(chooseNameAction);
+               ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+               if(nameChoosable){
+                   //choose name
+                   Action chooseNameAction = new Action("Choose Name", IAction.AS_PUSH_BUTTON){
+                       @Override
+                       public void run() {
+                           TaxonNameBase taxonName = NameSelectionDialog.select(getShell(), getConversationHolder(), null);
+                           if(taxonName!=null){
+                               if(taxonName.isInstanceOf(NonViralName.class)){
+                                   CdmStore.getService(ITaxonNodeService.class).list(TaxonNode.class, null, null, null, null);
+                                   NonViralName nonViralName = HibernateProxyHelper.deproxy(taxonName, NonViralName.class);
+                                   taxonBase.setName(nonViralName);
+                                   //                                  taxonBase.getTitleCache();
+                                   setEntity(nonViralName);
+                                   firePropertyChangeEvent(NonViralNameDetailSection.this);
+                               }
+                               else{
+                                   MessagingUtils.warningDialog("Invalid name", this, "The selected name can not be used for this taxon.");
+                               }
+                           }
+                       }
+                   };
+                   chooseNameAction.setToolTipText("Choose name for this taxon");
+                   chooseNameAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
+
+                   toolBarManager.add(chooseNameAction);
+           }
 
                //clone
                if(getEntity() != null && checkForMultipleNameUsages(getEntity())){