-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
package eu.etaxonomy.taxeditor.ui.section;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Observable;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.LoginManager;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
+import eu.etaxonomy.taxeditor.ui.element.LabelElement;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
/**
- * <p>
- * Abstract AbstractCdmDetailElement class.
- * </p>
*
* @author n.hoffmann
* @created Feb 26, 2010
- * @version 1.0
*/
-public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement implements ICdmDetailElement<T>, Observer {
+public abstract class AbstractCdmDetailElement<T> extends AbstractCdmFormElement implements ICdmDetailElement<T>, Observer{
private T entity;
private boolean irrelevant;
+ private boolean enabled = true;
+
+ private LabelElement warnForReferencedObjects;
+
private EnumSet<CRUD> requiredCrud = null;
- /**
- * <p>
- * Constructor for AbstractCdmDetailElement.
- * </p>
- *
- * @param formFactory
- * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
- * object.
- * @param formElement
- * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
- * object.
- * @param <T>
- * a T object.
- */
public AbstractCdmDetailElement(CdmFormFactory formFactory,
ICdmFormElement formElement) {
super(formFactory, formElement);
@Override
public void setEntity(T entity) {
this.entity = entity;
- if(StoreUtil.getCdmEntity(getEntity()).getCreatedBy() == null) {
- // new entity, not yet persisted to the database
+ // the id is always 0 if the entity was not yet saved, so it is new in this case
+ if(getEntity() == null || StoreUtil.getCdmEntity(getEntity()).getId() == 0) {
+ // new entity, not yet saved
requiredCrud = EnumSet.of(CRUD.CREATE);
} else {
requiredCrud = EnumSet.of(CRUD.UPDATE);
updateContent();
}
- /*
- * (non-Javadoc)
- *
- * @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity()
- */
- /**
- * <p>
- * Getter for the field <code>entity</code>.
- * </p>
- *
- * @return a T object.
- */
@Override
public T getEntity() {
return entity;
*/
protected void updateContent() {
removeElements();
- createControls(this, entity, SWT.WRAP);
- getLayoutComposite().layout();
-
+ createControls(this, entity, SWT.NONE);
+// StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
updateControlStates();
}
- /*
- * (non-Javadoc)
- *
- * @see
- * eu.etaxonomy.taxeditor.forms.ISelectableComposite#setSelected(boolean)
- */
- /** {@inheritDoc} */
- @Override
+ @Override
public void setSelected(boolean selected) {
Composite section = getLayoutComposite().getParent();
section.setBackground(selected ? SELECTED : getPersistentBackground());
* a {@link java.util.Collection} object.
*/
public void setEnabled(boolean enabled, Collection<Object> except) {
+ this.enabled = enabled;
for (ICdmFormElement element : getElements()) {
if (element instanceof IEnableableFormElement) {
IEnableableFormElement enableableElement = (IEnableableFormElement) element;
}
}
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
/**
* <p>
* Setter for the field <code>irrelevant</code>.
ICdmFormElement eventElement = (ICdmFormElement) eventSource;
ICdmFormElement eventElementContainer = eventElement
.getParentElement();
-
+ ICdmFormElement parent = this.getParentElement();
if (eventElementContainer == this) {
if (event instanceof CdmPropertyChangeEvent) {
if (((CdmPropertyChangeEvent) event).hasException()) {
}
protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
- boolean isRelevant = getEntity() instanceof TaxonNameBase
+ boolean isRelevant = getEntity() instanceof TaxonName
|| getEntity() instanceof TaxonBase;
isRelevant &= this instanceof AbstractIdentifiableEntityDetailElement;
if (isRelevant) {
((AbstractIdentifiableEntityDetailElement) this)
.updateToggleableCacheField();
- updateParentSection();
}
}
if (getParentElement() instanceof AbstractCdmDetailSection) {
((AbstractCdmDetailSection) getParentElement()).updateTitle();
}
+ //NOTE: This slows down the rendering of the details view
+// StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
}
/**
*/
public abstract void handleEvent(Object eventSource);
- /**
- * <p>
- * handleException
- * </p>
- *
- * @param event
- * a
- * {@link eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent}
- * object.
- */
public void handleException(CdmPropertyChangeEvent event) {
// override this in subclasses if you want to deal with the error
- AbstractUtility.error(event.getSource().getClass(), event.getException());
+ MessagingUtils.error(event.getSource().getClass(), event.getException());
}
- /**
- * <p>
- * isIrrelevant
- * </p>
- *
- * @return a boolean.
- */
public boolean isIrrelevant() {
return irrelevant;
}
- /**
- * <p>
- * getConversationHolder
- * </p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
- * object.
- */
@Override
public ConversationHolder getConversationHolder() {
if (getParentElement() instanceof IConversationEnabled) {
protected void updateControlStates(){
- setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud));
+ Collection<Object> except = new ArrayList<Object>();
+ for(ICdmFormElement formElement:getElements()){
+ if(formElement instanceof IEnableableFormElement && !((IEnableableFormElement) formElement).isEnabled()){
+ except.add(formElement);
+ }
+ }
+ setEnabled(getEntity() != null && CdmStore.currentAuthentiationHasPermission(StoreUtil.getCdmEntity(getEntity()), requiredCrud), except);
}
+
+ public LabelElement getWarnForReferencedObjects() {
+ return warnForReferencedObjects;
+ }
+
+ public void setWarnForReferencedObjects(LabelElement warnForReferencedObjects) {
+ this.warnForReferencedObjects = warnForReferencedObjects;
+ }
+
+ 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 > 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));
+ getWarnForReferencedObjects().setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
+
+ }
+ }
+ }
+ }
+
+ public void setWarnForReferencingObjects(ICdmFormElement formElement){
+ setWarnForReferencingObjects(formElement, 1);
+ }
+
+ public void setWarnForReferencingObjectsVisible(boolean isVisible){
+ if (getWarnForReferencedObjects() != null){
+ getWarnForReferencedObjects().setVisible(isVisible);
+ }
+ }
+
}