Project

General

Profile

« Previous | Next » 

Revision 9e8673a2

Added by Patrick Plitzner over 7 years ago

ref #5801 Fix several NPE when editing/creating concept relations from
active bulk editor

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/CreateConceptRelationHandler.java
1 1
// $Id$
2 2
/**
3 3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
4
* European Distributed Institute of Taxonomy
5 5
* http://www.e-taxonomy.eu
6
* 
6
*
7 7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8 8
* See LICENSE.TXT at the top of this package for the full license terms.
9 9
*/
......
14 14
import org.eclipse.core.commands.ExecutionEvent;
15 15
import org.eclipse.core.commands.ExecutionException;
16 16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.commands.operations.IUndoContext;
17 18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
18 21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.ui.IEditorPart;
19 23
import org.eclipse.ui.IWorkbenchPart;
20 24
import org.eclipse.ui.handlers.HandlerUtil;
21 25

  
26
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
22 27
import eu.etaxonomy.cdm.model.taxon.Taxon;
23 28
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24
import eu.etaxonomy.taxeditor.editor.EditorUtil;
25
import eu.etaxonomy.taxeditor.editor.Page;
26
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
29
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
30
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
27 31
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
28 32
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29 33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
33 37
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
34 38

  
35 39
/**
36
 * <p>CreateConceptRelationHandler class.</p>
37
 *
38 40
 * @author n.hoffmann
39 41
 * @created 16.04.2009
40 42
 * @version 1.0
41 43
 */
42 44
public class CreateConceptRelationHandler extends AbstractHandler {
43
	
44
	/* (non-Javadoc)
45
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
46
	 */
45

  
47 46
	/** {@inheritDoc} */
48 47
	@Override
49 48
	public Object execute(ExecutionEvent event) throws ExecutionException {
50
		TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
51
				Page.NAME);
52
		
53
		Taxon taxonToBeFiltered = editor.getTaxon();
54
		
55
		/* we need to get the activePart before calling TaxonBaseSelectionDialog.selectTaxon(), otherwise the 
49
	    IUndoContext undoContext = null;
50
	    ConversationHolder conversationHolder = null;
51
	    Taxon taxon = null;
52
		IEditorPart activeEditor = AbstractUtility.getActiveEditor();
53
		if(activeEditor instanceof MultiPageTaxonEditor){
54
		    MultiPageTaxonEditor taxonEditor = (MultiPageTaxonEditor)activeEditor;
55
		    taxon = taxonEditor.getTaxon();
56
		    conversationHolder = taxonEditor.getConversationHolder();
57
		    undoContext = taxonEditor.getUndoContext();
58
		}
59
		else if(activeEditor instanceof BulkEditor){
60
		    BulkEditor bulkEditor = (BulkEditor)activeEditor;
61
            ISelection selection = bulkEditor.getSelectionProvider().getSelection();
62
		    taxon = (Taxon) ((IStructuredSelection)selection).getFirstElement();
63
		    conversationHolder = bulkEditor.getConversationHolder();
64
		    undoContext = bulkEditor.getUndoContext();
65
		}
66

  
67

  
68
		/* we need to get the activePart before calling TaxonBaseSelectionDialog.selectTaxon(), otherwise the
56 69
		 * the variable of the parent applicationContext in event are overwritten during this method call
57 70
		 * this is Linux specific bugfix see: #2685 ([LINUX] Editing concept relationships does not work under linux)
58 71
		 */
59 72
		IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
60 73

  
61
		Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), taxonToBeFiltered);
62
					
63
		
74
		Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), conversationHolder, taxon);
75

  
76

  
64 77
		if(relatedConcept == null){
65 78
			return Status.CANCEL_STATUS;
66 79
		}
67 80
		TaxonRelationshipType type = (TaxonRelationshipType) ((Event)event.getTrigger()).data;
68 81
		boolean isInverse = type.getInverseLabel().isEmpty()?false:true;
69 82
		TaxonRelationshipTypeInverseContainer typeInverseContainer =new TaxonRelationshipTypeInverseContainer(type, isInverse) ;
70
		
83

  
71 84

  
72 85
		IPostOperationEnabled postOperationEnabled = (activePart instanceof IPostOperationEnabled) ? (IPostOperationEnabled) activePart : null;
73
		
86

  
74 87
		try {
75
			AbstractPostOperation operation = new CreateConceptRelationOperation(event.getCommand().getName(), 
76
					editor.getUndoContext(), editor.getTaxon(), relatedConcept, typeInverseContainer, postOperationEnabled);
88
			AbstractPostOperation operation = new CreateConceptRelationOperation(event.getCommand().getName(),
89
					undoContext, taxon, relatedConcept, typeInverseContainer, postOperationEnabled);
77 90
			AbstractUtility.executeOperation(operation);
78 91
		} catch (NotDefinedException e) {
79 92
			MessagingUtils.warn(getClass(), "Command name not set");
80 93
		}
81
		
94

  
82 95
		return null;
83 96
	}
84 97
}

Also available in: Unified diff