Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/handler/AddDescriptionHandler.java | ||
---|---|---|
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 |
package eu.etaxonomy.taxeditor.editor.view.descriptive.handler; |
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.eclipse.core.commands.AbstractHandler; |
|
13 |
import org.eclipse.core.commands.ExecutionEvent; |
|
14 |
import org.eclipse.core.commands.ExecutionException; |
|
15 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
16 |
import org.eclipse.ui.IEditorInput; |
|
17 |
import org.eclipse.ui.IEditorPart; |
|
18 |
import org.eclipse.ui.IWorkbenchPart; |
|
19 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
20 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
23 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
24 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
25 |
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation; |
|
26 |
import eu.etaxonomy.taxeditor.operations.CreateTaxonDescriptionOperation; |
|
27 |
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author p.ciardelli |
|
31 |
* @created 11.08.2009 |
|
32 |
* @version 1.0 |
|
33 |
*/ |
|
34 |
public class AddDescriptionHandler extends AbstractHandler { |
|
35 |
private static final Logger logger = Logger |
|
36 |
.getLogger(CreateDescriptionElementHandler.class); |
|
37 |
|
|
38 |
/* (non-Javadoc) |
|
39 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
40 |
*/ |
|
41 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
42 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
43 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; |
|
44 |
|
|
45 |
|
|
46 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
47 |
if (editor instanceof FormEditor) { |
|
48 |
editor = ((FormEditor) editor).getActiveEditor(); |
|
49 |
} |
|
50 |
IEditorInput input = editor.getEditorInput(); |
|
51 |
if (input instanceof TaxonEditorInput) { |
|
52 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
53 |
AbstractPostOperation operation; |
|
54 |
try { |
|
55 |
// TODO use undo context specific to editor |
|
56 |
operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), |
|
57 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
58 |
EditorUtil.executeOperation(operation); |
|
59 |
} catch (NotDefinedException e) { |
|
60 |
logger.warn("Command name not set"); |
|
61 |
} |
|
62 |
} |
|
63 |
return null; |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
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 |
package eu.etaxonomy.taxeditor.editor.view.descriptive.handler; |
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.eclipse.core.commands.AbstractHandler; |
|
13 |
import org.eclipse.core.commands.ExecutionEvent; |
|
14 |
import org.eclipse.core.commands.ExecutionException; |
|
15 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
16 |
import org.eclipse.ui.IEditorInput; |
|
17 |
import org.eclipse.ui.IEditorPart; |
|
18 |
import org.eclipse.ui.IWorkbenchPart; |
|
19 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
20 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
21 |
|
|
22 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
23 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
24 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
25 |
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation; |
|
26 |
import eu.etaxonomy.taxeditor.operations.CreateTaxonDescriptionOperation; |
|
27 |
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; |
|
28 |
|
|
29 |
/** |
|
30 |
* <p>AddDescriptionHandler class.</p> |
|
31 |
* |
|
32 |
* @author p.ciardelli |
|
33 |
* @created 11.08.2009 |
|
34 |
* @version 1.0 |
|
35 |
*/ |
|
36 |
public class AddDescriptionHandler extends AbstractHandler { |
|
37 |
private static final Logger logger = Logger |
|
38 |
.getLogger(CreateDescriptionElementHandler.class); |
|
39 |
|
|
40 |
/* (non-Javadoc) |
|
41 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
42 |
*/ |
|
43 |
/** {@inheritDoc} */ |
|
44 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
45 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
46 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; |
|
47 |
|
|
48 |
|
|
49 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
50 |
if (editor instanceof FormEditor) { |
|
51 |
editor = ((FormEditor) editor).getActiveEditor(); |
|
52 |
} |
|
53 |
IEditorInput input = editor.getEditorInput(); |
|
54 |
if (input instanceof TaxonEditorInput) { |
|
55 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
56 |
AbstractPostOperation operation; |
|
57 |
try { |
|
58 |
// TODO use undo context specific to editor |
|
59 |
operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), |
|
60 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled); |
|
61 |
EditorUtil.executeOperation(operation); |
|
62 |
} catch (NotDefinedException e) { |
|
63 |
logger.warn("Command name not set"); |
|
64 |
} |
|
65 |
} |
|
66 |
return null; |
|
67 |
} |
|
68 |
|
|
69 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation