Project

General

Profile

Revision b0a5a69c

IDb0a5a69c67eb3f48193a4e13d0ccd69e0492d114
Parent aa42dfd9
Child 4c124358

Added by Patrick Plitzner over 3 years ago

ref #7010 Adapt descriptive view handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/FactualDataPartE4.java
50 50
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveLabelProvider;
51 51
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
52 52
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
53
import eu.etaxonomy.taxeditor.model.AbstractUtility;
54 53
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
55 54
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
56 55
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
......
103 102
        viewer = treeViewer;
104 103

  
105 104
        // Propagate selection from viewer
106
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
105
        selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
107 106
        viewer.addSelectionChangedListener(selectionChangedListener);
108 107
        DescriptionElementDropAdapter dropListener = new DescriptionElementDropAdapter(viewer);
109 108
        ContextInjectionFactory.inject(dropListener, context);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/CreateDescriptionElementHandlerE4.java
13 13

  
14 14
import javax.inject.Named;
15 15

  
16
import org.eclipse.e4.core.di.annotations.CanExecute;
16 17
import org.eclipse.e4.core.di.annotations.Execute;
17 18
import org.eclipse.e4.core.di.annotations.Optional;
18 19
import org.eclipse.e4.ui.di.UISynchronize;
19 20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20 21
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
21 22
import org.eclipse.e4.ui.services.IServiceConstants;
23
import org.eclipse.jface.viewers.IStructuredSelection;
22 24

  
23 25
import eu.etaxonomy.cdm.api.service.ITermService;
24 26
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
......
45 47

  
46 48
    @Execute
47 49
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
48
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object object, MHandledMenuItem menuItem,
50
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
51
            MHandledMenuItem menuItem,
49 52
            UISynchronize sync) {
50 53

  
51 54
        String commandId = menuItem.getCommand().getElementId();
......
55 58
        FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
56 59

  
57 60
        DescriptionBase description = null;
61
        Object object = selection.getFirstElement();
58 62
        if(object instanceof FeatureNodeContainer){
59 63
            description = ((FeatureNodeContainer) object).getDescription();
60 64
        }
......
74 78
        AbstractUtility.executeOperation(operation, sync);
75 79
    }
76 80

  
81
    @CanExecute
82
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
83
            MHandledMenuItem menuItem){
84
        boolean canExecute = false;
85
        canExecute = selection!=null
86
                && selection.size()==1;
87
        menuItem.setVisible(canExecute);
88
        return canExecute;
89
    }
