- added AbstractUnboundEntityCollectionSection which allows adding elements to colle...
authorPatric Plitzner <p.plitzner@bgbm.org>
Tue, 21 Jan 2014 14:52:08 +0000 (14:52 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Tue, 21 Jan 2014 14:52:08 +0000 (14:52 +0000)
.gitattributes
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/AbstractEntityCollectionElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AbstractUnboundEntityCollectionSection.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/SequenceReferenceCollectionDetailElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/SequenceReferenceCollectionDetailSection.java

index 8fcd6efa0c4b64d1cfd0ad9966341e3990d04757..39cd847f3926c5835b83b399ee5c8883f2a933a5 100644 (file)
@@ -1535,6 +1535,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occ
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/derivedUnit/PreservedSpecimenGeneralDetailElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/derivedUnit/PreservedSpecimenGeneralDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/derivedUnit/PreservedSpecimenSourceCollectionDetailSection.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AbstractUnboundEntityCollectionSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AmplificationCloningDetailElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AmplificationCloningDetailSection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AmplificationGeneralDetailElement.java -text
index b6e1a416bfc039c687e6b8b9b193bdddf87efd71..02c02ac195cec6e813c55bf9a884ee8c09a00f50 100644 (file)
@@ -33,9 +33,10 @@ import eu.etaxonomy.taxeditor.ui.element.ISelectable;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 
 /**
- * <p>
- * Abstract AbstractEntityCollectionElement class.
- * </p>
+ * Visualizes an element of type ENTITY in an {@link AbstractEntityCollectionSection}
+ *  and links listener functionalities to it.
+ *
+ *  @param ENTITY the type of the element which is visualized by this class
  *
  * @author n.hoffmann
  * @created Nov 16, 2009
@@ -43,7 +44,7 @@ import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
  */
 public abstract class AbstractEntityCollectionElement<ENTITY> extends
                AbstractCdmFormElement implements IEntityElement<ENTITY>,
-               SelectionListener, IConversationEnabled, ISelectable {
+               SelectionListener, IConversationEnabled {
 
        protected ENTITY entity;
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AbstractUnboundEntityCollectionSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/AbstractUnboundEntityCollectionSection.java
new file mode 100644 (file)
index 0000000..da4e548
--- /dev/null
@@ -0,0 +1,112 @@
+// $Id$
+/**
+* Copyright (C) 2014 EDIT
+* 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.
+*/
+package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.widgets.Control;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.taxeditor.model.ImageResources;
+import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
+
+/**
+ * This class extends the functionality of {@link AbstractEntityCollectionSection}
+ * by creating an {@link AbstractEntityCollectionElement} for an 
+ * ELEMENT which is not directly added the the model ENTITY.<br>
+ * <br>
+ * This is useful if the ELEMENT is created after the creation of the AbstractEntityCollectionElement itself 
+ * and not in this class.
+ *
+ * @author pplitzner
+ * @date 21.01.2014
+ */
+public abstract class AbstractUnboundEntityCollectionSection<ENTITY, ELEMENT> extends AbstractEntityCollectionSection<ENTITY, ELEMENT> {
+
+    private boolean addUnboundElement = false;
+
+    /**
+     * @param formFactory
+     * @param conversation
+     * @param parentElement
+     * @param title
+     * @param style
+     */
+    public AbstractUnboundEntityCollectionSection(CdmFormFactory formFactory, ConversationHolder conversation, ICdmFormElement parentElement, String title, int style) {
+        super(formFactory, conversation, parentElement, title, style);
+    }
+
+    /**
+     * @deprecated this method should not be extended in sub classes of {@link AbstractUnboundEntityCollectionSection}.<br>
+     */
+    @Deprecated
+    @Override
+    public Collection<ELEMENT> getCollection(ENTITY entity) {
+        Collection<ELEMENT> elements = getEntityCollection(entity);
+        if(addUnboundElement){
+            //cloning to avoid saving the dummy element
+            Collection<ELEMENT> clonedElements = new HashSet<ELEMENT>();
+            clonedElements.addAll(elements);
+            clonedElements.add(createNewElement()); //add dummy element which is not bound to entity
+            return clonedElements;
+        }
+        return elements;
+    }
+
+    @Override
+    protected Control createToolbar() {
+        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+        Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
+            /* (non-Javadoc)
+             * @see org.eclipse.jface.action.Action#run()
+             */
+            @Override
+            public void run() {
+                addUnboundElement = true;
+                if(! getSection().isExpanded()) {
+                    getSection().setExpanded(true);
+                }
+                internalUpdateSection(false);
+                addUnboundElement = false;
+            }
+        };
+        addAction.setImageDescriptor(new ImageDescriptor() {
+
+            @Override
+            public ImageData getImageData() {
+                return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
+            }
+        });
+        addAction.setToolTipText(getTooltipString());
+
+        toolBarManager.add(addAction);
+
+        return toolBarManager.createControl(this);
+    }
+
+    /**
+     * Get all the elements that are represented by this section.
+     * @param entity the entity which is represented by the parent section
+     * @return a collection of the elements belonging to the entity
+     */
+    protected abstract Collection<ELEMENT> getEntityCollection(ENTITY entity);
+
+}
index 5ada8bdf984980b7095177d32456950b9a5022d5..087db08793f6ab32fe3486cba1f68d65305076c3 100644 (file)
@@ -105,6 +105,8 @@ public class SequenceReferenceCollectionDetailElement extends AbstractEntityColl
             Reference newCitation = selection_reference.getSelection();
             sequence.addCitation(newCitation);
             entity = newCitation;
+        } else if(eventSource==text_referenceDetail){
+//            entity.set???
         }
 
     }
