Project

General

Profile

Download (4.01 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.editor.view.concept.handler;
12

    
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.commands.ExecutionException;
16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.core.commands.operations.IUndoContext;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.swt.widgets.Event;
22
import org.eclipse.ui.IEditorPart;
23
import org.eclipse.ui.IWorkbenchPart;
24
import org.eclipse.ui.handlers.HandlerUtil;
25

    
26
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
27
import eu.etaxonomy.cdm.model.taxon.Taxon;
28
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
29
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
30
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
31
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
32
import eu.etaxonomy.taxeditor.model.AbstractUtility;
33
import eu.etaxonomy.taxeditor.model.MessagingUtils;
34
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
35
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
36
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
37
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
38

    
39
/**
40
 * @author n.hoffmann
41
 * @created 16.04.2009
42
 * @version 1.0
43
 */
44
public class CreateConceptRelationHandler extends AbstractHandler {
45

    
46
	/** {@inheritDoc} */
47
	@Override
48
	public Object execute(ExecutionEvent event) throws ExecutionException {
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
69
		 * the variable of the parent applicationContext in event are overwritten during this method call
70
		 * this is Linux specific bugfix see: #2685 ([LINUX] Editing concept relationships does not work under linux)
71
		 */
72
		IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
73

    
74
		Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), conversationHolder, taxon);
75

    
76

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

    
84

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

    
87
		try {
88
			AbstractPostOperation operation = new CreateConceptRelationOperation(event.getCommand().getName(),
89
					undoContext, taxon, relatedConcept, typeInverseContainer, postOperationEnabled);
90
			AbstractUtility.executeOperation(operation);
91
		} catch (NotDefinedException e) {
92
			MessagingUtils.warn(getClass(), "Command name not set");
93
		}
94

    
95
		return null;
96
	}
97
}
(5-5/8)