- added update() method to DerivateView
authorPatric Plitzner <p.plitzner@bgbm.org>
Wed, 2 Apr 2014 09:37:31 +0000 (09:37 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Wed, 2 Apr 2014 09:37:31 +0000 (09:37 +0000)
 - display different icon for SingleReads linked to multiple Sequences

.gitattributes
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateContentProvider.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateDropListener.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/PasteDerivateCommand.java
eu.etaxonomy.taxeditor.store/icons/single_read_derivate_multilink-16x16-32.png [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/ImageResources.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/derivateSearch/DerivateLabelProvider.java

index 5ab03daba733eee1058e51c5deb18ee7c020073f..d8f5d4f72fc4fd7ac69d6da0634edeef36a8f19b 100644 (file)
@@ -1075,6 +1075,7 @@ eu.etaxonomy.taxeditor.store/icons/search_src.gif -text
 eu.etaxonomy.taxeditor.store/icons/sequence_derivate-16x16-32.png -text
 eu.etaxonomy.taxeditor.store/icons/settings.gif -text
 eu.etaxonomy.taxeditor.store/icons/single_read_derivate-16x16-32.png -text
+eu.etaxonomy.taxeditor.store/icons/single_read_derivate_multilink-16x16-32.png -text
 eu.etaxonomy.taxeditor.store/icons/smartmode_co.gif -text
 eu.etaxonomy.taxeditor.store/icons/sort.gif -text
 eu.etaxonomy.taxeditor.store/icons/specimen_derivate-16x16-32.png -text
index 027b5d012082e658b6aaef5e8f8234e552ac9640..3d27e75c8f5ae1459f5ff177f5d97b5cf044f945 100644 (file)
@@ -49,12 +49,10 @@ public class DerivateContentProvider implements ITreeContentProvider {
 
        @Override
        public Object[] getChildren(Object element) {
-           TreeNode parentNode = null;
            TreeNode currentnode = null;
            Object value = null;
         if(element instanceof TreeNode){
             currentnode = (TreeNode) element;
-            parentNode = ((TreeNode) element).getParent();
             value = ((TreeNode) element).getValue();
         }
         Set<Object> children = new LinkedHashSet<Object>();
index 403a1576a6739f0f074f7d9829b177af9acd600d..6bc403d1b07bf5b1babc37a816dbd608922fe439 100644 (file)
@@ -58,7 +58,7 @@ public class DerivateDropListener extends ViewerDropAdapter {
             TreeNode draggednode = EditorUtil.getTreeNodeValueOfSelection((IStructuredSelection) data);
             if(draggednode!=null){
                 if(moveTreeNode(draggednode, targetNode)){
-                    derivateView.getViewer().setInput(derivateView.getEditorInput());
+                    derivateView.update();
                     LocalSelectionTransfer.getTransfer().setSelection(null);
                     return true;
                 }
index f79098099c7b53ca7947df9d3a808b74abc02547..5db82aa8444b6623fe949f62ae1a95daa94bed60 100644 (file)
@@ -1,5 +1,10 @@
 package eu.etaxonomy.taxeditor.editor.view.derivate;
 
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map.Entry;
+import java.util.Set;
+
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.util.LocalSelectionTransfer;
@@ -22,6 +27,9 @@ import org.eclipse.ui.part.EditorPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
+import eu.etaxonomy.cdm.model.molecular.Sequence;
+import eu.etaxonomy.cdm.model.molecular.SingleRead;
 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
@@ -29,6 +37,7 @@ import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
+import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider;
 
 /**
@@ -47,6 +56,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
 
     private final int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
 
+    private DerivateLabelProvider labelProvider;
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
      */
@@ -54,7 +65,8 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
     public void createPartControl(Composite parent) {
         viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION));
         viewer.setContentProvider(new DerivateContentProvider());
-        viewer.setLabelProvider(new DerivateLabelProvider());
+        labelProvider = new DerivateLabelProvider();
+        viewer.setLabelProvider(labelProvider);
         viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
         // Propagate selection from viewer
         getSite().setSelectionProvider(viewer);
@@ -66,6 +78,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         Menu menu = menuManager.createContextMenu(control);
         control.setMenu(menu);
 
+        labelProvider.setMultiLinkSingleReads(getMultiLinkSingleReads());
         IEditorInput editorInput = getEditorInput();
         viewer.setInput(editorInput);
         if(editorInput instanceof DerivateViewEditorInput){
@@ -100,6 +113,7 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
         monitor.worked(1);
         monitor.done();
         firePropertyChange(PROP_DIRTY);
+        update();
     }
 
     /* (non-Javadoc)
@@ -196,9 +210,29 @@ public class DerivateView extends EditorPart implements IPartContentHasFactualDa
      */
     @Override
     public void changed(Object element) {
-        viewer.setInput(getEditorInput());
         setDirty(true);
         firePropertyChange(IEditorPart.PROP_DIRTY);
     }
 
+    /**
+     * Updates the derivate hierarchy tree
+     */
+    public void update(){
+        labelProvider.setMultiLinkSingleReads(getMultiLinkSingleReads());
+        viewer.setInput(getEditorInput());
+    }
+
+    /**
+     * @return
+     */
+    private Set<SingleRead> getMultiLinkSingleReads() {
+        Set<SingleRead> multiLinkSingleReads = new HashSet<SingleRead>();
+        for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
+            if(entry.getValue().size()>1){
+                multiLinkSingleReads.add(entry.getKey());
+            }
+        }
+        return multiLinkSingleReads;
+    }
+
 }
index 03fcb74357632b7f830965a8f1ae7e47e9f2a76c..9d847d90a6d3f9a5dc364a94b80f482612418c54 100644 (file)
@@ -39,7 +39,7 @@ public class PasteDerivateCommand extends AbstractHandler {
             CdmStore.getService(ISequenceService.class).saveOrUpdate(sequence);
             if(activeEditor instanceof DerivateView) {
                 DerivateView derivateView = (DerivateView)activeEditor;
-                derivateView.getViewer().setInput(derivateView.getEditorInput());
+                derivateView.update();
                 LocalSelectionTransfer.getTransfer().setSelection(null);
             }
         }
diff --git a/eu.etaxonomy.taxeditor.store/icons/single_read_derivate_multilink-16x16-32.png b/eu.etaxonomy.taxeditor.store/icons/single_read_derivate_multilink-16x16-32.png
new file mode 100644 (file)
index 0000000..abb3bb9
Binary files /dev/null and b/eu.etaxonomy.taxeditor.store/icons/single_read_derivate_multilink-16x16-32.png differ
index f1cc4348ac8600f7e21a16c53e7ddd656b7efd49..176628d77295764c50064a2a20ab3238008daecc 100644 (file)
@@ -144,6 +144,7 @@ public class ImageResources {
     public static final String SEQUENCE_DERIVATE = "sequence_derivate";
     public static final String AMPLIFICATION_DERIVATE = "amplification_derivate";
     public static final String SINGLE_READ_DERIVATE = "single_read_derivate";
+    public static final String SINGLE_READ_DERIVATE_MULTILINK = "single_read_derivate_multilink";
 
 
 
@@ -341,6 +342,8 @@ public class ImageResources {
                        "amplification_derivate-16x16-32.png");
                registerImage(registry, SINGLE_READ_DERIVATE,
                        "single_read_derivate-16x16-32.png");
+               registerImage(registry, SINGLE_READ_DERIVATE_MULTILINK,
+                       "single_read_derivate_multilink-16x16-32.png");
        }
 
        private void registerImage(ImageRegistry registry, String key,
index 5666108263e45177175c18e64f121029f6c2ea61..48f90614b793c172532498024110d8e44004fa4b 100644 (file)
@@ -9,6 +9,9 @@
 */
 package eu.etaxonomy.taxeditor.view.derivateSearch;
 
+import java.util.HashSet;
+import java.util.Set;
+
 import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.TreeNode;
 import org.eclipse.swt.graphics.Image;
@@ -26,6 +29,8 @@ import eu.etaxonomy.taxeditor.model.ImageResources;
  */
 public class DerivateLabelProvider extends ColumnLabelProvider {
 
+    private Set<SingleRead> multiLinkSingleReads = new HashSet<SingleRead>();
+
     /** {@inheritDoc} */
     @Override
     public String getText(Object element) {
@@ -56,36 +61,49 @@ public class DerivateLabelProvider extends ColumnLabelProvider {
     @Override
     public Image getImage(Object element) {
         if(element instanceof TreeNode){
-            element = ((TreeNode) element).getValue();
-        }
-        if(element instanceof FieldUnit){
-            return ImageResources.getImage(ImageResources.FIELD_UNIT);
-        }
-        else if(element instanceof DerivedUnit){
-            DerivedUnit derivedUnit = (DerivedUnit)element;
-            if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
+            TreeNode treeNode = (TreeNode)element;
+            Object nodeValue = treeNode.getValue();
+            if(nodeValue instanceof FieldUnit){
                 return ImageResources.getImage(ImageResources.FIELD_UNIT);
             }
-            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
-                return ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
-            }
-            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
-                return ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
+            else if(nodeValue instanceof DerivedUnit){
+                DerivedUnit derivedUnit = (DerivedUnit)nodeValue;
+                if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
+                    return ImageResources.getImage(ImageResources.FIELD_UNIT);
+                }
+                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
+                    return ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
+                }
+                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
+                    return ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
+                }
+                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
+                    return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
+                }
+                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.StillImage){
+                    return ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
+                }
             }
-            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
-                return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
+            else if(nodeValue instanceof Sequence){
+                return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
             }
-            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.StillImage){
-                return ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
+            else if(nodeValue instanceof SingleRead){
+                if(multiLinkSingleReads.contains(nodeValue)){
+                    return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
+                }
+                else{
+                    return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
+                }
             }
         }
-        else if(element instanceof Sequence){
-            return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
-        }
-        else if(element instanceof SingleRead){
-            return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
-        }
         return super.getImage(element);
     }
 
+    /**
+     * @param multiLinkSingleReads the multiLinkSingleReads to set
+     */
+    public void setMultiLinkSingleReads(Set<SingleRead> multiLinkSingleReads) {
+        this.multiLinkSingleReads = multiLinkSingleReads;
+    }
+
 }