Project

General

Profile

Download (5.2 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.handler;
11
import org.eclipse.core.commands.AbstractHandler;
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.eclipse.core.commands.IHandler;
15
import org.eclipse.core.commands.common.NotDefinedException;
16
import org.eclipse.ui.IWorkbenchPage;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

    
19
import eu.etaxonomy.cdm.api.service.DeleteResult;
20
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
21
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.cdm.model.taxon.Synonym;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
26
import eu.etaxonomy.taxeditor.editor.Messages;
27
import eu.etaxonomy.taxeditor.editor.Page;
28
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin;
29
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
30
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteMisapplicationOperation;
31
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteSynonymOperation;
32
import eu.etaxonomy.taxeditor.editor.name.operation.DeleteTaxonBaseOperation;
33
import eu.etaxonomy.taxeditor.model.AbstractUtility;
34
import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
35
import eu.etaxonomy.taxeditor.model.MessagingUtils;
36
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
37
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
38
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
39
import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
40

    
41
/**
42
 * @author n.hoffmann
43
 * @created 21.04.2009
44
 * @version 1.0
45
 */
46
public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler, IPostOperationEnabled {
47

    
48
	TaxonNameEditor editor;
49
	/** {@inheritDoc} */
50
	@Override
51
    public Object execute(ExecutionEvent event) throws ExecutionException {
52
		editor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
53

    
54
		Object selectedElement = EditorUtil.getSelection(event).getFirstElement();
55

    
56
		doExecute(event, editor, selectedElement);
57

    
58
		return null;
59
	}
60

    
61
	protected void doExecute(ExecutionEvent event, TaxonNameEditor editor, Object selectedElement) {
62
		AbstractPostOperation operation = null;
63
		String commandName = null;
64

    
65
		try {
66
			commandName = event.getCommand().getName();
67
		} catch (NotDefinedException e) {
68
			MessagingUtils.error(getClass(), e);
69
		}
70
		IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
71
		// synonym
72
		if(selectedElement instanceof Synonym){
73
		    SynonymDeletionConfigurator deleteConfig = new SynonymDeletionConfigurator();
74
		    if(! DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfig, HandlerUtil.getActiveShell(event), Messages.DeleteTaxonBaseHandler_CONFIRM_DELETION,  Messages.DeleteTaxonBaseHandler_REALLY_DELETE_SYNONYM)){
75
		           return ;
76
            }
77
			operation = new DeleteSynonymOperation(commandName, editor.getUndoContext(), deleteConfig, activePage, editor.getTaxon(), (Synonym) selectedElement,this, editor, (ICdmEntitySessionEnabled)editor.getEditorInput());
78

    
79
		}
80
		// misapplication
81
		else if(selectedElement instanceof Taxon && ((Taxon) selectedElement).isMisapplication()){
82
		    TaxonDeletionConfigurator deleteConfig = new TaxonDeletionConfigurator();
83
		    if(! DeleteConfiguratorDialog.openConfirmWithConfigurator(deleteConfig, HandlerUtil.getActiveShell(event), Messages.DeleteTaxonBaseHandler_CONFIRM_DELETION,  Messages.DeleteTaxonBaseHandler_REALLY_DELETE_MISAPPLICATION)){
84
		        return ;
85
		    }
86
			operation = new DeleteMisapplicationOperation(commandName, editor.getUndoContext(),  deleteConfig, activePage, editor.getTaxon(), (Taxon) selectedElement,this, editor, (ICdmEntitySessionEnabled)editor.getEditorInput());
87
		} else {
88
			throw new IllegalArgumentException(Messages.DeleteTaxonBaseHandler_ELEMENT_MUST_BE_SYNONYM_MISAPP_CONCEPT);
89
		}
90

    
91
		AbstractUtility.executeOperation(operation);
92
		DeleteResult result = ((DeleteTaxonBaseOperation)operation).getResult();
93
		if (result.isError()){
94
            DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteDerivateOperation_DELETE_FAILED, TaxeditorEditorPlugin.PLUGIN_ID);
95
        } else {
96
            this.editor.redraw();
97
		    if (!result.getUpdatedObjects().isEmpty()){
98
                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
99
            }
100
		}
101
		    if (!result.getUpdatedObjects().isEmpty()){
102
                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
103
		    }
104

    
105

    
106
	}
107

    
108
	@Override
109
	public boolean postOperation(CdmBase objectAffectedByOperation) {
110

    
111
		return true;
112
	}
113

    
114
	@Override
115
	public boolean onComplete() {
116

    
117
		return false;
118
	}
119

    
120
}
(10-10/15)