import java.util.ConcurrentModificationException;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.ui.forms.widgets.Section;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
/**
- * <p>Abstract AbstractCdmFormElement class.</p>
- *
* @author n.hoffmann
* @version $Id: $
*/
private Color persistentBackgroundColor;
- /**
- * <p>Constructor for AbstractCdmFormElement.</p>
- *
- * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
- * @param layoutComposite a {@link org.eclipse.swt.widgets.Composite} object.
- */
protected AbstractCdmFormElement(CdmFormFactory formFactory, Composite layoutComposite){
this.layoutComposite = layoutComposite;
this.formFactory = formFactory;
}
- /**
- * <p>Constructor for AbstractCdmFormElement.</p>
- *
- * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
- * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
- */
public AbstractCdmFormElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
this(formFactory, formElement.getLayoutComposite());
this.parentElement = formElement;
controls.add(child);
}
- /**
- * <p>removeControl</p>
- *
- * @param child a {@link org.eclipse.swt.widgets.Control} object.
- */
protected void removeControl(Control child){
controls.remove(child);
}
}
/**
- * <p>removeElement</p>
- *
- * @param element a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
+ * Remove all child {@link ICdmFormElement}s and child {@link Control}s
+ * of the given and the element itself.
+ * @param formElement The element to remove
*/
- protected void removeElement(ICdmFormElement element){
- elements.remove(element);
+ public void removeElementsAndControls(ICdmFormElement formElement){
+ for(ICdmFormElement childElement : formElement.getElements()){
+ // recursion
+ childElement.removeElements();
+
+ // unregister selection arbitrator
+ if(childElement instanceof ISelectableElement){
+ SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+ if(selectionArbitrator != null){
+ formFactory.destroySelectionArbitrator(selectionArbitrator);
+ }
+ }
+
+ // unregister from property changes
+ formFactory.removePropertyChangeListener(childElement);
+
+ // dispose of the controls
+ removeControls(childElement);
+ }
+ removeControls(formElement);
}
/**
- * <p>removeElements</p>
+ * Removes all child {@link ICdmFormElement}s and child {@link Control}s
+ * and the element itself.
*/
@Override
public void removeElements(){
- for(ICdmFormElement childElement : getElements()){
+ for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
+ ICdmFormElement childElement = iterator.next();
// recursion
childElement.removeElements();
// dispose of the controls
removeControls(childElement);
}
+ if(this instanceof ISelectableElement){
+ SelectionArbitrator selectionArbitrator = ((ISelectableElement) this).getSelectionArbitrator();
+ if(selectionArbitrator != null){
+ formFactory.destroySelectionArbitrator(selectionArbitrator);
+ }
+ }
removeControls(this);
elements.clear();
}
this.layoutComposite = layoutComposite;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.forms.ICdmFormComposite#getPropertyChangeListeners()
- */
/**
* <p>Getter for the field <code>propertyChangeListeners</code>.</p>
*
return propertyChangeListeners;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.forms.ICdmFormComposite#setPropertyChangeListeners(org.eclipse.core.runtime.ListenerList)
- */
/** {@inheritDoc} */
@Override
public void setPropertyChangeListeners(List<IPropertyChangeListener> propertyChangeListeners){
this.propertyChangeListeners = propertyChangeListeners;
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.forms.IPropertyChangeEmitter#firePropertyChangeEvent()
- */
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.forms.ICdmFormComposite#firePropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent)
- */
/** {@inheritDoc} */
@Override
public void firePropertyChangeEvent(CdmPropertyChangeEvent event) {
// Described here: http://dev.e-taxonomy.eu/trac/ticket/2363#comment:2
// and here: http://dev.e-taxonomy.eu/trac/ticket/2438
// Ignoring the CME because nothing bad is happening
- AbstractUtility.warn(getClass(), "ConcurrentModificationException. Can be ignored.");
+ MessagingUtils.warn(getClass(), "ConcurrentModificationException. Can be ignored.");
}
}
}
}
- /*
- * (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.forms.ICdmFormElement#refresh()
- */
- /**
- * <p>refresh</p>
- */
@Override
public void refresh() {
// empty default implementation