Project

General

Profile

Revision aa42dfd9

IDaa42dfd92b08993bd5313a5e0e72bbe13a4aaa9c
Parent 611b3a85
Child b0a5a69c

Added by Patrick Plitzner over 3 years ago

ref #7010 Adapt derivate view handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.editor/fragment.e4xmi
51 51
        <children xsi:type="menu:MenuSeparator" xmi:id="_9nI4IDumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.4"/>
52 52
        <children xsi:type="menu:HandledMenuItem" xmi:id="_h4pX0DumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandnamereuse_single_read" label="%command.label.REUSE_SINGLE_READ_HERE" command="_HmerkDumEeeOtqC_3qh40A"/>
53 53
        <children xsi:type="menu:HandledMenuItem" xmi:id="_oQXH0DumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandlabelreuse_single_read_for_other_sequence" label="%command.label.REUSE_SINGLE_READ_FOR_OTHER_SEQUENCE" command="_N0wLsDumEeeOtqC_3qh40A"/>
54
        <children xsi:type="menu:HandledMenuItem" xmi:id="_1apX0DumEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandlabelremove_single_read_from_this_sequence" label="%command.label.REMOVE_SINGLE_READ_FROM_THIS_SEQUENCE"/>
55 54
        <children xsi:type="menu:MenuSeparator" xmi:id="_c0f98DulEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.menuseparator.beforeDelete"/>
56 55
        <children xsi:type="menu:HandledMenuItem" xmi:id="_XWW6QDulEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandlabel52" label="%command.label.52" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/delete.gif" command="_YPp1wDvREeeOtqC_3qh40A"/>
57 56
        <children xsi:type="menu:HandledMenuItem" xmi:id="_wg0-oDulEeeOtqC_3qh40A" elementId="eu.etaxonomy.taxeditor.editor.handledmenuitem.commandlabel54" label="%command.label.54" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.editor/icons/deep-delete-16x16-32.png" command="_fKT-wDulEeeOtqC_3qh40A"/>
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
30 30
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
31 31
import org.eclipse.jface.util.LocalSelectionTransfer;
32 32
import org.eclipse.jface.viewers.AbstractTreeViewer;
33
import org.eclipse.jface.viewers.ISelection;
34 33
import org.eclipse.jface.viewers.ISelectionChangedListener;
35 34
import org.eclipse.jface.viewers.IStructuredSelection;
36 35
import org.eclipse.jface.viewers.StructuredSelection;
......
61 60
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
62 61
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
63 62
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController;
64
import eu.etaxonomy.taxeditor.model.AbstractUtility;
65 63
import eu.etaxonomy.taxeditor.model.IContextListener;
66 64
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
67 65
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
......
224 222
        viewer.getTree().setEnabled(CdmStore.isActive());
225 223

  
226 224
        //propagate selection
227
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
225
        selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
228 226
        viewer.addSelectionChangedListener(selectionChangedListener);
229 227

  
230 228
        //create context menu
......
511 509

  
512 510
    @Inject
513 511
    @Optional