90

  
77 91
    /**
78 92
	 * Added to make the Class more generic and limit the amount of code changes required
79 93
	 * @param label
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DeleteHandlerE4.java
10 10
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler;
11 11

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

  
15 16
import javax.inject.Named;
......
24 25
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
25 26
import org.eclipse.e4.ui.services.IServiceConstants;
26 27
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
27 29
import org.eclipse.jface.viewers.TreePath;
28 30
import org.eclipse.jface.viewers.TreeSelection;
29 31
import org.eclipse.swt.widgets.Shell;
......
60 62

  
61 63
	@Execute
62 64
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
63
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
64 65
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell, MMenuItem menuItem,
65 66
            UISynchronize sync) {
66 67

  
67 68
        FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
69
        IStructuredSelection selection = (IStructuredSelection) factualDataPart.getViewer().getSelection();
68 70

  
69 71
        Object selectionProvidingPart = factualDataPart.getSelectionProvidingPart();
70 72
        ICdmEntitySessionEnabled cdmEntitySessionEnabled = null;
......
78 80

  
79 81
        List<AbstractPostOperation<?>> operations = new ArrayList<AbstractPostOperation<?>>();
80 82

  
81
//			for(Object object : selection.toArray()){
83
        for(Iterator iter = selection.iterator();iter.hasNext();){
84
            Object object = iter.next();
82 85

  
83
        // TaxonDescription
84
        if(selection instanceof TaxonDescription){
85
            operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) selection, factualDataPart, cdmEntitySessionEnabled));
86
        }
87
        else if(selection instanceof SpecimenDescription){
88
            operations.add(new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) selection, factualDataPart, cdmEntitySessionEnabled)) ;
89
        }
90
        // DescriptionElementBase
91
        else if(selection instanceof DescriptionElementBase){
92
            operations.add(new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) selection, factualDataPart, cdmEntitySessionEnabled));
93
        }
94
        else if(selection instanceof FeatureNodeContainer){
95
            List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) selection).getDescriptionElementsForEntireBranch();
96

  
97
            for(DescriptionElementBase description : descriptions){
98
                operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, factualDataPart, cdmEntitySessionEnabled));
86
            // TaxonDescription
87
            if(object instanceof TaxonDescription){
88
                operations.add(new DeleteTaxonDescriptionOperation(label, undoContext, (TaxonDescription) object, factualDataPart, cdmEntitySessionEnabled));
99 89
            }
100
        }
101
        // Media
102
        else if(selection instanceof Media){
103

  
104
            TreeSelection treeSelection = (TreeSelection) factualDataPart.getViewer().getSelection();
105

  
106
            TreePath[] path = treeSelection.getPathsFor(selection);
107

  
108
            DescriptionBase<?> imageGallery = (DescriptionBase<?>) path[0].getFirstSegment();
109

  
110
            // TODO use undo context specific to editor
111
            MediaDeletionConfigurator config = new MediaDeletionConfigurator();
112
            config.setDeleteFromDescription(true);
113
            config.setOnlyRemoveFromGallery(false);
114

  
115
            if (imageGallery instanceof SpecimenDescription){
116
                config.setDeleteFrom(((SpecimenDescription)imageGallery).getDescribedSpecimenOrObservation());
117
            } else if (imageGallery instanceof TaxonDescription){
118
                config.setDeleteFrom(((TaxonDescription)imageGallery).getTaxon());
119
            }else if (imageGallery instanceof TaxonNameDescription){
120
                config.setDeleteFrom(((TaxonNameDescription)imageGallery).getTaxonName());
90
            else if(object instanceof SpecimenDescription){
91
                operations.add(new DeleteSpecimenDescriptionOperation(label, undoContext, (SpecimenDescription) object, factualDataPart, cdmEntitySessionEnabled)) ;
121 92
            }
122

  
123

  
124
            if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, shell, Messages.DeleteHandler_CONFIRM_DELETION,  Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE)){
125
                return;
93
            // DescriptionElementBase
94
            else if(object instanceof DescriptionElementBase){
95
                operations.add(new DeleteDescriptionElementOperation(label, undoContext, (DescriptionElementBase) object, factualDataPart, cdmEntitySessionEnabled));
126 96
            }
97
            else if(object instanceof FeatureNodeContainer){
98
                List<DescriptionElementBase> descriptions = ((FeatureNodeContainer) object).getDescriptionElementsForEntireBranch();
127 99

  
128

  
129

  
130
            if (config.isOnlyRemoveFromGallery() || ((Media)selection).getId() == 0){
131
                operations.add(new RemoveImageFromDescriptionElementOperation(label, undoContext,  (Media) selection, imageGallery, factualDataPart));
132
            }else{
133
                operations.add(new DeleteMediaOperation(label, undoContext, imageGallery, (Media) selection, config, factualDataPart));
100
                for(DescriptionElementBase description : descriptions){
101
                    operations.add(new DeleteDescriptionElementOperation(label, undoContext, description, factualDataPart, cdmEntitySessionEnabled));
102
                }
103
            }
104
            // Media
105
            else if(object instanceof Media){
106

  
107
                TreeSelection treeSelection = (TreeSelection) factualDataPart.getViewer().getSelection();
108

  
109
                TreePath[] path = treeSelection.getPathsFor(object);
110

  
111
                DescriptionBase<?> imageGallery = (DescriptionBase<?>) path[0].getFirstSegment();
112

  
113
                MediaDeletionConfigurator config = new MediaDeletionConfigurator();
114
                config.setDeleteFromDescription(true);
115
                config.setOnlyRemoveFromGallery(false);
116

  
117
                if (imageGallery instanceof SpecimenDescription){
118
                    config.setDeleteFrom(((SpecimenDescription)imageGallery).getDescribedSpecimenOrObservation());
119
                } else if (imageGallery instanceof TaxonDescription){
120
                    config.setDeleteFrom(((TaxonDescription)imageGallery).getTaxon());
121
                }else if (imageGallery instanceof TaxonNameDescription){
122
                    config.setDeleteFrom(((TaxonNameDescription)imageGallery).getTaxonName());
123
                }
124
                if (!DeleteConfiguratorDialog.openConfirmWithConfigurator(config, shell, Messages.DeleteHandler_CONFIRM_DELETION,  Messages.DeleteHandler_CONFIRM_DELETION_MESSAGE)){
125
                    return;
126
                }
127
                if (config.isOnlyRemoveFromGallery() || ((Media)object).getId() == 0){
128
                    operations.add(new RemoveImageFromDescriptionElementOperation(label, undoContext,  (Media) object, imageGallery, factualDataPart));
129
                }else{
130
                    operations.add(new DeleteMediaOperation(label, undoContext, imageGallery, (Media) object, config, factualDataPart));
131
                }
132
            }
133
            else{
134
                MessagingUtils.error(getClass(), Messages.DeleteHandler_INVALID_SELECTION, null);
134 135
            }
135

  
136

  
137

  
138
        }
139
        else{
140
            MessagingUtils.error(getClass(), Messages.DeleteHandler_INVALID_SELECTION, null);
141 136
        }
142
//			}
143 137

  
144 138
        // execute all cumulated operations
145 139
        for(AbstractPostOperation<?> operation : operations){
......
147 141
        }
148 142
	}
149 143

  
144

  
150 145
    @CanExecute
151 146
    public boolean canExecute(@Optional @Named(IServiceConstants.ACTIVE_PART) MPart activePart,
152 147
            MHandledMenuItem menuItem){
153 148
        FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
154 149
        ISelection selection = factualDataPart.getViewer().getSelection();
155
        boolean canExecute = selection !=null && !selection.isEmpty();
150
        boolean canExecute = selection instanceof IStructuredSelection && !selection.isEmpty();
156 151
        menuItem.setVisible(canExecute);
157 152
        return canExecute;
158 153
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java
21 21
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
22 22
import org.eclipse.e4.ui.model.application.ui.menu.MMenuFactory;
23 23
import org.eclipse.e4.ui.services.IServiceConstants;
24
import org.eclipse.jface.viewers.IStructuredSelection;
24 25

  
25 26
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
26 27
import eu.etaxonomy.cdm.model.description.DescriptionBase;
......
44 45

  
45 46
    /** {@inheritDoc} */
