Project

General

Profile

« Previous | Next » 

Revision 325e86cf

Added by Patrick Plitzner over 5 years ago

ref #7887 Convert delete handler/operation to DTOs

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/DeleteTermBaseOperation.java
18 18
import eu.etaxonomy.cdm.api.service.DeleteResult;
19 19
import eu.etaxonomy.cdm.api.service.ITermService;
20 20
import eu.etaxonomy.cdm.api.service.IVocabularyService;
21
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
22
import eu.etaxonomy.cdm.model.common.TermBase;
23
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
22
import eu.etaxonomy.cdm.persistence.dto.TermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24 24
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
25 25
import eu.etaxonomy.taxeditor.l10n.Messages;
26 26
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
38 38
public class DeleteTermBaseOperation extends AbstractPostTaxonOperation {
39 39

  
40 40
	private final TermEditorInput definedEditorInput;
41
	private final TermBase termBase;
41
	private final AbstractTermDto termBase;
42 42

  
43 43
	public DeleteTermBaseOperation(String label,
44 44
			IUndoContext undoContext,
45
			TermBase termBase,
45
			AbstractTermDto termBase,
46 46
			TermEditorInput definedEditorInput,
47 47
			IPostOperationEnabled postOperationEnabled) {
48 48
		super(label, undoContext, postOperationEnabled);
......
53 53
	@Override
54 54
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
55 55
			throws ExecutionException {
56
		if (termBase instanceof TermVocabulary) {
57
			if (((TermVocabulary)termBase).getCreatedBy() == null) {
58
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), Messages.DeleteTermBaseOperation_SYSTEM_VOC);
59
				MessagingUtils.warningDialog(Messages.DeleteTermBaseOperation_CANNOT_DELETE_VOC, termBase, status);
60
				return status;
61
			}
62

  
63
			if (!((TermVocabulary)termBase).getTerms().isEmpty()) {
64
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), Messages.DeleteTermBaseOperation_DELETE_ALL_TERMS_BEFORE);
65
				MessagingUtils.warningDialog(Messages.DeleteTermBaseOperation_VOC_NOT_EMPTY, termBase, status);
66
				return status;
67
			}
68

  
56
		if (termBase instanceof TermVocabularyDto) {
69 57
			definedEditorInput.getVocabularies().remove(termBase);
70 58

  
71 59
			DeleteResult result =	CdmStore.getService(IVocabularyService.class).delete(termBase.getUuid());
......
73 61
			    return showErrorMessage(result);
74 62
			}
75 63

  
76
		} else if (termBase instanceof DefinedTermBase) {
77

  
78

  
79
			DefinedTermBase definedTermBase = (DefinedTermBase) termBase;
80

  
81
			if (((DefinedTermBase)termBase).getCreatedBy() == null) {
82
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), Messages.DeleteTermBaseOperation_SYSTEM_TERM);
83
				MessagingUtils.warningDialog(Messages.DeleteTermBaseOperation_CANNOT_DELETE_TERM, termBase, status);
84
				return status;
85
			}
86
			if(!definedTermBase.getIncludes().isEmpty()){
87
				IStatus status = new Status(IStatus.CANCEL, StoreUtil.getPluginId(), Messages.DeleteTermBaseOperation_TERM_INCLUDES_OTHERS);
88
				MessagingUtils.warningDialog(Messages.DeleteTermBaseOperation_TERM_INLCUDES, termBase, status);
89
				return status;
90
			}
91

  
64
		} else if (termBase instanceof TermDto) {
92 65
			DeleteResult result =	CdmStore.getService(ITermService.class).delete(termBase.getUuid());
93 66
			if (!result.isOk()){
94 67
			    return showErrorMessage(result);
95 68
            }
96 69
		}
97

  
98 70
		return postExecute(termBase);
99 71
	}
100 72

  

Also available in: Unified diff