Project

General

Profile

« Previous | Next » 

Revision c54a89ad

Added by Patrick Plitzner almost 7 years ago

Fix potential NPE when CdmStore is not yet active

View differences:

eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/search/SearchResultView.java
65 65
	private static Object[] EMPTY = new Object[0];
66 66

  
67 67
	private class ContextListener extends ContextListenerAdapter{
68
		/* (non-Javadoc)
69
		 * @see eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
70
		 */
71 68
		@Override
72 69
		public void contextStop(IMemento memento, IProgressMonitor monitor) {
73 70
			monitor.subTask(Messages.SearchResultView_REMOVE_SEARCH_RESULTS);
......
93 90

  
94 91
	private IContextListener contextListener;
95 92

  
96
	/* (non-Javadoc)
97
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
98
	 */
99 93
	/** {@inheritDoc} */
100 94
	@Override
101 95
	public void createPartControl(Composite parent) {
102 96

  
103
		conversation = CdmStore.createConversation();
97
	    conversation = getConversation_internal();
104 98
		contextListener = new ContextListener();
105 99
		CdmStore.getContextManager().addContextListener(contextListener);
106 100

  
......
230 224
		}
231 225
	}
232 226

  
233
	/* (non-Javadoc)
234
	 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
235
	 */
236 227
	/** {@inheritDoc} */
237 228
	@Override
238 229
	public void setFocus() {
239 230
		//logger.warn("Setting focus to search result viewer");
240
		conversation.bind();
231
		ConversationHolder conversation_internal = getConversation_internal();
232
		if(conversation_internal!=null){
233
		    conversation_internal.bind();
234
		}
241 235
		// pass focus to resultViewer
242 236
		resultViewer.getControl().setFocus();
243 237
	}
244 238

  
245
	/* (non-Javadoc)
246
	 * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
247
	 */
248 239
	/**
249 240
	 * <p>getConversationHolder</p>
250 241
	 *
......
255 246
		return this.conversation;
256 247
	}
257 248

  
258
	/* (non-Javadoc)
259
	 * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
260
	 */
261 249
	/** {@inheritDoc} */
262 250
	@Override
263 251
    public void update(CdmDataChangeMap changeEvents) {
......
265 253

  
266 254
	}
267 255

  
268
	/* (non-Javadoc)
269
	 * @see org.eclipse.ui.part.WorkbenchPart#dispose()
270
	 */
271 256
	/** {@inheritDoc} */
272 257
	@Override
273 258
	public void dispose() {
274 259
		super.dispose();
275
		conversation.close();
260
		if(conversation!=null){
261
		    conversation.close();
262
		}
276 263
		if(searchJob != null) {
277 264
            searchJob.cancel();
278 265
        }
279 266
		CdmStore.getContextManager().removeContextListener(contextListener);
280 267
	}
281 268

  
269
	private ConversationHolder getConversation_internal(){
270
	    if(conversation==null && CdmStore.isActive()){
271
	        try {
272
	            conversation = CdmStore.createConversation();
273
            } catch (Exception e) {
274
                //nothing
275
            }
276
	    }
277
	    return conversation;
278
	}
279

  
282 280
	/**
283 281
	 *
284 282
	 * @author n.hoffmann
......
300 298
			this.configurator = configurator;
301 299
		}
302 300

  
303
		/* (non-Javadoc)
304
		 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
305
		 */
306 301
		@Override
307 302
		protected IStatus run(IProgressMonitor monitor) {
308 303
			monitor.beginTask("", 100); //$NON-NLS-1$

Also available in: Unified diff