Project

General

Profile

Download (8.07 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.editor.name.e4.handler;
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.di.UISynchronize;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18
import org.eclipse.e4.ui.services.IServiceConstants;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.swt.widgets.Shell;
21

    
22
import eu.etaxonomy.cdm.api.application.ICdmRepository;
23
import eu.etaxonomy.cdm.api.service.DeleteResult;
24
import eu.etaxonomy.cdm.api.service.ITaxonService;
25
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
26
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
27
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29
import eu.etaxonomy.cdm.model.taxon.Synonym;
30
import eu.etaxonomy.cdm.model.taxon.Taxon;
31
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
32
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
33
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
34
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
35
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
36
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
37
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
38
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
39
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
40
import eu.etaxonomy.taxeditor.store.CdmStore;
41
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
42

    
43
/**
44
 *
45
 * @author pplitzner
46
 * @since Aug 28, 2017
47
 *
48
 */
49
public class DeleteTaxonBaseHandlerE4 implements IPostOperationEnabled {
50

    
51
    protected TaxonNameEditorE4 editor;
52

    
53
	@Execute
54
	public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
55
	        @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
56
	        @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
57
	        MHandledMenuItem menuItem,
58
            UISynchronize sync) {
59

    
60
	    editor = (TaxonNameEditorE4) activePart.getObject();
61

    
62
	    doExecute(menuItem.getLocalizedLabel(), shell, editor, selection.getFirstElement(), sync);
63

    
64
	}
65

    
66
	protected void doExecute(String commandName, Shell shell, TaxonNameEditorE4 editor, Object selectedElement,
67
            UISynchronize sync) {
68
		AbstractPostOperation operation = null;
69

    
70
		if (selectedElement instanceof TaxonBase){
71
		    if (((TaxonBase)selectedElement).getId() == 0){
72
		        if (selectedElement instanceof Taxon &&((Taxon) selectedElement).isMisapplication() ) {
73
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
74
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PRO_PARTE_MISAPPLIED_NAME_FOR());
75
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PARTIAL_MISAPPLIED_NAME_FOR());
76
                } else if (selectedElement instanceof Taxon &&((Taxon) selectedElement).isProparteSynonym()) {
77
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PRO_PARTE_SYNONYM_FOR());
78
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PARTIAL_SYNONYM_FOR());
79
                } else if (selectedElement instanceof Synonym){
80
                    editor.getTaxon().removeSynonym((Synonym)selectedElement);
81
                }
82
		        editor.redraw();
83
		        return;
84

    
85
	        }
86

    
87
		}
88
		TaxonBaseDeletionConfigurator deleteConfig;
89
		 ICdmRepository controller;
90

    
91
         controller = CdmStore.getCurrentApplicationConfiguration();
92

    
93
         ITaxonService service = controller.getTaxonService();
94
         DeleteResult result;
95
		// synonym
96
		if(selectedElement instanceof Synonym){
97
		    deleteConfig = new SynonymDeletionConfigurator();
98
		    if(! DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfig, shell, Messages.DeleteTaxonBaseHandler_CONFIRM_DELETION,  Messages.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM)){
99
		           return ;
100
            }
101

    
102
//			operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), deleteConfig, editor.getTaxon(), (Synonym) selectedElement,this, editor, editor.getEditorInput());
103

    
104
		}
105
		// misapplication
106
		else if(selectedElement instanceof Taxon && (((Taxon) selectedElement).isMisapplication() || ((Taxon) selectedElement).isProparteSynonym())){
107
		    deleteConfig = new TaxonDeletionConfigurator();
108
		    if(! DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfig, shell, Messages.DeleteTaxonBaseHandler_CONFIRM_DELETION,  Messages.DeleteTaxonBaseHandler_REALLY_DELETE_MISAPPLICATION)){
109
		        return ;
110
		    }
111

    
112
//			operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(),  deleteConfig, editor.getTaxon(), (Taxon) selectedElement,this, editor, editor.getEditorInput());
113
//		    editor.getEditorInput().addSynonymToDelete((TaxonBase)selectedElement,deleteConfig);
114
		} else {
115
			throw new IllegalArgumentException(Messages.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT);
116
		}
117
		result = service.isDeletable(((TaxonBase)selectedElement).getUuid(), deleteConfig);
118
//		AbstractUtility.executeOperation(operation, sync);
119
//		 = ((DeleteTaxonBaseOperation)operation).getResult();
120
		if (result != null){
121
    		if (result.isError()){
122
                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteDerivateOperation_DELETE_FAILED, TaxeditorEditorPlugin.PLUGIN_ID);
123
            } else if (selectedElement instanceof Synonym){
124
                editor.getEditorInput().addTaxonBaseToDelete((TaxonBase)selectedElement,deleteConfig);
125
                editor.getTaxon().removeSynonym((Synonym)selectedElement);
126
                editor.setDirty();
127
    		    if (!result.getExceptions().isEmpty()){
128
                    DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
129
                }
130
    		} else if (selectedElement instanceof Taxon ){
131
    		    if (selectedElement instanceof Taxon &&((Taxon) selectedElement).isProparteSynonym() ) {
132
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PRO_PARTE_SYNONYM_FOR());
133
                }else{
134
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
135
                }
136
    		    editor.getEditorInput().addTaxonBaseToDelete((TaxonBase)selectedElement,deleteConfig);
137
    		    editor.setDirty();
138
    		    if ( !result.getExceptions().isEmpty()){
139
                    DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
140
                }
141
    		}
142
      		editor.redraw();
143

    
144
		}
145
	}
146

    
147
    @CanExecute
148
    public boolean canExecute(
149
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
150
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
151
            MHandledMenuItem menuItem){
152
        boolean canExecute = false;
153
        Object selectedElement = selection.getFirstElement();
154
        canExecute =
155
                NameEditorMenuPropertyTester.isSynonym(selectedElement)
156
                || NameEditorMenuPropertyTester.isMisapplication(selectedElement)
157
                || NameEditorMenuPropertyTester.isRelatedConcept(selectedElement);
158
        menuItem.setVisible(canExecute);
159
        return canExecute;
160
    }
161

    
162
	@Override
163
	public boolean postOperation(CdmBase objectAffectedByOperation) {
164
	    editor.redraw();
165
		return true;
166
	}
167

    
168
	@Override
169
	public boolean onComplete() {
170

    
171
		return false;
172
	}
173

    
174
}
(11-11/14)