Project

General

Profile

« Previous | Next » 

Revision 843eefc4

Added by Katja Luther almost 3 years ago

ref #9448: remove E4 from file names - bulkeditor package

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/e4/handler/NewObjectHandler.java
25 25
import eu.etaxonomy.cdm.model.common.CdmBase;
26 26
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
27 27
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
29 29
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
30 30
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
31 31
import eu.etaxonomy.taxeditor.l10n.Messages;
......
40 40
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
41 41
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
42 42
            MHandledMenuItem menuItem) {
43
        if(!(activePart.getObject() instanceof BulkEditorE4)){
43
        if(!(activePart.getObject() instanceof BulkEditor)){
44 44
            return;
45 45
        }
46 46
        Object key = menuItem.getTransientData().get(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key");
47 47

  
48
        BulkEditorE4 bulkEditor = (BulkEditorE4) activePart.getObject();
48
        BulkEditor bulkEditor = (BulkEditor) activePart.getObject();
49 49

  
50 50
        if (key != null) {
51 51
            String text = menuItem.getCommand().getCommandName();
......
99 99
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
100 100
            MHandledMenuItem menuItem){
101 101
        boolean canExecute = false;
102
        canExecute = activePart.getObject() instanceof BulkEditorE4;
102
        canExecute = activePart.getObject() instanceof BulkEditor;
103 103
        menuItem.setVisible(canExecute);
104 104
        return canExecute;
105 105
    }
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/annotatedlineeditor/e4/handler/NewObjectHandlerE4.java
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
 */
9
package eu.etaxonomy.taxeditor.annotatedlineeditor.e4.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.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
17
import org.eclipse.e4.ui.services.IServiceConstants;
18
import org.eclipse.jface.dialogs.IInputValidator;
19
import org.eclipse.jface.dialogs.InputDialog;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.jface.window.Window;
23
import org.eclipse.swt.widgets.Shell;
24

  
25
import eu.etaxonomy.cdm.model.common.CdmBase;
26
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
27
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
29
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.GroupCreator;
30
import eu.etaxonomy.taxeditor.bulkeditor.input.entitycreator.UserCreator;
31
import eu.etaxonomy.taxeditor.l10n.Messages;
32

  
33
/**
34
 * @author pplitzner
35
 * @date 12.09.2017
36
 */
37
public class NewObjectHandlerE4 {
38

  
39
    @Execute
40
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
41
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
42
            MHandledMenuItem menuItem) {
43
        if(!(activePart.getObject() instanceof BulkEditorE4)){
44
            return;
45
        }
46
        Object key = menuItem.getTransientData().get(IBulkEditorConstants.DYNAMIC_OPEN_OBJECT_ID+".key");
47

  
48
        BulkEditorE4 bulkEditor = (BulkEditorE4) activePart.getObject();
49

  
50
        if (key != null) {
51
            String text = menuItem.getCommand().getCommandName();
52
            //FIXME : This should probably go into some ValidatorFactory
53
            IInputValidator nonEmptyInputValidator = null;
54
            //FIXME : This is a workaround to not allow empty strings in the
55
            //        input dialog for User and Group entities.
56
            //        Normally this should be default
57
            //        behaviour, so we need to discuss whether this handler
58
            //        should be used to handle the creating new entities of
59
            //        type other than User and Group.
60
            //        Once #4348 is fixed this check can be removed.
61
            if(text.equals(UserCreator.USER) || text.equals(GroupCreator.GROUP)) {
62
                nonEmptyInputValidator = new IInputValidator() {
63
                    @Override
64
                    public String isValid(String text) {
65
                        if(text == null || text.isEmpty()) {
66
                            return Messages.GROUP_CREATOR_Name_not_accepted_message;
67
                        }
68
                        return null;
69
                    }
70
                };
71
            }
72
            InputDialog dialog = new InputDialog(shell,
73
                    String.format("Create %s", text), String.format("Enter new %s", text), "",
74
                    nonEmptyInputValidator);
75

  
76
            if (dialog.open() != Window.CANCEL) {
77
                IEntityCreator<?> entityCreator = bulkEditor.getEditorInput().getEntityCreator();
78
                Object createdEntity = entityCreator.createEntity(key, dialog.getValue());
79
                if (createdEntity == null){
80
                    return;
81
                }
82
                bulkEditor.getEditorInput().getModel().add(createdEntity);
83
                if (createdEntity instanceof CdmBase){
84
                    if (!((CdmBase)createdEntity).isPersited()){
85
                        bulkEditor.getEditorInput().addSaveCandidate((CdmBase)createdEntity);
86
                        bulkEditor.setDirty();
87
                    }
88

  
89
                }
90
                IStructuredSelection selection = new StructuredSelection(createdEntity);
91
                bulkEditor.refresh();
92
                bulkEditor.setFocus();
93
                bulkEditor.setSelection(selection);
94
            }
95
        }
96
    }
97

  
98
    @CanExecute
99
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
100
            MHandledMenuItem menuItem){
101
        boolean canExecute = false;
102
        canExecute = activePart.getObject() instanceof BulkEditorE4;
103
        menuItem.setVisible(canExecute);
104
        return canExecute;
105
    }
106
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/BulkEditorUtil.java
18 18
import org.eclipse.e4.ui.workbench.modeling.EPartService;
19 19
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
20 20

  
21
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
21
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
22 22
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
23 23
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
24 24
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
49 49
            editorAreaPartStack.getChildren().add(part);
50 50
        }
51 51
        part = partService.showPart(part, PartState.ACTIVATE);
52
        BulkEditorE4 bulkEditor = (BulkEditorE4) part.getObject();
52
        BulkEditor bulkEditor = (BulkEditor) part.getObject();
53 53
        bulkEditor.init(input);
54 54
	}
55 55

  
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/command/BulkEditorPropertyTester.java
11 11
import org.apache.log4j.Logger;
12 12
import org.eclipse.core.expressions.PropertyTester;
13 13

  
14
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
14
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
15 15
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
16 16
import eu.etaxonomy.taxeditor.bulkeditor.input.GroupEditorInput;
17 17
import eu.etaxonomy.taxeditor.bulkeditor.input.MediaEditorInput;
......
40 40
	@Override
