Revision 15d18885
Added by Alex Theys almost 12 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/CreateDescriptionHandler.java | ||
---|---|---|
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.view.descriptive.handler; |
11 |
|
|
11 | 12 |
import org.eclipse.core.commands.AbstractHandler; |
12 | 13 |
import org.eclipse.core.commands.ExecutionEvent; |
13 | 14 |
import org.eclipse.core.commands.ExecutionException; |
... | ... | |
52 | 53 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
53 | 54 |
AbstractPostOperation operation; |
54 | 55 |
try { |
55 |
// TODO use undo context specific to editor |
|
56 |
operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), |
|
57 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
56 |
|
|
57 |
operation = createOperationInstance(event.getCommand().getName(), taxon, postOperationEnabled); |
|
58 | 58 |
EditorUtil.executeOperation(operation); |
59 | 59 |
} catch (NotDefinedException e) { |
60 | 60 |
EditorUtil.warn(getClass(), "Command name not set."); |
... | ... | |
62 | 62 |
} |
63 | 63 |
return null; |
64 | 64 |
} |
65 |
|
|
66 |
protected AbstractPostOperation createOperationInstance(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) { |
|
67 |
// TODO use undo context specific to editor |
|
68 |
return new CreateTaxonDescriptionOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
69 |
} |
|
70 |
|
|
65 | 71 |
|
66 | 72 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/CreateUseHandler.java | ||
---|---|---|
13 | 13 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
14 | 14 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
15 | 15 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
16 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionHandler; |
|
17 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation; |
|
16 | 18 |
import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateTaxonUseOperation; |
17 | 19 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
18 | 20 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
... | ... | |
24 | 26 |
* @created mar 13, 2012 |
25 | 27 |
* @version 1.0 |
26 | 28 |
*/ |
27 |
public class CreateUseHandler extends AbstractHandler {
|
|
29 |
public class CreateUseHandler extends CreateDescriptionHandler {
|
|
28 | 30 |
/* (non-Javadoc) |
29 | 31 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
30 | 32 |
*/ |
31 | 33 |
/** {@inheritDoc} */ |
32 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
33 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
34 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; |
|
35 |
|
|
36 |
|
|
37 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
38 |
if (editor instanceof FormEditor) { |
|
39 |
editor = ((FormEditor) editor).getActiveEditor(); |
|
40 |
} |
|
41 |
IEditorInput input = editor.getEditorInput(); |
|
42 |
if (input instanceof TaxonEditorInput) { |
|
43 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
44 |
AbstractPostOperation operation; |
|
45 |
try { |
|
46 |
operation = new CreateTaxonUseOperation(event.getCommand().getName(), |
|
47 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
48 |
EditorUtil.executeOperation(operation); |
|
49 |
} catch (NotDefinedException e) { |
|
50 |
EditorUtil.warn(getClass(), "Command name not set."); |
|
51 |
} |
|
52 |
} |
|
53 |
return null; |
|
34 |
@Override |
|
35 |
protected AbstractPostOperation createOperationInstance(String eventLabel, Taxon taxon, IPostOperationEnabled postOperationEnabled) { |
|
36 |
return new CreateTaxonUseOperation(eventLabel, EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
54 | 37 |
} |
55 | 38 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/CreateUseRecordHandler.java | ||
---|---|---|
23 | 23 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
24 | 24 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
25 | 25 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
26 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionElementHandler; |
|
26 | 27 |
import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateUseRecordOperation; |
27 | 28 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
28 | 29 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
... | ... | |
35 | 36 |
* @created mar 13, 2012 |
36 | 37 |
* @version 1.0 |
37 | 38 |
*/ |
38 |
public class CreateUseRecordHandler extends AbstractHandler { |
|
39 |
public class CreateUseRecordHandler extends CreateDescriptionElementHandler { |
|
40 |
@Override |
|
39 | 41 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
40 | 42 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
41 | 43 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/handler/CreateUseSummaryHandler.java | ||
---|---|---|
23 | 23 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
24 | 24 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
25 | 25 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
26 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.handler.CreateDescriptionElementHandler; |
|
26 | 27 |
import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateUseRecordOperation; |
27 | 28 |
import eu.etaxonomy.taxeditor.editor.view.uses.operation.CreateUseSummaryOperation; |
28 | 29 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
... | ... | |
36 | 37 |
* @created mar 13, 2012 |
37 | 38 |
* @version 1.0 |
38 | 39 |
*/ |
39 |
public class CreateUseSummaryHandler extends AbstractHandler { |
|
40 |
public class CreateUseSummaryHandler extends CreateDescriptionElementHandler { |
|
41 |
@Override |
|
40 | 42 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
41 | 43 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
42 | 44 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateTaxonUseOperation.java | ||
---|---|---|
18 | 18 |
import eu.etaxonomy.cdm.model.description.TextData; |
19 | 19 |
import eu.etaxonomy.cdm.model.media.Media; |
20 | 20 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
21 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation; |
|
21 | 22 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
22 | 23 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
23 | 24 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
... | ... | |
29 | 30 |
* @created mar 13, 2012 |
30 | 31 |
* @version 1.0 |
31 | 32 |
*/ |
32 |
public class CreateTaxonUseOperation extends AbstractPostOperation {
|
|
33 |
public class CreateTaxonUseOperation extends CreateTaxonDescriptionOperation {
|
|
33 | 34 |
private TaxonDescription description; |
34 | 35 |
private Marker marker; |
35 | 36 |
|
... | ... | |
77 | 78 |
|
78 | 79 |
return postExecute(description); |
79 | 80 |
} |
80 |
|
|
81 |
/* (non-Javadoc) |
|
82 |
* @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
83 |
*/ |
|
84 |
/** {@inheritDoc} */ |
|
85 |
@Override |
|
86 |
public IStatus redo(IProgressMonitor monitor, IAdaptable info) |
|
87 |
throws ExecutionException { |
|
88 |
|
|
89 |
taxon.addDescription(description); |
|
90 |
|
|
91 |
return postExecute(description); |
|
92 |
} |
|
93 |
|
|
94 |
/* (non-Javadoc) |
|
95 |
* @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) |
|
96 |
*/ |
|
97 |
/** {@inheritDoc} */ |
|
98 |
@Override |
|
99 |
public IStatus undo(IProgressMonitor monitor, IAdaptable info) |
|
100 |
throws ExecutionException { |
|
101 |
|
|
102 |
taxon.removeDescription(description); |
|
103 |
|
|
104 |
return postExecute(null); |
|
105 |
} |
|
106 | 81 |
} |
107 | 82 |
|
Also available in: Unified diff
AT: committing changes to the TaxEditor Post first round of code review