commit 12f992a264608418d4969757b7735b92d37e20f0
Author: Patric Plitzner <p.plitzner@bgbm.org>
Date:   Mon Aug 18 14:38:49 2014 +0000

     - added null check (fixes #4351)

diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
index 085783c8d..e61e15842 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/PolytomousKeyViewPart.java
@@ -1,5 +1,5 @@
 /**
- * 
+ *
  */
 package eu.etaxonomy.taxeditor.navigation.key.polytomous;
 
@@ -14,7 +14,6 @@ import org.eclipse.jface.viewers.DoubleClickEvent;
 import org.eclipse.jface.viewers.IDoubleClickListener;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ListViewer;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.viewers.ViewerFilter;
 import org.eclipse.swt.SWT;
@@ -63,28 +62,28 @@ public class PolytomousKeyViewPart extends ViewPart implements
 				@Override
 				public boolean select(Viewer viewer, Object parentElement,
 						Object element) {
-					
+
 					if(element instanceof PolytomousKey){
 						PolytomousKey key = (PolytomousKey) element;
 						if(key.getTitleCache().contains(text_filter.getText())){
 							return true;
 						}
 					}
-					
+
 					return false;
 				}
-				
+
 			};
-			
+
 			viewer.setFilters(new ViewerFilter[]{filter});
 		}
 	}
-	
-	
+
+
 	public static final String ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.polytomousKeyViewPart";
 
 	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.navigation.key.polytomous.editNodes";
-	
+
 	private class ContextListener extends ContextListenerAdapter{
 		/* (non-Javadoc)
 		 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
@@ -94,7 +93,7 @@ public class PolytomousKeyViewPart extends ViewPart implements
 			monitor.subTask("Shutting down Polytomous Key Viewer");
 			viewer.setInput(null);
 		}
-		
+
 		/* (non-Javadoc)
 		 * @see eu.etaxonomy.taxeditor.model.ContextListenerAdapter#contextStart(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
 		 */
@@ -104,7 +103,7 @@ public class PolytomousKeyViewPart extends ViewPart implements
 			setInput();
 		}
 	}
-	
+
 	private ListViewer viewer;
 	private ConversationHolder conversation;
 	private IContextListener contextListener;
@@ -116,7 +115,7 @@ public class PolytomousKeyViewPart extends ViewPart implements
 	public PolytomousKeyViewPart(){
 		formFactory = new CdmFormFactory(Display.getDefault());
 	}
-	
+
 	/* (non-Javadoc)
 	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
 	 */
@@ -125,46 +124,46 @@ public class PolytomousKeyViewPart extends ViewPart implements
 
 		Composite container = new Composite(parent, SWT.NONE);
 		container.setLayout(new GridLayout());
-		
+
 		contextListener = new ContextListener();
 		CdmStore.getContextManager().addContextListener(contextListener);
-		
+
 		text_filter = formFactory.createText(container, "");
 		text_filter.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
 		text_filter.addModifyListener(new FilterModifyListener());
-		
+
 		viewer = new ListViewer(container, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
 		viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-		
+
 		viewer.setContentProvider(new PolytomousKeyContentProvider());
 		viewer.setLabelProvider(new PolytomousKeyLabelProvider());
-		
+
 		viewer.addDoubleClickListener(new IDoubleClickListener() {
-			
+
 			@Override
-			public void doubleClick(DoubleClickEvent event) {				
+			public void doubleClick(DoubleClickEvent event) {
 			    openSelectedKeyNodes();
 			}
 		});
-		
-		
+
+
 		getSite().setSelectionProvider(viewer);
-				
+
 		createMenu();
-		
+
 		if(CdmStore.isActive()){
 			setInput();
 		}
 	}
-	
+
 	public void openSelectedKeyNodes() {
         ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class);
-        
-        Command command = commandService.getCommand(OPEN_COMMAND_ID); 
+
+        Command command = commandService.getCommand(OPEN_COMMAND_ID);
         if(command.isEnabled()) {
             IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
-            try {                
-                handlerService.executeCommand(OPEN_COMMAND_ID, null);            	
+            try {
+                handlerService.executeCommand(OPEN_COMMAND_ID, null);
             } catch (NotDefinedException e) {
                 throw new RuntimeException("Could not find open command: " + OPEN_COMMAND_ID);
             } catch (Exception e) {
@@ -172,29 +171,29 @@ public class PolytomousKeyViewPart extends ViewPart implements
             }
         }
 	}
-	
-	public void setViewerSelection(ISelection selection, boolean reveal) {	  
-	    getSite().setSelectionProvider(viewer);	    
-	    viewer.setSelection(selection,reveal);	    
-	    viewer.getList().notifyListeners(SWT.Selection,new Event());	    
+
+	public void setViewerSelection(ISelection selection, boolean reveal) {
+	    getSite().setSelectionProvider(viewer);
+	    viewer.setSelection(selection,reveal);
+	    viewer.getList().notifyListeners(SWT.Selection,new Event());
 	}
-	
+
 	private void createMenu(){
 		MenuManager menuManager = new MenuManager();
 		menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
-		
+
 		getSite().registerContextMenu(menuManager, viewer);
-				
+
 		Control control = viewer.getControl();
 		Menu menu = menuManager.createContextMenu(control);
-		
-		control.setMenu(menu);	
+
+		control.setMenu(menu);
 	}
 
 	private void setInput() {
 		conversation = CdmStore.createConversation();
 		conversation.registerForDataStoreChanges(this);
-		List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);			
+		List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);
 		viewer.setInput(input);
 	}
 
@@ -205,7 +204,7 @@ public class PolytomousKeyViewPart extends ViewPart implements
 	public void setFocus() {
 		viewer.getControl().setFocus();
 	}
-	
+
 	/* (non-Javadoc)
 	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
 	 */
@@ -225,15 +224,17 @@ public class PolytomousKeyViewPart extends ViewPart implements
 	public ConversationHolder getConversationHolder() {
 		return conversation;
 	}
-	
+
 	/* (non-Javadoc)
 	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
 	 */
 	@Override
 	public void dispose() {
-		conversation.unregisterForDataStoreChanges(this);
-		conversation.close();
-		CdmStore.getContextManager().removeContextListener(contextListener);
+	    if(conversation!=null){
+	        conversation.unregisterForDataStoreChanges(this);
+	        conversation.close();
+	        CdmStore.getContextManager().removeContextListener(contextListener);
+	    }
 		super.dispose();
 	}
 
@@ -255,16 +256,16 @@ public class PolytomousKeyViewPart extends ViewPart implements
 	}
 
 	/**
-	 * 
+	 *
 	 */
 	public void refresh() {
 		getConversationHolder().bind();
 		//FIXME : Need to make sure this is a stable fix (ticket 3822)
 		getConversationHolder().commit();
-		List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);			
+		List<PolytomousKey> input = CdmStore.getService(IPolytomousKeyService.class).list(PolytomousKey.class, null, null, null, null);
 		viewer.setInput(input);
 	}
-	
+
 	public List<PolytomousKey> getKeys() {
 		return (List<PolytomousKey>)viewer.getInput();
 	}