41 41
    public boolean test(Object receiver, String property, Object[] args,
42 42
			Object expectedValue) {
43
		BulkEditorE4 bulkEditor = null;
43
		BulkEditor bulkEditor = null;
44 44

  
45
		bulkEditor = (BulkEditorE4) receiver;
45
		bulkEditor = (BulkEditor) receiver;
46 46
		if (IS_MERGING_ENABLED.equals(property)) {
47 47
			AbstractBulkEditorInput<?> input = bulkEditor.getEditorInput();
48 48
			return ((AbstractBulkEditorInput<?>) input).isMergingEnabled();
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditor.java
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
*/
9
package eu.etaxonomy.taxeditor.bulkeditor.e4;
10

  
11
import java.io.FileOutputStream;
12
import java.io.IOException;
13
import java.util.List;
14

  
15
import javax.annotation.PostConstruct;
16
import javax.annotation.PreDestroy;
17
import javax.inject.Inject;
18

  
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
21
import org.eclipse.e4.core.contexts.IEclipseContext;
22
import org.eclipse.e4.core.di.annotations.Optional;
23
import org.eclipse.e4.core.services.events.IEventBroker;
24
import org.eclipse.e4.ui.di.Focus;
25
import org.eclipse.e4.ui.di.Persist;
26
import org.eclipse.e4.ui.di.UIEventTopic;
27
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
28
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.widgets.Composite;
33

  
34
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
35
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
36
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
37
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.model.description.DescriptionBase;
39
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
40
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
41
import eu.etaxonomy.cdm.model.description.TaxonDescription;
42
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
43
import eu.etaxonomy.cdm.model.media.Media;
44
import eu.etaxonomy.cdm.model.name.TaxonName;
45
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
46
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
47
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
48
import eu.etaxonomy.cdm.model.permission.Group;
49
import eu.etaxonomy.cdm.model.permission.User;
50
import eu.etaxonomy.cdm.model.taxon.Taxon;
51
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
52
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
53
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
54
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
55
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
56
import eu.etaxonomy.taxeditor.bulkeditor.input.GroupEditorInput;
57
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
58
import eu.etaxonomy.taxeditor.editor.IBulkEditor;
59
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
60
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
61
import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
62
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
63
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
64
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
65
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
66
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
67
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
68
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
69
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
70

  
71
/**
72
 * @author pplitzner
73
 * @since Sep 8, 2017
74
 */
75
public class BulkEditor implements IPartContentHasDetails, IConversationEnabled, IPostOperationEnabled,
76
        IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData,
77
        IPartContentHasSupplementalData, IPartContentHasMedia, IE4SavablePart, ITaxonEditor, IBulkEditor {
78

  
79
    @Inject
80
	private MDirtyable dirty;
81

  
82
    private AbstractBulkEditorInput input;
83

  
84
    private ConversationHolder conversation;
85

  
86
    @Inject
87
    private IEventBroker eventBroker;
88

  
89
    @Inject
90
    IEclipseContext context;
91

  
92
    @Inject
93
    private MPart thisPart;
94

  
95
    private BulkEditorQuery lastQuery = null;
96

  
97
    private BulkEditorE4Composite bulkEditorComposite;
98

  
99
    @Inject
100
    public BulkEditor() {
101
	}
102

  
103
    public void init(AbstractBulkEditorInput<?> input){
104
	    this.input = input;
105
	    this.conversation = input.getConversation();
106
	    thisPart.setLabel(input.getEditorName());
107

  
108
	    bulkEditorComposite.init(input);
109
	}
110

  
111
	@PostConstruct
112
	public void createPartControl(Composite parent, IEclipseContext context) {
113
	    bulkEditorComposite = new BulkEditorE4Composite(this, parent, SWT.NONE);
114
	    ContextInjectionFactory.inject(bulkEditorComposite, context);
115
	}
116

  
117
	@Override
118
	@Persist
119
	public void save(IProgressMonitor monitor) {
120
	    save(monitor, true);
121
	}
122

  
123
    public void save(IProgressMonitor monitor, boolean resetMerge) {
124
        if (!input.getCdmEntitySession().isActive()){
125
            input.getCdmEntitySession().bind();
126
        }
127
        input.saveModel(resetMerge);
128

  
129
        IStructuredSelection selection = getSelection();
130

  
131
        dirty.setDirty(false);
132
        input.dispose();
133
        input.bind();
134
        conversation.commit(true);
135

  
136
        if (lastQuery != null){
137
            bulkEditorComposite.performSearch(lastQuery, selection);
138
        }
139
    }
140

  
141

  
142
	@Focus
143
	public void setFocus() {
144
        //make sure to bind again if maybe in another view the conversation was unbound
145
        if(conversation!=null && !conversation.isBound()){
146
            conversation.bind();
147
        }
148
        if(input!=null && input.getCdmEntitySession()!= null) {
149
            input.getCdmEntitySession().bind();
150
        }
151

  
152
	    //make sure to bind again if maybe in another view the conversation was unbound
153
	    eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, this);
154
	}
155

  
156
	@PreDestroy
157
	public void dispose() {
158
	    if(conversation!=null){
159
	        conversation.unregisterForDataStoreChanges(this);
160
	        conversation.close();
161
	    }
162
	    if(input!=null){
163
	        input.dispose();
164
	    }
165
	    dirty.setDirty(false);
166
	    //save table settings
167
	    if(bulkEditorComposite.getNatTableState()!=null){
168
            try (FileOutputStream tableStateStream =
169
                    new FileOutputStream(bulkEditorComposite.getStatePropertiesFile())) {
170
                bulkEditorComposite.getNatTableState().store(tableStateStream, null);
171
            } catch (IOException ioe) {
172
                ioe.printStackTrace();
173
            }
174
        }
175
	}
176

  
177
    @Optional
178
    @Inject
179
    private void updateAfterSearch(@UIEventTopic(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED)IStructuredSelection selection){
180
        if(selection!=null){
181
            setSelection(selection);
182
        }
183
    }
184

  
185
    public void refresh(){
186
        bulkEditorComposite.refresh();
187
    }
188

  
189
    public IStructuredSelection getSelection(){
190
        return bulkEditorComposite.getSelection();
191
    }
192

  
193
    public IStructuredSelection getCellSelection(){
194
        return bulkEditorComposite.getCellSelection();
195
    }
196

  
197
    public void setSelection(IStructuredSelection selection){
198
        bulkEditorComposite.setSelection(selection);
199
    }
200

  
201
    public void setDirty(boolean isDirty){
202
        dirty.setDirty(isDirty);
203
    }
204

  
205
    public void setDirty(){
206
        setDirty(true);
207
    }
208

  
209
    @Override
210
    public boolean isDirty() {
211
        return dirty.isDirty();
212
    }
213

  
214
    public AbstractBulkEditorInput getEditorInput() {
215
        return input;
216
    }
217

  
218
    public void copyDataToClipboard() {
219
        bulkEditorComposite.copyDataToClipboard();
220
    }
221

  
222
    @Override
223
    public void update(CdmDataChangeMap arg0) {
224
    }
225

  
226
    @Override
227
    public boolean canAttachMedia() {
228
        return true;
229
    }
230

  
231
    @Override
232
    public void changed(Object element) {
233
        if(element instanceof DerivedUnitFacade){
234
            DerivedUnit derivedUnit = ((DerivedUnitFacade) element).innerDerivedUnit();
235
            if(derivedUnit!=null){
236
                getEditorInput().addSaveCandidate(derivedUnit);
237
            }
238
            FieldUnit fieldUnit = ((DerivedUnitFacade) element).innerFieldUnit();
239
            if(fieldUnit!=null){
240
                getEditorInput().addSaveCandidate(fieldUnit);
241
            }
242
        }
243
        else if (element instanceof CdmBase) {
244
            if (element instanceof DescriptionBase){
245
                if (element instanceof TaxonNameDescription){
246
                    TaxonName changedName = ((TaxonNameDescription)element).getTaxonName();
247
                    if (getEditorInput() instanceof TaxonEditorInput){
248
                        IStructuredSelection sel = getSelection();
249
                        Object firstElement = sel.getFirstElement();
250
                        if (firstElement instanceof TaxonBase){
251
                            getEditorInput().addSaveCandidate((TaxonBase)firstElement);
252
                        }
253
                    }else{
254
                        getEditorInput().addSaveCandidate(changedName);
255
                    }
256

  
257
                    input.replaceInModel(changedName);
258
                }else if (element instanceof TaxonDescription){
259
                    Taxon changedTaxon = ((TaxonDescription)element).getTaxon();
260
                    getEditorInput().addSaveCandidate(changedTaxon);
261
                    input.replaceInModel(changedTaxon);
262
                }
263
            }else if (element instanceof DescriptionElementBase){
264
                if (((DescriptionElementBase)element).getInDescription() instanceof TaxonNameDescription){
265
                    TaxonName changedName = ((TaxonNameDescription)((DescriptionElementBase)element).getInDescription()).getTaxonName();
266
                    //check whether the bulk editor is taxon or name bulk editor
267
                    if (getEditorInput() instanceof TaxonEditorInput){
268
                        IStructuredSelection sel = getSelection();
269
                        Object firstElement = sel.getFirstElement();
270
                        if (firstElement instanceof TaxonBase){
271
                            getEditorInput().addSaveCandidate((TaxonBase)firstElement);
272
                        }
273
                    }else{
274
                        getEditorInput().addSaveCandidate(changedName);
275
                    }
276
                    input.replaceInModel(changedName);
277
                }else if (((DescriptionElementBase)element).getInDescription() instanceof TaxonDescription){
278
                    Taxon changedTaxon = ((TaxonDescription)((DescriptionElementBase)element).getInDescription()).getTaxon();
279
                    getEditorInput().addSaveCandidate(changedTaxon);
280
                    input.replaceInModel(changedTaxon);
281
                }else if (((DescriptionElementBase)element).getInDescription() instanceof SpecimenDescription){
282
                    SpecimenOrObservationBase changedSpecimen = ((SpecimenDescription)((DescriptionElementBase)element).getInDescription()).getDescribedSpecimenOrObservation();
283
                    getEditorInput().addSaveCandidate(changedSpecimen);
284
                    input.replaceInModel(changedSpecimen);
285
                }
286
            }else if (element instanceof Media){
287
                IStructuredSelection sel = getSelection();
288
                Object firstElement = sel.getFirstElement();
289
                if (firstElement instanceof TaxonBase){
290
                    TaxonBase changedTaxon = (TaxonBase)sel.getFirstElement();
291
                    getEditorInput().addSaveCandidate(changedTaxon);
292
                    input.replaceInModel(changedTaxon);
293
                }else if (firstElement instanceof SpecimenOrObservationBase){
294
                    SpecimenOrObservationBase changedSpecimen = (SpecimenOrObservationBase)sel.getFirstElement();
295
                    getEditorInput().addSaveCandidate(changedSpecimen);
296
                    input.replaceInModel(changedSpecimen);
297
                } else if (firstElement instanceof Media){
298
                    getEditorInput().addSaveCandidate((Media)element);
299
                    input.replaceInModel((Media)element);
300
                }
301
            }else if(element instanceof Group){
302
                 Group oldGroup = ((GroupEditorInput)input).getEntityFromModel((Group)element);
303
                 ((GroupEditorInput)input).getSaveUserCandidates().addAll(oldGroup.getMembers());
304
                 getEditorInput().addSaveCandidate((Group)element);
305
                 input.replaceInModel((CdmBase) element);
306
            }else{
307
                getEditorInput().addSaveCandidate((CdmBase)element);
308
                input.replaceInModel((CdmBase) element);
309
            }
310
        }
311
        dirty.setDirty(true);
312
        setSelection(new StructuredSelection(element));
313
    }
314

  
315
    @Override
316
    public void forceDirty() {
317
        dirty.setDirty(true);
318
    }
319

  
320
    @Override
321
    public boolean postOperation(Object objectAffectedByOperation) {
322
        return false;
323
    }
324

  
325
    @Override
326
    public boolean onComplete() {
327
        return false;
328
    }
329

  
330
    @Override
331
    public ConversationHolder getConversationHolder() {
332
        return conversation;
333
    }
334

  
335
    public BulkEditorQuery getLastQuery() {
336
       return lastQuery;
337
    }
338

  
339
    public void setLastQuery(BulkEditorQuery lastQuery) {
340
       this.lastQuery = lastQuery;
341

  
342
    }
343

  
344
    @Override
345
    public Taxon getTaxon() {
346
        IStructuredSelection selection = getSelection();
347
        if(selection.size()==1) {
348
            Object object = selection.iterator().next();
349
            if(object instanceof Taxon){
350
                return (Taxon) object;
351
            }
352
        }
353
        return null;
354
    }
355

  
356
    @Override
357
    public void update() {
358
        input.performSearch(lastQuery, getSelection());
359
    }
360

  
361
    @Override
362
    public void addOperation(AbstractPostOperation operation) {
363
        // operations not yet used for bulk editor
364
    }
365

  
366
    @Inject
367
    @Optional
368
    private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAME_EDITOR) List<CdmBase> cdmBases) {
369
        if (getEditorInput() instanceof TaxonEditorInput){
370
            for (CdmBase cdmBase: cdmBases){
371
                if (getEditorInput().getModel().contains(cdmBase)){
372
                    input.performSearch(lastQuery, getSelection());
373
                    break;
374
                }
375
            }
376
        }
377
    }
