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.apache.log4j.Level;
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.eclipse.core.commands.AbstractHandler;
|
16
|
import org.eclipse.core.commands.ExecutionEvent;
|
17
|
import org.eclipse.core.commands.ExecutionException;
|
18
|
import org.eclipse.core.commands.common.NotDefinedException;
|
19
|
import org.eclipse.core.expressions.IEvaluationContext;
|
20
|
import org.eclipse.core.runtime.Status;
|
21
|
import org.eclipse.swt.widgets.Event;
|
22
|
import org.eclipse.ui.IWorkbenchPart;
|
23
|
import org.eclipse.ui.handlers.HandlerUtil;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
26
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
27
|
import eu.etaxonomy.taxeditor.editor.Page;
|
28
|
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
|
29
|
import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
|
30
|
import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
|
31
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
32
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
33
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
|
34
|
|
35
|
/**
|
36
|
* <p>CreateConceptRelationHandler class.</p>
|
37
|
*
|
38
|
* @author n.hoffmann
|
39
|
* @created 16.04.2009
|
40
|
* @version 1.0
|
41
|
*/
|
42
|
public class CreateConceptRelationHandler extends AbstractHandler {
|
43
|
|
44
|
/* (non-Javadoc)
|
45
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
46
|
*/
|
47
|
/** {@inheritDoc} */
|
48
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
49
|
TaxonNameEditor editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(
|
50
|
Page.NAME);
|
51
|
|
52
|
Taxon taxonToBeFiltered = editor.getTaxon();
|
53
|
|
54
|
/* we need to get the activePart before calling TaxonBaseSelectionDialog.selectTaxon(), otherwise the
|
55
|
* the variable of the parent applicationContext in event are overwritten during this method call
|
56
|
* this is Linux specific bugfix see: #2685 ([LINUX] Editing concept relationships does not work under linux)
|
57
|
*/
|
58
|
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
|
59
|
|
60
|
Taxon relatedConcept = TaxonBaseSelectionDialog.selectTaxon(HandlerUtil.getActiveShell(event), editor.getConversationHolder(), taxonToBeFiltered);
|
61
|
|
62
|
|
63
|
if(relatedConcept == null){
|
64
|
return Status.CANCEL_STATUS;
|
65
|
}
|
66
|
|
67
|
TaxonRelationshipTypeInverseContainer typeInverseContainer = (TaxonRelationshipTypeInverseContainer) ((Event)event.getTrigger()).data;
|
68
|
|
69
|
|
70
|
IPostOperationEnabled postOperationEnabled = (activePart instanceof IPostOperationEnabled) ? (IPostOperationEnabled) activePart : null;
|
71
|
|
72
|
try {
|
73
|
AbstractPostOperation operation = new CreateConceptRelationOperation(event.getCommand().getName(),
|
74
|
editor.getUndoContext(), editor.getTaxon(), relatedConcept, typeInverseContainer, postOperationEnabled);
|
75
|
EditorUtil.executeOperation(operation);
|
76
|
} catch (NotDefinedException e) {
|
77
|
EditorUtil.warn(getClass(), "Command name not set");
|
78
|
}
|
79
|
|
80
|
return null;
|
81
|
}
|
82
|
}
|