Project

General

Profile

Download (8.48 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.taxon.Synonym;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
31
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
32
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
33
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
34
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
35
import eu.etaxonomy.taxeditor.editor.name.handler.NameEditorMenuPropertyTester;
36
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
37
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
38
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
39
import eu.etaxonomy.taxeditor.store.CdmStore;
40
import eu.etaxonomy.taxeditor.ui.dialog.configurator.deleteConfigurator.DeleteConfiguratorDialog;
41

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

    
50
    protected TaxonNameEditorE4 editor;
51

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

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

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

    
63
	}
64

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

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

    
84
	        }
85

    
86
		}
87
		TaxonBaseDeletionConfigurator deleteConfig;
88
		 ICdmRepository controller;
89

    
90
         controller = CdmStore.getCurrentApplicationConfiguration();
91

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

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

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

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

    
134
                }else{
135
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.MISAPPLIED_NAME_FOR());
136
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PRO_PARTE_MISAPPLIED_NAME_FOR());
137
                    editor.getTaxon().removeTaxon((Taxon)selectedElement, TaxonRelationshipType.PARTIAL_MISAPPLIED_NAME_FOR());
138

    
139
                }
140
    		    editor.getEditorInput().addTaxonBaseToDelete((TaxonBase)selectedElement,deleteConfig);
141
    		    editor.setDirty();
142
    		    if ( !result.getExceptions().isEmpty()){
143
                    DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
144
                }
145
    		}
146
      		editor.redraw();
147

    
148
		}
149
	}
150

    
151
    @CanExecute
152
    public boolean canExecute(
153
            @SuppressWarnings("unused") @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
154
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
155
            MHandledMenuItem menuItem){
156
        boolean canExecute = false;
157
        if(selection.size()==1){
158
            Object selectedElement = selection.getFirstElement();
159
            canExecute =
160
                    NameEditorMenuPropertyTester.isSynonym(selectedElement)
161
                    || NameEditorMenuPropertyTester.isMisapplication(selectedElement)
162
                    || NameEditorMenuPropertyTester.isRelatedConcept(selectedElement);
163
        }
164
        menuItem.setVisible(canExecute);
165
        return canExecute;
166
    }
167

    
168
	@Override
169
	public boolean postOperation(Object objectAffectedByOperation) {
170
	    editor.redraw();
171
		return true;
172
	}
173

    
174
	@Override
175
	public boolean onComplete() {
176

    
177
		return false;
178
	}
179

    
180
}
(13-13/16)