378

  
379
    @Inject
380
    @Optional
381
    private void updatefromDelete(@UIEventTopic(WorkbenchEventConstants.REMOVE_USER) User user) {
382
        if (input instanceof GroupEditorInput){
383
            ((GroupEditorInput)input).getSaveUserCandidates().add(user);
384
        }
385
    }
386

  
387
    @Override
388
    public TaxonNode getTaxonNode() {
389
        return null;
390
    }
391

  
392
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
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
*/
9
package eu.etaxonomy.taxeditor.bulkeditor.e4;
10

  
11
import java.io.FileOutputStream;
12
import java.io.IOException;
13
import java.util.List;
14

  
15
import javax.annotation.PostConstruct;
16
import javax.annotation.PreDestroy;
17
import javax.inject.Inject;
18

  
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
21
import org.eclipse.e4.core.contexts.IEclipseContext;
22
import org.eclipse.e4.core.di.annotations.Optional;
23
import org.eclipse.e4.core.services.events.IEventBroker;
24
import org.eclipse.e4.ui.di.Focus;
25
import org.eclipse.e4.ui.di.Persist;
26
import org.eclipse.e4.ui.di.UIEventTopic;
27
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
28
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
29
import org.eclipse.jface.viewers.IStructuredSelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.widgets.Composite;
33

  
34
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
35
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
36
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
37
import eu.etaxonomy.cdm.model.common.CdmBase;
38
import eu.etaxonomy.cdm.model.description.DescriptionBase;
39
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
40
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
41
import eu.etaxonomy.cdm.model.description.TaxonDescription;
42
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
43
import eu.etaxonomy.cdm.model.media.Media;
44
import eu.etaxonomy.cdm.model.name.TaxonName;
45
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
46
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
47
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
48
import eu.etaxonomy.cdm.model.permission.Group;
49
import eu.etaxonomy.cdm.model.permission.User;
50
import eu.etaxonomy.cdm.model.taxon.Taxon;
51
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
52
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
53
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
54
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
55
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
56
import eu.etaxonomy.taxeditor.bulkeditor.input.GroupEditorInput;
57
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
58
import eu.etaxonomy.taxeditor.editor.IBulkEditor;
59
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
60
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
61
import eu.etaxonomy.taxeditor.model.IDerivedUnitFacadePart;
62
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
63
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
64
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
65
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
66
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
67
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
68
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
69
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
70

  
71
/**
72
 * @author pplitzner
73
 * @since Sep 8, 2017
74
 */
