Project

General

Profile

« Previous | Next » 

Revision afac11d7

Added by Patrick Plitzner almost 6 years ago

ref #7010 Adapt concept view handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/ConceptViewPartE4.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.editor.view.concept.e4;
11 11

  
12
import java.util.ArrayList;
13
import java.util.Iterator;
14
import java.util.List;
12 15
import java.util.Map.Entry;
13 16

  
14 17
import javax.annotation.PostConstruct;
......
30 33
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider;
31 34
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
32 35
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
33
import eu.etaxonomy.taxeditor.model.AbstractUtility;
34 36
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
35 37
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
36 38
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
......
91 93
		viewer = conceptViewer;
92 94

  
93 95
		// Propagate selection from viewer
94
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
96
        selectionChangedListener = (event -> selService.setSelection(viewer.getSelection()));
95 97
        viewer.addSelectionChangedListener(selectionChangedListener);
96 98

  
97 99
        //create context menu
......
114 116
		@Override
115 117
		public ISelection getSelection() {
116 118
			ISelection selection = super.getSelection();
119
			List<TaxonRelationship> relationships = new ArrayList<>();
117 120
			if(selection instanceof IStructuredSelection && !selection.isEmpty()){
118
				Object firstElement = ((IStructuredSelection) selection).getFirstElement();
119
				TaxonRelationship taxonRelationship = ((Entry<TaxonRelationship, Taxon>)firstElement).getKey();
120
				return new StructuredSelection(taxonRelationship);
121

  
121
			    for(Iterator iter = ((IStructuredSelection) selection).iterator();iter.hasNext();){
122
			        Object object = iter.next();
123
			        relationships.add(((Entry<TaxonRelationship, Taxon>)object).getKey());
124
			    }
125
			    return new StructuredSelection(relationships);
122 126
			}
123 127
			return selection;
124 128
		}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/handler/DeleteConceptRelationHandlerE4.java
10 10
package eu.etaxonomy.taxeditor.editor.view.concept.e4.handler;
11 11

  
12 12
import java.util.HashSet;
13
import java.util.Iterator;
13 14
import java.util.Set;
14 15

  
15 16
import javax.inject.Named;
......
22 23
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
23 24
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
24 25
import org.eclipse.e4.ui.services.IServiceConstants;
25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.IStructuredSelection;
26 27

  
27 28
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
28 29
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
......
42 43

  
43 44
    @Execute
44 45
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
45
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection, MMenuItem menuItem,
46
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
47
            MMenuItem menuItem,
46 48
            UISynchronize sync) {
47 49

  
48 50
        TaxonNameEditorE4 editor = null;
......
56 58
            Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
57 59

  
58 60

  
59
            // FIXME E4 multiple selection
60
            //			while (iterator.hasNext()){
61
            if(selection instanceof TaxonRelationship){
62
                relations.add((TaxonRelationship) selection);
61
            for (Iterator iterator = selection.iterator(); iterator.hasNext();){
62
                Object object = iterator.next();
63
                if(object instanceof TaxonRelationship){
64
                    relations.add((TaxonRelationship) object);
65
                }
63 66
            }
64
            //			}
65 67

  
66 68
            //editor should not be null because this is already checked in canExecute
67 69
            AbstractPostOperation operation = new DeleteConceptRelationOperation(menuItem.getLocalizedLabel(),
......
71 73
    }
72 74

  
73 75
	@CanExecute
74
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
75
            MHandledMenuItem menuItem){
76
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
77
            MHandledMenuItem menuItem) {
76 78
        boolean canExecute = false;
77
        ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
78

  
79
        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(conceptView.getSelectionProvidingPart());
80
        if(e4WrappedPart instanceof TaxonNameEditorE4){
81
            ISelection selection = conceptView.getViewer().getSelection();
82
            canExecute = selection!=null && !selection.isEmpty();
83
            menuItem.setVisible(canExecute);
84
        }
79
        canExecute = selection != null && !selection.isEmpty();
80
        menuItem.setVisible(canExecute);
85 81
        return canExecute;
86 82
    }
87 83
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/handler/OpenRelatedConceptHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
15 16
import org.eclipse.e4.core.di.annotations.Optional;
16 17
import org.eclipse.e4.ui.model.application.MApplication;
17 18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18 20
import org.eclipse.e4.ui.services.IServiceConstants;
19 21
import org.eclipse.e4.ui.workbench.modeling.EModelService;
20 22
import org.eclipse.e4.ui.workbench.modeling.EPartService;
......
41 43

  
42 44
    @Execute
43 45
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
44
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) TaxonRelationship taxonRelationship, EModelService modelService, EPartService partService, MApplication application) {
46
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
47
            EModelService modelService, EPartService partService, MApplication application) {
45 48

  
46 49
        TaxonNameEditorE4 editor = null;
47 50
        BulkEditorE4 bulkEditor = null;
51
        TaxonRelationship taxonRelationship = (TaxonRelationship) selection.getFirstElement();
48 52

  
49 53
        ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
50 54

  
......
91 95
			return null;
92 96
		}
93 97
	}
98

  
99
    @CanExecute
100
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
101
            MHandledMenuItem menuItem) {
102
        boolean canExecute = false;
103
        canExecute = selection != null
104
                && selection.size()==1
105
                && selection.getFirstElement() instanceof TaxonRelationship;
106
        menuItem.setVisible(canExecute);
107
        return canExecute;
108
    }
94 109
}

Also available in: Unified diff