Project

General

Profile

Download (2.42 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2015 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.handler;
10

    
11
import javax.inject.Named;
12

    
13
import org.eclipse.e4.core.di.annotations.Execute;
14
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
15
import org.eclipse.e4.ui.services.IServiceConstants;
16
import org.eclipse.jface.dialogs.MessageDialog;
17

    
18
import eu.etaxonomy.cdm.api.service.IAgentService;
19
import eu.etaxonomy.cdm.api.service.UpdateResult;
20
import eu.etaxonomy.cdm.model.agent.Person;
21
import eu.etaxonomy.cdm.model.agent.Team;
22
import eu.etaxonomy.cdm.strategy.merge.MergeException;
23
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
24
import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
26
import eu.etaxonomy.taxeditor.store.CdmStore;
27

    
28
/**
29
 * @author k.luther
30
 * @date 12.05.2015
31
 *
32
 */
33
public class ConvertPerson2TeamHandlerE4 {
34

    
35

    
36
    @Execute
37
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)Person person,
38
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
39

    
40
        BulkEditorE4 editor = (BulkEditorE4) activePart.getObject();
41

    
42
        if (editor.isDirty()){
43
            boolean proceed = MessageDialog.openQuestion(null,
44
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
45
            if (proceed) {
46
                editor.save();
47
            } else {
48
                return;
49
            }
50
        }
51

    
52
        Team team =null;
53
        UpdateResult result = null;
54
        try {
55
            result = CdmStore.getService(IAgentService.class).convertPerson2Team(person.getUuid());
56
        } catch (IllegalArgumentException e) {
57
            MessagingUtils.errorDialog("Can not convert Person into a Team", null, e.getLocalizedMessage(), TaxeditorBulkeditorPlugin.PLUGIN_ID,e, true);
58
        } catch (MergeException e) {
59
            MessagingUtils.informationDialog("Convert not possible", "Person can not be transformed into team as it is already part of a team.");
60
        }
61
        if (result != null &&result.isOk()){
62
            team = (Team)result.getCdmEntity();
63
        }
64
        if (team != null){
65
            editor.refresh();
66
        }
67
    }
68

    
69
}
(1-1/9)