Project

General

Profile

« Previous | Next » 

Revision e6aba306

Added by Patrick Plitzner over 6 years ago

ref #6906 Migrate media view context menu

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageUpInListHandler.java
1 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
*/
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 9
package eu.etaxonomy.taxeditor.editor.view.media.handler;
10
import org.eclipse.core.commands.AbstractHandler;
11
import org.eclipse.core.commands.ExecutionEvent;
12
import org.eclipse.core.commands.ExecutionException;
13
import org.eclipse.core.commands.common.NotDefinedException;
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;
14 16
import org.eclipse.jface.viewers.ISelection;
15 17
import org.eclipse.jface.viewers.TreePath;
16 18
import org.eclipse.jface.viewers.TreeSelection;
17 19
import org.eclipse.ui.IEditorInput;
18 20
import org.eclipse.ui.IEditorPart;
19
import org.eclipse.ui.IWorkbenchPart;
20 21
import org.eclipse.ui.forms.editor.FormEditor;
21
import org.eclipse.ui.handlers.HandlerUtil;
22 22

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

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

  
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44
	 */
45
	/** {@inheritDoc} */
46
	public Object execute(ExecutionEvent event) throws ExecutionException {
47
		IWorkbenchPart part = HandlerUtil.getActivePart(event);
48
		IPostOperationEnabled postOperationEnabled = (part instanceof IPostOperationEnabled) ? (IPostOperationEnabled) part : null;
49
				
50
		IEditorPart editor = HandlerUtil.getActiveEditor(event);
51
		if (editor instanceof FormEditor) {
52
			editor = ((FormEditor) editor).getActiveEditor();
53
		}
54
		IEditorInput input = editor.getEditorInput();
55
		if (input instanceof TaxonEditorInput) {
56
			Taxon taxon = ((TaxonEditorInput) input).getTaxon();
57
			
58
			ISelection selection = HandlerUtil.getCurrentSelection(event);
59
			if (selection instanceof TreeSelection) {
60
				TreePath[] paths = ((TreeSelection) selection).getPaths();
61
				int count = paths[0].getSegmentCount();
62
				DescriptionBase element = null;
63
				for (int i = 0; i < count; i++ ) {
64
					if (paths[0].getSegment(i) instanceof DescriptionBase) {
65
						element = (DescriptionBase) paths[0].getSegment(i);
66
						break;
67
					}
68
				}				
69
				Media media = (Media) paths[0].getLastSegment();
70
				AbstractPostOperation operation = null;
71
				try {
72
					// TODO use undo context specific to editor
73
					operation = new MoveMediaInListOperation(event.getCommand().getName(), 
74
							EditorUtil.getUndoContext(), taxon, element, media, MoveMediaInListOperation.UP, postOperationEnabled);
75
					EditorUtil.executeOperation(operation);
76
				} catch (NotDefinedException e) {
77
					MessagingUtils.warn(getClass(), "Command name not set."); //$NON-NLS-1$
78
				}
79
			}
80
		} 
81
		return null;
82
	}
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
    }
83 77

  
84 78
}

Also available in: Unified diff