index e130528f51deb572b25ee08bc31d35059d8e1644..46ec65e475a3b32ef87b9c21808f467b36ccc958 100644 (file)
@@ -11,34 +11,20 @@ package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
 
 import java.util.Collection;
 
-import org.eclipse.jface.action.Action;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.widgets.Control;
-
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.model.molecular.Sequence;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
-import eu.etaxonomy.taxeditor.model.AbstractUtility;
-import eu.etaxonomy.taxeditor.model.ImageResources;
-import eu.etaxonomy.taxeditor.preference.Resources;
 import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
 
 /**
+ * This section visualizes {@link Reference}s belonging to a {@link Sequence} and alllows adding/removing them.
  * @author pplitzner
  * @date 07.01.2014
  *
  */
-public class SequenceReferenceCollectionDetailSection extends AbstractEntityCollectionSection<Sequence, Reference> {
+public class SequenceReferenceCollectionDetailSection extends AbstractUnboundEntityCollectionSection<Sequence, Reference> {
 
     public SequenceReferenceCollectionDetailSection(CdmFormFactory formFactory,
             ConversationHolder conversation, ICdmFormElement parentElement, int style) {
@@ -46,16 +32,16 @@ public class SequenceReferenceCollectionDetailSection extends AbstractEntityColl
     }
 
     /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#getCollection(java.lang.Object)
+     * @see eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractNullEntityCollectionSection#getEntityCollection(java.lang.Object)
      */
     /** {@inheritDoc} */
     @Override
-    public Collection<Reference> getCollection(Sequence entity) {
+    protected Collection<Reference> getEntityCollection(Sequence entity) {
         return entity.getCitations();
     }
 
     /* (non-Javadoc)
-     * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#createNewElement()
+     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection#createNewElement()
      */
     /** {@inheritDoc} */
     @Override
@@ -63,73 +49,15 @@ public class SequenceReferenceCollectionDetailSection extends AbstractEntityColl
         return ReferenceFactory.newGeneric();
     }
 
-    @Override
-    protected Control createToolbar() {
-        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
-
-        Action addAction = new Action("add", IAction.AS_PUSH_BUTTON){
-            /* (non-Javadoc)
-             * @see org.eclipse.jface.action.Action#run()
-             */
-            @Override
-            public void run() {
-//                Reference element = createNewElement();
-//                if(element != null){
-//                    addElement((Reference)null);
-                    if(! getSection().isExpanded()) {
-                        getSection().setExpanded(true);
-                    }
-                    internalUpdateSection(true);
-//                }
-            }
-        };
-        addAction.setImageDescriptor(new ImageDescriptor() {
-
-            @Override
-            public ImageData getImageData() {
-                return ImageResources.getImage(ImageResources.ADD_ICON).getImageData();
-            }
-        });
-        addAction.setToolTipText(getTooltipString());
-
-        toolBarManager.add(addAction);
-
-        return toolBarManager.createControl(this);
-    }
-
-    @Override
-    protected void createDynamicContents(Collection<Reference> elements)
-    {
-        int i = 0;
-        for(final Reference element : elements){
-            SelectionAdapter removeListener = new SelectionAdapter(){
-                @Override
-                public void widgetSelected(SelectionEvent e) {
-                    removeElement(element);
-                    internalUpdateSection(true);
-                }
-            };
-            boolean modulo = i++%2 == 0;
-            String colorResource = modulo ? Resources.COLOR_LIST_EVEN : Resources.COLOR_LIST_ODD;
-            createElementComposite(element, removeListener, AbstractUtility.getColor(colorResource));
-        }
-        String colorString = i%2==0 ? Resources.COLOR_LIST_EVEN : Resources.COLOR_LIST_ODD;
-        Color backgroundColor = AbstractUtility.getColor(colorString);
-        final SequenceReferenceCollectionDetailElement dummyElement = new SequenceReferenceCollectionDetailElement(formFactory, this, (Reference) null, null, SWT.NULL);
-        if (backgroundColor != null && !backgroundColor.isDisposed()) {
-            dummyElement.setPersistentBackground(backgroundColor);
-            formFactory.adapt(dummyElement);
-            this.addElement(dummyElement);
-        }
-    }
-
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection#addElement(eu.etaxonomy.cdm.model.common.IVersionableEntity)
      */
     /** {@inheritDoc} */
     @Override
     public void addElement(Reference element) {
-        getEntity().addCitation(element);
+        if(element!=null){
+            getEntity().addCitation(element);
+        }
     }
 
     /* (non-Javadoc)