Project

General

Profile

Download (3.13 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

    
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
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

    
33
/**
34
 *
35
 * @author p.ciardelli
36
 * @created 11.08.2009
37
 * @version 1.0
38
 */
39
public class MoveImageDownInListHandler  {
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();
55

    
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 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
                AbstractPostOperation operation = null;
68
                // TODO use undo context specific to editor
69
                operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(),
70
                        EditorUtil.getUndoContext(), taxon, description, media, MoveMediaInListOperation.DOWN, mediaView);
71
                AbstractUtility.executeOperation(operation, sync);
72
            }
73
        }
74
    }
75

    
76
}
(5-5/6)