Project

General

Profile

« Previous | Next » 

Revision 017f41a2

Added by Patrick Plitzner almost 6 years ago

ref #7010 Adapt media view handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/e4/MediaViewPartE4.java
29 29
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
30 30
import eu.etaxonomy.taxeditor.editor.view.media.MediaContentProvider;
31 31
import eu.etaxonomy.taxeditor.editor.view.media.MediaViewLabelProvider;
32
import eu.etaxonomy.taxeditor.model.AbstractUtility;
33 32
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
34 33
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
35 34
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
......
51 50

  
52 51
	    this.thisPart = thisPart;
53 52
		TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
54
				| SWT.V_SCROLL | SWT.FULL_SELECTION));
53
				| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
55 54

  
56 55
		treeViewer.setContentProvider(new MediaContentProvider());
57 56
		treeViewer.setLabelProvider(new MediaViewLabelProvider());
......
64 63
		viewer = treeViewer;
65 64

  
66 65
		// Propagate selection from viewer
67
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
66
        selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
68 67
        viewer.addSelectionChangedListener(selectionChangedListener);
69 68

  
70 69
        //create context menu
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AbstractMoveImageHandler.java
1
/**
2
* Copyright (C) 2018 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

  
11
import javax.inject.Named;
12

  
13
import org.eclipse.e4.core.di.annotations.CanExecute;
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.di.UISynchronize;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.jface.viewers.TreePath;
22
import org.eclipse.jface.viewers.TreeSelection;
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.e4.TaxonEditorInputE4;
29
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
30
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
31
import eu.etaxonomy.taxeditor.editor.view.media.operation.MoveMediaInListOperation;
32
import eu.etaxonomy.taxeditor.model.AbstractUtility;
33
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
34
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
35

  
36
/**
37
 * @author pplitzner
38
 * @since Jun 6, 2018
39
 *
40
 */
41
public abstract class AbstractMoveImageHandler {
42
    @Execute
43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
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
            TreeSelection selection = (TreeSelection) mediaView.getViewer().getSelection();
57
            TreePath[] paths = selection.getPaths();
58
            int count = paths[0].getSegmentCount();
59
            DescriptionBase description = null;
60
            for (int i = 0; i < count; i++ ) {
61
                if (paths[0].getSegment(i) instanceof DescriptionBase) {
62
                    description = (DescriptionBase) paths[0].getSegment(i);
63
                    break;
64
                }
65
            }
66
            AbstractPostOperation operation = null;
67
            // TODO use undo context specific to editor
68
            operation = new MoveMediaInListOperation(menuItem.getLocalizedLabel(),
69
                    EditorUtil.getUndoContext(),
70
                    taxon,
71
                    description,
72
                    (Media)selection.getFirstElement(),
73
                    moveImageOperation(),
74
                    mediaView);
75
            AbstractUtility.executeOperation(operation, sync);
76
        }
77
    }
78

  
79
    public abstract int moveImageOperation();
80

  
81
    @CanExecute
82
    private boolean canExecute(MHandledMenuItem menuItem,
83
            @Named(IServiceConstants.ACTIVE_PART) MPart activePart){
84
        boolean canExecute = false;
85
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
86
        ISelection selection = mediaView.getViewer().getSelection();
87
        canExecute = selection instanceof TreeSelection
88
                && ((TreeSelection) selection).size()==1
89
                && ((TreeSelection) selection).getFirstElement() instanceof Media;
90
        menuItem.setVisible(canExecute);
91
        return canExecute;
92
    }
93
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/AddExistingMediaHandler.java
7 7
import org.eclipse.e4.core.di.annotations.Optional;
8 8
import org.eclipse.e4.ui.di.UISynchronize;
9 9
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
10
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
10 11
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
11 12
import org.eclipse.e4.ui.services.IServiceConstants;
13
import org.eclipse.jface.viewers.IStructuredSelection;
12 14

  
13 15
import eu.etaxonomy.cdm.model.description.DescriptionBase;
14 16
import eu.etaxonomy.cdm.model.media.Media;
......
23 25

  
24 26
    @Execute