46 47
    @AboutToShow
47
    public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) Object selection) {
48
    public void aboutToShow(List<MMenuElement> items, @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
48 49

  
49 50
        MMenu menu = MMenuFactory.INSTANCE.createMenu();
50 51
        menu.setLabel(Messages.DynamicFeatureMenuE4_new);
51 52
        items.add(menu);
52 53

  
53
        if (selection instanceof DescriptionBase<?>) {
54
            FeatureTree featureTree = getFeatureTree((DescriptionBase<?>) selection);
54
            Object selectedElement = selection.getFirstElement();
55

  
56
        if (selectedElement instanceof DescriptionBase<?>) {
57
            FeatureTree featureTree = getFeatureTree((DescriptionBase<?>) selectedElement);
55 58

  
56 59
            for (FeatureNode childNode : featureTree.getRootChildren()) {
57 60
                createMenuItem(menu, childNode.getFeature());
58 61

  
59 62
            }
60
        } else if (selection instanceof FeatureNodeContainer) {
61
            FeatureNode featureNode = ((FeatureNodeContainer) selection)
63
        } else if (selectedElement instanceof FeatureNodeContainer) {
64
            FeatureNode featureNode = ((FeatureNodeContainer) selectedElement)
62 65
                    .getFeatureNode();
63 66

  
64 67
            // add the feature to the menu
......
68 71
            for (FeatureNode childNode : featureNode.getChildNodes()) {
69 72
                createMenuItem(menu, childNode.getFeature());
70 73
            }
71
        } else if (selection instanceof DescriptionElementBase) {
72
            Feature feature = ((DescriptionElementBase) selection)
74
        } else if (selectedElement instanceof DescriptionElementBase) {
75
            Feature feature = ((DescriptionElementBase) selectedElement)
73 76
                    .getFeature();
74 77
            createMenuItem(menu, feature);
75 78
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
10 10
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4.handler;
11 11

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

  
......
69 70

  
70 71
    @Execute
71 72
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
72
            @Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
73 73
            @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, MMenuItem menuItem, EPartService partService,
74 74
            EModelService modelService, MApplication application, UISynchronize sync) {
75 75

  
......
78 78
        this.partService = partService;
79 79

  
80 80
        FactualDataPartE4 factualDataPart = (FactualDataPartE4) activePart.getObject();
81
        IStructuredSelection viewselection = (IStructuredSelection) factualDataPart.getViewer().getSelection();
82

  
81 83
        Object e4WrappedPart = WorkbenchUtility.getE4WrappedPart(factualDataPart.getSelectionProvidingPart());
82 84
        if(e4WrappedPart instanceof TaxonNameEditorE4){
83 85
            editor = (TaxonNameEditorE4) e4WrappedPart;
......
86 88

  
87 89
        List<DescriptionElementBase> elements = new ArrayList<DescriptionElementBase>();
88 90

  
89
        //			for(Object element : structuredSelection.toArray()){
90
        if(selection instanceof DescriptionElementBase){
91
            UUID uuid = ((DescriptionElementBase) selection).getUuid();
92

  
93
            elements.add(CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null));
94
        } else if(selection instanceof FeatureNodeContainer){
95
            for(DescriptionElementBase de : ((FeatureNodeContainer)selection).getDescriptionElements()){
96
                elements.add(
97
                        CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null)
98
                        );
91
        for (Iterator iter = viewselection.iterator(); iter.hasNext();) {
92
            Object object = iter.next();
93
            if (object instanceof DescriptionElementBase) {
94
                UUID uuid = ((DescriptionElementBase) object).getUuid();
95

  
96
                elements.add(CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null));
97
            } else if (object instanceof FeatureNodeContainer) {
98
                for (DescriptionElementBase de : ((FeatureNodeContainer) object).getDescriptionElements()) {
99
                    elements.add(
100
                            CdmStore.getService(IDescriptionService.class).loadDescriptionElement(de.getUuid(), null));
101
                }
99 102
            }
100 103
        }
101
        //			}
102 104

  
103 105
        if(elements.size() == 0){
104 106
            return;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
62 62

  
63 63
    @Execute
64 64
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
65
            @Optional @Named(IServiceConstants.ACTIVE_SELECTION) Object selection,
65
            @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection,
66 66
            @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, MMenuItem menuItem, EPartService partService,
67 67
            EModelService modelService, MApplication application, UISynchronize sync) {
68 68

  
......
88 88

  
89 89
        List<TaxonDescription> descriptions = new ArrayList<TaxonDescription>();
90 90
        TaxonDescription description = null;
91
        if (selection instanceof FeatureNodeContainer){
92
        	FeatureNodeContainer container = (FeatureNodeContainer)selection;
91
        Object selectedElement = selection.getFirstElement();
92
        if (selectedElement instanceof FeatureNodeContainer){
93
        	FeatureNodeContainer container = (FeatureNodeContainer)selectedElement;
93 94
        	description = (TaxonDescription) container.getDescription();
94
        }else if (selection instanceof TaxonDescription){
95
        	description = (TaxonDescription)selection;
95
        }else if (selectedElement instanceof TaxonDescription){
96
        	description = (TaxonDescription)selectedElement;
96 97
        }
97 98
        descriptions.add(description);
98 99

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)