75
public class BulkEditorE4 implements IPartContentHasDetails, IConversationEnabled, IPostOperationEnabled,
76
        IDirtyMarkable, IDerivedUnitFacadePart, IPartContentHasFactualData,
77
        IPartContentHasSupplementalData, IPartContentHasMedia, IE4SavablePart, ITaxonEditor, IBulkEditor {
78

  
79
    @Inject
80
	private MDirtyable dirty;
81

  
82
    private AbstractBulkEditorInput input;
83

  
84
    private ConversationHolder conversation;
85

  
86
    @Inject
87
    private IEventBroker eventBroker;
88

  
89
    @Inject
90
    IEclipseContext context;
91

  
92
    @Inject
93
    private MPart thisPart;
94

  
95
    private BulkEditorQuery lastQuery = null;
96

  
97
    private BulkEditorE4Composite bulkEditorComposite;
98

  
99
    @Inject
100
    public BulkEditorE4() {
101
	}
102

  
103
    public void init(AbstractBulkEditorInput<?> input){
104
	    this.input = input;
105
	    this.conversation = input.getConversation();
106
	    thisPart.setLabel(input.getEditorName());
107

  
108
	    bulkEditorComposite.init(input);
109
	}
110

  
111
	@PostConstruct
112
	public void createPartControl(Composite parent, IEclipseContext context) {
113
	    bulkEditorComposite = new BulkEditorE4Composite(this, parent, SWT.NONE);
114
	    ContextInjectionFactory.inject(bulkEditorComposite, context);
115
	}
116

  
117
	@Override
118
	@Persist
119
	public void save(IProgressMonitor monitor) {
120
	    save(monitor, true);
121
	}
122

  
123
    public void save(IProgressMonitor monitor, boolean resetMerge) {
124
        if (!input.getCdmEntitySession().isActive()){
125
            input.getCdmEntitySession().bind();
126
        }
127
        input.saveModel(resetMerge);
128

  
129
        IStructuredSelection selection = getSelection();
130

  
131
        dirty.setDirty(false);
132
        input.dispose();
133
        input.bind();
134
        conversation.commit(true);
135

  
136
        if (lastQuery != null){
137
            bulkEditorComposite.performSearch(lastQuery, selection);
138
        }
139
    }
140

  
141

  
142
	@Focus
143
	public void setFocus() {
144
        //make sure to bind again if maybe in another view the conversation was unbound
145
        if(conversation!=null && !conversation.isBound()){
146
            conversation.bind();
147
        }
148
        if(input!=null && input.getCdmEntitySession()!= null) {
149
            input.getCdmEntitySession().bind();
150
        }
151

  
152
	    //make sure to bind again if maybe in another view the conversation was unbound
153
	    eventBroker.post(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR, this);
154
	}
155

  
156
	@PreDestroy
157
	public void dispose() {
158
	    if(conversation!=null){
159
	        conversation.unregisterForDataStoreChanges(this);
160
	        conversation.close();
161
	    }
162
	    if(input!=null){
163
	        input.dispose();
164
	    }
165
	    dirty.setDirty(false);
166
	    //save table settings
167
	    if(bulkEditorComposite.getNatTableState()!=null){
168
            try (FileOutputStream tableStateStream =
169
                    new FileOutputStream(bulkEditorComposite.getStatePropertiesFile())) {
170
                bulkEditorComposite.getNatTableState().store(tableStateStream, null);
171
            } catch (IOException ioe) {
172
                ioe.printStackTrace();
173
            }
174
        }
175
	}
176

  
177
    @Optional
178
    @Inject
179
    private void updateAfterSearch(@UIEventTopic(WorkbenchEventConstants.BULK_EDITOR_SEARCH_FINISHED)IStructuredSelection selection){
180
        if(selection!=null){
181
            setSelection(selection);
182
        }
183
    }
184

  
185
    public void refresh(){
186
        bulkEditorComposite.refresh();
187
    }
188

  
189
    public IStructuredSelection getSelection(){
190
        return bulkEditorComposite.getSelection();
191
    }
192

  
193
    public IStructuredSelection getCellSelection(){
194
        return bulkEditorComposite.getCellSelection();
195
    }
196

  
197
    public void setSelection(IStructuredSelection selection){
198
        bulkEditorComposite.setSelection(selection);
199
    }
200

  
201
    public void setDirty(boolean isDirty){
202
        dirty.setDirty(isDirty);
203
    }
204

  
205
    public void setDirty(){
206
        setDirty(true);
207
    }
208

  
209
    @Override
210
    public boolean isDirty() {
211
        return dirty.isDirty();
212
    }
213

  
214
    public AbstractBulkEditorInput getEditorInput() {
215
        return input;
216
    }
217

  
218
    public void copyDataToClipboard() {
219
        bulkEditorComposite.copyDataToClipboard();
220
    }
221

  
222
    @Override
223
    public void update(CdmDataChangeMap arg0) {
224
    }
225

  
226
    @Override
227
    public boolean canAttachMedia() {
228
        return true;
229
    }
230

  
231
    @Override
232
    public void changed(Object element) {
233
        if(element instanceof DerivedUnitFacade){
234
            DerivedUnit derivedUnit = ((DerivedUnitFacade) element).innerDerivedUnit();
235
            if(derivedUnit!=null){
236
                getEditorInput().addSaveCandidate(derivedUnit);
237
            }
238
            FieldUnit fieldUnit = ((DerivedUnitFacade) element).innerFieldUnit();
239
            if(fieldUnit!=null){
240
                getEditorInput().addSaveCandidate(fieldUnit);
241
            }
242
        }
243
        else if (element instanceof CdmBase) {
244
            if (element instanceof DescriptionBase){
245
                if (element instanceof TaxonNameDescription){
246
                    TaxonName changedName = ((TaxonNameDescription)element).getTaxonName();
247
                    if (getEditorInput() instanceof TaxonEditorInput){
248
                        IStructuredSelection sel = getSelection();
249
                        Object firstElement = sel.getFirstElement();
250
                        if (firstElement instanceof TaxonBase){
251
                            getEditorInput().addSaveCandidate((TaxonBase)firstElement);
252
                        }
253
                    }else{
254
                        getEditorInput().addSaveCandidate(changedName);
255
                    }
256

  
257
                    input.replaceInModel(changedName);
258
                }else if (element instanceof TaxonDescription){
259
                    Taxon changedTaxon = ((TaxonDescription)element).getTaxon();
260
                    getEditorInput().addSaveCandidate(changedTaxon);
261
                    input.replaceInModel(changedTaxon);
262
                }
263
            }else if (element instanceof DescriptionElementBase){
264
                if (((DescriptionElementBase)element).getInDescription() instanceof TaxonNameDescription){
265
                    TaxonName changedName = ((TaxonNameDescription)((DescriptionElementBase)element).getInDescription()).getTaxonName();
266
                    //check whether the bulk editor is taxon or name bulk editor
267
                    if (getEditorInput() instanceof TaxonEditorInput){
268
                        IStructuredSelection sel = getSelection();
269
                        Object firstElement = sel.getFirstElement();
270
                        if (firstElement instanceof TaxonBase){
271
                            getEditorInput().addSaveCandidate((TaxonBase)firstElement);
272
                        }
273
                    }else{
274
                        getEditorInput().addSaveCandidate(changedName);
275
                    }
276
                    input.replaceInModel(changedName);
277
                }else if (((DescriptionElementBase)element).getInDescription() instanceof TaxonDescription){
278
                    Taxon changedTaxon = ((TaxonDescription)((DescriptionElementBase)element).getInDescription()).getTaxon();
279
                    getEditorInput().addSaveCandidate(changedTaxon);
280
                    input.replaceInModel(changedTaxon);
281
                }else if (((DescriptionElementBase)element).getInDescription() instanceof SpecimenDescription){
282
                    SpecimenOrObservationBase changedSpecimen = ((SpecimenDescription)((DescriptionElementBase)element).getInDescription()).getDescribedSpecimenOrObservation();
283
                    getEditorInput().addSaveCandidate(changedSpecimen);
284
                    input.replaceInModel(changedSpecimen);
285
                }
286
            }else if (element instanceof Media){
287
                IStructuredSelection sel = getSelection();
288
                Object firstElement = sel.getFirstElement();
289
                if (firstElement instanceof TaxonBase){
290
                    TaxonBase changedTaxon = (TaxonBase)sel.getFirstElement();
291
                    getEditorInput().addSaveCandidate(changedTaxon);
292
                    input.replaceInModel(changedTaxon);
293
                }else if (firstElement instanceof SpecimenOrObservationBase){
294
                    SpecimenOrObservationBase changedSpecimen = (SpecimenOrObservationBase)sel.getFirstElement();
295
                    getEditorInput().addSaveCandidate(changedSpecimen);
296
                    input.replaceInModel(changedSpecimen);
297
                } else if (firstElement instanceof Media){
298
                    getEditorInput().addSaveCandidate((Media)element);
299
                    input.replaceInModel((Media)element);
300
                }
301
            }else if(element instanceof Group){
302
                 Group oldGroup = ((GroupEditorInput)input).getEntityFromModel((Group)element);
303
                 ((GroupEditorInput)input).getSaveUserCandidates().addAll(oldGroup.getMembers());
304
                 getEditorInput().addSaveCandidate((Group)element);
305
                 input.replaceInModel((CdmBase) element);
306
            }else{
307
                getEditorInput().addSaveCandidate((CdmBase)element);
308
                input.replaceInModel((CdmBase) element);
309
            }
310
        }
311
        dirty.setDirty(true);
312
        setSelection(new StructuredSelection(element));
313
    }
314

  
315
    @Override
316
    public void forceDirty() {
317
        dirty.setDirty(true);
318
    }
319

  
320
    @Override
321
    public boolean postOperation(Object objectAffectedByOperation) {
322
        return false;
323
    }
324

  
325
    @Override
326
    public boolean onComplete() {
327
        return false;
328
    }
329

  
330
    @Override
331
    public ConversationHolder getConversationHolder() {
332
        return conversation;
333
    }
334

  
335
    public BulkEditorQuery getLastQuery() {
336
       return lastQuery;
337
    }
338

  
339
    public void setLastQuery(BulkEditorQuery lastQuery) {
340
       this.lastQuery = lastQuery;
341

  
342
    }
343

  
344
    @Override
345
    public Taxon getTaxon() {
346
        IStructuredSelection selection = getSelection();
347
        if(selection.size()==1) {
348
            Object object = selection.iterator().next();
349
            if(object instanceof Taxon){
350
                return (Taxon) object;
351
            }
352
        }
353
        return null;
354
    }
355

  
356
    @Override
357
    public void update() {
358
        input.performSearch(lastQuery, getSelection());
359
    }
360

  
361
    @Override
362
    public void addOperation(AbstractPostOperation operation) {
363
        // operations not yet used for bulk editor
364
    }
365

  
366
    @Inject
367
    @Optional
368
    private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_NAME_EDITOR) List<CdmBase> cdmBases) {
369
        if (getEditorInput() instanceof TaxonEditorInput){
370
            for (CdmBase cdmBase: cdmBases){
371
                if (getEditorInput().getModel().contains(cdmBase)){
372
                    input.performSearch(lastQuery, getSelection());
373
                    break;
374
                }
375
            }
376
        }
377
    }
