commit e11bc05e5a52760cf8a8b4099545a8eb7af1e39d
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Sep 27 09:56:08 2018 +0200

    add warning for referencing objects in details view and code cleaning

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElement.java
index 6ed49262a..65401d7ca 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractCdmDetailElement.java
@@ -47,7 +47,7 @@ import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
  * @author n.hoffmann
  * @created Feb 26, 2010
  */
-public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement implements ICdmDetailElement<T>, Observer, IEnableableFormElement{
+public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement implements ICdmDetailElement<T>, Observer{
 
 	private T entity;
 
@@ -106,7 +106,6 @@ public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement
 		removeElements();
 		createControls(this, entity, SWT.NONE);
 		StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
-
 		updateControlStates();
 	}
 
@@ -215,7 +214,7 @@ public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement
 			ICdmFormElement eventElement = (ICdmFormElement) eventSource;
 			ICdmFormElement eventElementContainer = eventElement
 					.getParentElement();
-
+			ICdmFormElement parent = this.getParentElement();
 			if (eventElementContainer == this) {
 				if (event instanceof CdmPropertyChangeEvent) {
 					if (((CdmPropertyChangeEvent) event).hasException()) {
@@ -311,13 +310,13 @@ public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement
 		this.warnForReferencedObjects = warnForReferencedObjects;
 	}
 
-	public void setWarnForReferencingObjects(ICdmFormElement formElement){
+	public void setWarnForReferencingObjects(ICdmFormElement formElement, int defaultReferencingObjects){
 	    if (getEntity() instanceof CdmBase){
 	    	CdmBase cdmBase = (CdmBase) getEntity();
 	    	if (cdmBase.getId() != 0){
 		        long referencingObjectsCount = CdmStore.getCommonService().getReferencingObjectsCount(cdmBase);
 
-	    		if (referencingObjectsCount > 1){
+	    		if (referencingObjectsCount > defaultReferencingObjects){
 	    			setWarnForReferencedObjects(formFactory.createLabel(formElement, CdmUtils.Nz("The "+ cdmBase.getUserFriendlyTypeName()+" is referenced by " + referencingObjectsCount+ " objects, if you change it, it is changed for all these objects")));
 	    			getWarnForReferencedObjects().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
 	    			getWarnForReferencedObjects().setLayout(LayoutConstants.FILL(2, 3));
@@ -328,6 +327,10 @@ public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement
 	    }
 	}
 
+	public void setWarnForReferencingObjects(ICdmFormElement formElement){
+	    setWarnForReferencingObjects(formElement, 1);
+	}
+
 	public void setWarnForReferencingObjectsVisible(boolean isVisible){
 		if (getWarnForReferencedObjects() != null){
 			getWarnForReferencedObjects().setVisible(isVisible);
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java
index a6bbaca09..b8f0c20f6 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java
@@ -16,18 +16,23 @@ import org.eclipse.swt.events.SelectionListener;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.forms.widgets.TableWrapLayout;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
 import eu.etaxonomy.taxeditor.ui.element.ISelectable;
+import eu.etaxonomy.taxeditor.ui.element.LabelElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 
 /**
@@ -57,6 +62,8 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
 
 	private Color backgroundColor;
 
+	private LabelElement warnForReferencedObjects;
+
 	public AbstractEntityCollectionElement(CdmFormFactory formFactory,
 			AbstractFormSection section, ENTITY entity, SelectionListener removeListener,
 			Color backgroundColor, int style) {
@@ -218,4 +225,34 @@ public abstract class AbstractEntityCollectionElement<ENTITY> extends
 	@Override
     public void update(CdmDataChangeMap changeEvents) {
 	}
+
+    public void setWarnForReferencedObjects(LabelElement warnForReferencedObjects) {
+        this.warnForReferencedObjects = warnForReferencedObjects;
+    }
+
+    public void setWarnForReferencingObjects(ICdmFormElement formElement, int defaultReferencingObjects){
+        if (entity instanceof CdmBase){
+            CdmBase cdmBase = (CdmBase)entity;
+            if (cdmBase.getId() != 0){
+                long referencingObjectsCount = CdmStore.getCommonService().getReferencingObjectsCount(cdmBase);
+
+                if (referencingObjectsCount > defaultReferencingObjects){
+                    setWarnForReferencedObjects(formFactory.createLabel(formElement, CdmUtils.Nz("The "+ cdmBase.getUserFriendlyTypeName()+" is referenced by more than one object, if you change it, it is changed for all these objects")));
+                    warnForReferencedObjects.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+                    warnForReferencedObjects.setLayout(LayoutConstants.FILL(2, 3));
+                    warnForReferencedObjects.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+                }
+            }
+        }
+    }
+
+    public void setWarnForReferencingObjects(ICdmFormElement formElement){
+        setWarnForReferencingObjects(formElement, 1);
+    }
+
+    public void setWarnForReferencingObjectsVisible(boolean isVisible){
+        if (warnForReferencedObjects != null){
+            warnForReferencedObjects.setVisible(isVisible);
+        }
+    }
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java
index f555e44f0..c7b262b54 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractIdentifiableEntityDetailElement.java
@@ -6,10 +6,6 @@ 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.cdm.persistence.hibernate.permission.CRUD;
@@ -18,7 +14,6 @@ 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;
 
 /**
@@ -42,6 +37,7 @@ public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentif
 
     }
 
+
     public void updateToggleableCacheField() {
         if (toggleable_cache != null){
             if (!getEntity().isProtectedTitleCache()) {
@@ -79,5 +75,5 @@ public abstract class AbstractIdentifiableEntityDetailElement<T extends IIdentif
         }
     }
 
-    
+
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java
index 623e44e6f..c8d5462cb 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/media/MediaMetaElement.java
@@ -5,14 +5,11 @@ package eu.etaxonomy.taxeditor.ui.section.media;
 
 import java.util.Map;
 
-import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Display;
 
 import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
-import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.common.TimePeriod;
@@ -24,9 +21,7 @@ import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
-import eu.etaxonomy.taxeditor.ui.element.LabelElement;
 import eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement;
-import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
 import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
@@ -46,7 +41,7 @@ public class MediaMetaElement extends AbstractEntityCollectionElement<Media> imp
     private MediaDetailElement mediaDetailElement;
     private TimePeriodElement mediaCreated;
     private SelectionArbitrator selectionArbitrator;
-    private LabelElement warnForReferencedObjects;
+
 
     public MediaMetaElement(CdmFormFactory cdmFormFactory,
             AbstractFormSection<?> formElement, Media element,
@@ -155,34 +150,6 @@ public class MediaMetaElement extends AbstractEntityCollectionElement<Media> imp
         return selectionArbitrator;
     }
 
-    public void setWarnForReferencedObjects(LabelElement warnForReferencedObjects) {
-        this.warnForReferencedObjects = warnForReferencedObjects;
-    }
-
-    public void setWarnForReferencingObjects(ICdmFormElement formElement, int defaultReferencingObjects){
-        if (getEntity() instanceof CdmBase){
-            CdmBase cdmBase = getEntity();
-            if (cdmBase.getId() != 0){
-                long referencingObjectsCount = CdmStore.getCommonService().getReferencingObjectsCount(cdmBase);
-
-                if (referencingObjectsCount > defaultReferencingObjects){
-                    setWarnForReferencedObjects(formFactory.createLabel(formElement, CdmUtils.Nz("The "+ cdmBase.getUserFriendlyTypeName()+" is referenced by more than one object, if you change it, it is changed for all these objects")));
-                    warnForReferencedObjects.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
-                    warnForReferencedObjects.setLayout(LayoutConstants.FILL(2, 3));
-                    warnForReferencedObjects.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
-                }
-            }
-        }
-    }
-
-    public void setWarnForReferencingObjects(ICdmFormElement formElement){
-        setWarnForReferencingObjects(formElement, 1);
-    }
 
-    public void setWarnForReferencingObjectsVisible(boolean isVisible){
-        if (warnForReferencedObjects != null){
-            warnForReferencedObjects.setVisible(isVisible);
-        }
-    }
 
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipDetailElement.java
index 7693ab1d1..a364f6c03 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameRelationshipDetailElement.java
@@ -1,8 +1,8 @@
 /**
 * 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.
 */
@@ -53,7 +53,7 @@ public class NameRelationshipDetailElement extends AbstractReferencedEntityEleme
 			NameRelationship entity, SelectionListener removeListener, int style) {
 		super(cdmFormFactory, formElement, entity, removeListener, style);
 	}
-	
+
 	/* (non-Javadoc)
 	 * @see eu.etaxonomy.taxeditor.forms.entitysections.AbstractEntitySetElementComposite#createControls(org.eclipse.swt.widgets.Composite, int)
 	 */
@@ -61,23 +61,23 @@ public class NameRelationshipDetailElement extends AbstractReferencedEntityEleme
 	@Override
 	public void createControls(ICdmFormElement element, int style) {
 		label = formFactory.createLabel(element, null);
-		
+
 		text_ruleConsidered = formFactory.createTextWithLabelElement(element, "Rule Considered", null, SWT.NULL);
-		
+
 		super.createControls(element, style);
 	}
-	
+
 	/** {@inheritDoc} */
 	@Override
 	public void setEntity(NameRelationship entity) {
 		String text = entity.getFromName().getTitleCache() + " is " + entity.getType().getLabel() + " " + entity.getToName().getTitleCache();
-		
+
 		label.setText(text);
 		text_ruleConsidered.setText(entity.getRuleConsidered());
-		
-		super.setEntity(entity);		
+
+		super.setEntity(entity);
 	}
-	
+
 	/** {@inheritDoc} */
 	@Override
 	public void handleEvent(Object eventSource) {
@@ -97,12 +97,13 @@ public class NameRelationshipDetailElement extends AbstractReferencedEntityEleme
 			getEntity().setCitationMicroReference(text_referenceDetail.getText());
 		}
 	}
-	
+
 	/** {@inheritDoc} */
 	@Override
 	public void setBackground(Color color) {
-		if(label != null)
-			label.setBackground(color);
+		if(label != null) {
+            label.setBackground(color);
+        }
 		super.setBackground(color);
 	}
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java
index 183a093fa..0228174d5 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/reference/ReferenceDetailElement.java
@@ -103,10 +103,7 @@ public class ReferenceDetailElement extends AbstractIdentifiableEntityDetailElem
 	@Override
 	protected void createControls(ICdmFormElement formElement,
 			Reference entity, int style) {
-		if (isWizard){
-		    setWarnForReferencingObjects(formElement);
-		}
-
+		setWarnForReferencingObjects(formElement);
 		toggleable_cache = formFactory.createToggleableTextField(formElement,
 				"Reference Cache", entity.getTitleCache(),
 				entity.isProtectedTitleCache(), style);