25 27
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
26
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MMenuItem menuItem,
28
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
27 29
            UISynchronize sync) {
28 30

  
29 31
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
30 32

  
31
        if(description != null){
32
            AbstractPostOperation operation = null;
33
            //select media
34
            Media media = MediaSelectionDialog.select(AbstractUtility.getShell(),// null,
35
                    null);
36
            if(media!=null){
37
                // TODO use undo context specific to editor
38
                operation = new AddExistingMediaToImageGalleryOperation(media, menuItem.getLocalizedLabel(),
39
                        EditorUtil.getUndoContext(), description, mediaView);
40
                AbstractUtility.executeOperation(operation, sync);
41
            }
33
        AbstractPostOperation operation = null;
34
        //select media
35
        Media media = MediaSelectionDialog.select(AbstractUtility.getShell(),// null,
36
                null);
37
        if(media!=null){
38
            // TODO use undo context specific to editor
39
            operation = new AddExistingMediaToImageGalleryOperation(media, menuItem.getLocalizedLabel(),
40
                    EditorUtil.getUndoContext(), (DescriptionBase<?>) selection.getFirstElement(), mediaView);
41
            AbstractUtility.executeOperation(operation, sync);
42 42
        }
43 43
    }
44 44

  
45 45
    @CanExecute
46
    private boolean canExecute(){
47
        return true;
46
    private boolean canExecute(MHandledMenuItem menuItem,
47
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
48
        boolean canExecute = false;
49
        canExecute = selection.size()==1 && selection.getFirstElement() instanceof DescriptionBase;
50
        menuItem.setVisible(canExecute);
51
        return canExecute;
48 52
    }
49 53

  
50 54
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/CreateMediaHandler.java
5 5

  
6 6
import javax.inject.Named;
7 7

  
8
import org.eclipse.e4.core.di.annotations.CanExecute;
8 9
import org.eclipse.e4.core.di.annotations.Execute;
9 10
import org.eclipse.e4.core.di.annotations.Optional;
10 11
import org.eclipse.e4.ui.di.UISynchronize;
11 12
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
13
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
12 14
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
13 15
import org.eclipse.e4.ui.services.IServiceConstants;
16
import org.eclipse.jface.viewers.IStructuredSelection;
14 17

  
15 18
import eu.etaxonomy.cdm.model.description.DescriptionBase;
16 19
import eu.etaxonomy.taxeditor.editor.EditorUtil;
......
29 32

  
30 33
    @Execute
31 34
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
32
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) DescriptionBase description, MMenuItem menuItem,
35
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
33 36
            UISynchronize sync) {
34 37

  
35 38
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
36 39

  
37
		if(description != null){
38
			AbstractPostOperation operation = null;
39
			// TODO use undo context specific to editor
40
            operation = new AddMediaToImageGalleryOperation(menuItem.getLocalizedLabel(),
41
                    EditorUtil.getUndoContext(), description, mediaView);
42
            AbstractUtility.executeOperation(operation, sync);
43
		}
40
        AbstractPostOperation operation = null;
41
        // TODO use undo context specific to editor
42
        operation = new AddMediaToImageGalleryOperation(menuItem.getLocalizedLabel(),
43
                EditorUtil.getUndoContext(), (DescriptionBase<?>) selection.getFirstElement(), mediaView);
44
        AbstractUtility.executeOperation(operation, sync);
44 45
	}
45 46

  
47
    @CanExecute
48
    private boolean canExecute(MHandledMenuItem menuItem,
49
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
50
        boolean canExecute = false;
51
        canExecute = selection.size()==1 && selection.getFirstElement() instanceof DescriptionBase;
52
        menuItem.setVisible(canExecute);
53
        return canExecute;
54
    }
55

  
46 56
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/DeleteMediaHandler.java
3 3
 */
4 4
package eu.etaxonomy.taxeditor.editor.view.media.handler;
5 5

  
6
import java.util.Iterator;
7

  
6 8
import javax.inject.Named;
7 9

  
8 10
import org.eclipse.core.runtime.IStatus;
......
45 47

  
46 48
    @Execute
47 49
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
48
            @Named(IServiceConstants.ACTIVE_SELECTION) Object object,
49 50
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
50 51
            MMenuItem menuItem,
51 52
            UISynchronize sync) {
52 53

  
53 54
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
55
        TreeSelection selection = (TreeSelection) mediaView.getViewer().getSelection();
54 56

  
55
        ISelection selection = mediaView.getViewer().getSelection();
56
        if (selection instanceof TreeSelection) {
57
            TreePath[] paths = ((TreeSelection) selection).getPaths();
57
        for(Iterator iter = selection.iterator();iter.hasNext();){
58
            Object object = iter.next();
59
            TreePath[] paths = selection.getPaths();
58 60
            int count = paths[0].getSegmentCount();
59 61
            DescriptionBase description = null;
60 62
            for (int i = 0; i < count; i++ ) {
......
94 96
                else if(object instanceof SpecimenDescription){
95 97
                    DeleteSpecimenDescriptionOperation deleteTaxonDescriptionOperation = new DeleteSpecimenDescriptionOperation(menuItem.getLocalizedLabel(), EditorUtil.getUndoContext(), (SpecimenDescription)object, mediaView, null);
96 98
                    AbstractUtility.executeOperation(deleteTaxonDescriptionOperation, sync);
97

  
98 99
                }
99 100
            }
100

  
101 101
        }
102 102
    }
103 103

  
104 104
    @CanExecute
105
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) Object object,
105
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
106 106
            MHandledMenuItem menuItem){
107
        boolean canExecute = false;
108
        canExecute = object instanceof Media
109
                || (object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery());
107
        MediaViewPartE4 mediaView = (MediaViewPartE4) activePart.getObject();
108
        ISelection selection = mediaView.getViewer().getSelection();
109

  
110
        boolean canExecute = selection instanceof TreeSelection && !selection.isEmpty();
111
        for(Iterator iter = ((TreeSelection) selection).iterator();iter.hasNext();){
112
            Object object = iter.next();
113
            canExecute &= object instanceof Media
114
                    || (object instanceof DescriptionBase && ((DescriptionBase) object).isImageGallery());
115
        }
110 116
        menuItem.setVisible(canExecute);
111 117
        return canExecute;
112 118
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/media/handler/MoveImageDownInListHandler.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

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

  
33 12
/**
34 13
 *
......
36 15
 * @created 11.08.2009
37 16
 * @version 1.0
38 17
 */
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();
18
public class MoveImageDownInListHandler extends AbstractMoveImageHandler{
55 19

  
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
        }
20
    @Override
21
    public int moveImageOperation() {
22
        return MoveMediaInListOperation.DOWN;
74 23
    }
75 24

  
76 25
}
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