Project

General

Profile

Revision fe08ca2d

IDfe08ca2d81fa532335495f504eb82752df61b8a8
Parent 036767ba
Child 75c87e6f

Added by Patrick Plitzner over 1 year ago

ref #7887 Use vocabulary service for term creation directly

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateDefinedTermHandlerE4.java
21 21
import org.eclipse.e4.ui.services.IServiceConstants;
22 22
import org.eclipse.jface.viewers.IStructuredSelection;
23 23

  
24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
24
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
25 25
import eu.etaxonomy.cdm.persistence.dto.TermDto;
26
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
26 27
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
27 28
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
28 29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
29 30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.store.AppModelId;
30 32
import eu.etaxonomy.taxeditor.store.StoreUtil;
31 33

  
32 34
/**
......
45 47
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
46 48

  
47 49
        boolean addTermAsKindOf =
48
                menuItem.getCommand().getElementId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false;
50
                menuItem.getCommand().getElementId()
51
                .equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERMS_NEWKINDOFTERM)?true:false;
49 52

  
50 53
        String label = menuItem.getLocalizedLabel();
51 54
        IUndoContext undoContext = StoreUtil.getUndoContext();
52 55

  
53
        TermDto parent = (TermDto) selection.getFirstElement();
56
        AbstractTermDto parent = (AbstractTermDto) selection.getFirstElement();
54 57
        AbstractPostOperation operation =
55 58
                new CreateDefinedTermOperation(label,
56 59
                        undoContext,
......
69 72
        canExecute = selection.size()==1
70 73
                &&
71 74
                (firstElement instanceof TermDto
72
                        || firstElement instanceof TermVocabulary);
75
                        || firstElement instanceof TermVocabularyDto);
73 76
        UUID vocabularyUuid = null;
74 77

  
75 78
        if(firstElement instanceof TermDto){
76 79
            vocabularyUuid = ((TermDto) firstElement).getVocabularyUuid();
77
        }else if(firstElement instanceof TermVocabulary){
78
            vocabularyUuid = ((TermVocabulary) firstElement).getUuid();
80
        }else if(firstElement instanceof TermVocabularyDto
81
                && !menuItem.getCommand().getElementId()
82
                .equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERMS_NEWKINDOFTERM)){
83
            vocabularyUuid = ((TermVocabularyDto) firstElement).getUuid();
79 84
        }
80 85
        canExecute &= vocabularyUuid!=null;
81 86
        menuItem.setVisible(canExecute);
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/operation/CreateDefinedTermOperation.java
15 15
import org.eclipse.core.runtime.IStatus;
16 16

  
17 17
import eu.etaxonomy.cdm.api.service.ITermService;
18
import eu.etaxonomy.cdm.api.service.IVocabularyService;
19
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
18 20
import eu.etaxonomy.cdm.persistence.dto.TermDto;
21
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
19 22
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
20 23
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
21 24
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
......
28 31
 */
29 32
public class CreateDefinedTermOperation extends AbstractPostOperation {
30 33

  
31
	private final TermDto parent;
34
	private final AbstractTermDto parent;
32 35
	private final TermEditorInput definedTermInput;
33 36
    private boolean addTermAsKindOf;
34 37

  
35 38

  
36 39
	public CreateDefinedTermOperation(String label,
37 40
			IUndoContext undoContext,
38
			TermDto parent,
41
			AbstractTermDto parent,
39 42
			TermEditorInput definedTermInput,
40 43
			IPostOperationEnabled postOperationEnabled, boolean addTermAsKindOf) {
41 44
		super(label, undoContext, null, postOperationEnabled);
......
47 50
	@Override
48 51
	public IStatus execute(IProgressMonitor monitor, IAdaptable info)
49 52
			throws ExecutionException {
50
	    CdmStore.getService(ITermService.class).addNewTerm(definedTermInput.getTermType(), parent.getUuid(), addTermAsKindOf);
51
//
52
//		//FIXME: Implement adding new terms to vocabularies
53
////		if (parentTermBase instanceof TermVocabulary){
54
////			TermVocabulary vocabulary = (TermVocabulary) parentTermBase;
55
////			vocabulary.addTerm(newTerm);
56
////		} else
57
//		DefinedTermBase parentTerm = CdmStore.getService(ITermService.class).load(parent.getUuid());
58
//		TermVocabulary vocabulary = parentTerm.getVocabulary();
59
//		parentTerm.addIncludes(newTerm);
60
////        parent.getIncludes().add(new TermDto(newTerm.getUuid(), null, parentTerm.getUuid(), vocabulary.getUuid(), null));
61
//
62
////			DefinedTermBase parent = (DefinedTermBase) parentTermBase;
63
////			if(addTermAsKindOf){
64
////			    parent.addGeneralizationOf(newTerm);
65
////			}
66
////			else{
67
////			    parent.addIncludes(newTerm);
68
////			}
69
//			vocabulary.addTerm(newTerm);
70
////		}
71

  
53
	    if(parent instanceof TermDto){
54
	        CdmStore.getService(ITermService.class).addNewTerm(definedTermInput.getTermType(), parent.getUuid(), addTermAsKindOf);
55
	    }
56
	    else if(parent instanceof TermVocabularyDto){
57
	        CdmStore.getService(IVocabularyService.class).addNewTerm(definedTermInput.getTermType(), parent.getUuid());
58
	    }
72 59
		return postExecute(null);
73 60
	}
74 61

  
75 62
	@Override
76 63
	public IStatus redo(IProgressMonitor monitor, IAdaptable info)
77 64
			throws ExecutionException {
78
		// TODO Auto-generated method stub
79 65
		return null;
80 66
	}
81 67

  
82 68
	@Override
83 69
	public IStatus undo(IProgressMonitor monitor, IAdaptable info)
84 70
			throws ExecutionException {
85
		// TODO Auto-generated method stub
86 71
		return null;
87 72
	}
88 73

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)