514
    public void selectionChanged(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection,
512
    public void selectionChanged(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
515 513
            @Named(IServiceConstants.ACTIVE_PART) MPart activePart, MPart thisPart)
516 514
    {
517 515
    	if(activePart == thisPart || viewer==null){
......
525 523
            if(activePart instanceof TaxonNameEditorE4){
526 524
                selectedTaxon = ((TaxonNameEditorE4) activePart).getTaxon();
527 525
            }
528
            else if(selection instanceof IStructuredSelection){
529
                Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
526
            else if(selection != null){
527
                Object selectedElement = selection.getFirstElement();
530 528
                if(selectedElement instanceof CdmBase){
531 529
                    if(((CdmBase) selectedElement).isInstanceOf(TaxonNode.class)){
532 530
                        selectedTaxon = HibernateProxyHelper.deproxy(selectedElement, TaxonNode.class).getTaxon();
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/AbstractAddDerivativeHandler.java
8 8
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
9 9
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
10 10
import org.eclipse.e4.ui.services.IServiceConstants;
11
import org.eclipse.jface.viewers.IStructuredSelection;
11 12
import org.eclipse.jface.viewers.TreeNode;
12 13

  
13 14
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeCacheStrategy;
......
23 24
public abstract class AbstractAddDerivativeHandler {
24 25

  
25 26
	@Execute
26
	public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
27
	public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
27 28
	    DerivateView derivateView = (DerivateView) part.getObject();
28 29

  
29 30
	    checkDirtyState(derivateView);
30 31

  
31
	    Object selectedDerivative = node.getValue();
32
	    Object selectedDerivative = ((TreeNode) selection.getFirstElement()).getValue();
32 33
	    if(isAllowed(selectedDerivative)){
33 34
	        Object createdElement = addElement(selectedDerivative);
34 35
	        refreshView(derivateView, createdElement);
......
36 37
	}
37 38

  
38 39
    @CanExecute
39
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) TreeNode node, MHandledMenuItem item) {
40
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem item) {
40 41
        boolean canExecute = false;
41

  
42
        Object derivate = node.getValue();
43
        canExecute = isAllowed(derivate);
42
        if(selection.size()==1){
43
            canExecute = selection.getFirstElement() instanceof TreeNode
44
                    && isAllowed(((TreeNode) selection.getFirstElement()).getValue());
45
        }
44 46
        item.setVisible(canExecute);
45 47
        return canExecute;
46 48
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/DeleteDerivateHandler.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
11 11

  
12
import java.util.Iterator;
13

  
12 14
import javax.inject.Named;
13 15

  
14 16
import org.eclipse.core.commands.ParameterizedCommand;
......
20 22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
21 23
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
22 24
import org.eclipse.e4.ui.services.IServiceConstants;
25
import org.eclipse.jface.viewers.IStructuredSelection;
23 26
import org.eclipse.jface.viewers.TreeNode;
24 27

  
25 28
import eu.etaxonomy.cdm.api.service.DeleteResult;
......
53 56
    private SpecimenDeleteConfigurator deleteConfigurator;
54 57

  
55 58
    @Execute
56
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection, ParameterizedCommand command) {
59
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
60
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
61
            ParameterizedCommand command) {
57 62
        deleteConfigurator = new SpecimenDeleteConfigurator();
58 63
        if(command.getId().equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DERIVATE_DEEPDELETE)){
59 64
            deleteConfigurator.setDeleteChildren(true);
......
74 79
            return;
75 80
        }
76 81

  
77
        if(selection instanceof Object[]){
78
            for (Object o : (Object[])selection) {
79
                if(o instanceof TreeNode){
80
                    delete((TreeNode)o, derivateView);
81
                }
82
        for(Iterator iter = selection.iterator();iter.hasNext();){
83
            Object object = iter.next();
84
            if(object instanceof TreeNode){
85
                delete((TreeNode)object, derivateView);
82 86
            }
83 87
        }
84
        if(selection instanceof TreeNode){
85
            delete((TreeNode)selection, derivateView);
86
        }
87 88

  
88 89
    }
89 90

  
90 91
    private void delete(TreeNode treeNode, DerivateView derivateView){
91 92
        Object value = treeNode.getValue();
92
        IStatus allowStatus = allowOperations(derivateView, treeNode);
93
        IStatus allowStatus = allowOperations(treeNode);
93 94
        if(allowStatus.isOK()) {
94 95
            DeleteResult deleteResult;
95 96
            if(value instanceof SingleRead
......
118 119

  
119 120
    }
120 121

  
121
    public IStatus allowOperations(DerivateView derivateView, TreeNode treeNode) {
122
    public IStatus allowOperations(TreeNode treeNode) {
122 123
        DeleteResult deleteResult;
123 124
        Object value = treeNode.getValue();
124 125
        if(value instanceof SpecimenOrObservationBase<?> || value instanceof Sequence || value instanceof SingleRead){
......
144 145
    }
145 146

  
146 147
    @CanExecute
147
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
148
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
148 149
            MHandledMenuItem menuItem){
149 150
        boolean canExecute = false;
150
        canExecute = selection!=null;
151
        canExecute = selection!=null && !selection.isEmpty();
151 152
        menuItem.setVisible(canExecute);
152 153
        return canExecute;
153 154
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/SingleReadCopyToClipboardHandler.java
9 9
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
10 10
import org.eclipse.e4.ui.services.IServiceConstants;
11 11
import org.eclipse.jface.util.LocalSelectionTransfer;
12
import org.eclipse.jface.viewers.StructuredSelection;
12
import org.eclipse.jface.viewers.IStructuredSelection;
13 13
import org.eclipse.jface.viewers.TreeNode;
14 14

  
15 15
import eu.etaxonomy.cdm.model.molecular.SingleRead;
......
18 18
public class SingleReadCopyToClipboardHandler {
19 19

  
20 20
    @Execute
21
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode){
21
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
22 22
        DerivateView derivateView = (DerivateView)part.getObject();
23
        LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(selectedTreeNode));
23
        LocalSelectionTransfer.getTransfer().setSelection(selection);
24 24
        derivateView.updateLabelCache();
25 25
        derivateView.refreshTree();
26 26
    }
27 27

  
28 28
    @CanExecute
29
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
29
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
30
            MHandledMenuItem menuItem){
30 31
        boolean canExecute = false;
31
        if(selectedTreeNode!=null){
32
            Object object = selectedTreeNode.getValue();
33
            canExecute = (object instanceof SingleRead);
34
        }
32
        canExecute = selection!=null
33
                && selection.size()==1
34
                && selection.getFirstElement() instanceof TreeNode
35
                && ((TreeNode) selection.getFirstElement()).getValue() instanceof SingleRead;
35 36
        menuItem.setVisible(canExecute);
36 37
        return canExecute;
37 38
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/SingleReadReuseHandler.java
10 10
import org.eclipse.e4.ui.services.IServiceConstants;
11 11
import org.eclipse.jface.util.LocalSelectionTransfer;
12 12
import org.eclipse.jface.viewers.ISelection;
13
import org.eclipse.jface.viewers.IStructuredSelection;
13 14
import org.eclipse.jface.viewers.TreeNode;
14 15

  
15 16
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
......
23 24
public class SingleReadReuseHandler {
24 25

  
25 26
    @Execute
26
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part, @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode){
27
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart part,
28
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection){
27 29
        ISelection clipBoardSelection = LocalSelectionTransfer.getTransfer().getSelection();
28 30
        TreeNode clipBoardTreeNode = EditorUtil.getTreeNodeOfSelection(clipBoardSelection);
29 31
        DerivateView derivateView = (DerivateView)part.getObject();
......
31 33
            MessagingUtils.warningDialog(DerivateView.VIEW_HAS_UNSAVED_CHANGES, this, DerivateView.YOU_NEED_TO_SAVE_BEFORE_PERFORMING_THIS_ACTION);
32 34
            return;
33 35
        }
34
        if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead
35
                && selectedTreeNode!=null && selectedTreeNode.getValue() instanceof Sequence){
36
        if(clipBoardTreeNode!=null && clipBoardTreeNode.getValue() instanceof SingleRead){
36 37
            SingleRead singleRead = (SingleRead)clipBoardTreeNode.getValue();
37
            Sequence sequence = (Sequence)selectedTreeNode.getValue();
38
            Sequence sequence = (Sequence)((TreeNode) selection.getFirstElement()).getValue();
38 39
            sequence.addSingleRead(singleRead);
39 40
            CdmStore.getService(ISequenceService.class).merge(sequence);
40 41

  
......
47 48
    }
48 49

  
49 50
    @CanExecute
50
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) TreeNode selectedTreeNode, MHandledMenuItem menuItem) {
51
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
52
            MHandledMenuItem menuItem){
51 53
        boolean canExecute = false;
52
        if(selectedTreeNode!=null){
53
            Object value = selectedTreeNode.getValue();
54
            TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
55
            if(value instanceof Sequence && clipboardNode!=null && clipboardNode.getValue() instanceof SingleRead
56
                    && !((Sequence) value).getSingleReads().contains(clipboardNode.getValue())){
57
                canExecute = true;
58
            }
59
        }
54
        canExecute = selection!=null
55
                && selection.size()==1
56
                && selection.getFirstElement() instanceof TreeNode
57
                && ((TreeNode) selection.getFirstElement()).getValue() instanceof Sequence;
58
        Sequence sequence = (Sequence) ((TreeNode) selection.getFirstElement()).getValue();
59
        TreeNode clipboardNode = EditorUtil.getTreeNodeOfSelection(LocalSelectionTransfer.getTransfer().getSelection());
60
        canExecute &= clipboardNode!=null
61
                && clipboardNode.getValue() instanceof SingleRead
62
                && !(sequence.getSingleReads().contains(clipboardNode.getValue()));
60 63
        menuItem.setVisible(canExecute);
61 64
        return canExecute;
62 65
    }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)