Revision cf0a8f3f
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddImageGalleryHandler.java | ||
---|---|---|
7 | 7 |
import org.eclipse.core.commands.ExecutionEvent; |
8 | 8 |
import org.eclipse.core.commands.ExecutionException; |
9 | 9 |
import org.eclipse.core.commands.common.NotDefinedException; |
10 |
import org.eclipse.jface.viewers.ISelection; |
|
11 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
12 |
import org.eclipse.jface.viewers.TreeNode; |
|
13 |
import org.eclipse.ui.IEditorInput; |
|
14 |
import org.eclipse.ui.IEditorPart; |
|
15 | 10 |
import org.eclipse.ui.IWorkbenchPart; |
16 | 11 |
import org.eclipse.ui.handlers.HandlerUtil; |
17 | 12 |
|
18 | 13 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
14 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
19 | 15 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
20 | 16 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
21 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
22 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
23 | 17 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil; |
24 |
import eu.etaxonomy.taxeditor.bulkeditor.input.OccurrenceEditorInput; |
|
25 | 18 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
26 |
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput; |
|
27 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView; |
|
28 |
import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput; |
|
29 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart; |
|
30 | 19 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.AddDerivedUnitFacadeMediaOperation; |
31 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateSpecimenDescriptionOperation; |
|
32 | 20 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.operation.CreateTaxonDescriptionOperation; |
33 | 21 |
import eu.etaxonomy.taxeditor.editor.view.media.MediaViewPart; |
34 | 22 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
... | ... | |
37 | 25 |
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; |
38 | 26 |
|
39 | 27 |
/** |
40 |
* <p>AddImageGalleryHandler class.</p> |
|
41 |
* |
|
42 | 28 |
* @author p.ciardelli |
43 | 29 |
* @version $Id: $ |
44 | 30 |
*/ |
45 | 31 |
public class AddImageGalleryHandler extends AbstractHandler { |
46 | 32 |
|
47 |
/* (non-Javadoc) |
|
48 |
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) |
|
49 |
*/ |
|
50 | 33 |
/** {@inheritDoc} */ |
51 | 34 |
@Override |
52 | 35 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
53 | 36 |
|
54 |
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
55 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
|
|
37 |
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
38 |
IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
|
|
56 | 39 |
|
40 |
if(part instanceof MediaViewPart){ |
|
41 |
Object viewerInput = ((MediaViewPart)part).getViewer().getInput(); |
|
42 |
try { |
|
43 |
if(viewerInput instanceof CdmBase){ |
|
44 |
if(((CdmBase) viewerInput).isInstanceOf(Taxon.class)){ |
|
45 |
Taxon taxon = HibernateProxyHelper.deproxy(viewerInput, Taxon.class); |
|
57 | 46 |
|
58 |
IEditorPart editor = HandlerUtil.getActiveEditor(event);
|
|
59 |
IEditorInput input = editor.getEditorInput();
|
|
47 |
AbstractPostOperation<?> operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(),
|
|
48 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled, true);
|
|
60 | 49 |
|
61 |
if (input instanceof TaxonEditorInput) { |
|
62 |
Taxon taxon = ((TaxonEditorInput) input).getTaxon(); |
|
63 |
AbstractPostOperation<?> operation; |
|
64 |
try { |
|
65 |
// TODO use undo context specific to editor |
|
66 |
operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), |
|
67 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled, true); |
|
68 |
AbstractUtility.executeOperation(operation); |
|
69 |
} catch (NotDefinedException e) { |
|
70 |
MessagingUtils.warn(getClass(), "Command name not set."); |
|
71 |
} |
|
72 |
} |
|
73 |
else if(input instanceof OccurrenceEditorInput){ |
|
74 |
BulkEditor bulkEditor = (BulkEditor) editor; |
|
75 |
ISelection selection = bulkEditor.getSelectionProvider().getSelection(); |
|
76 |
invokeOperation(event, postOperationEnabled, selection); |
|
77 |
} |
|
78 |
else if(input instanceof DerivateViewEditorInput){ |
|
79 |
ISelection selection = ((DerivateView)editor).getSelection(); |
|
80 |
invokeOperation(event, postOperationEnabled, selection); |
|
81 |
} else if(part instanceof MediaViewPart){ |
|
82 |
Object viewerInput = ((MediaViewPart)part).getViewer().getInput(); |
|
83 |
|
|
84 |
if(viewerInput instanceof Taxon){ |
|
85 |
Taxon taxon = HibernateProxyHelper.deproxy(viewerInput, Taxon.class); |
|
86 |
AbstractPostOperation<?> operation; |
|
87 |
try { |
|
88 |
// TODO use undo context specific to editor |
|
89 |
operation = new CreateTaxonDescriptionOperation(event.getCommand().getName(), |
|
90 |
EditorUtil.getUndoContext(), taxon, postOperationEnabled, true); |
|
91 |
AbstractUtility.executeOperation(operation); |
|
92 |
} catch (NotDefinedException e) { |
|
93 |
MessagingUtils.warn(getClass(), "Command name not set."); |
|
94 |
} |
|
95 |
|
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
return null; |
|
100 |
} |
|
50 |
AbstractUtility.executeOperation(operation); |
|
51 |
} |
|
52 |
else if(((CdmBase) viewerInput).isInstanceOf(SpecimenOrObservationBase.class)){ |
|
53 |
SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(viewerInput, SpecimenOrObservationBase.class); |
|
101 | 54 |
|
102 |
/** |
|
103 |
* @param event |
|
104 |
* @param postOperationEnabled |
|
105 |
* @param selection |
|
106 |
*/ |
|
107 |
private void invokeOperation(ExecutionEvent event, IPostOperationEnabled postOperationEnabled, ISelection selection) { |
|
108 |
if(selection instanceof IStructuredSelection){ |
|
109 |
Object element = ((IStructuredSelection) selection).getFirstElement(); |
|
110 |
if(element instanceof TreeNode){ |
|
111 |
element = ((TreeNode) element).getValue(); |
|
112 |
} |
|
113 |
if(element instanceof SpecimenOrObservationBase<?>){ |
|
114 |
try { |
|
115 |
AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(), |
|
116 |
BulkEditorUtil.getUndoContext(), (SpecimenOrObservationBase<?>)element, postOperationEnabled); |
|
117 |
AbstractUtility.executeOperation(operation); |
|
118 |
} catch (NotDefinedException e) { |
|
119 |
MessagingUtils.warn(getClass(), "Command name not set."); |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
55 |
AbstractPostOperation<?> operation = new AddDerivedUnitFacadeMediaOperation(event.getCommand().getName(), |
|
56 |
BulkEditorUtil.getUndoContext(), specimen, postOperationEnabled); |
|
57 |
|
|
58 |
AbstractUtility.executeOperation(operation); |
|
59 |
} |
|
60 |
} |
|
61 |
} catch (NotDefinedException e) { |
|
62 |
MessagingUtils.warn(getClass(), "Command name not set."); |
|
63 |
} |
|
64 |
} |
|
65 |
return null; |
|
66 |
} |
|
124 | 67 |
|
125 |
} |
|
68 |
} |
Also available in: Unified diff
Fix and refactor addImageGallerHandler