378

  
379
    @Inject
380
    @Optional
381
    private void updatefromDelete(@UIEventTopic(WorkbenchEventConstants.REMOVE_USER) User user) {
382
        if (input instanceof GroupEditorInput){
383
            ((GroupEditorInput)input).getSaveUserCandidates().add(user);
384
        }
385
    }
386

  
387
    @Override
388
    public TaxonNode getTaxonNode() {
389
        return null;
390
    }
391

  
392
}
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4Composite.java
120 120

  
121 121
    private ListDataProvider<CdmBase> bodyDataProvider;
122 122

  
123
    private BulkEditorE4 bulkEditor;
123
    private BulkEditor bulkEditor;
124 124
    private BulkEditorSearchE4 bulkEditorSearch;
125 125

  
126 126
    @Inject
127 127
    private IEventBroker eventBroker;
128 128

  
129 129

  
130
    public BulkEditorE4Composite(BulkEditorE4 bulkEditor, Composite parent, int style) {
130
    public BulkEditorE4Composite(BulkEditor bulkEditor, Composite parent, int style) {
131 131
        super(parent, style);
132 132
        parent.setLayout(new GridLayout());
133 133
        this.bulkEditor = bulkEditor;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicMarkerTypeEditingMenuE4.java
27 27

  
28 28
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
29 29
import eu.etaxonomy.cdm.model.common.MarkerType;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
31 31
import eu.etaxonomy.taxeditor.l10n.Messages;
32 32
import eu.etaxonomy.taxeditor.store.CdmStore;
33 33

  
......
85 85
	    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
86 86
	            MHandledMenuItem menuItem){
87 87
	        boolean canExecute = false;
88
	        StructuredSelection selection = (StructuredSelection)((BulkEditorE4)activePart.getObject()).getSelection();
88
	        StructuredSelection selection = (StructuredSelection)((BulkEditor)activePart.getObject()).getSelection();
89 89
	        canExecute = !selection.isEmpty() && selection.getFirstElement() instanceof IAnnotatableEntity;
90 90
	        menuItem.setVisible(canExecute);
91 91
	        return canExecute;
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/command/DynamicNewObjectMenuE4.java
27 27

  
28 28
import eu.etaxonomy.taxeditor.annotatedlineeditor.IEntityCreator;
29 29
import eu.etaxonomy.taxeditor.bulkeditor.IBulkEditorConstants;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
31 31
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
32 32
import eu.etaxonomy.taxeditor.l10n.Messages;
33 33

  
......
38 38
public class DynamicNewObjectMenuE4 {
39 39

  
40 40
	private Map<? extends Object, String> classLabelPairs;
41
    private BulkEditorE4 editor;
41
    private BulkEditor editor;
42 42

  
43 43
    @AboutToShow
44 44
    public void aboutToShow(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
45 45
            List<MMenuElement> items) {
46 46

  
47
        editor = (BulkEditorE4) activePart.getObject();
47
        editor = (BulkEditor) activePart.getObject();
48 48

  
49 49
		classLabelPairs = getClassLabelPairs();
50 50

  
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertPerson2TeamHandlerE4.java
27 27
import eu.etaxonomy.cdm.model.agent.Person;
28 28
import eu.etaxonomy.cdm.model.agent.Team;
29 29
import eu.etaxonomy.cdm.strategy.merge.MergeException;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
31 31
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
32 32
import eu.etaxonomy.taxeditor.model.MessagingUtils;
33 33
import eu.etaxonomy.taxeditor.store.CdmStore;
......
42 42
    @Execute
43 43
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
44 44

  
45
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
45
        BulkEditor editor = (BulkEditor) activePart.getObject();
46 46
        if (editor.isDirty()){
47 47
            boolean proceed = MessageDialog.openQuestion(null,
48 48
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
......
78 78
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
79 79
            MHandledMenuItem menuItem){
80 80
        boolean canExecute = false;
81
        BulkEditorE4 bulkEditorE4 = (BulkEditorE4)activePart.getObject();
81
        BulkEditor bulkEditorE4 = (BulkEditor)activePart.getObject();
82 82
        StructuredSelection selection = (StructuredSelection)bulkEditorE4.getSelection();
83 83
        canExecute = !selection.isEmpty() && bulkEditorE4.getEditorInput().isConvertingEnabled();
84 84
        Iterator<?> iterator = selection.iterator();
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/ConvertTeam2PersonHandlerE4.java
27 27
import eu.etaxonomy.cdm.model.agent.Person;
28 28
import eu.etaxonomy.cdm.model.agent.Team;
29 29
import eu.etaxonomy.cdm.strategy.merge.MergeException;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
30
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
31 31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32 32
import eu.etaxonomy.taxeditor.store.CdmStore;
33 33

  
......
41 41
    @Execute
42 42
	public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
43 43

  
44
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
44
        BulkEditor editor = (BulkEditor) activePart.getObject();
45 45
        if (editor.isDirty()){
46 46
            boolean proceed = MessageDialog.openQuestion(null,
47 47
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
......
77 77
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
78 78
            MHandledMenuItem menuItem){
79 79
        boolean canExecute = false;
80
        BulkEditorE4 bulkEditorE4 = (BulkEditorE4)activePart.getObject();
80
        BulkEditor bulkEditorE4 = (BulkEditor)activePart.getObject();
81 81
        StructuredSelection selection = (StructuredSelection)bulkEditorE4.getSelection();
82 82
        canExecute = !selection.isEmpty() && bulkEditorE4.getEditorInput().isConvertingEnabled();
83 83
        Iterator iterator = selection.iterator();
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/CopyHandler.java
17 17
import org.eclipse.e4.ui.services.IServiceConstants;
18 18
import org.eclipse.jface.viewers.IStructuredSelection;
19 19

  
20
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
20
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
21 21

  
22 22
/**
23 23
 *
......
29 29

  
30 30
    @Execute
31 31
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
32
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
32
        BulkEditor editor = (BulkEditor) activePart.getObject();
33 33
        editor.copyDataToClipboard();
34 34
    }
35 35

  
......
37 37
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
38 38
            MHandledMenuItem menuItem) {
39 39
        boolean canExecute = false;
40
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
40
        BulkEditor editor = (BulkEditor) activePart.getObject();
41 41
        IStructuredSelection selection = editor.getCellSelection();
42 42
        canExecute = selection.size()==1;
43 43
        menuItem.setVisible(canExecute);
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/DeleteHandlerE4.java
51 51
import eu.etaxonomy.cdm.model.taxon.Synonym;
52 52
import eu.etaxonomy.cdm.model.taxon.Taxon;
53 53
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
54
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
54
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
55 55
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
56 56
import eu.etaxonomy.taxeditor.l10n.Messages;
57 57
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
58 58
import eu.etaxonomy.taxeditor.model.MessagingUtils;
59 59
import eu.etaxonomy.taxeditor.remoting.CdmEagerLoadingException;
60
import eu.etaxonomy.taxeditor.security.RequiredPermissions;
60 61
import eu.etaxonomy.taxeditor.store.CdmStore;
61 62
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
62 63

  
......
79 80
    private static final String TAXON = Messages.DeleteHandler_TAXON;
80 81
    private static final String SYNONYM = Messages.DeleteHandler_SYNONYM;
81 82
    private static final String NAME = Messages.DeleteHandler_NAME;
83
    private static final String OBJECT_MISSIN_RIGHTS = Messages.DeleteHandler_OBJECT_MISSING_RIGHTS;
82 84
    private static final String USER = Messages.DeleteHandler_USER;
83 85
    private static final String GROUP = Messages.DeleteHandler_GROUP;
84 86
    private static final String REFERENCE = Messages.DeleteHandler_REFERENCE;
......
92 94
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
93 95
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
94 96

  
95
        BulkEditorE4 editor= (BulkEditorE4) activePart.getObject();
97
        BulkEditor editor= (BulkEditor) activePart.getObject();
96 98
        IStructuredSelection selection = editor.getSelection();
97 99

  
98 100
        Iterator iterator = selection.iterator();
......
135 137
        }
136 138
    }
137 139

  
138
    private void delete(CdmBase object, Shell shell, BulkEditorE4 editor){
140
    private void delete(CdmBase object, Shell shell, BulkEditor editor){
139 141
        String errorMessage= OBJECT;
140 142
        DeleteConfiguratorBase config = null;
141 143
        DeleteResult result = new DeleteResult();
144
        boolean deleteAllowed = CdmStore.currentAuthentiationHasPermission(object,
145
                RequiredPermissions.NAME_DELETE);
146
        if (!deleteAllowed){
147
            MessagingUtils.messageDialog(OBJECT_MISSIN_RIGHTS, getClass(),
148
                    String.format(
149
                            Messages.DeleteHandler_OBJECT_MISSING_RIGHTS_MESSAGE+"\n",
150
                            object.getUserFriendlyDescription()),
151
                    null);
152
            return;
153
        }
142 154
        try {
143 155
            ICdmRepository controller;
144 156
            controller = CdmStore.getCurrentApplicationConfiguration();
......
157 169
                if (result_dialog != IStatus.OK){
158 170
                    return;
159 171
                }
172

  
160 173
                result = service.isDeletable(((SpecimenOrObservationBase<?>) object).getUuid(), config);
161 174
                errorMessage = SPECIMEN_OR_OBSERVATION;
162 175

  
......
184 197
                    if (result_dialog != IStatus.OK){
185 198
                        return;
186 199
                    }
187
                    result = controller.getNameService().isDeletable(name.getUuid(), config);
188
                    errorMessage = NAME;
200

  
201
                    if (deleteAllowed){
202
                        result = controller.getNameService().isDeletable(name.getUuid(), config);
203
                        errorMessage = NAME;
204
                    }else{
205
                        errorMessage = NAME;
206
                        result.setError();
207
                    }
189 208
                } catch(Exception e){
190 209
                    MessagingUtils.messageDialog(((TaxonName) object).getTitleCache() + " " +ALREADY_DELETED, getClass(),
191 210
                            Messages.DeleteHandler_ALREADY_DELETED,
......
317 336
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
318 337
            MHandledMenuItem menuItem){
319 338
        boolean canExecute = false;
320
        IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
339
        IStructuredSelection selection = ((BulkEditor)activePart.getObject()).getSelection();
321 340
        canExecute = !selection.isEmpty();
322 341
        Iterator iterator = selection.iterator();
323 342
        for(selection.iterator();iterator.hasNext();){
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/MergeGroupHandlerE4.java
28 28
import eu.etaxonomy.cdm.model.reference.Reference;
29 29
import eu.etaxonomy.cdm.strategy.merge.MergeException;
30 30
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorQuery;
31
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
31
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
32 32
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
33 33
import eu.etaxonomy.taxeditor.l10n.Messages;
34 34
import eu.etaxonomy.taxeditor.store.CdmStore;
......
48 48
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
49 49
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
50 50

  
51
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
51
        BulkEditor editor = (BulkEditor) activePart.getObject();
52 52
        AbstractBulkEditorInput input = editor.getEditorInput();
53 53
        Set<CdmBase> mergedCandidates = new HashSet<>();
54 54

  
......
141 141
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
142 142
            MHandledMenuItem menuItem) {
143 143
        boolean canExecute = false;
144
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
144
        BulkEditor editor = (BulkEditor) activePart.getObject();
145 145
        canExecute = !editor.getEditorInput().getMergeCandidates().isEmpty()
146 146
                && editor.getEditorInput().getMergeTarget()!=null;
147 147
        menuItem.setVisible(canExecute);
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/RemoveMergeCandidateHandlerE4.java
20 20
import org.eclipse.jface.viewers.IStructuredSelection;
21 21

  
22 22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
23
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
24 24

  
25 25
/**
26 26
 *
......
33 33

  
34 34
    @Execute
35 35
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
36
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
36
        BulkEditor editor = (BulkEditor) activePart.getObject();
37 37
        IStructuredSelection selection = editor.getSelection();
38 38
        Iterator iterator = selection.iterator();
39 39
        for(selection.iterator();iterator.hasNext();){
......
47 47
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
48 48
            MHandledMenuItem menuItem) {
49 49
        boolean canExecute = false;
50
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
51
        IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
50
        BulkEditor editor = (BulkEditor) activePart.getObject();
51
        IStructuredSelection selection = ((BulkEditor)activePart.getObject()).getSelection();
52 52
        boolean selectedMergeCandidate = false;
53 53
        Iterator iterator = selection.iterator();
54 54
        for(selection.iterator();iterator.hasNext();){
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMarkerFlagHandlerE4.java
25 25
import eu.etaxonomy.cdm.model.common.CdmBase;
26 26
import eu.etaxonomy.cdm.model.common.MarkerType;
27 27
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
29 29
import eu.etaxonomy.taxeditor.bulkeditor.e4.command.DynamicMarkerTypeEditingMenuE4;
30 30
import eu.etaxonomy.taxeditor.bulkeditor.operation.SetMarkerFlagOperation;
31 31
import eu.etaxonomy.taxeditor.event.EventUtility;
......
45 45
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
46 46
            MHandledMenuItem menuItem, UISynchronize sync) {
47 47

  
48
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
48
        BulkEditor editor = (BulkEditor) activePart.getObject();
49 49
        MarkerType markerType = (MarkerType) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_TYPE);
50 50
        boolean markerState = (boolean) menuItem.getTransientData().get(DynamicMarkerTypeEditingMenuE4.COMMAND_PARAMETER_MARKER_STATE);
51 51

  
......
66 66
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
67 67
            MHandledMenuItem menuItem){
68 68
        boolean canExecute = false;
69
        IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
69
        IStructuredSelection selection = ((BulkEditor)activePart.getObject()).getSelection();
70 70
        canExecute = !selection.isEmpty();
71 71
        Iterator iterator = selection.iterator();
72 72
        for(selection.iterator();iterator.hasNext();){
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeCandidateHandlerE4.java
20 20
import org.eclipse.jface.viewers.IStructuredSelection;
21 21

  
22 22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
23
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
24 24
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
25 25

  
26 26
/**
......
33 33

  
34 34
    @Execute
35 35
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
36
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
36
        BulkEditor editor = (BulkEditor) activePart.getObject();
37 37
        IStructuredSelection selection = editor.getSelection();
38 38
        Iterator iterator = selection.iterator();
39 39
        for(selection.iterator();iterator.hasNext();){
......
56 56
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
57 57
            MHandledMenuItem menuItem) {
58 58
        boolean canExecute = false;
59
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
60
        IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
59
        BulkEditor editor = (BulkEditor) activePart.getObject();
60
        IStructuredSelection selection = ((BulkEditor)activePart.getObject()).getSelection();
61 61
        canExecute = !selection.isEmpty()
62 62
                && editor.getEditorInput().isMergingEnabled();
63 63
        Iterator iterator = selection.iterator();
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/handler/SetMergeTargetHandlerE4.java
18 18
import org.eclipse.jface.viewers.IStructuredSelection;
19 19

  
20 20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
21
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
22 22
import eu.etaxonomy.taxeditor.bulkeditor.input.AbstractBulkEditorInput;
23 23

  
24 24
/**
......
31 31

  
32 32
    @Execute
33 33
    public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
34
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
34
        BulkEditor editor = (BulkEditor) activePart.getObject();
35 35
        CdmBase cdmBase = (CdmBase) editor.getSelection().getFirstElement();
36 36
        AbstractBulkEditorInput input = editor.getEditorInput();
37 37
        if(input.getMergeCandidates().contains(cdmBase)){
......
45 45
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
46 46
            MHandledMenuItem menuItem) {
47 47
        boolean canExecute = false;
48
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
49
        IStructuredSelection selection = ((BulkEditorE4)activePart.getObject()).getSelection();
48
        BulkEditor editor = (BulkEditor) activePart.getObject();
49
        IStructuredSelection selection = ((BulkEditor)activePart.getObject()).getSelection();
50 50
        Object firstElement = selection.getFirstElement();
51 51
        canExecute = selection.size()==1
52 52
                && editor.getEditorInput().isMergingEnabled()
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/EditorUtil.java
41 41
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42 42
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
43 43
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
44
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
44
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
45 45
import eu.etaxonomy.taxeditor.bulkeditor.input.TaxonEditorInput;
46 46
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.DescriptiveDataSetEditor;
47 47
import eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix.CharacterMatrixPart;
......
321 321

  
322 322
                break;
323 323
            }else if (taxonUUID == null){
324
                if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditorE4 && ((BulkEditorE4)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
324
                if (part.isDirty() && (part.getObject() instanceof TaxonNameEditorE4 || (part.getObject() instanceof BulkEditor && ((BulkEditor)part.getObject()).getEditorInput() instanceof TaxonEditorInput))){
325 325
                    dirtyParts.add((IE4SavablePart) part.getObject());
326 326
                }
327 327
            }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/e4/handler/EditCdmAuthoritiesHandlerE4.java
21 21
import org.eclipse.jface.viewers.IStructuredSelection;
22 22

  
23 23
import eu.etaxonomy.cdm.model.permission.Group;
24
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
24
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
25 25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
26 26
import eu.etaxonomy.taxeditor.editor.group.authority.CdmAuthorityEditorInput;
27 27
import eu.etaxonomy.taxeditor.editor.group.authority.e4.CdmAuthorityEditorE4;
......
40 40
    @Execute
41 41
    public void execute(EPartService partService, EModelService modelService, MApplication application,
42 42
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
43
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
43
        BulkEditor editor = (BulkEditor) activePart.getObject();
44 44
        Group group = (Group) editor.getSelection().getFirstElement();
45 45
        try {
46 46
            EditorUtil.openRightsEditor(CdmAuthorityEditorInput.NewInstance(group.getUuid()), modelService, partService, application);
......
53 53
    public boolean execute(MHandledMenuItem menuItem,
54 54
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart){
55 55
        boolean canExecute = false;
56
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
56
        BulkEditor editor = (BulkEditor) activePart.getObject();
57 57
        IStructuredSelection selection = editor.getSelection();
58 58
        canExecute =
59 59
                selection.size()==1
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/e4/handler/OpenRelatedConceptHandlerE4.java
25 25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26 26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27 27
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
28
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
29 29
import eu.etaxonomy.taxeditor.editor.EditorUtil;
30 30
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
31 31
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
......
47 47
            EModelService modelService, EPartService partService, MApplication application) {
48 48

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

  
53 53
        ConceptViewPartE4 conceptView = (ConceptViewPartE4) activePart.getObject();
......
56 56
        if(e4WrappedPart instanceof TaxonNameEditorE4){
57 57
            editor = (TaxonNameEditorE4) e4WrappedPart;
58 58
        }
59
        else if(e4WrappedPart instanceof BulkEditorE4){
60
            bulkEditor = (BulkEditorE4) e4WrappedPart;
59
        else if(e4WrappedPart instanceof BulkEditor){
60
            bulkEditor = (BulkEditor) e4WrappedPart;
61 61
        }
62 62
        TaxonBase<?> relatedTaxon = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff