fix NPE in checklist editor
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / checklist / ChecklistEditor.java
index 4b6afb1a12f7a7f8570e1890491b743d95551d3a..7cdb3ea6ebbe7631109c7b3d08f11b37d1f72700 100644 (file)
@@ -12,6 +12,7 @@ package eu.etaxonomy.taxeditor.editor.view.checklist;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -57,6 +58,7 @@ import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
@@ -75,6 +77,8 @@ import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -87,7 +91,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @version 1.0
  */
 public class ChecklistEditor extends EditorPart implements ISelectionListener, IPartContentHasFactualData,
-        IConversationEnabled, IContextListener, IPartContentHasDetails, IDirtyMarkable {
+        IConversationEnabled, IContextListener, IPartContentHasDetails, IDirtyMarkable, ICdmEntitySessionEnabled {
 
     private static final Logger logger = Logger.getLogger(ChecklistEditor.class);
     /**
@@ -181,6 +185,8 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
 
     private Label statusLabel;
 
+    private final ICdmEntitySession cdmEntitySession;
+
     private SortedSet<DefinedTermBase> terms = null;
        private ToolItem toolItem;
        private ChecklistDropdownSelectionListener dropListener;
@@ -206,6 +212,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      * </p>
      */
     public ChecklistEditor() {
+        cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
     }
 
     /** {@inheritDoc} */
@@ -314,9 +321,9 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     private void createTable() {
         Table table = viewer.getTable();//new Table(parent, viewer.getTable().getStyle());
         List<String> titles = new ArrayList<String>();
-        Collections.addAll(titles, "Taxon", "Author", "Reference", "Rank");
+        Collections.addAll(titles, "Taxon", "Author", "Rank");
         List<Integer> bounds = new ArrayList<Integer>();
-        Collections.addAll(bounds, 300, 200, 200, 200);
+        Collections.addAll(bounds, 300, 200, 200);
         Map<Integer, Boolean> restoreValuesForColumnWidth = restoreValuesForColumnWidth(titles, bounds);
         createInitalDistributionColumns(table, titles, bounds, restoreValuesForColumnWidth);
         table.setSortDirection(SWT.DOWN);
@@ -325,7 +332,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
        }
     /**
      * This method creates initially the distribution columns for a table. It should only be called for creation.<br>
-     *<p> 
+     *<p>
      *
      *<b>Notice:</b> If you want to add additional columns later please use <b>addTableViewerColumn()</b>
      *
@@ -347,7 +354,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
             if (columnIndex == 1) {
                 table.setSortColumn(column.getColumn());
             }
-            if (columnIndex == 3) {
+            if (columnIndex == 2) {
                /** uncommented it for now because no rank editing is wanted **/
 //                column.setEditingSupport(new RankEditingSupport(viewer, this));
             }
@@ -365,9 +372,9 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
 
     /**
      * This methods loads the last opened distribution columns for the table viewer from the prefrence store.<br>
-     *<p> 
+     *<p>
      * <b>Notice:</b> It adds also the TitleCache to the titles list for the header of each column.<p>
-     * 
+     *
      * @param titles
      * @param bounds
      * @return Map<Integer, Boolean>
@@ -390,8 +397,8 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
        }
 
     /**
-     * This method adds new DistributionColumns to an existing table. 
-     * 
+     * This method adds new DistributionColumns to an existing table.
+     *
      * @param title
      * @param bound
      * @param colNumber
@@ -407,9 +414,9 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
         column.setMoveable(true);
         return viewerColumn;
       }
-    
-    
-    
+
+
+
     /**
      *
      * pull data from database and set input for view
@@ -431,7 +438,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
             getService().schedule(new ChecklistJob("loading Taxa", selectedTaxonNodes), Job.LONG);
         }
         if (taxonNode != null) {
-            selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, false);
+            selectedTaxonNodes = taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, NODE_INIT_STRATEGY, true, null);
             getService().schedule(new ChecklistJob("loading Taxa", selectedTaxonNodes), Job.LONG);
         }
     }
@@ -439,12 +446,14 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     /** {@inheritDoc} */
     @Override
     public void dispose() {
+        cdmEntitySession.dispose();
         super.dispose();
     }
 
     /** {@inheritDoc} */
     @Override
     public void setFocus() {
+        cdmEntitySession.bind();
         viewer.getControl().setFocus();
     }
 
@@ -488,7 +497,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
      * It will hide the old distribution column and load the newly added columns.<br>
      * <p>
      * <b>Notice:</b> for data update please use <b>refresh()</b>
-     * 
+     *
      */
     @SuppressWarnings({ "unchecked", "rawtypes" })
        public void reload(){
@@ -541,7 +550,7 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
                }
        }
        }
-    
+
     /**
      * <p>
      * Getter for the field <code>service</code>.
@@ -757,4 +766,31 @@ public class ChecklistEditor extends EditorPart implements ISelectionListener, I
     public boolean isDirty() {
         return dirty;
     }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
+     */
+    @Override
+    public ICdmEntitySession getCdmEntitySession() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
+     */
+    @Override
+    public <T extends CdmBase> Collection<T> getRootEntities() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+     */
+    @Override
+    public Map<Object, List<String>> getPropertyPathsMap() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 }