Project

General

Profile

Download (3.22 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.model.application.ui.basic.MPart;
14
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
15
import org.eclipse.e4.ui.services.IServiceConstants;
16
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.TreePath;
18
import org.eclipse.jface.viewers.TreeSelection;
19
import org.eclipse.ui.IEditorInput;
20
import org.eclipse.ui.IEditorPart;
21
import org.eclipse.ui.forms.editor.FormEditor;
22

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

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

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

    
47
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
48

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

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

    
78
}
(6-6/6)