Revision 7a0547ca
Added by Patrick Plitzner over 10 years ago
- enabled DescriptiveView (Factual Data) to show descriptions of SpecimenOrObservationBase
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/CreateDescriptionElementHandler.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 |
*/ |
... | ... | |
16 | 16 |
import org.eclipse.core.commands.common.NotDefinedException; |
17 | 17 |
import org.eclipse.jface.viewers.ISelection; |
18 | 18 |
import org.eclipse.jface.viewers.IStructuredSelection; |
19 |
import org.eclipse.jface.viewers.ITreeSelection; |
|
20 |
import org.eclipse.jface.viewers.TreePath; |
|
21 | 19 |
import org.eclipse.swt.widgets.Event; |
22 |
import org.eclipse.ui.IEditorInput; |
|
23 |
import org.eclipse.ui.IEditorPart; |
|
24 | 20 |
import org.eclipse.ui.IWorkbenchPart; |
25 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
26 | 21 |
import org.eclipse.ui.handlers.HandlerUtil; |
27 | 22 |
|
23 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
28 | 24 |
import eu.etaxonomy.cdm.model.description.Feature; |
29 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
30 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
31 | 25 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
32 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
33 | 26 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateDescriptionElementOperation; |
27 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
34 | 28 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
35 | 29 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
36 | 30 |
|
... | ... | |
45 | 39 |
|
46 | 40 |
/* |
47 | 41 |
* (non-Javadoc) |
48 |
*
|
|
42 |
* |
|
49 | 43 |
* @see |
50 | 44 |
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands. |
51 | 45 |
* ExecutionEvent) |
52 | 46 |
*/ |
53 |
/** {@inheritDoc} */ |
|
54 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
55 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
56 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part |
|
57 |
: null; |
|
47 |
/** {@inheritDoc} */ |
|
48 |
@Override |
|
49 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
50 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
51 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part |
|
52 |
: null; |
|
58 | 53 |
|
59 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
60 |
if (editor instanceof FormEditor) { |
|
61 |
editor = ((FormEditor) editor).getActiveEditor(); |
|
62 |
} |
|
63 |
IEditorInput input = editor.getEditorInput(); |
|
64 |
if (input instanceof TaxonEditorInput) { |
|
65 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
66 | 54 |
|
67 |
TaxonDescription description = null;
|
|
55 |
DescriptionBase<?> description = null;
|
|
68 | 56 |
|
69 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
|
70 |
if (selection instanceof ITreeSelection) { |
|
71 |
TreePath[] paths = ((ITreeSelection) selection).getPaths(); |
|
72 |
Object firstSegment = paths[0].getFirstSegment(); |
|
73 |
if (firstSegment instanceof TaxonDescription) { |
|
74 |
description = (TaxonDescription) firstSegment; |
|
75 |
} |
|
76 |
}else if (selection instanceof IStructuredSelection) { |
|
77 |
Object selectedElement = ((IStructuredSelection) selection) |
|
78 |
.getFirstElement(); |
|
79 |
if (selectedElement instanceof TaxonDescription){ |
|
80 |
description = (TaxonDescription) selectedElement; |
|
81 |
} |
|
82 |
} |
|
57 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
|
58 |
if (selection instanceof IStructuredSelection) { |
|
59 |
Object selectedElement = ((IStructuredSelection) selection).getFirstElement(); |
|
60 |
if (selectedElement instanceof DescriptionBase<?>) { |
|
61 |
description = (DescriptionBase<?>) selectedElement; |
|
62 |
} |
|
63 |
} |
|
83 | 64 |
|
84 |
if (description != null) { |
|
85 |
AbstractPostOperation operation = null; |
|
86 |
try { |
|
87 |
// TODO use undo context specific to editor |
|
88 |
operation = operationCreationInstance(event.getCommand().getName(), event, taxon, description, postOperationEnabled); |
|
89 |
EditorUtil.executeOperation(operation); |
|
90 |
} catch (NotDefinedException e) { |
|
91 |
EditorUtil.warn(getClass(), "Command name not set"); |
|
92 |
} |
|
93 |
} else { |
|
94 |
EditorUtil.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); |
|
95 |
return null; |
|
96 |
} |
|
97 |
} |
|
98 |
return null; |
|
65 |
if (description != null) { |
|
66 |
AbstractPostOperation operation = null; |
|
67 |
try { |
|
68 |
// TODO use undo context specific to editor |
|
69 |
operation = operationCreationInstance(event.getCommand().getName(), event, description, postOperationEnabled); |
|
70 |
AbstractUtility.executeOperation(operation); |
|
71 |
} catch (NotDefinedException e) { |
|
72 |
AbstractUtility.warn(getClass(), "Command name not set"); |
|
73 |
} |
|
74 |
} else { |
|
75 |
AbstractUtility.error(getClass(), new IllegalArgumentException("Could not determine the taxon description")); |
|
76 |
return null; |
|
77 |
} |
|
78 |
return null; |
|
99 | 79 |
|
100 |
}
|
|
101 |
|
|
102 |
/**
|
|
80 |
}
|
|
81 |
|
|
82 |
/**
|
|
103 | 83 |
* Added to make the Class more generic and limit the amount of code changes required |
104 | 84 |
* @param label |
105 | 85 |
* @param event |
... | ... | |
108 | 88 |
* @param postOperationEnabled |
109 | 89 |
* @return |
110 | 90 |
*/ |
111 |
protected AbstractPostOperation operationCreationInstance(String label, ExecutionEvent event, Taxon taxon, TaxonDescription description, IPostOperationEnabled postOperationEnabled) {
|
|
91 |
protected AbstractPostOperation operationCreationInstance(String label, ExecutionEvent event, DescriptionBase<?> description, IPostOperationEnabled postOperationEnabled) {
|
|
112 | 92 |
Feature feature = (Feature) ((Event) event.getTrigger()).data; |
113 |
return new CreateDescriptionElementOperation(label, |
|
114 |
EditorUtil.getUndoContext(), taxon, |
|
115 |
description, feature, postOperationEnabled); |
|
93 |
return new CreateDescriptionElementOperation(label, EditorUtil.getUndoContext(), description, feature, postOperationEnabled); |
|
116 | 94 |
} |
117 | 95 |
|
118 | 96 |
} |
Also available in: Unified diff