Project

General

Profile

Download (3.31 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.view.media.handler;
10
import javax.inject.Named;
11

    
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
import org.eclipse.ui.IEditorInput;
21
import org.eclipse.ui.IEditorPart;
22
import org.eclipse.ui.forms.editor.FormEditor;
23

    
24
import eu.etaxonomy.cdm.model.description.DescriptionBase;
25
import eu.etaxonomy.cdm.model.media.Media;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.taxeditor.editor.EditorUtil;
28
import eu.etaxonomy.taxeditor.editor.TaxonEditorInput;
29
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
30
import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation;
31
import eu.etaxonomy.taxeditor.model.AbstractUtility;
32
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
33
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
34

    
35
/**
36
 *
37
 * @author p.ciardelli
38
 * @created 11.08.2009
39
 * @version 1.0
40
 */
41
public class MoveImageDownInListHandler  {
42

    
43
    @Execute
44
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
45
            @Named(IServiceConstants.ACTIVE_SELECTION) Media media,
46
            MMenuItem menuItem,
47
            UISynchronize sync) {
48

    
49
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
50

    
51
        IEditorPart editor = null;
52
        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(mediaView.getSelectionProvidingPart());
53
        if (e4WrappedPart instanceof FormEditor) {
54
            editor = (FormEditor) e4WrappedPart;
55
            IEditorInput input = editor.getEditorInput();
56
            if (input instanceof TaxonEditorInput) {
57
                Taxon taxon = ((TaxonEditorInput) input).getTaxon();
58

    
59
                ISelection selection = mediaView.getViewer().getSelection();
60
                if (selection instanceof TreeSelection) {
61
                    TreePath[] paths = ((TreeSelection) selection).getPaths();
62
                    int count = paths[0].getSegmentCount();
63
                    DescriptionBase description = null;
64
                    for (int i = 0; i < count; i++ ) {
65
                        if (paths[0].getSegment(i) instanceof DescriptionBase) {
66
                            description = (DescriptionBase) paths[0].getSegment(i);
67
                            break;
68
                        }
69
                    }
70
                    AbstractPostOperation operation = null;
71
                    // TODO use undo context specific to editor
72
                    operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(),
73
                            EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, mediaView);
74
                    AbstractUtility.executeOperation(operation, sync);
75
                }
76
            }
77
        }
78
	}
79

    
80
}
(5-5/6)