Revision 3be6ef3e
Added by Niels Hoffmann over 13 years ago
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/CreateMediaHandler.java | ||
---|---|---|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.view.media.handler; |
|
5 |
|
|
6 |
import org.apache.log4j.Logger; |
|
7 |
import org.eclipse.core.commands.AbstractHandler; |
|
8 |
import org.eclipse.core.commands.ExecutionEvent; |
|
9 |
import org.eclipse.core.commands.ExecutionException; |
|
10 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
11 |
import org.eclipse.jface.viewers.ISelection; |
|
12 |
import org.eclipse.jface.viewers.TreePath; |
|
13 |
import org.eclipse.jface.viewers.TreeSelection; |
|
14 |
import org.eclipse.ui.IEditorInput; |
|
15 |
import org.eclipse.ui.IEditorPart; |
|
16 |
import org.eclipse.ui.IWorkbenchPart; |
|
17 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
18 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
22 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
23 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
24 |
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation; |
|
25 |
import eu.etaxonomy.taxeditor.operations.AddMediaToImageGalleryOperation; |
|
26 |
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author p.ciardelli |
|
30 |
* |
|
31 |
*/ |
|
32 |
public class CreateMediaHandler extends AbstractHandler { |
|
33 |
private static final Logger logger = Logger |
|
34 |
.getLogger(CreateMediaHandler.class); |
|
35 |
|
|
36 |
/* (non-Javadoc) |
|
37 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
38 |
*/ |
|
39 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
40 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
41 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; |
|
42 |
|
|
43 |
|
|
44 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
45 |
if (editor instanceof FormEditor) { |
|
46 |
editor = ((FormEditor) editor).getActiveEditor(); |
|
47 |
} |
|
48 |
IEditorInput input = editor.getEditorInput(); |
|
49 |
if (input instanceof TaxonEditorInput) { |
|
50 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
51 |
|
|
52 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
|
53 |
if (selection instanceof TreeSelection) { |
|
54 |
TreePath[] paths = ((TreeSelection) selection).getPaths(); |
|
55 |
|
|
56 |
int count = paths[0].getSegmentCount(); |
|
57 |
DescriptionBase description = null; |
|
58 |
for (int i = 0; i < count; i++ ) { |
|
59 |
if (paths[0].getSegment(i) instanceof DescriptionBase) { |
|
60 |
description = (DescriptionBase) paths[0].getSegment(i); |
|
61 |
break; |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
AbstractPostOperation operation = null; |
|
66 |
try { |
|
67 |
// TODO use undo context specific to editor |
|
68 |
operation = new AddMediaToImageGalleryOperation(event.getCommand().getName(), |
|
69 |
EditorUtil.getUndoContext(), taxon, description, postOperationEnabled); |
|
70 |
EditorUtil.executeOperation(operation); |
|
71 |
} catch (NotDefinedException e) { |
|
72 |
logger.warn("Command name not set"); |
|
73 |
} |
|
74 |
} |
|
75 |
} |
|
76 |
return null; |
|
77 |
} |
|
78 |
|
|
79 |
} |
|
1 |
/** |
|
2 |
* |
|
3 |
*/ |
|
4 |
package eu.etaxonomy.taxeditor.editor.view.media.handler; |
|
5 |
|
|
6 |
import org.apache.log4j.Logger; |
|
7 |
import org.eclipse.core.commands.AbstractHandler; |
|
8 |
import org.eclipse.core.commands.ExecutionEvent; |
|
9 |
import org.eclipse.core.commands.ExecutionException; |
|
10 |
import org.eclipse.core.commands.common.NotDefinedException; |
|
11 |
import org.eclipse.jface.viewers.ISelection; |
|
12 |
import org.eclipse.jface.viewers.TreePath; |
|
13 |
import org.eclipse.jface.viewers.TreeSelection; |
|
14 |
import org.eclipse.ui.IEditorInput; |
|
15 |
import org.eclipse.ui.IEditorPart; |
|
16 |
import org.eclipse.ui.IWorkbenchPart; |
|
17 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
18 |
import org.eclipse.ui.handlers.HandlerUtil; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
21 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
22 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
23 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
24 |
import eu.etaxonomy.taxeditor.operations.AbstractPostOperation; |
|
25 |
import eu.etaxonomy.taxeditor.operations.AddMediaToImageGalleryOperation; |
|
26 |
import eu.etaxonomy.taxeditor.operations.IPostOperationEnabled; |
|
27 |
|
|
28 |
/** |
|
29 |
* <p>CreateMediaHandler class.</p> |
|
30 |
* |
|
31 |
* @author p.ciardelli |
|
32 |
* @version $Id: $ |
|
33 |
*/ |
|
34 |
public class CreateMediaHandler extends AbstractHandler { |
|
35 |
private static final Logger logger = Logger |
|
36 |
.getLogger(CreateMediaHandler.class); |
|
37 |
|
|
38 |
/* (non-Javadoc) |
|
39 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
40 |
*/ |
|
41 |
/** {@inheritDoc} */ |
|
42 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
|
43 |
IWorkbenchPart part = HandlerUtil.getActivePart(event); |
|
44 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null; |
|
45 |
|
|
46 |
|
|
47 |
IEditorPart editor = HandlerUtil.getActiveEditor(event); |
|
48 |
if (editor instanceof FormEditor) { |
|
49 |
editor = ((FormEditor) editor).getActiveEditor(); |
|
50 |
} |
|
51 |
IEditorInput input = editor.getEditorInput(); |
|
52 |
if (input instanceof TaxonEditorInput) { |
|
53 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
54 |
|
|
55 |
ISelection selection = HandlerUtil.getCurrentSelection(event); |
|
56 |
if (selection instanceof TreeSelection) { |
|
57 |
TreePath[] paths = ((TreeSelection) selection).getPaths(); |
|
58 |
|
|
59 |
int count = paths[0].getSegmentCount(); |
|
60 |
DescriptionBase description = null; |
|
61 |
for (int i = 0; i < count; i++ ) { |
|
62 |
if (paths[0].getSegment(i) instanceof DescriptionBase) { |
|
63 |
description = (DescriptionBase) paths[0].getSegment(i); |
|
64 |
break; |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
AbstractPostOperation operation = null; |
|
69 |
try { |
|
70 |
// TODO use undo context specific to editor |
|
71 |
operation = new AddMediaToImageGalleryOperation(event.getCommand().getName(), |
|
72 |
EditorUtil.getUndoContext(), taxon, description, postOperationEnabled); |
|
73 |
EditorUtil.executeOperation(operation); |
|
74 |
} catch (NotDefinedException e) { |
|
75 |
logger.warn("Command name not set"); |
|
76 |
} |
|
77 |
} |
|
78 |
} |
|
79 |
return null; |
|
80 |
} |
|
81 |
|
|
82 |
} |
Also available in: Unified diff
performed javacscript:fix and worked on documentation