Revision 017f41a2
Added by Patrick Plitzner almost 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java | ||
---|---|---|
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.view.media.handler; |
10 |
import javax.inject.Named; |
|
11 | 10 |
|
12 |
import org.eclipse.e4.core.di.annotations.Execute; |
|
13 |
import org.eclipse.e4.ui.di.UISynchronize; |
|
14 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart; |
|
15 |
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem; |
|
16 |
import org.eclipse.e4.ui.services.IServiceConstants; |
|
17 |
import org.eclipse.jface.viewers.ISelection; |
|
18 |
import org.eclipse.jface.viewers.TreePath; |
|
19 |
import org.eclipse.jface.viewers.TreeSelection; |
|
20 |
|
|
21 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
22 |
import eu.etaxonomy.cdm.model.media.Media; |
|
23 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
24 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
25 |
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4; |
|
26 |
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4; |
|
27 |
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4; |
|
28 | 11 |
import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation; |
29 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
|
30 |
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation; |
|
31 |
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility; |
|
32 | 12 |
|
33 | 13 |
/** |
34 | 14 |
* |
... | ... | |
36 | 16 |
* @created 11.08.2009 |
37 | 17 |
* @version 1.0 |
38 | 18 |
*/ |
39 |
public class MoveImageUpInListHandler { |
|
40 |
|
|
41 |
@Execute |
|
42 |
public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart, |
|
43 |
@Named(IServiceConstants.ACTIVE_SELECTION) Media media, |
|
44 |
MMenuItem menuItem, |
|
45 |
UISynchronize sync) { |
|
46 |
|
|
47 |
MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject(); |
|
48 |
|
|
49 |
TaxonNameEditorE4 editor = null; |
|
50 |
Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart()); |
|
51 |
if (e4WrappedPart instanceof TaxonNameEditorE4) { |
|
52 |
editor = (TaxonNameEditorE4) e4WrappedPart; |
|
53 |
TaxonEditorInputE4 input = editor.getEditorInput(); |
|
54 |
Taxon taxon =input.getTaxon(); |
|
19 |
public class MoveImageUpInListHandler extends AbstractMoveImageHandler{ |
|
55 | 20 |
|
56 |
ISelection selection = mediaView.getViewer().getSelection(); |
|
57 |
if (selection instanceof TreeSelection) { |
|
58 |
TreePath[] paths = ((TreeSelection) selection).getPaths(); |
|
59 |
int count = paths[0].getSegmentCount(); |
|
60 |
DescriptionBase element = null; |
|
61 |
for (int i = 0; i < count; i++ ) { |
|
62 |
if (paths[0].getSegment(i) instanceof DescriptionBase) { |
|
63 |
element = (DescriptionBase) paths[0].getSegment(i); |
|
64 |
break; |
|
65 |
} |
|
66 |
} |
|
67 |
AbstractPostOperation operation = null; |
|
68 |
// TODO use undo context specific to editor |
|
69 |
operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(), |
|
70 |
EditorUtil.getUndoContext(), taxon, element, media, MoveMediaInListOperation.UP, mediaView); |
|
71 |
AbstractUtility.executeOperation(operation, sync); |
|
72 |
} |
|
73 |
} |
|
21 |
@Override |
|
22 |
public int moveImageOperation() { |
|
23 |
return MoveMediaInListOperation.UP; |
|
74 | 24 |
} |
75 | 25 |
|
76 | 26 |
} |
Also available in: Unified diff
ref #7010 Adapt media view handlers for multiple selection